-
Notifications
You must be signed in to change notification settings - Fork 41
/
menu.sh
274 lines (255 loc) · 6.49 KB
/
menu.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
source $SCRIPTDIR/prepare.sh
white=$(echo -en "\e[39m")
green=$(echo -en "\e[92m")
red=$(echo -en "\e[91m")
magenta=$(echo -en "\e[35m")
cyan=$(echo -en "\e[96m")
yellow=$(echo -en "\e[93m")
main_menu() {
VERSION=1.0.11
#reset
UDEV=''
TEMPUSB=''
CAM=''
TEMPUSBCAM=''
INSTANCE=''
INSTALL=''
CAMHAPROXY=''
echo
echo
echo "${cyan}*************************${white}"
echo "${green}octoprint_deploy${white} $VERSION"
echo "${cyan}*************************${white}"
echo
PS3="${green}Select operation: ${white}"
if [ -f "/etc/octoprint_deploy" ]; then
options=("Add instance" "Delete instance" "Add USB Camera" "Add PiCam" "Delete Camera" "Utilities" "Backup Menu" "Update" "Quit")
else
options=("Prepare system" "Update" "Quit")
fi
select opt in "${options[@]}"
do
case $opt in
"Prepare system")
detect_installs
break
;;
"Add instance")
new_instance
break
;;
"Delete instance")
remove_instance_menu
break
;;
"Add USB Camera")
add_camera
break
;;
"Add PiCam")
add_camera true
break
;;
"Delete Camera")
remove_camera_menu
break
;;
"Utilities")
utility_menu
break
;;
"Backup Menu")
backup_menu
break
;;
"Update")
octo_deploy_update
break
;;
"Quit")
exit 1
;;
*) echo "invalid option $REPLY";;
esac
done
}
remove_instance_menu() {
echo
echo
get_settings
if [ $SUDO_USER ]; then user=$SUDO_USER; fi
if [ -f "/etc/octoprint_instances" ]; then
PS3="${green}Select instance number to remove: ${white}"
get_instances true
select opt in "${INSTANCE_ARR[@]}"
do
if [ "$opt" == Quit ]; then
main_menu
fi
echo "Selected instance to remove: $opt"
break
done
if prompt_confirm "Do you want to remove everything associated with this instance?"; then
remove_instance $opt
fi
fi
main_menu
}
remove_camera_menu() {
get_settings
PS3="${green}Select camera number to remove: ${white}"
get_cameras true
select camera in "${CAMERA_ARR[@]}"
do
if [ "$camera" == Quit ]; then
main_menu
fi
echo "Removing udev, service files, and haproxy entry for $camera"
remove_camera $camera
main_menu
done
}
utility_menu() {
echo
echo
PS3="${green}Select an option: ${white}"
options=("Instance Status" "USB Port Testing" "Sync Users" "Share Uploads" "Change Streamer" "Set Global Config" "Udev Menu" "Diagnostic Output" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Instance Status")
instance_status
break
;;
"USB Port Testing")
usb_testing
break
;;
"Sync Users")
sync_users
break
;;
"Share Uploads")
share_uploads
break
;;
"Set Global Config")
global_config
break
;;
"Udev Menu")
udev_menu
break
;;
"Change Streamer")
change_streamer
break
;;
"Diagnostic Output")
diagnostics
break
;;
"Quit")
main_menu
break
;;*) echo "invalid option $REPLY";;
esac
done
}
udev_menu() {
echo
echo
PS3="${green}Select an option: ${white}"
options=("Add printer udev rule" "Remove printer udev rule" "Add camera udev rule" "Remove camera udev rule" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Add printer udev rule")
add_udev
break
;;
"Remove printer udev rule")
remove_udev
break
;;
"Add camera udev rule")
add_udev_camera
break
;;
"Remove camera udev rule")
remove_udev_camera
break
;;
"Quit")
main_menu
break
;;*) echo "invalid option $REPLY";;
esac
done
}
backup_menu() {
echo
echo
PS3="${green}Select an option: ${white}"
options=("Create Backup" "Restore Backup" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Create Backup")
create_menu
break
;;
"Restore Backup")
restore_menu
break
break
;;
"Quit")
main_menu
break
;;*) echo "invalid option $REPLY";;
esac
done
}
create_menu() {
echo
echo
PS3="${green}Select instance number to backup: ${white}"
get_instances true
select opt in "${INSTANCE_ARR[@]}"
do
if [ "$opt" == Quit ]; then
main_menu
fi
echo "Selected instance to backup: $opt"
back_up $opt
main_menu
done
}
restore_menu() {
echo
echo "${magenta}You must have already created an instance in order to restore it.${white}"
PS3="${green}Select instance to restore: ${white}"
get_instances true
select opt in "${INSTANCE_ARR[@]}"
do
if [ "$opt" == Quit ]; then
main_menu
fi
echo "Selected instance to restore: $opt"
clear
PS3="${green}Select backup to restore: ${white}"
readarray -t options < <(ls /home/$user/instance_backup/$opt-backup-*.zip)
options+=("Quit")
select zipfile in "${options[@]}"
do
if [ "$zipfile" == Quit ]; then
main_menu
fi
echo "Selected $opt to restore"
restore $opt $zipfile
main_menu
done
done
}