mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-11-23 20:38:16 +08:00
[dev] common.sh parses args; riot; getdfs; install.sh -x KEY=VAL (#35)
* common.sh: export vars in env; zshrc: gdebug
* fix error when locale not exists
* DFS_COLOR
* common.sh: parse args automatically
* ci: test common.sh getopts
* common.sh: argparser supports spaces
* ciot: init
* ciot -> diot; remove sibd, sob and snasp
* rename diot -> riot
* update home0 ssh pubkey; fix ci temperarily
* gdebug will record time
* gdebug supports empty; --dry-run wip
* get.dotfiles.cn
* bug fix (Thu Jan 5 20:53:58 CST 2023)
* fix ci
* fix ci
* install.sh: -d will set -x
* ci: -asl
* getdfs: install for another user using -u <uname>
* try fix when su doesnot exist
* bug fix (Thu Jan 5 22:58:40 CST 2023)
* bug fix (Thu Jan 5 22:59:33 CST 2023)
* introduce SUDOE and so debug
* ask_for_yn now use stdout to return
* getdfs: support multiple users
* install.sh: -x to set dfs config; ci
* fix ci
* bug fix (Fri Jan 6 15:11:24 CST 2023)
* auto-detect DFS_NO_WALL
* bug fix (Fri Jan 6 15:43:25 CST 2023)
* getdfs: ${repo}
* bug fix (Fri Jan 6 16:08:41 CST 2023)
* getdfs: prompt user
Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
This commit is contained in:
62
tools/get.dotfiles.cn
Normal file
62
tools/get.dotfiles.cn
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
ARG=""
|
||||
GOT_OPTS=()
|
||||
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
|
||||
DFS_USER="${ARG#*=}"
|
||||
else
|
||||
DFS_USER=$1
|
||||
shift
|
||||
fi
|
||||
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");;
|
||||
esac
|
||||
if [[ "$ARG" == "--"*||! "$ARG" == "-"*||${#ARG} -le 2 ]];then
|
||||
ARG=""
|
||||
else
|
||||
ARG=-${ARG:2}
|
||||
fi
|
||||
done
|
||||
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
|
||||
echo "install for user $u in 3 seconds ..."
|
||||
sleep 3
|
||||
$SUCMD<<EOF
|
||||
cd
|
||||
if [[ ! -f ~/dotfiles/install.sh ]];then
|
||||
git clone ${repo}
|
||||
fi
|
||||
if [[ "$DFS_SECURE" == "1" ]];then
|
||||
echo "enter secure mode"
|
||||
cd dotfiles
|
||||
git fetch --all
|
||||
git -c advice.detachedHead=false checkout $(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id)
|
||||
cd
|
||||
fi
|
||||
./dotfiles/install.sh ${GOT_OPTS[@]}
|
||||
zsh -c "source ~/.zshrc"
|
||||
EOF
|
||||
done
|
||||
Reference in New Issue
Block a user