diff --git a/.update.sh b/.update.sh index 47c09fa..0a6566b 100644 --- a/.update.sh +++ b/.update.sh @@ -3,15 +3,10 @@ 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 - fmt_error "invalid commit id" - post_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}" - exit -fi +DFS_UPDATED_RET=${DFS_UPDATED_RET:-0} +DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"} + # fetch origin cd $DOTFILES git fetch --all @@ -20,6 +15,19 @@ if [[ -n "$(git status -s)" ]]; then post_log "ERROR" "$THIS_FILE" "directory not clean" exit fi + +# get the specified commit id +case $DFS_UPDATE_CHANNEL in + "main" ) DFS_COMMIT=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;; + "latest" ) DFS_COMMIT=$(git for-each-ref --sort=-committerdate refs/heads refs/remotes --format='%(objectname)' | head -n 1) ;; + * ) fmt_fatal "invalid update channel: $DFS_UPDATE_CHANNEL" ;; +esac +if [[ ${#DFS_COMMIT} != 40 ]]; then + fmt_error "invalid commit id" + post_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}" + exit +fi + # update if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then fmt_info "nothing to do" @@ -29,7 +37,7 @@ else if [[ -z "$DFS_DEV" ]]; then 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 + cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET else fmt_warning "won't really checkout in dev mode" fi diff --git a/install.sh b/install.sh index f7e7ad5..e94d4d2 100755 --- a/install.sh +++ b/install.sh @@ -219,7 +219,7 @@ install_update(){ cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh" chmod +x "${DOTFILES}/update.sh" fmt_note "running update.sh ..." - DFS_ENABLE_RET=1 ${DOTFILES}/update.sh + DFS_UPDATED_RET=1 ${DOTFILES}/update.sh if [[ $? == 1 ]]; then fmt_note "dfs updated. re-running install.sh ..." "${DOTFILES}/install.sh" && exit