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

View File

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

View File

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