mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-04-28 23:02:22 +08:00
DFS_UPDATE_CHANNEL?
This commit is contained in:
parent
1e992797f9
commit
bb648df789
26
.update.sh
26
.update.sh
|
@ -3,15 +3,10 @@
|
||||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
THIS_FILE=$(basename "${BASH_SOURCE}")
|
THIS_FILE=$(basename "${BASH_SOURCE}")
|
||||||
source "$THIS_DIR/tools/common.sh"
|
source "$THIS_DIR/tools/common.sh"
|
||||||
DFS_ENABLE_RET=${DFS_ENABLE_RET:-0}
|
|
||||||
|
|
||||||
# get the specified commit id
|
DFS_UPDATED_RET=${DFS_UPDATED_RET:-0}
|
||||||
DFS_COMMIT=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id)
|
DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"}
|
||||||
if [[ ${#DFS_COMMIT} != 40 ]]; then
|
|
||||||
fmt_error "invalid commit id"
|
|
||||||
post_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
# fetch origin
|
# fetch origin
|
||||||
cd $DOTFILES
|
cd $DOTFILES
|
||||||
git fetch --all
|
git fetch --all
|
||||||
|
@ -20,6 +15,19 @@ if [[ -n "$(git status -s)" ]]; then
|
||||||
post_log "ERROR" "$THIS_FILE" "directory not clean"
|
post_log "ERROR" "$THIS_FILE" "directory not clean"
|
||||||
exit
|
exit
|
||||||
fi
|
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
|
# update
|
||||||
if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then
|
if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then
|
||||||
fmt_info "nothing to do"
|
fmt_info "nothing to do"
|
||||||
|
@ -29,7 +37,7 @@ else
|
||||||
if [[ -z "$DFS_DEV" ]]; then
|
if [[ -z "$DFS_DEV" ]]; then
|
||||||
post_log "INFO" "$THIS_FILE" "will check out to commit $DFS_COMMIT"
|
post_log "INFO" "$THIS_FILE" "will check out to commit $DFS_COMMIT"
|
||||||
git -c advice.detachedHead=false checkout $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
|
else
|
||||||
fmt_warning "won't really checkout in dev mode"
|
fmt_warning "won't really checkout in dev mode"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -219,7 +219,7 @@ install_update(){
|
||||||
cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh"
|
cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh"
|
||||||
chmod +x "${DOTFILES}/update.sh"
|
chmod +x "${DOTFILES}/update.sh"
|
||||||
fmt_note "running update.sh ..."
|
fmt_note "running update.sh ..."
|
||||||
DFS_ENABLE_RET=1 ${DOTFILES}/update.sh
|
DFS_UPDATED_RET=1 ${DOTFILES}/update.sh
|
||||||
if [[ $? == 1 ]]; then
|
if [[ $? == 1 ]]; then
|
||||||
fmt_note "dfs updated. re-running install.sh ..."
|
fmt_note "dfs updated. re-running install.sh ..."
|
||||||
"${DOTFILES}/install.sh" && exit
|
"${DOTFILES}/install.sh" && exit
|
||||||
|
|
Loading…
Reference in New Issue
Block a user