struct: standard file structure (#11)

* mass change. staged, not tested

* still mass changed without test

* bug fix

* bug fix
This commit is contained in:
2022-08-26 20:43:00 +08:00
committed by GitHub
parent f313a6887e
commit 8782121dcc
9 changed files with 220 additions and 201 deletions

View File

@@ -1,29 +1,32 @@
#!/bin/bash
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
THIS_FILE=$(basename "${BASH_SOURCE}")
source "$THIS_DIR/tools/common.sh"
# get the specified commit id
dfs_commit=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id)
if [[ ${#dfs_commit} != 40 ]]; then
echo "Error: invalid commit id."
python3 "${DOTFILES}/tools/post-log.py" "[ERROR] update.sh: invalid commit id: ${dfs_commit}"
fmt_error "invalid commit id"
post_log "ERROR" "$THIS_FILE" "invalid commit id: ${dfs_commit}"
exit
fi
# fetch origin
cd $DOTFILES
git fetch
if [[ -n "$(git status -s)" ]]; then
echo "Error: directory not clean."
python3 "${DOTFILES}/tools/post-log.py" "[ERROR] update.sh: directory not clean"
fmt_error "directory not clean"
post_log "ERROR" "$THIS_FILE" "directory not clean"
exit
fi
# update
if [[ "$(git rev-parse HEAD)" == "$dfs_commit" ]]; then
echo "Nothing to do."
python3 "${DOTFILES}/tools/post-log.py" "[INFO] update.sh: Nothing to do"
fmt_info "nothing to do"
post_log "INFO" "$THIS_FILE" "nothing to do"
else
echo "Checking out to commit $dfs_commit ..."
fmt_info "checking out to commit $dfs_commit ..."
git -c advice.detachedHead=false checkout $dfs_commit
cp ./.update.sh ./update.sh
chmod +x ./update.sh
python3 "${DOTFILES}/tools/post-log.py" "[INFO] update.sh: Checked out to commit $dfs_commit"
post_log "INFO" "$THIS_FILE" "checked out to commit $dfs_commit"
fi