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