more beacon; use stderr

This commit is contained in:
Dict Xiong 2022-11-27 12:03:50 +08:00
parent 20f60adb5c
commit 64e024d4f8
3 changed files with 25 additions and 17 deletions

View File

@ -12,7 +12,7 @@ cd $DOTFILES
git fetch --all --prune git fetch --all --prune
if [[ -n "$(git status -s)" ]]; then if [[ -n "$(git status -s)" ]]; then
fmt_error "directory not clean" fmt_error "directory not clean"
post_log "ERROR" "$THIS_FILE" "directory not clean" post_beacon "dfs.dirty" 1>/dev/null &
exit exit
fi fi
@ -25,6 +25,7 @@ case $DFS_UPDATE_CHANNEL in
esac esac
if [[ ${#DFS_COMMIT} != 40 ]]; then if [[ ${#DFS_COMMIT} != 40 ]]; then
fmt_error "invalid commit id" fmt_error "invalid commit id"
post_beacon "dfs.invalid-commit" 1>/dev/null &
post_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}" post_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}"
exit exit
fi fi
@ -35,7 +36,7 @@ if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then
else else
fmt_info "checking out to commit $DFS_COMMIT ..." fmt_info "checking out to commit $DFS_COMMIT ..."
if [[ -z "$DFS_DEV" ]]; then if [[ -z "$DFS_DEV" ]]; then
post_beacon "dfs-update" post_beacon "dfs.updated" 1>/dev/null &
git -c advice.detachedHead=false checkout $DFS_COMMIT git -c advice.detachedHead=false checkout $DFS_COMMIT
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET
else else

View File

@ -238,6 +238,7 @@ install(){
install_crontab install_crontab
install_file_content install_file_content
install_symlink install_symlink
post_beacon "dfs.installed" 1>/dev/null &
# those that won't be uninstalled in the future # those that won't be uninstalled in the future
install_tmux_tpm install_tmux_tpm
install_vim_vundle install_vim_vundle
@ -254,6 +255,7 @@ uninstall(){
uninstall_crontab uninstall_crontab
uninstall_file_content uninstall_file_content
uninstall_symlink uninstall_symlink
post_beacon "dfs.uninstalled" 1>/dev/null &
fmt_note "done uninstalling!" fmt_note "done uninstalling!"
} }

View File

@ -43,9 +43,13 @@ post_beacon()
if [[ -z "$beacon_type" ]]; then if [[ -z "$beacon_type" ]]; then
fmt_fatal "beacon type is required" fmt_fatal "beacon type is required"
fi fi
exec 9>&1 resp=$(curl -sSL -X POST "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type")
resp=$(curl -sSL -X POST "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type" | tee >(cat - >&9)) if grep -q "200" <<< "$resp"; then
(grep -q "200" <<< "$resp") || fmt_fatal "error posting beacon" echo $resp
else
echo $resp >&2
fmt_fatal "error posting beacon"
fi
} }
post_log() post_log()
@ -55,17 +59,18 @@ post_log()
fmt_fatal "log content is required" fmt_fatal "log content is required"
fi fi
init_uuid init_uuid
exec 9>&1 resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$1" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid")
resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$1" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid" | tee >(cat - >&9)) if grep -q "200" <<< "$resp"; then
if ! grep -q "200" <<< "$resp"; then echo $resp
if grep -q "403" <<< "$resp"; then elif grep -q "403" <<< "$resp"; then
fmt_error "error posting log: authentification failed" echo $resp >&2
fmt_info "try to register you hostname and uuid" fmt_error "error posting log: authentification failed"
fmt_info "hostname: $hostname" fmt_info "try to register you hostname and uuid"
fmt_info "uuid: $uuid" fmt_info "hostname: $hostname"
else fmt_info "uuid: $uuid"
fmt_fatal "error posting log" else
fi echo $resp >&2
fmt_fatal "error posting log"
fi fi
} }
@ -75,7 +80,7 @@ print_help()
} }
if [[ $# != 2 ]]; then if [[ $# != 2 ]]; then
print_help print_help >&2
exit 1 exit 1
fi fi