summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/home_linux_boards/etc/default/homekit_ipcam_server2
-rwxr-xr-x[-rw-r--r--]misc/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh (renamed from misc/scripts/ipcam_capture_restart.sh)0
-rwxr-xr-x[-rw-r--r--]misc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh (renamed from misc/scripts/ipcam_rtsp2hls_restart.sh)0
-rwxr-xr-x[-rw-r--r--]misc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh (renamed from misc/scripts/make_netns_per_upstream.sh)0
-rwxr-xr-xmisc/home_linux_boards/usr/local/bin/homekit_sunxi_h3_i2c_reset.sh25
-rwxr-xr-xmisc/home_linux_boards/usr/local/bin/homekit_sunxi_setup_amixer.sh114
-rwxr-xr-xmisc/home_linux_boards/usr/local/bin/homekit_sync_recordings_to_remote.sh72
-rw-r--r--misc/mqtt_ca.crt23
-rw-r--r--misc/openwrt/etc/rc.local2
-rwxr-xr-xmisc/remote_server/usr/local/bin/clickhouse_backup.sh31
-rwxr-xr-xmisc/remote_server/usr/local/bin/remove_old_recordings.sh5
11 files changed, 273 insertions, 1 deletions
diff --git a/misc/home_linux_boards/etc/default/homekit_ipcam_server b/misc/home_linux_boards/etc/default/homekit_ipcam_server
new file mode 100644
index 0000000..e5ee2a3
--- /dev/null
+++ b/misc/home_linux_boards/etc/default/homekit_ipcam_server
@@ -0,0 +1,2 @@
+LISTEN="0.0.0.0:8320"
+DATABASE_PATH="/data1/ipcam_server.db" \ No newline at end of file
diff --git a/misc/scripts/ipcam_capture_restart.sh b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh
index 85144da..85144da 100644..100755
--- a/misc/scripts/ipcam_capture_restart.sh
+++ b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh
diff --git a/misc/scripts/ipcam_rtsp2hls_restart.sh b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh
index 61ee623..61ee623 100644..100755
--- a/misc/scripts/ipcam_rtsp2hls_restart.sh
+++ b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh
diff --git a/misc/scripts/make_netns_per_upstream.sh b/misc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh
index fb152fa..fb152fa 100644..100755
--- a/misc/scripts/make_netns_per_upstream.sh
+++ b/misc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh
diff --git a/misc/home_linux_boards/usr/local/bin/homekit_sunxi_h3_i2c_reset.sh b/misc/home_linux_boards/usr/local/bin/homekit_sunxi_h3_i2c_reset.sh
new file mode 100755
index 0000000..e654dfb
--- /dev/null
+++ b/misc/home_linux_boards/usr/local/bin/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/home_linux_boards/usr/local/bin/homekit_sunxi_setup_amixer.sh b/misc/home_linux_boards/usr/local/bin/homekit_sunxi_setup_amixer.sh
new file mode 100755
index 0000000..5746514
--- /dev/null
+++ b/misc/home_linux_boards/usr/local/bin/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/home_linux_boards/usr/local/bin/homekit_sync_recordings_to_remote.sh b/misc/home_linux_boards/usr/local/bin/homekit_sync_recordings_to_remote.sh
new file mode 100755
index 0000000..cf979d1
--- /dev/null
+++ b/misc/home_linux_boards/usr/local/bin/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/mqtt_ca.crt b/misc/mqtt_ca.crt
new file mode 100644
index 0000000..045ae10
--- /dev/null
+++ b/misc/mqtt_ca.crt
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID4zCCAsugAwIBAgIUcW9D2Yym/nNf//Sfv1G8kwpEBCMwDQYJKoZIhvcNAQEL
+BQAwgYAxCzAJBgNVBAYTAlJVMQ8wDQYDVQQIDAZNb3Njb3cxDzANBgNVBAcMBk1v
+c2NvdzEUMBIGA1UECgwLU29sYXJNb24uUlUxFzAVBgNVBAMMDmNhLnNvbGFybW9u
+LnJ1MSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBzb2xhcm1vbi5ydTAeFw0yMTA1MTYx
+NzI2MjRaFw0zMTA1MTQxNzI2MjRaMIGAMQswCQYDVQQGEwJSVTEPMA0GA1UECAwG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-----
diff --git a/misc/openwrt/etc/rc.local b/misc/openwrt/etc/rc.local
index 407d1eb..32b1227 100644
--- a/misc/openwrt/etc/rc.local
+++ b/misc/openwrt/etc/rc.local
@@ -17,7 +17,7 @@ done
sleep 0.1
# block internet access for untrusted cameras
-iptables -I FORWARD 1 -m set --match-set ipcam src ! -d 192.168.5.0 -j REJECT
+iptables -I FORWARD 1 -m set --match-set ipcam src ! -d 192.168.5.0/24 -j REJECT
# add some default routing rules
ipset add mts-azov 192.168.5.0/24 # everybody
diff --git a/misc/remote_server/usr/local/bin/clickhouse_backup.sh b/misc/remote_server/usr/local/bin/clickhouse_backup.sh
new file mode 100755
index 0000000..6e938e4
--- /dev/null
+++ b/misc/remote_server/usr/local/bin/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/remote_server/usr/local/bin/remove_old_recordings.sh b/misc/remote_server/usr/local/bin/remove_old_recordings.sh
new file mode 100755
index 0000000..d376572
--- /dev/null
+++ b/misc/remote_server/usr/local/bin/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