get.dotfiles.cn

This commit is contained in:
xiongdian.me 2023-01-05 20:52:54 +08:00
parent b2e26067ac
commit 90e8efc0d9
3 changed files with 69 additions and 1 deletions

View File

@ -116,3 +116,20 @@ jobs:
run: | run: |
echo $SHELL echo $SHELL
antigen list antigen list
test-get-dotfiles-cn:
name: test of get.dotfiles.cn script
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: run the script
run: |
bash tools/get.dotfiles.cn
- name: run tests
shell: /bin/zsh -ileo PIPE_FAIL {0}
run: source tools/test.zsh

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
# ask_for_Yn is not compatible with `set -e`
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/tools/common.sh" source "$THIS_DIR/tools/common.sh"
@ -42,7 +43,7 @@ install_dependencies()
"msys" ) "msys" )
"$DOTFILES/tools/msys2.sh" pacman-S "$DOTFILES/tools/msys2.sh" pacman-S
;; ;;
* ) fmt_error "dfs auto-install is not implemented on OS: $(get_os_name)" * ) fmt_error "dfs auto-install is not implemented on OS: $(get_os_name). skipping ..."
esac esac
} }

50
tools/get.dotfiles.cn Normal file
View File

@ -0,0 +1,50 @@
#!/bin/bash
set -e
ARG=""
GOT_OPTS=()
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
# install
if [[ -n "$DFS_USER" ]]; then
su $DFS_USER
fi
cd
if [[ ! -f ~/dotfiles/install.sh ]]; then
git clone https://gitee.com/dictxiong/dotfiles
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"