Compare commits

...

166 Commits
v2 ... v3.1.0

Author SHA1 Message Date
th33xitus
e9706b52d8 Update changelog.md 2021-06-15 17:22:39 +02:00
th33xitus
412e084d6d script: add short changelog url to kiauh update message 2021-06-15 16:40:10 +02:00
th33xitus
3ebee823ad script: remove KlipperScreen.log symlink dialog. 2021-06-15 16:12:58 +02:00
th33xitus
72312422e3 fix: performance improvement for loading the advanced menu ui 2021-06-15 15:56:13 +02:00
th33xitus
54089582e4 script: rewrite the auto mainsailOS/fluiddPi migration function
No auto update anymore when updating Klipper. The user now must start this function. It's available in the Advanced Menu.
2021-06-15 15:56:13 +02:00
th33xitus
9fd3f930df script: advanced_menu.sh, switch version becomes switch branch 2021-06-15 15:56:13 +02:00
th33xitus
98f0aa4b8f script: update log-upload function 2021-06-15 15:56:13 +02:00
th33xitus
19b37e4dc4 script: update klipper.service raw file link 2021-06-15 15:56:13 +02:00
th33xitus
d344b1c5f6 feat: auto mainsailOS / fluiddPi migration
script: make use of moonrakers new log_path configuration option

script: create webui nginx log symlinks upon installation/update
2021-06-15 15:56:13 +02:00
jordanruthe
f804fcb65d update: Fix detached head on KlipperScreen update (#93) 2021-06-13 17:39:12 +02:00
th33xitus
0edfc746d4 script: improve dependency checks on klipper/moonraker update 2021-06-08 17:55:40 +02:00
th33xitus
02ef0578e3 script: reading klipper/moonraker dependencies from their respective install scripts 2021-06-08 17:54:23 +02:00
th33xitus
5d11cd212a script: update install_moonraker.sh (#89) 2021-06-04 14:01:54 +02:00
cron410
bf33c77db7 script: install_klipper.sh prompt phrasing (#90) 2021-06-04 13:55:05 +02:00
th33xitus
0815d7778c feat: add cyberpunk theme to mainsail theme installer 2021-05-25 18:53:07 +02:00
th33xitus
9a3814f480 fix: typo in SYSTEMDDIR variable 2021-05-25 18:49:45 +02:00
th33xitus
a83585fb06 fix: improve pattern matching 2021-05-25 18:39:37 +02:00
th33xitus
dc27fe47e1 Merge branch 'b3tuning-install-mjpg-steamer-fix' 2021-05-25 12:16:27 +02:00
th33xitus
11b3d7a961 fix: replace config dir in webcamd file 2021-05-25 12:15:01 +02:00
th33xitus
9e0cdb0715 fix: remove webcamd file when removing mjpgstreamer 2021-05-25 12:13:36 +02:00
th33xitus
8abda56749 fix: typo in WEBCAM_TXT_SRC 2021-05-25 12:04:13 +02:00
James Hildebrand
cf20fc3c48 Issue 85 fix 2021-05-24 16:57:21 -07:00
th33xitus
6c8845d7b4 script: show found services in error message 2021-05-23 11:38:32 +02:00
th33xitus
fb0a30814d fix: validate user input for amount of Klipper instances to install 2021-05-23 10:44:51 +02:00
th33xitus
87f229c62d Update README.md 2021-05-23 10:08:16 +02:00
th33xitus
5b1da45688 fix: typo in dialog of get_mcu_id 2021-05-23 09:58:34 +02:00
th33xitus
545b978e80 update kiauh_macros.cfg
Update macros to reflect recent changes to Klipper

f10247a498
2021-05-21 08:55:11 +02:00
th33xitus
44f5609de6 script: remove deprecated moonraker.conf entries 2021-04-20 21:53:13 +02:00
th33xitus
f2a26d9b3d fix: false positive error message during klipper setup
add fix some status.sh functions too
2021-04-15 13:03:36 +02:00
Evgenii Shavrin
bb2cdab02b script: better moonraker service detection (#79)
More accurate service search
2021-04-13 12:21:16 +02:00
th33xitus
d6596d0a3d script: change kiauh update notification to a dialog 2021-04-08 18:07:30 +02:00
th33xitus
865fbc07dc script: updating webui nginx config and moonraker.conf template 2021-04-05 08:59:19 +02:00
th33xitus
40ba33eb19 fix: fix a bug that potentially caused writing a wrong config directory path to the moonraker.service file under special conditions 2021-04-03 19:29:59 +02:00
th33xitus
49b77162b0 fix: typo 2021-03-31 10:06:11 +02:00
th33xitus
adf087e3e5 script: activate [history] in moonraker.conf template 2021-03-31 09:16:31 +02:00
th33xitus
8220647564 script: rework mjpg-streamer service setup 2021-03-28 17:00:25 +02:00
th33xitus
57075ff525 script: rework klipper service setup 2021-03-28 16:45:16 +02:00
th33xitus
2f9de620bc script: rework moonraker service setup 2021-03-28 15:51:50 +02:00
th33xitus
d658c3a4cd fix: update nginx config 2021-03-28 15:46:48 +02:00
th33xitus
67f6a2c599 fix: broken update menu 2021-03-27 00:04:25 +01:00
th33xitus
f369c132d2 fix #74 - remove leftovers 2021-03-26 21:48:12 +01:00
th33xitus
cce6ac3c88 feat: add system upgrade 2021-03-26 18:36:05 +01:00
th33xitus
b9fe29068d script: apt-get update before apt-get install in dependency_check() 2021-03-25 21:40:16 +01:00
th33xitus
104089ea3d feat: add mjpg-streamer installer 2021-03-25 21:35:24 +01:00
th33xitus
48d97dab01 feat: backup moonraker database 2021-03-24 11:19:50 +01:00
th33xitus
e4a56564a1 fix: command for removing .octoprint dirs while uninstalling OctoPrint 2021-03-24 11:04:43 +01:00
th33xitus
6de8ce3278 script: add database_path to moonraker.conf template 2021-03-22 22:04:27 +01:00
th33xitus
b46457328f feat: followup to 7c7dd4e 2021-03-22 13:34:52 +01:00
th33xitus
7c7dd4ec3c feat: add mainsail theme installer 2021-03-22 10:55:24 +01:00
th33xitus
749293dde0 fix: visual bug 2021-03-17 16:13:53 +01:00
th33xitus
85f8ab4f24 fix: typo 2021-03-17 16:11:56 +01:00
th33xitus
e894496a6e script: add [history] to moonraker.conf template 2021-03-14 21:30:03 +01:00
th33xitus
19b220b772 fix: #71 2021-03-14 21:15:02 +01:00
th33xitus
a4eaa8952a script: remove unnecessary cors domains from moonraker.conf template 2021-03-12 11:20:38 +01:00
th33xitus
74a9bf783b script: deactivate moonrakers debug logging in moonraker.conf template 2021-03-11 22:08:05 +01:00
th33xitus
7597e999a1 fix: add 'octoprint_compat' entry to moonraker.conf template to enable slicer uploads 2021-03-05 09:12:00 +01:00
th33xitus
64d73ca86a refactor: determine installed services, combine single and multi remove into one step 2021-02-19 11:09:46 +01:00
th33xitus
d3283f7ab7 fix: try to fix a bug where the script errors out, telling that there is already a moonraker service installed but actually there isn't 2021-02-19 11:05:43 +01:00
th33xitus
cb443f6fee fix: rework remove processes 2021-02-17 20:50:36 +01:00
th33xitus
7162256e3f fix: remove klipperscreen log from tmp and user defined config folder 2021-02-17 20:31:26 +01:00
th33xitus
938b9d24f5 feature: add sdcard updates 2021-02-06 14:56:57 +01:00
th33xitus
38a3517c89 fix: autocommit.sh example uses .version files for getting mainsail and fluidd version 2021-02-06 12:16:04 +01:00
th33xitus
0b15cd0d9b fix: delete doubled status_msg in gcode_shell_command extension setup 2021-02-06 12:16:04 +01:00
th33xitus
9d7752a6c5 fix: typo in example pause macro 2021-02-04 19:36:57 +01:00
th33xitus
d1dff4d3b5 fix: logic error in build+flash function 2021-02-01 20:48:05 +01:00
th33xitus
49b7fe395b fix: detect an existing "legacy" klipper init.d installation 2021-01-31 18:34:05 +01:00
th33xitus
51469d8992 Update screenshot for KIAUH v3.0 2021-01-31 16:28:43 +01:00
th33xitus
16e6dde998 publish KIAUH v3.0 2021-01-31 16:20:52 +01:00
th33xitus
431f58af4b fix: code cleanup 2021-01-31 16:16:44 +01:00
th33xitus
c3af82745b Update docs 2021-01-31 16:09:00 +01:00
th33xitus
26eecbc94b fix: refactor main menu, add dwc and octoprint commands 2021-01-31 15:59:50 +01:00
th33xitus
fa8a9ff7ba fix: don't use systemctl commands anymore for reading the status if a service is installed and how much instances. instead only count the service files in /etc/systemd/system. this significantly improves performance of the script on low power hardware like a pi zero 2021-01-31 14:04:23 +01:00
th33xitus
dc08d8e7e3 fix: should fix #65 2021-01-31 13:32:16 +01:00
th33xitus
d0b895a469 fix.: make warning more clear 2021-01-30 20:42:32 +01:00
th33xitus
5aaebc2bec fix: add new cors domain to allow other ports than 80 only too. 2021-01-30 19:34:41 +01:00
th33xitus
538c179671 fix: visual bug in the webui installer 2021-01-30 19:33:38 +01:00
th33xitus
dc6fea8c3b fix: enable mainsail remoteMode if its already installed before moonraker 2021-01-30 18:19:49 +01:00
th33xitus
82227f8d0b fix: bug while creating the kiauh_macros.cfg 2021-01-30 16:13:20 +01:00
th33xitus
31c3f344e5 fix: add dialog: ask user to remove moonraker after klipper 2021-01-30 15:54:28 +01:00
th33xitus
a7b7b362f3 fix: typo in moonraker instance count status 2021-01-30 15:43:59 +01:00
th33xitus
5f142da1b6 fix: activate remoteMode for mainsail when moonraker multi-instances are found 2021-01-30 14:57:38 +01:00
th33xitus
99209f97de fix: refactor webui installer 2021-01-30 14:19:51 +01:00
th33xitus
8a64fe495e fix: add inactive klipperscreen entry to moonraker.conf 2021-01-30 12:52:58 +01:00
th33xitus
c3468c04e4 fix: bug when creating the local network ip range for moonraker.conf 2021-01-30 10:15:24 +01:00
th33xitus
2ef3273b74 fix: make remove function now also remove disabled octoprint services 2021-01-29 20:23:55 +01:00
th33xitus
47cf96ef74 fix: more verbose error message 2021-01-29 20:12:53 +01:00
th33xitus
17524bf49b fix: lock changing config folder function until klipper was installed through kiauh. 2021-01-29 20:10:04 +01:00
th33xitus
0d29bf9f31 fix: wording, description dialog 2021-01-29 18:00:47 +01:00
th33xitus
6105122467 fix: better explanation in the macro dialog 2021-01-29 17:13:19 +01:00
th33xitus
55dad5ffb6 fix: switch back to stephans repo, PR was merged. 2021-01-29 15:14:13 +01:00
th33xitus
53aa86d138 fix: missed updating a file name 2021-01-29 13:28:10 +01:00
th33xitus
a0e53655bd fix: bug with sourcing the kiauh.ini and improve config change function 2021-01-29 12:17:42 +01:00
th33xitus
69d134d9d1 fix: rework .octoprint folder remove function to be able to remove multiple instances 2021-01-28 23:42:38 +01:00
th33xitus
7224040f8a fix: check for multiple installed and enabled octoprint services 2021-01-28 23:41:54 +01:00
th33xitus
1570fd588e fix: display disabled octoprint services as installed, and show the number of instances 2021-01-28 23:40:37 +01:00
th33xitus
0eb2d066be fix: rework dwc and octoprint service handling 2021-01-28 23:39:42 +01:00
th33xitus
61d1c46694 fix: dependency check was missing for moonraker installation 2021-01-28 22:57:35 +01:00
th33xitus
04f204e4c7 fix: re-arrange mainsail and fluidd 2021-01-28 18:56:11 +01:00
th33xitus
f8aa88f480 fix: rework menus and UI 2021-01-28 18:54:02 +01:00
th33xitus
0c4f1a5378 fix: rework/refactor remove functions 2021-01-28 18:52:53 +01:00
th33xitus
4652e5c177 fix: added one more cors domain and changed ip-range for local network 2021-01-28 18:02:21 +01:00
th33xitus
a6156ebdf3 fix: make kiauh.ini a hidden file in users home folder 2021-01-28 17:56:23 +01:00
th33xitus
1c92987b42 fix: logic error 2021-01-28 17:50:35 +01:00
th33xitus
d01140638a fix: some typos when creating minimal cfg 2021-01-28 16:48:36 +01:00
th33xitus
254e1b8244 fix: create mainsail or fluidd nginx config from template 2021-01-28 16:45:12 +01:00
th33xitus
19aed15db0 fix: typos 2021-01-28 16:44:05 +01:00
th33xitus
b2b19f446b fix: use $klipper_cfg_loc in klipperscreen system check 2021-01-28 16:25:25 +01:00
th33xitus
8ad7f5d47c fix: remove update manager question. thanks to the recent changes to the update manager, mainsail and fluidd can be supported at the same time. 2021-01-28 16:21:24 +01:00
th33xitus
69eb96d006 fix: typo in moonraker backup function 2021-01-28 16:20:35 +01:00
th33xitus
e233d8435a fix: new date format, fix a typo, restructure backup.sh 2021-01-27 19:57:19 +01:00
th33xitus
fb52c7e4ab fix: relocate the kiauh.ini file to ~/.config to keep values even after reinstalling kiauh. 2021-01-27 18:51:48 +01:00
th33xitus
bc53de626f fix: version comparing and displaying issues 2021-01-27 18:13:21 +01:00
th33xitus
f10a604f97 fix: small clean-up 2021-01-25 19:09:30 +01:00
th33xitus
1527d7a25d Merge remote-tracking branch 'origin/master' into kiauh-rework 2021-01-25 19:01:55 +01:00
th33xitus
65062bdfda fix: update the macros used for pause, cancel resume by mainsail and fluidd to better ones 2021-01-25 18:51:31 +01:00
th33xitus
e3d242017d fix: update a comment in nginx configs 2021-01-25 18:50:49 +01:00
th33xitus
c14289a8a6 fix: add the new update manager entries to moonraker.conf 2021-01-25 18:50:25 +01:00
th33xitus
d9e697216f fix: small dwc2 related fixes 2021-01-21 23:47:29 +01:00
th33xitus
d958c1ba2a fix: prepare for possible multi instance capabilities of dwc2-for-klipper-socket 2021-01-21 23:34:25 +01:00
th33xitus
fb1d3a8cd9 fix: dwc installer rework, only for single instance atm. multi instance tbd... 2021-01-21 17:38:21 +01:00
th33xitus
7eb0fe24f8 fix: some typos in moonraker installer 2021-01-21 17:35:21 +01:00
th33xitus
738269adae fix: make use of the delivered .version files to read mainsail and fluidd version 2021-01-21 11:28:31 +01:00
th33xitus
d098eef08e fix: rename files to their correct name 2021-01-21 10:28:04 +01:00
th33xitus
598c106c3a fix: correct mainsail url 2021-01-21 10:23:08 +01:00
th33xitus
51207e2eb9 fix: remove file, config.yaml gets dynamically created now 2021-01-20 20:25:48 +01:00
th33xitus
ee252d185a fix: update octoprint installer for multi instances 2021-01-20 20:24:24 +01:00
th33xitus
cf1e37fb2a fix: rework octoprint remove function for removing multi instances 2021-01-20 20:23:55 +01:00
th33xitus
3d9722f877 fix: rename array 2021-01-20 20:19:53 +01:00
th33xitus
1ef67fa05c fix: insert blank lines in output 2021-01-20 15:16:41 +01:00
th33xitus
db856de8e5 fix: fix shell command installation 2021-01-20 15:16:22 +01:00
th33xitus
4748c15424 fix: update UI nginx configs 2021-01-20 15:00:12 +01:00
th33xitus
ab9d73b5b5 fix: minimal cfg 2021-01-20 14:55:20 +01:00
th33xitus
6c33282d43 fix: refactor main_menu 2021-01-17 14:50:55 +01:00
th33xitus
e71f1b9dfd fix: refactor install_menu 2021-01-17 14:44:10 +01:00
th33xitus
e24afa42ac fix: made log upload function multi instance capable 2021-01-17 14:29:36 +01:00
th33xitus
2fa975e3c2 fix: missed closing an if statement 2021-01-17 14:29:06 +01:00
th33xitus
feb912da8a fix: make adding the kiauh_macros optional 2021-01-17 12:58:25 +01:00
th33xitus
e5ce642018 fix: reorder the klippy_uds to the bottom 2021-01-17 12:44:42 +01:00
th33xitus
7a4ccfe4df fix: remove the functionality of patching an old/existing moonraker.conf only for making it compatible again. it will be way easier now to simply re-install moonraker and let those configs be created from scratch. 2021-01-17 11:50:20 +01:00
th33xitus
6b2175e439 fix: make klipperscreen installer use the klipper_cfg_loc variable for the printer config directory 2021-01-17 11:28:14 +01:00
th33xitus
dd2a26e2d0 del: remove now unused moonraker.conf template from resources 2021-01-17 11:23:26 +01:00
th33xitus
cd1489f0e5 fix: move the update manager function to the webinterface installations 2021-01-17 11:20:57 +01:00
th33xitus
d705a043c9 fix: add more trusted clients, cors domains, auto create a config folder if missing for whatever reason 2021-01-17 11:19:22 +01:00
th33xitus
c1a21c52b6 fix: create cfg directories if they are missing for whatever reason. 2021-01-17 11:18:09 +01:00
th33xitus
94762727ae fix: rename webui_macros.cfg to kiauh_macros.cfg 2021-01-17 11:17:37 +01:00
th33xitus
9cde005e08 fix: better default park position for printers with less than 230mm on x and y 2021-01-15 20:10:19 +01:00
th33xitus
86e7f37f7b fix: bigger refactoring of the klipper webui installer 2021-01-15 19:52:56 +01:00
th33xitus
4d2eb49e85 fix: big refactoring of the moonraker installer 2021-01-15 17:52:04 +01:00
th33xitus
715ab5f4e2 fix: display instance count in main menu status 2021-01-15 17:50:43 +01:00
th33xitus
146586f894 fix: correct mjpgstreamer port 2021-01-13 18:04:36 +01:00
th33xitus
bd78fa8ef7 add: quick and simple solution to start, stop, restart klipper/moonraker from within the main menu 2021-01-10 13:05:58 +01:00
th33xitus
b12d344b40 fix: update the config folder change function (its more like a "rename only" function now and should be plenty sufficient?) 2021-01-10 12:55:24 +01:00
th33xitus
9ea29bf995 fix: introduce new/better folder structure for multi instance setups 2021-01-09 23:17:45 +01:00
th33xitus
d066999d0b fix: little UI fixes 2021-01-09 18:02:59 +01:00
th33xitus
1ab681e71a fix: enable python3 check again, display moonraker IP at the end of the setup 2021-01-09 16:49:10 +01:00
th33xitus
f782a32e9c fix: bug in assigning correct port to instances 2021-01-09 16:08:29 +01:00
th33xitus
7dc1bc6cc8 fix: add full range of local network to auto-created moonraker.conf files 2021-01-08 20:02:58 +01:00
th33xitus
2a29716bb9 fix: make mcu ids verbose again for easier copy pasting into configs 2021-01-08 20:02:18 +01:00
th33xitus
33a9fef676 fix: check via md5sum of requirements text file if an update of the python env is necessary. if yes, do that update automatically. no user interaction anymore. 2021-01-08 14:57:51 +01:00
th33xitus
88afa55268 feat: support flashing of multiple connected mcus 2021-01-08 13:56:36 +01:00
th33xitus
65ec2e5e1a fix: bugs 2021-01-07 17:03:14 +01:00
th33xitus
08c1807cc7 fix: forgot to stop services first 2021-01-07 16:40:52 +01:00
th33xitus
218700b63d fix: add remove method for init.d moonraker service 2021-01-07 16:27:51 +01:00
th33xitus
bb1c5c4900 fix: add remove method for removing old init.d klipper service 2021-01-07 16:25:31 +01:00
th33xitus
08ae57d349 initial commit of a bigger kiauh rework to make multi instance installations possible 2021-01-07 15:26:19 +01:00
th33xitus
61dfab5683 feat: klipper config backup function 2021-01-07 15:24:25 +01:00
46 changed files with 3325 additions and 2348 deletions

View File

@@ -1,6 +1,6 @@
# **KIAUH - Klipper Installation And Update Helper** # **KIAUH - Klipper Installation And Update Helper**
![main_menu](resources/screenshots/main.png) ![main_menu](resources/screenshots/main_v3.png)
--- ---
@@ -12,42 +12,37 @@
This script acts as a helping hand for you to get set up in a fast and comfortable way.\ This script acts as a helping hand for you to get set up in a fast and comfortable way.\
**This does not mean, it will relieve you of using your brain.exe! 🧠**\ **This does not mean, it will relieve you of using your brain.exe! 🧠**\
Please also always pay attention to the individual component repositories (all linked below).\
Feel free to give it a try. If you have suggestions or encounter any problems, please report them. Feel free to give it a try. If you have suggestions or encounter any problems, please report them.
--- ---
## **🛠️ Instructions:** ## **🛠️ Instructions:**
For downloading this script it is best to have git already installed.\ For downloading this script it is necessary to have git installed.\
If you haven't, please run `sudo apt-get install git -y` to install git first.\ If you haven't, please run `sudo apt-get install git -y` to install git first.\
You will need it anyways! You will need it anyways! 😄
After git is installed, use the following commands in the given order to download and execute the script: After git is installed, use the following commands in the given order to download and execute the script:
```shell ```shell
cd ~ cd ~
git clone https://github.com/th33xitus/kiauh.git git clone https://github.com/th33xitus/kiauh.git
cd kiauh ./kiauh/kiauh.sh
chmod +x kiauh.sh scripts/*
./kiauh.sh
``` ```
## Additional Instructions:
If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website:\
[Installing Klipper and Mainsail](https://3dp.tumbleweedlabs.com/firmware/klipper-firmware/installing-klipper-and-mainsail-on-your-raspberry-pi)\
Credits for these instructions go to [@tumbleweedlabs](https://github.com/tumbleweedlabs).\
Feel free to check out his work.
--- ---
## **🧰 Functions and Features:** ## **🧰 Functions and Features:**
- **New in v3.0.0:** You can now install multiple instances (Klipper/Moonraker/DWC/Octoprint) on the same Pi!
---
### **Core Functions:** ### **Core Functions:**
- **Installing** of the Klipper Firmware to your Raspberry Pi or other Linux Distribution which makes use of init.d. - **Installing** Klipper to your Raspberry Pi or other Debian based Linux Distribution.
- **Installing** of several different web interfaces such as Duet Web Control, Mainsail, Fluidd or OctoPrint including their dependencies. - **Installing** of the Moonraker API (needed for Mainsail, Fluidd and KlipperScreen)
- **Installing** of the Moonraker API - **Installing** several different web interfaces such as Mainsail, Fluidd, Duet Web Control or OctoPrint including their dependencies.
- **Installing** of KlipperScreen (OctoScreen but for Klipper!)
- **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface! - **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface!
- **Removing** of all the listed installations above. - **Removing** of all the listed installations above.
- **Backup** of all the listed installations above. - **Backup** of all the listed installations above.
@@ -56,8 +51,7 @@ Feel free to check out his work.
- Build the Klipper Firmware - Build the Klipper Firmware
- Flash the MCU - Flash the MCU
- Read ID of the currently connected printer (only one at the time) - Read ID of the currently connected MCU
- Write necessary entries to your printer.cfg, some of them customizable right in the CLI.
- and more ... - and more ...
### **For a list of additional features please see: [Feature List](docs/features.md)** ### **For a list of additional features please see: [Feature List](docs/features.md)**
@@ -66,14 +60,16 @@ Feel free to check out his work.
## **📝 Notes:** ## **📝 Notes:**
- Tested **only** on Raspberry Pi OS Lite (Debian Buster) - Tested **only** on Raspberry Pi OS Lite (Debian 10 Buster)
- Other Debian based distributions can work
- Reported to work on Armbian too
- During the use of this script you might be asked for your sudo password. There are several functions involved which need sudo privileges. - During the use of this script you might be asked for your sudo password. There are several functions involved which need sudo privileges.
--- ---
## **🛈 Sources & Further Information** ## **🛈 Sources & Further Information**
For more information or instructions, please check out the appropriate repositories listed below: For more information or instructions to the various components KIAUH can install, please check out the corresponding repositories listed below:
--- ---
@@ -135,6 +131,6 @@ https://github.com/OctoPrint/OctoPrint
## **❓ FAQ** ## **❓ FAQ**
**_Q: Can i use this script to install multiple instancec of Klipper on the same Pi? (Multisession?)_** **_Q: Can i use this script to install multiple instances of Klipper on the same Pi? (Multisession?)_**
**A:** No, and at the moment i don't plan to implement this function. For multisession installations take a look at this script manu7irl created: https://github.com/manu7irl/klipper-DWC2-installer . Keep in mind that klipper-DWC2-installer and KIAUH are **NOT** compatible with each other. **A:** Yes, it is finally possible 🙂

View File

@@ -2,6 +2,89 @@
This document covers possible important changes to KIAUH. This document covers possible important changes to KIAUH.
### 2021-06-15
* Moonraker introduced an optional `log_path` which clients can make use of to show log files located in that folder to their users. More info here: https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a \
Client developers agreed upon using `~/klipper_logs` as the new default log path.\
That means, from now on, Klipper and Moonraker services installed with KIAUH will place their logfiles in that mentioned folder.
* Additionally, KIAUH will now detect Klipper and Moonraker systemd services that still use the old default location of `/tmp/<service>.log` and will update them next time the user updates Klipper and/or Moonraker with the KIAUH update function.
* Additional symlinks for the following logfiles will get created along those update procedures to make them accessible through the webinterface once its supported:
- webcamd.log
- mainsail-access.log
- mainsail-error.log
- fluidd-access.log
- fluidd-error.log
* For MainsailOS and FluiddPi users:\
MainsailOS and FluiddPi will switch the shipped Klipper service from SysVinit to systemd probably with their next release. KIAUH can already help migrate older MainsailOS (0.4.0 and below) and FluiddPi (v1.13.0) releases to match their new service-, file- and folder-structure so you don't have to re-flash the SD-Card of your Raspberry Pi.\
In detail here is what is going to happen when you use the new "CustomPiOS Migration Helper" from the Advanced Menu `(Main Menu -> 4 -> Enter -> 10 -> Enter)` in a short summary:
1) The Klipper SysVinit service will get replaced by a Klipper systemd service
2) Klipper and Moonraker will use the new log-directory `~/klipper_logs`
3) The webcamd service gets updated
4) The webcamd script gets updated and moved from `/root/bin/webcamd` to `/usr/local/bin/webcamd`
5) The NGINX `upstreams.conf` gets updated to be able to configure up to 4 webcams
6) The `mainsail.txt` / `fluiddpi.txt` gets moved from `/boot` to `~/klipper_config` and renamed to `webcam.txt`
7) Symlinks for the webcamd.log and various NGINX logs get created in `~/klipper_config`
8) Configuration files for Klipper, Moonraker and webcamd get added to `/etc/logrotate.d`
9) If they still exist, two lines will be removed from the mainsail.cfg or client_macros.cfg macro configurations:\
`SAVE_GCODE_STATE NAME=PAUSE_state` and
`RESTORE_GCODE_STATE NAME=PAUSE_state`\
* **Please note:**\
The "CustomPiOS Migration Helper" is intended to only work on "vanilla" MainsailOS and FluiddPi systems. Do not try to migrate a modified MainsailOS or FluiddPi system (for example if you already used KIAUH to re-install services or to set up a multi-instance installation for Klipper / Moonraker). This won't work.
### 2021-01-31
* **This is a big one... KIAUH v3.0 is out.**\
With this update you can now install multiple instances of Klipper, Moonraker, Duet Web Control or Octoprint on the same Pi. This was quite a big rework of the whole script. So bugs can appear but with the help of some testers, i think there shouldn't be any critical ones anymore. In this regards thanks to @lixxbox and @zellneralex for testing.
* Important changes to how installations are set up now: All components get installed as systemd services. Installation via init.d was dropped completely! This shouldn't affect you at all, since the common linux distributions like RaspberryPi OS or custom distributions like MainsailOS, FluiddPi or OctoPi support both ways of installing services. I just wanted to mention it here.
* Now with KIAUH v3.0 and multi-instance installation capabilities, there are some things to point out. You will now need to tell KIAUH where your printers configurations are located when installing Klipper for the first time. Even though it is not recommended, you can change this location with the help of KIAUH and rewrite Klipper and Moonraker to use the new location.
* When setting up a multi-instance system, the folder structure will only change slightly. The goal was to keep it as compatible as possible with the custom distributions like mainsailOS and FluiddPi. This should help converting a single-instance setup of mainsailOS/FluiddPi to a multi-instance setup in no time, but keeping single-instance backwards compatibility if needed at a later point in time.
* The folder structure is as follows when setting up multi-instances:\
Each printer instance will get its own folder within your configuration location. The decision to this specific structure was made to make it as painless and easy as possible to convert to a multi-instance setup.
Here is an example:
```shell
/home/<username>
└── klipper_config
├── printer_1
│ ├── printer.cfg
│ └── moonraker.conf
├── printer_2
│ ├── printer.cfg
│ └── moonraker.conf
└── printer_n
├── printer.cfg
└── moonraker.conf
```
* Also when setting up multi-instances of each service, the name of each service slightly changes.
Each service gets its corresponding instance added to the service filename.
**This only applies to multi-instances! Single instance installations with KIAUH will keep their original names!**
Corresponding to the filetree example from above that would mean:
```
Klipper services:
--> klipper-1.service
--> klipper-2.service
--> klipper-n.service
Moonraker services:
--> moonraker-1.service
--> moonraker-2.service
--> moonraker-n.service
```
* The same service file rules from above apply to DWC and OctoPrint even though only Klipper and Moonraker are shown in this example.
* You can start, stop and restart all Klipper, Moonraker, DWC and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on.
* KIAUH v3.0 relocated its ini-file. It is now a hidden file in the users home-directory calles `.kiauh.ini`. This has the benefit of keeping all values in that file between possible re-installations of KIAUH. Otherwise that file would be lost.
* The option of adding more trusted clients to the moonraker.conf file was dropped. Since you can edit this file right inside of Mainsail or Fluidd, only some basic entries are made which get you running.
* I bet i have missed mentioning other stuff as well because it took me quite some time to re-write many functions. So i just hope you like the new version 😄
### 2020-11-28 ### 2020-11-28
* KIAUH now supports the installation, update and removal of [KlipperScreen](https://github.com/jordanruthe/KlipperScreen). This feature was was provided by [jordanruthe](https://github.com/jordanruthe)! Thank you! * KIAUH now supports the installation, update and removal of [KlipperScreen](https://github.com/jordanruthe/KlipperScreen). This feature was was provided by [jordanruthe](https://github.com/jordanruthe)! Thank you!

View File

@@ -17,11 +17,6 @@ That means:
- set the behavior to "Cancel any ongoing prints but stay connected to the printer" - set the behavior to "Cancel any ongoing prints but stay connected to the printer"
- **Enable/Disable OctoPrint Service:**\ - **Enable/Disable OctoPrint Service:**\
Usefull when using DWC2/Mainsail/Fluidd and OctoPrint at the same time to prevent them interfering with each other Usefull when using DWC2/Mainsail/Fluidd and OctoPrint at the same time to prevent them interfering with each other
- **Set up reverse proxy for DWC2, Mainsail, Fluidd and OctoPrint and changing the hostname:**
- The script can install and configure Nginx for the selected webinterface
- It also allows you to make your webinterface reachable over an URL like `<hostname>.local` via avahi
- Example: If you name the host "my-printer", type `my-printer.local` in your webbrowser to open the installed webinterface
- If there is more than one webinterface installed, you have to append the port to that adress
- **Installing a G-Code Shell Command extension:**\ - **Installing a G-Code Shell Command extension:**\
For further information about that extension please see the [G-Code Shell Command Extension Doc](gcode_shell_command.md) For further information about that extension please see the [G-Code Shell Command Extension Doc](gcode_shell_command.md)

View File

@@ -17,19 +17,14 @@ for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done
### set important directories ### set important directories
#klipper #klipper
KLIPPER_DIR=${HOME}/klipper KLIPPER_DIR=${HOME}/klipper
KLIPPY_ENV_DIR=${HOME}/klippy-env KLIPPY_ENV=${HOME}/klippy-env
KLIPPER_SERVICE1=/etc/init.d/klipper
KLIPPER_SERVICE2=/etc/default/klipper
KLIPPER_SERVICE3=/etc/systemd/system/klipper.service
#nginx #nginx
NGINX_SA=/etc/nginx/sites-available NGINX_SA=/etc/nginx/sites-available
NGINX_SE=/etc/nginx/sites-enabled NGINX_SE=/etc/nginx/sites-enabled
NGINX_CONFD=/etc/nginx/conf.d NGINX_CONFD=/etc/nginx/conf.d
#moonraker #moonraker
MOONRAKER_DIR=${HOME}/moonraker MOONRAKER_DIR=${HOME}/moonraker
MOONRAKER_ENV_DIR=${HOME}/moonraker-env MOONRAKER_ENV=${HOME}/moonraker-env
MOONRAKER_SERVICE1=/etc/init.d/moonraker
MOONRAKER_SERVICE2=/etc/default/moonraker
#mainsail #mainsail
MAINSAIL_DIR=${HOME}/mainsail MAINSAIL_DIR=${HOME}/mainsail
#fluidd #fluidd
@@ -37,17 +32,14 @@ FLUIDD_DIR=${HOME}/fluidd
#dwc2 #dwc2
DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket
DWC_ENV_DIR=${HOME}/dwc-env DWC_ENV_DIR=${HOME}/dwc-env
DWC2_DIR=${HOME}/sdcard/web DWC2_DIR=${HOME}/duetwebcontrol
#octoprint #octoprint
OCTOPRINT_DIR=${HOME}/OctoPrint OCTOPRINT_DIR=${HOME}/OctoPrint
OCTOPRINT_CFG_DIR=${HOME}/.octoprint
OCTOPRINT_SERVICE1=/etc/init.d/octoprint
OCTOPRINT_SERVICE2=/etc/default/octoprint
#KlipperScreen #KlipperScreen
KLIPPERSCREEN_DIR=${HOME}/KlipperScreen KLIPPERSCREEN_DIR=${HOME}/KlipperScreen
KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env
#misc #misc
INI_FILE=${SRCDIR}/kiauh/kiauh.ini INI_FILE=${HOME}/.kiauh.ini
BACKUP_DIR=${HOME}/kiauh-backups BACKUP_DIR=${HOME}/kiauh-backups
### set github repos ### set github repos
@@ -55,7 +47,6 @@ KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git
ARKSINE_REPO=https://github.com/Arksine/klipper.git ARKSINE_REPO=https://github.com/Arksine/klipper.git
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git
MOONRAKER_REPO=https://github.com/Arksine/moonraker.git
KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git
#branches #branches
BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing
@@ -75,7 +66,7 @@ title_msg(){
echo -e "${cyan}$1${default}" echo -e "${cyan}$1${default}"
} }
get_date(){ get_date(){
current_date=$(date +"%Y-%m-%d_%H-%M") current_date=$(date +"%y%m%d-%H%M")
} }
print_unkown_cmd(){ print_unkown_cmd(){
ERROR_MSG="Invalid command!" ERROR_MSG="Invalid command!"

View File

@@ -40,13 +40,11 @@ grab_version(){
cd .. cd ..
fi fi
if [ ! -z "$mainsail_folder" ]; then if [ ! -z "$mainsail_folder" ]; then
mainsail_file=$(find $mainsail_folder/js -name "app.*.js" 2>/dev/null) mainsail_ver=$(head -n 1 $mainsail_folder/.version)
mainsail_ver=$(grep -o -E 'state:{packageVersion:.+' $mainsail_file | cut -d'"' -f2)
m3="Mainsail version: $mainsail_ver" m3="Mainsail version: $mainsail_ver"
fi fi
if [ ! -z "$fluidd_folder" ]; then if [ ! -z "$fluidd_folder" ]; then
fluidd_file=$(find $fluidd_folder/js -name "app.*.js" 2>/dev/null) fluidd_ver=$(head -n 1 $fluidd_folder/.version)
fluidd_ver=$(grep -o -E '"setVersion",".+"' $fluidd_file | cut -d'"' -f4)
m4="Fluidd version: $fluidd_ver" m4="Fluidd version: $fluidd_ver"
fi fi
} }

View File

@@ -1,87 +0,0 @@
# /etc/nginx/sites-available/fluidd
server {
listen 80;
listen [::]:80;
access_log /var/log/nginx/fluidd-access.log;
error_log /var/log/nginx/fluidd-error.log;
#disable this section on smaller hardware like a pi zero
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
#web_path from fluidd static files
root /home/pi/fluidd;
index index.html;
server_name _;
#max upload size for gcodes
client_max_body_size 0;
location / {
try_files $uri $uri/ /index.html;
}
location /printer {
proxy_pass http://apiserver/printer;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /api {
proxy_pass http://apiserver/api;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /access {
proxy_pass http://apiserver/access;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /websocket {
proxy_pass http://apiserver/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400;
}
location /machine {
proxy_pass http://apiserver/machine;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /server {
proxy_pass http://apiserver/server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /webcam/ {
proxy_pass http://mjpgstreamer/;
}
}

View File

@@ -0,0 +1,59 @@
################################################################################
# ~~~~~~~~~~~~~~~~~~~~~~~~ AUTOCREATED WITH KIAUH ~~~~~~~~~~~~~~~~~~~~~~~~~~ #
################################################################################
# Recommended macros and config entries if you use Mainsail or Fluidd! #
# You can edit or delete those macros if you already defined them elsewhere! #
################################################################################
[pause_resume]
[display_status]
[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
TURN_OFF_HEATERS
CLEAR_PAUSE
SDCARD_RESET_FILE
BASE_CANCEL_PRINT
[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
gcode:
##### set defaults #####
{% set x = params.X|default(230) %} #edit to your park position
{% set y = params.Y|default(230) %} #edit to your park position
{% set z = params.Z|default(10)|float %} #edit to your park position
{% set e = params.E|default(1) %} #edit to your retract length
##### calculate save lift position #####
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% set lift_z = z|abs %}
{% if act_z < (max_z - lift_z) %}
{% set z_safe = lift_z %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
##### end of definitions #####
SAVE_GCODE_STATE NAME=PAUSE_state
BASE_PAUSE
G91
G1 E-{e} F2100
G1 Z{z_safe}
G90
G1 X{x} Y{y} F6000
[gcode_macro RESUME]
rename_existing: BASE_RESUME
gcode:
##### set defaults #####
{% set e = params.E|default(1) %} #edit to your retract length
G91
G1 E{e} F2100
G90
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
BASE_RESUME
################################################################################
################################################################################

15
resources/klipper.service Normal file
View File

@@ -0,0 +1,15 @@
#Systemd service file for klipper
[Unit]
Description=Starts klipper instance %INST% on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=%USER%
RemainAfterExit=yes
ExecStart=%KL_ENV%/bin/python %KL_DIR%/klippy/klippy.py %P_CFG% -I %P_TMP% -l %KL_LOG% -a %KL_UDS%
Restart=always
RestartSec=10

View File

@@ -0,0 +1,61 @@
# /etc/nginx/sites-available/<<UI>>
server {
listen 80;
access_log /var/log/nginx/<<UI>>-access.log;
error_log /var/log/nginx/<<UI>>-error.log;
# disable this section on smaller hardware like a pi zero
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
# web_path from <<UI>> static files
root /home/pi/<<UI>>;
index index.html;
server_name _;
# disable max upload size checks
client_max_body_size 0;
# disable proxy request buffering
proxy_request_buffering off;
location / {
try_files $uri $uri/ /index.html;
}
location = /index.html {
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
location /websocket {
proxy_pass http://apiserver/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400;
}
location ~ ^/(printer|api|access|machine|server)/ {
proxy_pass http://apiserver$request_uri;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /webcam/ {
proxy_pass http://mjpgstreamer/;
}
}

View File

@@ -1,87 +0,0 @@
# /etc/nginx/sites-available/mainsail
server {
listen 80;
listen [::]:80;
access_log /var/log/nginx/mainsail-access.log;
error_log /var/log/nginx/mainsail-error.log;
#disable this section on smaller hardware like a pi zero
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
#web_path from mainsail static files
root /home/pi/mainsail;
index index.html;
server_name _;
#max upload size for gcodes
client_max_body_size 0;
location / {
try_files $uri $uri/ /index.html;
}
location /printer {
proxy_pass http://apiserver/printer;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /api {
proxy_pass http://apiserver/api;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /access {
proxy_pass http://apiserver/access;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /websocket {
proxy_pass http://apiserver/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400;
}
location /machine {
proxy_pass http://apiserver/machine;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /server {
proxy_pass http://apiserver/server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
location /webcam/ {
proxy_pass http://mjpgstreamer/;
}
}

View File

@@ -1,10 +1,44 @@
[server] [server]
host: 0.0.0.0 host: 0.0.0.0
port: 7125 port: %PORT%
enable_debug_logging: True enable_debug_logging: False
config_path: ~/klipper_config config_path: %CFG%
log_path: %LOG%
database_path: %MR_DB%
klippy_uds_address: %UDS%
[authorization] [authorization]
enabled: True
trusted_clients: trusted_clients:
127.0.0.1 127.0.0.1
%LAN%
::1/128
FE80::/10
cors_domains:
*.lan
*.local
*://my.mainsail.xyz
*://app.fluidd.xyz
[octoprint_compat]
[history]
[update_manager]
[update_manager client mainsail]
type: web
repo: meteyou/mainsail
path: ~/mainsail
[update_manager client fluidd]
type: web
repo: cadriel/fluidd
path: ~/fluidd
#[update_manager client KlipperScreen]
#type: git_repo
#path: /home/%USER%/KlipperScreen
#origin: https://github.com/jordanruthe/KlipperScreen.git
#env: /home/%USER%/.KlipperScreen-env/bin/python
#requirements: scripts/KlipperScreen-requirements.txt
#install_script: scripts/KlipperScreen-install.sh

View File

@@ -0,0 +1,15 @@
#Systemd service file for moonraker
[Unit]
Description=Starts Moonraker %INST% on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=%USER%
RemainAfterExit=yes
ExecStart=%MR_ENV%/bin/python %MR_DIR%/moonraker/moonraker.py -l %MR_LOG% -c %MR_CONF%
Restart=always
RestartSec=10

View File

@@ -1,10 +0,0 @@
serial:
additionalPorts:
- /tmp/printer
disconnectOnErrors: false
port: /tmp/printer
server:
commands:
serverRestartCommand: sudo service octoprint restart
systemRestartCommand: sudo shutdown -r now
systemShutdownCommand: sudo shutdown -h now

14
resources/printer.cfg Normal file
View File

@@ -0,0 +1,14 @@
[mcu]
serial: /dev/serial/by-id/<your-mcu-id>
[pause_resume]
[display_status]
[virtual_sdcard]
path: ~/gcode_files
[printer]
kinematics: none
max_velocity: 1000
max_accel: 1000

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -0,0 +1,7 @@
[gcode_shell_command hello_world]
command: echo hello world
timeout: 2.
verbose: True
[gcode_macro HELLO_WORLD]
gcode:
RUN_SHELL_COMMAND CMD=hello_world

16
resources/webcamd.service Normal file
View File

@@ -0,0 +1,16 @@
[Unit]
Description=Starts mjpg-streamer on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
User=%USER%
WorkingDirectory=/usr/local/bin
StandardOutput=append:/var/log/webcamd.log
StandardError=append:/var/log/webcamd.log
ExecStart=/usr/local/bin/webcamd
Restart=always
RestartSec=10

View File

@@ -1,38 +0,0 @@
### AUTOCREATED WITH KIAUH ###
#is required to load the pause_resume module in klipper
[pause_resume]
[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
default_parameter_X: 230 #edit to your park position
default_parameter_Y: 230 #edit to your park position
default_parameter_Z: 10 #edit to your park position
default_parameter_E: 1 #edit to your retract length
gcode:
SAVE_GCODE_STATE NAME=PAUSE_state
BASE_PAUSE
G91
G1 E-{E} F2100
G1 Z{Z}
G90
G1 X{X} Y{Y} F6000
[gcode_macro RESUME]
rename_existing: BASE_RESUME
default_parameter_E: 1 #edit to your retract length
gcode:
G91
G1 E{E} F2100
G90
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
BASE_RESUME
[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
TURN_OFF_HEATERS
CLEAR_PAUSE
SDCARD_RESET_FILE
BASE_CANCEL_PRINT
##########################
##########################

View File

@@ -5,39 +5,8 @@ check_for_backup_dir(){
fi fi
} }
backup_printer_cfg(){
check_for_backup_dir
if [ -f $PRINTER_CFG ]; then
get_date
status_msg "Create backup of printer.cfg ..."
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!"
else
ok_msg "No printer.cfg found! Skipping backup ..."
fi
}
backup_moonraker_conf(){
check_for_backup_dir
if [ -f ${HOME}/moonraker.conf ]; then
get_date
status_msg "Create backup of moonraker.conf ..."
cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!"
else
ok_msg "No moonraker.conf found! Skipping backup ..."
fi
}
read_bb4u_stat(){
source_ini
if [ ! "$backup_before_update" = "true" ]; then
BB4U_STATUS="${green}[Enable]${default} backups before updating "
else
BB4U_STATUS="${red}[Disable]${default} backups before updating "
fi
}
toggle_backups(){ toggle_backups(){
source_ini source_kiauh_ini
if [ "$backup_before_update" = "true" ]; then if [ "$backup_before_update" = "true" ]; then
sed -i '/backup_before_update=/s/true/false/' $INI_FILE sed -i '/backup_before_update=/s/true/false/' $INI_FILE
BB4U_STATUS="${green}[Enable]${default} backups before updating " BB4U_STATUS="${green}[Enable]${default} backups before updating "
@@ -51,20 +20,80 @@ toggle_backups(){
} }
bb4u(){ bb4u(){
source_ini source_kiauh_ini
if [ "$backup_before_update" = "true" ]; then if [ "$backup_before_update" = "true" ]; then
backup_$1 backup_$1
fi fi
} }
read_bb4u_stat(){
source_kiauh_ini
if [ ! "$backup_before_update" = "true" ]; then
BB4U_STATUS="${green}[Enable]${default} backups before updating "
else
BB4U_STATUS="${red}[Disable]${default} backups before updating "
fi
}
################################################################################
#******************************************************************************#
################################################################################
backup_printer_cfg(){
check_for_backup_dir
if [ -f $PRINTER_CFG ]; then
get_date
status_msg "Timestamp: $current_date"
status_msg "Create backup of printer.cfg ..."
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!"
else
ok_msg "No printer.cfg found! Skipping backup ..."
fi
}
backup_klipper_config_dir(){
source_kiauh_ini
check_for_backup_dir
if [ -d "$klipper_cfg_loc" ]; then
get_date
status_msg "Timestamp: $current_date"
status_msg "Create backup of the Klipper config directory ..."
config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)"
mkdir -p $BACKUP_DIR/$config_folder_name/$current_date
cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!"
echo
else
ok_msg "No config directory found! Skipping backup ..."
echo
fi
}
backup_moonraker_database(){
check_for_backup_dir
if ls -d ${HOME}/.moonraker_database* 2>/dev/null 1>&2; then
get_date
status_msg "Timestamp: $current_date"
mkdir -p "$BACKUP_DIR/mr_db_backup/$current_date"
for database in $(ls -d ${HOME}/.moonraker_database*)
do
status_msg "Create backup of $database ..."
cp -r $database "$BACKUP_DIR/mr_db_backup/$current_date"
ok_msg "Done!"
done
ok_msg "Backup complete!\n"
else
ok_msg "No Moonraker database found! Skipping backup ..."
fi
}
backup_klipper(){ backup_klipper(){
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV_DIR ]; then if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then
status_msg "Creating Klipper backup ..." status_msg "Creating Klipper backup ..."
check_for_backup_dir check_for_backup_dir
get_date get_date
status_msg "Timestamp: $current_date" status_msg "Timestamp: $current_date"
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date" mkdir -p $BACKUP_DIR/klipper-backups/"$current_date"
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV_DIR $_ && ok_msg "Backup complete!" cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!"
else else
ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!" ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!"
fi fi
@@ -111,13 +140,13 @@ backup_fluidd(){
} }
backup_moonraker(){ backup_moonraker(){
if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV_DIR ]; then if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV ]; then
status_msg "Creating Moonraker backup ..." status_msg "Creating Moonraker backup ..."
check_for_backup_dir check_for_backup_dir
get_date get_date
status_msg "Timestamp: $current_date" status_msg "Timestamp: $current_date"
mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date" mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date"
cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV_DIR $_ && ok_msg "Backup complete!" cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV $_ && ok_msg "Backup complete!"
else else
ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!" ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!"
fi fi

View File

@@ -1,3 +1,6 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
# setting up some frequently used functions # setting up some frequently used functions
check_euid(){ check_euid(){
if [ "$EUID" -eq 0 ] if [ "$EUID" -eq 0 ]
@@ -11,130 +14,247 @@ check_euid(){
fi fi
} }
locate_printer_cfg(){ check_klipper_cfg_path(){
unset PRINTER_CFG source_kiauh_ini
if [ -e $KLIPPER_SERVICE2 ]; then if [ -z $klipper_cfg_loc ]; then
status_msg "Locating printer.cfg via $KLIPPER_SERVICE2 ..." echo
#reads /etc/default/klipper and gets the default printer.cfg location top_border
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)" echo -e "| ${red}!!! WARNING !!!${default} |"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)" echo -e "| ${red}No Klipper configuration directory set!${default} |"
i=1 hr
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/default/klipper | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg") echo -e "| Before we can continue, KIAUH needs to know where |"
ok_msg "printer.cfg location: '$PRINTER_CFG'" echo -e "| you want your printer configuration to be. |"
elif [ -e $KLIPPER_SERVICE3 ]; then blank_line
status_msg "Locating printer.cfg via $KLIPPER_SERVICE3 ..." echo -e "| Please specify a folder where your Klipper configu- |"
#reads /etc/systemd/system/klipper.service and gets the default printer.cfg location echo -e "| ration is stored or, if you don't have one yet, in |"
KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)" echo -e "| which it should be saved after the installation. |"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)" bottom_border
i=1 change_klipper_cfg_path
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/systemd/system/klipper.service | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg") fi
ok_msg "printer.cfg location: '$PRINTER_CFG'" }
change_klipper_cfg_path(){
source_kiauh_ini
old_klipper_cfg_loc="$klipper_cfg_loc"
EXAMPLE_FOLDER=$(printf "%s/your_config_folder" "${HOME}")
while true; do
top_border
echo -e "| ${red}IMPORTANT:${default} |"
echo -e "| Please enter the new path in the following format: |"
printf "| ${yellow}%-51s${default} |\n" "$EXAMPLE_FOLDER"
blank_line
echo -e "| By default 'klipper_config' is recommended! |"
bottom_border
echo
echo -e "${cyan}###### Please set the Klipper config directory:${default} "
if [ -z "$old_klipper_cfg_loc" ]; then
read -e -i "/home/${USER}/klipper_config" -e new_klipper_cfg_loc
else else
PRINTER_CFG="" read -e -i "$old_klipper_cfg_loc" -e new_klipper_cfg_loc
warn_msg "Can't read printer.cfg location!" fi
echo
read -p "${cyan}###### Set config directory to '${yellow}$new_klipper_cfg_loc${cyan}' ? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
### backup the old config dir
backup_klipper_config_dir
### write new location to kiauh.ini
sed -i "s|klipper_cfg_loc=$old_klipper_cfg_loc|klipper_cfg_loc=$new_klipper_cfg_loc|" $INI_FILE
status_msg "Directory set to '$new_klipper_cfg_loc'!"
### write new location to klipper and moonraker service
set_klipper_cfg_path
echo; ok_msg "Config directory changed!"
break;;
N|n|No|no)
echo -e "###### > No"
change_klipper_cfg_path
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
set_klipper_cfg_path(){
### stop services
klipper_service "stop" && moonraker_service "stop"
### copy config files to new klipper config folder
if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then
if [ ! -d "$new_klipper_cfg_loc" ]; then
status_msg "Copy config files to '$new_klipper_cfg_loc' ..."
mkdir -p $new_klipper_cfg_loc
cd $old_klipper_cfg_loc
cp -r -v ./* $new_klipper_cfg_loc
ok_msg "Done!"
fi
fi
### handle single klipper instance service file
if [ -f $SYSTEMDDIR/klipper.service ]; then
status_msg "Configuring Klipper for new path ..."
sudo sed -i -r "/ExecStart=/ s| (.+)\/printer.cfg| $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service
ok_msg "OK!"
fi
### handle multi klipper instance service file
if ls $SYSTEMDDIR/klipper-*.service 2>/dev/null 1>&2; then
status_msg "Configuring Klipper for new path ..."
for service in $(find $SYSTEMDDIR/klipper-*.service); do
sudo sed -i -r "/ExecStart=/ s| (.+)\/printer_| $new_klipper_cfg_loc/printer_|" $service
done
ok_msg "OK!"
fi
### handle single moonraker instance service and moonraker.conf file
if [ -f $SYSTEMDDIR/moonraker.service ]; then
status_msg "Configuring Moonraker for new path ..."
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c $new_klipper_cfg_loc/moonraker.conf|" $SYSTEMDDIR/moonraker.service
### replace old file path with new one in moonraker.conf
sed -i -r "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
ok_msg "OK!"
fi
### handle multi moonraker instance service file
if ls $SYSTEMDDIR/moonraker-*.service 2>/dev/null 1>&2; then
status_msg "Configuring Moonraker for new path ..."
for service in $(find $SYSTEMDDIR/moonraker-*.service); do
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" $service
done
### replace old file path with new one in moonraker.conf
for moonraker_conf in $(find $new_klipper_cfg_loc/printer_*/moonraker.conf); do
loc=$(echo "$moonraker_conf" | rev | cut -d"/" -f2- | rev)
sed -i -r "/config_path:/ s|config_path:.*|config_path: $loc|" $moonraker_conf
done
ok_msg "OK!"
fi
### reloading units
sudo systemctl daemon-reload
### restart services
klipper_service "restart" && moonraker_service "restart"
}
source_kiauh_ini(){
source $INI_FILE
}
klipper_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Klipper Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 klipper-$INSTANCE && ok_msg "Klipper Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper.service")" ]; then
status_msg "$ACTION2 Klipper Service ..."
sudo systemctl $1 klipper && ok_msg "Klipper Service $ACTION1!"
fi fi
} }
source_ini(){ moonraker_service(){
source ${SRCDIR}/kiauh/kiauh.ini ### set a variable for the ok and status messages
} [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
start_klipper(){ if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then
status_msg "Starting Klipper Service ..." INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l)
sudo systemctl start klipper && ok_msg "Klipper Service started!" INSTANCE=1
} status_msg "$ACTION2 $INSTANCE_COUNT Moonraker Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
stop_klipper(){ sudo systemctl $1 moonraker-$INSTANCE && ok_msg "Moonraker Service #$INSTANCE $ACTION1!"
status_msg "Stopping Klipper Service ..." ### instance counter +1
sudo systemctl stop klipper && ok_msg "Klipper Service stopped!" INSTANCE=$(expr $INSTANCE + 1)
} done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker.service")" ]; then
restart_klipper(){ status_msg "$ACTION2 Moonraker Service ..."
status_msg "Restarting Klipper Service ..." sudo systemctl $1 moonraker && ok_msg "Moonraker Service $ACTION1!"
sudo systemctl restart klipper && ok_msg "Klipper Service restarted!"
}
start_dwc(){
status_msg "Starting DWC-for-Klipper-Socket Service ..."
sudo systemctl start dwc && ok_msg "DWC-for-Klipper-Socket Service started!"
}
stop_dwc(){
status_msg "Stopping DWC-for-Klipper-Socket Service ..."
sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!"
}
start_moonraker(){
status_msg "Starting Moonraker Service ..."
sudo systemctl start moonraker && ok_msg "Moonraker Service started!"
}
stop_moonraker(){
status_msg "Stopping Moonraker Service ..."
sudo systemctl stop moonraker && ok_msg "Moonraker Service stopped!"
}
restart_moonraker(){
status_msg "Restarting Moonraker Service ..."
sudo systemctl restart moonraker && ok_msg "Moonraker Service restarted!"
}
start_octoprint(){
status_msg "Starting OctoPrint Service ..."
sudo systemctl start octoprint && ok_msg "OctoPrint Service started!"
}
stop_octoprint(){
status_msg "Stopping OctoPrint Service ..."
sudo systemctl stop octoprint && ok_msg "OctoPrint Service stopped!"
}
restart_octoprint(){
status_msg "Restarting OctoPrint Service ..."
sudo systemctl restart octoprint && ok_msg "OctoPrint Service restarted!"
}
enable_octoprint_service(){
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
status_msg "OctoPrint Service is disabled! Enabling now ..."
sudo systemctl enable octoprint -q && sudo systemctl start octoprint
fi fi
} }
disable_octoprint(){ dwc_service(){
if [ "$DISABLE_OPRINT" = "true" ]; then ### set a variable for the ok and status messages
disable_octoprint_service [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/dwc-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT DWC-for-Klipper-Socket Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 dwc-$INSTANCE && ok_msg "DWC-for-Klipper-Socket Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc.service")" ]; then
status_msg "$ACTION2 DWC-for-Klipper-Socket Service ..."
sudo systemctl $1 dwc && ok_msg "DWC-for-Klipper-Socket Service $ACTION1!"
fi fi
} }
disable_octoprint_service(){ octoprint_service(){
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then ### set a variable for the ok and status messages
status_msg "OctoPrint Service is enabled! Disabling now ..." [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
sudo systemctl stop octoprint && sudo systemctl disable octoprint -q [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling"
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling"
if ls /etc/systemd/system/octoprint-*.service 2>/dev/null 1>&2; then
INSTANCE=1
INSTANCE_COUNT=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l)
status_msg "$ACTION2 $INSTANCE_COUNT OctoPrint Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 octoprint-$INSTANCE && ok_msg "OctoPrint Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-unit-files | grep -E "octoprint.*")" ]; then
status_msg "$ACTION2 OctoPrint Service ..."
sudo systemctl $1 octoprint && ok_msg "OctoPrint Service $ACTION1!"
fi fi
} }
toggle_octoprint_service(){ toggle_octoprint_service(){
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
if systemctl is-enabled octoprint.service -q; then octoprint_service "stop"
disable_octoprint_service octoprint_service "disable"
sleep 2 sleep 2
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !" CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
else elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
enable_octoprint_service octoprint_service "enable"
octoprint_service "start"
sleep 2 sleep 2
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !" CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
fi
else else
ERROR_MSG=" You cannot activate a service that does not exist!" ERROR_MSG=" You cannot activate a service that does not exist!"
fi fi
} }
read_octoprint_service_status(){ read_octoprint_service_status(){
if ! systemctl is-enabled octoprint.service -q &>/dev/null; then unset OPRINT_SERVICE_STATUS
OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service " if [ ! -f "/etc/systemd/system/octoprint.service" ]; then
else return 0
fi
if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service " OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
else
OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service "
fi fi
} }
@@ -155,8 +275,8 @@ restart_klipperscreen(){
restart_nginx(){ restart_nginx(){
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then
status_msg "Restarting Nginx Service ..." status_msg "Restarting NGINX Service ..."
sudo systemctl restart nginx && ok_msg "Nginx Service restarted!" sudo systemctl restart nginx && ok_msg "NGINX Service restarted!"
fi fi
} }
@@ -178,7 +298,7 @@ dependency_check(){
echo -e "${cyan}$element ${default}" echo -e "${cyan}$element ${default}"
done done
echo echo
sudo apt-get install ${inst[@]} -y sudo apt-get update && sudo apt-get install ${inst[@]} -y
ok_msg "Dependencies installed!" ok_msg "Dependencies installed!"
#clearing the array #clearing the array
unset inst unset inst
@@ -220,10 +340,8 @@ setup_gcode_shell_command(){
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
if [ -d $KLIPPER_DIR/klippy/extras ]; then if [ -d $KLIPPER_DIR/klippy/extras ]; then
status_msg "Installing gcode shell command extension ..." status_msg "Installing gcode shell command extension ..."
status_msg "Copy gcode_shell_command.py to '$KLIPPER_DIR/klippy/extras' ..."
if [ -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py ]; then if [ -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py ]; then
warn_msg "There is already a file named 'gcode_shell_command.py'" warn_msg "There is already a file named 'gcode_shell_command.py'\nin the destination location!"
warn_msg "in the destination location!"
while true; do while true; do
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${default} " yn read -p "${cyan}###### Do you want to overwrite it? (Y/n):${default} " yn
case "$yn" in case "$yn" in
@@ -252,27 +370,49 @@ setup_gcode_shell_command(){
} }
install_gcode_shell_command(){ install_gcode_shell_command(){
stop_klipper klipper_service "stop"
status_msg "Copy 'gcode_shell_command.py' to $KLIPPER_DIR/klippy/extras" status_msg "Copy 'gcode_shell_command.py' to '$KLIPPER_DIR/klippy/extras' ..."
cp ${HOME}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras cp ${SRCDIR}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
echo
while true; do while true; do
echo
read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${default} " yn read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
ADD_SHELL_CMD_MACRO="true" status_msg "Copy shell_command.cfg ..."
status_msg "Creating example macro ..." ### create a backup of the config folder
locate_printer_cfg backup_klipper_config_dir
read_printer_cfg "gcode_shell_command"
write_printer_cfg ### handle single printer.cfg
ok_msg "Example macro created!" if [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/shell_command.cfg ]; then
### copy shell_command.cfg to config location
cp ${SRCDIR}/kiauh/resources/shell_command.cfg $klipper_cfg_loc
ok_msg "$klipper_cfg_loc/shell_command.cfg created!"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" $klipper_cfg_loc/printer.cfg
fi
### handle multi printer.cfg
if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then
for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do
path=$(echo $config | rev | cut -d"/" -f2- | rev)
if [ ! -f $path/shell_command.cfg ]; then
### copy shell_command.cfg to config location
cp ${SRCDIR}/kiauh/resources/shell_command.cfg $path
ok_msg "$path/shell_command.cfg created!"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" $path/printer.cfg
fi
done
fi
break;; break;;
N|n|No|no) N|n|No|no)
break;; break;;
esac esac
done done
ok_msg "Shell command extension installed!" ok_msg "Shell command extension installed!"
restart_klipper klipper_service "restart"
} }
create_minimal_cfg(){ create_minimal_cfg(){
@@ -331,22 +471,6 @@ write_printer_cfg(){
if [ "$DISPLAY_STATUS" = "false" ] && [[ ! $(grep '^\[display_status]$' $KIAUH_CFG) ]]; then if [ "$DISPLAY_STATUS" = "false" ] && [[ ! $(grep '^\[display_status]$' $KIAUH_CFG) ]]; then
echo -e "\n[display_status]" >> $KIAUH_CFG echo -e "\n[display_status]" >> $KIAUH_CFG
fi fi
#Klipper webui related config options
if [ "$WEBUI_MACROS" = "false" ] && [ "$ADD_WEBUI_MACROS" = "true" ] && [[ ! $(grep '^\[include webui_macros.cfg]$' $KIAUH_CFG) ]]; then
echo -e "\n[include webui_macros.cfg]" >> $KIAUH_CFG
fi
#G-Code Shell Command extension related config options
if [ "$ADD_SHELL_CMD_MACRO" = "true" ] && [[ ! $(grep '^\[gcode_shell_command hello_world]$' $KIAUH_CFG) ]]; then
cat <<-EOF >> $KIAUH_CFG
[gcode_shell_command hello_world]
command: echo hello world
timeout: 2.
verbose: True
[gcode_macro HELLO_WORLD]
gcode:
RUN_SHELL_COMMAND CMD=hello_world
EOF
fi
#including the kiauh.cfg into printer.cfg if not already done #including the kiauh.cfg into printer.cfg if not already done
if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Writing [include kiauh.cfg] to printer.cfg ..." status_msg "Writing [include kiauh.cfg] to printer.cfg ..."
@@ -356,6 +480,10 @@ EOF
} }
init_ini(){ init_ini(){
### copy an existing kiauh.ini to its new location to keep all possible saved values
if [ -f ${SRCDIR}/kiauh/kiauh.ini ] && [ ! -f $INI_FILE ]; then
cp ${SRCDIR}/kiauh/kiauh.ini $INI_FILE
fi
if [ ! -f $INI_FILE ]; then if [ ! -f $INI_FILE ]; then
echo -e "#don't edit this file if you don't know what you are doing...\c" > $INI_FILE echo -e "#don't edit this file if you don't know what you are doing...\c" > $INI_FILE
fi fi
@@ -374,4 +502,8 @@ init_ini(){
if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then
echo -e "\nlogupload_accepted=false\c" >> $INI_FILE echo -e "\nlogupload_accepted=false\c" >> $INI_FILE
fi fi
###add empty klipper config path if missing
if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then
echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE
fi
} }

View File

@@ -1,124 +1,95 @@
install_dwc2(){ ### base variables
if [ -d $KLIPPER_DIR ]; then SYSTEMDDIR="/etc/systemd/system"
system_check_dwc2 DWC_ENV="${HOME}/dwc-env"
#check for other enabled web interfaces DWC2_DIR="${HOME}/duetwebcontrol"
unset SET_LISTEN_PORT
detect_enabled_sites
#ask user for customization
get_user_selections_dwc2
#dwc2 main installation
stop_klipper
dwc2_setup
#setup config
setup_printer_config_dwc2
#execute customizations
disable_octoprint
set_nginx_cfg "dwc2"
set_hostname
#after install actions
restart_klipper
else
ERROR_MSG=" Please install Klipper first!\n Skipping..."
fi
}
system_check_dwc2(){ system_check_dwc(){
status_msg "Initializing DWC2 installation ..." ### check system for an installed octoprint service
#check for existing printer.cfg
locate_printer_cfg
if [ -f $PRINTER_CFG ]; then
PRINTER_CFG_FOUND="true"
else
PRINTER_CFG_FOUND="false"
fi
#check if octoprint is installed
if systemctl is-enabled octoprint.service -q 2>/dev/null; then if systemctl is-enabled octoprint.service -q 2>/dev/null; then
OCTOPRINT_ENABLED="true" OCTOPRINT_ENABLED="true"
fi fi
} }
get_user_selections_dwc2(){ dwc_setup_dialog(){
#let user choose to install systemd or init.d service status_msg "Initializing Duet Web Control installation ..."
### check system for several requirements before initializing the dwc2 installation
system_check_dwc
### check for existing klipper service installations
if [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
fi
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### initial config path check
check_klipper_cfg_path
### ask user how to handle OctoPrint, Haproxy and Lighttpd
process_octoprint_dialog_dwc2
process_haproxy_lighttpd_dialog
### instance confirmation dialog
while true; do while true; do
echo echo
top_border top_border
echo -e "| Do you want to install dwc2-for-klipper-socket as |" if [ $INSTANCE_COUNT -gt 1 ]; then
echo -e "| 1) Init.d Service (default) |" printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
echo -e "| 2) Systemd Service |" else
hr echo -e "| 1 Klipper instance was found! | "
echo -e "| Please use the appropriate option for your chosen |" fi
echo -e "| Linux distribution. If you are unsure what to select, |" echo -e "| You need one DWC instance per Klipper instance. | "
echo -e "| please do a research before. |"
hr
echo -e "| If you run Raspberry Pi OS, both options will work. |"
bottom_border bottom_border
read -p "${cyan}###### Please choose:${default} " action
case "$action" in
1|"")
echo -e "###### > 1) Init.d"
INST_DWC2_INITD="true"
INST_DWC2_SYSTEMD="false"
break;;
2)
echo -e "###### > 1) Systemd"
INST_DWC2_INITD="false"
INST_DWC2_SYSTEMD="true"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
#user selection for printer.cfg
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
while true; do
echo echo
top_border read -p "${cyan}###### Create $INSTANCE_COUNT DWC instances? (Y/n):${default} " yn
echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |"
hr
echo -e "| KIAUH can create a minimal printer.cfg with only the |"
echo -e "| necessary config entries if you wish. |"
echo -e "| |"
echo -e "| Please be aware, that this option will ${red}NOT${default} create a |"
echo -e "| fully working printer.cfg for you! |"
bottom_border
read -p "${cyan}###### Create a default printer.cfg? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
SEL_DEF_CFG="true" status_msg "Creating $INSTANCE_COUNT DWC instances ..."
dwc_setup
break;; break;;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
SEL_DEF_CFG="false" warn_msg "Exiting DWC setup ..."
echo
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
print_msg && clear_msg;; print_msg && clear_msg;;
esac esac
done done
fi }
#ask user to install reverse proxy
dwc2_reverse_proxy_dialog ###TODO for future: should be some kind of shared function between moonraker and this installer, since it does the same
#ask to change hostname process_octoprint_dialog_dwc2(){
[ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname ### ask user to disable octoprint when its service was found
#ask user to disable octoprint when such installed service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then if [ "$OCTOPRINT_ENABLED" = "true" ]; then
while true; do while true; do
echo echo
warn_msg "OctoPrint service found!" top_border
echo -e "You might consider disabling the OctoPrint service," echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
echo -e "since an active OctoPrint service may lead to unexpected" hr
echo -e "behavior of the DWC2 Webinterface." echo -e "| You might consider disabling the OctoPrint service, |"
echo -e "| since an active OctoPrint service may lead to unex- |"
echo -e "| pected behavior of Duet Web Control for Klipper. |"
bottom_border
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
DISABLE_OPRINT="true" status_msg "Stopping OctoPrint ..."
sudo systemctl stop octoprint && ok_msg "OctoPrint service stopped!"
status_msg "Disabling OctoPrint ..."
sudo systemctl disable octoprint && ok_msg "OctoPrint service disabled!"
break;; break;;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
DISABLE_OPRINT="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
@@ -132,43 +103,54 @@ get_user_selections_dwc2(){
############################################################# #############################################################
############################################################# #############################################################
get_dwc2_ver(){ get_dwc_ver(){
DWC2_VERSION=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4) DWC2_VERSION=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4)
} }
dwc2_setup(){ dwc_setup(){
#check dependencies ### get printer config directory
source_kiauh_ini
DWC_CONF_LOC="$klipper_cfg_loc"
### check dependencies
dep=(git wget gzip tar curl) dep=(git wget gzip tar curl)
dependency_check dependency_check
#get dwc2-for-klipper
status_msg "Cloning DWC2-for-Klipper-Socket repository ..." ### step 1: get dwc2-for-klipper
status_msg "Downloading DWC2-for-Klipper-Socket ..."
cd ${HOME} && git clone $DWC2FK_REPO cd ${HOME} && git clone $DWC2FK_REPO
ok_msg "DWC2-for-Klipper successfully cloned!" ok_msg "Download complete!"
#copy installers from kiauh srcdir to dwc-for-klipper-socket
status_msg "Copy installers to $DWC2FK_DIR" ### step 2: install dwc2 dependencies and create python virtualenv
cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts status_msg "Installing dependencies ..."
ok_msg "Done!" install_dwc_packages
status_msg "Starting service-installer ..." create_dwc_virtualenv
if [ "$INST_DWC2_INITD" = "true" ]; then
$DWC2FK_DIR/scripts/install-octopi.sh ### step 3: create dwc2.cfg folder and dwc2.cfg
elif [ "$INST_DWC2_SYSTEMD" = "true" ]; then [ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC
$DWC2FK_DIR/scripts/install-debian.sh dwc_cfg_creation
### step 4: download Duet Web Control
download_dwc_webui
### step 5: create dwc instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_dwc_instance
else
#create_multi_dwc_instance
create_multi_dwc_instance
fi fi
ok_msg "Service installed!"
#patch /etc/default/klipper to append the uds argument
patch_klipper_sysfile "dwc2"
#download Duet Web Control
download_dwc2_webui
} }
download_dwc2_webui(){ download_dwc_webui(){
#get Duet Web Control #get Duet Web Control
GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4) GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4)
status_msg "Downloading DWC2 Web UI ..." status_msg "Downloading DWC2 Web UI ..."
[ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR [ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR
cd $DWC2_DIR && wget $GET_DWC2_URL cd $DWC2_DIR && wget $GET_DWC2_URL
ok_msg "Download complete!" ok_msg "Download complete!"
status_msg "Unzipping archive ..." status_msg "Extracting archive ..."
unzip -q -o *.zip unzip -q -o *.zip
for f_ in $(find . | grep '.gz') for f_ in $(find . | grep '.gz')
do do
@@ -176,103 +158,233 @@ download_dwc2_webui(){
done done
ok_msg "Done!" ok_msg "Done!"
status_msg "Writing DWC version to file ..." status_msg "Writing DWC version to file ..."
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/version echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/.version
ok_msg "Done!" ok_msg "Done!"
status_msg "Do a little cleanup ..." status_msg "Remove downloaded archive ..."
rm -rf DuetWebControl-SD.zip rm -rf *.zip && ok_msg "Done!" && ok_msg "Duet Web Control installed!"
ok_msg "Done!"
ok_msg "DWC2 Web UI installed!"
} }
############################################################# ##############################################################################################
############################################################# #********************************************************************************************#
##############################################################################################
setup_printer_config_dwc2(){ install_dwc_packages()
if [ "$PRINTER_CFG_FOUND" = "true" ]; then {
#check printer.cfg for necessary dwc2 entries PKGLIST="python3-virtualenv python3-dev python3-tornado"
read_printer_cfg "dwc2" && write_printer_cfg
fi # Update system package info
if [ "$SEL_DEF_CFG" = "true" ]; then status_msg "Running apt-get update..."
status_msg "Creating minimal default printer.cfg ..." sudo apt-get update
create_minimal_cfg
ok_msg "printer.cfg location: '$PRINTER_CFG'" # Install desired packages
ok_msg "Done!" status_msg "Installing packages..."
fi sudo apt-get install --yes ${PKGLIST}
} }
############################################################# create_dwc_virtualenv()
############################################################# {
status_msg "Installing python virtual environment..."
dwc2_reverse_proxy_dialog(){ # Create virtualenv if it doesn't already exist
echo [ ! -d ${DWC_ENV} ] && virtualenv -p /usr/bin/python3 ${DWC_ENV}
top_border
echo -e "| If you want to have a nicer URL or simply need/want | " # Install/update dependencies
echo -e "| DWC2 to run on port 80 (http's default port) you | " ${DWC_ENV}/bin/pip install tornado==6.0.4
echo -e "| can set up a reverse proxy to run DWC2 on port 80. | " }
bottom_border
while true; do create_single_dwc_startscript(){
read -p "${cyan}###### Do you want to set up a reverse proxy now? (y/N):${default} " yn ### create systemd service file
case "$yn" in sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC
Y|y|Yes|yes) [Unit]
dwc2_port_check Description=DuetWebControl
break;; After=network.target
N|n|No|no|"") [Install]
break;; WantedBy=multi-user.target
*) [Service]
print_unkown_cmd Type=simple
print_msg && clear_msg;; User=${USER}
esac RemainAfterExit=yes
ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG}
Restart=always
RestartSec=10
DWC
}
create_multi_dwc_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc-$INSTANCE.service" << DWC
[Unit]
Description=DuetWebControl
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=${USER}
RemainAfterExit=yes
ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG}
Restart=always
RestartSec=10
DWC
}
create_single_dwcfk_cfg(){
### create single instance config file
/bin/sh -c "cat > $DWC_CONF_LOC/dwc2.cfg" << DWCCFG
[webserver]
listen_adress: 0.0.0.0
web_root: ${HOME}/duetwebcontrol
port: ${PORT}
[reply_filters]
regex:
max_accel: \d+.\d+
max_accel_to_decel: \d+.\d+
square_corner_velocity: \d+.\d+
max_velocity: \d+.\d+
DWCCFG
}
create_multi_dwcfk_cfg(){
### create single instance config file
/bin/sh -c "cat > $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" << DWCCFG
[webserver]
listen_adress: 0.0.0.0
web_root: ${HOME}/duetwebcontrol
port: ${PORT}
[reply_filters]
regex:
max_accel: \d+.\d+
max_accel_to_decel: \d+.\d+
square_corner_velocity: \d+.\d+
max_velocity: \d+.\d+
DWCCFG
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
print_dwc_ip_list(){
i=1
for ip in ${dwc_ip_list[@]}; do
echo -e " ${cyan}● Instance $i:${default} $ip"
i=$((i + 1))
done done
} }
dwc2_port_check(){ create_single_dwc_instance(){
if [ "$DWC2_ENABLED" = "false" ]; then status_msg "Setting up 1 Duet Web Control instance ..."
if [ "$SITE_ENABLED" = "true" ]; then
status_msg "Detected other enabled interfaces:" ### single instance variables
[ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port:$OCTOPRINT_PORT${default}" DWC_LOG=/tmp/dwc.log
[ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}" DWC_CFG="$DWC_CONF_LOC/dwc2.cfg"
[ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}"
if [ "$MAINSAIL_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then ### create instance
PORT_80_BLOCKED="true" status_msg "Creating single DWC instance ..."
select_dwc2_port create_single_dwc_startscript
fi
else ### enable instance
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/dwc2_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) sudo systemctl enable dwc.service
SET_LISTEN_PORT=$DEFAULT_PORT ok_msg "Single DWC instance created!"
fi
SET_NGINX_CFG="true" ### launching instance
else status_msg "Launching DWC instance ..."
SET_NGINX_CFG="false" sudo systemctl start dwc
fi
### confirm message
CONFIRM_MSG="Single DWC instance has been set up!"
print_msg && clear_msg
### display moonraker ip to the user
print_dwc_ip_list; echo
} }
select_dwc2_port(){ create_multi_dwc_instance(){
if [ "$PORT_80_BLOCKED" = "true" ]; then status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..."
echo while [ $INSTANCE -le $INSTANCE_COUNT ]; do
top_border ### multi instance variables
echo -e "| ${red}!!!WARNING!!!${default} |" DWC_LOG=/tmp/dwc-$INSTANCE.log
echo -e "| ${red}You need to choose a different port for DWC2!${default} |" DWC_CFG="$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg"
echo -e "| ${red}The following web interface is listening at port 80:${default} |"
blank_line ### create instance
[ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" status_msg "Creating instance #$INSTANCE ..."
[ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" create_multi_dwc_startscript
[ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |"
blank_line ### enable instance
echo -e "| Make sure you don't choose a port which was already |" sudo systemctl enable dwc-$INSTANCE.service
echo -e "| assigned to one of the other web interfaces! |" ok_msg "DWC instance $INSTANCE created!"
blank_line
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" ### launching instance
echo -e "| input. So make sure to choose a valid port! |" status_msg "Launching DWC instance $INSTANCE ..."
bottom_border sudo systemctl start dwc-$INSTANCE
while true; do
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT ### instance counter +1
if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then INSTANCE=$(expr $INSTANCE + 1)
echo "Setting port $NEW_PORT for DWC2!" done
SET_LISTEN_PORT=$NEW_PORT
break ### confirm message
CONFIRM_MSG="$INSTANCE_COUNT DWC instances has been set up!"
print_msg && clear_msg
### display moonraker ip to the user
print_dwc_ip_list; echo
}
dwc_cfg_creation(){
### default dwc port
DEFAULT_PORT=4750
### get printer config directory
source_kiauh_ini
DWC_CONF_LOC="$klipper_cfg_loc"
### reset instances back to 1 again
INSTANCE=1
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
dwc_ip_list=()
### create single instance dwc2.cfg file
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
### set port
PORT=$DEFAULT_PORT
### write the ip and port to the ip list for displaying it later to the user
dwc_ip_list+=("$HOSTNAME:$PORT")
status_msg "Creating dwc2.cfg in $DWC_CONF_LOC"
[ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC
if [ ! -f $DWC_CONF_LOC/dwc2.cfg ]; then
create_single_dwcfk_cfg && ok_msg "dwc2.cfg created!"
else else
echo "That port is already taken! Select a different one!" warn_msg "There is already a file called 'dwc2.cfg'!"
warn_msg "Skipping..."
fi fi
### create multi instance moonraker.conf files
else
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### set each instance to its own port
PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1)
### write the ip and port to the ip list for displaying it later to the user
dwc_ip_list+=("$HOSTNAME:$PORT")
### start the creation of each instance
status_msg "Creating dwc2.cfg for instance #$INSTANCE"
[ ! -d $DWC_CONF_LOC/printer_$INSTANCE ] && mkdir -p $DWC_CONF_LOC/printer_$INSTANCE
if [ ! -f $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg ]; then
create_multi_dwcfk_cfg && ok_msg "dwc2.cfg created!"
else
warn_msg "There is already a file called 'dwc2.cfg'!"
warn_msg "Skipping..."
fi
### raise instance counter by 1
INSTANCE=$(expr $INSTANCE + 1)
done done
fi fi
} }

View File

@@ -1,77 +1,199 @@
install_klipper(){ ### base variables
if [ -e $KLIPPER_SERVICE1 ] && [ -e $KLIPPER_SERVICE2 ] || [ -e $KLIPPER_SERVICE3 ]; then SYSTEMDDIR="/etc/systemd/system"
ERROR_MSG="Looks like Klipper is already installed!" KLIPPY_ENV="${HOME}/klippy-env"
KLIPPER_DIR="${HOME}/klipper"
klipper_setup_dialog(){
status_msg "Initializing Klipper installation ..."
### check for existing klipper service files
INITD=$(ls /etc/init.d | grep -E "^klipper(\-[[:digit:]]+)?$")
SYSTEMD=$(ls /etc/systemd/system | grep -E "^klipper(\-[[:digit:]]+)?\.service$")
if [ ! -z "$INITD" ] || [ ! -z "$SYSTEMD" ]; then
echo "${red}$INITD${default}" && echo "${red}$SYSTEMD${default}"
ERROR_MSG="At least one Klipper service is already installed!\n Please remove Klipper first, before installing it again." && return 0
fi
### initial printer.cfg path check
check_klipper_cfg_path
### ask for amount of instances to create
INSTANCE_COUNT=""
while [[ ! ($INSTANCE_COUNT =~ ^[1-9]+$) ]]; do
echo
read -p "${cyan}###### Number of Klipper instances to set up:${default} " INSTANCE_COUNT
if [[ ! ($INSTANCE_COUNT =~ ^[1-9]+$) ]]; then
warn_msg "Invalid Input!" && echo
else else
get_user_selections_klipper echo
read -p "${cyan}###### Install $INSTANCE_COUNT instance(s)? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Installing $INSTANCE_COUNT Klipper instance(s) ..."
klipper_setup klipper_setup
build_fw break;;
flash_mcu N|n|No|no)
write_printer_usb echo -e "###### > No"
warn_msg "Exiting Klipper setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
fi
done
}
install_klipper_packages(){
### read PKGLIST from official install script
status_msg "Reading dependencies..."
install_script="${HOME}/klipper/scripts/install-octopi.sh"
PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g')
### rewrite packages into new array
unset PKGARR
for PKG in $PKGLIST; do PKGARR+=($PKG); done
### add dbus requirement for DietPi distro
PKGARR+=("dbus")
echo "${cyan}${PKGARR[@]}${default}"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGARR[@]}
}
create_klipper_virtualenv(){
status_msg "Installing python virtual environment..."
# Create virtualenv if it doesn't already exist
[ ! -d ${KLIPPY_ENV} ] && virtualenv -p python2 ${KLIPPY_ENV}
# Install/update dependencies
${KLIPPY_ENV}/bin/pip install -r ${KLIPPER_DIR}/scripts/klippy-requirements.txt
}
klipper_setup(){
### step 1: clone klipper
status_msg "Downloading Klipper ..."
### force remove existing klipper dir and clone into fresh klipper dir
[ -d $KLIPPER_DIR ] && rm -rf $KLIPPER_DIR
cd ${HOME} && git clone $KLIPPER_REPO
status_msg "Download complete!"
### step 2: install klipper dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_klipper_packages
create_klipper_virtualenv
### step 3: create shared gcode_files and logs folder
[ ! -d ${HOME}/gcode_files ] && mkdir -p ${HOME}/gcode_files
[ ! -d ${HOME}/klipper_logs ] && mkdir -p ${HOME}/klipper_logs
### step 4: create klipper instances
create_klipper_service
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
[ $INSTANCE_COUNT -eq 1 ] && CONFIRM_MSG="Klipper has been set up!"
print_msg && clear_msg
}
create_klipper_service(){
### get config directory
source_kiauh_ini
### set up default values
SINGLE_INST=1
CFG_PATH="$klipper_cfg_loc"
KL_ENV=$KLIPPY_ENV
KL_DIR=$KLIPPER_DIR
KL_LOG="${HOME}/klipper_logs/klippy.log"
KL_UDS="/tmp/klippy_uds"
P_TMP="/tmp/printer"
P_CFG="$CFG_PATH/printer.cfg"
P_CFG_SRC="${SRCDIR}/kiauh/resources/printer.cfg"
KL_SERV_SRC="${SRCDIR}/kiauh/resources/klipper.service"
KL_SERV_TARGET="$SYSTEMDDIR/klipper.service"
write_kl_service(){
[ ! -d $CFG_PATH ] && mkdir -p $CFG_PATH
### create a minimal config if there is no printer.cfg
[ ! -f $P_CFG ] && cp $P_CFG_SRC $P_CFG
### replace placeholder
if [ ! -f $KL_SERV_TARGET ]; then
status_msg "Creating Klipper Service $i ..."
sudo cp $KL_SERV_SRC $KL_SERV_TARGET
sudo sed -i "s|%INST%|$i|" $KL_SERV_TARGET
sudo sed -i "s|%USER%|${USER}|" $KL_SERV_TARGET
sudo sed -i "s|%KL_ENV%|$KL_ENV|" $KL_SERV_TARGET
sudo sed -i "s|%KL_DIR%|$KL_DIR|" $KL_SERV_TARGET
sudo sed -i "s|%KL_LOG%|$KL_LOG|" $KL_SERV_TARGET
sudo sed -i "s|%P_CFG%|$P_CFG|" $KL_SERV_TARGET
sudo sed -i "s|%P_TMP%|$P_TMP|" $KL_SERV_TARGET
sudo sed -i "s|%KL_UDS%|$KL_UDS|" $KL_SERV_TARGET
fi
}
if [ $SINGLE_INST -eq $INSTANCE_COUNT ]; then
### write single instance service
write_kl_service
### enable instance
sudo systemctl enable klipper.service
ok_msg "Single Klipper instance created!"
### launching instance
status_msg "Launching Klipper instance ..."
sudo systemctl start klipper
else
i=1
while [ $i -le $INSTANCE_COUNT ]; do
### rewrite default variables for multi instance cases
CFG_PATH="$klipper_cfg_loc/printer_$i"
KL_SERV_TARGET="$SYSTEMDDIR/klipper-$i.service"
P_TMP="/tmp/printer-$i"
P_CFG="$CFG_PATH/printer.cfg"
KL_LOG="${HOME}/klipper_logs/klippy-$i.log"
KL_UDS="/tmp/klippy_uds-$i"
### write multi instance service
write_kl_service
### enable instance
sudo systemctl enable klipper-$i.service
ok_msg "Klipper instance #$i created!"
### launching instance
status_msg "Launching Klipper instance #$i ..."
sudo systemctl start klipper-$i
### raise values by 1
i=$((i+1))
done
unset i
fi fi
} }
get_user_selections_klipper(){ flash_routine(){
status_msg "Initializing Klipper installation ..."
#let user choose to install systemd or init.d service
while true; do
echo echo
top_border top_border
echo -e "| Do you want to install Klipper as: |" echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
echo -e "| 1) Init.d Service (default) |"
echo -e "| 2) Systemd Service |"
hr hr
echo -e "| Please use the appropriate option for your chosen |" echo -e "| Flashing a Smoothie based board with this method will |"
echo -e "| Linux distribution. If you are unsure what to select, |" echo -e "| certainly fail. This applies to boards like the SKR |"
echo -e "| please do some research before. |" echo -e "| V1.3 / V1.4. You have to copy the firmware file to |"
echo -e "| the SD card manually and rename it to 'firmware.bin'. |"
hr hr
echo -e "| If you run Raspberry Pi OS, both options will work. |" echo -e "| You can find the file in: ~/klipper/out/klipper.bin |"
bottom_border bottom_border
read -p "${cyan}###### Please choose:${default} " action
case "$action" in
1|"")
echo -e "###### > 1) Init.d"
INST_KLIPPER_INITD="true"
INST_KLIPPER_SYSTEMD="false"
break;;
2)
echo -e "###### > 2) Systemd"
INST_KLIPPER_INITD="false"
INST_KLIPPER_SYSTEMD="true"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
#ask user for building firmware
while true; do while true; do
echo read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
read -p "${cyan}###### Do you want to build the Firmware? (y/N):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes) Y|y|Yes|yes|"")
echo -e "###### > Yes"
BUILD_FIRMWARE="true"
break;;
N|n|No|no|"")
echo -e "###### > No"
BUILD_FIRMWARE="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
#ask user for flashing mcu
while true; do
echo
read -p "${cyan}###### Do you want to flash your MCU? (y/N):${default} " yn
case "$yn" in
Y|y|Yes|yes)
echo -e "###### > Yes" echo -e "###### > Yes"
FLASH_FIRMWARE="true" FLASH_FIRMWARE="true"
flash_routine get_mcu_id
break;; break;;
N|n|No|no|"") N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
FLASH_FIRMWARE="false" FLASH_FIRMWARE="false"
break;; break;;
@@ -82,167 +204,215 @@ get_user_selections_klipper(){
done done
} }
klipper_setup(){ flash_routine_sd(){
#check for dependencies
dep=(git dbus)
dependency_check
#execute operation
cd ${HOME}
status_msg "Cloning Klipper repository ..."
git clone $KLIPPER_REPO
ok_msg "Klipper successfully cloned!"
status_msg "Installing Klipper Service ..."
if [ "$INST_KLIPPER_INITD" = "true" ]; then
$KLIPPER_DIR/scripts/install-octopi.sh
elif [ "$INST_KLIPPER_SYSTEMD" = "true" ]; then
$KLIPPER_DIR/scripts/install-debian.sh
fi
ok_msg "Klipper installation complete!"
}
flash_routine(){
if [ "$FLASH_FIRMWARE" = "true" ]; then
echo echo
top_border top_border
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |" echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
hr hr
echo -e "| Flashing a Smoothie based board with this script will |" echo -e "| If you have a Smoothie based board with an already |"
echo -e "| certainly fail. This applies to boards like the BTT |" echo -e "| flashed Klipper Firmware, you can now choose to flash |"
echo -e "| SKR V1.3 or SKR V1.4(Turbo). You have to copy the |" echo -e "| directly from the internal SD if your control board |"
echo -e "| firmware file to the microSD card manually and rename |" echo -e "| is supported by that function. |"
echo -e "| it to 'firmware.bin'. |"
hr
echo -e "| You can find the file in: ~/klipper/out/klipper.bin |"
bottom_border bottom_border
while true; do while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
CONFIRM_FLASHING="true" FLASH_FW_SD="true"
CONFIRM_WRITE_PRINTER_USB="true" get_mcu_id
get_printer_usb
break;; break;;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
CONFIRM_FLASHING="false" FLASH_FW_SD="false"
CONFIRM_WRITE_PRINTER_USB="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
print_msg && clear_msg;; print_msg && clear_msg;;
esac esac
done done
}
select_mcu_id(){
if [ ${#mcu_list[@]} -ge 1 ]; then
top_border
echo -e "| ${red}!!! IMPORTANT WARNING !!!${default} |"
hr
echo -e "| Make sure, that you select the correct ID for the MCU |"
echo -e "| you have build the firmware for in the previous step! |"
blank_line
echo -e "| This is especially important if you use different MCU |"
echo -e "| models which each require their own firmware! |"
blank_line
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
bottom_border
### list all mcus
i=1
for mcu in ${mcu_list[@]}; do
echo -e "$i) ${cyan}$mcu${default}"
i=$(expr $i + 1)
done
while true; do
echo
read -p "${cyan}###### Please select the ID for flashing:${default} " selected_index
mcu_index=$(echo $((selected_index - 1)))
selected_mcu_id="${mcu_list[$mcu_index]}"
echo -e "\nYou have selected to flash:\n● MCU #$selected_index: $selected_mcu_id\n"
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Flashing $selected_mcu_id ..."
if [ "$FLASH_FIRMWARE" = "true" ]; then
flash_mcu
fi
if [ "$FLASH_FW_SD" = "true" ]; then
flash_mcu_sd
fi
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
break
done
fi fi
} }
flash_mcu(){ flash_mcu(){
if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then klipper_service "stop"
stop_klipper if ! make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" ; then
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
warn_msg "Flashing failed!" warn_msg "Flashing failed!"
warn_msg "Please read the console output above!" warn_msg "Please read the console output above!"
else else
ok_msg "Flashing successfull!" ok_msg "Flashing successfull!"
fi fi
start_klipper klipper_service "start"
}
flash_mcu_sd(){
klipper_service "stop"
### write each supported board to the array to make it selectable
board_list=()
for board in $(~/klipper/scripts/flash-sdcard.sh -l | tail -n +2); do
board_list+=($board)
done
i=0
top_border
echo -e "| Please select the type of board that corresponds to |"
echo -e "| the currently selected MCU ID you chose before. |"
blank_line
echo -e "| The following boards are currently supported: |"
hr
### display all supported boards to the user
for board in ${board_list[@]}; do
if [ $i -lt 10 ]; then
printf "| $i) %-50s|\n" "${board_list[$i]}"
else
printf "| $i) %-49s|\n" "${board_list[$i]}"
fi fi
i=$((i + 1))
done
quit_footer
### make the user select one of the boards
while true; do
read -p "${cyan}###### Please select board type:${default} " choice
if [ $choice = "q" ] || [ $choice = "Q" ]; then
clear && advanced_menu && break
elif [ $choice -le ${#board_list[@]} ]; then
selected_board="${board_list[$choice]}"
break
else
clear && print_header
ERROR_MSG="Invalid choice!" && print_msg && clear_msg
flash_mcu_sd
fi
done
while true; do
top_border
echo -e "| If your board is flashed with firmware that connects |"
echo -e "| at a custom baud rate, please change it now. |"
blank_line
echo -e "| If you are unsure, stick to the default 250000! |"
bottom_border
echo -e "${cyan}###### Please set the baud rate:${default} "
unset baud_rate
while [[ ! $baud_rate =~ ^[0-9]+$ ]]; do
read -e -i "250000" -e baud_rate
selected_baud_rate=$baud_rate
break
done
break
done
if ! ${HOME}/klipper/scripts/flash-sdcard.sh -b "$selected_baud_rate" "$selected_mcu_id" "$selected_board" ; then
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
else
ok_msg "Flashing successfull!"
fi
klipper_service "start"
} }
build_fw(){ build_fw(){
if [ "$BUILD_FIRMWARE" = "true" ]; then
if [ -d $KLIPPER_DIR ]; then if [ -d $KLIPPER_DIR ]; then
cd $KLIPPER_DIR cd $KLIPPER_DIR
status_msg "Initializing Firmware Setup ..." status_msg "Initializing firmware build ..."
make clean
make menuconfig make menuconfig
status_msg "Building Firmware ..." status_msg "Building firmware ..."
make clean && make && ok_msg "Firmware built!" make && ok_msg "Firmware built!"
else else
warn_msg "Can not build Firmware without a Klipper directory!" warn_msg "Can not build firmware without a Klipper directory!"
fi
fi fi
} }
### grab the printers id ### grab the mcu id
get_printer_usb(){ get_mcu_id(){
echo echo
top_border top_border
echo -e "| Please make sure your printer is connected to the Pi! |" echo -e "| Please make sure your MCU is connected to the Pi! |"
echo -e "| If the printer is not connected yet, connect it now. |" echo -e "| If the MCU is not connected yet, connect it now. |"
hr
echo -e "| Also make sure, that it is the only USB device |"
echo -e "| connected at for now! Otherwise this step may fail! |"
bottom_border bottom_border
while true; do while true; do
echo -e "${cyan}" echo -e "${cyan}"
read -p "###### Press any key to continue ... " yn read -p "###### Press ENTER to continue ... " yn
echo -e "${default}" echo -e "${default}"
case "$yn" in case "$yn" in
*) *)
CONFIRM_PRINTER_USB="true"
break;; break;;
esac esac
done done
status_msg "Identifying the correct USB port ..." status_msg "Identifying the ID of your MCU ..."
sleep 2 sleep 2
unset PRINTER_USB unset MCU_ID
if [ -e /dev/serial/by-id/* ]; then ### if there are devices found, continue, else show warn message
if [ -e /dev/serial/by-id/* ]; then if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then
PRINTER_USB=$(ls /dev/serial/by-id/*) mcu_count=1
status_msg "The ID of your printer is:" mcu_list=()
title_msg "$PRINTER_USB" status_msg "The ID of your printers MCU is:"
### loop over the IDs, write every ID as an item of the array 'mcu_list'
for mcu in /dev/serial/by-id/*; do
declare "mcu_id_$mcu_count"="$mcu"
mcu_id="mcu_id_$mcu_count"
mcu_list+=("${!mcu_id}")
echo " ● MCU #$mcu_count: ${cyan}$mcu${default}"
mcu_count=$(expr $mcu_count + 1)
done
unset mcu_count
else else
warn_msg "Could not retrieve ID!" warn_msg "Could not retrieve ID!"
fi
elif [ -e /dev/serial/by-path/* ]; then
if [ -e /dev/serial/by-path/* ]; then
PRINTER_USB=$(ls /dev/serial/by-path/*)
status_msg "The path of your printer is:"
title_msg "$PRINTER_USB"
else
warn_msg "Could not retrieve path!"
fi
else
warn_msg "Printer not plugged in or not detectable!" warn_msg "Printer not plugged in or not detectable!"
fi
}
write_printer_usb(){
locate_printer_cfg
if [ ! -z "$PRINTER_CFG" ] && [ "$CONFIRM_WRITE_PRINTER_USB" = "true" ]; then
SERIAL_OLD=$(grep "serial" $PRINTER_CFG | tail -1 | cut -d" " -f2)
SERIAL_NEW=$PRINTER_USB
if [ "$SERIAL_OLD" != "$SERIAL_NEW" ]; then
unset write_entries
backup_printer_cfg
write_entries+=("[mcu]\nserial: $SERIAL_NEW")
write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################")
write_entries=("############################\n" "${write_entries[@]}")
#check for a SAVE_CONFIG entry
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
if [[ $(grep "$SC" $PRINTER_CFG) ]]; then
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
PRE_SC_LINE=$(expr $SC_LINE - 1)
SC_ENTRY="true"
else
SC_ENTRY="false"
fi
status_msg "Writing printer ID/path to printer.cfg ..."
if [ "$SC_ENTRY" = "true" ]; then
PRE_SC_LINE="$(expr $SC_LINE - 1)a"
for entry in "${write_entries[@]}"
do
sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG
done
fi
if [ "$SC_ENTRY" = "false" ]; then
LINE_COUNT="$(wc -l < $PRINTER_CFG)a"
for entry in "${write_entries[@]}"
do
sed -i "$LINE_COUNT $entry" $PRINTER_CFG
done
fi
ok_msg "Done!"
fi
fi fi
} }

View File

@@ -1,36 +1,28 @@
check_moonraker(){ check_moonraker(){
status_msg "Checking for Moonraker service ..." status_msg "Checking for Moonraker service ..."
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
ok_msg "Moonraker service found!"; echo moonraker_chk_ok="true"
MOONRAKER_SERVICE_FOUND="true"
else else
warn_msg "Moonraker service not found!" moonraker_chk_ok="false"
warn_msg "Please install Moonraker first!"; echo
MOONRAKER_SERVICE_FOUND="false"
fi fi
} }
get_user_selection_webui(){ get_user_selection_mjpg-streamer(){
#ask user for webui default macros
while true; do while true; do
unset ADD_WEBUI_MACROS unset INSTALL_MJPG
echo echo
top_border top_border
echo -e "| It is recommended to have some important macros to |" echo -e "| Install MJGP-Streamer for webcam support? |"
echo -e "| have full functionality of the web interface. |"
blank_line
echo -e "| If you do not have such macros, you can choose to |"
echo -e "| install the suggested default macros now. |"
bottom_border bottom_border
read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
ADD_WEBUI_MACROS="true" INSTALL_MJPG="true"
break;; break;;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
ADD_WEBUI_MACROS="false" INSTALL_MJPG="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
@@ -39,56 +31,140 @@ get_user_selection_webui(){
done done
} }
install_mainsail(){ get_user_selection_kiauh_macros(){
get_user_selection_webui #ask user for webui default macros
#check if moonraker is already installed while true; do
check_moonraker unset ADD_KIAUH_MACROS
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then echo
#check for other enabled web interfaces top_border
unset SET_LISTEN_PORT echo -e "| It is recommended to have some important macros set |"
detect_enabled_sites echo -e "| up in your printer configuration to have $1|"
#check if another site already listens to port 80 echo -e "| fully functional and working. |"
mainsail_port_check blank_line
#creating the mainsail nginx cfg echo -e "| Those macros are: |"
set_nginx_cfg "mainsail" echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |"
#test_nginx "$SET_LISTEN_PORT" echo -e "| ${cyan}● [gcode_macro RESUME]${default} |"
locate_printer_cfg && read_printer_cfg "mainsail" echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |"
install_webui_macros blank_line
mainsail_setup echo -e "| If you already have these macros in your config file |"
fi echo -e "| you can skip this step and choose 'no'. |"
echo -e "| Otherwise you should consider to answer with 'yes' to |"
echo -e "| add the recommended example macros to your config. |"
bottom_border
read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
ADD_KIAUH_MACROS="true"
break;;
N|n|No|no)
echo -e "###### > No"
ADD_KIAUH_MACROS="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
} }
install_fluidd(){ install_webui(){
get_user_selection_webui ### check if moonraker is already installed
#check if moonraker is already installed
check_moonraker check_moonraker
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
#check for other enabled web interfaces
unset SET_LISTEN_PORT
detect_enabled_sites
#check if another site already listens to port 80
fluidd_port_check
#creating the fluidd nginx cfg
set_nginx_cfg "fluidd"
#test_nginx "$SET_LISTEN_PORT"
locate_printer_cfg && read_printer_cfg "fluidd"
install_webui_macros
fluidd_setup
fi
}
install_webui_macros(){ [ $1 == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail "
#copy webui_macros.cfg [ $1 == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd "
if [ "$ADD_WEBUI_MACROS" = "true" ]; then
status_msg "Create webui_macros.cfg ..." ### exit mainsail/fluidd setup if moonraker not found
if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then if [ $moonraker_chk_ok = "false" ]; then
cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!"
ok_msg "File created!" print_msg && clear_msg && return 0
else else
warn_msg "File already exists! Skipping ..." ok_msg "Moonraker service found!"
status_msg "Initializing $IF_NAME1 installation ..."
fi fi
### check for other enabled web interfaces
unset SET_LISTEN_PORT
detect_enabled_sites
### check if another site already listens to port 80
$1_port_check
### ask user to install mjpg-streamer
get_user_selection_mjpg-streamer
### ask user to install the recommended webinterface macros
get_user_selection_kiauh_macros "$IF_NAME2"
### creating the mainsail/fluidd nginx cfg
set_nginx_cfg "$1"
### symlink nginx log
symlink_webui_nginx_log "$1"
### copy the kiauh_macros.cfg to the config location
install_kiauh_macros
### install mainsail/fluidd
$1_setup
### install mjpg-streamer
[ "$INSTALL_MJPG" = "true" ] && install_mjpg-streamer
### confirm message
CONFIRM_MSG="$IF_NAME1 has been set up!"
print_msg && clear_msg
}
symlink_webui_nginx_log(){
LPATH="${HOME}/klipper_logs"
UI_ACCESS_LOG="/var/log/nginx/$1-access.log"
UI_ERROR_LOG="/var/log/nginx/$1-error.log"
[ ! -d "$LPATH" ] && mkdir -p "$LPATH"
if [ -f "$UI_ACCESS_LOG" ] && [ ! -L "$LPATH/$1-access.log" ]; then
status_msg "Creating symlink for $UI_ACCESS_LOG ..."
ln -s $UI_ACCESS_LOG "$LPATH"
ok_msg "OK!"
fi
if [ -f "$UI_ERROR_LOG" ] && [ ! -L "$LPATH/$1-error.log" ]; then
status_msg "Creating symlink for $UI_ERROR_LOG ..."
ln -s $UI_ERROR_LOG "$LPATH"
ok_msg "OK!"
fi
}
install_kiauh_macros(){
source_kiauh_ini
### copy kiauh_macros.cfg
if [ "$ADD_KIAUH_MACROS" = "true" ]; then
### create a backup of the config folder
backup_klipper_config_dir
### handle multi printer.cfg
if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then
for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do
path=$(echo $config | rev | cut -d"/" -f2- | rev)
if [ ! -f $path/kiauh_macros.cfg ]; then
### copy kiauh_macros.cfg to config location
status_msg "Creating macro config file ..."
cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $path
### write the include to the very first line of the printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg
ok_msg "$path/kiauh_macros.cfg created!"
fi
done
### handle single printer.cfg
elif [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/kiauh_macros.cfg ]; then
### copy kiauh_macros.cfg to config location
status_msg "Creating macro config file ..."
cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc
### write the include to the very first line of the printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" $klipper_cfg_loc/printer.cfg
ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!"
fi
### restart klipper service to parse the modified printer.cfg
klipper_service "restart"
fi fi
write_printer_cfg
} }
mainsail_port_check(){ mainsail_port_check(){
@@ -103,7 +179,7 @@ mainsail_port_check(){
select_mainsail_port select_mainsail_port
fi fi
else else
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/mainsail_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
SET_LISTEN_PORT=$DEFAULT_PORT SET_LISTEN_PORT=$DEFAULT_PORT
fi fi
SET_NGINX_CFG="true" SET_NGINX_CFG="true"
@@ -124,7 +200,7 @@ fluidd_port_check(){
select_fluidd_port select_fluidd_port
fi fi
else else
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/fluidd_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
SET_LISTEN_PORT=$DEFAULT_PORT SET_LISTEN_PORT=$DEFAULT_PORT
fi fi
SET_NGINX_CFG="true" SET_NGINX_CFG="true"
@@ -146,7 +222,8 @@ select_mainsail_port(){
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
blank_line blank_line
echo -e "| Make sure you don't choose a port which was already |" echo -e "| Make sure you don't choose a port which was already |"
echo -e "| assigned to one of the other web interfaces! |" echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |"
echo -e "| use ports in the range of 4750 or above! |"
blank_line blank_line
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
echo -e "| input. So make sure to choose a valid port! |" echo -e "| input. So make sure to choose a valid port! |"
@@ -177,7 +254,8 @@ select_fluidd_port(){
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
blank_line blank_line
echo -e "| Make sure you don't choose a port which was already |" echo -e "| Make sure you don't choose a port which was already |"
echo -e "| assigned to one of the other web interfaces! |" echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |"
echo -e "| use ports in the range of 4750 or above! |"
blank_line blank_line
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
echo -e "| input. So make sure to choose a valid port! |" echo -e "| input. So make sure to choose a valid port! |"
@@ -196,83 +274,57 @@ select_fluidd_port(){
} }
get_mainsail_ver(){ get_mainsail_ver(){
MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/releases | grep tag_name | cut -d'"' -f4 | cut -d"v" -f2 | head -1) MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/releases | grep tag_name | cut -d'"' -f4 | head -1)
} }
get_fluidd_ver(){ get_fluidd_ver(){
FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | cut -d"v" -f2 | head -1) FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | head -1)
} }
mainsail_setup(){ mainsail_setup(){
#get mainsail download url ### get mainsail download url
MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1) MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1)
#clean up an existing mainsail folder
### remove existing and create fresh mainsail folder, then download mainsail
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR [ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
#create fresh mainsail folder and download mainsail
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
status_msg "Downloading Mainsail $MAINSAIL_VERSION ..." status_msg "Downloading Mainsail $MAINSAIL_VERSION ..."
wget $MAINSAIL_DL_URL && ok_msg "Download complete!" wget $MAINSAIL_DL_URL && ok_msg "Download complete!"
#extract archive
### extract archive
status_msg "Extracting archive ..." status_msg "Extracting archive ..."
unzip -q -o *.zip && ok_msg "Done!" unzip -q -o *.zip && ok_msg "Done!"
#delete downloaded zip
### delete downloaded zip
status_msg "Remove downloaded archive ..." status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!" && ok_msg "Mainsail installation complete!" rm -rf *.zip && ok_msg "Done!"
echo
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode
if [ $(ls /etc/systemd/system/moonraker* | wc -l) -gt 1 ]; then
enable_mainsail_remotemode
fi
}
enable_mainsail_remotemode(){
rm -f $MAINSAIL_DIR/config.json
echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json
} }
fluidd_setup(){ fluidd_setup(){
#get fluidd download url ### get fluidd download url
FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4) FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4)
#clean up an existing fluidd folder
### remove existing and create fresh fluidd folder, then download fluidd
[ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR [ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR
#create fresh fluidd folder and download fluidd
mkdir $FLUIDD_DIR && cd $FLUIDD_DIR mkdir $FLUIDD_DIR && cd $FLUIDD_DIR
status_msg "Downloading Fluidd $FLUIDD_VERSION ..." status_msg "Downloading Fluidd $FLUIDD_VERSION ..."
wget $FLUIDD_DL_URL && ok_msg "Download complete!" wget $FLUIDD_DL_URL && ok_msg "Download complete!"
#extract archive
### extract archive
status_msg "Extracting archive ..." status_msg "Extracting archive ..."
unzip -q -o *.zip && ok_msg "Done!" unzip -q -o *.zip && ok_msg "Done!"
#patch moonraker.conf to apply cors domains if needed
backup_moonraker_conf
patch_moonraker
#delete downloaded zip
status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!"
echo
}
patch_moonraker(){ ### delete downloaded zip
status_msg "Patching moonraker.conf ..." status_msg "Remove downloaded archive ..."
mr_conf=${HOME}/moonraker.conf rm -rf *.zip && ok_msg "Done!"
# remove the now deprecated enable_cors option from moonraker.conf if it still exists
if [ "$(grep "^enable_cors:" $mr_conf)" ]; then
line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d"
sed -i "$line" $mr_conf && mr_restart="true"
fi
# looking for a cors_domain entry in moonraker.conf
if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then
#find trusted_clients line number and subtract one, to insert cors_domains later
line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i"
sed -i "$line cors_domains:" $mr_conf && mr_restart="true"
fi
if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then
hostname=$(hostname -I | cut -d" " -f1)
url1="\ \ \ \ http://*.local"
url2="\ \ \ \ http://app.fluidd.xyz"
url3="\ \ \ \ https://app.fluidd.xyz"
url4="\ \ \ \ http://$hostname:*"
#find cors_domains line number and add one, to insert urls later
line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i"
[ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true"
[ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true"
[ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true"
[ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true"
fi
#restart moonraker service if mr_restart was set to true
if [[ $mr_restart == "true" ]]; then
ok_msg "Patching done!" && restart_moonraker
else
ok_msg "No patching was needed!"
fi
} }

View File

@@ -1,13 +1,9 @@
install_klipperscreen(){ install_klipperscreen(){
python3_check python3_check
if [ $py_chk_ok = "true" ]; then if [ $py_chk_ok = "true" ]; then
system_check_klipperscreen source_kiauh_ini
#ask user for customization
get_user_selections_klipperscreen
#KlipperScreen main installation #KlipperScreen main installation
klipperscreen_setup klipperscreen_setup
#execute customizations
symlinks_klipperscreen
#after install actions #after install actions
restart_klipperscreen restart_klipperscreen
else else
@@ -28,56 +24,16 @@ python3_check(){
fi fi
} }
system_check_klipperscreen(){
if [ ! -e ${HOME}/klipper_config/KlipperScreen.log ]; then
KLIPPERSCREEN_SL_FOUND="false"
else
KLIPPERSCREEN_SL_FOUND="true"
fi
}
get_user_selections_klipperscreen(){
#user selection for KlipperScreen.log symlink
if [ "$KLIPPERSCREEN_SL_FOUND" = "false" ]; then
while true; do
echo
read -p "${cyan}###### Create KlipperScreen.log symlink? (y/N):${default} " yn
case "$yn" in
Y|y|Yes|yes)
echo -e "###### > Yes"
SEL_KSLOG_SL="true"
break;;
N|n|No|no|"")
echo -e "###### > No"
SEL_KSLOG_SL="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
klipperscreen_setup(){ klipperscreen_setup(){
dep=(wget curl unzip dfu-util) dep=(wget curl unzip dfu-util)
dependency_check dependency_check
status_msg "Downloading KlipperScreen ..." status_msg "Downloading KlipperScreen ..."
#force remove existing KlipperScreen dir # force remove existing KlipperScreen dir
[ -d $KLIPPERSCREEN_DIR ] && rm -rf $KLIPPERSCREEN_DIR [ -d $KLIPPERSCREEN_DIR ] && rm -rf $KLIPPERSCREEN_DIR
#clone into fresh KlipperScreen dir # clone into fresh KlipperScreen dir
cd ${HOME} && git clone $KLIPPERSCREEN_REPO cd ${HOME} && git clone $KLIPPERSCREEN_REPO
ok_msg "Download complete!" ok_msg "Download complete!"
status_msg "Installing KlipperScreen ..." status_msg "Installing KlipperScreen ..."
$KLIPPERSCREEN_DIR/scripts/KlipperScreen-install.sh $KLIPPERSCREEN_DIR/scripts/KlipperScreen-install.sh
echo; ok_msg "KlipperScreen successfully installed!" ok_msg "KlipperScreen successfully installed!"
}
symlinks_klipperscreen(){
#create a KlipperScreen.log symlink in klipper_config-dir just for convenience
if [ "$SEL_KSLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/KlipperScreen.log ]; then
status_msg "Creating KlipperScreen.log symlink ..."
ln -s /tmp/KlipperScreen.log ${HOME}/klipper_config
ok_msg "Symlink created!"
fi
} }

View File

@@ -0,0 +1,93 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
WEBCAM_TXT_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
install_mjpg-streamer(){
### checking dependencies
check_klipper_cfg_path
### set default values
MJPG_SERV_SRC="${SRCDIR}/kiauh/resources/webcamd.service"
MJPG_SERV_TARGET="$SYSTEMDDIR/webcamd.service"
WEBCAM_TXT="$klipper_cfg_loc/webcam.txt"
### if there is a webcamd.service -> exit
if [ -f $MJPG_SERV_TARGET ]; then
ERROR_MSG="Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
print_msg && clear_msg && return 0
fi
### check and install dependencies if missing
dep=(build-essential git imagemagick libv4l-dev libjpeg-dev libjpeg62-turbo-dev cmake)
dependency_check
### step 1: clone moonraker
status_msg "Downloading MJPG-Streamer ..."
cd ${HOME} && git clone https://github.com/jacksonliam/mjpg-streamer.git
ok_msg "Download complete!"
### step 2: compiling mjpg-streamer
status_msg "Compiling MJPG-Streamer ..."
cd ${HOME}/mjpg-streamer/mjpg-streamer-experimental && make
ok_msg "Compiling complete!"
#step 3: install mjpg-streamer
status_msg "Installing MJPG-Streamer ..."
cd ${HOME}/mjpg-streamer && mv mjpg-streamer-experimental/* .
mkdir www-mjpgstreamer
cat <<EOT >> ./www-mjpgstreamer/index.html
<html>
<head><title>mjpg_streamer test page</title></head>
<body>
<h1>Snapshot</h1>
<p>Refresh the page to refresh the snapshot</p>
<img src="./?action=snapshot" alt="Snapshot">
<h1>Stream</h1>
<img src="./?action=stream" alt="Stream">
</body>
</html>
EOT
sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd"
sudo sed -i "/^config_dir=/ s|=.*|=$klipper_cfg_loc|" /usr/local/bin/webcamd
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
sudo chmod +x /usr/local/bin/webcamd
### step 4: create webcam.txt config file
[ ! -d $klipper_cfg_loc ] && mkdir -p $klipper_cfg_loc
if [ ! -f $WEBCAM_TXT ]; then
status_msg "Creating webcam.txt config file ..."
wget $WEBCAM_TXT_SRC -O $WEBCAM_TXT
ok_msg "Done!"
fi
### step 5: create systemd service
status_msg "Creating MJPG-Streamer service ..."
sudo cp $MJPG_SERV_SRC $MJPG_SERV_TARGET
sudo sed -i "s|%USER%|${USER}|" $MJPG_SERV_TARGET
ok_msg "MJPG-Streamer service created!"
### step 6: enabling and starting mjpg-streamer service
status_msg "Starting MJPG-Streamer service ..."
sudo systemctl enable webcamd.service
sudo systemctl start webcamd.service
ok_msg "MJPG-Streamer service started!"
### step 6.1: create webcamd.log symlink
[ ! -d ${HOME}/klipper_logs ] && mkdir -p "${HOME}/klipper_logs"
if [ -f "/var/log/webcamd.log" ] && [ ! -L "${HOME}/klipper_logs/webcamd.log" ]; then
ln -s "/var/log/webcamd.log" "${HOME}/klipper_logs/webcamd.log"
fi
### confirm message
CONFIRM_MSG="MJPG-Streamer has been set up!"
print_msg && clear_msg
### print webcam ip adress/url
IP=$(hostname -I | cut -d" " -f1)
WEBCAM_IP="http://$IP:8080/?action=stream"
WEBCAM_URL="http://$IP/webcam/?action=stream"
echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_IP"
echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_URL"
echo
}

View File

@@ -1,31 +1,11 @@
install_moonraker(){ ### base variables
python3_check SYSTEMDDIR="/etc/systemd/system"
if [ $py_chk_ok = "true" ]; then MOONRAKER_ENV="${HOME}/moonraker-env"
system_check_moonraker MOONRAKER_DIR="${HOME}/moonraker"
#ask user for customization MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
get_user_selections_moonraker
#disable/remove haproxy/lighttpd
handle_haproxy_lighttpd
#moonraker main installation
moonraker_setup
check_for_folder_moonraker
#setup configs
setup_printer_config_moonraker
setup_moonraker_conf
#execute customizations
write_custom_trusted_clients
symlinks_moonraker
disable_octoprint
#after install actions
restart_moonraker
restart_klipper
else
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
print_msg && clear_msg
fi
}
python3_check(){ system_check_moonraker(){
### python 3 check
status_msg "Your Python 3 version is: $(python3 --version)" status_msg "Your Python 3 version is: $(python3 --version)"
major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1)
minor=$(python3 --version | cut -d"." -f2) minor=$(python3 --version | cut -d"." -f2)
@@ -33,156 +13,351 @@ python3_check(){
ok_msg "Python version ok!" ok_msg "Python version ok!"
py_chk_ok="true" py_chk_ok="true"
else else
warn_msg "Python version not ok!"
py_chk_ok="false" py_chk_ok="false"
fi fi
}
system_check_moonraker(){ ### check system for an installed and enabled octoprint service
status_msg "Initializing Moonraker installation ..." if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
#check for existing printer.cfg and for the location
locate_printer_cfg
if [ -f $PRINTER_CFG ]; then
PRINTER_CFG_FOUND="true"
PRINTER_CFG_LOC=$PRINTER_CFG
else
PRINTER_CFG_FOUND="false"
fi
#check for existing klippy.log symlink in /klipper_config
[ ! -e ${HOME}/klipper_config/klippy.log ] && KLIPPY_SL_FOUND="false"
#check for existing moonraker.log symlink in /klipper_config
[ ! -e ${HOME}/klipper_config/moonraker.log ] && MOONRAKER_SL_FOUND="false"
#check for existing moonraker.conf
if [ ! -f ${HOME}/moonraker.conf ]; then
MOONRAKER_CONF_FOUND="false"
else
MOONRAKER_CONF_FOUND="true"
fi
#check if octoprint is installed
if systemctl is-enabled octoprint.service -q 2>/dev/null; then
unset OCTOPRINT_ENABLED
OCTOPRINT_ENABLED="true" OCTOPRINT_ENABLED="true"
fi fi
#check if haproxy is installed
### check system for an installed haproxy service
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true" HAPROXY_FOUND="true"
fi fi
#check if lighttpd is installed
### check system for an installed lighttpd service
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
LIGHTTPD_FOUND="true" LIGHTTPD_FOUND="true"
fi fi
} }
get_user_selections_moonraker(){ moonraker_setup_dialog(){
#user selection for printer.cfg status_msg "Initializing Moonraker installation ..."
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
### check system for several requirements before initializing the moonraker installation
system_check_moonraker
### exit moonraker setup if python version is not ok
if [ $py_chk_ok = "false" ]; then
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
print_msg && clear_msg && return 0
fi
shopt -s extglob # enable extended globbing
### check for existing moonraker service installations
FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service"
if ls $FILE 2>/dev/null 1>&2; then
ERROR_MSG="At least one Moonraker service is already installed!" && return 0
fi
### check for existing klipper service installations
FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service"
if ! ls $FILE 2>/dev/null 1>&2; then
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
fi
shopt -u extglob # disable extended globbing
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### initial moonraker.conf path check
check_klipper_cfg_path
### ask user how to handle OctoPrint, Haproxy and Lighttpd
process_octoprint_dialog
process_haproxy_lighttpd_dialog
### instance confirmation dialog
while true; do while true; do
echo echo
top_border top_border
echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |" if [ $INSTANCE_COUNT -gt 1 ]; then
hr printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
echo -e "| KIAUH can create a minimal printer.cfg with only the |" else
echo -e "| recommended Moonraker config entries if you wish. |" echo -e "| 1 Klipper instance was found! | "
echo -e "| |" fi
echo -e "| Please be aware, that this option will ${red}NOT${default} create a |" echo -e "| You need one Moonraker instance per Klipper instance. | "
echo -e "| fully working printer.cfg for you! |"
bottom_border bottom_border
read -p "${cyan}###### Create a default printer.cfg? (Y/n):${default} " yn echo
read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
SEL_DEF_CFG="true" status_msg "Creating $INSTANCE_COUNT Moonraker instances ..."
moonraker_setup
break;; break;;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
SEL_DEF_CFG="false" warn_msg "Exiting Moonraker setup ..."
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
#user selection for moonraker.log symlink
if [ "$KLIPPY_SL_FOUND" = "false" ]; then
while true; do
echo echo
read -p "${cyan}###### Create klippy.log symlink? (y/N):${default} " yn
case "$yn" in
Y|y|Yes|yes)
echo -e "###### > Yes"
SEL_KLIPPYLOG_SL="true"
break;;
N|n|No|no|"")
echo -e "###### > No"
SEL_KLIPPYLOG_SL="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
print_msg && clear_msg;; print_msg && clear_msg;;
esac esac
done done
}
moonraker_setup(){
### checking dependencies
dep=(wget curl unzip dfu-util)
### additional deps for kiauh compatibility for armbian
dep+=(libjpeg-dev zlib1g-dev)
dependency_check
### step 1: clone moonraker
status_msg "Downloading Moonraker ..."
### force remove existing moonraker dir and clone into fresh moonraker dir
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
cd ${HOME} && git clone $MOONRAKER_REPO
ok_msg "Download complete!"
### step 2: install moonraker dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_moonraker_packages
create_moonraker_virtualenv
### step 3: create moonraker.conf folder and moonraker.confs
create_moonraker_conf
### step 4: set up moonrakers nginx configs
setup_moonraker_nginx_cfg
### step 5: process possible disruptive services
process_haproxy_lighttpd_services
# ### step 6: create final moonraker instances
create_moonraker_service
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
[ $INSTANCE_COUNT -eq 1 ] && CONFIRM_MSG="Moonraker has been set up!"
print_msg && clear_msg
### display moonraker ips to the user
print_mr_ip_list; echo
}
install_moonraker_packages(){
### read PKGLIST from official install script
status_msg "Reading dependencies..."
install_script="${HOME}/moonraker/scripts/install-moonraker.sh"
PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g')
### rewrite packages into new array
unset PKGARR
for PKG in $PKGLIST; do PKGARR+=($PKG); done
echo "${cyan}${PKGARR[@]}${default}"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGARR[@]}
}
create_moonraker_virtualenv(){
status_msg "Installing python virtual environment..."
### If venv exists and user prompts a rebuild, then do so
if [ -d ${MOONRAKER_ENV} ] && [ $REBUILD_ENV = "y" ]; then
status_msg "Removing old virtualenv"
rm -rf ${MOONRAKER_ENV}
fi fi
#user selection for moonraker.log symlink
if [ "$MOONRAKER_SL_FOUND" = "false" ]; then if [ ! -d ${MOONRAKER_ENV} ]; then
while true; do virtualenv -p /usr/bin/python3 ${MOONRAKER_ENV}
echo ln -s /usr/lib/python3/dist-packages/gpiod* ${MOONRAKER_ENV}/lib/python*/site-packages
read -p "${cyan}###### Create moonraker.log symlink? (y/N):${default} " yn fi
case "$yn" in
Y|y|Yes|yes) ### Install/update dependencies
echo -e "###### > Yes" ${MOONRAKER_ENV}/bin/pip install -r ${MOONRAKER_DIR}/scripts/moonraker-requirements.txt
SEL_MRLOG_SL="true" }
break;;
N|n|No|no|"") create_moonraker_service(){
echo -e "###### > No" ### get config directory
SEL_MRLOG_SL="false" source_kiauh_ini
break;;
*) ### set up default values
print_unkown_cmd SINGLE_INST=1
print_msg && clear_msg;; CFG_PATH="$klipper_cfg_loc"
esac MR_ENV=$MOONRAKER_ENV
MR_DIR=$MOONRAKER_DIR
MR_LOG="${HOME}/klipper_logs/moonraker.log"
MR_CONF="$CFG_PATH/moonraker.conf"
MR_SERV_SRC="${SRCDIR}/kiauh/resources/moonraker.service"
MR_SERV_TARGET="$SYSTEMDDIR/moonraker.service"
write_mr_service(){
if [ ! -f $MR_SERV_TARGET ]; then
status_msg "Creating Moonraker Service $i ..."
sudo cp $MR_SERV_SRC $MR_SERV_TARGET
sudo sed -i "s|%INST%|$i|" $MR_SERV_TARGET
sudo sed -i "s|%USER%|${USER}|" $MR_SERV_TARGET
sudo sed -i "s|%MR_ENV%|$MR_ENV|" $MR_SERV_TARGET
sudo sed -i "s|%MR_DIR%|$MR_DIR|" $MR_SERV_TARGET
sudo sed -i "s|%MR_LOG%|$MR_LOG|" $MR_SERV_TARGET
sudo sed -i "s|%MR_CONF%|$MR_CONF|" $MR_SERV_TARGET
fi
}
if [ $SINGLE_INST -eq $INSTANCE_COUNT ]; then
### write single instance service
write_mr_service
### enable instance
sudo systemctl enable moonraker.service
ok_msg "Single Moonraker instance created!"
### launching instance
status_msg "Launching Moonraker instance ..."
sudo systemctl start moonraker
else
i=1
while [ $i -le $INSTANCE_COUNT ]; do
### rewrite default variables for multi instance cases
CFG_PATH="$klipper_cfg_loc/printer_$i"
MR_SERV_TARGET="$SYSTEMDDIR/moonraker-$i.service"
MR_CONF="$CFG_PATH/moonraker.conf"
MR_LOG="${HOME}/klipper_logs/moonraker-$i.log"
### write multi instance service
write_mr_service
### enable instance
sudo systemctl enable moonraker-$i.service
ok_msg "Moonraker instance #$i created!"
### launching instance
status_msg "Launching Moonraker instance #$i ..."
sudo systemctl start moonraker-$i
### raise values by 1
i=$((i+1))
done done
unset i
### enable mainsails remoteMode if mainsail is found
if [ -d $MAINSAIL_DIR ]; then
status_msg "Mainsail installation found!"
status_msg "Enabling Mainsail remoteMode ..."
enable_mainsail_remotemode
ok_msg "Mainsails remoteMode enabled!"
fi fi
#ask user for more trusted clients fi
}
create_moonraker_conf(){
### get config directory
source_kiauh_ini
### set up default values
SINGLE_INST=1
PORT=7125
CFG_PATH="$klipper_cfg_loc"
LOG_PATH="${HOME}/klipper_logs"
MR_CONF="$CFG_PATH/moonraker.conf"
MR_DB="~/.moonraker_database"
KLIPPY_UDS="/tmp/klippy_uds"
MR_CONF_SRC="${SRCDIR}/kiauh/resources/moonraker.conf"
mr_ip_list=()
IP=$(hostname -I | cut -d" " -f1)
LAN="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
write_mr_conf(){
[ ! -d $CFG_PATH ] && mkdir -p $CFG_PATH
if [ ! -f $MR_CONF ]; then
status_msg "Creating moonraker.conf in $CFG_PATH ..."
cp $MR_CONF_SRC $MR_CONF
sed -i "s|%PORT%|$PORT|" $MR_CONF
sed -i "s|%CFG%|$CFG_PATH|" $MR_CONF
sed -i "s|%LOG%|$LOG_PATH|" $MR_CONF
sed -i "s|%MR_DB%|$MR_DB|" $MR_CONF
sed -i "s|%UDS%|$KLIPPY_UDS|" $MR_CONF
sed -i "s|%LAN%|$LAN|" $MR_CONF
sed -i "s|%USER%|${USER}|g" $MR_CONF
ok_msg "moonraker.conf created!"
else
warn_msg "There is already a file called 'moonraker.conf'!"
warn_msg "Skipping..."
fi
}
if [ $SINGLE_INST -eq $INSTANCE_COUNT ]; then
### write single instance config
write_mr_conf
mr_ip_list+=("$IP:$PORT")
else
i=1
while [ $i -le $INSTANCE_COUNT ]; do
### rewrite default variables for multi instance cases
CFG_PATH="$klipper_cfg_loc/printer_$i"
MR_CONF="$CFG_PATH/moonraker.conf"
MR_DB="~/.moonraker_database_$i"
KLIPPY_UDS="/tmp/klippy_uds-$i"
### write multi instance config
write_mr_conf
mr_ip_list+=("$IP:$PORT")
### raise values by 1
PORT=$((PORT+1))
i=$((i+1))
done
unset PORT && unset i
fi
}
print_mr_ip_list(){
i=1
for ip in ${mr_ip_list[@]}; do
echo -e " ${cyan}● Instance $i:${default} $ip"
i=$((i + 1))
done
}
setup_moonraker_nginx_cfg(){
get_date
### backup existing nginx configs
[ -f $NGINX_CONFD/upstreams.conf ] && sudo mv $NGINX_CONFD/upstreams.conf $NGINX_CONFD/$current_date_upstreams.conf
[ -f $NGINX_CONFD/common_vars.conf ] && sudo mv $NGINX_CONFD/common_vars.conf $NGINX_CONFD/$current_date_common_vars.conf
### copy nginx configs to target destination
if [ ! -f $NGINX_CONFD/upstreams.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/upstreams.conf $NGINX_CONFD
fi
if [ ! -f $NGINX_CONFD/common_vars.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/common_vars.conf $NGINX_CONFD
fi
}
process_octoprint_dialog(){
#ask user to disable octoprint when its service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
while true; do while true; do
echo echo
top_border top_border
echo -e "| Apart from devices of your local network, you can add |" echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
echo -e "| additional trusted clients to the moonraker.conf file |" hr
echo -e "| You might consider disabling the OctoPrint service, |"
echo -e "| since an active OctoPrint service may lead to unex- |"
echo -e "| pected behavior of the Klipper Webinterfaces. |"
bottom_border bottom_border
read -p "${cyan}###### Add additional trusted clients? (y/N):${default} " yn
case "$yn" in
Y|y|Yes|yes)
echo -e "###### > Yes"
ADD_TRUSTED_CLIENT="true"
custom_trusted_clients
break;;
N|n|No|no|"")
echo -e "###### > No"
ADD_TRUSTED_CLIENT="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
#ask user to disable octoprint when such installed service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
unset DISABLE_OPRINT
while true; do
echo
warn_msg "OctoPrint service found!"
echo -e "You might consider disabling the OctoPrint service,"
echo -e "since an active OctoPrint service may lead to unexpected"
echo -e "behavior of the Mainsail Webinterface."
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
DISABLE_OPRINT="true" status_msg "Stopping OctoPrint ..."
octoprint_service "stop" && ok_msg "OctoPrint service stopped!"
status_msg "Disabling OctoPrint ..."
octoprint_service "disable" && ok_msg "OctoPrint service disabled!"
break;; break;;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
DISABLE_OPRINT="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
@@ -190,6 +365,51 @@ get_user_selections_moonraker(){
esac esac
done done
fi fi
}
process_haproxy_lighttpd_services(){
#handle haproxy service
if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo systemctl stop haproxy && ok_msg "Service stopped!"
fi
### disable haproxy
if [ "$DISABLE_HAPROXY" = "true" ]; then
status_msg "Disabling haproxy ..."
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
### remove haproxy
if [ "$REMOVE_HAPROXY" = "true" ]; then
status_msg "Removing haproxy ..."
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!"
fi
fi
fi
### handle lighttpd service
if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo systemctl stop lighttpd && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!"
### remove lighttpd
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
status_msg "Removing lighttpd ..."
sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!"
fi
fi
fi
}
process_haproxy_lighttpd_dialog(){
#notify user about haproxy or lighttpd services found and possible issues #notify user about haproxy or lighttpd services found and possible issues
if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then
while true; do while true; do
@@ -216,11 +436,11 @@ get_user_selections_moonraker(){
1) 1)
echo -e "###### > Remove packages" echo -e "###### > Remove packages"
if [ "$HAPROXY_FOUND" = "true" ]; then if [ "$HAPROXY_FOUND" = "true" ]; then
DISABLE_HAPROXY="false" DISABLE_HAPROXY="true"
REMOVE_HAPROXY="true" REMOVE_HAPROXY="true"
fi fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then if [ "$LIGHTTPD_FOUND" = "true" ]; then
DISABLE_LIGHTTPD="false" DISABLE_LIGHTTPD="true"
REMOVE_LIGHTTPD="true" REMOVE_LIGHTTPD="true"
fi fi
break;; break;;
@@ -237,10 +457,6 @@ get_user_selections_moonraker(){
break;; break;;
3) 3)
echo -e "###### > Skip" echo -e "###### > Skip"
DISABLE_LIGHTTPD="false"
REMOVE_LIGHTTPD="false"
DISABLE_HAPROXY="false"
REMOVE_HAPROXY="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
@@ -248,297 +464,4 @@ get_user_selections_moonraker(){
esac esac
done done
fi fi
status_msg "Installation will start now! Please wait ..."
}
#############################################################
#############################################################
moonraker_setup(){
dep=(wget curl unzip dfu-util libjpeg-dev zlib1g-dev)
dependency_check
status_msg "Downloading Moonraker ..."
#force remove existing moonraker dir
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
#clone into fresh moonraker dir
cd ${HOME} && git clone $MOONRAKER_REPO
ok_msg "Download complete!"
status_msg "Installing Moonraker ..."
$MOONRAKER_DIR/scripts/install-moonraker.sh
#copy moonraker configuration for nginx to /etc/nginx/conf.d
setup_moonraker_nginx_cfg
#backup a possible existing printer.cfg at the old location and before patching in the new location
backup_printer_cfg
patch_klipper_sysfile "moonraker"
#re-run printer.cfg location function to read the new path for the printer.cfg
locate_printer_cfg
echo; ok_msg "Moonraker successfully installed!"
}
patch_klipper_sysfile(){
if [ -e $KLIPPER_SERVICE2 ]; then
status_msg "Checking /etc/default/klipper for necessary entries ..."
#patching new printer.cfg location to /etc/default/klipper
if [ "$1" = "moonraker" ]; then
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
sudo sed -i "/KLIPPY_ARGS=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE2
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
fi
fi
#patching new UDS argument to /etc/default/klipper
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then
status_msg "Patching unix domain socket to /etc/default/klipper ..."
#append the new argument to /tmp/klippy.log argument
sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2
ok_msg "Patching done!"
fi
fi
fi
if [ -e $KLIPPER_SERVICE3 ]; then
status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..."
#patching new printer.cfg location to /etc/systemd/system/klipper.service
if [ "$1" = "moonraker" ]; then
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then
status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..."
sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
#set variable if file got edited
SERVICE_FILE_PATCHED="true"
fi
fi
#patching new UDS argument to /etc/systemd/system/klipper.service
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then
status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..."
#append the new argument to /tmp/klippy.log argument
sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3
ok_msg "Patching done!"
#set variable if file got edited
SERVICE_FILE_PATCHED="true"
fi
fi
#reloading the units is only needed when the service file was patched.
[ "$SERVICE_FILE_PATCHED" = "true" ] && status_msg "Reloading unit ..." && sudo systemctl daemon-reload
fi
ok_msg "Check complete!"
echo
}
check_for_folder_moonraker(){
#check for / create sdcard folder
if [ ! -d ${HOME}/sdcard ]; then
status_msg "Creating sdcard directory ..."
mkdir ${HOME}/sdcard
ok_msg "sdcard directory created!"
fi
##check for / create klipper_config folder
if [ ! -d ${HOME}/klipper_config ]; then
status_msg "Creating klipper_config directory ..."
mkdir ${HOME}/klipper_config
ok_msg "klipper_config directory created!"
fi
}
#############################################################
#############################################################
setup_printer_config_moonraker(){
if [ "$PRINTER_CFG_FOUND" = "true" ]; then
#copy printer.cfg to new location if there is no printer.cfg at the new location already
if [ -f ${HOME}/printer.cfg ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then
status_msg "Copy printer.cfg to new location ..."
cp ${HOME}/printer.cfg $PRINTER_CFG
ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!"
fi
#check printer.cfg for necessary moonraker entries
read_printer_cfg "moonraker" && write_printer_cfg
fi
if [ "$SEL_DEF_CFG" = "true" ]; then
status_msg "Creating minimal default printer.cfg ..."
create_minimal_cfg
ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!"
fi
}
setup_moonraker_conf(){
if [ "$MOONRAKER_CONF_FOUND" = "false" ]; then
status_msg "Creating moonraker.conf ..."
cp ${HOME}/kiauh/resources/moonraker.conf ${HOME}
ok_msg "moonraker.conf created!"
status_msg "Writing trusted clients to config ..."
write_default_trusted_clients
ok_msg "Trusted clients written!"
fi
#check for at least one trusted client in an already existing moonraker.conf
#if no entry is found, write default trusted client
if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then
if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then
TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1)
FIRST_IP_LINE=$(expr $TC_LINE + 1)
FIRST_IP=$(sed -n "$FIRST_IP_LINE"p ${HOME}/moonraker.conf | cut -d" " -f5)
#if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then
if [ "$FIRST_IP" = "" ]; then
status_msg "Writing trusted clients to config ..."
backup_moonraker_conf && write_default_trusted_clients
ok_msg "Trusted clients written!"
fi
fi
fi
}
setup_moonraker_nginx_cfg(){
if [ ! -f $NGINX_CONFD/upstreams.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/moonraker_nginx.cfg $NGINX_CONFD/upstreams.conf
fi
if [ ! -f $NGINX_CONFD/common_vars.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/common_vars_nginx.cfg $NGINX_CONFD/common_vars.conf
fi
}
#############################################################
#############################################################
write_default_trusted_clients(){
DEFAULT_IP=$(hostname -I)
status_msg "Your devices current IP adress is:\n${cyan}$DEFAULT_IP ${default}"
#make IP of the device KIAUH is exectuted on as
#default trusted client and expand the IP range from 0 - 255
DEFAULT_IP_RANGE="$(echo "$DEFAULT_IP" | cut -d"." -f1-3).0/24"
status_msg "Writing the following IP range to moonraker.conf:\n${cyan}$DEFAULT_IP_RANGE ${default}"
#write the ip range in the first line below "trusted clients"
#example: 192.168.1.0/24
sed -i "/trusted_clients\:/a \ \ \ \ $DEFAULT_IP_RANGE" ${HOME}/moonraker.conf
ok_msg "IP range of ● $DEFAULT_IP_RANGE written to moonraker.conf!"
}
#############################################################
#############################################################
custom_trusted_clients(){
if [ "$ADD_TRUSTED_CLIENT" = "true" ]; then
unset trusted_arr
echo
top_border
echo -e "| You can now add additional trusted clients to your |"
echo -e "| moonraker.conf file. Be warned, that there is no |"
echo -e "| spellcheck to check for valid input. |"
echo -e "| Make sure to type the IP correct! |"
echo -e "| |"
echo -e "| If you want to add IP ranges, you can type in e.g.: |"
echo -e "| 192.168.1.0/24 |"
echo -e "| This will add the IPs 192.168.1.1 to 192.168.1.254 |"
echo -e "|-------------------------------------------------------|"
echo -e "| You can add as many IPs / IP ranges as you want. |"
echo -e "| When you are done type '${cyan}done${default}' to exit this dialoge. |"
bottom_border
while true; do
read -p "${cyan}###### Enter IP and press ENTER:${default} " TRUSTED_IP
case "$TRUSTED_IP" in
done)
echo
echo -e "List of IPs to add:"
for ip in ${trusted_arr[@]}
do
echo -e "${cyan}$ip ${default}"
done
while true; do
echo
echo -e "Select 'Yes' to confirm, 'No' to start again"
echo -e "or 'Q' to abort and skip."
read -p "${cyan}###### Confirm writing (Y/n/q):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
TUSTED_CLIENT_CONFIRM="true"
break;;
N|n|No|no)
echo -e "###### > No"
custom_trusted_clients
break;;
Q|q)
unset trusted_arr
echo -e "###### > Abort"
echo -e "${red}Aborting ...${default}"
break;;
esac
done
break;;
*)
trusted_arr+=($TRUSTED_IP);;
esac
done
fi
}
write_custom_trusted_clients(){
if [ "$TUSTED_CLIENT_CONFIRM" = "true" ]; then
if [ "${#trusted_arr[@]}" != "0" ]; then
for ip in ${trusted_arr[@]}
do
sed -i "/trusted_clients\:/a \ \ \ \ $ip" ${HOME}/moonraker.conf
done
ok_msg "Custom IPs written to moonraker.conf!"
fi
fi
}
symlinks_moonraker(){
#create a klippy.log/moonraker.log symlink in klipper_config-dir just for convenience
if [ "$SEL_KLIPPYLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/klippy.log ]; then
status_msg "Creating klippy.log symlink ..."
ln -s /tmp/klippy.log ${HOME}/klipper_config
ok_msg "Symlink created!"
fi
if [ "$SEL_MRLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/moonraker.log ]; then
status_msg "Creating moonraker.log symlink ..."
ln -s /tmp/moonraker.log ${HOME}/klipper_config
ok_msg "Symlink created!"
fi
}
handle_haproxy_lighttpd(){
#handle haproxy
if [ "$DISABLE_HAPROXY" = "true" ]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
fi
sudo systemctl disable haproxy
ok_msg "Haproxy service disabled!"
else
if [ "$REMOVE_HAPROXY" = "true" ]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
fi
status_msg "Removing haproxy ..."
sudo apt-get remove haproxy -y
sudo update-rc.d -f haproxy remove
ok_msg "Haproxy removed!"
fi
fi
#handle lighttpd
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!"
fi
sudo systemctl disable lighttpd
ok_msg "Lighttpd service disabled!"
else
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!"
fi
status_msg "Removing lighttpd ..."
sudo apt-get remove lighttpd -y
sudo update-rc.d -f lighttpd remove
ok_msg "Lighttpd removed!"
fi
fi
} }

View File

@@ -1,30 +1,46 @@
install_octoprint(){ ### base variables
#check for other enabled web interfaces SYSTEMDDIR="/etc/systemd/system"
unset SET_LISTEN_PORT OCTOPRINT_ENV="${HOME}/OctoPrint"
detect_enabled_sites
#ask user for customization
get_user_selections_octoprint
#octoprint main installation
octoprint_dependencies
octoprint_setup
add_groups
configure_autostart
add_reboot_permission
create_config_yaml
#execute customizations
set_nginx_cfg "octoprint"
set_hostname
#after install actions
load_octoprint_server
}
get_user_selections_octoprint(){ octoprint_setup_dialog(){
status_msg "Initializing OctoPrint installation ..." status_msg "Initializing OctoPrint installation ..."
#ask user to set a reverse proxy
octoprint_reverse_proxy_dialog ### count amount of klipper services
#ask to change hostname if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
[ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname INSTANCE_COUNT=1
status_msg "Installation will start now! Please wait ..." else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### instance confirmation dialog
while true; do
echo
top_border
if [ $INSTANCE_COUNT -gt 1 ]; then
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
else
echo -e "| 1 Klipper instance was found! | "
fi
echo -e "| You need one OctoPrint instance per Klipper instance. | "
bottom_border
echo
read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT OctoPrint instances ..."
octoprint_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting OctoPrint setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
} }
octoprint_dependencies(){ octoprint_dependencies(){
@@ -42,25 +58,39 @@ octoprint_dependencies(){
} }
octoprint_setup(){ octoprint_setup(){
if [ ! -d $OCTOPRINT_DIR ];then ### check and install all dependencies
status_msg "Create OctoPrint directory ..." octoprint_dependencies
mkdir -p $OCTOPRINT_DIR && ok_msg "Directory created!"
fi ### add user to usergroups and add reboot permissions
cd $OCTOPRINT_DIR add_to_groups
#create the virtualenv add_reboot_permission
### create and activate the virtualenv
[ ! -d $OCTOPRINT_ENV ] && mkdir -p $OCTOPRINT_ENV
status_msg "Set up virtualenv ..." status_msg "Set up virtualenv ..."
virtualenv venv cd $OCTOPRINT_ENV
virtualenv --python=python3 venv
source venv/bin/activate source venv/bin/activate
#install octoprint with pip
### install octoprint with pip
status_msg "Download and install OctoPrint ..." status_msg "Download and install OctoPrint ..."
pip install pip --upgrade pip install pip --upgrade
pip install --no-cache-dir octoprint pip install --no-cache-dir octoprint
ok_msg "Download complete!" ok_msg "Download complete!"
#leave virtualenv
### leave virtualenv
deactivate deactivate
### set up instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_octoprint_instance
else
create_multi_octoprint_instance
fi
} }
add_groups(){ add_to_groups(){
if [ ! "$(groups | grep tty)" ]; then if [ ! "$(groups | grep tty)" ]; then
status_msg "Adding user '${USER}' to group 'tty' ..." status_msg "Adding user '${USER}' to group 'tty' ..."
sudo usermod -a -G tty ${USER} && ok_msg "Done!" sudo usermod -a -G tty ${USER} && ok_msg "Done!"
@@ -71,143 +101,176 @@ add_groups(){
fi fi
} }
configure_autostart(){ create_single_octoprint_startscript(){
USER=$(whoami) ### create single instance systemd service file
cd $OCTOPRINT_DIR sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint.service" << OCTOPRINT
status_msg "Downloading files ..." [Unit]
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init Description=Starts OctoPrint on startup
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default After=network-online.target
ok_msg "Files downloaded successfully!" Wants=network-online.target
#make necessary changes in default file
status_msg "Configure OctoPrint Service ..." [Service]
DEFAULT_FILE=$OCTOPRINT_DIR/octoprint.default Environment="LC_ALL=C.UTF-8"
sed -i "s/pi/$USER/g" $DEFAULT_FILE Environment="LANG=C.UTF-8"
sed -i "s/#BASEDIR=/BASEDIR=/" $DEFAULT_FILE Type=simple
sed -i "s/#CONFIGFILE=/CONFIGFILE=/" $DEFAULT_FILE User=$USER
sed -i "s/#DAEMON=/DAEMON=/" $DEFAULT_FILE ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve
#move files to correct location
sudo mv octoprint.init $OCTOPRINT_SERVICE1 [Install]
sudo mv octoprint.default $OCTOPRINT_SERVICE2 WantedBy=multi-user.target
#make file in init.d executable OCTOPRINT
sudo chmod +x $OCTOPRINT_SERVICE1 }
status_msg "Reload systemd configuration files"
sudo update-rc.d octoprint defaults create_multi_octoprint_startscript(){
sudo systemctl daemon-reload ### create multi instance systemd service file
ok_msg "Configuration complete!" sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint-$INSTANCE.service" << OCTOPRINT
ok_msg "OctoPrint installed!" [Unit]
Description=Starts OctoPrint instance $INSTANCE on startup
After=network-online.target
Wants=network-online.target
[Service]
Environment="LC_ALL=C.UTF-8"
Environment="LANG=C.UTF-8"
Type=simple
User=$USER
ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve
[Install]
WantedBy=multi-user.target
OCTOPRINT
}
create_config_yaml(){
### create multi instance config.yaml file
/bin/sh -c "cat > ${BASEDIR}/config.yaml" << CONFIGYAML
serial:
additionalPorts:
- ${TMP_PRINTER}
disconnectOnErrors: false
port: ${TMP_PRINTER}
server:
commands:
serverRestartCommand: ${RESTART_COMMAND}
systemRestartCommand: sudo shutdown -r now
systemShutdownCommand: sudo shutdown -h now
CONFIGYAML
}
create_single_octoprint_instance(){
status_msg "Setting up 1 OctoPrint instance ..."
### single instance variables
PORT=5000
BASEDIR="${HOME}/.octoprint"
TMP_PRINTER="/tmp/printer"
CONFIG_YAML="$BASEDIR/config.yaml"
RESTART_COMMAND="sudo service octoprint restart"
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
op_ip_list=()
### create instance
status_msg "Creating single OctoPrint instance ..."
create_single_octoprint_startscript
op_ip_list+=("$HOSTNAME:$PORT")
### create the config.yaml
if [ ! -f $BASEDIR/config.yaml ]; then
status_msg "Creating config.yaml ..."
[ ! -d $BASEDIR ] && mkdir $BASEDIR
create_config_yaml
ok_msg "Config created!"
fi
### enable instance
sudo systemctl enable octoprint.service
ok_msg "Single OctoPrint instance created!"
### launching instance
status_msg "Launching OctoPrint instance ..."
sudo systemctl start octoprint
### confirm message
CONFIRM_MSG="Single OctoPrint instance has been set up!"
print_msg && clear_msg
### display all octoprint ips to the user
print_op_ip_list; echo
}
create_multi_octoprint_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of OctoPrint ..."
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
op_ip_list=()
### default port
PORT=5000
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
BASEDIR="${HOME}/.octoprint-$INSTANCE"
TMP_PRINTER="/tmp/printer-$INSTANCE"
CONFIG_YAML="$BASEDIR/config.yaml"
RESTART_COMMAND="sudo service octoprint restart"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_octoprint_startscript
op_ip_list+=("$HOSTNAME:$PORT")
### create the config.yaml
if [ ! -f $BASEDIR/config.yaml ]; then
status_msg "Creating config.yaml for instance #$INSTANCE..."
[ ! -d $BASEDIR ] && mkdir $BASEDIR
create_config_yaml
ok_msg "Config #$INSTANCE created!"
fi
### enable instance
sudo systemctl enable octoprint-$INSTANCE.service
ok_msg "OctoPrint instance $INSTANCE created!"
### launching instance
status_msg "Launching OctoPrint instance $INSTANCE ..."
sudo systemctl start octoprint-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
### port +1
PORT=$(expr $PORT + 1)
done
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT OctoPrint instances have been set up!"
print_msg && clear_msg
### display all moonraker ips to the user
print_op_ip_list; echo
} }
add_reboot_permission(){ add_reboot_permission(){
USER=$(whoami) USER=${USER}
#create a backup when file already exists #create a backup when file already exists
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old
fi fi
#create new permission file #create new permission file
status_msg "Add reboot permission to user '$USER' ..." status_msg "Add reboot permission to user '$USER' ..."
cd $OCTOPRINT_DIR cd ${HOME} && echo "$USER ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
echo "$USER ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
sudo chown 0 octoprint-shutdown sudo chown 0 octoprint-shutdown
sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown
ok_msg "Permission set!" ok_msg "Permission set!"
sleep 2
} }
octoprint_reverse_proxy_dialog(){ print_op_ip_list(){
echo i=1
top_border for ip in ${op_ip_list[@]}; do
echo -e "| If you want to have nicer URLs or simply need | " echo -e " ${cyan}● Instance $i:${default} $ip"
echo -e "| OctoPrint to run on port 80 (http's default port) | " i=$((i + 1))
echo -e "| due to some network restrictions, you can set up a | "
echo -e "| reverse proxy instead of configuring OctoPrint to | "
echo -e "| run on port 80. | "
bottom_border
while true; do
echo -e "${cyan}"
read -p "###### Do you want to set up a reverse proxy now? (y/N): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes)
octoprint_port_check
break;;
N|n|No|no|"")
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done done
} }
octoprint_port_check(){
if [ "$OCTOPRINT_ENABLED" = "false" ]; then
if [ "$SITE_ENABLED" = "true" ]; then
status_msg "Detected other enabled interfaces:"
[ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}"
[ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}"
[ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port:$DWC2_PORT${default}"
if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then
PORT_80_BLOCKED="true"
select_octoprint_port
fi
else
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/octoprint_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
SET_LISTEN_PORT=$DEFAULT_PORT
fi
SET_NGINX_CFG="true"
else
SET_NGINX_CFG="false"
fi
}
select_octoprint_port(){
if [ "$PORT_80_BLOCKED" = "true" ]; then
echo
top_border
echo -e "| ${red}!!!WARNING!!!${default} |"
echo -e "| ${red}You need to choose a different port for OctoPrint!${default} |"
echo -e "| ${red}The following web interface is listening at port 80:${default} |"
blank_line
[ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |"
[ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |"
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
blank_line
echo -e "| Make sure you don't choose a port which was already |"
echo -e "| assigned to one of the other web interfaces! |"
blank_line
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
echo -e "| input. So make sure to choose a valid port! |"
bottom_border
while true; do
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT
if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ]; then
echo "Setting port $NEW_PORT for OctoPrint!"
SET_LISTEN_PORT=$NEW_PORT
break
else
echo "That port is already taken! Select a different one!"
fi
done
fi
}
create_config_yaml(){
if [ ! -d $OCTOPRINT_CFG_DIR ]; then
status_msg "Creating config.yaml ..."
mkdir $OCTOPRINT_CFG_DIR
cp ${HOME}/kiauh/resources/octoprint_config.cfg $OCTOPRINT_CFG_DIR/config.yaml
ok_msg "Config created!"
fi
}
load_octoprint_server(){
start_octoprint
#create an octoprint.log symlink in home-dir just for convenience
if [ ! -e ${HOME}/octoprint.log ]; then
status_msg "Creating octoprint.log Symlink ..."
ln -s ${HOME}/.octoprint/logs/octoprint.log ${HOME}/octoprint.log && ok_msg "Symlink created!"
fi
ok_msg "OctoPrint is now running on:"
ok_msg "$(hostname -I | cut -d " " -f1):5000 or"
ok_msg "http://localhost:5000"; echo
}

75
scripts/ms_theme_installer.sh Executable file
View File

@@ -0,0 +1,75 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
check_select_printer(){
unset printer_num
### get klipper cfg loc and set default .theme folder loc
check_klipper_cfg_path
THEME_PATH="$klipper_cfg_loc"
### check if there is more than one moonraker instance and if yes
### ask the user to select the printer he wants to install/remove the theme
printer_count=$(ls /etc/systemd/system/moonraker*.service | wc -l)
if [ $printer_count -gt 1 ]; then
top_border
echo -e "| More than one printer was found on this system! | "
echo -e "| Please select the printer to which you want to | "
echo -e "| apply the previously selected action. | "
bottom_border
read -p "${cyan}Select printer:${default} " printer_num
### rewrite the .theme path matching the selected printer
THEME_PATH="$klipper_cfg_loc/printer_$printer_num"
fi
### create the cfg folder if there is none yet
[ ! -d $THEME_PATH ] && mkdir -p $THEME_PATH
}
ms_theme_delete(){
### check and select printer if there is more than 1
check_select_printer
### remove .theme folder
if [ -d "$THEME_PATH/.theme" ]; then
status_msg "Removing Theme ..."
rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n"
else
status_msg "No Theme installed!\n"
fi
}
ms_theme_dracula(){
THEME_URL="https://github.com/steadyjaw/dracula-mainsail-theme"
### check and select printer if there is more than 1
check_select_printer
### download all files
status_msg "Installing Dracula theme ..."
status_msg "Please wait ..."
[ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme"
cd $THEME_PATH && git clone "$THEME_URL" ".theme"
ok_msg "Theme installation complete!"
ok_msg "Please remember to delete your browser cache!\n"
}
ms_theme_cyberpunk(){
THEME_URL="https://github.com/Dario-Ciceri/cp2077-mainsail-theme"
### check and select printer if there is more than 1
check_select_printer
### download all files
status_msg "Installing Cyberpunk theme ..."
status_msg "Please wait ..."
[ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme"
cd $THEME_PATH && git clone "$THEME_URL" ".theme"
ok_msg "Theme installation complete!"
ok_msg "Please remember to delete your browser cache!\n"
}

View File

@@ -6,8 +6,9 @@ set_nginx_cfg(){
#execute operations #execute operations
status_msg "Creating Nginx configuration for $1 ..." status_msg "Creating Nginx configuration for $1 ..."
#copy content from resources to the respective nginx config file #copy content from resources to the respective nginx config file
cat ${SRCDIR}/kiauh/resources/$1_nginx.cfg > ${SRCDIR}/kiauh/resources/$1 cat ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg > ${SRCDIR}/kiauh/resources/$1
##edit the nginx config file before moving it ##edit the nginx config file before moving it
sed -i "s/<<UI>>/$1/g" ${SRCDIR}/kiauh/resources/$1
if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then
status_msg "Configuring port for $1 ..." status_msg "Configuring port for $1 ..."
#set listen port ipv4 #set listen port ipv4

View File

@@ -1,138 +1,33 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
remove_klipper(){ remove_klipper(){
data_arr=( shopt -s extglob # enable extended globbing
/etc/init.d/klipper ### ask the user if he wants to uninstall moonraker too.
/etc/default/klipper ###? currently usefull if the user wants to switch from single-instance to multi-instance
/etc/systemd/system/klipper.service FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service"
$KLIPPER_DIR if ls $FILE 2>/dev/null 1>&2; then
$KLIPPY_ENV_DIR
${HOME}/klippy.log
)
print_error "Klipper" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
stop_klipper
if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then
status_msg "Removing Klipper Service ..."
sudo rm -rf /etc/init.d/klipper /etc/default/klipper
sudo update-rc.d -f klipper remove
sudo systemctl disable klipper
sudo systemctl daemon-reload
ok_msg "Klipper Service removed!"
fi
if [ -e /etc/systemd/system/klipper.service ]; then
status_msg "Removing Klipper Service ..."
sudo rm -rf /etc/systemd/system/klipper.service
sudo update-rc.d -f klipper remove
sudo systemctl disable klipper
sudo systemctl daemon-reload
ok_msg "Klipper Service removed!"
fi
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then
status_msg "Removing Klipper and klippy-env directory ..."
rm -rf $KLIPPER_DIR $KLIPPY_ENV_DIR && ok_msg "Directories removed!"
fi
if [[ -L ${HOME}/klippy.log || -e /tmp/klippy.log ]]; then
status_msg "Removing klippy.log Symlink ..."
rm -rf ${HOME}/klippy.log /tmp/klippy.log && ok_msg "Symlink removed!"
fi
CONFIRM_MSG=" Klipper successfully removed!"
fi
}
#############################################################
#############################################################
remove_dwc2(){
data_arr=(
/etc/init.d/dwc
/etc/default/dwc
/etc/systemd/system/dwc.service
$DWC2FK_DIR
$DWC_ENV_DIR
$DWC2_DIR
/etc/nginx/sites-available/dwc2
/etc/nginx/sites-enabled/dwc2
)
print_error "DWC2-for-Klipper-Socket &\n DWC2 Web UI" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
if systemctl is-active dwc -q; then
status_msg "Stopping DWC2-for-Klipper-Socket Service ..."
sudo systemctl stop dwc && sudo systemctl disable dwc
ok_msg "Service stopped!"
fi
#remove if init.d service
if [[ -e /etc/init.d/dwc || -e /etc/default/dwc ]]; then
status_msg "Init.d Service found ..."
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
sudo rm -rf /etc/init.d/dwc /etc/default/dwc
sudo update-rc.d -f dwc remove
ok_msg "DWC2-for-Klipper-Socket Service removed!"
fi
#remove if systemd service
if [ -e /etc/systemd/system/dwc.service ]; then
status_msg "Systemd Service found ..."
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
sudo rm -rf /etc/systemd/system/dwc.service
ok_msg "DWC2-for-Klipper-Socket Service removed!"
fi
if [ -d $DWC2FK_DIR ]; then
status_msg "Removing DWC2-for-Klipper-Socket directory ..."
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
fi
if [ -d $DWC_ENV_DIR ]; then
status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..."
rm -rf $DWC_ENV_DIR && ok_msg "File removed!"
fi
if [ -d $DWC2_DIR ]; then
status_msg "Removing DWC2 directory ..."
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
fi
#remove dwc2 config for nginx
if [ -e /etc/nginx/sites-available/dwc2 ]; then
status_msg "Removing DWC2 configuration for Nginx ..."
sudo rm /etc/nginx/sites-available/dwc2 && ok_msg "File removed!"
fi
#remove dwc2 symlink for nginx
if [ -L /etc/nginx/sites-enabled/dwc2 ]; then
status_msg "Removing DWC2 Symlink for Nginx ..."
sudo rm /etc/nginx/sites-enabled/dwc2 && ok_msg "File removed!"
fi
CONFIRM_MSG=" DWC2-for-Klipper-Socket & DWC2 successfully removed!"
fi
}
#############################################################
#############################################################
remove_moonraker(){
data_arr=(
$MOONRAKER_SERVICE1
$MOONRAKER_SERVICE2
$MOONRAKER_DIR
$MOONRAKER_ENV_DIR
$NGINX_CONFD/upstreams.conf
$NGINX_CONFD/common_vars.conf
${HOME}/moonraker.conf
${HOME}/moonraker.log
${HOME}/klipper_config/moonraker.log
${HOME}/klipper_config/klippy.log
${HOME}/.klippy_api_key
${HOME}/.moonraker_api_key
)
print_error "Moonraker" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
if [ -e ${HOME}/moonraker.conf ]; then
unset REMOVE_MOONRAKER_CONF
while true; do while true; do
echo unset REM_MR
read -p "${cyan}###### Delete moonraker.conf? (y/N):${default} " yn top_border
echo -e "| Do you want to remove Moonraker afterwards? |"
echo -e "| |"
echo -e "| This is useful in case you want to switch from a |"
echo -e "| single-instance to a multi-instance installation, |"
echo -e "| which makes a re-installation of Moonraker necessary. |"
echo -e "| |"
echo -e "| If for any other reason you only want to uninstall |"
echo -e "| Klipper, please select 'No' and continue. |"
bottom_border
read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes) Y|y|Yes|yes)
echo -e "###### > Yes" echo -e "###### > Yes"
REMOVE_MOONRAKER_CONF="true" REM_MR="true"
break;; break;;
N|n|No|no|"") N|n|No|no|"")
echo -e "###### > No" echo -e "###### > No"
REMOVE_MOONRAKER_CONF="false" REM_MR="false"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
@@ -140,151 +35,317 @@ remove_moonraker(){
esac esac
done done
fi fi
status_msg "Processing ..."
stop_moonraker ### remove "legacy" klipper init.d service
#remove moonraker services if [ -e /etc/init.d/klipper ]; then
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then status_msg "Removing Klipper Service ..."
sudo systemctl stop klipper
sudo update-rc.d -f klipper remove
sudo rm -f /etc/init.d/klipper
sudo rm -f /etc/default/klipper
ok_msg "Klipper Service removed!"
fi
### remove all klipper services
FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service"
if ls $FILE 2>/dev/null 1>&2; then
status_msg "Removing Klipper Services ..."
for service in $(ls $FILE | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Klipper Service removed!"
fi
### remove all logfiles
FILE="${HOME}/klipper_logs/klippy?(-*([0-9])).log"
if ls $FILE 2>/dev/null 1>&2; then
for log in $(ls $FILE); do
status_msg "Removing $log ..."
rm -f $log
ok_msg "$log removed!"
done
fi
### remove all UDS
FILE="/tmp/klippy_uds?(-*([0-9]))"
if ls $FILE 2>/dev/null 1>&2; then
for uds in $(ls $FILE); do
status_msg "Removing $uds ..."
rm -f $uds
ok_msg "$uds removed!"
done
fi
### remove all tmp-printer
FILE="/tmp/printer?(-*([0-9]))"
if ls $FILE 2>/dev/null 1>&2; then
for tmp_printer in $(ls $FILE); do
status_msg "Removing $tmp_printer ..."
rm -f $tmp_printer
ok_msg "$tmp_printer removed!"
done
fi
### removing klipper and klippy-env folders
if [ -d $KLIPPER_DIR ]; then
status_msg "Removing Klipper directory ..."
rm -rf $KLIPPER_DIR && ok_msg "Directory removed!"
fi
if [ -d $KLIPPY_ENV ]; then
status_msg "Removing klippy-env directory ..."
rm -rf $KLIPPY_ENV && ok_msg "Directory removed!"
fi
CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg
shopt -u extglob # enable extended globbing
if [ "$REM_MR" == "true" ]; then
remove_moonraker && unset REM_MR
fi
}
#############################################################
#############################################################
remove_moonraker(){
shopt -s extglob # enable extended globbing
### remove "legacy" moonraker init.d service
if [ -f /etc/init.d/moonraker ]; then
status_msg "Removing Moonraker Service ..." status_msg "Removing Moonraker Service ..."
sudo systemctl stop moonraker
sudo update-rc.d -f moonraker remove sudo update-rc.d -f moonraker remove
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker Service removed!" sudo rm -f /etc/init.d/moonraker
sudo rm -f /etc/default/moonraker
ok_msg "Moonraker Service removed!"
fi fi
#remove moonraker and moonraker-env dir
if [[ -d $MOONRAKER_DIR || -d $MOONRAKER_ENV_DIR ]]; then ### remove all moonraker services
status_msg "Removing Moonraker and moonraker-env directory ..." FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service"
rm -rf $MOONRAKER_DIR $MOONRAKER_ENV_DIR && ok_msg "Directories removed!" if ls $FILE 2>/dev/null 1>&2; then
status_msg "Removing Moonraker Services ..."
for service in $(ls $FILE | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Moonraker Service removed!"
fi fi
#remove moonraker.conf
if [ "$REMOVE_MOONRAKER_CONF" = "true" ]; then ### remove all logfiles
status_msg "Removing moonraker.conf ..." FILE="${HOME}/klipper_logs/moonraker?(-*([0-9])).log"
rm -rf ${HOME}/moonraker.conf && ok_msg "File removed!" if ls $FILE 2>/dev/null 1>&2; then
for log in $(ls $FILE); do
status_msg "Removing $log ..."
rm -f $log
ok_msg "$log removed!"
done
fi fi
#remove moonraker.log and symlink
if [[ -L ${HOME}/moonraker.log || -L ${HOME}/klipper_config/moonraker.log || -L ${HOME}/klipper_config/klippy.log || -e /tmp/moonraker.log ]]; then ### remove moonraker nginx config
status_msg "Removing Logs and Symlinks ..."
rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log ${HOME}/klipper_config/klippy.log /tmp/moonraker.log
ok_msg "Files removed!"
fi
#remove moonraker nginx config
if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then
status_msg "Removing Moonraker NGINX configuration ..." status_msg "Removing Moonraker NGINX configuration ..."
sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!" sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!"
fi fi
#remove legacy api key
### remove legacy api key
if [ -e ${HOME}/.klippy_api_key ]; then if [ -e ${HOME}/.klippy_api_key ]; then
status_msg "Removing legacy API Key ..." status_msg "Removing legacy API Key ..." && rm ${HOME}/.klippy_api_key && ok_msg "Done!"
rm ${HOME}/.klippy_api_key && ok_msg "Done!"
fi fi
#remove api key
### remove api key
if [ -e ${HOME}/.moonraker_api_key ]; then if [ -e ${HOME}/.moonraker_api_key ]; then
status_msg "Removing API Key ..." status_msg "Removing API Key ..." && rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
fi fi
CONFIRM_MSG="Moonraker successfully removed!"
### removing moonraker and moonraker-env folder
if [ -d $MOONRAKER_DIR ]; then
status_msg "Removing Moonraker directory ..."
rm -rf $MOONRAKER_DIR && ok_msg "Directory removed!"
fi fi
if [ -d $MOONRAKER_ENV ]; then
status_msg "Removing moonraker-env directory ..."
rm -rf $MOONRAKER_ENV && ok_msg "Directory removed!"
fi
CONFIRM_MSG=" Moonraker was successfully removed!"
shopt -u extglob # disable extended globbing
}
#############################################################
#############################################################
remove_dwc2(){
### remove "legacy" init.d service
if [ -e /etc/init.d/dwc ]; then
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
sudo systemctl stop dwc
sudo update-rc.d -f dwc remove
sudo rm -f /etc/init.d/dwc
sudo rm -f /etc/default/dwc
ok_msg "DWC2-for-Klipper-Socket Service removed!"
fi
### remove all dwc services
if ls /etc/systemd/system/dwc*.service 2>/dev/null 1>&2; then
status_msg "Removing DWC2-for-Klipper-Socket Services ..."
for service in $(ls /etc/systemd/system/dwc*.service | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "DWC2-for-Klipper-Socket Service removed!"
fi
### remove all logfiles
if ls /tmp/dwc*.log 2>/dev/null 1>&2; then
for logfile in $(ls /tmp/dwc*.log)
do
status_msg "Removing $logfile ..."
rm -f $logfile
ok_msg "File '$logfile' removed!"
done
fi
### removing the rest of the folders
if [ -d $DWC2FK_DIR ]; then
status_msg "Removing DWC2-for-Klipper-Socket directory ..."
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
fi
if [ -d $DWC_ENV_DIR ]; then
status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..."
rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!"
fi
if [ -d $DWC2_DIR ]; then
status_msg "Removing DWC2 directory ..."
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
fi
CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!"
} }
############################################################# #############################################################
############################################################# #############################################################
remove_mainsail(){ remove_mainsail(){
data_arr=( ### remove mainsail dir
$MAINSAIL_DIR
/etc/nginx/sites-available/mainsail
/etc/nginx/sites-enabled/mainsail
)
print_error "Mainsail" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
#remove mainsail dir
if [ -d $MAINSAIL_DIR ]; then if [ -d $MAINSAIL_DIR ]; then
status_msg "Removing Mainsail directory ..." status_msg "Removing Mainsail directory ..."
rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!" rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!"
fi fi
#remove mainsail config for nginx
### remove mainsail config for nginx
if [ -e /etc/nginx/sites-available/mainsail ]; then if [ -e /etc/nginx/sites-available/mainsail ]; then
status_msg "Removing Mainsail configuration for Nginx ..." status_msg "Removing Mainsail configuration for Nginx ..."
sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!" sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!"
fi fi
#remove mainsail symlink for nginx
### remove mainsail symlink for nginx
if [ -L /etc/nginx/sites-enabled/mainsail ]; then if [ -L /etc/nginx/sites-enabled/mainsail ]; then
status_msg "Removing Mainsail Symlink for Nginx ..." status_msg "Removing Mainsail Symlink for Nginx ..."
sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!" sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!"
fi fi
### remove mainsail nginx logs and log symlinks
for log in $(find /var/log/nginx -name "mainsail*"); do
sudo rm -f $log
done
for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do
rm -f $log
done
CONFIRM_MSG="Mainsail successfully removed!" CONFIRM_MSG="Mainsail successfully removed!"
fi
} }
remove_fluidd(){ remove_fluidd(){
data_arr=( ### remove fluidd dir
$FLUIDD_DIR
/etc/nginx/sites-available/fluidd
/etc/nginx/sites-enabled/fluidd
)
print_error "Fluidd" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
#remove fluidd dir
if [ -d $FLUIDD_DIR ]; then if [ -d $FLUIDD_DIR ]; then
status_msg "Removing Fluidd directory ..." status_msg "Removing Fluidd directory ..."
rm -rf $FLUIDD_DIR && ok_msg "Directory removed!" rm -rf $FLUIDD_DIR && ok_msg "Directory removed!"
fi fi
#remove fluidd config for nginx
### remove fluidd config for nginx
if [ -e /etc/nginx/sites-available/fluidd ]; then if [ -e /etc/nginx/sites-available/fluidd ]; then
status_msg "Removing Fluidd configuration for Nginx ..." status_msg "Removing Fluidd configuration for Nginx ..."
sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!" sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!"
fi fi
#remove fluidd symlink for nginx
### remove fluidd symlink for nginx
if [ -L /etc/nginx/sites-enabled/fluidd ]; then if [ -L /etc/nginx/sites-enabled/fluidd ]; then
status_msg "Removing Fluidd Symlink for Nginx ..." status_msg "Removing Fluidd Symlink for Nginx ..."
sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!"
fi fi
### remove mainsail nginx logs and log symlinks
for log in $(find /var/log/nginx -name "fluidd*"); do
sudo rm -f $log
done
for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do
rm -f $log
done
CONFIRM_MSG="Fluidd successfully removed!" CONFIRM_MSG="Fluidd successfully removed!"
fi
} }
############################################################# #############################################################
############################################################# #############################################################
remove_octoprint(){ remove_octoprint(){
data_arr=( ###remove all octoprint services
$OCTOPRINT_SERVICE1 if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then
$OCTOPRINT_SERVICE2 status_msg "Removing OctoPrint Services ..."
$OCTOPRINT_DIR for service in $(ls /etc/systemd/system/octoprint*.service | cut -d"/" -f5)
$OCTOPRINT_CFG_DIR do
${HOME}/octoprint.log status_msg "Removing $service ..."
/etc/sudoers.d/octoprint-shutdown sudo systemctl stop $service
/etc/nginx/sites-available/octoprint sudo systemctl disable $service
/etc/nginx/sites-enabled/octoprint sudo rm -f $SYSTEMDDIR/$service
) ok_msg "OctoPrint Service removed!"
print_error "OctoPrint" && data_count=() done
if [ "$ERROR_MSG" = "" ]; then ### reloading units
stop_octoprint sudo systemctl daemon-reload
if [[ -e $OCTOPRINT_SERVICE1 || -e $OCTOPRINT_SERVICE2 ]]; then sudo systemctl reset-failed
status_msg "Removing OctoPrint Service ..."
sudo update-rc.d -f octoprint remove
sudo rm -rf $OCTOPRINT_SERVICE1 $OCTOPRINT_SERVICE2 && ok_msg "OctoPrint Service removed!"
fi
if [[ -d $OCTOPRINT_DIR || -d $OCTOPRINT_CFG_DIR ]]; then
status_msg "Removing OctoPrint and .octoprint directory ..."
rm -rf $OCTOPRINT_DIR $OCTOPRINT_CFG_DIR && ok_msg "Directories removed!"
fi fi
### remove sudoers file
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
sudo rm -rf /etc/sudoers.d/octoprint-shutdown sudo rm -rf /etc/sudoers.d/octoprint-shutdown
fi fi
if [ -L ${HOME}/octoprint.log ]; then
status_msg "Removing octoprint.log Symlink ..." ### remove OctoPrint directory
rm -rf ${HOME}/octoprint.log && ok_msg "Symlink removed!" if [ -d ${HOME}/OctoPrint ]; then
status_msg "Removing OctoPrint directory ..."
rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!"
fi fi
#remove octoprint config for nginx
if [ -e /etc/nginx/sites-available/octoprint ]; then ###remove .octoprint directories
status_msg "Removing OctoPrint configuration for Nginx ..." if ls -d ${HOME}/.octoprint* 2>/dev/null 1>&2; then
sudo rm /etc/nginx/sites-available/octoprint && ok_msg "File removed!" for folder in $(ls -d ${HOME}/.octoprint*)
fi do
#remove octoprint symlink for nginx status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!"
if [ -L /etc/nginx/sites-enabled/octoprint ]; then done
status_msg "Removing OctoPrint Symlink for Nginx ..."
sudo rm /etc/nginx/sites-enabled/octoprint && ok_msg "File removed!"
fi fi
CONFIRM_MSG=" OctoPrint successfully removed!" CONFIRM_MSG=" OctoPrint successfully removed!"
fi
} }
############################################################# #############################################################
@@ -307,27 +368,75 @@ remove_nginx(){
} }
remove_klipperscreen(){ remove_klipperscreen(){
data_arr=( source_kiauh_ini
$KLIPPERSCREEN_DIR
$KLIPPERSCREEN_ENV_DIR ### remove KlipperScreen dir
/etc/systemd/system/KlipperScreen.service
)
print_error "KlipperScreen" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
#remove KlipperScreen dir
if [ -d $KLIPPERSCREEN_DIR ]; then if [ -d $KLIPPERSCREEN_DIR ]; then
status_msg "Removing KlipperScreen directory ..." status_msg "Removing KlipperScreen directory ..."
rm -rf $KLIPPERSCREEN_DIR && ok_msg "Directory removed!" rm -rf $KLIPPERSCREEN_DIR && ok_msg "Directory removed!"
fi fi
### remove KlipperScreen VENV dir
if [ -d $KLIPPERSCREEN_ENV_DIR ]; then if [ -d $KLIPPERSCREEN_ENV_DIR ]; then
status_msg "Removing KlipperScreen VENV directory ..." status_msg "Removing KlipperScreen VENV directory ..."
rm -rf $KLIPPERSCREEN_ENV_DIR && ok_msg "Directory removed!" rm -rf $KLIPPERSCREEN_ENV_DIR && ok_msg "Directory removed!"
fi fi
#remove KlipperScreen systemd file
### remove KlipperScreen service
if [ -e /etc/systemd/system/KlipperScreen.service ]; then if [ -e /etc/systemd/system/KlipperScreen.service ]; then
status_msg "Removing KlipperScreen Service ..." status_msg "Removing KlipperScreen service ..."
sudo rm /etc/systemd/system/KlipperScreen.service && ok_msg "File removed!" sudo systemctl stop KlipperScreen
sudo systemctl disable moonraker
sudo rm -f $SYSTEMDDIR/KlipperScreen.service
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "KlipperScreen Service removed!"
fi fi
### remove KlipperScreen log
if [ -e /tmp/KlipperScreen.log ]; then
status_msg "Removing KlipperScreen log file ..."
rm -f /tmp/KlipperScreen.log && ok_msg "File removed!"
fi
### remove KlipperScreen log symlink in config dir
if [ -e $klipper_cfg_loc/KlipperScreen.log ]; then
status_msg "Removing KlipperScreen log symlink ..."
rm -f $klipper_cfg_loc/KlipperScreen.log && ok_msg "File removed!"
fi
CONFIRM_MSG="KlipperScreen successfully removed!" CONFIRM_MSG="KlipperScreen successfully removed!"
fi }
remove_mjpg-streamer(){
### remove MJPG-Streamer service
if [ -e $SYSTEMDDIR/webcamd.service ]; then
status_msg "Removing MJPG-Streamer service ..."
sudo systemctl stop webcamd && sudo systemctl disable webcamd
sudo rm -f $SYSTEMDDIR/webcamd.service
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "MJPG-Streamer Service removed!"
fi
### remove webcamd from /usr/local/bin
if [ -e "/usr/local/bin/webcamd" ]; then
sudo rm -f "/usr/local/bin/webcamd"
fi
### remove MJPG-Streamer directory
if [ -d ${HOME}/mjpg-streamer ]; then
status_msg "Removing MJPG-Streamer directory ..."
rm -rf ${HOME}/mjpg-streamer
ok_msg "MJPG-Streamer directory removed!"
fi
### remove webcamd log and symlink
[ -f "/var/log/webcamd.log" ] && sudo rm -f "/var/log/webcamd.log"
[ -L "${HOME}/klipper_logs/webcamd.log" ] && rm -f "${HOME}/klipper_logs/webcamd.log"
CONFIRM_MSG="MJPG-Streamer successfully removed!"
} }

View File

@@ -1,5 +1,5 @@
save_klipper_state(){ save_klipper_state(){
source_ini source_kiauh_ini
#read current klipper state #read current klipper state
cd $KLIPPER_DIR cd $KLIPPER_DIR
COMMIT_STATE=$(git rev-parse --short HEAD) COMMIT_STATE=$(git rev-parse --short HEAD)
@@ -19,7 +19,7 @@ save_klipper_state(){
} }
load_klipper_state(){ load_klipper_state(){
source_ini source_kiauh_ini
print_branch print_branch
cd $KLIPPER_DIR cd $KLIPPER_DIR
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) CURRENT_COMMIT=$(git rev-parse --short=8 HEAD)

View File

@@ -1,8 +1,8 @@
kiauh_status(){ kiauh_status(){
if [ -d "${SRCDIR}/kiauh/.git" ]; then if [ -d "${SRCDIR}/kiauh/.git" ]; then
cd ${HOME}/kiauh cd ${SRCDIR}/kiauh
git fetch -q
if git branch -a | grep "* master" -q; then if git branch -a | grep "* master" -q; then
git fetch -q
if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then
KIAUH_UPDATE_AVAIL="true" KIAUH_UPDATE_AVAIL="true"
fi fi
@@ -10,6 +10,17 @@ kiauh_status(){
fi fi
} }
check_system_updates(){
SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d")
if [ ! -z "$SYS_UPDATE" ]; then
SYS_UPDATE_AVAIL="true"
DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${default}"
else
SYS_UPDATE_AVAIL="false"
DISPLAY_SYS_UPDATE="${green}System up to date! ${default}"
fi
}
klipper_status(){ klipper_status(){
kcount=0 kcount=0
klipper_data=( klipper_data=(
@@ -17,17 +28,29 @@ klipper_status(){
$KLIPPER_DIR $KLIPPER_DIR
$KLIPPY_ENV_DIR $KLIPPY_ENV_DIR
) )
#remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && unset klipper_data[0] ### count amount of klipper service files in /etc/systemd/system
#count+1 for each found data-item from array SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^klipper(\-[[:digit:]]+)?\.service$" | wc -l)
### a fix to detect an existing "legacy" klipper init.d installation
if [ -f /etc/init.d/klipper ] && [ -f /etc/init.d/klipper ]; then
SERVICE_FILE_COUNT=1
fi
### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0]
### count+1 for each found data-item from array
for kd in "${klipper_data[@]}" for kd in "${klipper_data[@]}"
do do
if [ -e $kd ]; then if [ -e $kd ]; then
kcount=$(expr $kcount + 1) kcount=$(expr $kcount + 1)
fi fi
done done
### display status
if [ "$kcount" == "${#klipper_data[*]}" ]; then if [ "$kcount" == "${#klipper_data[*]}" ]; then
KLIPPER_STATUS="${green}Installed!${default} " KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
elif [ "$kcount" == 0 ]; then elif [ "$kcount" == 0 ]; then
KLIPPER_STATUS="${red}Not installed!${default} " KLIPPER_STATUS="${red}Not installed!${default} "
else else
@@ -37,20 +60,29 @@ klipper_status(){
dwc2_status(){ dwc2_status(){
dcount=0 dcount=0
dwc2_data=( dwc_data=(
SERVICE
$DWC2_DIR
$DWC2FK_DIR $DWC2FK_DIR
$DWC_ENV_DIR $DWC_ENV_DIR
$DWC2_DIR
) )
### count amount of dwc service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^dwc(\-[[:digit:]]+)?\.service$" | wc -l)
### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0]
#count+1 for each found data-item from array #count+1 for each found data-item from array
for dd in "${dwc2_data[@]}" for dd in "${dwc_data[@]}"
do do
if [ -e $dd ]; then if [ -e $dd ]; then
dcount=$(expr $dcount + 1) dcount=$(expr $dcount + 1)
fi fi
done done
if [ "$dcount" == "${#dwc2_data[*]}" ]; then
DWC2_STATUS="${green}Installed!${default} " if [ "$dcount" == "${#dwc_data[*]}" ]; then
DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
elif [ "$dcount" == 0 ]; then elif [ "$dcount" == 0 ]; then
DWC2_STATUS="${red}Not installed!${default} " DWC2_STATUS="${red}Not installed!${default} "
else else
@@ -64,20 +96,25 @@ moonraker_status(){
SERVICE SERVICE
$MOONRAKER_DIR $MOONRAKER_DIR
$MOONRAKER_ENV_DIR $MOONRAKER_ENV_DIR
$NGINX_CONFD/upstreams.conf
$NGINX_CONFD/common_vars.conf
) )
#remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] && unset moonraker_data[0] ### count amount of moonraker service files in /etc/systemd/system
#count+1 for each found data-item from array SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^moonraker(\-[[:digit:]]+)?\.service$" | wc -l)
### remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset moonraker_data[0]
### count+1 for each found data-item from array
for mrd in "${moonraker_data[@]}" for mrd in "${moonraker_data[@]}"
do do
if [ -e $mrd ]; then if [ -e $mrd ]; then
mrcount=$(expr $mrcount + 1) mrcount=$(expr $mrcount + 1)
fi fi
done done
### display status
if [ "$mrcount" == "${#moonraker_data[*]}" ]; then if [ "$mrcount" == "${#moonraker_data[*]}" ]; then
MOONRAKER_STATUS="${green}Installed!${default} " MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
elif [ "$mrcount" == 0 ]; then elif [ "$mrcount" == 0 ]; then
MOONRAKER_STATUS="${red}Not installed!${default} " MOONRAKER_STATUS="${red}Not installed!${default} "
else else
@@ -134,11 +171,15 @@ fluidd_status(){
octoprint_status(){ octoprint_status(){
ocount=0 ocount=0
octoprint_data=( octoprint_data=(
SERVICE
$OCTOPRINT_DIR $OCTOPRINT_DIR
$OCTOPRINT_CFG_DIR
$OCTOPRINT_SERVICE1
$OCTOPRINT_SERVICE2
) )
### count amount of octoprint service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^octoprint(\-[[:digit:]]+)?\.service$" | wc -l)
### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0]
#count+1 for each found data-item from array #count+1 for each found data-item from array
for op in "${octoprint_data[@]}" for op in "${octoprint_data[@]}"
do do
@@ -146,8 +187,10 @@ octoprint_status(){
ocount=$(expr $ocount + 1) ocount=$(expr $ocount + 1)
fi fi
done done
### display status
if [ "$ocount" == "${#octoprint_data[*]}" ]; then if [ "$ocount" == "${#octoprint_data[*]}" ]; then
OCTOPRINT_STATUS="${green}Installed!${default} " OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
elif [ "$ocount" == 0 ]; then elif [ "$ocount" == 0 ]; then
OCTOPRINT_STATUS="${red}Not installed!${default} " OCTOPRINT_STATUS="${red}Not installed!${default} "
else else
@@ -162,8 +205,13 @@ klipperscreen_status(){
$KLIPPERSCREEN_DIR $KLIPPERSCREEN_DIR
$KLIPPERSCREEN_ENV_DIR $KLIPPERSCREEN_ENV_DIR
) )
#remove the "SERVICE" entry from the klipperscreen_data array if a klipperscreen service is installed
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "KlipperScreen.service")" ] && unset klipperscreen_data[0] ### count amount of klipperscreen_data service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l)
### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset klipperscreen_data[0]
#count+1 for each found data-item from array #count+1 for each found data-item from array
for klscd in "${klipperscreen_data[@]}" for klscd in "${klipperscreen_data[@]}"
do do
@@ -297,9 +345,9 @@ compare_dwc2fk_versions(){
read_local_dwc2_version(){ read_local_dwc2_version(){
unset DWC2_VER_FOUND unset DWC2_VER_FOUND
if [ -e $DWC2_DIR/version ]; then if [ -e $DWC2_DIR/.version ]; then
DWC2_VER_FOUND="true" DWC2_VER_FOUND="true"
DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/version) DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/.version)
else else
DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER
fi fi
@@ -310,7 +358,7 @@ read_remote_dwc2_version(){
if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then
DWC2_REMOTE_VER=$NONE DWC2_REMOTE_VER=$NONE
else else
get_dwc2_ver get_dwc_ver
DWC2_REMOTE_VER=$DWC2_VERSION DWC2_REMOTE_VER=$DWC2_VERSION
fi fi
} }
@@ -320,16 +368,16 @@ compare_dwc2_versions(){
read_local_dwc2_version && read_remote_dwc2_version read_local_dwc2_version && read_remote_dwc2_version
if [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER == $DWC2_REMOTE_VER ]]; then if [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER == $DWC2_REMOTE_VER ]]; then
#printf fits the string for displaying it in the ui to a total char length of 12 #printf fits the string for displaying it in the ui to a total char length of 12
DWC2_LOCAL_VER="${green}$(printf "v%-11s" "$DWC2_LOCAL_VER")${default}" DWC2_LOCAL_VER="${green}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}"
DWC2_REMOTE_VER="${green}$(printf "v%-11s" "$DWC2_REMOTE_VER")${default}" DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}"
elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then
DWC2_LOCAL_VER="${yellow}$(printf "v%-11s" "$DWC2_LOCAL_VER")${default}" DWC2_LOCAL_VER="${yellow}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}"
DWC2_REMOTE_VER="${green}$(printf "v%-11s" "$DWC2_REMOTE_VER")${default}" DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}"
# set flag for the multi update function # set flag for the multi update function
DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2) DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2)
else else
DWC2_LOCAL_VER=$NONE DWC2_LOCAL_VER=$NONE
DWC2_REMOTE_VER="${green}$(printf "v%-11s" "$DWC2_REMOTE_VER")${default}" DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}"
DWC2_UPDATE_AVAIL="false" DWC2_UPDATE_AVAIL="false"
fi fi
} }
@@ -366,10 +414,9 @@ compare_moonraker_versions(){
read_local_mainsail_version(){ read_local_mainsail_version(){
unset MAINSAIL_VER_FOUND unset MAINSAIL_VER_FOUND
MAINSAIL_APP_FILE=$(find $MAINSAIL_DIR/js -name "app.*.js" 2>/dev/null) if [ -e $MAINSAIL_DIR/.version ]; then
if [ ! -z $MAINSAIL_APP_FILE ]; then
MAINSAIL_LOCAL_VER=$(grep -o -E 'state:{packageVersion:.+' $MAINSAIL_APP_FILE | cut -d'"' -f2)
MAINSAIL_VER_FOUND="true" MAINSAIL_VER_FOUND="true"
MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/.version)
else else
MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER
fi fi
@@ -390,26 +437,25 @@ compare_mainsail_versions(){
read_local_mainsail_version && read_remote_mainsail_version read_local_mainsail_version && read_remote_mainsail_version
if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then
#printf fits the string for displaying it in the ui to a total char length of 12 #printf fits the string for displaying it in the ui to a total char length of 12
MAINSAIL_LOCAL_VER="${green}$(printf "v%-11s" "$MAINSAIL_LOCAL_VER")${default}" MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}"
MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then
MAINSAIL_LOCAL_VER="${yellow}$(printf "v%-11s" "$MAINSAIL_LOCAL_VER")${default}" MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}"
MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
# set flag for the multi update function # set flag for the multi update function
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
else else
MAINSAIL_LOCAL_VER=$NONE MAINSAIL_LOCAL_VER=$NONE
MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
MAINSAIL_UPDATE_AVAIL="false" MAINSAIL_UPDATE_AVAIL="false"
fi fi
} }
read_local_fluidd_version(){ read_local_fluidd_version(){
unset FLUIDD_VER_FOUND unset FLUIDD_VER_FOUND
FLUIDD_APP_FILE=$(find $FLUIDD_DIR/js -name "app.*.js" 2>/dev/null) if [ -e $FLUIDD_DIR/.version ]; then
if [ ! -z $FLUIDD_APP_FILE ]; then
FLUIDD_LOCAL_VER=$(grep -o -E '"version/setVersion",".+"' $FLUIDD_APP_FILE | cut -d'"' -f4)
FLUIDD_VER_FOUND="true" FLUIDD_VER_FOUND="true"
FLUIDD_LOCAL_VER=$(head -n 1 $FLUIDD_DIR/.version)
else else
FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER
fi fi
@@ -430,16 +476,16 @@ compare_fluidd_versions(){
read_local_fluidd_version && read_remote_fluidd_version read_local_fluidd_version && read_remote_fluidd_version
if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then
#printf fits the string for displaying it in the ui to a total char length of 12 #printf fits the string for displaying it in the ui to a total char length of 12
FLUIDD_LOCAL_VER="${green}$(printf "v%-11s" "$FLUIDD_LOCAL_VER")${default}" FLUIDD_LOCAL_VER="${green}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}"
FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}" FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}"
elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then
FLUIDD_LOCAL_VER="${yellow}$(printf "v%-11s" "$FLUIDD_LOCAL_VER")${default}" FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}"
FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}" FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}"
# set flag for the multi update function # set flag for the multi update function
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
else else
FLUIDD_LOCAL_VER=$NONE FLUIDD_LOCAL_VER=$NONE
FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}" FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}"
FLUIDD_UPDATE_AVAIL="false" FLUIDD_UPDATE_AVAIL="false"
fi fi
} }
@@ -479,6 +525,7 @@ NONE="${red}$(printf "%-12s" "--------")${default}"
ui_print_versions(){ ui_print_versions(){
unset update_arr unset update_arr
check_system_updates
compare_klipper_versions compare_klipper_versions
compare_dwc2fk_versions compare_dwc2fk_versions
compare_dwc2_versions compare_dwc2_versions

View File

@@ -2,26 +2,28 @@ advanced_ui(){
top_border top_border
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | "
hr hr
if [ ! "$OPRINT_SERVICE_STATUS" == "" ]; then
echo -e "| 0) $OPRINT_SERVICE_STATUS| " echo -e "| 0) $OPRINT_SERVICE_STATUS| "
hr hr
echo -e "| | | " echo -e "| | | "
echo -e "| Klipper: | System: | " fi
echo -e "| 1) [Switch Version] | 6) [Change hostname] | " echo -e "| Klipper: | Mainsail: | "
echo -e "| 1) [Switch Branch] | 7) [Theme installer] | "
echo -e "| 2) [Rollback] | | " echo -e "| 2) [Rollback] | | "
echo -e "| | Extensions: | " echo -e "| | System: | "
echo -e "| Firmware: | 7) [Shell Command] | " echo -e "| Firmware: | 8) [Change hostname] | "
echo -e "| 3) [Build only] | | " echo -e "| 3) [Build only] | | "
echo -e "| 4) [Build + Flash MCU] | | " echo -e "| 4) [Build + Flash] | Extensions: | "
echo -e "| 5) [Get Printer-USB] | | " echo -e "| 5) [Build + SD Flash] | 9) [Shell Command] | "
echo -e "| | | " echo -e "| 6) [Get MCU ID] | | "
echo -e "| | CustomPiOS: | "
echo -e "| | 10) [Migration Helper] | "
quit_footer quit_footer
} }
advanced_menu(){ advanced_menu(){
print_header
print_msg && clear_msg
read_octoprint_service_status read_octoprint_service_status
advanced_ui do_action "" "advanced_ui"
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
@@ -33,61 +35,47 @@ advanced_menu(){
print_msg && clear_msg print_msg && clear_msg
advanced_ui;; advanced_ui;;
1) 1)
clear do_action "switch_menu";;
print_header
switch_menu
print_msg && clear_msg
advanced_ui;;
2) 2)
clear do_action "load_klipper_state" "advanced_ui";;
print_header
load_klipper_state
print_msg && clear_msg
advanced_ui;;
3) 3)
clear do_action "build_fw" "advanced_ui";;
print_header
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
build_fw
print_msg && clear_msg
advanced_ui;;
4) 4)
clear clear && print_header
print_header
unset FLASH_FIRMWARE && FLASH_FIRMWARE="true"
flash_routine flash_routine
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true" if [ $FLASH_FIRMWARE = "true" ]; then
build_fw status_msg "Please wait..." && sleep 5 && build_fw
unset CONFIRM_FLASHING && CONFIRM_FLASHING="true" select_mcu_id
flash_mcu fi
print_msg && clear_msg print_msg && clear_msg
advanced_ui;; advanced_ui;;
5) 5)
clear clear && print_header
print_header flash_routine_sd
get_printer_usb if [ $FLASH_FW_SD = "true" ]; then
status_msg "Please wait..." && sleep 5 && build_fw
select_mcu_id
fi
print_msg && clear_msg print_msg && clear_msg
advanced_ui;; advanced_ui;;
6) 6)
do_action "get_mcu_id" "advanced_ui";;
7)
do_action "ms_theme_menu";;
8)
clear clear
print_header print_header
create_custom_hostname && set_hostname create_custom_hostname && set_hostname
print_msg && clear_msg print_msg && clear_msg
advanced_ui;; advanced_ui;;
7) 9)
clear do_action "setup_gcode_shell_command" "advanced_ui";;
print_header 10)
setup_gcode_shell_command do_action "migration_menu";;
print_msg && clear_msg
advanced_ui;;
Q|q) Q|q)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
clear deny_action "advanced_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
advanced_ui;;
esac esac
done done
advanced_menu advanced_menu
@@ -117,8 +105,7 @@ switch_ui(){
switch_menu(){ switch_menu(){
if [ -d $KLIPPER_DIR ]; then if [ -d $KLIPPER_DIR ]; then
read_branch read_branch
print_msg && clear_msg do_action "" "switch_ui"
switch_ui
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
@@ -153,11 +140,7 @@ switch_menu(){
Q|q) Q|q)
clear; advanced_menu; break;; clear; advanced_menu; break;;
*) *)
clear deny_action "switch_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
switch_ui;;
esac esac
done done
else else
@@ -186,3 +169,40 @@ rollback_ui(){
echo -e "| $PREV_UI | " echo -e "| $PREV_UI | "
quit_footer quit_footer
} }
#############################################################
#############################################################
migration_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~ [ CustomPiOS Migration ] ~~~~~~~~~~") | "
hr
echo -e "| This function will help you to migrate a vanilla | "
echo -e "| MainsailOS or FluiddPi image to a newer state. | "
blank_line
echo -e "| Only use this function if you use MainsailOS 0.4.0 | "
echo -e "| or lower, or FluiddPi v1.13.0 or lower. | "
blank_line
echo -e "| Please have a look at the KIAUH changelog for more | "
echo -e "| details on what this function will do. | "
hr
echo -e "| | "
echo -e "| 1) [Migrate MainsailOS] | "
echo -e "| 2) [Migrate FluiddPi] | "
echo -e "| | "
quit_footer
}
migration_menu(){
print_msg && clear_msg
migration_ui
while true; do
read -p "${cyan}Perform action:${default} " action; echo
case "$action" in
1) migrate_custompios "mainsail"; migration_menu;;
2) migrate_custompios "fluiddpi"; migration_menu;;
Q|q) clear; advanced_menu; break;;
*) print_unkown_cmd; migration_menu;;
esac
done
}

View File

@@ -4,81 +4,46 @@ backup_ui(){
hr hr
echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | "
hr hr
echo -e "| Firmware: | " echo -e "| Configuration folder: | Klipper Webinterface: | "
echo -e "| 1) [Klipper] | " echo -e "| 0) [Klipper configs] | 4) [Mainsail] | "
echo -e "| | " echo -e "| | 5) [Fluidd] | "
echo -e "| Klipper API: | " echo -e "| Firmware: | | "
echo -e "| 2) [Moonraker] | " echo -e "| 1) [Klipper] | HDMI Screen: | "
echo -e "| | " echo -e "| | 6) [KlipperScreen] | "
echo -e "| Webinterface: | " echo -e "| Klipper API: | | "
echo -e "| 3) [Mainsail] | " echo -e "| 2) [Moonraker] | Other: | "
echo -e "| 4) [Fluidd] | " echo -e "| 3) [Moonraker DB] | 7) [Duet Web Control] | "
echo -e "| 5) [DWC2 Web UI] | " echo -e "| | 8) [OctoPrint] | "
echo -e "| 6) [OctoPrint] | "
echo -e "| | "
echo -e "| HDMI Screen: | "
echo -e "| 7) [KlipperScreen] | "
echo -e "| | "
quit_footer quit_footer
} }
backup_menu(){ backup_menu(){
print_header do_action "" "backup_ui"
print_msg && clear_msg
backup_ui
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
0)
do_action "backup_klipper_config_dir" "backup_ui";;
1) 1)
clear do_action "backup_klipper" "backup_ui";;
print_header
backup_klipper
print_msg && clear_msg
backup_ui;;
2) 2)
clear do_action "backup_moonraker" "backup_ui";;
print_header
backup_moonraker
print_msg && clear_msg
backup_ui;;
3) 3)
clear do_action "backup_moonraker_database" "backup_ui";;
print_header
backup_mainsail
print_msg && clear_msg
backup_ui;;
4) 4)
clear do_action "backup_mainsail" "backup_ui";;
print_header
backup_fluidd
print_msg && clear_msg
backup_ui;;
5) 5)
clear do_action "backup_fluidd" "backup_ui";;
print_header
backup_dwc2
print_msg && clear_msg
backup_ui;;
6) 6)
clear do_action "backup_klipperscreen" "backup_ui";;
print_header
backup_octoprint
print_msg && clear_msg
backup_ui;;
7) 7)
clear do_action "backup_dwc2" "backup_ui";;
print_header 8)
backup_klipperscreen do_action "backup_octoprint" "backup_ui";;
print_msg && clear_msg
backup_ui;;
Q|q) Q|q)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
clear deny_action "backup_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
backup_ui;;
esac esac
done done
backup_menu backup_menu

View File

@@ -31,10 +31,33 @@ print_header(){
kiauh_update_msg(){ kiauh_update_msg(){
top_border top_border
echo -e "| ${yellow}There is a newer version of this script available!${default} | " echo -e "|${green} New KIAUH update available! ${default}| "
echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | " hr
echo -e "|${green} View Changelog: https://git.io/JnmlX ${default}| "
blank_line blank_line
echo -e "| ${yellow}Check out the KIAUH changelog for important changes${default} | " echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${default}| "
echo -e "| ${yellow}either to the script or the installable components!${default} | " echo -e "|${yellow} usually contain bugfixes, important changes or new ${default}| "
echo -e "|${yellow} features. Please consider updating! ${default}| "
bottom_border bottom_border
} }
################################################################################
#******************************************************************************#
################################################################################
### TODO: rework other menus to make use of the following functions too and make them more readable
do_action(){
clear && print_header
### $1 is the action the user wants to fire
$1
print_msg && clear_msg
### $2 is the menu the user usually gets directed back to after an action is completed
$2
}
deny_action(){
clear && print_header
print_unkown_cmd
print_msg && clear_msg
$1
}

View File

@@ -6,73 +6,44 @@ install_ui(){
echo -e "| all necessary dependencies for the various | " echo -e "| all necessary dependencies for the various | "
echo -e "| functions on a completely fresh system. | " echo -e "| functions on a completely fresh system. | "
hr hr
echo -e "| Firmware: | Webinterface: | " echo -e "| Firmware: | Touchscreen GUI: | "
echo -e "| 1) [Klipper] | 3) [DWC2] | " echo -e "| 1) [Klipper] | 5) [KlipperScreen] | "
echo -e "| | 4) [Mainsail] | " echo -e "| | | "
echo -e "| Klipper API: | 5) [Fluidd] | " echo -e "| Klipper API: | Other: | "
echo -e "| 2) [Moonraker] | 6) [Octoprint] | " echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Klipper Webinterface: | | "
echo -e "| 3) [Mainsail] | Webcam: | "
echo -e "| 4) [Fluidd] | 8) [MJPG-Streamer] | "
echo -e "| | | " echo -e "| | | "
echo -e "| | HDMI Screen | "
echo -e "| | 7) [KlipperScreen] | "
quit_footer quit_footer
} }
install_menu(){ install_menu(){
print_header do_action "" "install_ui"
install_ui
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
1) 1)
clear do_action "klipper_setup_dialog" "install_ui";;
print_header
install_klipper
print_msg && clear_msg
install_ui;;
2) 2)
clear do_action "moonraker_setup_dialog" "install_ui";;
print_header
install_moonraker
print_msg && clear_msg
install_ui;;
3) 3)
clear do_action "install_webui mainsail" "install_ui";;
print_header
install_dwc2
print_msg && clear_msg
install_ui;;
4) 4)
clear do_action "install_webui fluidd" "install_ui";;
print_header
install_mainsail
print_msg && clear_msg
install_ui;;
5) 5)
clear do_action "install_klipperscreen" "install_ui";;
print_header
install_fluidd
print_msg && clear_msg
install_ui;;
6) 6)
clear do_action "dwc_setup_dialog" "install_ui";;
print_header
install_octoprint
print_msg && clear_msg
install_ui;;
7) 7)
clear do_action "octoprint_setup_dialog" "install_ui";;
print_header 8)
install_klipperscreen do_action "install_mjpg-streamer" "install_ui";;
print_msg && clear_msg
install_ui;;
Q|q) Q|q)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
clear deny_action "install_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
install_ui;;
esac esac
done done
install_menu install_menu

View File

@@ -1,4 +1,5 @@
main_ui(){ main_ui(){
#[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder
top_border top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr hr
@@ -7,12 +8,12 @@ main_ui(){
echo -e "| 1) [Install] | |" echo -e "| 1) [Install] | |"
echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|"
echo -e "| 3) [Remove] | |" echo -e "| 3) [Remove] | |"
echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|"
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|"
echo -e "| 6) [Settings] | |"
echo -e "| | DWC2: $DWC2_STATUS|" echo -e "| | DWC2: $DWC2_STATUS|"
echo -e "| 4) [Advanced] | Fluidd: $FLUIDD_STATUS|" echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|"
echo -e "| 5) [Backup] | Mainsail: $MAINSAIL_STATUS|"
echo -e "| | Octoprint: $OCTOPRINT_STATUS|"
echo -e "| | |"
echo -e "| ${cyan}$KIAUH_VER${default}| KlipperScreen: $KLIPPERSCREEN_STATUS|"
quit_footer quit_footer
} }
@@ -22,11 +23,26 @@ print_kiauh_version(){
KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")" KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")"
} }
kiauh_update_dialog(){
kiauh_update_msg
read -p "${cyan}Do you want to update now? (Y/n):${default} " yn
while true; do
case "$yn" in
Y|y|Yes|yes|"")
do_action "update_kiauh"
break;;
N|n|No|no) break;;
*)
deny_action "kiauh_update_dialog";;
esac
done
}
main_menu(){ main_menu(){
print_header print_header
#print KIAUH update msg if update available #print KIAUH update msg if update available
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
kiauh_update_msg kiauh_update_dialog
fi fi
#check install status #check install status
print_kiauh_version print_kiauh_version
@@ -43,47 +59,51 @@ main_menu(){
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
"start klipper")
do_action "klipper_service start" "main_ui";;
"stop klipper")
do_action "klipper_service stop" "main_ui";;
"restart klipper")
do_action "klipper_service restart" "main_ui";;
"start moonraker")
do_action "moonraker_service start" "main_ui";;
"stop moonraker")
do_action "moonraker_service stop" "main_ui";;
"restart moonraker")
do_action "moonraker_service restart" "main_ui";;
"start dwc")
do_action "dwc_service start" "main_ui";;
"stop dwc")
do_action "dwc_service stop" "main_ui";;
"restart dwc")
do_action "dwc_service restart" "main_ui";;
"start octoprint")
do_action "octoprint_service start" "main_ui";;
"stop octoprint")
do_action "octoprint_service stop" "main_ui";;
"restart octoprint")
do_action "octoprint_service restart" "main_ui";;
update) update)
clear do_action "update_kiauh" "main_ui";;
print_header
update_kiauh
print_msg && clear_msg
main_ui;;
0) 0)
clear do_action "upload_selection" "main_ui";;
print_header
upload_selection
print_msg && clear_msg
main_ui;;
1) 1)
clear clear && install_menu && break;;
install_menu
break;;
2) 2)
clear clear && update_menu && break;;
update_menu
break;;
3) 3)
clear clear && remove_menu && break;;
remove_menu
break;;
4) 4)
clear clear && advanced_menu && break;;
advanced_menu
break;;
5) 5)
clear clear && backup_menu && break;;
backup_menu 6)
break;; clear && settings_menu && break;;
Q|q) Q|q)
echo -e "${green}###### Happy printing! ######${default}"; echo echo -e "${green}###### Happy printing! ######${default}"; echo
exit -1;; exit -1;;
*) *)
clear deny_action "main_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
main_ui;;
esac esac
done done
clear; main_menu clear; main_menu

31
scripts/ui/ms_theme_menu.sh Executable file
View File

@@ -0,0 +1,31 @@
ms_theme_ui(){
top_border
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | "
hr
echo -e "| Please note: | "
echo -e "| Installing a theme from this menu will overwrite an | "
echo -e "| already installed theme or modified custom.css file! | "
hr
echo -e "| Theme: | "
echo -e "| 1) [Dracula] | "
echo -e "| 2) [Cyberpunk] | "
echo -e "| | "
echo -e "| R) [Remove Theme] | "
echo -e "| | "
quit_footer
}
ms_theme_menu(){
do_action "" "ms_theme_ui"
while true; do
read -p "${cyan}Perform action:${default} " action; echo
case "$action" in
1) do_action "ms_theme_dracula" "ms_theme_ui";;
2) do_action "ms_theme_cyberpunk" "ms_theme_ui";;
R|r) do_action "ms_theme_delete" "ms_theme_ui";;
Q|q) clear; advanced_menu; break;;
*) deny_action "ms_theme_ui";;
esac
done
ms_theme_menu
}

View File

@@ -2,88 +2,51 @@ remove_ui(){
top_border top_border
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | "
hr hr
echo -e "| Files and directories which remain untouched: | " echo -e "| Directories which remain untouched: | "
echo -e "| --> ~/printer.cfg | " echo -e "| --> Your printer configuration directory | "
echo -e "| --> ~/klipper_config | "
echo -e "| --> ~/kiauh-backups | " echo -e "| --> ~/kiauh-backups | "
echo -e "| You need remove them manually if you wish so. | " echo -e "| You need remove them manually if you wish so. | "
hr hr
echo -e "| Firmware: | Webinterface: | " echo -e "| Firmware: | Touchscreen GUI: | "
echo -e "| 1) [Klipper] | 3) [DWC2] | " echo -e "| 1) [Klipper] | 5) [KlipperScreen] | "
echo -e "| | 4) [Mainsail] | "
echo -e "| Klipper API: | 5) [Fluidd] | "
echo -e "| 2) [Moonraker] | 6) [Octoprint] | "
echo -e "| | | " echo -e "| | | "
echo -e "| | Webserver: | " echo -e "| Klipper API: | Other: | "
echo -e "| | 7) [Nginx] | " echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Klipper Webinterface: | 8) [NGINX] | "
echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] | "
echo -e "| 4) [Fluidd] | | "
echo -e "| | | " echo -e "| | | "
echo -e "| | HDMI Screen: | "
echo -e "| | 8) [KlipperScreen] | "
quit_footer quit_footer
} }
remove_menu(){ remove_menu(){
print_header do_action "" "remove_ui"
remove_ui
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
1) 1)
clear do_action "remove_klipper" "remove_ui";;
print_header
remove_klipper
print_msg && clear_msg
remove_ui;;
2) 2)
clear do_action "remove_moonraker" "remove_ui";;
print_header
remove_moonraker
print_msg && clear_msg
remove_ui;;
3) 3)
clear do_action "remove_mainsail" "remove_ui";;
print_header
remove_dwc2
print_msg && clear_msg
remove_ui;;
4) 4)
clear do_action "remove_fluidd" "remove_ui";;
print_header
remove_mainsail
print_msg && clear_msg
remove_ui;;
5) 5)
clear do_action "remove_klipperscreen" "remove_ui";;
print_header
remove_fluidd
print_msg && clear_msg
remove_ui;;
6) 6)
clear do_action "remove_dwc2" "remove_ui";;
print_header
remove_octoprint
print_msg && clear_msg
remove_ui;;
7) 7)
clear do_action "remove_octoprint" "remove_ui";;
print_header
remove_nginx
print_msg && clear_msg
remove_ui;;
8) 8)
clear do_action "remove_nginx" "remove_ui";;
print_header 9)
remove_klipperscreen do_action "remove_mjpg-streamer" "remove_ui";;
print_msg && clear_msg
remove_ui;;
Q|q) Q|q)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
clear deny_action "remove_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
remove_ui;;
esac esac
done done
remove_menu remove_menu

44
scripts/ui/settings_menu.sh Executable file
View File

@@ -0,0 +1,44 @@
settings_ui(){
source_kiauh_ini
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | "
hr
echo -e "| ${red}Caution:${default} | "
echo -e "| When you change the config folder, be aware that ALL | "
echo -e "| Klipper and Moonraker services will be STOPPED, | "
echo -e "| reconfigured and then restarted again. | "
blank_line
echo -e "| ${red}DO NOT change the folder during printing!${default} | "
hr
blank_line
echo -e "| ${cyan}● Current Klipper config folder:${default} | "
printf "|%-55s|\n" " $klipper_cfg_loc"
blank_line
hr
if [ -z $klipper_cfg_loc ]; then
echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${default} | "
else
echo -e "| 1) Change config folder | "
fi
quit_footer
}
settings_menu(){
do_action "" "settings_ui"
while true; do
read -p "${cyan}Perform action:${default} " action; echo
case "$action" in
1)
if [ ! -z $klipper_cfg_loc ]; then
do_action "change_klipper_cfg_path" "settings_ui"
else
deny_action "settings_ui"
fi;;
Q|q)
clear; main_menu; break;;
*)
deny_action "settings_ui";;
esac
done
settings_ui
}

View File

@@ -1,106 +1,61 @@
update_ui(){ update_ui(){
ui_print_versions
top_border top_border
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | "
hr hr
echo -e "| Check the following website for important software | "
echo -e "| changes to the config file before updating Klipper: | "
echo -e "| | "
echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | "
bottom_border
top_border
echo -e "| 0) $BB4U_STATUS| " echo -e "| 0) $BB4U_STATUS| "
hr hr
echo -e "| a) [Update all] | Local Vers: | Remote Vers: | " echo -e "| a) [Update all] | | | "
echo -e "| | | | " echo -e "| | Local Vers: | Remote Vers: | "
echo -e "| Firmware: | | | " echo -e "| Klipper/Klipper API: |---------------|--------------| "
echo -e "| 1) [Klipper] | $LOCAL_COMMIT | $REMOTE_COMMIT | " echo -e "| 1) [Klipper] | $LOCAL_COMMIT | $REMOTE_COMMIT | "
echo -e "| 2) [Moonraker] | $LOCAL_MOONRAKER_COMMIT | $REMOTE_MOONRAKER_COMMIT | "
echo -e "| | | | " echo -e "| | | | "
echo -e "| Webinterface: |---------------|--------------| " echo -e "| Klipper Webinterface: |---------------|--------------| "
echo -e "| 2) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | " echo -e "| 3) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | "
echo -e "| 3) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | " echo -e "| 4) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | "
echo -e "| |---------------|--------------| "
echo -e "| 4) [Moonraker] | $LOCAL_MOONRAKER_COMMIT | $REMOTE_MOONRAKER_COMMIT | "
echo -e "| 5) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | "
echo -e "| 6) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | "
echo -e "| | | | " echo -e "| | | | "
echo -e "| HDMI Screen: |---------------|--------------| " echo -e "| Touchscreen GUI: |---------------|--------------| "
echo -e "| 7) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | " echo -e "| 5) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | "
echo -e "| | | | "
echo -e "| Other: |---------------|--------------| "
echo -e "| 6) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | "
echo -e "| 7) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | "
echo -e "| |------------------------------| "
echo -e "| 8) [System] | $DISPLAY_SYS_UPDATE | "
quit_footer quit_footer
} }
update_menu(){ update_menu(){
print_header
#compare versions
ui_print_versions
print_msg && clear_msg
read_bb4u_stat read_bb4u_stat
update_ui do_action "" "update_ui"
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}Perform action:${default} " action; echo
case "$action" in case "$action" in
0) 0)
clear do_action "toggle_backups" "update_ui";;
print_header
toggle_backups
print_msg && clear_msg
update_ui;;
1) 1)
clear do_action "update_klipper" "update_ui";;
print_header
update_klipper && ui_print_versions
print_msg && clear_msg
update_ui;;
2) 2)
clear do_action "update_moonraker" "update_ui";;
print_header
update_dwc2fk && ui_print_versions
print_msg && clear_msg
update_ui;;
3) 3)
clear do_action "update_mainsail" "update_ui";;
print_header
update_dwc2 && ui_print_versions
print_msg && clear_msg
update_ui;;
4) 4)
clear do_action "update_fluidd" "update_ui";;
print_header
update_moonraker && ui_print_versions
print_msg && clear_msg
update_ui;;
5) 5)
clear do_action "update_klipperscreen" "update_ui";;
print_header
update_mainsail && ui_print_versions
print_msg && clear_msg
update_ui;;
6) 6)
clear do_action "update_dwc2fk" "update_ui";;
print_header
update_fluidd && ui_print_versions
print_msg && clear_msg
update_ui;;
7) 7)
clear do_action "update_dwc2" "update_ui";;
print_header 8)
update_klipperscreen && ui_print_versions do_action "update_system" "update_ui";;
print_msg && clear_msg
update_ui;;
a) a)
clear do_action "update_all" "update_ui";;
print_header
update_all && ui_print_versions
print_msg && clear_msg
update_ui;;
Q|q) Q|q)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
clear deny_action "update_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
ui_print_versions
update_ui;;
esac esac
done done
update_menu update_menu

View File

@@ -1,7 +1,7 @@
update_kiauh(){ update_kiauh(){
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
status_msg "Updating KIAUH ..." status_msg "Updating KIAUH ..."
cd ${HOME}/kiauh cd ${SRCDIR}/kiauh
### force reset kiauh before updating ### force reset kiauh before updating
git reset --hard git reset --hard
git pull && ok_msg "Update complete! Please restart KIAUH." git pull && ok_msg "Update complete! Please restart KIAUH."
@@ -39,6 +39,9 @@ update_all(){
if [ "$KLIPPERSCREEN_UPDATE_AVAIL" = "true" ]; then if [ "$KLIPPERSCREEN_UPDATE_AVAIL" = "true" ]; then
echo -e "| ${cyan}● KlipperScreen${default} |" echo -e "| ${cyan}● KlipperScreen${default} |"
fi fi
if [ "$SYS_UPDATE_AVAIL" = "true" ]; then
echo -e "| ${cyan}● System${default} |"
fi
bottom_border bottom_border
if [ "${#update_arr[@]}" != "0" ]; then if [ "${#update_arr[@]}" != "0" ]; then
read -p "${cyan}###### Do you want to proceed? (Y/n):${default} " yn read -p "${cyan}###### Do you want to proceed? (Y/n):${default} " yn
@@ -59,8 +62,147 @@ update_all(){
done done
} }
update_log_paths(){
### update services to make use of moonrakers new log_path option
### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a
shopt -s extglob # enable extended globbing
LPATH="${HOME}/klipper_logs"
[ ! -d "$LPATH" ] && mkdir -p "$LPATH"
FILE="$SYSTEMDDIR/$1?(-*([0-9])).service"
for file in $(ls $FILE); do
[ "$1" == "klipper" ] && LOG="klippy"
[ "$1" == "moonraker" ] && LOG="moonraker"
if [ ! "$(grep "\-l" $file)" ]; then
status_msg "Updating $file ..."
sudo sed -i -r "/ExecStart=/ s|$| -l $LPATH/$LOG.log|" $file
ok_msg "$file updated!"
elif [ "$(grep "\-l \/tmp\/$LOG" $file)" ]; then
status_msg "Updating $file ..."
sudo sed -i -r "/ExecStart=/ s|-l \/tmp\/$LOG|-l $LPATH/$LOG|" $file
ok_msg "$file updated!"
fi
done
sudo systemctl daemon-reload
# create symlink for mainsail and fluidd nginx logs
symlink_webui_nginx_log "mainsail"
symlink_webui_nginx_log "fluidd"
# create symlink for webcamd log
if [ -f "/var/log/webcamd.log" ] && [ ! -L "$LPATH/webcamd.log" ]; then
status_msg "Creating symlink for '/var/log/webcamd.log' ..."
ln -s "/var/log/webcamd.log" "$LPATH"
ok_msg "OK!"
fi
shopt -u extglob # disable extended globbing
}
migrate_custompios(){
### migrate vanilla mainsailOS 0.4.0 / fluiddPI v1.13.0
### and older to be in sync with newer releases
WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
MJPG_SERV_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/etc/systemd/system/webcamd.service"
KL_SERV_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/klipper/filesystem/root/etc/systemd/system/klipper.service"
NGINX_CFG1="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mainsail/filesystem/root/etc/nginx/conf.d/upstreams.conf"
NGINX_CFG2="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mainsail/filesystem/root/etc/nginx/sites-available/mainsail"
LOG_ROTATE_KLIPPER="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/klipper/filesystem/root/etc/logrotate.d/klipper"
LOG_ROTATE_MOONRAKER="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/moonraker/filesystem/root/etc/logrotate.d/moonraker"
LOG_ROTATE_WEBCAMD="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/etc/logrotate.d/webcamd"
if [ "$1" == "mainsail" ]; then
OS_VER="MainsailOS"
MACRO_CFG="mainsail.cfg"
fi
if [ "$1" == "fluiddpi" ]; then
OS_VER="FluiddPi"
MACRO_CFG="client_macros.cfg"
fi
if [ ! -f "/boot/$1.txt" ] || [ ! -f "/etc/init.d/klipper" ]; then
# abort function if there is no sign of an old CustomPiOS anymore
ERROR_MSG="No vanilla $OS_VER found. Aborting..." && return 0
fi
status_msg "Starting migration of $OS_VER... Please wait..."
if [ -d "${HOME}/klipper_logs" ]; then
# delete an existing klipper_logs directory
# shouldn't be there in the first place if its a true vanilla CustomPiOS
status_msg "Recreate '~/klipper_logs' directory..."
rm -rf "${HOME}/klipper_logs" && mkdir "${HOME}/klipper_logs"
ok_msg "OK!"
fi
if [ -f "/boot/$1.txt" ]; then
# replace old webcamd.service and webcamd
status_msg "Migrating MJPG-Streamer..."
sudo systemctl stop webcamd
sudo rm -f "/etc/systemd/system/webcamd.service"
sudo rm -f "/root/bin/webcamd"
sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd"
sudo wget $MJPG_SERV_SRC -O "/etc/systemd/system/webcamd.service"
sudo sed -i "s/MainsailOS/$OS_VER/" "/etc/systemd/system/webcamd.service"
sudo chmod +x "/usr/local/bin/webcamd"
# move mainsail.txt/fluiddpi.txt from boot to klipper_config and rename it
sudo mv "/boot/$1.txt" "${HOME}/klipper_config/webcam.txt"
sudo chown pi:pi "${HOME}/klipper_config/webcam.txt"
sudo systemctl daemon-reload
sudo systemctl restart webcamd
ok_msg "OK!"
fi
if [ -f "/etc/init.d/klipper" ] && [ ! -f "/etc/systemd/system/klipper.service" ]; then
# replace klipper SysVinit service with systemd service
status_msg "Migrating Klipper Service..."
sudo systemctl stop klipper
sudo update-rc.d -f klipper remove
sudo rm -f "/etc/init.d/klipper"
sudo rm -f "/etc/default/klipper"
sudo wget $KL_SERV_SRC -O "/etc/systemd/system/klipper.service"
sudo systemctl enable klipper.service
sudo systemctl daemon-reload
sudo systemctl restart klipper
ok_msg "OK!"
fi
if [ -f "/etc/systemd/system/moonraker.service" ]; then
# update new log path in existing moonraker service
status_msg "Updating Moonraker Service..."
sudo systemctl stop moonraker
update_log_paths "moonraker"
sudo systemctl restart moonraker
ok_msg "OK!"
fi
if [ -f "/etc/nginx/conf.d/upstreams.conf" ]; then
[ "$1" == "mainsail" ] && cfg="mainsail"
[ "$1" == "fluiddpi" ] && cfg="fluidd"
# update nginx upstreams.conf and mainsail/fluidd config file
status_msg "Updating NGINX configurations..."
sudo systemctl stop nginx
sudo rm -f "/etc/nginx/conf.d/upstreams.conf"
sudo rm -f "/etc/nginx/sites-available/$cfg"
sudo wget $NGINX_CFG1 -O "/etc/nginx/conf.d/upstreams.conf"
sudo wget $NGINX_CFG2 -O "/etc/nginx/sites-available/$cfg"
sudo sed -i "s/mainsail/$cfg/g" "/etc/nginx/sites-available/$cfg"
sudo systemctl restart nginx
ok_msg "OK!"
fi
if [ -f "${HOME}/klipper_config/$MACRO_CFG" ]; then
# update macro files
status_msg "Updating $MACRO_CFG ..."
MACRO_CFG_PATH="${HOME}/klipper_config/$MACRO_CFG"
sed -i "/SAVE_GCODE_STATE NAME=PAUSE_state/d" $MACRO_CFG_PATH
sed -i "/RESTORE_GCODE_STATE NAME=PAUSE_state/d" $MACRO_CFG_PATH
ok_msg "OK!"
fi
if [ -d "/etc/logrotate.d" ]; then
# download logrotate configs
status_msg "Setting up logrotations..."
sudo wget $LOG_ROTATE_KLIPPER -O "/etc/logrotate.d/klipper"
sudo wget $LOG_ROTATE_MOONRAKER -O "/etc/logrotate.d/moonraker"
sudo wget $LOG_ROTATE_WEBCAMD -O "/etc/logrotate.d/webcamd"
ok_msg "OK!"
fi
ok_msg "Migration done!"
}
update_klipper(){ update_klipper(){
stop_klipper klipper_service "stop"
if [ ! -d $KLIPPER_DIR ]; then if [ ! -d $KLIPPER_DIR ]; then
cd ${HOME} && git clone $KLIPPER_REPO cd ${HOME} && git clone $KLIPPER_REPO
else else
@@ -69,100 +211,97 @@ update_klipper(){
save_klipper_state save_klipper_state
status_msg "Updating $GET_BRANCH" status_msg "Updating $GET_BRANCH"
cd $KLIPPER_DIR cd $KLIPPER_DIR
if [ "$DETACHED_HEAD" == "true" ]; then if [ "$DETACHED_HEAD" == "true" ]; then
git checkout $GET_BRANCH git checkout $GET_BRANCH
unset DETACHED_HEAD unset DETACHED_HEAD
fi fi
git pull && ok_msg "Update successfull!"
#check for possible new dependencies and install them ### get current klippy-requirements.txt md5sum
status_msg "Checking for possible new dependencies ..." KLIPPER_OLDREQ_MD5SUM="$(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1)"
PKGLIST=$(grep "PKGLIST=" ~/klipper/scripts/install-octopi.sh | cut -d'"' -f2- | cut -d'"' -f1 | cut -d"}" -f2) ### pull latest files from github
git pull
### read PKGLIST and install possible new dependencies
install_klipper_packages
### get possible new klippy-requirements.txt md5sum
KLIPPER_NEWREQ_MD5SUM="$(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1)"
### check for possible new dependencies and install them
if [[ $KLIPPER_NEWREQ_MD5SUM != $KLIPPER_OLDREQ_MD5SUM ]]; then
PYTHONDIR="${HOME}/klippy-env" PYTHONDIR="${HOME}/klippy-env"
sudo apt-get update && sudo apt-get install --yes $PKGLIST status_msg "New dependecies detected..."
$PYTHONDIR/bin/pip install -r ~/klipper/scripts/klippy-requirements.txt
ok_msg "Dependencies already met or have been installed!" ### always rebuild the pythondir from scratch if new dependencies were detected
ok_msg "Update complete!" rm -rf ${PYTHONDIR}
virtualenv -p python2 ${PYTHONDIR}
$PYTHONDIR/bin/pip install -r $KLIPPER_DIR/scripts/klippy-requirements.txt
ok_msg "Dependencies have been installed!"
fi fi
start_klipper fi
update_log_paths "klipper"
ok_msg "Update complete!"
klipper_service "restart"
} }
update_dwc2fk(){ update_dwc2fk(){
stop_dwc dwc_service "stop"
bb4u "dwc2" bb4u "dwc2"
if [ ! -d $DWC2FK_DIR ]; then if [ ! -d $DWC2FK_DIR ]; then
cd ${HOME} && git clone $DWC2FK_REPO cd ${HOME} && git clone $DWC2FK_REPO
else else
cd $DWC2FK_DIR && git pull cd $DWC2FK_DIR && git pull
fi fi
start_dwc dwc_service "start"
} }
update_dwc2(){ update_dwc2(){
bb4u "dwc2" bb4u "dwc2"
download_dwc2_webui download_dwc_webui
} }
update_mainsail(){ update_mainsail(){
bb4u "mainsail" bb4u "mainsail"
status_msg "Updating Mainsail ..." status_msg "Updating Mainsail ..."
mainsail_setup mainsail_setup
symlink_webui_nginx_log "mainsail"
} }
update_fluidd(){ update_fluidd(){
bb4u "fluidd" bb4u "fluidd"
status_msg "Updating Fluidd ..." status_msg "Updating Fluidd ..."
fluidd_setup fluidd_setup
symlink_webui_nginx_log "fluidd"
} }
update_moonraker(){ update_moonraker(){
moonraker_service "stop"
bb4u "moonraker" bb4u "moonraker"
status_msg "Updating Moonraker ..." status_msg "Updating Moonraker ..."
while true; do cd $MOONRAKER_DIR
echo
top_border ### get current moonraker-requirements.txt md5sum
echo -e "| You can now choose how you want to update Moonraker. |" MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
blank_line ### pull latest files from github
echo -e "| Changes made to the Moonraker code and/or its depen- |" git pull
echo -e "| dencies might require a rebuild of the python virtual |" ### read PKGLIST and install possible new dependencies
echo -e "| environment or downloading of additional packages. |" install_moonraker_packages
blank_line ### get possible new moonraker-requirements.txt md5sum
echo -e "| ${red}Check the docs in the Moonraker repository to see if${default} |" MOONRAKER_NEWREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
echo -e "| ${red}rebuilding is necessary (user_changes.md)!${default} |"
blank_line ### check for possible new dependencies and install them
echo -e "| 1) Update Moonraker (default) |" if [[ $MOONRAKER_NEWREQ_MD5SUM != $MOONRAKER_OLDREQ_MD5SUM ]]; then
echo -e "| 2) Update Moonraker + rebuild virtualenv/dependencies |" PYTHONDIR="${HOME}/moonraker-env"
quit_footer status_msg "New dependecies detected..."
read -p "${cyan}###### Please choose:${default} " action ### always rebuild the pythondir from scratch if new dependencies were detected
case "$action" in rm -rf ${PYTHONDIR}
1|"") virtualenv -p /usr/bin/python3 ${PYTHONDIR}
echo -e "###### > Update Moonraker" ln -s /usr/lib/python3/dist-packages/gpiod* ${PYTHONDIR}/lib/python*/site-packages
update_mr="true" && rebuild_env="false" ${PYTHONDIR}/bin/pip install -r $MOONRAKER_DIR/scripts/moonraker-requirements.txt
break;; ok_msg "Dependencies have been installed!"
2)
echo -e "###### > Update Moonraker + rebuild virtualenv/dependencies"
update_mr="true" && rebuild_env="true"
break;;
Q|q)
clear; update_menu; break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
stop_moonraker; echo
if [[ $update_mr = "true" ]] && [[ $rebuild_env = "false" ]]; then
unset update_mr && unset rebuild_env
cd $MOONRAKER_DIR && git pull
fi fi
if [[ $update_mr = "true" ]] && [[ $rebuild_env = "true" ]]; then update_log_paths "moonraker"
unset update_mr && unset rebuild_env
cd $MOONRAKER_DIR && git pull && ./scripts/install-moonraker.sh -r
fi
#read printer.cfg location and patch /etc/default/klipper if entries don't match
locate_printer_cfg && patch_klipper_sysfile
ok_msg "Update complete!" ok_msg "Update complete!"
restart_moonraker moonraker_service "restart"
} }
update_klipperscreen(){ update_klipperscreen(){
@@ -170,7 +309,7 @@ update_klipperscreen(){
cd $KLIPPERSCREEN_DIR cd $KLIPPERSCREEN_DIR
KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1) KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1)
git pull origin master -q && ok_msg "Fetch successfull!" git pull origin master -q && ok_msg "Fetch successfull!"
git checkout -f origin/master && ok_msg "Checkout successfull" git checkout -f master && ok_msg "Checkout successfull"
#KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt) #KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt)
if [[ $(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1) != $KLIPPERSCREEN_OLDREQ_MD5SUM ]]; then if [[ $(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1) != $KLIPPERSCREEN_OLDREQ_MD5SUM ]]; then
status_msg "New dependecies detected..." status_msg "New dependecies detected..."
@@ -181,3 +320,10 @@ update_klipperscreen(){
ok_msg "Update complete!" ok_msg "Update complete!"
start_klipperscreen start_klipperscreen
} }
update_system(){
status_msg "Updating System ..."
sudo apt-get update && sudo apt-get upgrade -y
ok_msg "Update complete! Check the log above!"
ok_msg "KIAUH won't do any dist-upgrades!\n"
}

View File

@@ -37,44 +37,59 @@ accept_upload_conditions(){
} }
upload_selection(){ upload_selection(){
source_ini source_kiauh_ini
[ "$logupload_accepted" = "false" ] && accept_upload_conditions [ "$logupload_accepted" = "false" ] && accept_upload_conditions
KLIPPY_LOG=/tmp/klippy.log
MOONRAKER_LOG=/tmp/moonraker.log ### find all suitable logfiles for klipper
DWC2_LOG=/tmp/dwc2.log logfiles=()
klipper_logs="${HOME}/klipper_logs/klippy*.log"
moonraker_logs="${HOME}/klipper_logs/moonraker*.log"
if ls $klipper_logs 2>/dev/null 1>&2; then
for kl_log in $(find $klipper_logs); do
logfiles+=($kl_log)
done
fi
if ls $moonraker_logs 2>/dev/null 1>&2; then
for mr_log in $(find $moonraker_logs); do
logfiles+=($mr_log)
done
fi
if ls /tmp/dwc2*.log 2>/dev/null 1>&2; then
for dwc_log in $(find /tmp/dwc2*.log); do
logfiles+=($dwc_log)
done
fi
### draw interface
i=0
top_border top_border
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |" echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |"
hr hr
echo -e "| You can choose the following files for uploading: |" echo -e "| You can choose the following files for uploading: |"
echo -e "| 1) klippy.log |" for log in ${logfiles[@]}; do
echo -e "| 2) moonraker.log |" printf "| $i) %-50s|\n" "${logfiles[$i]}"
echo -e "| 3) dwc2.log |" i=$((i + 1))
done
quit_footer quit_footer
while true; do while true; do
read -p "${cyan}Please select:${default} " choice read -p "${cyan}Please select:${default} " choice
case "$choice" in if [ $choice = "q" ] || [ $choice = "Q" ]; then
1) clear && main_menu && break
clear && print_header elif [ $choice -le ${#logfiles[@]} ]; then
upload_log "$KLIPPY_LOG" upload_log "${logfiles[$choice]}"
upload_selection upload_selection
;; else
2)
clear && print_header clear && print_header
upload_log "$MOONRAKER_LOG" ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection upload_selection
;; fi
3)
clear && print_header
upload_log "$DWC2_LOG"
upload_selection
;;
q | Q) clear; main_menu; break;;
esac
done done
} }
upload_log(){ upload_log(){
if [ -f "$1" ]; then if [ -f "$1" ]; then
clear && print_header
status_msg "Uploading $1 ..." status_msg "Uploading $1 ..."
LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/')
[ ! -z "$LINK" ] && ok_msg "$1 upload successfull!" [ ! -z "$LINK" ] && ok_msg "$1 upload successfull!"
@@ -83,7 +98,7 @@ upload_log(){
unset LINK unset LINK
else else
clear && print_header clear && print_header
ERROR_MSG="$1 not found!" && print_msg && clear_msg ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection upload_selection
fi fi
} }