forked from OpenNeptune3D/OpenNept4une
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenNept4une.sh
480 lines (432 loc) · 14.7 KB
/
OpenNept4une.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#!/bin/bash
# Path to the script and other resources
SCRIPT="/home/mks/OpenNept4une/OpenNept4une.sh"
DISPLAY_SERVICE_INSTALLER="/home/mks/OpenNept4une/display/display-service-installer.sh"
MCU_RPI_INSTALLER="/home/mks/OpenNept4une/img-config/rpi-mcu-install.sh"
USB_STORAGE_AUTOMOUNT="/home/mks/OpenNept4une/img-config/usb-storage-automount.sh"
ANDROID_RULE_INSTALLER="/home/mks/OpenNept4une/img-config/adb-automount.sh"
CROWSNEST_FIX_INSTALLER="/home/mks/OpenNept4une/img-config/crowsnest-lag-fix.sh"
BASE_IMAGE_INSTALLER="/home/mks/OpenNept4une/img-config/base_image_configuration.sh"
DE_ELEGOO_IMAGE_CLEANSER="/home/mks/OpenNept4une/img-config/de_elegoo_cleanser.sh"
FLAG_FILE="/boot/.OpenNept4une.txt"
# Image Fixes
sudo usermod -aG gpio,spiusers mks &>/dev/null
sudo rm -f /usr/local/bin/set_gpio.sh
# Ensure the flag file exists and update its timestamp
sudo touch "$FLAG_FILE"
# Get system information
SYSTEM_INFO=$(uname -a)
# Check if the system information is already in the flag file and append it if not
if ! sudo grep -qF "$SYSTEM_INFO" "$FLAG_FILE"; then
echo "$SYSTEM_INFO" | sudo tee -a "$FLAG_FILE" > /dev/null
fi
# ASCII art for OpenNept4une
OPENNEPT4UNE_ART=$(cat <<'EOF'
____ _ __ __ ____
/ __ \___ ___ ___ / |/ /__ ___ / /_/ / /__ _____ ___
/ /_/ / _ \/ -_) _ \/ / -_) _ \/ __/_ _/ // / _ \/ -_)
\____/ .__/\__/_//_/_/|_/\__/ .__/\__/ /_/ \_,_/_//_/\__/
/_/ /_/
EOF
)
clear_screen() {
# Clear the screen and move the cursor to the top left
clear
tput cup 0 0
}
# Function to update the repository
update_repo() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Checking for updates..."
echo "======================================"
repo_dir="/home/mks/OpenNept4une"
if [ -d "$repo_dir" ]; then
cd "$repo_dir"
else
echo "Repository directory not found!"
return 1
fi
# Pull the updates
git fetch origin main --quiet
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
if [ "$LOCAL" != "$REMOTE" ]; then
echo "Updates are available for the repository."
read -p "Would you like to update the repository? (y/n): " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Updating repository..."
git reset --hard
git clean -fd
# Pull the updates
git pull origin main --force
chmod +x "$SCRIPT"
exec "$SCRIPT"
exit 0
else
echo "Update skipped."
fi
else
echo "Your repository is already up-to-date."
fi
echo "======================================"
}
update_repo
advanced_more() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Welcome to OpenNept4une"
echo "======================================"
echo "1) Install Android ADB rules (klipperscreen)"
echo ""
echo "2) Install Crowsnest FPS Fix"
echo ""
echo "3) Base Compiled Image Config (Dont use on release images)"
echo ""
echo "4) Elegoo Image Cleanser Script (De-Elegoo)"
echo ""
echo "5) Return Main Menu"
echo "======================================"
read -p "Enter your choice: " choice
case $choice in
1)
android_rules
;;
2)
crowsnest_fix
;;
3)
base_image_config
;;
4)
de_elegoo_image_cleanser
;;
5)
print_menu
;;
esac
}
android_rules() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Do you want to install the android ADB rules? (may fix klipperscreen issues)"
read -p "Enter 'y' to install, any other key to skip: " install_android_rules
if [[ $install_android_rules == "y" ]]; then
echo "Running ADB Rule Installer..."
if [ -f "$ANDROID_RULE_INSTALLER" ]; then
chmod +x "$ANDROID_RULE_INSTALLER"
"$ANDROID_RULE_INSTALLER"
else
echo "Error: Android rule installer script not found."
fi
echo "======================================"
fi
}
crowsnest_fix() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Do you want to install the crowsnest fps fix?"
read -p "Enter 'y' to install, any other key to skip: " install_crowsnest_fix
if [[ $install_crowsnest_fix == "y" ]]; then
echo "Running crowsnest Fix Installer..."
if [ -f "$CROWSNEST_FIX_INSTALLER" ]; then
chmod +x "$CROWSNEST_FIX_INSTALLER"
"$CROWSNEST_FIX_INSTALLER"
else
echo "Error: crowsnest fix installer script not found."
fi
echo "======================================"
fi
}
base_image_config() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Do you want to configure a base/fresh armbian image that you compiled?"
read -p "Enter 'y' to install, any other key to skip: " install_base_image_config
if [[ $install_base_image_config == "y" ]]; then
echo "Running base/fresh image Installer..."
if [ -f "$BASE_IMAGE_INSTALLER" ]; then
chmod +x "$BASE_IMAGE_INSTALLER"
"$BASE_IMAGE_INSTALLER"
else
echo "Error: Base Image installer script not found."
fi
echo "======================================"
fi
}
de_elegoo_image_cleanser() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "DO NOT run this on an OpenNept4une GitHub Image, for Elegoo images only! Continue at your own risk?"
read -p "Enter 'y' to install, any other key to skip: " install_de_elegoo_image_cleanser
if [[ $install_de_elegoo_image_cleanser == "y" ]]; then
echo "Running De-Elegoo Script..."
if [ -f "$DE_ELEGOO_IMAGE_CLEANSER" ]; then
chmod +x "$DE_ELEGOO_IMAGE_CLEANSER"
"$DE_ELEGOO_IMAGE_CLEANSER"
else
echo "Error: De-Elegoo script not found."
fi
echo "======================================"
fi
}
# Function to install the Screen Service
install_screen_service() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Do you want to install the (WIP) Touch-Screen implementation? (barely functional, frequent updates)"
read -p "Enter 'y' to install, any other key to skip: " install_screen
if [[ $install_screen == "y" ]]; then
echo "Installing Touch-Screen Service..."
if [ -f "$DISPLAY_SERVICE_INSTALLER" ]; then
chmod +x "$DISPLAY_SERVICE_INSTALLER"
"$DISPLAY_SERVICE_INSTALLER"
else
echo "Error: Display service installer script not found."
fi
echo "======================================"
fi
}
update_mcu_rpi_fw() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Do you want to update the Virtual MCU rpi (responsible for ADXL SPI & LED control only)"
read -p "Enter 'y' to install, any other key to skip: " install_mcu_rpi
if [[ $install_mcu_rpi == "y" ]]; then
echo "Running MCU rpi Installer..."
if [ -f "$MCU_RPI_INSTALLER" ]; then
chmod +x "$MCU_RPI_INSTALLER"
"$MCU_RPI_INSTALLER"
else
echo "Error: Virtual MCU installer script not found."
fi
echo "======================================"
fi
}
usb_auto_mount() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Do you want to auto mount USB drives? (Folder will mount as 'USB' in fluid 'Jobs' Tab)"
read -p "Enter 'y' to install, any other key to skip: " install_usb_auto_mount
if [[ $install_usb_auto_mount == "y" ]]; then
echo "Running USB Auto Mount Installer..."
if [ -f "$USB_STORAGE_AUTOMOUNT" ]; then
chmod +x "$USB_STORAGE_AUTOMOUNT"
"$USB_STORAGE_AUTOMOUNT"
else
echo "Error: USB Auto Mount installer script not found."
fi
echo "======================================"
fi
}
# Function to copy files with error handling
copy_file() {
local base_path="/home/mks/OpenNept4une"
local src="$base_path/$1"
local dest=$2
local use_sudo=${3:-false}
if [[ -f "$src" ]]; then
if [[ "$use_sudo" == true ]]; then
sudo cp "$src" "$dest" || {
echo "Error: Failed to copy $src to $dest."
return 1
}
else
cp "$src" "$dest" || {
echo "Error: Failed to copy $src to $dest."
return 1
}
fi
echo "Successfully copied $src to $dest."
else
echo "Error: Source file $src not found."
return 1
fi
}
# Function to apply configuration
apply_configuration() {
if [[ -n "$PRINTER_CFG_SOURCE" ]]; then
copy_file "$PRINTER_CFG_SOURCE" "$PRINTER_CFG_DEST/printer.cfg" false
else
echo "Error: Invalid printer configuration file."
return 1
fi
if [[ -n "$DTB_SOURCE" ]]; then
copy_file "$DTB_SOURCE" "$DTB_DEST" true
else
echo "Error: Invalid DTB file selection."
return 1
fi
cp -r /home/mks/OpenNept4une/img-config/printer-data/* /home/mks/printer_data/config/
mv /home/mks/printer_data/config/data.mdb /home/mks/printer_data/database/data.mdb
}
install_printer_cfg() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "Please select your machine type:"
echo "1) Neptune4"
echo "2) Neptune4 Pro"
echo "3) Neptune4 Plus"
echo "4) Neptune4 Max"
read -p "Enter your choice (1-4): " MACHINE_TYPE
PRINTER_CFG_DEST="/home/mks/printer_data/config"
DTB_DEST="/boot/dtb/rockchip/rk3328-roc-cc.dtb"
DATABASE_DEST="/home/mks/printer_data/database"
mkdir -p "$PRINTER_CFG_DEST" "$DATABASE_DEST"
update_flag_file() {
local flag_value=$1
sudo awk -v line="$flag_value" '
BEGIN { added = 0 }
/^N4/ { print line; added = 1; next }
{ print }
END { if (!added) print line }
' "$FLAG_FILE" > temp
sudo cp temp "$FLAG_FILE" && rm temp # Replacing mv with cp and rm
}
stepper_motor_current() {
read -p "Enter stepper motor current (0.8 or 1.2): " MOTOR_CURRENT
if [[ "$MOTOR_CURRENT" != "0.8" && "$MOTOR_CURRENT" != "1.2" ]]; then
echo "Invalid motor current selection. Please enter 0.8 or 1.2."
stepper_motor_current
fi
}
pcb_version() {
read -p "Enter PCB Version (1.0 or 1.1): " PCB_VERSION
if [[ "$PCB_VERSION" != "1.0" && "$PCB_VERSION" != "1.1" ]]; then
echo "Invalid PCB selection. Please enter 1.0 or 1.1."
pcb_version
fi
}
case $MACHINE_TYPE in
1)
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "Configuring for Neptune4..."
stepper_motor_current
pcb_version
PRINTER_CFG_SOURCE="printer-confs/n4/n4-${MOTOR_CURRENT}-printer.cfg"
DTB_SOURCE="dtb/n4-n4pro-v${PCB_VERSION}/rk3328-roc-cc.dtb"
FLAG_LINE="N4-${MOTOR_CURRENT}A-v${PCB_VERSION}"
;;
2)
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "Configuring for Neptune4 Pro..."
stepper_motor_current
pcb_version
PRINTER_CFG_SOURCE="printer-confs/n4pro/n4pro-${MOTOR_CURRENT}-printer.cfg"
DTB_SOURCE="dtb/n4-n4pro-v${PCB_VERSION}/rk3328-roc-cc.dtb"
FLAG_LINE="N4Pro-${MOTOR_CURRENT}A-v${PCB_VERSION}"
;;
3)
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "Configuring for Neptune4 Plus..."
PRINTER_CFG_SOURCE="printer-confs/n4plus/n4plus-printer.cfg"
DTB_SOURCE="dtb/n4plus-n4max-v1.1-2.0/rk3328-roc-cc.dtb"
FLAG_LINE="N4Plus"
;;
4)
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "Configuring for Neptune4 Max..."
PRINTER_CFG_SOURCE="configs/neptune4max/printer.cfg"
DTB_SOURCE="dtb/n4plus-n4max-v1.1-2.0/rk3328-roc-cc.dtb"
FLAG_LINE="N4Max"
;;
*)
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "Invalid selection. Please try again."
return
;;
esac
update_flag_file "$FLAG_LINE"
apply_configuration
reboot_system
}
# Function to reboot the system
reboot_system() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "The system needs to be rebooted to continue. Reboot now? (y/n)"
read -p "Enter your choice (highly advised): " REBOOT_CHOICE
if [[ "$REBOOT_CHOICE" == "y" ]]; then
echo "System will reboot now."
sudo reboot
else
echo "Reboot canceled."
fi
}
# Function to configure WiFi
wifi_config() {
sudo nmtui
}
# Function to print the main menu
print_menu() {
clear_screen
echo -e "\033[0;33m$OPENNEPT4UNE_ART\033[0m"
echo "======================================"
echo "Welcome to OpenNept4une"
echo "======================================"
echo "1) Install latest OpenNept4une Printer.cfg"
echo ""
echo "2) WiFi Config"
echo ""
echo "3) Enable USB Storage AutoMount"
echo ""
echo "4) Update (Virtual) MCU rpi Firmware"
echo ""
echo "5) Install (WIP) Touch Screen Implementation"
echo ""
echo "6) Advanced / More"
echo ""
echo "7) Update repository"
echo ""
echo "8) Exit"
echo "======================================"
}
# Main menu loop
while true; do
print_menu
read -p "Enter your choice: " choice
case $choice in
1)
install_printer_cfg
;;
2)
wifi_config
;;
3)
usb_auto_mount
;;
4)
update_mcu_rpi_fw
;;
5)
install_screen_service
;;
6)
advanced_more
;;
7)
update_repo
;;
8)
echo "Exiting..."
exit 0
;;
*)
echo "Invalid choice. Please try again."
;;
esac
done