diff --git a/.update.sh b/.update.sh index 1f13374..47c09fa 100644 --- a/.update.sh +++ b/.update.sh @@ -3,12 +3,13 @@ THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_FILE=$(basename "${BASH_SOURCE}") source "$THIS_DIR/tools/common.sh" +DFS_ENABLE_RET=${DFS_ENABLE_RET:-0} # get the specified commit id -dfs_commit=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id) -if [[ ${#dfs_commit} != 40 ]]; then +DFS_COMMIT=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id) +if [[ ${#DFS_COMMIT} != 40 ]]; then fmt_error "invalid commit id" - post_log "ERROR" "$THIS_FILE" "invalid commit id: ${dfs_commit}" + post_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}" exit fi # fetch origin @@ -20,16 +21,16 @@ if [[ -n "$(git status -s)" ]]; then exit fi # update -if [[ "$(git rev-parse HEAD)" == "$dfs_commit" ]]; then +if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then fmt_info "nothing to do" post_log "INFO" "$THIS_FILE" "nothing to do" else - fmt_info "checking out to commit $dfs_commit ..." + fmt_info "checking out to commit $DFS_COMMIT ..." if [[ -z "$DFS_DEV" ]]; then - git -c advice.detachedHead=false checkout $dfs_commit + post_log "INFO" "$THIS_FILE" "will check out to commit $DFS_COMMIT" + git -c advice.detachedHead=false checkout $DFS_COMMIT + cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_ENABLE_RET else fmt_warning "won't really checkout in dev mode" fi - post_log "INFO" "$THIS_FILE" "will check out to commit $dfs_commit" - cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit fi diff --git a/install.sh b/install.sh index 2b61496..f7e7ad5 100755 --- a/install.sh +++ b/install.sh @@ -219,7 +219,11 @@ install_update(){ cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh" chmod +x "${DOTFILES}/update.sh" fmt_note "running update.sh ..." - ${DOTFILES}/update.sh + DFS_ENABLE_RET=1 ${DOTFILES}/update.sh + if [[ $? == 1 ]]; then + fmt_note "dfs updated. re-running install.sh ..." + "${DOTFILES}/install.sh" && exit + fi } uninstall_update(){ @@ -228,8 +232,8 @@ uninstall_update(){ } install(){ - preinstall_check install_update + preinstall_check install_crontab install_file_content install_symlink