-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathconfigure.sh
executable file
·267 lines (239 loc) · 7.43 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
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
#!/usr/bin/env bash
#### crowsnest - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2021 - 2022
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck enable=require-variable-braces
# Exit on errors
set -Ee
## Debug
# set -x
# Global Vars
CN_CONFIG_USER=$(whoami)
CN_CONFIG_CONFIGFILE="tools/.config"
CN_CONFIG_ROOTPATH="/home/${CN_CONFIG_USER}/printer_data"
CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
CN_USTREAMER_REPO="https://github.com/pikvm/ustreamer.git"
CN_USTREAMER_BRANCH="v6.10"
CN_CAMERA_STREAMER_REPO="https://github.com/ayufan/camera-streamer.git"
CN_CAMERA_STREAMER_BRANCH="master"
### Messages
header_msg() {
clear
echo -e "\e[34m\n #### Crowsnest Install Configurator ####\e[0m\n"
}
welcome_msg() {
header_msg
echo -e "This will guide you through install configuration"
echo -e "After successful configuration use\n"
echo -e "\t\e[32msudo make install\e[0m\n"
echo -e "to install crowsnest ..."
}
abort_msg() {
header_msg
echo -e "Configuration aborted by user ... \e[31mExiting!\e[0m"
}
check_config_file_msg() {
header_msg
echo -e "\n\t\e[33mWarning:\e[0m Found an existing .config!\n"
}
default_path_msg() {
echo -e "Hit ENTER to use default."
}
root_path_msg() {
header_msg
echo -e "Please specify path to your 'printer_data' root path\n"
echo -e "For example: /home/pi/voron_data or /home/kwad/ender_data"
echo -e "\t\e[34mNOTE:\e[0m File names are hardcoded! Also skip trailing backslash!"
echo -e "\tDefault: \e[32m${CN_CONFIG_ROOTPATH}\e[0m\n"
}
config_path_msg() {
header_msg
echo -e "Please specify path to config file (crowsnest.conf)\n"
echo -e "\t\e[34mNOTE:\e[0m File names are hardcoded! Also skip trailing backslash!"
echo -e "\tDefault: \e[32m${CN_CONFIG_CONFIGPATH}\e[0m\n"
}
log_path_msg() {
header_msg
echo -e "Please specify path to log file (crowsnest.log)\n"
echo -e "\t\e[34mNOTE:\e[0m File names are hardcoded! Also skip trailing backslash!"
echo -e "\tDefault: \e[32m${CN_CONFIG_LOGPATH}\e[0m\n"
}
env_path_msg() {
header_msg
echo -e "Please specify path to service environment file (crowsnest.env)\n"
echo -e "\t\e[34mNOTE:\e[0m File names are hardcoded! Also skip trailing backslash!"
echo -e "\tDefault: \e[32m${CN_CONFIG_ENVPATH}\e[0m\n"
}
add_moonraker_entry_msg() {
header_msg
echo -e "Should the update_manager entry added to your moonraker.conf?\n"
echo -e "\t\e[34mNOTE:\e[0m\n\tThis will only work if your moonraker.conf"
echo -e "\tshares the same path as your crowsnest.conf!!!\n"
echo -e "If you want/have to do that manually,\nplease see 'resources/moonraker_update.txt'"
echo -e "Copy the content in your moonraker.conf\n"
}
goodbye_msg() {
header_msg
echo -e "\t\e[32mSuccessful\e[0m configuration."
echo -e "\tIn order to install crowsnest, please run:\n"
echo -e "\t\t\e[32msudo make install\e[0m\n"
echo -e "Goodbye ..."
}
### funcs
continue_config() {
local reply
while true; do
read -erp "Continue? [Y/n]: " -i "Y" reply
case "${reply}" in
[Yy]* )
break
;;
[Nn]* )
abort_msg
exit 0
;;
* )
echo -e "\e[31mERROR: Please type Y or N !\e[0m"
;;
esac
done
}
check_config_file() {
local reply
if [[ -f "${CN_CONFIG_CONFIGFILE}" ]]; then
check_config_file_msg
while true; do
read -erp "Overwrite? [y/N]: " -i "N" reply
case "${reply}" in
[Yy]* )
rm -f tools/.config
break
;;
[Nn]* )
abort_msg
exit 0
;;
* )
echo -e "\e[31mERROR:\e[0m Please type Y or N !"
;;
esac
done
return 0
fi
return 0
}
create_config_header() {
{
echo -e "BASE_USER=\"${CN_CONFIG_USER}\"";
echo -e "CROWSNEST_USTREAMER_REPO_SHIP=\"${CN_USTREAMER_REPO}\"";
echo -e "CROWSNEST_USTREAMER_REPO_BRANCH=\"${CN_USTREAMER_BRANCH}\""
echo -e "CROWSNEST_CAMERA_STREAMER_REPO_SHIP=\"${CN_CAMERA_STREAMER_REPO}\"";
echo -e "CROWSNEST_CAMERA_STREAMER_REPO_BRANCH=\"${CN_CAMERA_STREAMER_BRANCH}\""
} >> "${CN_CONFIG_CONFIGFILE}"
}
specify_root_path() {
local reply
root_path_msg
default_path_msg
read -erp "Please enter path: " -i "${CN_CONFIG_ROOTPATH}" reply
if [[ -n "${reply}" ]]; then
CN_CONFIG_ROOTPATH="${reply}"
CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
fi
return 0
}
specify_config_path() {
local reply
config_path_msg
default_path_msg
read -erp "Please enter path: " -i "${CN_CONFIG_CONFIGPATH}" reply
if [[ -z "${reply}" ]]; then
echo -e "CROWSNEST_CONFIG_PATH=\"${CN_CONFIG_CONFIGPATH}\"" >> \
"${CN_CONFIG_CONFIGFILE}"
return 0
fi
if [[ -n "${reply}" ]]; then
echo -e "CROWSNEST_CONFIG_PATH=\"${reply}\"" >> "${CN_CONFIG_CONFIGFILE}"
CN_MOONRAKER_CONFIG_PATH="${reply}/moonraker.conf"
return 0
fi
}
specify_log_path() {
local reply
log_path_msg
default_path_msg
read -erp "Please enter path: " -i "${CN_CONFIG_LOGPATH}" reply
if [[ -z "${reply}" ]]; then
echo -e "CROWSNEST_LOG_PATH=\"${CN_CONFIG_LOGPATH}\"" >> \
"${CN_CONFIG_CONFIGFILE}"
return 0
fi
if [[ -n "${reply}" ]]; then
echo -e "CROWSNEST_LOG_PATH=\"${reply}\"" >> "${CN_CONFIG_CONFIGFILE}"
return 0
fi
}
specify_env_path() {
local reply
env_path_msg
default_path_msg
read -erp "Please enter path: " -i "${CN_CONFIG_ENVPATH}" reply
if [[ -z "${reply}" ]]; then
echo -e "CROWSNEST_ENV_PATH=\"${CN_CONFIG_ENVPATH}\"" >> \
"${CN_CONFIG_CONFIGFILE}"
return 0
fi
if [[ -n "${reply}" ]]; then
echo -e "CROWSNEST_ENV_PATH=\"${reply}\"" >> "${CN_CONFIG_CONFIGFILE}"
return 0
fi
}
add_moonraker_entry() {
local reply
add_moonraker_entry_msg
while true; do
read -erp "Add update_manager entry? [Y/n]: " -i "Y" reply
case "${reply}" in
[yY]*)
echo -e "CROWSNEST_ADD_CROWSNEST_MOONRAKER=\"1\"" >> "${CN_CONFIG_CONFIGFILE}"
echo "CROWSNEST_MOONRAKER_CONF_PATH=\"${CN_MOONRAKER_CONFIG_PATH}\"" \
>> "${CN_CONFIG_CONFIGFILE}"
break
;;
[nN]*)
echo -e "CROWSNEST_ADD_CROWSNEST_MOONRAKER=\"0\"" >> "${CN_CONFIG_CONFIGFILE}"
break
;;
* )
echo -e "\e[31mERROR:\e[0m Please type Y or N !"
;;
esac
done
}
### Main func
main() {
welcome_msg
continue_config
check_config_file
create_config_header
specify_root_path
specify_config_path
specify_log_path
specify_env_path
add_moonraker_entry
goodbye_msg
}
### MAIN
main
exit 0