mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-04-24 09:36:59 +08:00
getdfs: support multiple users
This commit is contained in:
parent
90895fe4a9
commit
e24b15edd1
|
@ -1,48 +1,53 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
ARG=""
|
||||
GOT_OPTS=()
|
||||
while [[ $# > 0 || -n "$ARG" ]]; do
|
||||
if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
|
||||
DFS_USER="$(whoami)"
|
||||
while [[ $# > 0||-n "$ARG" ]];do
|
||||
if [[ -z "$ARG" ]];then ARG=$1;shift;fi
|
||||
case $ARG in
|
||||
-s*|--secure ) DFS_SECURE=1 ;;
|
||||
-u*|--user )
|
||||
if [[ "$ARG" == --*=* ]]; then
|
||||
-s*|--secure)DFS_SECURE=1;;
|
||||
-u*|--user)if [[ "$ARG" == --*=* ]];then
|
||||
DFS_USER="${ARG#*=}"
|
||||
else
|
||||
DFS_USER=$1
|
||||
shift
|
||||
fi
|
||||
if [[ -z "$DFS_USER" ]]; then
|
||||
if [[ -z "$DFS_USER" ]];then
|
||||
echo "install user is required"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--*=* ) GOT_OPTS+=("${ARG%%=*}" "${ARG#*=}") ;;
|
||||
--* ) GOT_OPTS+=("$ARG") ;;
|
||||
-* ) GOT_OPTS+=("${ARG:0:2}") ;;
|
||||
* ) GOT_OPTS+=("$ARG") ;;
|
||||
fi;;
|
||||
--*=*)GOT_OPTS+=("${ARG%%=*}" "${ARG#*=}");;
|
||||
--*)GOT_OPTS+=("$ARG");;
|
||||
-*)GOT_OPTS+=("${ARG:0:2}");;
|
||||
*)GOT_OPTS+=("$ARG");;
|
||||
esac
|
||||
if [[ "$ARG" == "--"* || ! "$ARG" == "-"* || ${#ARG} -le 2 ]]; then
|
||||
if [[ "$ARG" == "--"*||! "$ARG" == "-"*||${#ARG} -le 2 ]];then
|
||||
ARG=""
|
||||
else
|
||||
ARG=-${ARG:2}
|
||||
fi
|
||||
done
|
||||
|
||||
# install TODO: multiple users; remove -a after installed for the first user
|
||||
if command -v su 1>/dev/null && test -n "$DFS_USER" && test "$DFS_USER" != "$(whoami)"; then
|
||||
SUCMD="su $DFS_USER"
|
||||
else
|
||||
SUCMD="bash"
|
||||
fi
|
||||
$SUCMD << EOF
|
||||
IFS=',' read -r -a DFS_USERS<<<"$DFS_USER"
|
||||
for u in "${DFS_USERS[@]}";do
|
||||
if [[ -z "$u" ]];then
|
||||
continue
|
||||
fi
|
||||
if ! id -u "$u" >/dev/null 2>&1;then
|
||||
echo "user $u not exists"
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$u" == "$(whoami)" ]];then
|
||||
SUCMD="bash"
|
||||
else
|
||||
SUCMD="su $u"
|
||||
fi
|
||||
$SUCMD<<EOF
|
||||
cd
|
||||
if [[ ! -f ~/dotfiles/install.sh ]]; then
|
||||
if [[ ! -f ~/dotfiles/install.sh ]];then
|
||||
git clone https://gitee.com/dictxiong/dotfiles
|
||||
fi
|
||||
if [[ "$DFS_SECURE" == "1" ]]; then
|
||||
if [[ "$DFS_SECURE" == "1" ]];then
|
||||
echo "enter secure mode"
|
||||
cd dotfiles
|
||||
git fetch --all
|
||||
|
@ -51,4 +56,5 @@ if [[ "$DFS_SECURE" == "1" ]]; then
|
|||
fi
|
||||
./dotfiles/install.sh ${GOT_OPTS[@]}
|
||||
zsh -c "source ~/.zshrc"
|
||||
EOF
|
||||
EOF
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue
Block a user