summaryrefslogtreecommitdiff
path: root/misc/home_linux_boards
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-09-27 00:54:57 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-09-27 00:54:57 +0300
commitd3a295872c49defb55fc8e4e43e55550991e0927 (patch)
treeb9dca15454f9027d5a9dad0d4443a20de04dbc5d /misc/home_linux_boards
parentb7cbc2571c1870b4582ead45277d0aa7f961bec8 (diff)
parentbdbb296697f55f4c3a07af43c9aaf7a9ea86f3d0 (diff)
Merge branch 'master' of ch1p.io:homekit
Diffstat (limited to 'misc/home_linux_boards')
-rw-r--r--misc/home_linux_boards/etc/default/homekit_ipcam_server2
-rwxr-xr-xmisc/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh7
-rwxr-xr-xmisc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh8
-rwxr-xr-xmisc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh38
-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
7 files changed, 266 insertions, 0 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/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh
new file mode 100755
index 0000000..85144da
--- /dev/null
+++ b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_capture_restart.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+for f in $(ls /etc/ipcam_capture.conf.d/ | xargs); do
+ camera="${f/.conf/}"
+ echo "restarting $camera"
+ systemctl restart ipcam_capture@${camera}
+done \ No newline at end of file
diff --git a/misc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh
new file mode 100755
index 0000000..61ee623
--- /dev/null
+++ b/misc/home_linux_boards/usr/local/bin/homekit_ipcam_rtsp2hls_restart.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+cd /etc/ipcam_rtsp2hls.conf.d/
+for f in *-low.conf; do
+ f=${f/-low.conf/}
+ echo "restarting $f"
+ systemctl restart ipcam_rtsp2hls@${f}
+ systemctl restart ipcam_rtsp2hls@${f}-low
+done
diff --git a/misc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh b/misc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh
new file mode 100755
index 0000000..fb152fa
--- /dev/null
+++ b/misc/home_linux_boards/usr/local/bin/homekit_make_netns_per_upstream.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+set -x
+set -e
+
+get_default_iface() {
+ ip -4 r show default | awk '{print $5}'
+}
+
+declare -A UPSTREAMS=(
+ [mtsil]=102
+ [mtsazov]=100
+ [rtazov]=101
+)
+
+for name in "${!UPSTREAMS[@]}"; do
+ mark=${UPSTREAMS[$name]}
+ veth_addr=10.${mark}.1.1
+ vpeer_addr=10.${mark}.1.2
+ veth_if=veth${name}
+ vpeer_if=vpeer${name}
+
+ ip netns add $name
+ ip link add $veth_if type veth peer name $vpeer_if
+ ip link set $vpeer_if netns $name
+ ip addr add $veth_addr/24 dev $veth_if
+ ip link set $veth_if up
+
+ ip netns exec $name ip addr add $vpeer_addr/24 dev $vpeer_if
+ ip netns exec $name ip link set $vpeer_if up
+ ip netns exec $name ip link set lo up
+ ip netns exec $name ip route add default via $veth_addr
+
+ iptables -t mangle -A PREROUTING -s $vpeer_addr/24 -j MARK --set-mark $mark
+ iptables -t nat -A POSTROUTING -s $vpeer_addr/24 -o "$(get_default_iface)" -j MASQUERADE
+done
+
+sysctl net.ipv4.ip_forward=1
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