-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcelestrius.sh
executable file
·218 lines (173 loc) · 6.6 KB
/
celestrius.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
#!/bin/bash
set -e
CEL_DIR=$(realpath $(dirname "$0"))
CEL_CFG_FILE="${CEL_DIR}/moonraker-celestrius.cfg"
CEL_SERVICE_NAME="moonraker-celestrius"
green=$(echo -en "\e[92m")
yellow=$(echo -en "\e[93m")
magenta=$(echo -en "\e[35m")
red=$(echo -en "\e[91m")
cyan=$(echo -en "\e[96m")
default=$(echo -en "\e[39m")
report_status() {
echo -e "${magenta}###### $*\n${default}"
}
welcome() {
cat <<EOF
${cyan}
======================================================================================================
### ###
### Welcome, Celestrius Pilot! ###
### ###
======================================================================================================
${default}
EOF
}
success() {
echo -e "\n"
cat <<EOF
${cyan}
====================================================================================================
### ###
### SUCCESS!!! ###
### Celestrius data collection program is ready. ###
### ###
====================================================================================================
${default}
NOTE:
${magenta}
- The data collection is disabled so that you won't accidentally upload unintended data. To enable:
./celestrius.sh enable
${default}
- To disable the data collection, run "./celestrius.sh disable".
- To make changes to the configurations, run "./celestrius.sh install" again.
- To update Celestrius to the latest version, run "./celestrius.sh update".
- To uninstall Celestrius,, run "./celestrius.sh uninstall"
EOF
}
ensure_deps() {
sudo apt install libgeos-dev
CEL_ENV="${CEL_DIR}/env"
if [ ! -f "${CEL_ENV}/bin/activate" ] ; then
report_status "Creating python virtual environment for moonraker-celestrius..."
mkdir -p "${CEL_ENV}"
virtualenv -p /usr/bin/python3 --system-site-packages "${CEL_ENV}"
fi
report_status "Making sure all dependencies are properly installed..."
"${CEL_ENV}"/bin/pip3 install -q -r "${CEL_DIR}"/requirements.txt
}
usage() {
cat <<EOF
Usage: $0 install # Install/Re-install and configure/re-configure the Celestrius data collection program, including adding a system service.
$0 update # Update Celestrius to the latest version
$0 enable # Enable the data collection. Default to be disabled.
$0 disable # Disable the data collection.
$0 uninstall # Show instructions for uninstalling elestrius data collection program
$0 help # Show this message
EOF
}
config_incomplete() {
cat <<EOF
${red}
Incomplete Celstrius configuration. No data will be sent until the Celestrius data collection program is configured properly.
${default}
To rerun the configuration process at a later time, run:
-------------------------------------------------------------------------------------------------
cd ~/moonraker-celestrius
./celestrius.sh install
-------------------------------------------------------------------------------------------------
EOF
exit 1
}
recreate_service() {
echo ""
echo ""
report_status "Creating moonraker-celestrius systemctl service... You may need to enter password to run sudo."
sudo systemctl stop "${CEL_SERVICE_NAME}" 2>/dev/null || true
sudo /bin/sh -c "cat > /etc/systemd/system/${CEL_SERVICE_NAME}.service" <<EOF
#Systemd service file for moonraker-celestrius
[Unit]
Description=Celestrius data collection service
After=network-online.target moonraker.service
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=${USER}
WorkingDirectory=${CEL_DIR}
ExecStart=${CEL_ENV}/bin/python3 -m moonraker_celestrius.app -c ${CEL_CFG_FILE}
Restart=always
RestartSec=5
EOF
sudo systemctl enable "${CEL_SERVICE_NAME}"
sudo systemctl daemon-reload
report_status "Launching ${CEL_SERVICE_NAME} service..."
sudo systemctl restart "${CEL_SERVICE_NAME}"
}
uninstall() {
cat <<EOF
To uninstall Celestrius data collection program, please run:
sudo systemctl stop "${CEL_SERVICE_NAME}"
sudo systemctl disable "${CEL_SERVICE_NAME}"
sudo rm "/etc/systemd/system/${CEL_SERVICE_NAME}.service"
sudo systemctl daemon-reload
sudo systemctl reset-failed
rm -rf ~/moonraker-celestrius
EOF
exit 0
}
configure() {
welcome
ensure_deps
"${CEL_DIR}/moonraker_celestrius/scripts/terms.sh"
read -p "Do you understand and accept the terms and the privacy policy [Y/n]: " -e -i "Y" accepted
if [ "${accepted^^}" != "Y" ] ; then
config_incomplete
fi
if ! PYTHONPATH="${CEL_DIR}:${PYTHONPATH}" ${CEL_ENV}/bin/python3 -m moonraker_celestrius.config -c "${CEL_CFG_FILE}" $@; then
config_incomplete
fi
mkdir -p "${CEL_DIR}/logs"
recreate_service
success
}
enable() {
PYTHONPATH="${CEL_DIR}:${PYTHONPATH}" ${CEL_ENV}/bin/python3 -m moonraker_celestrius.config -c "${CEL_CFG_FILE}" -e
report_status "Restarting moonraker-celestrius systemctl service... You may need to enter password to run sudo."
sudo systemctl restart "${CEL_SERVICE_NAME}"
cat <<EOF
${cyan}
Celestrius data collection enabled!
Snapshots will be collected from configured nozzle camera for all subsequent prints until disabled.
${default}
To disable Celestrius data collection:
-------------------------------------------------------------------------------------------------
cd ~/moonraker-celestrius
./celestrius.sh disable
-------------------------------------------------------------------------------------------------
EOF
}
disable() {
report_status "Restarting moonraker-celestrius systemctl service... You may need to enter password to run sudo."
sudo systemctl restart "${CEL_SERVICE_NAME}"
PYTHONPATH="${CEL_DIR}:${PYTHONPATH}" ${CEL_ENV}/bin/python3 -m moonraker_celestrius.config -c "${CEL_CFG_FILE}" -d
cat <<EOF
${cyan}
Celestrius data collection disabled!
${default}
To enable Celestrius data collection:
-------------------------------------------------------------------------------------------------
cd ~/moonraker-celestrius
./celestrius.sh enable
-------------------------------------------------------------------------------------------------
EOF
}
case $1 in
help) usage && exit 0;;
install) configure;;
update) git pull && ensure_deps;;
enable) enable;;
disable) disable;;
uninstall) uninstall ;;
*) usage && exit 1;;
esac