-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinfimechTxUpgrade.sh
300 lines (243 loc) · 9.01 KB
/
infimechTxUpgrade.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
HOME_DIR="/home/mks"
PRINTER_DATA="printer_data"
BACKUP_LOCATION="${HOME_DIR}/config_backup"
PRINTER_DATA_CP="${HOME_DIR}/${PRINTER_DATA}"
PRINTER_CONFIG_FOLDER="${PRINTER_DATA_CP}/config"
PRINTER_CONFIG_FOLDER_ESCAPED="${PRINTER_DATA}\/config"
FLUIDD_CONFIG="${PRINTER_CONFIG_FOLDER}/fluidd.cfg"
MOONRAKER_CONFIG="${PRINTER_CONFIG_FOLDER}/moonraker.conf"
PLR_CONFIG="${PRINTER_CONFIG_FOLDER}/plr.cfg"
PRINTER_CONFIG="${PRINTER_CONFIG_FOLDER}/printer.cfg"
R=$'\e[1;91m'
G=$'\e[1;92m'
NL_NOCOLOR=$'\n\e[0m'
clear_screen() {
clear
tput cup 0 0
}
press_any_key() {
echo -e "${G}Done, press any key to continue${NL_NOCOLOR}"
read
}
# Helper function to stop moonraker and klipper services
stop_services() {
echo -e "${G}Stopping moonraker and klipper services${NL_NOCOLOR}"
sudo systemctl stop moonraker.service
sudo systemctl stop klipper.service
}
# Helper function to start moonraker and klipper services
start_services() {
echo -e "${G}Starting moonraker and klipper services${NL_NOCOLOR}"
sudo systemctl start klipper.service
sudo systemctl start moonraker.service
}
# Changes deb. to archive. in sources.list so users can update and so kiauh does not error out
update_system() {
echo -e "${G}Updating sources.list, see Updating armbian section in Readme for more info${NL_NOCOLOR}"
sudo sed -i "s/\/\/deb./\/\/archive./g" /etc/apt/sources.list
echo -e "${G}sources.list after update${NL_NOCOLOR}"
cat /etc/apt/sources.list
echo -e "${G}Performing update${NL_NOCOLOR}"
sudo apt update
sudo apt upgrade
# Making sure numpy is installed for resonance compensation
echo -e "${G}Making sure numpy is installed${NL_NOCOLOR}"
sudo apt install python3-numpy python3-matplotlib libatlas-base-dev libopenblas-dev
press_any_key
}
# Starts armbian-config so that user can update timezone
update_timezone() {
echo -e "${G}Updating Timezone, see Timezone Configuration section in Readme${NL_NOCOLOR}"
sleep 5
sudo armbian-config
press_any_key
}
# starts armbian resize to resize to larger eMMC drive
resize_disk()
{
echo -e "${G}Resizing disk${NL_NOCOLOR}"
sleep 5
sudo systemctl start armbian-resize-filesystem.service
press_any_key
}
# Runs kiauh installer
run_kiauh()
{
echo -e "${G}Going to launch Kiauh, see Running Kiauh in Readme to remove/install plugins"
sleep 5
${HOME_DIR}/kiauh/kiauh.sh
echo -e "${G}Did Kiauh update?"
read choice
case $choice in
Y|y|Yes|yes) echo "${G}Launching Kiauh again...${NL_NOCOLOR}"; sleep 5; ${HOME_DIR}/kiauh/kiauh.sh;;
esac
press_any_key
}
install_numpy(){
echo -e "${G}Installing numpy${NL_NOCOLOR}"
${HOME_DIR}/klippy-env/bin/pip install -v numpy
press_any_key
}
# Backups folders before removing them just in case....
backup_function() {
echo -e "${G}Backing up files${NL_NOCOLOR}"
stop_services
echo -e "${G}Making backup location${NL_NOCOLOR}"
mkdir ${BACKUP_LOCATION}
echo -e "${G}Backing up gcode_files${NL_NOCOLOR}"
cp -rp ${HOME_DIR}/gcode_files ${BACKUP_LOCATION}/
echo -e "${G}Backing up klipper config${NL_NOCOLOR}"
cp -rp ${HOME_DIR}/klipper_config ${BACKUP_LOCATION}/
echo -e "${G}Backing up moonraker database to keep print history${NL_NOCOLOR}"
cp -rp ${HOME_DIR}/.moonraker_database ${BACKUP_LOCATION}/
press_any_key
}
# Moves configuration from backup folder to printer_data folder
# Finds and replaces paths so that klipper and moonraker are happy
# Remove lines that are deprecated
# Create symlinks to mks user folder so that webcamd and touch screen still works
fix_config_files() {
echo -e "${G}Copying and fixing config files${NL_NOCOLOR}"
echo -e "${G}Stopping klipper and moonraker services${NL_NOCOLOR}"
stop_services
echo -e "${G}Updating configuration files${NL_NOCOLOR}"
echo -e "${G}Copying gcode_files${NL_NOCOLOR}"
cp -rp ${BACKUP_LOCATION}/gcode_files/. ${PRINTER_DATA_CP}/gcodes/
echo -e "${G}Removing ~/gcode_files${NL_NOCOLOR}"
rm -rf ${HOME_DIR}/gcode_files
echo -e "${G}Copying klipper config${NL_NOCOLOR}"
cp -rp ${BACKUP_LOCATION}/klipper_config/* ${PRINTER_DATA_CP}/config/
echo -e "${G}Removing ~/klipper_config${NL_NOCOLOR}"
rm -rf ${HOME_DIR}/klipper_config
echo -e "${G}Removing newly created moonraker database files"
rm -rf ${PRINTER_DATA_CP}/database/*
echo -e "${G}Moving moonraker data to keep print history${NL_NOCOLOR}"
cp ${BACKUP_LOCATION}/.moonraker_database/* ${PRINTER_DATA_CP}/database/
echo -e "${G}Removing ~/.moonraker_database${NL_NOCOLOR}"
rm -rf ${HOME_DIR}/.moonraker_database
echo -e "${G}Removing ~/klipper_logs${NL_NOCOLOR}"
rm -rf ${HOME_DIR}/klipper_logs
echo -e "${G}Moving power loss resume scripts in to ${PRINTER_CONFIG_FOLDER} folder"
mkdir --parents ${PRINTER_CONFIG_FOLDER}/plr
mv ${HOME_DIR}/clear_plr.sh ${PRINTER_CONFIG_FOLDER}/plr
mv ${HOME_DIR}/plr.sh ${PRINTER_CONFIG_FOLDER}/plr
echo -e "${G}Creating symlinks so that webcamd and touchscreen still works correctly${NL_NOCOLOR}"
ln -s ${PRINTER_DATA_CP}/gcodes ${HOME_DIR}/gcode_files
ln -s ${PRINTER_DATA_CP}/config ${HOME_DIR}/klipper_config
ln -s ${PRINTER_DATA_CP}/logs ${HOME_DIR}/klipper_logs
echo -e "${G}Fixing configuration files to point to new configuration location${NL_NOCOLOR}"
# fluidd.cfg
sed -i -e "s/mks\/gcode_files/mks\/${PRINTER_DATA}\/gcodes/g" ${FLUIDD_CONFIG}
# moonraker.conf
sed -i -e "s/klipper_config/${PRINTER_CONFIG_FOLDER_ESCAPED}/g" ${MOONRAKER_CONFIG}
sed -i -e "s/\/tmp\/klippy_uds/\/home\/mks\/${PRINTER_DATA}\/comms\/klippy.sock/g" ${MOONRAKER_CONFIG}
#Removing depreciated lines
sed -i -e "/enable_debug_logging: False/d" ${MOONRAKER_CONFIG}
sed -i -e "/config_path/d" ${MOONRAKER_CONFIG}
sed -i -e "/\[file_manager\]/d" ${MOONRAKER_CONFIG}
sed -i -e "/log_path/d" ${MOONRAKER_CONFIG}
sed -i -e "/database/d" ${MOONRAKER_CONFIG}
#plr.cfg
sed -i -e "s/klipper_config/${PRINTER_DATA}/g" ${PLR_CONFIG}
sed -i -e "s/mks\/clear_plr.sh/mks\/${PRINTER_CONFIG_FOLDER_ESCAPED}\/plr\/clear_plr.sh/g" ${PLR_CONFIG}
sed -i -e "s/mks\/plr.sh/mks\/${PRINTER_CONFIG_FOLDER_ESCAPED}\/plr\/plr.sh/g" ${PLR_CONFIG}
#printer.cfg
sed -i -e "s/path: ~\/gcode_files/path: \/home\/mks\/${PRINTER_DATA}\/gcodes/g" ${PRINTER_CONFIG}
sed -i -e "s/klipper_config/printer_data\/config/g" ${PRINTER_CONFIG}
#Removing depreciated lines
sed -i "/max_accel_to_decel/d" ${PRINTER_CONFIG}
#Updating away from the custom gcode
sed -i -e "s/K109/M109/g" ${PRINTER_CONFIG}
sed -i -e "s/K190/M190/g" ${PRINTER_CONFIG}
press_any_key
}
# Launches menuconfig so that user can select Linux process to recompile
# Reference : https://www.klipper3d.org/RPi_microcontroller.html#install-the-rc-script
update_rpi_mcu() {
echo -e "${G}Recompiling RPI mcu${NL_NOCOLOR}"
#Updating RPI
cd ${HOME_DIR}/klipper
echo -e "${G}Launching menuconfig, please see Updating RPI MCU section in Readme${NL_NOCOLOR}"
sleep 5
make menuconfig
make flash
press_any_key
}
# Function helper to clean up ~config_backup folder
clean_up_config_backup(){
echo -e "${G}Removing ~/config_backup folder${NL_NOCOLOR}"
rm -rf ${HOME_DIR}/config_backup
press_any_key
}
# Enables webcamd service
enable_webcamd() {
echo -e "${G}Enabling webcamd service${NL_NOCOLOR}"
sudo systemctl enable webcamd.service
echo -e "${G}Starting webcamd service${NL_NOCOLOR}"
sudo systemctl start webcamd.service
press_any_key
}
# Prints out menu
print_menu() {
clear_screen
echo ""
echo "Choose a to update all or go through 1-7 in order"
echo ""
echo "1) Update System"
echo ""
echo "2) Update Timezone"
echo ""
echo "3) Resized Disk"
echo ""
echo "4) Backup files"
echo ""
echo "5) Run kiauh"
echo ""
echo "6) Install numpy (resonance compensation)"
echo ""
echo "7) Fix configuration files"
echo ""
echo "8) Update RPI MCU"
echo ""
echo "9) Clean up config_back (only run after everything is working correctly)"
echo ""
echo "10) Enable webcamd"
echo ""
echo "a) Run all"
echo ""
echo "q) Quit"
}
# Runs all commands in correct order
run_all(){
update_system
update_timezone
resize_disk
backup_function
run_kiauh
install_numpy
fix_config_files
update_rpi_mcu
start_services
}
# Main loop
while true; do
print_menu
echo -e "${G}Enter your choice: ${NL_NOCOLOR}"
read choice
case $choice in
1) update_system;;
2) update_timezone;;
3) resize_disk;;
4) backup_function;;
5) run_kiauh;;
6) install_numpy;;
7) fix_config_files;;
8) update_rpi_mcu;;
9) clean_up_config_backup;;
10) enable_webcamd;;
a) run_all;;
q) clear; echo -e "${G}Please reboot and Happy Printing${NL_NOCOLOR}"; sleep 2; exit 0;;
*) echo -e "${R}Invalid choice. Please try again.${NL_NOCOLOR}";;
esac
done