diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-09-27 00:54:57 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-09-27 00:54:57 +0300 |
commit | d3a295872c49defb55fc8e4e43e55550991e0927 (patch) | |
tree | b9dca15454f9027d5a9dad0d4443a20de04dbc5d /tools/sync-recordings-to-remote.sh | |
parent | b7cbc2571c1870b4582ead45277d0aa7f961bec8 (diff) | |
parent | bdbb296697f55f4c3a07af43c9aaf7a9ea86f3d0 (diff) |
Merge branch 'master' of ch1p.io:homekit
Diffstat (limited to 'tools/sync-recordings-to-remote.sh')
-rwxr-xr-x | tools/sync-recordings-to-remote.sh | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/tools/sync-recordings-to-remote.sh b/tools/sync-recordings-to-remote.sh deleted file mode 100755 index cf979d1..0000000 --- a/tools/sync-recordings-to-remote.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash - -PROGNAME="$0" -NODE_CONFIG="/etc/sound_node.toml" -REMOTE_USER=user -REMOTE_SERVER=solarmon.ru -REMOTE_DIRECTORY=/var/recordings - -set -e - -echoerr() { - >&2 echo "error: $@" -} - -echowarn() { - >&2 echo "warning: $@" -} - -telegram_alert() { - if [ -z "$TG_TOKEN" ] || [ -z "$TG_CHAT_ID" ]; then return; fi - curl -X POST \ - -F "chat_id=${TG_CHAT_ID}" \ - -F "text=$1" \ - "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" -} - -fatal() { - echoerr "$@" - telegram_alert "$PROGNAME: $@" - exit 1 -} - -get_config_var() { - local varname="$1" - cat "$NODE_CONFIG" | grep "^$varname = \"" | awk '{print $3}' | tr -d '"' -} - -get_mp3_count() { - find "$LOCAL_DIR" -mindepth 1 -type f -name "*.mp3" -printf x | wc -c -} - -[ -z "$TG_TOKEN" ] && echowarn "TG_TOKEN is not set" -[ -z "$TG_CHAT_ID" ] && echowarn "TG_CHAT_ID is not set" - -NODE_NAME=$(get_config_var name) -LOCAL_DIR=$(get_config_var storage) - -[ -z "$NODE_NAME" ] && fatal "failed to parse NODE_NAME" -[ -z "$LOCAL_DIR" ] && fatal "failed to parse LOCAL_DIR" - -[ -d "$LOCAL_DIR" ] || fatal "$LOCAL_DIR is not a directory" - -COUNT=$(get_mp3_count) -(( $COUNT < 1 )) && { - echo "seems there's nothing to sync" - exit -} - -cd "$LOCAL_DIR" || fatal "failed to change to $LOCAL_DIR" - -rsync -azPv -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR" \ - *.mp3 \ - ${REMOTE_USER}@${REMOTE_SERVER}:"${REMOTE_DIRECTORY}/${NODE_NAME}/" \ - --exclude temp.mp3 - -RC=$? - -if [ $RC -eq 0 ]; then - find "$LOCAL_DIR" -name "*.mp3" -type f -mmin +1440 -delete || fatal "find failed to delete old files" -else - fatal "failed to rsync: code $RC" -fi |