2022-08-14 20:34:18 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-08-26 20:43:00 +08:00
|
|
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
|
|
|
THIS_FILE=$(basename "${BASH_SOURCE}")
|
|
|
|
source "$THIS_DIR/tools/common.sh"
|
|
|
|
|
2022-11-15 22:18:16 +08:00
|
|
|
DFS_UPDATED_RET=${DFS_UPDATED_RET:-0}
|
|
|
|
DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"}
|
|
|
|
|
2023-01-21 15:28:55 +08:00
|
|
|
# send beacon online
|
|
|
|
apost_beacon "sys.online"
|
|
|
|
|
2023-03-01 01:28:53 +08:00
|
|
|
# update dns
|
2023-03-01 16:37:42 +08:00
|
|
|
if [[ "$DFS_DDNS_ENABLE" == "1" ]]; then
|
2023-03-01 01:28:53 +08:00
|
|
|
fmt_info "updating dns ..."
|
|
|
|
"$THIS_DIR/tools/logger.sh" ddns || (fmt_error "failed to update dns" && apost_beacon "dfs.ddns.failed")
|
|
|
|
fi
|
|
|
|
|
2022-08-14 20:34:18 +08:00
|
|
|
# fetch origin
|
|
|
|
cd $DOTFILES
|
2022-12-03 20:37:20 +08:00
|
|
|
git fetch --all --prune
|
2022-08-14 20:34:18 +08:00
|
|
|
if [[ -n "$(git status -s)" ]]; then
|
2022-08-26 20:43:00 +08:00
|
|
|
fmt_error "directory not clean"
|
2022-12-03 20:37:20 +08:00
|
|
|
apost_beacon "dfs.dirty"
|
2022-08-14 20:34:18 +08:00
|
|
|
exit
|
|
|
|
fi
|
2022-11-15 22:18:16 +08:00
|
|
|
|
|
|
|
# get the specified commit id
|
|
|
|
case $DFS_UPDATE_CHANNEL in
|
|
|
|
"main" ) DFS_COMMIT=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;;
|
2022-11-24 20:51:35 +08:00
|
|
|
"dev" ) DFS_COMMIT=$(git rev-parse origin/dev 2> /dev/null) || DFS_COMMIT=$(git rev-parse origin/main) ;;
|
2022-11-15 22:18:16 +08:00
|
|
|
"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"
|
2022-12-03 20:37:20 +08:00
|
|
|
apost_beacon "dfs.invalid-commit"
|
|
|
|
apost_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}"
|
2022-11-15 22:18:16 +08:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-08-14 20:34:18 +08:00
|
|
|
# update
|
2022-11-12 20:05:29 +08:00
|
|
|
if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then
|
2022-08-26 20:43:00 +08:00
|
|
|
fmt_info "nothing to do"
|
2022-08-14 20:34:18 +08:00
|
|
|
else
|
2022-11-12 20:05:29 +08:00
|
|
|
fmt_info "checking out to commit $DFS_COMMIT ..."
|
2023-01-06 16:14:41 +08:00
|
|
|
if [[ -z "$DFS_DEV" || "$DFS_DEV" == "0" ]]; then
|
2022-12-03 20:37:20 +08:00
|
|
|
post_beacon "dfs.updated"
|
2022-11-12 20:05:29 +08:00
|
|
|
git -c advice.detachedHead=false checkout $DFS_COMMIT
|
2022-11-15 22:18:16 +08:00
|
|
|
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET
|
2022-11-05 19:45:21 +08:00
|
|
|
else
|
|
|
|
fmt_warning "won't really checkout in dev mode"
|
|
|
|
fi
|
2022-08-14 20:34:18 +08:00
|
|
|
fi
|