DFS_UPDATE_CHANNEL?

This commit is contained in:
xiongdian.me 2022-11-15 20:18:19 +08:00
parent 1e992797f9
commit bb648df789
2 changed files with 18 additions and 10 deletions

View File

@ -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

View File

@ -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