diff options
Diffstat (limited to 'misc/scripts')
-rw-r--r-- | misc/scripts/home_linux_boards/homekit_ipcam_capture_restart.sh (renamed from misc/scripts/ipcam_capture_restart.sh) | 0 | ||||
-rw-r--r-- | misc/scripts/home_linux_boards/homekit_ipcam_rtsp2hls_restart.sh (renamed from misc/scripts/ipcam_rtsp2hls_restart.sh) | 0 | ||||
-rw-r--r-- | misc/scripts/home_linux_boards/homekit_make_netns_per_upstream.sh (renamed from misc/scripts/make_netns_per_upstream.sh) | 0 | ||||
-rw-r--r-- | misc/scripts/home_linux_boards/homekit_sunxi_h3_i2c_reset.sh | 25 | ||||
-rwxr-xr-x | misc/scripts/home_linux_boards/homekit_sunxi_setup_amixer.sh | 114 | ||||
-rwxr-xr-x | misc/scripts/home_linux_boards/homekit_sync_recordings_to_remote.sh | 72 | ||||
-rw-r--r-- | misc/scripts/remote_server/clickhouse_backup.sh | 31 | ||||
-rw-r--r-- | misc/scripts/remote_server/remove_old_recordings.sh | 5 |
8 files changed, 247 insertions, 0 deletions
diff --git a/misc/scripts/ipcam_capture_restart.sh b/misc/scripts/home_linux_boards/homekit_ipcam_capture_restart.sh index 85144da..85144da 100644 --- a/misc/scripts/ipcam_capture_restart.sh +++ b/misc/scripts/home_linux_boards/homekit_ipcam_capture_restart.sh diff --git a/misc/scripts/ipcam_rtsp2hls_restart.sh b/misc/scripts/home_linux_boards/homekit_ipcam_rtsp2hls_restart.sh index 61ee623..61ee623 100644 --- a/misc/scripts/ipcam_rtsp2hls_restart.sh +++ b/misc/scripts/home_linux_boards/homekit_ipcam_rtsp2hls_restart.sh diff --git a/misc/scripts/make_netns_per_upstream.sh b/misc/scripts/home_linux_boards/homekit_make_netns_per_upstream.sh index fb152fa..fb152fa 100644 --- a/misc/scripts/make_netns_per_upstream.sh +++ b/misc/scripts/home_linux_boards/homekit_make_netns_per_upstream.sh diff --git a/misc/scripts/home_linux_boards/homekit_sunxi_h3_i2c_reset.sh b/misc/scripts/home_linux_boards/homekit_sunxi_h3_i2c_reset.sh new file mode 100644 index 0000000..e654dfb --- /dev/null +++ b/misc/scripts/home_linux_boards/homekit_sunxi_h3_i2c_reset.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +devices="1c2ac00.i2c 1c2b000.i2c" +pins="8 9 28 30" +driver_path="/sys/bus/platform/drivers/mv64xxx_i2c" + +driver_unbind() { + echo -n "$1" > "$driver_path/unbind" +} + +driver_bind() { + echo -n "$1" > "$driver_path/bind" +} + +for dev in $devices; do driver_unbind "$dev"; done +echo "unbind done" + +for pin in pins; do + gpio mode $pin out + gpio write $pin 0 +done +echo "gpio reset done" + +for dev in $devices; do driver_bind "$dev"; done +echo "bind done"
\ No newline at end of file diff --git a/misc/scripts/home_linux_boards/homekit_sunxi_setup_amixer.sh b/misc/scripts/home_linux_boards/homekit_sunxi_setup_amixer.sh new file mode 100755 index 0000000..5746514 --- /dev/null +++ b/misc/scripts/home_linux_boards/homekit_sunxi_setup_amixer.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +amixer() { + /usr/bin/amixer "$@" +} + +setup_opi_pc2() { + for v in unmute cap; do + amixer set "Line In" $v + amixer set "Mic1" $v + amixer set "Mic2" $v + done + + for k in "Mic1 Boost" "Line In" "Mic1" "Mic2 Boost" "Mic2"; do + amixer set "$k" "86%" + done +} + +setup_opi_one() { + for v in unmute cap; do + amixer set "Line In" $v + amixer set "Mic1" $v + done + + for k in "Mic1 Boost" "Line In" "Mic1"; do + amixer set "$k" "86%" + done +} + +setup_opi3lts() { + switches=( + "Left DAC Mixer ADCL" + "Left DAC Mixer I2SDACL" + "Left I2S Mixer ADCL" + "Left I2S Mixer I2SDACL" + "Left Input Mixer LINEINL" + "Left Input Mixer MIC1" + "Left Input Mixer MIC2" + "Left Input Mixer OMixerL" + "Left Input Mixer OMixerR" + "Left Input Mixer PhoneN" + "Left Input Mixer PhonePN" + "Left Output Mixer DACL" + "Left Output Mixer DACR" + "Left Output Mixer LINEINL" + "Left Output Mixer MIC1" + "Left Output Mixer MIC2" + "Left Output Mixer PhoneN" + "Left Output Mixer PhonePN" + "Right DAC Mixer ADCR" + "Right DAC Mixer I2SDACR" + "Right I2S Mixer ADCR" + "Right I2S Mixer I2SDACR" + "Right Input Mixer LINEINR" + "Right Input Mixer MIC1" + "Right Input Mixer MIC2" + "Right Input Mixer OMixerL" + "Right Input Mixer OMixerR" + "Right Input Mixer PhoneP" + "Right Input Mixer PhonePN" + "Right Output Mixer DACL" + "Right Output Mixer DACR" + "Right Output Mixer LINEINR" + "Right Output Mixer MIC1" + "Right Output Mixer MIC2" + "Right Output Mixer PhoneP" + "Right Output Mixer PhonePN" + ) + for v in "${switches[@]}"; do + value=on + case "$v" in + *Input*) + value=on + ;; + *Output*) + value=off + ;; + esac + amixer set "$v" $value + done + + to_mute=( + "I2S Mixer ADC" + "I2S Mixer DAC" + "ADC Input" + "DAC Mixer ADC" + "DAC Mxier DAC" # this is not a typo + ) + for v in "${to_mute[@]}"; do + amixer set "$v" "0%" + done + + amixer set "Master" "100%" + amixer set "MIC1 Boost" "100%" + amixer set "MIC2 Boost" "100%" + amixer set "Line Out Mixer" "86%" + amixer set "MIC Out Mixer" "71%" +} + +device="$(tr -d '\0' < /sys/firmware/devicetree/base/model)" +case "$device" in + *"Orange Pi PC 2") + setup_opi_pc2 + ;; + *"Orange Pi One"|*"Orange Pi Lite") + setup_opi_one + ;; + *"OrangePi 3 LTS") + setup_opi3lts + ;; + *) + >&2 echo "error: unidentified device: $device" + ;; +esac diff --git a/misc/scripts/home_linux_boards/homekit_sync_recordings_to_remote.sh b/misc/scripts/home_linux_boards/homekit_sync_recordings_to_remote.sh new file mode 100755 index 0000000..cf979d1 --- /dev/null +++ b/misc/scripts/home_linux_boards/homekit_sync_recordings_to_remote.sh @@ -0,0 +1,72 @@ +#!/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 diff --git a/misc/scripts/remote_server/clickhouse_backup.sh b/misc/scripts/remote_server/clickhouse_backup.sh new file mode 100644 index 0000000..6e938e4 --- /dev/null +++ b/misc/scripts/remote_server/clickhouse_backup.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +DIR=/var/lib/clickhouse/backup +MAX_COUNT=3 +NAME=backup_$(date -u +%Y-%m-%d) + +create() { + local name="$1" + clickhouse-backup create "$name" +} + +del() { + local name="$1" + clickhouse-backup delete local "$name" +} + +# create a backup +create "$NAME" + +# compress backup +cd "$DIR" +tar czvf $NAME.tar.gz $NAME + +# delete uncompressed files +del "$NAME" + +# delete old backups +for file in $(ls -t "${DIR}" | tail -n +$(( MAX_COUNT+1 ))); do + echo "removing $file..." + rm "$file" +done
\ No newline at end of file diff --git a/misc/scripts/remote_server/remove_old_recordings.sh b/misc/scripts/remote_server/remove_old_recordings.sh new file mode 100644 index 0000000..d376572 --- /dev/null +++ b/misc/scripts/remote_server/remove_old_recordings.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# to be launched by cron on remote server + +find /var/recordings -type f -mtime +14 -delete |