install.sh: rerun when updated (#25)

* install.sh: rerun when updated

* update ci
This commit is contained in:
Dict Xiong 2022-11-12 20:05:29 +08:00 committed by GitHub
parent 9a7f0b1b06
commit 995899f3a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -3,12 +3,13 @@
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 # get the specified commit id
dfs_commit=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id) DFS_COMMIT=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id)
if [[ ${#dfs_commit} != 40 ]]; then if [[ ${#DFS_COMMIT} != 40 ]]; then
fmt_error "invalid commit id" 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 exit
fi fi
# fetch origin # fetch origin
@ -20,16 +21,16 @@ if [[ -n "$(git status -s)" ]]; then
exit exit
fi 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"
post_log "INFO" "$THIS_FILE" "nothing to do" post_log "INFO" "$THIS_FILE" "nothing to do"
else else
fmt_info "checking out to commit $dfs_commit ..." fmt_info "checking out to commit $DFS_COMMIT ..."
if [[ -z "$DFS_DEV" ]]; then 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 else
fmt_warning "won't really checkout in dev mode" fmt_warning "won't really checkout in dev mode"
fi fi
post_log "INFO" "$THIS_FILE" "will check out to commit $dfs_commit"
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit
fi fi

View File

@ -219,7 +219,11 @@ 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 ..."
${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(){ uninstall_update(){
@ -228,8 +232,8 @@ uninstall_update(){
} }
install(){ install(){
preinstall_check
install_update install_update
preinstall_check
install_crontab install_crontab
install_file_content install_file_content
install_symlink install_symlink

View File

@ -34,6 +34,14 @@ dfs version
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id` test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`
# clean # clean
dfs cd
git reset --hard $DFS_VERSION git reset --hard $DFS_VERSION
# then check install.sh
./install.sh -l
dfs version
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`
# clean
git reset --hard $DFS_VERSION
set +x set +x