summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2019-01-11 04:23:31 +0000
committerMike Crute <mike@crute.us>2019-01-11 04:23:31 +0000
commit769043aa828524c14116023597755959ce8697b7 (patch)
tree6c9586752f998f481b9b0c82b4ee80ed37003dc0
parentc65de179509081e5010e86212f15ec34d238f74b (diff)
downloadmfi_homekit-769043aa828524c14116023597755959ce8697b7.tar.bz2
mfi_homekit-769043aa828524c14116023597755959ce8697b7.tar.xz
mfi_homekit-769043aa828524c14116023597755959ce8697b7.zip
Don't corrupt output, cleanup procs
-rw-r--r--cleanup_processes.sh11
-rwxr-xr-xpower_control.sh37
2 files changed, 35 insertions, 13 deletions
diff --git a/cleanup_processes.sh b/cleanup_processes.sh
deleted file mode 100644
index 144a01f..0000000
--- a/cleanup_processes.sh
+++ /dev/null
@@ -1,11 +0,0 @@
1#!/bin/sh
2
3sed -i -e '/ubnt-websockets/s/^/#/' -e '/telnetd/s/^/#/' -e '/mca[-d]/s/^/#/' -e '/lighttpd/s/^/#/' /etc/inittab
4kill -HUP 1
5pkill -9 ubnt-websockets
6pkill -9 lighttpd
7pkill upnpd
8pkill telnetd
9pkill mca-monitor
10pkill mcad
11pkill avahi-daemon
diff --git a/power_control.sh b/power_control.sh
index c64a235..a3d9d88 100755
--- a/power_control.sh
+++ b/power_control.sh
@@ -41,17 +41,47 @@ report() {
41 echo -e "\t\t\"output\": $i," 41 echo -e "\t\t\"output\": $i,"
42 echo -e "\t\t\"engaged\": $state," 42 echo -e "\t\t\"engaged\": $state,"
43 echo -e "\t\t\"active_power\": $2," 43 echo -e "\t\t\"active_power\": $2,"
44 echo -e "\t\t\"energy_sum\": $6)," 44 echo -e "\t\t\"energy_sum\": $6,"
45 echo -e "\t\t\"current_rms\": $3," 45 echo -e "\t\t\"current_rms\": $3,"
46 echo -e "\t\t\"voltage_rms\": $4," 46 echo -e "\t\t\"voltage_rms\": $4,"
47 echo -e "\t\t\"power_factor\": $5" 47 echo -e "\t\t\"power_factor\": $5"
48 echo -en "\t}" 48 echo -en "\t}"
49 49
50 [ $i -eq $NUM_OUTPUTS ] && echo -e "," 50 [ $i -ne $NUM_OUTPUTS ] && echo -e ","
51 done 51 done
52 echo "]" 52 echo "]"
53} 53}
54 54
55disable_junk_processes() {
56 # Otherwise init will continue to respawn them
57 sed -i \
58 -e '/ubnt-websockets/s/^/#/' \
59 -e '/telnetd/s/^/#/' \
60 -e '/mca[-d]/s/^/#/' \
61 -e '/lighttpd/s/^/#/' \
62 /etc/inittab
63
64 kill -HUP 1
65
66 # Most of these kill cleanly but a few are stubborn so don't ask, tell.
67 pkill -9 ubnt-websockets
68 pkill -9 lighttpd
69 pkill upnpd
70 pkill telnetd
71 pkill mca-monitor
72 pkill mcad
73 pkill avahi-daemon
74}
75
76disable_blinking() {
77 echo 0 > /proc/led/freq
78 echo 1 > /proc/led/status
79}
80
81if ! grep -E '^#.*mcad$' /etc/inittab 2>&1 > /dev/null; then
82 disable_junk_processes
83 disable_blinking
84fi
55 85
56case $1 in 86case $1 in
57 on) 87 on)
@@ -70,6 +100,9 @@ case $1 in
70 clear) 100 clear)
71 clear_all 101 clear_all
72 ;; 102 ;;
103 disable_blinking)
104 disable_blinking
105 ;;
73 *) 106 *)
74 error "Invalid command" 107 error "Invalid command"
75 ;; 108 ;;