forked from macnow/homebridge-raspbian-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·179 lines (166 loc) · 4.6 KB
/
configure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
LINES=$(tput lines)
COLS=$(tput cols)
function menu_main()
{
unset CMD
unset OPTIONS
unset CHOICE
CMD=(dialog \
--title "Homebridge configuration tool" \
--backtitle "Homebridge configuration tool by @macnow" \
--keep-tite \
--no-cancel \
--menu "Select options:" \
12 50 17)
OPTIONS=(M "Manage Plugins"
C "Configuration Editor"
R "Restart Homebridge"
Q "Quit")
CHOICE=$("${CMD[@]}" "${OPTIONS[@]}" 3>&1 1>&2 2>&3 3>&-)
case $CHOICE in
M) menu_plugins;;
C) menu_configure;;
R) menu_restart;;
Q) menu_end;;
esac
}
function menu_configure()
{
unset CMD
unset OPTIONS
unset CHOICE
CHOICE=$("dialog \
--title "/var/homebridge/config.json" \
--backtitle "Homebridge configuration tool by @macnow - Configuration Editor" \
--stdout \
--ok-label Save \
--editbox /var/homebridge/config.json \
$((LINES-10)) $((COLS-5))" 3>&1 1>&2 2>&3 3>&-)
case $CHOICE in
0) echo $CHOICE|json -4 > /tmp/config.json$$
JSON_OUTPUT=$?
if [[ $JSON_OUTPUT -eq 0 ]]
then
sudo mv -f /tmp/config.json$$ /var/homebridge/config.json
sudo chown homebridge:homebridge /var/homebridge/config.json
dialog \
--title "Homebridge configure" \
--backtitle "Homebridge configurator" \
--stdout \
--msgbox "Configuration saved!" \
5 50
else
dialog \
--title "Homebridge configure" \
--backtitle "Homebridge configurator" \
--stdout \
--msgbox "ERROR: Configuration not saved!" \
5 50
fi
;;
esac
menu_main
}
function menu_plugins()
{
unset CMD
unset OPTIONS
unset CHOICE
unset FILES
CMD=(dialog \
--title "Homebridge configuration tool" \
--backtitle "Homebridge configuration tool by @macnow - Plugins Installer" \
--keep-tite \
--menu "Select options:" \
13 50 17)
FILES=configs/homebridge-*
c=0
for f in $FILES
do
FILE=${f#'configs/'}
OPTIONS+=($((++c)) ${FILE%'.json'})
done
OPTIONS+=(B "Back")
CHOICE=$("${CMD[@]}" "${OPTIONS[@]}" 3>&1 1>&2 2>&3 3>&-)
case $CHOICE in
B) menu_main;;
*) if [[ $CHOICE -eq 1 ]]; then
menu_plugin ${OPTIONS[$CHOICE]}
else
menu_plugin ${OPTIONS[2*$CHOICE-1]}
fi;;
esac
}
function menu_plugin()
{
unset CMD
unset OPTIONS
unset CHOICE
CMD=(dialog
--title "Homebridge configuration tool" \
--backtitle "Homebridge configuration tool by @macnow - Plugins Installer - $1" \
--keep-tite \
--no-cancel \
--menu "Select options:" \
12 50 17)
OPTIONS=(I "Install Plugin"
U "Update Plugin"
B "Back")
CHOICE=$("${CMD[@]}" "${OPTIONS[@]}" 3>&1 1>&2 2>&3 3>&-)
case $CHOICE in
I) dialog \
--title "$1" \
--backtitle "Homebridge configuration tool by @macnow - Plugins Installer - $1" \
--stdout \
--infobox "Installing plugin...\nThis may take several minutes." \
4 50
sudo npm install -g $1
scripts/config-merge.py /var/homebridge/config.json configs/$1.json > /tmp/config.json$$
sudo mv -f /tmp/config.json$$ /var/homebridge/config.json
sudo chown homebridge:homebridge /var/homebridge/config.json
dialog \
--title "$1" \
--backtitle "Homebridge configuration tool by @macnow - Plugins Installer - $1" \
--stdout \
--msgbox "$1 plugin installed." \
5 50;;
U) dialog \
--title "$1" \
--backtitle "Homebridge configuration tool by @macnow - Plugins Installer - $1" \
--stdout \
--infobox "Updating plugin...\nThis may take several minutes..." \
4 50
sudo npm update -g $1
dialog \
--title "$1" \
--backtitle "Homebridge configuration tool by @macnow - Plugins Installer - $1" \
--stdout \
--msgbox "$1 plugin updated." \
5 50;;
B) ;;
esac
menu_plugins
}
function menu_restart()
{
dialog \
--title "Homebridge configuration tool" \
--backtitle "Homebridge configuration tool by @macnow - Restart" \
--stdout \
--infobox "Homebridge is restarting now!\nThis may take several minutes." \
4 50
sudo systemctl restart homebridge
sleep 3s
menu_main
}
function menu_end()
{
dialog \
--title "Homebridge configuration tool" \
--backtitle "Homebridge configuration tool by @macnow" \
--stdout \
--infobox "Thanks for using.\nFollow me on Twitter: @macnow" \
4 50
}
menu_main