dotfiles/.update.sh
Dict Xiong 995899f3a3
install.sh: rerun when updated (#25)
* install.sh: rerun when updated

* update ci
2022-11-12 20:05:29 +08:00

37 lines
1.1 KiB
Bash

#!/bin/bash
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
# fetch origin
cd $DOTFILES
git fetch --all
if [[ -n "$(git status -s)" ]]; then
fmt_error "directory not clean"
post_log "ERROR" "$THIS_FILE" "directory not clean"
exit
fi
# update
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 ..."
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
else
fmt_warning "won't really checkout in dev mode"
fi
fi