From 25a74c15b41ef12fd90d4b154b8d9b6414972969 Mon Sep 17 00:00:00 2001 From: "xiongdian.me" Date: Fri, 6 Jan 2023 15:00:54 +0800 Subject: [PATCH] install.sh: -x to set dfs config; ci --- install.sh | 31 ++++++++++++++++++++++++++++++- tools/test.zsh | 3 ++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index af62d1b..bfbe11d 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,7 @@ fi DOTFILE_TILDE=${DOTFILES/"$HOME"/\~} CRON_JOB="0 * * * * ${DOTFILES}/update.sh" +declare -a DFS_CONFIGS declare -a HOME_FILES_PATH declare -a HOME_FILES_CONTENT HOME_FILES_PATH[0]=".zshrc" @@ -81,6 +82,26 @@ preinstall_check() done } +prepare_config() +{ + fmt_note "preparing dotfiles configurations ..." + local key value + for i in "${DFS_CONFIGS[@]}"; do + if [[ $i =~ *=* ]]; then + key=${i%%=*} + value=${i#*=} + else + key=$i + value=$(eval echo \$$key) + fi + HOME_FILES_PATH+=(".config/dotfiles/env") + HOME_FILES_CONTENT+=("$key=$value") + echo -n "$key=$value" + export $key=$value + done + echo +} + install_file_content() { fmt_note "installing file content ..." @@ -239,6 +260,9 @@ install() if [[ "$INSTALL_DEP" == "1" ]]; then install_dependencies; fi install_update preinstall_check + if [[ ${#DFS_CONFIGS[@]} > 0 ]]; then + prepare_config + fi install_crontab install_file_content install_symlink @@ -267,13 +291,18 @@ FUNC=install INSTALL_DEP=0 store_config=0 for i in ${GOT_OPTS[@]}; do + if [[ "$store_config" == "1" ]]; then + store_config=0 + DFS_CONFIGS+=("$i") + continue + fi case $i in -i ) FUNC=install ;; -r ) FUNC=uninstall ;; -d|--dev ) export DFS_DEV=1; set -x ;; -a|--auto ) INSTALL_DEP=1 ;; -s|--secure ) export DFS_DEV=0 ;; - -x ) store_config=1 ;; # TODO: store and write to config + -x ) store_config=1 ;; * ) fmt_fatal "unknown option \"$i\"" ;; esac done diff --git a/tools/test.zsh b/tools/test.zsh index 4694f7c..36643fc 100644 --- a/tools/test.zsh +++ b/tools/test.zsh @@ -43,9 +43,10 @@ test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commi git reset --hard $DFS_VERSION # then check install.sh -./install.sh -l +./install.sh -l -x DFS_CI=1 dfs version test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id` +grep -q "DFS_CI=1" ~/.config/dotfiles/env # clean git reset --hard $DFS_VERSION