diff --git a/.update.sh b/.update.sh index 47c09fa..0a6566b 100644 --- a/.update.sh +++ b/.update.sh @@ -3,15 +3,10 @@ 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 +DFS_UPDATED_RET=${DFS_UPDATED_RET:-0} +DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"} + # fetch origin cd $DOTFILES git fetch --all @@ -20,6 +15,19 @@ if [[ -n "$(git status -s)" ]]; then post_log "ERROR" "$THIS_FILE" "directory not clean" exit 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 if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then fmt_info "nothing to do" @@ -29,7 +37,7 @@ else 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 + cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET else fmt_warning "won't really checkout in dev mode" fi diff --git a/.zshrc2 b/.zshrc2 index 5ad32e4..4db1ef9 100644 --- a/.zshrc2 +++ b/.zshrc2 @@ -88,23 +88,27 @@ alias "se"='sudo -sE' alias "pbd"='ping baidu.com' alias "p114"='ping 114.114.114.114' alias "p666"='ping6 2001:da8::666' +alias "git-branches"='git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset)) %(authorname)"' sibd() { ssh -p 12022 root@$1${1:+.}ibd.ink } sob() { ssh -p 24022 root@$1${1:+.}ob.ac.cn } +snasp() { ssh -o ProxyJump="ssh@nasp.ob.ac.cn:36022" dictxiong@$1 } case $(bash "$DOTFILES/tools/common.sh" get_os_type) in macos ) alias l='ls -lAGh -D "%y-%m-%d %H:%M"' ;; * ) alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"' ;; esac piv-agent() { + eval $(ssh-agent -k) # they are: ubuntu, macos, respectively local SO_PATHS=( "/usr/lib64/opensc-pkcs11.so" "/usr/local/lib/opensc-pkcs11.so" ) for i in ${SO_PATHS[*]}; do if [[ -f "$i" ]]; then + echo "using: $i" eval $(ssh-agent -P "$i") ssh-add -s "$i" echo "now available keys:" ssh-add -l - break + return 0 fi done echo "opensc-pkcs11.so not found" diff --git a/install.sh b/install.sh index f7e7ad5..e94d4d2 100755 --- a/install.sh +++ b/install.sh @@ -219,7 +219,7 @@ install_update(){ cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh" chmod +x "${DOTFILES}/update.sh" fmt_note "running update.sh ..." - DFS_ENABLE_RET=1 ${DOTFILES}/update.sh + DFS_UPDATED_RET=1 ${DOTFILES}/update.sh if [[ $? == 1 ]]; then fmt_note "dfs updated. re-running install.sh ..." "${DOTFILES}/install.sh" && exit diff --git a/scripts/dogo b/scripts/dogo index 44ffe34..2c2c6c3 100755 --- a/scripts/dogo +++ b/scripts/dogo @@ -26,5 +26,5 @@ if [[ -z "$CONTAINER" ]]; then fmt_fatal "container not found" else echo "--> ${CONTAINER_META[@]}" - $SUDO docker exec -it $CONTAINER sh -c 'if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi' + $SUDO docker exec -it $CONTAINER sh -c 'export DFS="bash <(curl dfs.beardic.cn) -a"; if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; unset DFS; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi' fi diff --git a/scripts/doll b/scripts/doll index c13308e..2fb7c91 100755 --- a/scripts/doll +++ b/scripts/doll @@ -21,5 +21,5 @@ if [[ -z "$IMAGE" ]]; then fmt_fatal "image not found" else echo "--> ${IMAGE_META[@]}" - $SUDO docker run -itd $IMAGE sh + $SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh fi diff --git a/tools/test.zsh b/tools/test.zsh index 19024b8..381f039 100644 --- a/tools/test.zsh +++ b/tools/test.zsh @@ -29,6 +29,7 @@ tools/common.sh get_linux_dist alias p114 sibd || which sibd piv-agent || which piv-agent +git-branches || which git-branches # check update DFS_VERSION=`dfs version`