dotfiles/.update.sh
Dict Xiong 8fdd3c477f
[dev] ddns; better ssh agent; riot sshl; sys.online; zsh hist import; DFS_DEBUG; cbd/cbds (#36)
* riot: bj1 -> proxy

* ci: test ask_for_yn

* --wip-- [skip ci]

* install.sh: will prompt version

* zshrc: piv-agent now can re-use agents

* zshrc: in docker use theme robbyrussell

* update.sh: will send online beacon

* beacon: support meta with limited len 64

* bug fix (Sat Jan 21 16:45:35 CST 2023)

* well, finally add ssh key for ltp1-bd

* set DFS_INITED and do not send login beacon if it was set

* rewrite piv-agent to sagent; fmt_note and fmt_into will write to stderr

* bug fix (Mon Jan 30 19:41:00 CST 2023)

* bug fix (Mon Jan 30 19:46:27 CST 2023)

* login beacon add details

* $DFS_ORPHAN turns logger off

* disable more beacons in CI

* install.sh: prepare config earlier

* init pbin

* install.sh: -H|--hist|--history

* install.sh: -H hint

* install.sh: -H support multiple keys

* fix zsh hist with no new line at the end

* remove ^M in hist

* bug fix (Wed Feb  1 21:11:41 CST 2023)

* bug fix (Wed Feb  1 21:16:29 CST 2023)

* bug fix (Wed Feb  1 21:20:21 CST 2023)

* ci will send gh.ci.fail

* show install opts

* DFS_DEBUG to set -x

* bug fix: install.sh re-start itself with no args incorrectly

* bug fix (Thu Feb  2 18:43:16 CST 2023)

* riot: ob->ebd, swap option $1 and $2 and $2 is default to ssh

* riot: introduce sshl

* logger.sh: support ddns

* bug fix (Wed Mar  1 16:37:42 CST 2023)

* dfs.ddns.failed -> dfs.ddns.fail

* login beacon 2>/dev/null

* logger.sh -> frigg-client.sh; curl add time limit 10s

* to-install.sh: improve docker-ce

* use $DFS_CURL_OPTIONS

* ci: add ddns

* bug fix (Wed Mar 15 19:37:21 CST 2023)

* Revert "bug fix (Wed Mar 15 19:37:21 CST 2023)"

This reverts commit 2df87ce1a8.

* Revert "ci: add ddns"

This reverts commit 4fe8321504.

* alias cbd and cbds, riot nasp port to 12022

* .zshrc: sagent -> sagt

* fix ci

* riot: bug fix when 'tmp' has leading zeros

* add ci for cbds

---------

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2023-04-21 12:37:05 +08:00

55 lines
1.8 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_UPDATED_RET=${DFS_UPDATED_RET:-0}
DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"}
# send beacon online
apost_beacon "sys.online"
# update dns
if [[ "$DFS_DDNS_ENABLE" == "1" ]]; then
fmt_info "updating dns ..."
"$THIS_DIR/tools/frigg-client.sh" ddns || (fmt_error "failed to update dns" && apost_beacon "dfs.ddns.fail")
fi
# fetch origin
cd $DOTFILES
git fetch --all --prune
if [[ -n "$(git status -s)" ]]; then
fmt_error "directory not clean"
apost_beacon "dfs.dirty"
exit
fi
# get the specified commit id
case $DFS_UPDATE_CHANNEL in
"main" ) DFS_COMMIT=$(curl $DFS_CURL_OPTIONS -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;;
"dev" ) DFS_COMMIT=$(git rev-parse origin/dev 2> /dev/null) || DFS_COMMIT=$(git rev-parse origin/main) ;;
"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"
apost_beacon "dfs.invalid-commit"
apost_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"
else
fmt_info "checking out to commit $DFS_COMMIT ..."
if [[ -z "$DFS_DEV" || "$DFS_DEV" == "0" ]]; then
post_beacon "dfs.updated"
git -c advice.detachedHead=false checkout $DFS_COMMIT
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET
else
fmt_warning "won't really checkout in dev mode"
fi
fi