Compare commits

...

566 Commits

Author SHA1 Message Date
th33xitus
fcf059df73 feat: KIAUH v4.0.0 (#191) 2022-05-29 20:11:15 +02:00
th33xitus
4bf9e8f0a8 fix(moonraker.conf): typos in cors domains 2022-05-10 20:15:50 +02:00
th33xitus
dd58229fee fix: bug in remove_klipperscreen() 2022-03-06 11:56:31 +01:00
Alex Zellner
6c4635fa4e fix(gcode_shell_command): py3 virtual env compatibility (#175) 2022-02-26 19:28:06 +01:00
th33xitus
4517415e9d fix: CRLF to LF 2022-02-26 19:17:22 +01:00
th33xitus
5c45bc7617 readme: fix link to user profile 2022-02-26 17:46:47 +01:00
th33xitus
d8ce465126 readme: add shields to readme 2022-02-26 17:44:59 +01:00
th33xitus
2f8c95a8c7 readme: update readme 2022-02-26 17:24:02 +01:00
th33xitus
4c083ceade fix: broken set_klipper_cfg_path function (#163) 2022-02-26 16:51:43 +01:00
th33xitus
259a6919f0 fix: link for theme data csv 2022-02-10 09:14:44 +01:00
th33xitus
4f7a49d85a fix: bug not updating all when selecting to do so.
* also make the confirm message more verbose and make it clear that KIAUH won't update any held back packages or any dist upgrades.
2022-02-07 14:47:36 +01:00
th33xitus
005a5061a7 chore: apply changes made in mainsailOS 0.6.1 2022-02-03 16:57:55 +01:00
th33xitus
634d795557 fix: bug not successfully copying new upstreams.conf and common_vars.conf 2022-01-31 12:00:57 +01:00
th33xitus
a14e321df9 fix: apply required changes due to introduction of PolicyKit and PackageKit in Moonraker 2022-01-29 23:06:02 +01:00
th33xitus
1682642e47 fix: revert 7e9d18b
Due to some investigations made in #158, the default IPv6 configuration will be removed again
2022-01-11 08:51:32 +01:00
th33xitus
7e9d18b54c script: add webui ipv6 listen directive (fixes #158) 2022-01-08 22:16:38 +01:00
th33xitus
d049d4c770 script: remove unused functions 2022-01-08 21:48:38 +01:00
th33xitus
108cda3cd6 shellcheck: apply fixes for SC2086 2022-01-08 21:45:55 +01:00
th33xitus
d7de58f538 feat: check for apache2 and prompt for action 2022-01-08 20:57:47 +01:00
th33xitus
572afa0396 fix: typo in bug_report.yml 2021-12-30 19:52:22 +01:00
th33xitus
63a5e1e323 update bug_report.yml 2021-12-30 19:49:14 +01:00
th33xitus
8c68eaa995 doc: update changelog.md 2021-12-30 19:26:28 +01:00
th33xitus
e8c0b3cf39 fix: formatting / add INFO prefix 2021-12-26 12:18:45 +01:00
th33xitus
cfad7a1fb0 fix: add check for membership of group 'tty'
It's possible that being part of group 'tty' is also needed to be able to flash an MCU
2021-12-25 00:52:08 +01:00
th33xitus
4113732daa fix: check if group dialout exists
first check if group dialout exists on the system. then check if the current user is not part of it. only then ask for adding the user to that group
2021-12-24 23:33:05 +01:00
th33xitus
95808a0d5b shellcheck: apply several fixes
apply fix for SC2219, SC2086, SC2236
2021-12-24 23:02:38 +01:00
th33xitus
e551c02507 chore: remove unused code 2021-12-24 22:52:21 +01:00
th33xitus
1f40686ea1 fix: improve moonraker service detection (fixes #156) 2021-12-24 22:50:50 +01:00
th33xitus
9b3d96545b refactor: improve error message 2021-12-24 16:22:46 +01:00
th33xitus
a632fae8f6 fix: check if user is in group "dialout" before starting flash or build+flash routine 2021-12-24 16:17:07 +01:00
th33xitus
4e3a701db4 fix: warn_msg should be status_msg 2021-12-24 14:49:23 +01:00
th33xitus
0c760b5aa2 fix: check membership of "video" usergroup (should fix #135) 2021-12-24 14:36:30 +01:00
th33xitus
3bc2f3b498 doc: document passing parameters to gcode_shell_commands 2021-12-24 01:08:09 +01:00
th33xitus
b92cfc3984 fix: klipper_cfg_loc was an empty string
if the config location wasn't already set before installing mjpg-streamer, klipper_cfg_loc was empty, even after calling the check_klipper_cfg_path function beforehand

moonraker.conf: set refresh_interval to 24hrs
2021-12-24 00:22:15 +01:00
th33xitus
01790b5c11 moonraker.conf: pre-configure clients for pre-release updates
moonraker.conf: set refresh_interval to 24hrs
2021-12-23 17:17:48 +01:00
th33xitus
8c7891e360 fix: libjpeg dependencies for ubuntu
chore: several shellcheck fixes
2021-12-23 16:50:48 +01:00
th33xitus
852f7c056a fix: wrong logic in if condition 2021-12-23 16:45:06 +01:00
th33xitus
8cffd07aef fix: klipper service detection
refactor: move $INSTANCE_COUNT into setup function

refactor: creating $PKGLIST

script: add short description to the dialog for selecting the amount of klipper instances

chore: several shellcheck fixes
2021-12-23 15:03:52 +01:00
th33xitus
40745e90df refactor: move $INSTANCE_COUNT into setup function 2021-12-23 14:19:06 +01:00
th33xitus
a43645cca0 refactor: better klipper service detection 2021-12-23 10:35:18 +01:00
th33xitus
4d834db5df refactor: unlink moonraker install from klipper instances
chore: several shellcheck fixes
2021-12-23 10:35:09 +01:00
th33xitus
771191ab69 chore: update .gitignore 2021-12-22 22:39:17 +01:00
th33xitus
7afe943ecc shellcheck: apply fix for SC2086 2021-12-19 17:14:24 +01:00
th33xitus
b06c17c184 fix: confirm flash condition (fixes #155) 2021-12-19 17:05:41 +01:00
Pedro Lamas
3af46b45ee github: adds GitHub issue templates (#150)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
2021-12-05 14:37:08 +01:00
th33xitus
b58e79634c fix: update URLs 2021-11-29 11:13:47 +01:00
Yoshito Komatsu
1ef9b0f58f fix: use [[:digit:]] instead of \d (#146) 2021-11-29 11:09:24 +01:00
th33xitus
8333ae1dc4 fix: also get pre-release versions
previous endpoint didn't allow kiauh to get pre-release versions of mainsail/fluidd
2021-11-20 15:17:21 +01:00
th33xitus
e0ae312a9e fix: missing declaration for OctoPrint backup (fixes #143) 2021-11-17 18:30:33 +01:00
th33xitus
4ce1ce72d3 chore: update moonraker.conf template 2021-11-14 11:29:14 +01:00
th33xitus
60842a330d chore: update webui links 2021-11-14 11:21:34 +01:00
th33xitus
05a59e9261 fix: correct ls command to find kiauh_macros.cfg 2021-11-11 14:15:00 +01:00
th33xitus
36a8757cfd chore: use ls to look for webcamd installation 2021-11-11 13:26:01 +01:00
th33xitus
fe4625d3e1 chore: refactor how moonraker is detected 2021-11-11 13:21:57 +01:00
th33xitus
19ddf3e023 fix: silence grep 2021-11-11 13:02:36 +01:00
th33xitus
ba888b1f97 chore: use ls within remove_nginx method 2021-11-11 12:51:09 +01:00
th33xitus
0284a36e7f chore: use ls to look for nginx installation 2021-11-11 12:43:13 +01:00
th33xitus
22f705e06c chore: manage moonraker service enable/start with do_action_service method 2021-11-11 12:28:20 +01:00
th33xitus
4c34245da0 chore: refactor how klipper services are count 2021-11-11 12:12:43 +01:00
th33xitus
f7cb3d6c97 script: refactor exit code evaluation in flash_mcu.sh 2021-10-31 13:53:22 +01:00
th33xitus
aaf4f7dd5c script: add logrotate rule for webcam service (#127) 2021-10-31 11:23:48 +01:00
Noah Pan
26bac791aa service: remove webcamd service restart interval. (#132) 2021-10-31 10:52:22 +01:00
th33xitus
aa4bdfc7b2 fix: invalid command bug in rollback UI (fixes #131) 2021-10-29 14:04:39 +02:00
th33xitus
311f3be864 fix: wrong check for moonraker multi-instance
The previous command also counted an available `moonraker-telegram-bot.service` and caused further issues with enabling the mainsail remoteMode accidentially.
2021-10-26 20:55:31 +02:00
th33xitus
511df1a889 fix: use correct themes.csv url 2021-10-25 22:22:32 +02:00
th33xitus
8d3ddc273a fix: allow non-single digit instance counts containing a 0 #129 2021-10-22 23:52:58 +02:00
th33xitus
f231fa9c69 gcode_shell_command: make RUN_SHELL_COMMAND accept optional parameters
Thanks @lixxbox for that code
2021-10-17 20:13:48 +02:00
th33xitus
9b6925e9c4 fix: add missing function call in install_webui 2021-10-02 11:26:43 +02:00
th33xitus
7f8ee7939c script: move nginx functions from install_moonraker.sh to install_klipper_webui.sh
nginx was removed as a dependency from moonraker. moonraker didn't make use of it, only mainsail/fluidd do. so moving all nginx related functions to  is reasonable
2021-10-01 23:58:03 +02:00
th33xitus
4d4c49d4c9 script: only display dialogs if files/service not found 2021-10-01 22:53:32 +02:00
th33xitus
7692227946 fix: function setup_moonraker_nginx_cfg 2021-10-01 21:51:33 +02:00
th33xitus
3da993a67c fix: breaking bug 2021-09-29 18:55:13 +02:00
th33xitus
6b74c59d15 script: add function to match nginx configurations
this should fix a common issue where mainsail/fluidd was installed with a more up2date nginx config which didn't match with a previously configured upstreams.conf.
this should also cover cases where the upstreams.conf is more up2date than the corresponding interface configs.
2021-09-29 14:44:01 +02:00
th33xitus
9cd27f7052 fix: backup nginx configs now works correctly 2021-09-28 18:22:50 +02:00
th33xitus
fc4fe130cd script: read webui ports from nginx config, write them to kiauh.ini 2021-09-28 18:22:50 +02:00
th33xitus
2a46b00cda Updating README.md / changelog.md 2021-09-28 17:25:40 +02:00
th33xitus
560186a40b chore: little UI tweaks, renaming "MTelegramBot" to "Telegram Bot" 2021-09-28 17:24:52 +02:00
th33xitus
75bca847f8 fix: remove telegram bot log also from ~/klipper_logs upon removal 2021-09-28 16:56:17 +02:00
Evgenii Shavrin
bb1f2eadca feat: add moonraker-telegram-bot by nlef (#117)
Adds installation and removing feature for https://github.com/nlef/moonraker-telegram-bot
2021-09-28 16:52:59 +02:00
Richard Mitchell
6d87716b1d gcode_shell_command: Fix issue with partial lines being repeated (#118)
Without clearing the partial line on a full line being sent the self.partial_output was repeated for every subsequent line.
2021-09-27 17:44:11 +02:00
th33xitus
1e8c379623 Create FUNDING.yml 2021-09-24 12:21:30 +02:00
th33xitus
6a8991d51e Update changelog.md 2021-09-24 12:19:41 +02:00
th33xitus
fb4367bb41 script: refactoring of the flash routine
script: uart devices can be detected/selected now

script: first implementation of a little help page
2021-09-24 11:59:50 +02:00
th33xitus
9463b719e4 script: update klipper github repository URL 2021-09-24 08:31:11 +02:00
th33xitus
65bf3d5251 fix: fix of previous commit and small refactor 2021-09-12 20:46:39 +02:00
AKA "Thom Wiley
68327262fc chore: change submenu "quit" to "back"
Changing the "Quit" option to "Back" as it is more intuitive, causes less confusion and is in fact the more fitting description of what is happening.
2021-09-12 20:41:27 +02:00
th33xitus
14ef39b87c fix: typo and missing function call for PrettyGCode 2021-08-25 10:14:05 +02:00
th33xitus
969d3b5dab script: add --allow-releaseinfo-change option to apt-get update 2021-08-25 10:05:31 +02:00
th33xitus
05842f8e1d feat: add PrettyGCode for Klipper 2021-08-10 12:25:05 +02:00
th33xitus
39219c105e script: add additional dependency check - should fix #97
Before starting the firmware building process, check for dependencies again.
2021-07-25 18:42:22 +02:00
th33xitus
7984c28fe5 script: add more default trusted_clients to moonraker.conf template
the previous method of adding the host network range was too unreliable in some cases and didn't cover some popular usecases
2021-07-11 19:13:37 +02:00
th33xitus
b44e855a98 script: simplify python dependency installation during klipper and moonraker update 2021-07-11 14:45:58 +02:00
th33xitus
52ab909ba5 script: update moonraker.conf, apply recent changes to the update manager section 2021-07-10 09:27:13 +02:00
th33xitus
4d7e10e5c3 script: update nginx configurations 2021-07-10 09:22:43 +02:00
th33xitus
d3726733e5 fix: small flash routine rework + user input validation 2021-07-04 20:09:25 +02:00
th33xitus
765f016ea2 fix: menu action for removing mainsail theme was missing 2021-07-01 21:38:14 +02:00
th33xitus
5deb987b8a script: patch log_path to moonraker.conf if missing 2021-06-29 22:58:21 +02:00
th33xitus
47d1321979 script: mainsail theme installer overhaul 2021-06-22 17:12:38 +02:00
th33xitus
b47a9cf7ed feat: add voron toolhead theme to mainsail theme installer 2021-06-22 12:07:27 +02:00
th33xitus
a9f23e9b23 script: remove else statement from do_action_service
Caused spamming of error messages when starting from a complete new Pi image.
2021-06-21 20:43:01 +02:00
th33xitus
814acbe92a script: add virtualenv to the moonraker dependency check #95 2021-06-21 08:44:37 +02:00
th33xitus
991dd79d01 script: add simple check for DietPi distro when creating the klipper dependency array 2021-06-18 18:28:27 +02:00
th33xitus
40875dfe49 script: simplify service action methods 2021-06-18 18:03:47 +02:00
th33xitus
806c6fd275 Update changelog.md 2021-06-15 17:36:08 +02:00
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
Keith Sachs
18e85235c1 Update install_moonraker.sh (#64)
added libjpeg-dev and zlib1g-dev to moonraker dependencies, this makes kiauh work for armbian
2021-01-28 22:48:14 +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
d12554d2b7 fix: apply a force reset --hard before updating KIAUH. Fix for #63 2021-01-23 22:52:41 +01:00
th33xitus
036fb08132 fix: remove upload limit of 200M in NGINX configs for mainsail and fluidd 2021-01-23 22:51:44 +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
8bf20aa059 Merge pull request #60 from jordanruthe/klipperscreen_fix
klipperscreen: update to fix an exit problem
2021-01-20 23:12:34 +01:00
Jordan Ruthe
748a700c36 klipperscreen: update to fix an exit problem 2021-01-20 17:07:30 -05: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
43a724b80e fix: add disable command 2021-01-07 16:22:20 +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
th33xitus
8ee277fe2c fix: set the correct port 8080 for mjpgstreamer 2021-01-03 16:18:37 +01:00
th33xitus
a44ae4c2b9 fix: followup to 240746e. kiauh now also tries to identify the branch from the commit SHA if the HEAD was detached at a single commit, if the other method does not give a usefull output. 2020-12-22 21:58:20 +01:00
th33xitus
240746e1b6 fix: a fix for the detached HEAD issue when updating klipper that was introduced in a past commit. the user now gets a warn message that he needs to force update klipper. behind the scenes he will be brought back onto the branch and head gets reattached. 2020-12-22 20:39:12 +01:00
th33xitus
1fd839bc7a fix: add "v" to versions, add kiauh version to bottom left corner in main menu 2020-12-21 21:00:27 +01:00
th33xitus
a6bfb30235 fix: add missing fluidd backup function 2020-12-21 19:08:26 +01:00
th33xitus
7854fe3d95 fix: fix #50 2020-12-20 19:25:13 +01:00
th33xitus
1eda775571 fix: previous klipper updates resulted in a detached head state. fixed update routine and other stuff relaying on the read_branch function/GET_BRANCH variable 2020-12-20 18:41:42 +01:00
th33xitus
06eb86efd7 fix: grep pattern changed to read fluidd version again 2020-12-20 16:23:03 +01:00
th33xitus
0339f3f4f5 fix: update script
there is a new way of grabbing the mainsail and fluidd version without reading them from a version file kiauh created in the past.
2020-12-04 19:38:40 +01:00
domi
3032356f89 fix: bug that caused the script to hang because the file that was searched for was not found 2020-12-04 16:43:51 +01:00
th33xitus
f1289504bf fix: few moonraker update changes
- change in the description
- option 1 only does a git pull again when rebuilding venv/deps is not necessary
2020-12-02 21:39:16 +01:00
th33xitus
d3b7c923bd fix: followup to 1b7b8a1 2020-12-01 18:53:30 +01:00
th33xitus
194b8a54cc Merge pull request #47 from th33xitus/rework-display-version
Rework how versions are displayed and fetched
2020-11-29 14:57:15 +01:00
domi
1b7b8a1cf9 fix: new way of getting mainsail and fluidd version 2020-11-29 14:57:24 +01:00
domi
e6dde2cf23 fix: different way of displaying versions 2020-11-28 23:15:29 +01:00
domi
94926d5985 Update README.md 2020-11-28 18:04:14 +01:00
domi
acf8a817d8 Update changelog.md 2020-11-28 17:46:37 +01:00
domi
10558103a5 fix: fix some UI stuff 2020-11-28 17:42:36 +01:00
th33xitus
c61e101627 fix: fix typo 2020-11-28 16:46:43 +01:00
th33xitus
ddcaee0838 Merge pull request #44 from jordanruthe/master
Add KlipperScreen to kiauh
2020-11-28 16:45:47 +01:00
Jordan Ruthe
622e8251a3 Fixing typos 2020-11-28 10:37:04 -05:00
Jordan
b2556641ac Fix symlinks 2020-11-27 13:50:19 +00:00
Jordan
93f8e5e265 Add KlipperScreen to kiauh 2020-11-27 13:44:06 +00:00
domi
dde5812c6b fix: add check for dbus dependency (fix #43) 2020-11-26 15:23:16 +01:00
domi
42a5a0b6d8 fix: fix typo, should fix #42 2020-11-26 11:00:05 +01:00
domi
d95b8ac763 fix: reset to default foreground color 2020-11-21 21:17:24 +01:00
domi
865177d0fd fix: highlight note in moonraker update menu 2020-11-21 16:45:00 +01:00
domi
8923620414 fix: issue with displaying longer version numbers 2020-11-21 16:39:19 +01:00
th33xitus
ecc349e550 Merge pull request #40 from th33xitus/work-moonraker
fix: rework moonraker update function
2020-11-20 14:06:02 +01:00
domi
bc35a82cc8 fix: rework moonraker update function 2020-11-20 13:14:01 +01:00
domi
4fe964e886 fix: a bit better python3 check for moonraker 2020-11-20 11:18:29 +01:00
th33xitus
8371a014a0 fix: restart nginx with systemctl 2020-11-19 13:47:26 +01:00
th33xitus
90af76402b fix: add messages to ongoing process 2020-11-19 13:43:33 +01:00
th33xitus
25b911e867 fix: followup to d3a12f7d 2020-11-19 12:40:47 +01:00
th33xitus
4e9776cac3 Merge pull request #38 from th33xitus/work-fluidd
Fix KIAUH for update to Fluidd
2020-11-18 18:05:01 +01:00
th33xitus
2e3975374a Update Docs 2020-11-18 18:03:41 +01:00
th33xitus
ed9b8d844b fix: must restart moonraker after changes to moonraker.conf 2020-11-18 17:48:19 +01:00
th33xitus
d3a12f7db7 fix: add a patch due to recent changes to fluidd 2020-11-18 17:37:54 +01:00
th33xitus
3b74bb0b77 fix: add python check to moonraker installer 2020-11-13 21:20:48 +01:00
th33xitus
4f7ac68af6 fix: better moonraker service status check 2020-11-13 21:17:17 +01:00
th33xitus
e22c6be490 fix: cleanup 2020-11-13 20:49:10 +01:00
th33xitus
3fd9f95da3 fix: littel rework for dwc2 installer etc. 2020-11-13 20:48:57 +01:00
th33xitus
065786fea7 fix: forgot to disable nginx test during fluidd install 2020-11-07 10:00:20 +01:00
th33xitus
e370c54739 fix: add dependency check into klipper & moonraker update function 2020-11-06 17:56:30 +01:00
th33xitus
88fd83638c fix: disable error-prone api checks 2020-11-06 17:53:39 +01:00
th33xitus
3d065c0f1b add: example script for autocommits 2020-10-30 16:49:27 +01:00
th33xitus
d98151cfef fix: little typo (but it breaks stuff) 2020-10-30 12:50:51 +01:00
th33xitus
41d2dd80a7 Merge pull request #34 from th33xitus/work-webui
Work webui
2020-10-30 00:13:26 +01:00
th33xitus
7ff1d972b4 Update README.md, changelog.md, features.md 2020-10-30 00:11:20 +01:00
th33xitus
efe482ea58 fix: upload new image 2020-10-30 00:10:40 +01:00
th33xitus
8ba6aee952 fix: add fluidd to ui message 2020-10-29 23:32:24 +01:00
th33xitus
9ecf7068f1 fix: rework of writing to configs 2020-10-29 22:28:24 +01:00
th33xitus
74a6b04762 Merge branch 'work-webui' of https://github.com/th33xitus/kiauh into work-webui 2020-10-29 18:32:01 +01:00
th33xitus
55382b1ecb fix: followup to 9fc7f41 2020-10-29 18:31:07 +01:00
th33xitus
b48319e24d fix: rework klipper webui installers 2020-10-29 18:31:07 +01:00
th33xitus
8b03b27902 Merge remote-tracking branch 'origin/master' into work-webui 2020-10-29 18:30:14 +01:00
th33xitus
be2734e640 fix: little rework and fixes of shell command extension installation 2020-10-29 18:27:22 +01:00
th33xitus
7431124d87 fix: formatting 2020-10-29 17:32:48 +01:00
th33xitus
4ae696857f fix: followup to 9fc7f41 2020-10-28 23:16:24 +01:00
th33xitus
9fc7f4120a Merge branch 'moonraker-rework' into work-webui 2020-10-28 21:29:53 +01:00
th33xitus
dc32470a7c Merge pull request #33 from th33xitus/klipper-systemd
Support installation for klipper as systemd service
2020-10-28 21:24:22 +01:00
th33xitus
d91d01ae2c fix: rework klipper webui installers 2020-10-28 20:39:34 +01:00
th33xitus
62b0f2afd6 fix: convert test echo into status_msg 2020-10-28 13:03:21 +01:00
th33xitus
6ce475e27a fix: revert default selection for log creation question 2020-10-28 12:10:38 +01:00
th33xitus
e6d5a73a79 fix: followup to 5fd19ae to support klipper systemd service 2020-10-28 12:09:15 +01:00
th33xitus
5fd19aef0b add: support to install klipper as systemd service 2020-10-28 12:08:02 +01:00
th33xitus
911d0d37e5 fix: invert default selections during klipper install 2020-10-26 17:59:52 +01:00
th33xitus
cbffa1b31a fix: formatting 2020-10-21 21:40:21 +02:00
th33xitus
32c176bf2f fix: add missing function call and simplify function to set hostname 2020-10-21 21:15:30 +02:00
th33xitus
b4fc691da1 fix: possible fix for #24 2020-10-20 10:32:55 +02:00
th33xitus
6129f15386 Merge pull request #28 from th33xitus/work-ini
fix: #24 - .gitignore for kiauh.ini
2020-10-13 11:59:35 +02:00
th33xitus
759cc8e196 fix: whitespaces 2020-10-13 11:58:05 +02:00
th33xitus
dec1c0e83c fix: addition to b20cda1 2020-10-13 11:55:01 +02:00
th33xitus
b20cda1d15 fix: new function to fix #26 2020-10-13 11:41:57 +02:00
th33xitus
2c522e717f add: .gitignore for kiauh.ini 2020-10-13 11:02:42 +02:00
th33xitus
c06aa0457f bugfix: fix typo 2020-10-10 16:55:47 +02:00
th33xitus
253f4e1bf9 Merge pull request #25 from th33xitus/work-logupload
Add: log upload function
2020-10-10 16:42:19 +02:00
th33xitus
29e3d8b3d2 add: log update function 2020-10-10 16:41:00 +02:00
th33xitus
e0b7a75116 fix: update_all ui 2020-10-10 09:46:45 +02:00
th33xitus
083ca8b7fd fix: fetching correct download url + more status messages 2020-10-10 09:37:06 +02:00
th33xitus
4e2c6aa2cc fix: fluidd update function not existing 2020-10-10 09:35:40 +02:00
th33xitus
a4a85b1045 func: drop support for switching to moonraker klipper branch (it's obsolete) 2020-10-10 01:22:08 +02:00
th33xitus
ccf5b003fe fix: more verbose ok_msg 2020-10-09 19:00:59 +02:00
th33xitus
0027886f4f Update changelog.md 2020-10-06 22:48:07 +02:00
th33xitus
26599d734d Update README.md 2020-10-06 22:37:08 +02:00
th33xitus
d58841a269 Merge pull request #22 from th33xitus/work-fluidd
Installer for Fluidd and several other fixes
2020-10-06 22:31:41 +02:00
th33xitus
ab6fa29bd2 Update README.md 2020-10-06 22:29:03 +02:00
th33xitus
6142c0c18f bugfix: typos 2020-10-06 21:58:25 +02:00
th33xitus
fb14d9c717 bugfix: fix typos 2020-10-06 21:14:56 +02:00
th33xitus
bc658f38bc fix: UI 2020-10-06 21:04:35 +02:00
th33xitus
976d9cb5a9 fix: add gzip to fluidd nginx config 2020-10-06 20:34:45 +02:00
th33xitus
029127bf00 fix: nginx port stuff on all interface installers 2020-10-06 20:19:37 +02:00
th33xitus
9b424c8343 bugfix: add missing removal actions 2020-10-06 18:33:02 +02:00
th33xitus
3658137a1c bugfix: fix introduced bug in fe941f4 2020-10-06 18:18:40 +02:00
th33xitus
4e38e85962 bugfix: add greater delay to test_api to let cpu usage settle on slower devices 2020-10-06 17:55:24 +02:00
th33xitus
fe941f4227 feature: initial commit to add installer for Fluidd + rewrite nginx related stuff 2020-10-06 15:03:54 +02:00
th33xitus
9a4ca4114c fix: more verbose kiauh update message 2020-10-05 14:30:52 +02:00
th33xitus
1c41abe40f bugfix: fix the wrong displaying of color codes in windows-consoles 2020-10-05 14:14:26 +02:00
th33xitus
3257c845ee remove branding removal function for mainsail 2020-09-21 23:48:25 +02:00
th33xitus
3d6b4bec95 Update mainsail_macros.cfg
Bring mainsail_macros.cfg in line with the macro examples from the mainsail instructions: https://github.com/meteyou/mainsail/blob/master/docs/macros.md
2020-09-20 11:02:11 +02:00
th33xitus
c55a010bcd Update README.md 2020-09-18 09:00:32 +02:00
th33xitus
78dcc0a1ad fix: concatenate with && again 2020-09-18 08:58:46 +02:00
th33xitus
2a2bc6b377 Update README.md 2020-09-17 23:29:06 +02:00
th33xitus
1159d74748 Update README.md
update image url
2020-09-17 21:37:03 +02:00
th33xitus
40f34f26ea Merge pull request #18 from th33xitus/work17092020
add: update all function
2020-09-17 21:36:00 +02:00
th33xitus
668331e7ea add: update all function 2020-09-17 21:23:26 +02:00
th33xitus
d2bdf6b089 start/restart/stop services with systemctl 2020-09-17 19:31:33 +02:00
th33xitus
10f75268ab Update README.md 2020-09-17 19:05:04 +02:00
th33xitus
46e6b7d40a Update changelog.md 2020-09-17 19:02:43 +02:00
th33xitus
bd876c744d remove: update check for branch dev-2.0
abandon the dev-2.0 branch
2020-09-17 18:49:58 +02:00
th33xitus
db0a4b4e03 fix: adresses #17 2020-09-16 22:19:14 +02:00
th33xitus
efa67b5843 Update README.md
add link to a gitbook with more detailed instructions for installing klipper and mainsail
2020-09-16 10:16:35 +02:00
th33xitus
d393b0a9e9 Merge pull request #16 from tumbleweedlabs/master, fixes #15
Update mainsail_macros.cfg, fixes #15
2020-09-16 09:52:21 +02:00
tumbleweedlabs
85f0c26215 Update mainsail_macros.cfg
Per meteyou, the last G91 in the resume macro is erroneous and can be eliminated.

https://discordapp.com/channels/431557959978450984/704747457795588100/755540226843345038
2020-09-15 20:39:13 -07:00
tumbleweedlabs
35dcf10c9a Update mainsail_macros.cfg
Pull request to fix issue 15: https://github.com/th33xitus/kiauh/issues/15
2020-09-15 17:30:25 -07:00
th33xitus
64b6d6b26a fix: stop/start dwc service when updating 2020-09-14 22:54:01 +02:00
th33xitus
a2201ab3f7 Merge pull request #13 from th33xitus/work-13092020
Work 13092020
2020-09-13 12:25:14 +02:00
th33xitus
63a2f95cc0 Update README.md 2020-09-13 12:24:02 +02:00
th33xitus
043f09aeeb Delete core_functions.md 2020-09-13 12:23:04 +02:00
th33xitus
1fa1636f75 Update features.md 2020-09-13 12:21:54 +02:00
th33xitus
3770f0fd7a Update README.md 2020-09-13 12:12:33 +02:00
th33xitus
ecd9e7f489 Update README.md 2020-09-13 12:11:52 +02:00
th33xitus
125eea921f add: some docs 2020-09-13 11:57:03 +02:00
th33xitus
2e9be1adc5 fix: typos 2020-09-13 11:47:01 +02:00
th33xitus
3e35be5681 add: user choice for dwc service (init.d or systemd) 2020-09-13 11:25:46 +02:00
th33xitus
d9d3006be4 fix: correct ExecStart parameter 2020-09-13 11:25:13 +02:00
th33xitus
6abab9fb06 fix: remove a sudo command from removal process 2020-09-12 12:31:14 +02:00
th33xitus
ef4b6b092f Update README.md 2020-09-12 09:45:22 +02:00
th33xitus
b2a8c52995 Merge branch 'dev-2.0' 2020-09-12 09:32:24 +02:00
th33xitus
9bfce238d7 add: support for new dwc-for-klipper-socket by @Stephan3
This will replace the previous installer for dwc2-for-klipper without substitution. dwc2-for-klipper won't be maintained anymore.
2020-09-12 09:31:40 +02:00
th33xitus
d0ac497a60 add: dwc2-for-klipper-socket installer scripts 2020-09-12 08:48:33 +02:00
th33xitus
4c44b8714a Update moonraker.conf
Update the default moonraker.conf to be mostly in sync with https://github.com/Arksine/moonraker/blob/master/docs/installation.md#moonraker-configuration-moonrakerconf
2020-09-11 16:17:03 +02:00
th33xitus
da1820a7da Merge branch 'dev-2.0' 2020-09-11 14:34:28 +02:00
th33xitus
b576491320 fix: rework dialogues to display invalid input 2020-09-11 14:12:49 +02:00
th33xitus
0c9e967ebe fix: invert default selection
invert the pre-selected option from yes to no.
2020-09-11 12:55:34 +02:00
th33xitus
4d53a92c83 Merge branch 'master' into dev-2.0 2020-09-11 12:35:42 +02:00
th33xitus
0b474514b1 fix: bug introduced with c98584d 2020-09-11 12:34:47 +02:00
th33xitus
9b7bde7da0 fix: bug introduced in previous commit 2020-09-11 12:20:31 +02:00
th33xitus
fc61f17297 Merge branch 'dev-2.0' of https://github.com/th33xitus/kiauh into dev-2.0 2020-09-11 12:04:41 +02:00
th33xitus
3a4fbdbd61 fix: tweak moonraker/mainsail install process 2020-09-11 12:04:35 +02:00
th33xitus
1ec269969b fix: tweak moonraker/mainsail install process 2020-09-11 11:31:53 +02:00
th33xitus
fa669a8690 fix: do not automatically remove moonraker.conf 2020-09-11 11:31:04 +02:00
th33xitus
599b85c47d fix: issue #12 2020-09-11 10:26:15 +02:00
th33xitus
83e9618a75 fix: cleaner nginx removal process 2020-09-11 10:25:38 +02:00
th33xitus
c98584dde8 bugfix: kiauh status check prevents kiauh from starting if no kiauh .git directory present 2020-09-06 11:16:34 +02:00
th33xitus
53f4b9a9f5 Merge pull request #11 from leifbladt/patch-1
Simplify installation instructions
2020-09-04 11:31:15 +02:00
Leif Bladt
a23fb6b79e Simplify installation instructions
As you're already in the kiauh directory, the `chmod` command can be simplified.
2020-09-04 09:26:29 +02:00
th33xitus
262e489d1a fix: moonraker update function - check for patched klipper sysfile 2020-09-03 09:55:37 +02:00
th33xitus
9e13c2d0ea fix: wrong include path in default mainsail printer.cfg 2020-09-02 23:20:25 +02:00
th33xitus
34162c4b65 fix: bug in moonraker system check for printer.cfg 2020-09-02 23:18:47 +02:00
th33xitus
7384ed8a0e fix: tweak mainsail setup 2020-09-02 23:16:01 +02:00
th33xitus
8899275022 function: re-enable the branding removal function 2020-09-02 22:22:10 +02:00
th33xitus
03c3c3d50f fix: Mainsail update function not working 2020-09-01 18:01:08 +02:00
th33xitus
45c8b5a33f Merge branch 'dev-2.0' 2020-09-01 14:28:40 +02:00
th33xitus
4a60b9c8ec remove: function to remove voron brandings from mainsail, mainsail has its own logo now (thx @lixxbox). function therefore obsolete 2020-09-01 14:27:53 +02:00
th33xitus
d964523558 fix: make some output silent 2020-09-01 14:22:28 +02:00
th33xitus
49a28cff22 fix: better suited status message 2020-09-01 14:19:36 +02:00
th33xitus
8a5e358a73 fix: remove use of symlinks, also update for mainsail v0.2.0 2020-09-01 13:52:36 +02:00
th33xitus
9ec63be673 fix: rework locate_printer_cfg function 2020-09-01 13:51:51 +02:00
th33xitus
bae0c1f0fd fix: typo and bug, also bring code in place for later moonraker version 2020-08-30 13:59:19 +02:00
th33xitus
fc777ccb96 fix: remove two menu entries 2020-08-30 13:37:49 +02:00
th33xitus
96be30343d fix: rework klipper installation routine 2020-08-30 13:35:14 +02:00
th33xitus
24a59cffb7 Merge branch 'dev-2.0' 2020-08-26 10:47:43 +02:00
th33xitus
dba14aadb6 new function: install shell command extension by Arksine 2020-08-26 08:18:59 +02:00
th33xitus
d51062c5ae fix: use new method to locate printer.cfg, rework depending functions 2020-08-26 08:18:18 +02:00
th33xitus
1b4baad654 fix: status message 2020-08-24 11:48:57 +02:00
th33xitus
5a25bd3686 fix: remove old read branch function 2020-08-23 21:52:18 +02:00
th33xitus
f08d6ecdc2 fix: clean up and restructure menus and ui 2020-08-23 20:48:07 +02:00
th33xitus
be56439587 fix: typo in mainsail installer 2020-08-23 16:31:55 +02:00
th33xitus
dd16a2503b fix: extend description 2020-08-22 23:32:35 +02:00
th33xitus
613e0d779f fix: rollback function 2020-08-22 23:21:26 +02:00
th33xitus
612a4225be fix: recreate deleted variable 2020-08-22 22:20:13 +02:00
th33xitus
35ecf3ae65 fix: kiauh update function (finally?) 2020-08-22 21:58:55 +02:00
th33xitus
e32cc9d3cb fix: remove deprecated main menu entry 2020-08-22 20:29:22 +02:00
th33xitus
9a3e41716e fix: delete a debug msg 2020-08-22 20:05:56 +02:00
th33xitus
09e4c7bea5 fix: bring octoprint installation routine into line with dwc2 and mainsail/moonraker routines 2020-08-22 19:30:35 +02:00
th33xitus
5392e2a9ab add: status message for starting installation 2020-08-22 19:18:27 +02:00
th33xitus
41789fd158 fix: restructuring reverse proxy and hostname functions 2020-08-22 19:18:08 +02:00
th33xitus
2532fc7e4c fix: restructure functions.sh 2020-08-22 19:14:11 +02:00
th33xitus
63f65a02b4 fix: a more verbose dependency check message 2020-08-22 18:23:41 +02:00
th33xitus
f3a139f317 fix: remove_ui 2020-08-22 18:19:33 +02:00
th33xitus
68cb5427b6 fix: rewrite dwc2 installation 2020-08-22 17:49:35 +02:00
th33xitus
2be2ce12c6 add: variable triggered function to disable octoprint service 2020-08-22 17:48:52 +02:00
th33xitus
eb6b2465c7 fix: mainsail/moonraker related 2020-08-22 17:47:47 +02:00
th33xitus
cc1c804730 fix: klipper update function 2020-08-22 09:10:09 +02:00
th33xitus
7dda59649b fix: ui not printing branch 2020-08-22 09:09:28 +02:00
th33xitus
60dc9d623e fix: rollback function 2020-08-22 09:09:00 +02:00
th33xitus
92b4bc41ac fix: move test_api to moonraker install routine 2020-08-20 18:58:57 +02:00
th33xitus
db5b906e5b add: separate install/remove function for mainsail and moonraker 2020-08-20 18:30:56 +02:00
th33xitus
d78670e0ab fix: formatting 2020-08-20 17:38:24 +02:00
th33xitus
716b21a629 feature: new experimental moonraker/mainsail install routine 2020-08-20 16:32:01 +02:00
th33xitus
1a037c687b add: new log location to mainsail remove data_arr 2020-08-20 16:31:28 +02:00
th33xitus
0dc5edfd7b add: mainsail_macros.cfg 2020-08-20 16:30:40 +02:00
th33xitus
c82e21419c fix: change color variables 2020-08-20 16:29:15 +02:00
th33xitus
7b220c6546 fix: wrong path for include config 2020-08-16 12:57:53 +02:00
th33xitus
15c6296e2c fix: all scripts chmod +x 2020-08-16 10:49:53 +02:00
th33xitus
e00d2951a9 fix: bug in klipper version check 2020-08-16 10:19:58 +02:00
th33xitus
68f7c98985 Merge pull request #9 from th33xitus/master
fix: kiauh update function
2020-08-15 20:13:25 +02:00
th33xitus
82408fee2e fix: kiauh update function 2020-08-15 19:27:29 +02:00
th33xitus
3076d400a0 fix: kiauh update check 2020-08-15 19:03:44 +02:00
th33xitus
c91718cfc3 update: mainsail installation routine 2020-08-15 17:11:11 +02:00
th33xitus
9c20ad7d99 fix: read branch error 2020-08-15 17:08:55 +02:00
th33xitus
7614d596ab fix: kiauh update function 2020-08-15 10:01:32 +02:00
th33xitus
5bcd9a73b5 fix: missing quotes in remove_brandings 2020-08-12 19:46:54 +02:00
th33xitus
a06b06eb46 show error message if warning is ignored or no printer connection was found. extend the function to search by path as well if search by id is not successfull 2020-08-12 18:02:31 +02:00
th33xitus
66e9069687 feature: remove voron branding from mainsail ui 2020-08-12 17:34:53 +02:00
th33xitus
a782fecd25 fix missing entry in mainsail nginx cfg 2020-08-12 16:23:26 +02:00
th33xitus
5dda935f58 Merge branch 'master' into dev-2.0 2020-08-09 10:20:21 +02:00
th33xitus
8cfe4a81ef Update README.md 2020-08-09 09:47:07 +02:00
th33xitus
2e4da7f220 fix read branch error 2020-08-05 00:09:18 +02:00
th33xitus
be6a63f95b new kiauh update check 2020-08-05 00:03:54 +02:00
th33xitus
9fcbcfcba8 new way of reading current active klipper branch 2020-08-04 23:27:51 +02:00
th33xitus
3ec26ba319 update mainsail config 2020-08-03 09:40:54 +02:00
th33xitus
188239d7ea fix kiauh update check 2020-07-31 17:05:11 +02:00
th33xitus
b850aa4d96 Fix Bug 2020-07-31 10:30:14 +02:00
th33xitus
2e5e06c1ff remove tornado with DWC2 2020-07-31 10:18:03 +02:00
th33xitus
96c094d36b UI Fix 2020-07-31 10:17:53 +02:00
th33xitus
3be01528d9 Merge branch 'master' of https://github.com/th33xitus/kiauh 2020-07-29 21:29:56 +02:00
th33xitus
6b77070baa one screenshot only 2020-07-29 21:27:12 +02:00
th33xitus
4e2743d587 make backup function usable 2020-07-29 21:25:31 +02:00
th33xitus
1d9cbecbb5 add moonraker update function + ui stuff
add moonraker update function + ui stuff
2020-07-29 21:13:51 +02:00
th33xitus
bd90677cfa add moonraker update function + ui stuff 2020-07-29 21:12:07 +02:00
th33xitus
e75df6d46c kiauh status now checks master branch 2020-07-29 15:58:27 +02:00
th33xitus
b6c07fc357 Merge branch 'dev-2.0' 2020-07-29 15:48:47 +02:00
th33xitus
fce1eb5a8c update script to use mainsail beta - dropping mainsail alpha 2020-07-27 11:26:22 +02:00
th33xitus
82d76b18f0 new rollback feature 2020-07-27 10:29:28 +02:00
th33xitus
dc4cc59038 before updating, save the current klipper commit state in ini 2020-07-26 18:15:36 +02:00
th33xitus
6f30208863 rename INI_DIR to INI_FILE 2020-07-26 18:11:22 +02:00
th33xitus
303c96cbb1 remove hint msg -> useless 2020-07-26 18:10:45 +02:00
th33xitus
da57fe7ccc fix bug 2020-07-26 15:16:29 +02:00
th33xitus
e5e135c68b add confirmation messages 2020-07-26 12:36:05 +02:00
th33xitus
22888f5756 simple startup update check for KIAUH 2020-07-25 20:57:32 +02:00
th33xitus
d84a740f0d Merge branch 'dev-2.0' of https://github.com/th33xitus/kiauh into dev-2.0 2020-07-25 13:16:41 +02:00
th33xitus
64a7dec09d Fix UI stuff 2020-07-25 13:16:37 +02:00
th33xitus
a76cab0fe6 restructure install/update for dwc2 2020-07-25 13:16:04 +02:00
th33xitus
e0b9a1ef3b Update README.md 2020-07-24 23:09:06 +02:00
th33xitus
6c4e6b057e Update README.md 2020-07-24 23:08:12 +02:00
th33xitus
37b23129c0 Update README.md 2020-07-24 23:05:24 +02:00
th33xitus
5651ce2d63 add screenshots 2020-07-24 22:07:52 +02:00
th33xitus
0a0a9f2f93 preconfigure octoprint for use with klipper 2020-07-24 21:44:58 +02:00
th33xitus
876b316af4 change nginx configs listen to ipv4 only 2020-07-24 21:44:30 +02:00
th33xitus
f51ba88f64 advanced menu: change hostname function 2020-07-24 18:00:57 +02:00
th33xitus
02c6a46a78 Fix bugs 2020-07-24 13:21:34 +02:00
th33xitus
84fc849caf UI stuff 2020-07-24 13:12:04 +02:00
th33xitus
87ed15a117 Finish backup functions 2020-07-24 13:11:53 +02:00
th33xitus
2bbf006475 some reverse proxy tweaks 2020-07-23 19:39:12 +02:00
th33xitus
2596e8d08a Fixes 2020-07-23 16:13:33 +02:00
th33xitus
80344ec41c Fixes 2020-07-23 11:04:23 +02:00
th33xitus
a2042ec378 Better tornado install check 2020-07-23 10:50:10 +02:00
th33xitus
734aed1f7b Better dependency check 2020-07-23 10:20:14 +02:00
th33xitus
108b5c7b0c Fixes 2020-07-22 17:50:46 +02:00
th33xitus
3091ce55ad Fix bug 2020-07-22 13:27:41 +02:00
th33xitus
e6b6dbfa74 Merge branch 'dev-2.0' of https://github.com/th33xitus/kiauh into dev-2.0 2020-07-22 10:16:57 +02:00
th33xitus
e22105a728 add dwc2 reverse proxy option 2020-07-22 10:16:52 +02:00
th33xitus
092f2793b3 Update README.md 2020-07-20 11:59:02 +02:00
th33xitus
3ab4244709 Update README.md 2020-07-20 11:50:24 +02:00
th33xitus
7b48061281 Update README.md 2020-07-20 11:02:11 +02:00
th33xitus
2b6dbaab76 remove webcam stuff: i can't test it sufficient enough, users need to install it manually for now 2020-07-20 10:45:04 +02:00
th33xitus
4cb2ba51bd fix remote version checks 2020-07-20 10:09:42 +02:00
th33xitus
8ffdf12a4a add octoprint reverse proxy 2020-07-19 22:38:21 +02:00
th33xitus
28d7a4aeda feature: remove option for tornado and nginx 2020-07-18 20:30:49 +02:00
th33xitus
fed882298e do not remove tornado when removing dwc2fk, will get seperate function 2020-07-18 18:49:55 +02:00
th33xitus
e4cfad4162 new function: allow hostname to be set 2020-07-18 18:33:55 +02:00
th33xitus
b4496603ed Update README.md 2020-07-18 15:17:50 +02:00
th33xitus
1cc94d4874 Fix bugs 2020-07-16 17:01:57 +02:00
th33xitus
d19c4d33cb Fix OctoPrint toggle function 2020-07-16 16:33:44 +02:00
th33xitus
fd71b0ee62 Fixes/Tweaks 2020-07-16 15:54:57 +02:00
th33xitus
49d0a65bcd Merge branch 'dev-2.0' of https://github.com/th33xitus/kiauh into dev-2.0 2020-07-16 15:14:27 +02:00
th33xitus
ba53517f09 fix breaking stuff 2020-07-16 15:14:23 +02:00
th33xitus
1be6cd0a3d remove nginx-purge option 2020-07-16 15:09:28 +02:00
th33xitus
8c0e231ade some "debloating" 2020-07-16 15:07:00 +02:00
th33xitus
1551920fe3 Update README.md 2020-07-15 23:33:20 +02:00
th33xitus
a5155c50cc Fixes/Tweaks 2020-07-15 22:52:23 +02:00
th33xitus
57d86b9ef4 Add checks for octoprint service when installing DWC2/Mainsail 2020-07-15 22:02:42 +02:00
th33xitus
182164af9c Small fixes/tweaks 2020-07-15 21:50:40 +02:00
th33xitus
45fe688f87 Add Octoprint Service toggle function and a new confirm message 2020-07-15 21:41:20 +02:00
th33xitus
fe27d054f8 Add Octoprint installer/remover 2020-07-15 18:57:46 +02:00
th33xitus
21aa2f45e5 Rename mainsail service to moonraker service 2020-07-15 11:50:57 +02:00
th33xitus
eea1f5540e Better error message 2020-07-15 11:25:16 +02:00
th33xitus
2771184e48 Add abort method if not on moonraker fork 2020-07-15 11:17:36 +02:00
th33xitus
2b6abac0c9 Fix missing function call
Fixed a missing function call for creating config entries.
Installing mainsail should work now pretty straight forward.
2020-07-13 21:09:40 +02:00
th33xitus
85a9186c78 Add restart functions 2020-07-13 21:08:31 +02:00
th33xitus
7106994bf6 Deactivate backup menu
Still WIP, has no function at all at them moment.
2020-07-13 18:14:10 +02:00
th33xitus
c57acefc16 Delete status.sh
derp...
2020-07-13 18:10:10 +02:00
th33xitus
e2bb6cd849 Fix visual issue
Fix an UI issue when DWC2 or Mainsail are not installed
2020-07-13 18:09:30 +02:00
th33xitus
f1d9b9c21b Fix visual issue
Fix an UI issue when DWC2 or Mainsail are not installed
2020-07-13 18:07:43 +02:00
th33xitus
6cf253eb8c Fix typo 2020-07-13 17:53:08 +02:00
th33xitus
3f7b454710 Update README.md
add screenshot
2020-07-13 17:42:38 +02:00
th33xitus
50eb2621d7 Update README.md
Update instructions for switching to the dev-2.0 branch.
2020-07-13 17:21:10 +02:00
th33xitus
bf70157a64 Update README.md 2020-07-13 17:15:09 +02:00
61 changed files with 7581 additions and 1809 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: th33xitus
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

50
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
name: Bug report
description: Create a report to help us improve
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
This issue form is for reporting bugs only!
If you have a feature request, please use [feature_request](/new?template=feature_request.yml)
- type: textarea
id: distro
attributes:
label: Linux Distribution
description: >-
The linux distribution the issue occured on
validations:
required: true
- type: textarea
id: what-happened
attributes:
label: What happened
description: >-
A clear and concise description of what the bug is.
validations:
required: true
- type: textarea
id: expected-behavior
attributes:
label: What did you expect to happen
description: >-
A clear and concise description of what you expected to happen.
validations:
required: true
- type: textarea
id: repro-steps
attributes:
label: How to reproduce
description: >-
Minimal and precise steps to reproduce this bug.
validations:
required: true
- type: textarea
id: additional-info
attributes:
label: Additional information
description: |
If you have any additional information for us, use the field below.
Please note, you can attach screenshots or screen recordings here, by
dragging and dropping files in the field below.

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Klipper Discord
url: https://discord.klipper3d.org/
about: Quickest way to get in contact

View File

@@ -0,0 +1,40 @@
name: Feature request
description: Suggest an idea for this project
labels: ["feature request"]
body:
- type: markdown
attributes:
value: |
This issue form is for feature requests only!
If you've found a bug, please use [bug_report](/new?template=bug_report.yml)
- type: textarea
id: problem-description
attributes:
label: Is your feature request related to a problem? Please describe
description: >-
A clear and concise description of what the problem is.
validations:
required: true
- type: textarea
id: solution-description
attributes:
label: Describe the solution you'd like
description: >-
A clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
id: possible-alternatives
attributes:
label: Describe alternatives you've considered
description: >-
A clear and concise description of any alternative solutions or features you've considered.
- type: textarea
id: additional-info
attributes:
label: Additional information
description: |
If you have any additional information for us, use the field below.
Please note, you can attach screenshots or screen recordings here, by
dragging and dropping files in the field below.

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
klipper_repos.txt

15
.shellcheckrc Normal file
View File

@@ -0,0 +1,15 @@
source=scripts
enable=avoid-nullary-conditions
enable=deprecate-which
enable=quote-safe-variables
enable=require-variable-braces
enable=require-double-brackets
# SC2162: `read` without `-r` will mangle backslashes.
# https://github.com/koalaman/shellcheck/wiki/SC2162
disable=SC2162
# SC2164: Use `cd ... || exit` in case `cd` fails
# https://github.com/koalaman/shellcheck/wiki/SC2164
disable=SC2164

View File

@@ -1,12 +1,93 @@
# KIAUH
<p align="center">
<a>
<img src="https://raw.githubusercontent.com/th33xitus/kiauh/master/resources/screenshots/kiauh.png" alt="KIAUH logo" height="181">
<h1 align="center">Klipper Installation And Update Helper</h1>
</a>
</p>
## Klipper Installation And Update Helper
<p align="center">
A handy installation script that makes installing Klipper (and more) a breeze!
</p>
This script was actually created for my personal use only but i then decided to make the script accessible for everyone.
It is meant to help guiding you through a complete fresh install of Klipper and optionally the DWC2 web UI + DWC2-for-Klipper.
There are also functions for updating your current installations or removing them from your system.
<p align="center">
<a><img src="https://img.shields.io/github/license/th33xitus/kiauh"></a>
<a><img src="https://img.shields.io/github/stars/th33xitus/kiauh"></a>
<a><img src="https://img.shields.io/github/forks/th33xitus/kiauh"></a>
<a><img src="https://img.shields.io/github/languages/top/th33xitus/kiauh?logo=gnubash&logoColor=white"></a>
<a><img src="https://img.shields.io/github/v/tag/th33xitus/kiauh"></a>
<br />
<a><img src="https://img.shields.io/github/last-commit/th33xitus/kiauh"></a>
<a><img src="https://img.shields.io/github/contributors/th33xitus/kiauh"></a>
</p>
## First things first: When you decide to use this script, you use it at your own risk!
## **🛠️ Instructions:**
# THIS VERSION IS WORK IN PROGRESS!!!
# BUGS MAY BE STILL PRESENT!!!
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.\
After git is installed, use the following commands in the given order to download and execute the script:
```shell
cd ~
git clone https://github.com/th33xitus/kiauh.git
./kiauh/kiauh.sh
```
**📢 Disclaimer: Usage of this script happens at your own risk!**
## **❗ Notes:**
**📋 Please see the [Changelog](docs/changelog.md) for possible important changes!**
- 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.
## **🌐 Sources & Further Information**
<table>
<tr>
<th><h3><a href="https://github.com/Klipper3d/klipper">Klipper</a></h3></th>
<th><h3><a href="https://github.com/Arksine/moonraker">Moonraker</a></h3></th>
<th><h3><a href="https://github.com/mainsail-crew/mainsail">Mainsail</a></h3></th>
<th><h3><a href="https://github.com/fluidd-core/fluidd">Fluidd</a></h3></th>
</tr>
<tr>
<th><img src="https://raw.githubusercontent.com/Klipper3d/klipper/master/docs/img/klipper-logo.png" alt="Klipper Logo" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/9563098?v=4" alt="Arksine avatar" height="64"></th>
<th><img src="https://raw.githubusercontent.com/mainsail-crew/docs/master/assets/img/logo.png" alt="Mainsail Logo" height="64"></th>
<th><img src="https://raw.githubusercontent.com/fluidd-core/fluidd/master/docs/assets/images/logo.svg" alt="Fluidd Logo" height="64"></th>
</tr>
<tr>
<th>by <a href="https://github.com/KevinOConnor">KevinOConnor</a></th>
<th>by <a href="https://github.com/Arksine">Arksine</a></th>
<th>by <a href="https://github.com/mainsail-crew">mainsail-crew</a></th>
<th>by <a href="https://github.com/fluidd-core">fluidd-core</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/jordanruthe/KlipperScreen">KlipperScreen</a></h3></th>
<th><h3><a href="https://github.com/nlef/moonraker-telegram-bot">Moonraker-Telegram-Bot</a></h3></th>
<th><h3><a href="https://github.com/Kragrathea/pgcode">PrettyGCode for Klipper</a></h3></th>
<th><h3><a href="https://github.com/OctoPrint/OctoPrint">OctoPrint</a></h3></th>
</tr>
<tr>
<th><img src="https://avatars.githubusercontent.com/u/31575189?v=4" alt="jordanruthe avatar" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/52351624?v=4" alt="nlef avatar" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/5917231?v=4" alt="Kragrathea avatar" height="64"></th>
<th><img src="https://camo.githubusercontent.com/627be7fc67195b626b298af9b9677d7c58e698c67305e54324cffbe06130d4a4/68747470733a2f2f6f63746f7072696e742e6f72672f6173736574732f696d672f6c6f676f2e706e67" alt="OctoPrint Logo" height="64"></th>
</tr>
<tr>
<th>by <a href="https://github.com/jordanruthe">jordanruthe</a></th>
<th>by <a href="https://github.com/nlef">nlef</a></th>
<th>by <a href="https://github.com/Kragrathea">Kragrathea</a></th>
<th>by <a href="https://github.com/OctoPrint">OctoPrint</a></th>
</tr>
</table>
## **Credits**
* A big thank you to [lixxbox](https://github.com/lixxbox) for that awesome KIAUH-Logo!
* Also a big thank you to everyone who supported my work with a [Ko-fi](https://ko-fi.com/th33xitus) !
* Last but not least: Thank you to all contributors and members of the Klipper Community who like and share this project!

189
docs/changelog.md Normal file
View File

@@ -0,0 +1,189 @@
## Changelog
This document covers possible important changes to KIAUH.
### 2022-04-XX
KIAUH has now reached major version 4 !
* feat: Klipper can be installed under Python3 (considered as experimental)
* feat: Klipper can be installed from custom repositories / inofficial forks
* feat: Custom instance name for multi instance installations of Klipper
* Any other multi instance will share the same name given to the corresponding Klipper instance
* E.g. klipper-voron2 -> moonraker-voron2 -> moonraker-telegram-bot-voron2
* feat: Option to only allow the installation of stable Mainsail and Fluidd versions
* feat: Multi-Instance OctoPrint installations now each have their own virtual python environment
* allows independent installation of plugins for each instance
* feat: Implementing the use of shellcheck during development
* feat: Implementing a simple logging mechanic
* feat: Log-upload function now also allows uploading other logfiles (kiauh.log, webcamd.log etc.)
* fix: During Klipper installation, checks for group membership of `tty` and `dialout` are made
* refactor: Support for DWC and DWC-for-Klipper has been removed
* refactor: The backup before update settings were moved to the KIAUH settings menu
* refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature)
* refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen were removed from the moonraker.conf template
* They will now be individually added during installation of the corresponding interface
* refactor: The rollback function was reworked and now also allows rollbacks of Moonraker
* It now takes numerical inputs and reverts the corresponding repository by the given amount instead
* KIAUH does not save previous states to its config anymore like it did with the previous approach
### 2022-01-29
* Starting from the 28th of January, Moonraker can make use of PackageKit and PolicyKit.\
More details on that can be found [here](
https://github.com/Arksine/moonraker/issues/349) and [here](https://github.com/Arksine/moonraker/pull/346)
* KIAUH will install Moonrakers PolicyKit rules by default when __installing__ Moonraker
* KIAUH will also install Moonrakers PolicyKit rules when __updating__ Moonraker __via KIAUH__ as of now
### 2021-12-30
* Updated the doc for the usage of the [G-Code Shell Command Extension](docs/gcode_shell_command.md)
* It became apparent, that some user groups are missing on some systems. A missing video group \
membership for example caused issues when installing mjpg-streamer while not using the default pi user. \
Other issues could occur when trying to flash an MCU on Debian or Ubuntu distributions where a user might not be part
of the dialout group by default. A check for the tty group is also done. The tty group is needed for setting
up a linux MCU (currently not yet supported by KIAUH).
* There is an issue when trying to install Mainsail or Fluidd on Ubuntu 21.10. Permissions on that distro seem to have seen a rework
in comparison to 20.04 and users will be greeted with an "Error 403 - Permission denied" message after installing one of Klippers webinterfaces.
I still have to figure out a viable solution for that.
### 2021-09-28
* New Feature! Added an installer for the Telegram Bot for Moonraker by [nlef](https://github.com/nlef).
Checkout his project! Remember to report all issues and/or bugs regarding that project in its corresponding repo and not here 😛.\
You can find it here: https://github.com/nlef/moonraker-telegram-bot
### 2021-09-24
* The flashing function got adjusted a bit. It is now possible to also flash controllers which are connected over UART and thus accessible via `/dev/ttyAMA0`. You now have to select a connection methop prior flashing which is either USB or UART.
* Due to several requests over time I have now created a Ko-fi account for those who want to support this project and my work with a small donation. Many thanks in advance to all future donors. You can support me on Ko-fi with this link: https://ko-fi.com/th33xitus
* As usual, if you find any bugs or issues please report them. I tested the little rework i did with the hardware i have available and haven't encountered any malfunctions of flashing them yet.
### 2021-08-10
* KIAUH now supports the installation of the "PrettyGCode for Klipper" GCode-Viewer created by [Kragrathea](https://github.com/Kragrathea)! Installation, updating and removal are possible with KIAUH. For more details to this cool piece of software, please have a look here: https://github.com/Kragrathea/pgcode
### 2021-07-10
* The NGINX configuration files got updated to be in sync with MainsailOS and FluiddPi. Issues with the NGINX service not starting up due to wrong configuration should be resolved now. To get the updated configuration files, please remove Moonraker and Mainsail / Fluidd with KIAUH first and then re-install it. An automated file check for those configuration files might follow in the future which then automates updating those files if there were important changes.
* The default `moonraker.conf` was updated to reflect the recent changes to the update manager section. The update channel is set to `dev`.
### 2021-06-29
* KIAUH will now patch the new `log_path` to existing moonraker.conf files when updating Moonraker and the entry is missing. Before that, it was necessary that the user provided that path manually to make Fluidd display the logfiles in its interface. This issue should be resolved now.
### 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:
* The Klipper SysVinit service will get replaced by a Klipper systemd service
* Klipper and Moonraker will use the new log-directory `~/klipper_logs`
* The webcamd service gets updated
* The webcamd script gets updated and moved from `/root/bin/webcamd` to `/usr/local/bin/webcamd`
* The NGINX `upstreams.conf` gets updated to be able to configure up to 4 webcams
* The `mainsail.txt` / `fluiddpi.txt` gets moved from `/boot` to `~/klipper_config` and renamed to `webcam.txt`
* Symlinks for the webcamd.log and various NGINX logs get created in `~/klipper_config`
* Configuration files for Klipper, Moonraker and webcamd get added to `/etc/logrotate.d`
* 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 OctoPrint even though only Klipper and Moonraker are shown in this example.
* You can start, stop and restart all Klipper, Moonraker 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
* 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!
### 2020-11-18
* Some changes to Fluidd caused a little rework on how KIAUH will install/update Fluidd from now on. Please see the [fluidd v1.0.0-rc0 release notes](https://github.com/cadriel/fluidd/releases/tag/v1.0.0-rc.0) for further information about what modifications to the moonraker.conf file exactly had to be done. In a nutshell, KIAUH will now always patch the required entries to the moonraker.conf if not already there.
### 2020-10-30:
* The user can now choose to install Klipper as a systemd service.
* The Shell Command extension and `shell_command.py` got renamed to G-Code Shell Command extension and `gcode_shell_command.py`. In case the [pending PR](https://github.com/KevinOConnor/klipper/pull/2173) will be merged in the future, this was an early attempt to dodge possible incompatibilities. The [G-Code Shell Command docs](gcode_shell_command.md) has been updated accordingly.
* The way how KIAUH interacts and writes to the users printer.cfg got changed. Usually KIAUH wrote everything directly into the printer.cfg. The way it will work from now on is, that a new file called `kiauh.cfg` will be created if there is something that needs to be written to the printer.cfg and everything gets written to `kiauh.cfg` instead. The only thing which then gets written to the users printer.cfg is `[include kiauh.cfg]`. This line will be located at the very top of the existing printer.cfg with a little comment as a note. The user can then decide to either keep the `kiauh.cfg` or take its content, places it into the printer.cfg directly and remove the `[include kiauh.cfg]`.
* The `mainsail_macros.cfg` got renamed to `webui_macros.cfg`. Since Mainsail and Fluidd both use the same kind of pause, cancel and resume macros, a more generic name was chosen for the file containing the example macros one can choose to install when installing those webinterfaces.
### 2020-10-10:
* Support for changing the Klipper branch to the moonraker-dev branch from @Arksine has been dropped. Support for Moonraker has been merged into Klipper mainline a long time ago.
* A new function is available from the main menu. You can now upload your log files to http://paste.c-net.org/ to share them for debugging purposes.
### 2020-10-06:
* Fluidd, a new Klipper interface got added to the list of available installers. At the same time some installation routines have changed or have seen some rework. Changes were made to the installation of NGINX configurations. A method was introduced to change the listen port of a webinterface configuration if there is already another webinterface listening on the default port (80).
* At the moment, the Moonraker installer no longer asks you whether you want to install a web interface too. For now you therefore have to install them with their respective installers. Please report any bugs or issues you encounter.
### 2020-09-17:
* The dev-2.0 branch will be abandoned as of today. If you did a checkout to that branch in the past, you have to checkout back to master to receive updates.
### 2020-09-12:
* The old [dwc2-for-klipper](https://github.com/Stephan3/dwc2-for-klipper) won't be supported anymore!\
The is a new, fully rewritten project available: [dwc2-for-klipper-socket](https://github.com/Stephan3/dwc2-for-klipper-socket).\
The installer of this script also got rewritten to make use of that new project. You will not be able to install or remove the old [dwc2-for-klipper](https://github.com/Stephan3/dwc2-for-klipper) with KIAUH anymore if you updated KIAUH to the newest version.

View File

@@ -0,0 +1,74 @@
# G-Code Shell Command Extension
### Creator of this extension is [Arksine](https://github.com/Arksine).
This is a brief explanation of how to use the shell command extension for Klipper, which you can install with KIAUH.
After installing the extension you can execute linux commands or even scripts from within Klipper with custom commands defined in your printer.cfg.
#### How to configure a shell command:
```shell
# Runs a linux command or script from within klipper. Note that sudo commands
# that require password authentication are disallowed. All executable scripts
# should include a shebang.
# [gcode_shell_command my_shell_cmd]
#command:
# The linux shell command/script to be executed. This parameter must be
# provided
#timeout: 2.
# The timeout in seconds until the command is forcably terminated. Default
# is 2 seconds.
#verbose: True
# If enabled, the command's output will be forwarded to the terminal. Its
# recommended to set this to false for commands that my run in quick
# succession. Default is True.
```
Once you have set up a shell command with the given parameters from above in your printer.cfg you can run the command as follows:
`RUN_SHELL_COMMAND CMD=name`
Example:
```
[gcode_shell_command hello_world]
command: echo hello world
timeout: 2.
verbose: True
```
Execute with:
`RUN_SHELL_COMMAND CMD=hello_world`
### Passing parameters:
As of commit [f231fa9](https://github.com/th33xitus/kiauh/commit/f231fa9c69191f23277b4e3319f6b675bfa0ee42) it is also possible to pass optional parameters to a `gcode_shell_command`.
The following short example shows storing the extruder temperature into a variable, passing that value with a parameter to a `gcode_shell_command`, which then,
once the gcode_macro runs and the gcode_shell_command gets called, executes the `script.sh`. The script then echoes a message to the console (if `verbose: True`)
and writes the value of the parameter into a textfile called `test.txt` located in the home directory.
Content of the `gcode_shell_command` and the `gcode_macro`:
```
[gcode_shell_command print_to_file]
command: sh /home/pi/klipper_config/script.sh
timeout: 30.
verbose: True
[gcode_macro GET_TEMP]
gcode:
{% set temp = printer.extruder.temperature %}
{ action_respond_info("%s" % (temp)) }
RUN_SHELL_COMMAND CMD=print_to_file PARAMS={temp}
```
Content of `script.sh`:
```shell
#!/bin/sh
echo "temp is: $1"
echo "$1" >> "${HOME}/test.txt"
```
## Warning
This extension may have a high potential for abuse if not used carefully! Also, depending on the command you execute, high system loads may occur and can cause system instabilities.
Use this extension at your own risk and only if you know what you are doing!

View File

@@ -1 +0,0 @@
backup_before_update=false

440
kiauh.sh Normal file → Executable file
View File

@@ -1,387 +1,89 @@
#!/bin/bash
clear
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
### set some variables
ERROR_MSG=""
green="\e[92m"
yellow="\e[93m"
red="\e[91m"
cyan="\e[96m"
default="\e[39m"
### set some messages
warn_msg(){
echo -e "${red}<!!!!> $1${default}"
}
status_msg(){
echo; echo -e "${yellow}###### $1${default}"
}
ok_msg(){
echo -e "${green}>>>>>> $1${default}"
}
title_msg(){
echo -e "${cyan}$1${default}"
}
get_date(){
current_date=`date +"%Y-%m-%d_%H%M%S"`
}
clear
### sourcing all additional scripts
for script in ${HOME}/kiauh/scripts/*; do . $script; done
KIAUH_SRCDIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
for script in "${KIAUH_SRCDIR}/scripts/"*.sh; do . "${script}"; done
for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
### set important directories
#klipper
KLIPPER_DIR=${HOME}/klipper
KLIPPY_ENV_DIR=${HOME}/klippy-env
KLIPPER_SERVICE1=/etc/init.d/klipper
KLIPPER_SERVICE2=/etc/default/klipper
#dwc2
DWC2FK_DIR=${HOME}/dwc2-for-klipper
DWC2_DIR=${HOME}/sdcard/dwc2
WEB_DWC2=${HOME}/klipper/klippy/extras/web_dwc2.py
TORNADO_DIR1=${HOME}/klippy-env/lib/python2.7/site-packages/tornado
TORNADO_DIR2=${HOME}/klippy-env/lib/python2.7/site-packages/tornado-5.1.1.dist-info
#mainsail/moonraker
MAINSAIL_DIR=${HOME}/mainsail
MAINSAIL_SERVICE1=/etc/init.d/moonraker
MAINSAIL_SERVICE2=/etc/default/moonraker
#misc
BACKUP_DIR=${HOME}/kiauh-backups
PRINTER_CFG=${HOME}/printer.cfg
#===================================================#
#=================== UPDATE KIAUH ==================#
#===================================================#
### set github repos
KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git
ARKSINE_REPO=https://github.com/Arksine/klipper.git
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper.git
#branches
BRANCH_MOONRAKER=Arksine/work-web_server-20200131
BRANCH_DEV_MOONRAKER=Arksine/dev-moonraker-testing
BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing
BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping
function update_kiauh() {
status_msg "Updating KIAUH ..."
print_error_msg(){
if [[ "$ERROR_MSG" != "" ]]; then
echo -e "${red}"
echo -e "#########################################################"
echo -e "$ERROR_MSG "
echo -e "#########################################################"
echo -e "${default}"
cd "${KIAUH_SRCDIR}"
git reset --hard && git pull
ok_msg "Update complete! Please restart KIAUH."
exit 0
}
#===================================================#
#=================== KIAUH STATUS ==================#
#===================================================#
function kiauh_update_avail() {
[[ ! -d "${KIAUH_SRCDIR}/.git" ]] && return
local origin head
cd "${KIAUH_SRCDIR}"
### abort if not on master branch
! git branch -a | grep -q "\* master" && return
### compare commit hash
git fetch -q
origin=$(git rev-parse --short=8 origin/master)
head=$(git rev-parse --short=8 HEAD)
if [[ ${origin} != "${head}" ]]; then
echo "true"
fi
}
main_menu(){
print_header
print_error_msg && ERROR_MSG=""
#check install status
klipper_status
dwc2_status
mainsail_status
print_branch
main_ui
function kiauh_update_dialog() {
[[ ! $(kiauh_update_avail) == "true" ]] && return
top_border
echo -e "|${green} New KIAUH update available! ${white}|"
hr
echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}|"
blank_line
echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}|"
echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|"
echo -e "|${yellow} features. Please consider updating! ${white}|"
bottom_border
local yn
read -p "${cyan}###### Do you want to update now? (Y/n):${white} " yn
while true; do
read -p "Perform action: " action; echo
case "$action" in
0)
clear
print_header
ERROR_MSG=" Sorry this function is not implemented yet!"
print_error_msg && ERROR_MSG=""
main_ui;;
1)
clear
install_menu
case "${yn}" in
Y|y|Yes|yes|"")
do_action "update_kiauh"
break;;
2)
clear
update_menu
N|n|No|no)
break;;
3)
clear
remove_menu
break;;
4)
clear
advanced_menu
break;;
5)
clear
backup_menu
break;;
Q|q)
exit -1;;
*)
clear
print_header
ERROR_MSG=" Unknown command '$action'"
print_error_msg && ERROR_MSG=""
main_ui;;
deny_action "kiauh_update_dialog";;
esac
done
clear; main_menu
}
install_menu(){
print_header
install_ui
while true; do
read -p "Perform action: " action; echo
case "$action" in
1)
clear
print_header
install_klipper
print_error_msg && ERROR_MSG=""
install_ui;;
2)
clear
print_header
dwc2_install_routine
print_error_msg && ERROR_MSG=""
install_ui;;
3)
clear
print_header
mainsail_install_routine
print_error_msg && ERROR_MSG=""
install_ui;;
Q|q)
clear; main_menu; break;;
*)
clear
print_header
ERROR_MSG=" Unknown command '$action'"
print_error_msg && ERROR_MSG=""
install_ui;;
esac
done
install_menu
}
update_menu(){
print_header
read_bb4u_stat
#compare versions
ui_print_versions
update_ui
while true; do
read -p "Perform action: " action; echo
case "$action" in
0)
clear
print_header
toggle_backups
print_error_msg && ERROR_MSG=""
update_ui;;
1)
clear
print_header
update_klipper && ui_print_versions
print_error_msg && ERROR_MSG=""
update_ui;;
2)
clear
print_header
update_dwc2fk && ui_print_versions
print_error_msg && ERROR_MSG=""
update_ui;;
3)
clear
print_header
update_dwc2 && ui_print_versions
print_error_msg && ERROR_MSG=""
update_ui;;
4)
clear
print_header
update_mainsail && ui_print_versions
print_error_msg && ERROR_MSG=""
update_ui;;
Q|q)
clear; main_menu; break;;
*)
clear
print_header
ERROR_MSG=" Unknown command '$action'"
print_error_msg && ERROR_MSG=""
ui_print_versions
update_ui;;
esac
done
update_menu
}
remove_menu(){
print_header
remove_ui
while true; do
read -p "Perform action: " action; echo
case "$action" in
1)
clear
print_header
remove_klipper
print_error_msg && ERROR_MSG=""
remove_ui;;
2)
clear
print_header
remove_dwc2
print_error_msg && ERROR_MSG=""
remove_ui;;
3)
clear
print_header
remove_mainsail
print_error_msg && ERROR_MSG=""
remove_ui;;
Q|q)
clear; main_menu; break;;
*)
clear
print_header
ERROR_MSG=" Unknown command '$action'"
print_error_msg && ERROR_MSG=""
remove_ui;;
esac
done
remove_menu
}
advanced_menu(){
print_header
print_error_msg && ERROR_MSG=""
advanced_ui
while true; do
read -p "Perform action: " action; echo
case "$action" in
1)
clear
switch_menu
print_error_msg && ERROR_MSG=""
advanced_ui;;
2)
clear
print_header
build_fw
print_error_msg && ERROR_MSG=""
advanced_ui;;
3)
clear
print_header
flash_routine
print_error_msg && ERROR_MSG=""
advanced_ui;;
4)
clear
print_header
get_usb_id
print_error_msg && ERROR_MSG=""
advanced_ui;;
5)
clear
print_header
get_usb_id && write_printer_id
print_error_msg && ERROR_MSG=""
advanced_ui;;
6)
clear
print_header
create_dwc2fk_cfg
print_error_msg && ERROR_MSG=""
advanced_ui;;
Q|q)
clear; main_menu; break;;
*)
clear
print_header
ERROR_MSG=" Unknown command '$action'"
print_error_msg && ERROR_MSG=""
advanced_ui;;
esac
done
advanced_menu
}
switch_menu(){
print_header
if [ -d $KLIPPER_DIR ]; then
read_branch
print_error_msg && ERROR_MSG=""
switch_ui
while true; do
read -p "Perform action: " action; echo
case "$action" in
1)
clear
print_header
switch_to_origin
read_branch
print_error_msg && ERROR_MSG=""
switch_ui;;
2)
clear
print_header
switch_to_scurve_shaping
read_branch
print_error_msg && ERROR_MSG=""
switch_ui;;
3)
clear
print_header
switch_to_scurve_smoothing
read_branch
print_error_msg && ERROR_MSG=""
switch_ui;;
4)
clear
print_header
switch_to_moonraker
read_branch
print_error_msg && ERROR_MSG=""
switch_ui;;
5)
clear
print_header
switch_to_dev_moonraker
read_branch
print_error_msg && ERROR_MSG=""
switch_ui;;
Q|q)
clear; advanced_menu; break;;
esac
done
else
ERROR_MSG=" No klipper directory found! Download klipper first!"
fi
}
backup_menu(){
print_header
print_error_msg && ERROR_MSG=""
backup_ui
while true; do
read -p "Perform action: " action; echo
case "$action" in
1)
clear
print_header
#function goes here
print_error_msg && ERROR_MSG=""
backup_ui;;
Q|q)
clear; main_menu; break;;
*)
clear
print_header
ERROR_MSG=" Unknown command '$action'"
print_error_msg && ERROR_MSG=""
backup_ui;;
esac
done
backup_menu
}
check_euid
main_menu
init_logfile
set_globals
init_ini
kiauh_update_dialog
main_menu

18
klipper_repos.txt.example Normal file
View File

@@ -0,0 +1,18 @@
# This file acts as an example file.
#
# 1) Make a copy of this file and rename it to 'klipper_repos.txt'
# 2) Add your custom Klipper repository to the bottom of that copy
# 3) Save the file
#
# Back in KIAUH you can now go into -> [Settings] and use action '2' to set a different Klipper repository
#
# Make sure to always separate the repository and the branch with a ','.
# <repository>,<branch> -> https://github.com/Klipper3d/klipper,master
# If you omit a branch, it will always default to 'master'
#
# You are allowed to omit the 'https://github.com/' part of the repository URL
# Down below are now a few examples of what is considered as valid:
https://github.com/Klipper3d/klipper,master
https://github.com/Klipper3d/klipper
Klipper3d/klipper,master
Klipper3d/klipper

65
resources/autocommit.sh Executable file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/env bash
#####################################################################
### Please set the paths accordingly. In case you don't have all ###
### the listed folders, just keep that line commented out. ###
#####################################################################
### Path to your config folder you want to back up
#config_folder=~/klipper_config
### Path to your Klipper folder, by default that is '~/klipper'
#klipper_folder=~/klipper
### Path to your Moonraker folder, by default that is '~/moonraker'
#moonraker_folder=~/moonraker
### Path to your Mainsail folder, by default that is '~/mainsail'
#mainsail_folder=~/mainsail
### Path to your Fluidd folder, by default that is '~/fluidd'
#fluidd_folder=~/fluidd
#####################################################################
#####################################################################
#####################################################################
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
#####################################################################
grab_version() {
local klipper_commit moonraker_commit
local mainsail_ver fluidd_ver
if [[ -n ${klipper_folder} ]]; then
cd "${klipper_folder}"
klipper_commit=$(git rev-parse --short=7 HEAD)
m1="Klipper on commit: ${klipper_commit}"
fi
if [[ -n ${moonraker_folder} ]]; then
cd "${moonraker_folder}"
moonraker_commit=$(git rev-parse --short=7 HEAD)
m2="Moonraker on commit: ${moonraker_commit}"
fi
if [[ -n ${mainsail_folder} ]]; then
mainsail_ver=$(head -n 1 "${mainsail_folder}/.version")
m3="Mainsail version: ${mainsail_ver}"
fi
if [[ -n ${fluidd_folder} ]]; then
fluidd_ver=$(head -n 1 "${fluidd_folder}/.version")
m4="Fluidd version: ${fluidd_ver}"
fi
}
push_config() {
local current_date
cd "${config_folder}" || exit 1
git pull
git add .
current_date=$(date +"%Y-%m-%d %T")
git commit -m "Autocommit from ${current_date}" -m "${m1}" -m "${m2}" -m "${m3}" -m "${m4}"
git push
}
grab_version
push_config

View File

@@ -0,0 +1,6 @@
# /etc/nginx/conf.d/common_vars.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

View File

@@ -0,0 +1,87 @@
# Run a shell command via gcode
#
# Copyright (C) 2019 Eric Callahan <arksine.code@gmail.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os
import shlex
import subprocess
import logging
class ShellCommand:
def __init__(self, config):
self.name = config.get_name().split()[-1]
self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode')
cmd = config.get('command')
cmd = os.path.expanduser(cmd)
self.command = shlex.split(cmd)
self.timeout = config.getfloat('timeout', 2., above=0.)
self.verbose = config.getboolean('verbose', True)
self.proc_fd = None
self.partial_output = ""
self.gcode.register_mux_command(
"RUN_SHELL_COMMAND", "CMD", self.name,
self.cmd_RUN_SHELL_COMMAND,
desc=self.cmd_RUN_SHELL_COMMAND_help)
def _process_output(self, eventime):
if self.proc_fd is None:
return
try:
data = os.read(self.proc_fd, 4096)
except Exception:
pass
data = self.partial_output + data.decode()
if '\n' not in data:
self.partial_output = data
return
elif data[-1] != '\n':
split = data.rfind('\n') + 1
self.partial_output = data[split:]
data = data[:split]
else:
self.partial_output = ""
self.gcode.respond_info(data)
cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command"
def cmd_RUN_SHELL_COMMAND(self, params):
gcode_params = params.get('PARAMS','')
gcode_params = shlex.split(gcode_params)
reactor = self.printer.get_reactor()
try:
proc = subprocess.Popen(
self.command + gcode_params, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except Exception:
logging.exception(
"shell_command: Command {%s} failed" % (self.name))
raise self.gcode.error("Error running command {%s}" % (self.name))
if self.verbose:
self.proc_fd = proc.stdout.fileno()
self.gcode.respond_info("Running Command {%s}...:" % (self.name))
hdl = reactor.register_fd(self.proc_fd, self._process_output)
eventtime = reactor.monotonic()
endtime = eventtime + self.timeout
complete = False
while eventtime < endtime:
eventtime = reactor.pause(eventtime + .05)
if proc.poll() is not None:
complete = True
break
if not complete:
proc.terminate()
if self.verbose:
if self.partial_output:
self.gcode.respond_info(self.partial_output)
self.partial_output = ""
if complete:
msg = "Command {%s} finished\n" % (self.name)
else:
msg = "Command {%s} timed out" % (self.name)
self.gcode.respond_info(msg)
reactor.unregister_fd(hdl)
self.proc_fd = None
def load_config_prefix(config):
return ShellCommand(config)

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
################################################################################
################################################################################

22
resources/klipper.service Normal file
View File

@@ -0,0 +1,22 @@
#Systemd Klipper Service
[Unit]
Description=Systemd Klipper Service for instance klipper-%INST%
Documentation=https://www.klipper3d.org/
After=network.target
Wants=udev.target
[Install]
WantedBy=multi-user.target
[Service]
Environment=KLIPPER_CONFIG=%CFG%
Environment=KLIPPER_LOG=%LOG%
Environment=KLIPPER_SOCKET=%UDS%
Environment=KLIPPER_PRINTER=%PRINTER%
Type=simple
User=%USER%
RemainAfterExit=yes
ExecStart=%ENV%/bin/python %DIR%/klippy/klippy.py ${KLIPPER_CONFIG} -I ${KLIPPER_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPER_SOCKET}
Restart=always
RestartSec=10

View File

@@ -0,0 +1,95 @@
# /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/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_http_version 1.1;
proxy_set_header Upgrade $http_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_set_header X-Scheme $scheme;
}
location /webcam/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer1/;
}
location /webcam2/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer2/;
}
location /webcam3/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer3/;
}
location /webcam4/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer4/;
}
}

View File

@@ -0,0 +1,19 @@
#Systemd service file for Moonraker Telegram Bot
[Unit]
Description=Starts Moonraker Telegram Bot instance %INST% on startup
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Environment=TELEGRAM_CONF=%CFG%
Environment=TELEGRAM_LOG=%LOG%
Type=simple
User=%USER%
RemainAfterExit=yes
ExecStart=%ENV%/bin/python %DIR%/bot/main.py -c ${TELEGRAM_CONF} -l ${TELEGRAM_LOG}
Restart=always
RestartSec=10

38
resources/moonraker.conf Normal file
View File

@@ -0,0 +1,38 @@
[server]
host: 0.0.0.0
port: %PORT%
enable_debug_logging: False
klippy_uds_address: %UDS%
[authorization]
trusted_clients:
%LAN%
10.0.0.0/8
127.0.0.0/8
169.254.0.0/16
172.16.0.0/12
192.168.0.0/16
FE80::/10
::1/128
cors_domains:
http://*.lan
http://*.local
https://my.mainsail.xyz
http://my.mainsail.xyz
https://app.fluidd.xyz
http://app.fluidd.xyz
[database]
database_path: %DB%
[file_manager]
config_path: %CFG%
log_path: %LOG%
[octoprint_compat]
[history]
[update_manager]
channel: dev
refresh_interval: 168

View File

@@ -0,0 +1,20 @@
#Systemd Moonraker Service
[Unit]
Description=Systemd Moonraker Service for instance moonraker-%INST%
Documentation=https://moonraker.readthedocs.io/
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Environment=MOONRAKER_CONF=%CFG%
Environment=MOONRAKER_LOG=%LOG%
Type=simple
SupplementaryGroups=moonraker-admin
User=%USER%
RemainAfterExit=yes
ExecStart=%ENV%/bin/python %DIR%/moonraker/moonraker.py -c ${MOONRAKER_CONF} -l ${MOONRAKER_LOG}
Restart=always
RestartSec=10

7
resources/printer.cfg Normal file
View File

@@ -0,0 +1,7 @@
[mcu]
serial: /dev/serial/by-id/<your-mcu-id>
[printer]
kinematics: none
max_velocity: 1000
max_accel: 1000

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 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

25
resources/upstreams.conf Normal file
View File

@@ -0,0 +1,25 @@
# /etc/nginx/conf.d/upstreams.conf
upstream apiserver {
ip_hash;
server 127.0.0.1:7125;
}
upstream mjpgstreamer1 {
ip_hash;
server 127.0.0.1:8080;
}
upstream mjpgstreamer2 {
ip_hash;
server 127.0.0.1:8081;
}
upstream mjpgstreamer3 {
ip_hash;
server 127.0.0.1:8082;
}
upstream mjpgstreamer4 {
ip_hash;
server 127.0.0.1:8083;
}

15
resources/webcamd.service Normal file
View File

@@ -0,0 +1,15 @@
[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

230
scripts/backup.sh Normal file → Executable file
View File

@@ -1,74 +1,188 @@
backup_printer_cfg(){
if [ ! -d $BACKUP_DIR ]; then
status_msg "Create backup directory ..."
mkdir -p $BACKUP_DIR && ok_msg "Directory created!"
fi
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 created!"
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function get_date() {
local current_date
current_date=$(date +"%y%m%d-%H%M")
echo "${current_date}"
}
function check_for_backup_dir() {
[[ -d ${BACKUP_DIR} ]] && return
status_msg "Create KIAUH backup directory ..."
mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
}
function backup_before_update() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${backup_before_update}"
[[ ${state} = "false" ]] && return
backup_"${1}"
}
function backup_klipper_config_dir() {
check_for_backup_dir
local current_date config_folder_name
if [[ -d "${KLIPPER_CONFIG}" ]]; then
current_date=$(get_date)
config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)"
status_msg "Timestamp: ${current_date}"
status_msg "Create backup of the Klipper config directory ..."
mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}"
cp -r "${KLIPPER_CONFIG}" "${_}"
print_confirm "Configuration directory backup complete!"
else
ok_msg "No printer.cfg found! Skipping backup ..."
ok_msg "No config directory found! Skipping backup ..."
fi
}
read_bb4u_stat(){
source_ini
if [ ! "$backup_before_update" = "true" ]; then
BB4U_STATUS="${green}[Enable]${default} backups before updating "
function backup_moonraker_database() {
check_for_backup_dir
local current_date databases target_dir regex=".moonraker_database(_[0-9a-zA-Z]+)?"
databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/${regex}" | sort)
if [[ -n ${databases} ]]; then
current_date=$(get_date)
target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}"
status_msg "Timestamp: ${current_date}"
mkdir -p "${target_dir}"
for database in ${databases}; do
status_msg "Create backup of ${database} ..."
cp -r "${database}" "${target_dir}"
ok_msg "Done!"
done
print_confirm "Moonraker database backup complete!"
else
BB4U_STATUS="${red}[Disable]${default} backups before updating "
print_error "No Moonraker database found! Skipping backup ..."
fi
return
}
toggle_backups(){
source_ini
if [ "$backup_before_update" = "true" ]; then
sed -i '/backup_before_update=/s/true/false/' ${HOME}/kiauh2/kiauh.ini
BB4U_STATUS="${green}[Enable]${default} backups before updating "
fi
if [ "$backup_before_update" = "false" ]; then
sed -i '/backup_before_update=/s/false/true/' ${HOME}/kiauh2/kiauh.ini
BB4U_STATUS="${red}[Disable]${default} backups before updating "
fi
}
function backup_klipper() {
local current_date
bb4u_klipper(){
source_ini
if [ -d $KLIPPER_DIR ] && [ "$backup_before_update" = "true" ]; then
get_date
if [[ -d ${KLIPPER_DIR} && -d ${KLIPPY_ENV} ]]; then
status_msg "Creating Klipper backup ..."
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date"
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV_DIR $_ && ok_msg "Backup complete!"
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}"
cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}"
print_confirm "Klipper backup complete!"
else
print_error "Can't back up 'klipper' and/or 'klipper-env' directory! Not found!"
fi
}
bb4u_dwc2fk(){
source_ini
if [ -d $DWC2FK_DIR ] && [ "$backup_before_update" = "true" ]; then
get_date
status_msg "Creating DWC2-for-Klipper backup ..."
mkdir -p $BACKUP_DIR/dwc2-for-klipper-backups/"$current_date"
cp -r $DWC2FK_DIR $_ && ok_msg "Backup complete!"
fi
}
function backup_mainsail() {
local current_date
bb4u_dwc2(){
source_ini
if [ -d $DWC2_DIR ] && [ "$backup_before_update" = "true" ]; then
get_date
status_msg "Creating DWC2 Web UI backup ..."
mkdir -p $BACKUP_DIR/dwc2-backups/"$current_date"
cp -r $DWC2_DIR $_ && ok_msg "Backup complete!"
fi
}
bb4u_mainsail(){
source_ini
if [ -d $MAINSAIL_DIR ] && [ "$backup_before_update" = "true" ]; then
get_date
if [[ -d ${MAINSAIL_DIR} ]]; then
status_msg "Creating Mainsail backup ..."
mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date"
cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!"
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}"
cp -r "${MAINSAIL_DIR}" "${_}"
print_confirm "Mainsail backup complete!"
else
print_error "Can't back up 'mainsail' directory! Not found!"
fi
}
}
function backup_fluidd() {
local current_date
if [[ -d ${FLUIDD_DIR} ]]; then
status_msg "Creating Fluidd backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}"
cp -r "${FLUIDD_DIR}" "${_}"
print_confirm "Fluidd backup complete!"
else
print_error "Can't back up 'fluidd' directory! Not found!"
fi
}
function backup_moonraker() {
local current_date
if [[ -d ${MOONRAKER_DIR} && -d ${MOONRAKER_ENV} ]]; then
status_msg "Creating Moonraker backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}"
cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}"
print_confirm "Moonraker backup complete!"
else
print_error "Can't back up moonraker and/or moonraker-env directory! Not found!"
fi
}
function backup_octoprint() {
local current_date
if [[ -d ${OCTOPRINT_DIR} && -d ${OCTOPRINT_CFG_DIR} ]]; then
status_msg "Creating OctoPrint backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}"
cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
print_confirm " OctoPrint backup complete!"
else
print_error "Can't back up OctoPrint and/or .octoprint directory!\n Not found!"
fi
}
function backup_klipperscreen() {
local current_date
if [[ -d ${KLIPPERSCREEN_DIR} ]] ; then
status_msg "Creating KlipperScreen backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}"
cp -r "${KLIPPERSCREEN_DIR}" "${_}"
print_confirm "KlipperScreen backup complete!"
else
print_error "Can't back up KlipperScreen directory!\n Not found!"
fi
}
function backup_telegram_bot() {
local current_date
if [[ -d ${TELEGRAM_BOT_DIR} ]] ; then
status_msg "Creating MoonrakerTelegramBot backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}"
cp -r "${TELEGRAM_BOT_DIR}" "${_}"
print_confirm "MoonrakerTelegramBot backup complete!"
else
print_error "Can't back up MoonrakerTelegramBot directory!\n Not found!"
fi
}

409
scripts/flash_klipper.sh Normal file
View File

@@ -0,0 +1,409 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function init_flash_process() {
### step 1: check for required userhgroups (tty & dialout)
check_usergroups
top_border
echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |"
hr
echo -e "| Please select the flashing method to flash your MCU. |"
echo -e "| Make sure to only select a method your MCU supports. |"
echo -e "| Not all MCUs support both methods! |"
hr
blank_line
echo -e "| 1) Regular flashing method |"
echo -e "| 2) Updating via SD-Card Update |"
blank_line
back_help_footer
local choice method
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
1)
select_msg "Regular flashing method"
method="regular"
break;;
2)
select_msg "SD-Card Update"
method="sdcard"
break;;
B|b)
advanced_menu
break;;
H|h)
clear && print_header
show_flash_method_help
break;;
*)
error_msg "Invalid command!";;
esac
done
### step 2: select how the mcu is connected to the host
select_mcu_connection
### step 3: select which detected mcu should be flashed
select_mcu_id "${method}"
}
#================================================#
#=================== STEP 2 =====================#
#================================================#
function select_mcu_connection() {
top_border
echo -e "| ${yellow}Make sure that the controller board is connected now!${white} |"
hr
blank_line
echo -e "| How is the controller board connected to the host? |"
echo -e "| 1) USB |"
echo -e "| 2) UART |"
blank_line
back_help_footer
local choice
while true; do
read -p "${cyan}###### Connection method:${white} " choice
case "${choice}" in
1)
status_msg "Identifying MCU connected via USB ...\n"
get_usb_id || true # continue even after exit code 1
break;;
2)
status_msg "Identifying MCU possibly connected via UART ...\n"
get_uart_id || true # continue even after exit code 1
break;;
B|b)
advanced_menu
break;;
H|h)
clear && print_header
show_mcu_connection_help
break;;
*)
error_msg "Invalid command!";;
esac
done
}
function print_detected_mcu_to_screen() {
local i=1
if (( ${#mcu_list[@]} < 1 )); then
print_error "No MCU found!\n MCU eihter not connected or not detected!"
return
fi
for mcu in "${mcu_list[@]}"; do
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
i=$(( i + 1 ))
done
echo
}
#================================================#
#=================== STEP 3 =====================#
#================================================#
function select_mcu_id() {
local i=0 sel_index=0 method=${1}
if (( ${#mcu_list[@]} < 1 )); then
print_error "No MCU found!\n MCU eihter not connected or not detected!"
return
fi
top_border
echo -e "| ${red}!!! ATTENTION !!!${white} |"
hr
echo -e "| Make sure, to select the correct MCU! |"
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |"
bottom_border
echo -e "${cyan}###### List of available MCU:${white}"
### list all mcus
for mcu in "${mcu_list[@]}"; do
i=$(( i + 1 ))
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
done
### verify user input
local regex="^[1-9]+$"
while [[ ! ${sel_index} =~ ${regex} ]] || [[ ${sel_index} -gt ${i} ]]; do
echo
read -p "${cyan}###### Select MCU to flash:${white} " sel_index
if [[ ! ${sel_index} =~ ${regex} ]]; then
error_msg "Invalid input!"
elif [[ ${sel_index} -lt 1 ]] || [[ ${sel_index} -gt ${i} ]]; then
error_msg "Please select a number between 1 and ${i}!"
fi
local mcu_index=$(( sel_index - 1 ))
local selected_mcu_id="${mcu_list[${mcu_index}]}"
done
### confirm selection
local yn
while true; do
echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n"
read -p "${cyan}###### Continue? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
status_msg "Flashing ${selected_mcu_id} ..."
if [[ ${method} == "regular" ]]; then
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
start_flash_mcu "${selected_mcu_id}"
elif [[ ${method} == "sdcard" ]]; then
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
start_flash_sd "${selected_mcu_id}"
else
print_error "No flash method set! Aborting..."
log_error "No flash method set!"
return
fi
break;;
N|n|No|no)
select_msg "No"
break;;
*)
error_msg "Invalid command!";;
esac
done
}
function start_flash_mcu() {
local device=${1}
do_action_service "stop" "klipper"
if make flash FLASH_DEVICE="${device}"; then
ok_msg "Flashing successfull!"
else
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
fi
do_action_service "start" "klipper"
}
function start_flash_sd() {
local i=0 board_list=() device=${1}
local flash_script="${KLIPPER_DIR}/scripts/flash-sdcard.sh"
### write each supported board to the array to make it selectable
for board in $("${flash_script}" -l | tail -n +2); do
board_list+=("${board}")
done
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
i=$(( i + 1 ))
done
quit_footer
### make the user select one of the boards
local choice
while true; do
read -p "${cyan}###### Please select board type:${white} " choice
if [[ ${choice} = "q" || ${choice} = "Q" ]]; then
clear && advanced_menu && break
elif [[ ${choice} -le ${#board_list[@]} ]]; then
local selected_board="${board_list[${choice}]}"
break
else
clear && print_header
error_msg "Invalid choice!"
flash_mcu_sd
fi
done
while true; do
echo
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
local baud_rate regex="^[0-9]+$"
echo -e "${cyan}###### Please set the baud rate:${white} "
while [[ ! ${baud_rate} =~ ${regex} ]]; do
read -e -i "250000" -e baud_rate
local selected_baud_rate=${baud_rate}
break
done
break
done
###flash process
do_action_service "stop" "klipper"
if "${flash_script}" -b "${selected_baud_rate}" "${device}" "${selected_board}"; then
print_confirm "Flashing successfull!"
log_info "Flash successfull!"
else
print_error "Flashing failed!\n Please read the console output above!"
log_error "Flash failed!"
fi
do_action_service "start" "klipper"
}
function build_fw() {
local python_version
if [[ ! -d ${KLIPPER_DIR} || ! -d ${KLIPPY_ENV} ]]; then
print_error "Klipper not found!\n Cannot build firmware without Klipper!"
return
fi
python_version=$(get_klipper_python_ver)
cd "${KLIPPER_DIR}"
status_msg "Initializing firmware build ..."
local dep=(build-essential dpkg-dev make)
dependency_check "${dep[@]}"
make clean
status_msg "Building firmware ..."
if (( python_version == 3 )); then
make PYTHON=python3 menuconfig
make PYTHON=python3
elif (( python_version == 2 )); then
make PYTHON=python2 menuconfig
make PYTHON=python2
else
warn_msg "Error reading Python version!"
return 1
fi
ok_msg "Firmware built!"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function get_usb_id() {
unset mcu_list
sleep 1
mcus=$(find /dev/serial/by-id/* 2>/dev/null)
for mcu in ${mcus}; do
mcu_list+=("${mcu}")
done
}
function get_uart_id() {
unset mcu_list
sleep 1
mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty(AMA0|S0)$" 2>/dev/null)
for mcu in ${mcus}; do
mcu_list+=("${mcu}")
done
}
function show_flash_method_help() {
top_border
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
hr
echo -e "| ${cyan}Regular flashing method:${white} |"
echo -e "| The default method to flash controller boards which |"
echo -e "| are connected and updated over USB and not by placing |"
echo -e "| a compiled firmware file onto an internal SD-Card. |"
blank_line
echo -e "| Common controllers that get flashed that way are: |"
echo -e "| - Arduino Mega 2560 |"
echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |"
blank_line
echo -e "| ${cyan}Updating via SD-Card Update:${white} |"
echo -e "| Many popular controller boards ship with a bootloader |"
echo -e "| capable of updating the firmware via SD-Card. |"
echo -e "| Choose this method if your controller board supports |"
echo -e "| this way of updating. This method ONLY works for up- |"
echo -e "| grading firmware. The initial flashing procedure must |"
echo -e "| be done manually per the instructions that apply to |"
echo -e "| your controller board. |"
blank_line
echo -e "| Common controllers that can be flashed that way are: |"
echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |"
echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |"
echo -e "| - Fysetc Spider |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
B|b)
clear && print_header
init_flash_process
break;;
*)
error_msg "Invalid command!";;
esac
done
}
function show_mcu_connection_help() {
top_border
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
hr
echo -e "| ${cyan}USB:${white} |"
echo -e "| Selecting USB as the connection method will scan the |"
echo -e "| USB ports for connected controller boards. This will |"
echo -e "| be similar to the 'ls /dev/serial/by-id/*' command |"
echo -e "| suggested by the official Klipper documentation for |"
echo -e "| determining successfull USB connections! |"
blank_line
echo -e "| ${cyan}UART:${white} |"
echo -e "| Selecting UART as the connection method will list all |"
echo -e "| possible UART serial ports. Note: This method ALWAYS |"
echo -e "| returns something as it seems impossible to determine |"
echo -e "| if a valid Klipper controller board is connected or |"
echo -e "| not. Because of that, you ${red}MUST${white} know which UART serial |"
echo -e "| port your controller board is connected to when using |"
echo -e "| this connection method. |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
B|b)
clear && print_header
select_mcu_connection
break;;
*)
error_msg "Invalid command!";;
esac
done
}

421
scripts/fluidd.sh Normal file
View File

@@ -0,0 +1,421 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#================== INSTALL FLUIDD =================#
#===================================================#
function install_fluidd() {
### exit early if moonraker not found
if [[ -z $(moonraker_systemd) ]]; then
local error="Moonraker not installed! Please install Moonraker first!"
print_error "${error}" && return
fi
### checking dependencies
local dep=(wget nginx)
dependency_check "${dep[@]}"
### detect conflicting Haproxy and Apache2 installations
detect_conflicting_packages
status_msg "Initializing Fluidd installation ..."
### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir
### 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
### ask user to install mjpg-streamer
local install_mjpg_streamer
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
while true; do
echo
top_border
echo -e "| Install MJGP-Streamer for webcam support? |"
bottom_border
read -p "${cyan}###### Please select (y/N):${white} " yn
case "${yn}" in
Y|y|Yes|yes)
select_msg "Yes"
install_mjpg_streamer="true"
break;;
N|n|No|no|"")
select_msg "No"
install_mjpg_streamer="false"
break;;
*)
error_msg "Invalid command!";;
esac
done
fi
### download fluidd
download_fluidd
### ask user to install the recommended webinterface macros
install_fluidd_macros
### create /etc/nginx/conf.d/upstreams.conf
set_upstream_nginx_cfg
### create /etc/nginx/sites-available/<interface config>
set_nginx_cfg "fluidd"
### nginx on ubuntu 21 and above needs special permissions to access the files
set_nginx_permissions
### symlink nginx log
symlink_webui_nginx_log "fluidd"
### add fluidd to the update manager in moonraker.conf
patch_fluidd_update_manager
### install mjpg-streamer
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
fetch_webui_ports #WIP
### confirm message
print_confirm "Fluidd has been set up!"
}
function install_fluidd_macros() {
while true; do
echo
top_border
echo -e "| It is recommended to have some important macros in |"
echo -e "| your printer configuration to have Fluidd fully |"
echo -e "| functional and working. |"
blank_line
echo -e "| The recommended macros for Fluidd can be found here: |"
echo -e "| https://docs.fluidd.xyz/configuration/initial_setup |"
blank_line
echo -e "| If you already have these macros in your config file, |"
echo -e "| skip this step and answer with '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):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
download_fluidd_macros
break;;
N|n|No|no)
select_msg "No"
break;;
*)
print_error "Invalid command!";;
esac
done
return
}
function download_fluidd_macros() {
local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg"
local configs path
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
if [[ -n ${configs} ]]; then
for config in ${configs}; do
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
if [[ ! -f "${path}/fluidd.cfg" ]]; then
status_msg "Downloading fluidd.cfg to ${path} ..."
log_info "downloading fluidd.cfg to: ${path}"
wget "${fluidd_cfg}" -O "${path}/fluidd.cfg"
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
log_info "modify fluidd.cfg"
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg"
### write include to the very first line of the printer.cfg
if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then
log_info "modify printer.cfg"
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
fi
ok_msg "Done!"
fi
done
else
log_error "execution stopped! reason: no printer.cfg found"
return
fi
}
function download_fluidd() {
local url
url=$(get_fluidd_download_url)
status_msg "Downloading Fluidd from ${url} ..."
if [[ -d ${FLUIDD_DIR} ]]; then
rm -rf "${FLUIDD_DIR}"
fi
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
if wget "${url}"; then
ok_msg "Download complete!"
status_msg "Extracting archive ..."
unzip -q -o ./*.zip && ok_msg "Done!"
status_msg "Remove downloaded archive ..."
rm -rf ./*.zip && ok_msg "Done!"
else
print_error "Downloading Fluidd from\n ${url}\n failed!"
exit 1
fi
}
#===================================================#
#================== REMOVE FLUIDD ==================#
#===================================================#
function remove_fluidd_dir() {
[[ ! -d ${FLUIDD_DIR} ]] && return
status_msg "Removing Fluidd directory ..."
rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!"
}
function remove_fluidd_config() {
if [[ -e "/etc/nginx/sites-available/fluidd" ]]; then
status_msg "Removing Fluidd configuration for Nginx ..."
sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!"
fi
if [[ -L "/etc/nginx/sites-enabled/fluidd" ]]; then
status_msg "Removing Fluidd Symlink for Nginx ..."
sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!"
fi
}
function remove_fluidd_logs() {
local files
files=$(find /var/log/nginx -name "fluidd*" 2> /dev/null | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
sudo rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_fluidd_log_symlinks() {
local files
files=$(find "${KLIPPER_LOGS}" -name "fluidd*" 2> /dev/null | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_fluidd() {
remove_fluidd_dir
remove_fluidd_config
remove_fluidd_logs
remove_fluidd_log_symlinks
### remove fluidd_port from ~/.kiauh.ini
sed -i "/^fluidd_port=/d" "${INI_FILE}"
print_confirm "Fluidd successfully removed!"
}
#===================================================#
#================== UPDATE FLUIDD ==================#
#===================================================#
function update_fluidd() {
backup_before_update "fluidd"
status_msg "Updating Fluidd ..."
download_fluidd
match_nginx_configs
symlink_webui_nginx_log "fluidd"
print_confirm "Fluidd successfully updated!"
}
#===================================================#
#================== FLUIDD STATUS ==================#
#===================================================#
function get_fluidd_status() {
local status
local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd")
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]} )); then
status="Installed!"
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
fi
echo "${status}"
}
function get_local_fluidd_version() {
[[ ! -f "${FLUIDD_DIR}/.version" ]] && return
local version
version=$(head -n 1 "${FLUIDD_DIR}/.version")
echo "${version}"
}
function get_remote_fluidd_version() {
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
local version
version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev)
echo "${version}"
}
function compare_fluidd_versions() {
unset FLUIDD_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_fluidd_version)"
remote_ver="$(get_remote_fluidd_version)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add fluidd to the update all array for the update all function in the updater
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
FLUIDD_UPDATE_AVAIL="false"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function get_fluidd_download_url() {
local tags latest_tag latest_url stable_tag stable_url url
tags=$(curl -s "${FLUIDD_TAGS}" | grep "name" | cut -d'"' -f4)
### latest download url including pre-releases (alpha, beta, rc)
latest_tag=$(echo "${tags}" | head -1)
latest_url="https://github.com/fluidd-core/fluidd/releases/download/${latest_tag}/fluidd.zip"
### get stable fluidd download url
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip"
read_kiauh_ini "${FUNCNAME[0]}"
if [[ ${fluidd_install_unstable} == "true" ]]; then
url="${latest_url}"
echo "${url}"
else
url="${stable_url}"
echo "${url}"
fi
}
function fluidd_port_check() {
if [[ ${FLUIDD_ENABLED} == "false" ]]; then
if [[ ${SITE_ENABLED} == "true" ]]; then
status_msg "Detected other enabled interfaces:"
[[ ${MAINSAIL_ENABLED} == "true" ]] && \
echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}"
if [[ ${MAINSAIL_PORT} == "80" ]]; then
PORT_80_BLOCKED="true"
select_fluidd_port
fi
else
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/klipper_webui_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
}
function select_fluidd_port() {
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
echo
top_border
echo -e "| ${red}!!!WARNING!!!${white} |"
echo -e "| ${red}You need to choose a different port for Fluidd!${white} |"
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
blank_line
[[ ${MAINSAIL_PORT} == "80" ]] && echo "| ● Mainsail |"
blank_line
echo -e "| Make sure you don't choose a port which is already |"
echo -e "| assigned to another webinterface! |"
blank_line
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
echo -e "| input. So make sure to choose a valid port! |"
bottom_border
local new_port re="^[0-9]+$"
while true; do
read -p "${cyan}Please enter a new Port:${white} " new_port
if [[ ${new_port} =~ ${re} && ${new_port} != "${MAINSAIL_PORT}" ]]; then
select_msg "Setting port ${new_port} for Fluidd!"
SET_LISTEN_PORT=${new_port}
break
else
if [[ ! ${new_port} =~ ${re} ]]; then
error_msg "Invalid input!"
else
error_msg "Port already taken! Select a different one!"
fi
fi
done
fi
}
function patch_fluidd_update_manager() {
local moonraker_configs
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager fluidd\]$" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
### add Fluidds update manager section to moonraker.conf
status_msg "Adding Fluidd to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager fluidd]
type: web
channel: stable
repo: fluidd-core/fluidd
path: ~/fluidd
MOONRAKER_CONF
fi
done
}

View File

@@ -1,185 +0,0 @@
# setting up some frequently used functions
check_euid(){
if [ "$EUID" -eq 0 ]
then
echo -e "${red}"
echo -e "/=================================================\ "
echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |"
echo -e "\=================================================/ "
echo -e "${default}"
exit 1
fi
}
source_ini(){
source ${HOME}/kiauh2/kiauh.ini
}
start_klipper(){
if [ -e /etc/init.d/klipper ]; then
status_msg "Starting klipper service ..."
sudo /etc/init.d/klipper start && sleep 2 && ok_msg "Klipper service started!"
fi
}
stop_klipper(){
if [ -e /etc/init.d/klipper ]; then
status_msg "Stopping klipper service ..."
sudo /etc/init.d/klipper stop && sleep 2 && ok_msg "Klipper service stopped!"
fi
}
start_moonraker(){
if [ -e /etc/init.d/moonraker ]; then
status_msg "Starting moonraker service ..."
sudo /etc/init.d/moonraker start && sleep 2 && ok_msg "Moonraker service started!"
fi
}
stop_moonraker(){
if [ -e /etc/init.d/moonraker ]; then
status_msg "Stopping moonraker service ..."
sudo /etc/init.d/moonraker stop && sleep 2 && ok_msg "Moonraker service stopped!"
fi
}
dep_check(){
for package in "${dep[@]}"
do
! command -v $package >&/dev/null 2>&1 && install+=($package)
done
if ! [ ${#install[@]} -eq 0 ]; then
warn_msg "The following packages are missing but necessary:"
echo ${install[@]}
while true; do
read -p "Do you want to install them now? (Y/n): " yn
case "$yn" in
Y|y|Yes|yes|"")
status_msg "Installing dependencies ..."
sudo apt-get install ${install[@]} -y && ok_msg "Dependencies installed!"
break;;
N|n|No|no) break;;
*) echo "Unknown parameter: $yn"; echo;;
esac
done
fi
}
print_error(){
for data in "${data_arr[@]}"
do
if [ ! -e $data ]; then
data_count+=(0)
else
data_count+=(1)
fi
done
sum=$(IFS=+; echo "$((${data_count[*]}))")
if [ $sum -eq 0 ]; then
ERROR_MSG=" Looks like $1 was already removed!\n Skipping..."
else
ERROR_MSG=""
fi
}
pkg_check(){
status_msg "Checking if nginx is installed"
if [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
echo "nginx found!"
else
echo "nginx was not found, installing..." 2>&1
sudo apt-get -y install nginx 2>/dev/null
fi
}
build_fw(){
if [ -d $KLIPPER_DIR ]; then
cd $KLIPPER_DIR && make menuconfig
status_msg "Building firmware ..."
make clean && make && ok_msg "Firmware built!"
else
warn_msg "Can not build firmware without a Klipper directory!"
fi
}
### grab the printers id
get_usb_id(){
warn_msg "Make sure your printer is the only USB device connected!"
while true; do
echo -e "${cyan}"
read -p "###### Press any key to continue ... " yn
echo -e "${default}"
case "$yn" in
*) break;;
esac
done
status_msg "Identifying the correct USB port ..."
USB_ID=$(ls /dev/serial/by-id/*)
if [ -e /dev/serial/by-id/* ]; then
status_msg "The ID of your printer is:"
title_msg "$USB_ID"
else
warn_msg "Could not retrieve ID!"
return 1
fi
}
write_printer_id(){
while true; do
echo -e "${cyan}"
read -p "###### Do you want to write the ID to your printer.cfg? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"")
backup_printer_cfg
cat <<PRINTERID >> $PRINTER_CFG
##########################
### CREATED WITH KIAUH ###
##########################
[mcu]
serial: $USB_ID
##########################
##########################
PRINTERID
ok_msg "Config written!"
break;;
N|n|No|no) break;;
esac
done
}
flash_routine(){
echo -e "/=================================================\ "
echo -e "| ATTENTION! |"
echo -e "| Flashing a Smoothie based board for the first |"
echo -e "| time with this script will certainly fail. |"
echo -e "| This applies to boards like the BTT SKR V1.3 or |"
echo -e "| the newer SKR V1.4 (Turbo). You have to copy |"
echo -e "| the firmware file to the microSD card manually |"
echo -e "| and rename it to 'firmware.bin'. |"
echo -e "| |"
echo -e "| You find the file in: ~/klipper/out/klipper.bin |"
echo -e "\=================================================/ "
echo
while true; do
echo -e "${cyan}"
read -p "###### Do you want to continue? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"")
get_usb_id && flash_mcu && write_printer_id; break;;
N|n|No|no) break;;
esac
done
}
flash_mcu(){
stop_klipper
if ! make flash FLASH_DEVICE="$USB_ID" ; then
warn_msg "Flashing failed!"
warn_msg "Please read the log above!"
else
ok_msg "Flashing successfull!"
fi
start_klipper
}

View File

@@ -0,0 +1,122 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#=================================================#
#======== INSTALL GCODE_SHELL_COMMAND.PY =========#
#=================================================#
function setup_gcode_shell_command() {
top_border
echo -e "| You are about to install the 'G-Code Shell Command' |"
echo -e "| extension. Please make sure to read the instructions |"
echo -e "| before you continue and remember that potential risks |"
echo -e "| can be involved after installing this extension! |"
blank_line
echo -e "| ${red}You accept that you are doing this on your own risk!${white} |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
if [[ ! -d "${KLIPPER_DIR}/klippy/extras" ]]; then
print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?"
return
fi
status_msg "Installing gcode shell command extension ..."
if [[ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]]; then
install_gcode_shell_command
else
echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!"
while true; do
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py"
install_gcode_shell_command
break;;
N|n|No|no)
select_msg "No"
break;;
*)
error_msg "Invalid Input!";;
esac
done
fi
return;;
N|n|No|no)
select_msg "No"
return;;
*)
error_msg "Invalid Input!";;
esac
done
}
function install_gcode_shell_command() {
do_action_service "stop" "klipper"
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
if cp "${KIAUH_SRCDIR}/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then
ok_msg "Done!"
else
error_msg "Cannot copy file to target destination...Exiting!"
return 1
fi
local yn
while true; do
echo
read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
create_example_shell_command
break;;
N|n|No|no)
select_msg "No"
break;;
esac
done
do_action_service "restart" "klipper"
print_confirm "Shell command extension installed!"
return
}
function create_example_shell_command() {
### create a backup of the config folder
backup_klipper_config_dir
local printer_cfgs path
printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg" | sort)
for cfg in ${printer_cfgs}; do
path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev)
if [[ ! -f "${path}/shell_command.cfg" ]]; then
status_msg "Copy shell_command.cfg to ${path} ..."
cp "${KIAUH_SRCDIR}/resources/shell_command.cfg" "${path}"
ok_msg "${path}/shell_command.cfg created!"
### write include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" "${cfg}"
fi
done
}

73
scripts/globals.sh Normal file
View File

@@ -0,0 +1,73 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
# shellcheck disable=SC2034
set -e
function set_globals() {
#=================== SYSTEM ===================#
SYSTEMD="/etc/systemd/system"
INITD="/etc/init.d"
ETCDEF="/etc/default"
#=================== KIAUH ====================#
green=$(echo -en "\e[92m")
yellow=$(echo -en "\e[93m")
magenta=$(echo -en "\e[35m")
red=$(echo -en "\e[91m")
cyan=$(echo -en "\e[96m")
white=$(echo -en "\e[39m")
INI_FILE="${HOME}/.kiauh.ini"
LOGFILE="/tmp/kiauh.log"
RESOURCES="${KIAUH_SRCDIR}/resources"
BACKUP_DIR="${HOME}/kiauh-backups"
#================== KLIPPER ===================#
KLIPPY_ENV="${HOME}/klippy-env"
KLIPPER_DIR="${HOME}/klipper"
KLIPPER_REPO="https://github.com/Klipper3d/klipper.git"
KLIPPER_LOGS="${HOME}/klipper_logs"
KLIPPER_CONFIG="$(get_klipper_cfg_dir)" # default: ${HOME}/klipper_config
#================= MOONRAKER ==================#
MOONRAKER_ENV="${HOME}/moonraker-env"
MOONRAKER_DIR="${HOME}/moonraker"
MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
#================= MAINSAIL ===================#
MAINSAIL_DIR="${HOME}/mainsail"
MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases"
MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags"
#================== FLUIDD ====================#
FLUIDD_DIR="${HOME}/fluidd"
FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases"
FLUIDD_TAGS="https://api.github.com/repos/fluidd-core/fluidd/tags"
#=============== KLIPPERSCREEN ================#
KLIPPERSCREEN_ENV="${HOME}/.KlipperScreen-env"
KLIPPERSCREEN_DIR="${HOME}/KlipperScreen"
KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git"
#========== MOONRAKER-TELEGRAM-BOT ============#
TELEGRAM_BOT_ENV="${HOME}/moonraker-telegram-bot-env"
TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot"
TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git"
#=============== PRETTY-GCODE =================#
PGC_DIR="${HOME}/pgcode"
PGC_REPO="https://github.com/Kragrathea/pgcode"
#================== NGINX =====================#
NGINX_SA="/etc/nginx/sites-available"
NGINX_SE="/etc/nginx/sites-enabled"
NGINX_CONFD="/etc/nginx/conf.d"
}

View File

@@ -1,166 +0,0 @@
#TODO:
# - check for existing/running octoprint service
# - ask for permission to disable octoprint service
dwc2_install_routine(){
if [ -d $KLIPPER_DIR ]; then
# check for existing installation
if [ -d ${HOME}/klippy-env/lib/python2.7/site-packages/tornado ]; then
ERROR_MSG=" Looks like DWC2 is already installed!\n Skipping..."
return
fi
stop_klipper
install_tornado
install_dwc2fk && dwc2fk_cfg
install_dwc2
start_klipper
else
ERROR_MSG=" Please install Klipper first!\n Skipping..."
fi
}
install_tornado(){
#check for dependencies
dep=(virtualenv)
dep_check
#execute operation
status_msg "Installing Tornado 5.1.1 ..."
cd ${HOME}
PYTHONDIR="${HOME}/klippy-env"
virtualenv ${PYTHONDIR}
${PYTHONDIR}/bin/pip install tornado==5.1.1 && ok_msg "Tornado 5.1.1 successfully installed!"
}
install_dwc2fk(){
cd ${HOME}
status_msg "Cloning dwc2-for-klipper repository ..."
git clone $DWC2FK_REPO && ok_msg "dwc2-for-klipper successfully cloned!"
#create a web_dwc2.py symlink if not already existing
if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -e $KLIPPER_DIR/klippy/extras/web_dwc2.py ]; then
status_msg "Creating web_dwc2.py symlink ..."
ln -s $DWC2FK_DIR/web_dwc2.py $KLIPPER_DIR/klippy/extras/web_dwc2.py && ok_msg "Symlink created!"
fi
}
dwc2fk_cfg(){
while true; do
echo -e "${cyan}"
read -p "###### Do you want to create the config now? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"") create_dwc2fk_cfg; break;;
N|n|No|no) break;;
*) echo "Unknown parameter: $yn"; dwc2fk_cfg;;
esac
done
}
create_dwc2fk_cfg(){
echo -e "/=================================================\ "
echo -e "| 1) [Default configuration] | "
echo -e "| 2) [Custom configuration] | "
echo -e "| 3) [Skip] | "
echo -e "\=================================================/ "
while true; do
read -p "Please select: " choice; echo
case "$choice" in
1) dwc2fk_default_cfg && ok_msg "Config written ..."; break;;
2) create_dwc2fk_custom_cfg && ok_msg "Config written ..."; break;;
3) echo "Skipping ..."; break;;
esac
done
}
dwc2fk_default_cfg(){
cat <<DWC2 >> $PRINTER_CFG
##########################
### CREATED WITH KIAUH ###
##########################
[virtual_sdcard]
path: ~/sdcard
[web_dwc2]
printer_name: my_printer
listen_adress: 0.0.0.0
listen_port: 4750
web_path: dwc2/web
##########################
##########################
DWC2
}
create_dwc2fk_custom_cfg(){
echo -e "${cyan}"
read -e -p "Printer name: " -i "my_printer" PRINTER_NAME
read -e -p "Listen adress: " -i "0.0.0.0" LISTEN_ADRESS
read -e -p "Listen port: " -i "4750" LISTEN_PORT
read -e -p "Web path: " -i "dwc2/web" WEB_PATH
echo -e "${default}"
DWC2_CFG=$(cat <<DWC2
##########################
### CREATED WITH KIAUH ###
##########################
[virtual_sdcard]
path: ~/sdcard
[web_dwc2]
printer_name: $PRINTER_NAME
listen_adress: $LISTEN_ADRESS
listen_port: $LISTEN_PORT
web_path: $WEB_PATH
##########################
##########################
DWC2
)
echo "The following lines will be written:"
echo -e "$DWC2_CFG"
while true; do
echo -e "${cyan}"
read -p "###### Write now (Y) or start over (n)? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"") echo -e "$DWC2_CFG" >> $PRINTER_CFG; break;;
N|n|No|no) create_dwc2fk_custom_cfg;;
esac
done
}
install_dwc2(){
#needed packages for webcam
while true; do
echo -e "${cyan}"
read -p "###### Do you want to use a webcam? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"")
status_msg "Checking for dependencies ..."
webcam_dep_check && ok_msg "Dependencies installed!"
break;;
N|n|No|no) break;;
*) echo "Unknown parameter: $yn"; echo;;
esac
done
#the update_dwc2 function does the same as installing dwc2
update_dwc2 && ok_msg "DWC2 Web UI installed!"
}
webcam_dep_check(){
webcam_dep=(
build-essential
libjpeg8-dev
imagemagick
libv4l-dev
cmake
)
for pkg in "${webcam_dep[@]}"
do
if ! [[ $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then
install+=($pkg)
fi
done
if ! [ ${#install[@]} -eq 0 ]; then
sudo apt-get install ${install[@]} -y
fi
}

View File

@@ -1,30 +0,0 @@
install_klipper(){
if [ -e /etc/init.d/klipper ] && [ -e /etc/default/klipper ]; then
ERROR_MSG=" Looks like klipper is already installed!\n Skipping ..."
else
#check for dependencies
dep=(git)
dep_check
#execute operation
cd ${HOME}
status_msg "Cloning klipper repository ..."
git clone $KLIPPER_REPO && ok_msg "Klipper successfully cloned!"
status_msg "Installing klipper service ..."
$KLIPPER_DIR/scripts/install-octopi.sh && sleep 2 && ok_msg "Klipper installation complete!"
#create a klippy.log symlink in home-dir just for convenience
if [ ! -e ${HOME}/klippy.log ]; then
status_msg "Creating klippy.log symlink ..."
ln -s /tmp/klippy.log ${HOME}/klippy.log && ok_msg "Symlink created!"
fi
while true; do
echo -e "${cyan}"
read -p "###### Do you want to flash your MCU now? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"") build_fw && flash_routine; break;;
N|n|No|no) break;;
*) warn_msg "Unknown parameter: $yn"; echo;;
esac
done
fi
}

View File

@@ -1,349 +0,0 @@
mainsail_install_routine(){
if [ -d $KLIPPER_DIR ]; then
#check for dependencies
dep=(wget curl unzip)
dep_check
#execute operation
install_moonraker
disable_wrong_webserver
remove_wrong_webserver
install_nginx
test_api
test_nginx
install_mainsail && ok_msg "Mainsail install complete!"; echo
else
ERROR_MSG=" Please install Klipper first!\n Skipping..."
fi
}
install_moonraker(){
cd $KLIPPER_DIR
if [[ $(git describe --all) = "remotes/Arksine/work-web_server-20200131" ]]; then
status_msg "Installing Moonraker ..."
$KLIPPER_DIR/scripts/install-moonraker.sh && ok_msg "Moonraker successfully installed!"
if [ ! -d ${HOME}/sdcard ]; then
mkdir ${HOME}/sdcard
fi
#create a moonraker.log symlink in home-dir just for convenience
if [ ! -e ${HOME}/moonraker.log ]; then
status_msg "Creating moonraker.log symlink ..."
ln -s /tmp/moonraker.log ${HOME}/moonraker.log && ok_msg "Symlink created!"
fi
else
warn_msg "You are not using Arksine/work-web_server-20200131."
warn_msg "Please switch to the moonraker fork first!"
while true; do
echo -e "${cyan}"
read -p "###### Do you want to switch to it now? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"") switch_to_moonraker && install_moonraker; break;;
N|n|No|no) break;;
*) echo "Unknown parameter: $yn"; echo;;
esac
done
fi
}
check_printer_cfg(){
if [ ! -e $PRINTER_CFG ]; then
warn_msg "No printer.cfg found"
while true; do
echo -e "${cyan}"
read -p "###### Do you want to create a default config? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"") create_default_cfg; break;;
N|n|No|no) break;;
*) echo "Unknown parameter: $yn"; echo;;
esac
done
else
check_vsdcard_section
check_api_section
fi
}
disable_wrong_webserver(){
if systemctl is-active haproxy ; then
status_msg "Stopping haproxy service ..."
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
fi
if systemctl is-active lighttpd ; then
status_msg "Stopping lighttpd service ..."
sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!"
fi
}
remove_wrong_webserver(){
rem=(haproxy lighttpd)
for remove in "${rem[@]}"
do
if [[ $(dpkg-query -f'${Status}' --show $remove 2>/dev/null) = *\ installed ]]; then
delete+=($remove)
fi
done
if ! [ ${#delete[@]} -eq 0 ]; then
sudo apt-get remove ${delete[@]} -y
fi
}
install_nginx(){
if ! [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
status_msg "Installing Nginx ..."
sudo apt-get install nginx -y && ok_msg "Nginx successfully installed!"
fi
if [ ! -d $MAINSAIL_DIR ]; then
mkdir $MAINSAIL_DIR
fi
status_msg "Configure Nginx ..."
create_mainsail_cfgfile && sudo mv $MAINSAIL_DIR/mainsail /etc/nginx/sites-available/
if [ -e /etc/nginx/sites-enabled/default ]; then
sudo rm /etc/nginx/sites-enabled/default
fi
if [ ! -e /etc/nginx/sites-enabled/mainsail ]; then
sudo ln -s /etc/nginx/sites-available/mainsail /etc/nginx/sites-enabled/
fi
ok_msg "Nginx configured!"
}
test_api(){
status_msg "Testing API ..."
sleep 5
status_msg "API response from http://localhost:7125/printer/info:"
API_RESPONSE="$(curl -sG4 http://localhost:7125/printer/info)"
echo -e "${cyan}$API_RESPONSE${default}"
if [ $(curl -sG4 "http://localhost:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then
echo; ok_msg "Klipper API is working correctly!"; echo
else
echo; warn_msg "Klipper API not working correctly!"; echo
fi
}
test_nginx(){
sudo /etc/init.d/nginx restart
status_msg "Testing Nginx ..."
sleep 5
status_msg "API response from http://localhost/printer/info:"
API_RESPONSE="$(curl -sG4 http://localhost/printer/info)"
echo -e "${cyan}$API_RESPONSE${default}"
if [ $(curl -sG4 "http://localhost/printer/info" | grep '^{"result"' -c) -eq 1 ]; then
echo; ok_msg "Nginx is working correctly!"; echo
else
echo; warn_msg "Nginx is not working correctly!"; echo
fi
}
get_mainsail_ver(){
MAINSAIL_VERSION=`curl -s https://api.github.com/repositories/240875926/tags | grep name | cut -d'"' -f4 | cut -d"v" -f2 | head -1`
}
mainsail_dl_url(){
get_mainsail_ver
MAINSAIL_URL=https://github.com/meteyou/mainsail/releases/download/v"$MAINSAIL_VERSION"/mainsail-alpha-"$MAINSAIL_VERSION".zip
}
install_mainsail(){
mainsail_dl_url
if [ ! -d $MAINSAIL_DIR ]; then
mkdir $MAINSAIL_DIR
fi
cd $MAINSAIL_DIR
status_msg "Downloading Mainsail v$MAINSAIL_VERSION ..."
wget -q -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip
### write mainsail version to file for update check reasons
echo "$MAINSAIL_VERSION" > $MAINSAIL_DIR/version
}
create_mainsail_cfgfile(){
cat <<MAINSAIL_CFG > $MAINSAIL_DIR/mainsail
map \$http_upgrade \$connection_upgrade {
default upgrade;
'' close;
}
upstream apiserver {
#edit your api port here
ip_hash;
server 127.0.0.1:7125;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
access_log /var/log/nginx/mainsail-access.log;
error_log /var/log/nginx/mainsail-error.log;
#web_path from mainsail static files
root /home/pi/mainsail;
index index.html;
server_name _;
#max upload size for gcodes
client_max_body_size 200M;
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;
}
}
MAINSAIL_CFG
}
check_vsdcard_section(){
# check if virtual sdcard is present in printer.cfg
if [ $(grep '^\[virtual_sdcard\]$' /home/pi/printer.cfg) ]; then
echo "Virtual sdcard already configured"
else
echo "No virtual sdcard entry found..."
echo "Configuring virtual sdcard..."
# append the following lines to printer.cfg
cat <<VSDCARD >> $PRINTER_CFG
##########################
### CREATED WITH KIAUH ###
##########################
[virtual_sdcard]
path: ~/sdcard
##########################
##########################
VSDCARD
fi
}
check_api_section(){
# check if api server is present in printer.cfg
if [ $(grep '^\[api_server\]$' /home/pi/printer.cfg) ]; then
echo "API server already configured"
else
echo "No API server entry found..."
echo "Configuring API server..."
# append the following lines to printer.cfg
cat <<API >> $PRINTER_CFG
##########################
### CREATED WITH KIAUH ###
##########################
[api_server]
trusted_clients:
192.168.0.0/24
192.168.1.0/24
127.0.0.0/24
##########################
##########################
API
fi
}
create_default_cfg(){
cat <<MAINSAIL_CFG >> $PRINTER_CFG
##########################
### CREATED WITH KIAUH ###
##########################
[virtual_sdcard]
path: ~/sdcard
[api_server]
trusted_clients:
192.168.0.0/24
192.168.1.0/24
127.0.0.0/24
[pause_resume]
[gcode_macro CANCEL]
default_parameter_X: 230
default_parameter_Y: 230
default_parameter_Z: 10
gcode:
M104 S0
M140 S0
M141 S0
M106 S0
CLEAR_PAUSE
RESET_SD
[gcode_macro CANCEL_PRINT]
gcode:
CANCEL
[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
default_parameter_X: 230
default_parameter_Y: 230
default_parameter_Z: 10
gcode:
SAVE_GCODE_STATE NAME=PAUSE_state
BASE_PAUSE
G91
G1 E-1.7 F2100
G1 Z{Z}
G90
G1 X{X} Y{Y} F6000
G91
[gcode_macro RESUME]
rename_existing: BASE_RESUME
gcode:
G91
G1 E1.7 F2100
G91
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
BASE_RESUME
##########################
##########################
MAINSAIL_CFG
}

599
scripts/klipper.sh Normal file
View File

@@ -0,0 +1,599 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#=================================================#
#================ INSTALL KLIPPER ================#
#=================================================#
### check for existing klipper service installations
function klipper_initd() {
local services
services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*" | sort)
echo "${services}"
}
function klipper_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service" | sort)
echo "${services}"
}
function klipper_exists() {
local services
[[ -n $(klipper_initd) ]] && services+="$(klipper_initd) "
[[ -n $(klipper_systemd) ]] && services+="$(klipper_systemd)"
echo "${services}"
}
function klipper_setup_dialog() {
status_msg "Initializing Klipper installation ..."
local klipper_services
local python_version="${1}" user_input=()
klipper_services=$(klipper_exists)
user_input+=("${python_version}")
### return early if klipper already exists
if [[ -n ${klipper_services} ]]; then
local error="At least one Klipper service is already installed:"
for s in ${klipper_services}; do
log_info "Found Klipper service: ${s}"
error="${error}\n ➔ ${s}"
done
print_error "${error}" && return
fi
### ask for amount of instances to create
top_border
echo -e "| Please select the number of Klipper instances to set |"
echo -e "| up. The number of Klipper instances will determine |"
echo -e "| the amount of printers you can run from this host. |"
blank_line
echo -e "| ${yellow}WARNING:${white} |"
echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |"
bottom_border
### ask for amount of instances
local klipper_count re="^[1-9][0-9]*$"
while [[ ! ${klipper_count} =~ ${re} ]]; do
read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e klipper_count
### break if input is valid
[[ ${klipper_count} =~ ${re} ]] && break
### error messages on invalid input
error_msg "Input not a number"
done && select_msg "${klipper_count}"
user_input+=("${klipper_count}")
### confirm instance amount
local yn
while true; do
read -p "${cyan}###### Install ${klipper_count} instance(s)? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
break;;
N|n|No|no)
select_msg "No"
abort_msg "Exiting Klipper setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
### ask for custom names
if (( klipper_count > 1 )); then
local custom_names="false"
top_border
echo -e "| You can give each instance a custom name or skip. |"
echo -e "| If skipped, KIAUH will automatically assign an index |"
echo -e "| to each instance in ascending order, starting at '1'. |"
blank_line
echo -e "| Info: |"
echo -e "| Only alphanumeric characters will be allowed. |"
bottom_border
while true; do
read -p "${cyan}###### Use custom names? (y/N):${white} " yn
case "${yn}" in
Y|y|Yes|yes)
select_msg "Yes"
custom_names="true"
break;;
N|n|No|no|"")
select_msg "No"
break;;
*)
error_msg "Invalid Input!";;
esac
done
### get user input for custom names
if [[ ${custom_names} == "true" ]]; then
local i=1 name re="^[0-9a-zA-Z]+$"
while [[ ! ${name} =~ ${re} || ${i} -le ${klipper_count} ]]; do
read -p "${cyan}###### Name for instance #${i}:${white} " name
if [[ ${name} =~ ${re} ]]; then
select_msg "Name: ${name}"
user_input+=("${name}")
i=$(( i + 1 ))
else
error_msg "Invalid Input!"
fi
done
else
### if no custom names are used, add the respective amount of indices to the user_input array
for (( i=1; i <= klipper_count; i++ )); do
user_input+=("${i}")
done
fi
fi
(( klipper_count > 1 )) && status_msg "Installing ${klipper_count} Klipper instances ..."
(( klipper_count == 1 )) && status_msg "Installing single Klipper instance ..."
klipper_setup "${user_input[@]}"
}
function install_klipper_packages() {
local packages python_version="${1}"
local install_script="${KLIPPER_DIR}/scripts/install-debian.sh"
status_msg "Reading dependencies..."
# shellcheck disable=SC2016
packages=$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')
### add dfu-util for octopi-images
packages+=" dfu-util"
### add dbus requirement for DietPi distro
[[ -e "/boot/dietpi/.version" ]] && packages+=" dbus"
if [[ ${python_version} == "python3" ]]; then
### replace python-dev with python3-dev if python3 was selected
packages="${packages//python-dev/python3-dev}"
else
### package name 'python-dev' is deprecated (-> no installation candidate) on more modern linux distros
packages="${packages//python-dev/python2-dev}"
fi
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
### Update system package info
status_msg "Updating package lists..."
if ! sudo apt-get update --allow-releaseinfo-change; then
log_error "failure while updating package lists"
error_msg "Updating package lists failed!"
exit 1
fi
### Install required packages
status_msg "Installing required packages..."
if ! sudo apt-get install --yes "${packages[@]}"; then
log_error "failure while installing required klipper packages"
error_msg "Installing required packages failed!"
exit 1
fi
}
function create_klipper_virtualenv() {
local python_version="${1}"
[[ ${python_version} == "python2" ]] && \
status_msg "Installing $(python2 -V) virtual environment..."
[[ ${python_version} == "python3" ]] && \
status_msg "Installing $(python3 -V) virtual environment..."
### remove klippy-env if it already exists
[[ -d ${KLIPPY_ENV} ]] && rm -rf "${KLIPPY_ENV}"
if [[ ${python_version} == "python2" ]]; then
if virtualenv -p python2 "${KLIPPY_ENV}"; then
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
else
log_error "failure while creating python2 klippy-env"
error_msg "Creation of Klipper virtualenv failed!"
exit 1
fi
fi
if [[ ${python_version} == "python3" ]]; then
if virtualenv -p python3 "${KLIPPY_ENV}"; then
"${KLIPPY_ENV}"/bin/pip install -U pip
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
else
log_error "failure while creating python3 klippy-env"
error_msg "Creation of Klipper virtualenv failed!"
exit 1
fi
fi
return
}
function klipper_setup() {
read_kiauh_ini "${FUNCNAME[0]}"
### index 0: python version, index 1: instance count, index 2-n: instance names (optional)
local user_input=("${@}")
local python_version="${user_input[0]}" && unset "user_input[0]"
local instance_arr=("${user_input[@]}") && unset "user_input[@]"
local custom_repo="${custom_klipper_repo}"
local custom_branch="${custom_klipper_repo_branch}"
### checking dependencies
local dep=(git)
dependency_check "${dep[@]}"
### step 1: clone klipper
clone_klipper "${custom_repo}" "${custom_branch}"
### step 2: install klipper dependencies and create python virtualenv
install_klipper_packages "${python_version}"
create_klipper_virtualenv "${python_version}"
### step 3: create gcode_files and logs folder
[[ ! -d "${HOME}/gcode_files" ]] && mkdir -p "${HOME}/gcode_files"
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
### step 4: create klipper instances
create_klipper_service "${instance_arr[@]}"
### step 5: enable and start all instances
do_action_service "enable" "klipper"
do_action_service "start" "klipper"
### step 6: check for dialout group membership
check_usergroups
### confirm message
local confirm=""
(( instance_arr[0] == 1 )) && confirm="Klipper has been set up!"
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Klipper instances have been set up!"
print_confirm "${confirm}" && return
}
function clone_klipper() {
local repo=${1} branch=${2}
[[ -z ${repo} ]] && repo="${KLIPPER_REPO}"
repo=$(echo "${repo}" | sed -r "s/^(http|https):\/\/github\.com\///i; s/\.git$//")
repo="https://github.com/${repo}"
[[ -z ${branch} ]] && branch="master"
### force remove existing klipper dir and clone into fresh klipper dir
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
status_msg "Cloning Klipper from ${repo} ..."
cd "${HOME}" || exit 1
if git clone "${repo}" "${KLIPPER_DIR}"; then
cd "${KLIPPER_DIR}" && git checkout "${branch}"
else
print_error "Cloning Klipper from\n ${repo}\n failed!"
exit 1
fi
}
function write_klipper_service() {
local i=${1} cfg=${2} log=${3} printer=${4} uds=${5} service=${6}
local service_template="${KIAUH_SRCDIR}/resources/klipper.service"
### replace all placeholders
if [[ ! -f ${service} ]]; then
status_msg "Creating Klipper Service ${i} ..."
sudo cp "${service_template}" "${service}"
[[ -z ${i} ]] && sudo sed -i "s| for instance klipper-%INST%||" "${service}"
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${KLIPPY_ENV}|; s|%DIR%|${KLIPPER_DIR}|" "${service}"
sudo sed -i "s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${printer}|; s|%UDS%|${uds}|" "${service}"
fi
}
function write_example_printer_cfg() {
local cfg_dir=${1} cfg=${2}
local cfg_template="${KIAUH_SRCDIR}/resources/printer.cfg"
### create a config directory if it doesn't exist
if [[ ! -d ${cfg_dir} ]]; then
status_msg "Creating '${cfg_dir}' ..."
mkdir -p "${cfg_dir}"
fi
### create a minimal config if there is no printer.cfg
if [[ ! -f ${cfg} ]]; then
status_msg "Creating minimal example printer.cfg ..."
cp "${cfg_template}" "${cfg}"
fi
}
function create_klipper_service() {
local input=("${@}")
local klipper_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local cfg_dir cfg log printer uds service
if (( klipper_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
cfg_dir="${KLIPPER_CONFIG}"
cfg="${cfg_dir}/printer.cfg"
log="${KLIPPER_LOGS}/klippy.log"
printer="/tmp/printer"
uds="/tmp/klippy_uds"
service="${SYSTEMD}/klipper.service"
### write single instance service
write_klipper_service "" "${cfg}" "${log}" "${printer}" "${uds}" "${service}"
write_example_printer_cfg "${cfg_dir}" "${cfg}"
ok_msg "Klipper instance created!"
elif (( klipper_count >= 1 )) && [[ ${#names[@]} -gt 0 ]]; then
local j=0 re="^[1-9][0-9]*$"
for (( i=1; i <= klipper_count; i++ )); do
### overwrite config folder if name is only a number
if [[ ${names[j]} =~ ${re} ]]; then
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
else
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
fi
cfg="${cfg_dir}/printer.cfg"
log="${KLIPPER_LOGS}/klippy-${names[${j}]}.log"
printer="/tmp/printer-${names[${j}]}"
uds="/tmp/klippy_uds-${names[${j}]}"
service="${SYSTEMD}/klipper-${names[${j}]}.service"
### write multi instance service
write_klipper_service "${names[${j}]}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}"
write_example_printer_cfg "${cfg_dir}" "${cfg}"
ok_msg "Klipper instance 'klipper-${names[${j}]}' created!"
j=$(( j + 1 ))
done && unset j
else
return 1
fi
}
#================================================#
#================ REMOVE KLIPPER ================#
#================================================#
function remove_klipper_sysvinit() {
[[ ! -e "${INITD}/klipper" ]] && return
status_msg "Removing Klipper SysVinit service ..."
sudo systemctl stop klipper
sudo update-rc.d -f klipper remove
sudo rm -f "${INITD}/klipper" "${ETCDEF}/klipper"
ok_msg "Klipper SysVinit service removed!"
}
function remove_klipper_systemd() {
[[ -z $(klipper_systemd) ]] && return
status_msg "Removing Klipper Systemd Services ..."
for service in $(klipper_systemd | cut -d"/" -f5); do
status_msg "Removing ${service} ..."
sudo systemctl stop "${service}"
sudo systemctl disable "${service}"
sudo rm -f "${SYSTEMD}/${service}"
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Klipper Service removed!"
}
function remove_klipper_logs() {
local files regex="klippy(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_klipper_uds() {
local files
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_klipper_printer() {
local files
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_klipper_dir() {
[[ ! -d ${KLIPPER_DIR} ]] && return
status_msg "Removing Klipper directory ..."
rm -rf "${KLIPPER_DIR}"
ok_msg "Directory removed!"
}
function remove_klipper_env() {
[[ ! -d ${KLIPPY_ENV} ]] && return
status_msg "Removing klippy-env directory ..."
rm -rf "${KLIPPY_ENV}"
ok_msg "Directory removed!"
}
function remove_klipper() {
remove_klipper_sysvinit
remove_klipper_systemd
remove_klipper_logs
remove_klipper_uds
remove_klipper_printer
remove_klipper_dir
remove_klipper_env
local confirm="Klipper was successfully removed!"
print_confirm "${confirm}" && return
}
#================================================#
#================ UPDATE KLIPPER ================#
#================================================#
function update_klipper() {
read_kiauh_ini "${FUNCNAME[0]}"
local custom_repo="${custom_klipper_repo}"
local custom_branch="${custom_klipper_repo_branch}"
do_action_service "stop" "klipper"
if [[ ! -d ${KLIPPER_DIR} ]]; then
clone_klipper "${custom_repo}" "${custom_branch}"
else
backup_before_update "klipper"
status_msg "Updating Klipper ..."
cd "${KLIPPER_DIR}" && git pull
### read PKGLIST and install possible new dependencies
install_klipper_packages
### install possible new python dependencies
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt"
fi
ok_msg "Update complete!"
do_action_service "restart" "klipper"
}
#================================================#
#================ KLIPPER STATUS ================#
#================================================#
function get_klipper_status() {
local sf_count status py_ver
sf_count="$(klipper_systemd | wc -w)"
### detect an existing "legacy" klipper init.d installation
if [[ $(klipper_systemd | wc -w) -eq 0 ]] \
&& [[ $(klipper_initd | wc -w) -ge 1 ]]; then
sf_count=1
fi
py_ver=$(get_klipper_python_ver)
### remove the "SERVICE" entry from the data array if a klipper service is installed
local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}")
(( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]} )); then
if (( py_ver == 3 )); then
status="Installed: ${sf_count}(py${py_ver})"
else
status="Installed: ${sf_count}"
fi
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
fi
echo "${status}"
}
function get_local_klipper_commit() {
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
local commit
cd "${KLIPPER_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_klipper_commit() {
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
local commit
cd "${KLIPPER_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_klipper_versions() {
unset KLIPPER_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_klipper_commit)"
remote_ver="$(get_remote_klipper_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add klipper to the update all array for the update all function in the updater
KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
KLIPPER_UPDATE_AVAIL="false"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function get_klipper_cfg_dir() {
local cfg_dir
read_kiauh_ini "${FUNCNAME[0]}"
if [[ -z ${custom_klipper_cfg_loc} ]]; then
cfg_dir="${HOME}/klipper_config"
else
cfg_dir="${custom_klipper_cfg_loc}"
fi
echo "${cfg_dir}"
}
### returns the major python version the klippy-env was created with
function get_klipper_python_ver() {
[[ ! -d ${KLIPPY_ENV} ]] && return
local version
version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
echo "${version}"
}

230
scripts/klipperscreen.sh Normal file
View File

@@ -0,0 +1,230 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#============== INSTALL KLIPPERSCREEN ==============#
#===================================================#
function klipperscreen_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/KlipperScreen.service")
echo "${services}"
}
function install_klipperscreen() {
### return early if python version check fails
if [[ $(python3_check) == "false" ]]; then
local error="Versioncheck failed! Python 3.7 or newer required!\n"
error="${error} Please upgrade Python."
print_error "${error}" && return
fi
### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir
### install KlipperScreen
klipperscreen_setup
### add klipperscreen to the update manager in moonraker.conf
patch_klipperscreen_update_manager
do_action_service "restart" "KlipperScreen"
}
function klipperscreen_setup() {
local dep=(wget curl unzip dfu-util)
dependency_check "${dep[@]}"
status_msg "Cloning KlipperScreen from ${KLIPPERSCREEN_REPO} ..."
# force remove existing KlipperScreen dir
[[ -d ${KLIPPERSCREEN_DIR} ]] && rm -rf "${KLIPPERSCREEN_DIR}"
# clone into fresh KlipperScreen dir
cd "${HOME}" || exit 1
if ! git clone "${KLIPPERSCREEN_REPO}" "${KLIPPERSCREEN_DIR}"; then
print_error "Cloning KlipperScreen from\n ${KLIPPERSCREEN_REPO}\n failed!"
exit 1
fi
status_msg "Installing KlipperScreen ..."
if "${KLIPPERSCREEN_DIR}"/scripts/KlipperScreen-install.sh; then
ok_msg "KlipperScreen successfully installed!"
else
print_error "KlipperScreen installation failed!"
exit 1
fi
}
#===================================================#
#=============== REMOVE KLIPPERSCREEN ==============#
#===================================================#
function remove_klipperscreen() {
### remove KlipperScreen dir
if [[ -d ${KLIPPERSCREEN_DIR} ]]; then
status_msg "Removing KlipperScreen directory ..."
rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!"
fi
### remove KlipperScreen VENV dir
if [[ -d ${KLIPPERSCREEN_ENV} ]]; then
status_msg "Removing KlipperScreen VENV directory ..."
rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
fi
### remove KlipperScreen service
if [[ -e "${SYSTEMD}/KlipperScreen.service" ]]; then
status_msg "Removing KlipperScreen service ..."
do_action_service "stop" "KlipperScreen"
do_action_service "disable" "KlipperScreen"
sudo rm -f "${SYSTEMD}/KlipperScreen.service"
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "KlipperScreen Service removed!"
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_CONFIG}/KlipperScreen.log" ]]; then
status_msg "Removing KlipperScreen log symlink ..."
rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!"
fi
print_confirm "KlipperScreen successfully removed!"
}
#===================================================#
#=============== UPDATE KLIPPERSCREEN ==============#
#===================================================#
function update_klipperscreen() {
local old_md5
old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
do_action_service "stop" "KlipperScreen"
cd "${KLIPPERSCREEN_DIR}"
git pull origin master -q && ok_msg "Fetch successfull!"
git checkout -f master && ok_msg "Checkout successfull"
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
status_msg "New dependecies detected..."
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
ok_msg "Dependencies have been installed!"
fi
ok_msg "Update complete!"
do_action_service "start" "KlipperScreen"
}
#===================================================#
#=============== KLIPPERSCREEN STATUS ==============#
#===================================================#
function get_klipperscreen_status() {
local sf_count status
sf_count="$(klipperscreen_systemd | wc -w)"
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV}")
(( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]} )); then
status="Installed!"
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
fi
echo "${status}"
}
function get_local_klipperscreen_commit() {
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
local commit
cd "${KLIPPERSCREEN_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_klipperscreen_commit() {
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
local commit
cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_klipperscreen_versions() {
unset KLIPPERSCREEN_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_klipperscreen_commit)"
remote_ver="$(get_remote_klipperscreen_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add klipperscreen to the update all array for the update all function in the updater
KLIPPERSCREEN_UPDATE_AVAIL="true" && update_arr+=(update_klipperscreen)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
KLIPPERSCREEN_UPDATE_AVAIL="false"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function patch_klipperscreen_update_manager() {
local moonraker_configs
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager KlipperScreen\]$" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
### add KlipperScreens update manager section to moonraker.conf
status_msg "Adding KlipperScreen to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager KlipperScreen]
type: git_repo
path: ${HOME}/KlipperScreen
origin: https://github.com/jordanruthe/KlipperScreen.git
env: ${HOME}/.KlipperScreen-env/bin/python
requirements: scripts/KlipperScreen-requirements.txt
install_script: scripts/KlipperScreen-install.sh
MOONRAKER_CONF
fi
done
}

577
scripts/mainsail.sh Normal file
View File

@@ -0,0 +1,577 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#================= INSTALL MAINSAIL ================#
#===================================================#
function install_mainsail() {
### exit early if moonraker not found
if [[ -z $(moonraker_systemd) ]]; then
local error="Moonraker not installed! Please install Moonraker first!"
print_error "${error}" && return
fi
### checking dependencies
local dep=(wget nginx)
dependency_check "${dep[@]}"
### detect conflicting Haproxy and Apache2 installations
detect_conflicting_packages
status_msg "Initializing Mainsail installation ..."
### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir
### check for other enabled web interfaces
unset SET_LISTEN_PORT
detect_enabled_sites
### check if another site already listens to port 80
mainsail_port_check
### ask user to install mjpg-streamer
local install_mjpg_streamer
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
while true; do
echo
top_border
echo -e "| Install MJGP-Streamer for webcam support? |"
bottom_border
read -p "${cyan}###### Please select (y/N):${white} " yn
case "${yn}" in
Y|y|Yes|yes)
select_msg "Yes"
install_mjpg_streamer="true"
break;;
N|n|No|no|"")
select_msg "No"
install_mjpg_streamer="false"
break;;
*)
error_msg "Invalid command!";;
esac
done
fi
### download mainsail
download_mainsail
### ask user to install the recommended webinterface macros
install_mainsail_macros
### create /etc/nginx/conf.d/upstreams.conf
set_upstream_nginx_cfg
### create /etc/nginx/sites-available/<interface config>
set_nginx_cfg "mainsail"
### nginx on ubuntu 21 and above needs special permissions to access the files
set_nginx_permissions
### symlink nginx log
symlink_webui_nginx_log "mainsail"
### add mainsail to the update manager in moonraker.conf
patch_mainsail_update_manager
### install mjpg-streamer
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
fetch_webui_ports #WIP
### confirm message
print_confirm "Mainsail has been set up!"
}
function install_mainsail_macros() {
while true; do
echo
top_border
echo -e "| It is recommended to have some important macros in |"
echo -e "| your printer configuration to have Mainsail fully |"
echo -e "| functional and working. |"
blank_line
echo -e "| The recommended macros for Mainsail can be seen here: |"
echo -e "| https://docs.mainsail.xyz/configuration#macros |"
blank_line
echo -e "| If you already have these macros in your config file, |"
echo -e "| skip this step and answer with '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):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
download_mainsail_macros
break;;
N|n|No|no)
select_msg "No"
break;;
*)
print_error "Invalid command!";;
esac
done
return
}
function download_mainsail_macros() {
local ms_cfg="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mainsail/filesystem/home/pi/klipper_config/mainsail.cfg"
local configs path
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
if [[ -n ${configs} ]]; then
for config in ${configs}; do
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
if [[ ! -f "${path}/mainsail.cfg" ]]; then
status_msg "Downloading mainsail.cfg to ${path} ..."
log_info "downloading mainsail.cfg to: ${path}"
wget "${ms_cfg}" -O "${path}/mainsail.cfg"
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
log_info "modify mainsail.cfg"
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg"
### write include to the very first line of the printer.cfg
if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then
log_info "modify printer.cfg"
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
fi
ok_msg "Done!"
fi
done
else
log_error "execution stopped! reason: no printer.cfg found"
return
fi
}
function download_mainsail() {
local url
url=$(get_mainsail_download_url)
status_msg "Downloading Mainsail from ${url} ..."
if [[ -d ${MAINSAIL_DIR} ]]; then
rm -rf "${MAINSAIL_DIR}"
fi
mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}"
if wget "${url}"; then
ok_msg "Download complete!"
status_msg "Extracting archive ..."
unzip -q -o ./*.zip && ok_msg "Done!"
status_msg "Remove downloaded archive ..."
rm -rf ./*.zip && ok_msg "Done!"
else
print_error "Downloading Mainsail from\n ${url}\n failed!"
exit 1
fi
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode
if [[ $(moonraker_systemd | wc -w) -gt 1 ]]; then
enable_mainsail_remotemode
fi
}
#===================================================#
#================= REMOVE MAINSAIL =================#
#===================================================#
function remove_mainsail_dir() {
[[ ! -d ${MAINSAIL_DIR} ]] && return
status_msg "Removing Mainsail directory ..."
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
}
function remove_mainsail_config() {
if [[ -e "/etc/nginx/sites-available/mainsail" ]]; then
status_msg "Removing Mainsail configuration for Nginx ..."
sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!"
fi
if [[ -L "/etc/nginx/sites-enabled/mainsail" ]]; then
status_msg "Removing Mainsail Symlink for Nginx ..."
sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!"
fi
}
function remove_mainsail_logs() {
local files
files=$(find /var/log/nginx -name "mainsail*" 2> /dev/null | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
sudo rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_mainsail_log_symlinks() {
local files
files=$(find "${KLIPPER_LOGS}" -name "mainsail*" 2> /dev/null | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_mainsail() {
remove_mainsail_dir
remove_mainsail_config
remove_mainsail_logs
remove_mainsail_log_symlinks
### remove mainsail_port from ~/.kiauh.ini
sed -i "/^mainsail_port=/d" "${INI_FILE}"
print_confirm "Mainsail successfully removed!"
}
#===================================================#
#================= UPDATE MAINSAIL =================#
#===================================================#
function update_mainsail() {
backup_before_update "mainsail"
status_msg "Updating Mainsail ..."
download_mainsail
match_nginx_configs
symlink_webui_nginx_log "mainsail"
print_confirm "Mainsail successfully updated!"
}
#===================================================#
#================= MAINSAIL STATUS =================#
#===================================================#
function get_mainsail_status() {
local status
local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail")
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]} )); then
status="Installed!"
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
fi
echo "${status}"
}
function get_local_mainsail_version() {
[[ ! -f "${MAINSAIL_DIR}/.version" ]] && return
local version
version=$(head -n 1 "${MAINSAIL_DIR}/.version")
echo "${version}"
}
function get_remote_mainsail_version() {
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
local version
version=$(get_mainsail_download_url | rev | cut -d"/" -f2 | rev)
echo "${version}"
}
function compare_mainsail_versions() {
unset MAINSAIL_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_mainsail_version)"
remote_ver="$(get_remote_mainsail_version)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add mainsail to the update all array for the update all function in the updater
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
MAINSAIL_UPDATE_AVAIL="false"
fi
echo "${versions}"
}
#================================================#
#=========== MAINSAIL THEME INSTALLER ===========#
#================================================#
function print_theme_list() {
local i=0 theme_list=${1}
while IFS="," read -r col1 col2 col3 col4; do
if [[ ${col1} != "name" ]]; then
printf "| ${i}) %-51s|\n" "[${col1}]"
fi
i=$(( i + 1 ))
done <<< "${theme_list}"
}
function ms_theme_installer_menu() {
local theme_list theme_author theme_repo theme_name theme_note theme_url
local theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv"
theme_list=$(curl -s -L "${theme_csv_url}")
top_border
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} |"
hr
echo -e "| ${cyan}A preview of each Mainsail theme can be found here:${white} |"
echo -e "| https://docs.mainsail.xyz/theming/themes |"
blank_line
echo -e "| ${yellow}Important note:${white} |"
echo -e "| Installing a theme from this menu will overwrite an |"
echo -e "| already installed theme or modified custom.css file! |"
hr
print_theme_list "${theme_list}"
echo -e "| |"
echo -e "| R) [Remove Theme] |"
back_footer
while IFS="," read -r col1 col2 col3 col4; do
theme_name+=("${col1}")
theme_note+=("${col2}")
theme_author+=("${col3}")
theme_repo+=("${col4}")
done <<< "${theme_list}"
local option
while true; do
read -p "${cyan}Install theme:${white} " option
if (( option > 0 && option < ${#theme_name[@]} )); then
theme_url="https://github.com/${theme_author[${option}]}/${theme_repo[${option}]}"
ms_theme_install "${theme_url}" "${theme_name[${option}]}" "${theme_note[${option}]}"
break
elif [[ ${option} == "R" || ${option} == "r" ]]; then
ms_theme_delete
break
elif [[ ${option} == "B" || ${option} == "b" ]]; then
advanced_menu
break
else
error_msg "Invalid command!"
fi
done
ms_theme_installer_menu
}
function ms_theme_install() {
local theme_url=${1} theme_name theme_note
theme_name=${2} theme_note=${3}
local config_folders target_folders=()
config_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -maxdepth 1 -type d | sort)
### build target folder array
for folder in ${config_folders}; do
target_folders+=("${folder}")
done
if (( ${#target_folders[@]} > 1 )); then
top_border
echo -e "| Please select the printer you want to apply the theme |"
echo -e "| installation to: |"
for (( i=0; i < ${#target_folders[@]}; i++ )); do
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f1 | rev)
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
done
bottom_border
local target re="^[0-9]*$"
while true; do
read -p "${cyan}###### Select printer:${white} " target
### break while loop if input is valid, else display error
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
error_msg "Invalid command!"
done
fi
[[ -d "${target_folders[${target}]}/.theme" ]] && rm -rf "${target_folders[${target}]}/.theme"
status_msg "Installing '${theme_name}' to ${target_folders[${target}]} ..."
cd "${target_folders[${target}]}"
if git clone "${theme_url}" ".theme"; then
ok_msg "Theme installation complete!"
[[ -n ${theme_note} ]] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
ok_msg "Please remember to delete your browser cache!\n"
else
error_msg "Theme installation failed!\n"
fi
}
function ms_theme_delete() {
local theme_folders target_folders=()
theme_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -type d -name ".theme" | sort)
### build target folder array
for folder in ${theme_folders}; do
target_folders+=("${folder}")
done
if (( ${#target_folders[@]} > 0 )); then
top_border
echo -e "| Please select the printer you want to remove the |"
echo -e "| theme installation from. |"
for (( i=0; i < ${#target_folders[@]}; i++ )); do
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f2 | rev)
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
done
bottom_border
local target re="^[0-9]*$"
while true; do
read -p "${cyan}###### Select printer:${white} " target
### break while loop if input is valid, else display error
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
error_msg "Invalid command!"
done
else
status_msg "No Themes installed!\n"
return
fi
status_msg "Removing ${target_folders[${target}]} ..."
rm -rf "${target_folders[${target}]}" && ok_msg "Theme removed!\n"
return
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function get_mainsail_download_url() {
local tags latest_tag latest_url stable_tag stable_url url
tags=$(curl -s "${MAINSAIL_TAGS}" | grep "name" | cut -d'"' -f4)
### latest download url including pre-releases (alpha, beta, rc)
latest_tag=$(echo "${tags}" | head -1)
latest_url="https://github.com/mainsail-crew/mainsail/releases/download/${latest_tag}/mainsail.zip"
### get stable mainsail download url
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip"
read_kiauh_ini "${FUNCNAME[0]}"
if [[ ${mainsail_install_unstable} == "true" ]]; then
url="${latest_url}"
echo "${url}"
else
url="${stable_url}"
echo "${url}"
fi
}
function mainsail_port_check() {
if [[ ${MAINSAIL_ENABLED} == "false" ]]; then
if [[ ${SITE_ENABLED} == "true" ]]; then
status_msg "Detected other enabled interfaces:"
[[ ${FLUIDD_ENABLED} == "true" ]] && \
echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${white}"
if [[ ${FLUIDD_PORT} == "80" ]]; then
PORT_80_BLOCKED="true"
select_mainsail_port
fi
else
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/klipper_webui_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
}
function select_mainsail_port() {
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
echo
top_border
echo -e "| ${red}!!!WARNING!!!${white} |"
echo -e "| ${red}You need to choose a different port for Mainsail!${white} |"
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
blank_line
[[ ${FLUIDD_PORT} == "80" ]] && echo "| ● Fluidd |"
blank_line
echo -e "| Make sure you don't choose a port which was already |"
echo -e "| assigned to another webinterface! |"
blank_line
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
echo -e "| input. So make sure to choose a valid port! |"
bottom_border
local new_port re="^[0-9]+$"
while true; do
read -p "${cyan}Please enter a new Port:${white} " new_port
if [[ ${new_port} =~ ${re} && ${new_port} != "${FLUIDD_PORT}" ]]; then
select_msg "Setting port ${new_port} for Mainsail!"
SET_LISTEN_PORT=${new_port}
break
else
if [[ ! ${new_port} =~ ${re} ]]; then
error_msg "Invalid input!"
else
error_msg "Port already taken! Select a different one!"
fi
fi
done
fi
}
function enable_mainsail_remotemode() {
[[ ! -f "${MAINSAIL_DIR}/config.json" ]] && return
rm -f "${MAINSAIL_DIR}/config.json"
echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json"
}
function patch_mainsail_update_manager() {
local moonraker_configs
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager mainsail\]$" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
### add Mainsails update manager section to moonraker.conf
status_msg "Adding Mainsail to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager mainsail]
type: web
channel: stable
repo: mainsail-crew/mainsail
path: ~/mainsail
MOONRAKER_CONF
fi
done
}

193
scripts/mjpg-streamer.sh Normal file
View File

@@ -0,0 +1,193 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#=================================================#
#============= INSTALL MJPG-STREAMER =============#
#=================================================#
function install_mjpg-streamer() {
local webcamd="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
local webcam_txt="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
local repo="https://github.com/jacksonliam/mjpg-streamer.git"
local service="${KIAUH_SRCDIR}/resources/webcamd.service"
### return early if webcamd.service already exists
if [[ -f "${SYSTEMD}/webcamd.service" ]]; then
print_error "Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
return
fi
status_msg "Initializing MJPG-Streamer installation ..."
### check and install dependencies if missing
local dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg)
if apt-cache search libjpeg62-turbo-dev | grep -Eq "^libjpeg62-turbo-dev "; then
dep+=(libjpeg62-turbo-dev)
elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then
dep+=(libjpeg8-dev)
fi
dependency_check "${dep[@]}"
### step 1: clone mjpg-streamer
status_msg "Cloning MJPG-Streamer from ${repo} ..."
[[ -d "${HOME}/mjpg-streamer" ]] && rm -rf "${HOME}/mjpg-streamer"
cd "${HOME}" || exit 1
if ! git clone "${repo}" "${HOME}/mjpg-streamer"; then
print_error "Cloning MJPG-Streamer from\n ${repo}\n failed!"
exit 1
fi
ok_msg "Cloning complete!"
### step 2: compiling mjpg-streamer
status_msg "Compiling MJPG-Streamer ..."
cd "${HOME}/mjpg-streamer/mjpg-streamer-experimental"
if ! make; then
print_error "Compiling MJPG-Streamer failed!"
exit 1
fi
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}" -O "/usr/local/bin/webcamd"
sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /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_CONFIG} ]] && mkdir -p "${KLIPPER_CONFIG}"
if [[ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]]; then
status_msg "Creating webcam.txt config file ..."
wget "${webcam_txt}" -O "${KLIPPER_CONFIG}/webcam.txt"
ok_msg "Done!"
fi
### step 5: create systemd service
status_msg "Creating MJPG-Streamer service ..."
sudo cp "${service}" "${SYSTEMD}/webcamd.service"
sudo sed -i "s|%USER%|${USER}|" "${SYSTEMD}/webcamd.service"
ok_msg "MJPG-Streamer service created!"
### step 6: enabling and starting mjpg-streamer service
status_msg "Starting MJPG-Streamer service, please wait ..."
sudo systemctl enable webcamd.service
if sudo systemctl start webcamd.service; then
ok_msg "MJPG-Streamer service started!"
else
status_msg "MJPG-Streamer service couldn't be started! No webcam connected?\n###### You need to manually restart the service once your webcam is set up correctly."
fi
### step 6.1: create webcamd.log symlink
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
if [[ -f "/var/log/webcamd.log" && ! -L "${KLIPPER_LOGS}/webcamd.log" ]]; then
ln -s "/var/log/webcamd.log" "${KLIPPER_LOGS}/webcamd.log"
fi
### step 6.2: add webcamd.log logrotate
if [[ ! -f "/etc/logrotate.d/webcamd" ]]; then
status_msg "Create logrotate rule ..."
sudo /bin/sh -c "cat > /etc/logrotate.d/webcamd" << EOF
/var/log/webcamd.log
{
rotate 2
weekly
maxsize 32M
missingok
notifempty
compress
delaycompress
sharedscripts
}
EOF
ok_msg "Done!"
fi
### step 7: check if user is in group "video"
local usergroup_changed="false"
if ! groups "${USER}" | grep -q "video"; then
status_msg "Adding user '${USER}' to group 'video' ..."
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
usergroup_changed="true"
fi
### confirm message
local confirm_msg="MJPG-Streamer has been set up!"
if [[ ${usergroup_changed} == "true" ]]; then
confirm_msg="${confirm_msg}\n ${yellow}INFO: Your User was added to a new group!${green}"
confirm_msg="${confirm_msg}\n ${yellow}You need to relog/restart for the group to be applied!${green}"
fi
print_confirm "${confirm_msg}"
### print webcam ip adress/url
local ip
ip=$(hostname -I | cut -d" " -f1)
local cam_url="http://${ip}:8080/?action=stream"
local cam_url_alt="http://${ip}/webcam/?action=stream"
echo -e " ${cyan}● Webcam URL:${white} ${cam_url}"
echo -e " ${cyan}● Webcam URL:${white} ${cam_url_alt}"
echo
}
#=================================================#
#============== REMOVE MJPG-STREAMER =============#
#=================================================#
function remove_mjpg-streamer() {
### remove MJPG-Streamer service
if [[ -e "${SYSTEMD}/webcamd.service" ]]; then
status_msg "Removing MJPG-Streamer service ..."
sudo systemctl stop webcamd && sudo systemctl disable webcamd
sudo rm -f "${SYSTEMD}/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 "${KLIPPER_LOGS}/webcamd.log" ]] && rm -f "${KLIPPER_LOGS}/webcamd.log"
print_confirm "MJPG-Streamer successfully removed!"
}

View File

@@ -0,0 +1,486 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#========== INSTALL MOONRAKERTELEGRAMBOT ===========#
#===================================================#
function telegram_bot_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[0-9a-zA-Z]+)?.service" | sort)
echo "${services}"
}
function telegram_bot_setup_dialog() {
### return early if moonraker is not installed
local moonraker_services
moonraker_services=$(moonraker_systemd)
if [[ -z ${moonraker_services} ]]; then
local error="Moonraker not installed! Please install Moonraker first!"
print_error "${error}" && return
fi
status_msg "Initializing Telegram Bot installation ..."
### first, we create a backup of the full klipper_config dir - safety first!
backup_klipper_config_dir
local moonraker_count user_input=() moonraker_names=()
moonraker_count=$(echo "${moonraker_services}" | wc -w )
for service in ${moonraker_services}; do
moonraker_names+=( "$(get_instance_name "${service}")" )
done
local telegram_bot_count
if (( moonraker_count == 1 )); then
ok_msg "Moonraker installation found!\n"
telegram_bot_count=1
elif (( moonraker_count > 1 )); then
top_border
printf "|${green}%-55s${white}|\n" " ${moonraker_count} Moonraker instances found!"
for name in "${moonraker_names[@]}"; do
printf "|${cyan}%-57s${white}|\n" "${name}"
done
blank_line
echo -e "| The setup will apply the same names to Telegram Bot! |"
blank_line
echo -e "| Please select the number of Telegram Bot instances to |"
echo -e "| install. Usually one Telegram Bot instance per |"
echo -e "| Moonraker instance is required, but you may not |"
echo -e "| install more Telegram Bot instances than available |"
echo -e "| Moonraker instances. |"
bottom_border
### ask for amount of instances
local re="^[1-9][0-9]*$"
while [[ ! ${telegram_bot_count} =~ ${re} || ${telegram_bot_count} -gt ${moonraker_count} ]]; do
read -p "${cyan}###### Number of Telegram Bot instances to set up:${white} " -i "${moonraker_count}" -e telegram_bot_count
### break if input is valid
[[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]] && break
### conditional error messages
[[ ! ${telegram_bot_count} =~ ${re} ]] && error_msg "Input not a number"
(( telegram_bot_count > moonraker_count )) && error_msg "Number of Telegram Bot instances larger than existing Moonraker instances"
done && select_msg "${telegram_bot_count}"
else
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
return 1
fi
user_input+=("${telegram_bot_count}")
### confirm instance amount
local yn
while true; do
(( telegram_bot_count == 1 )) && local question="Install Telegram Bot?"
(( telegram_bot_count > 1 )) && local question="Install ${telegram_bot_count} Telegram Bot instances?"
read -p "${cyan}###### ${question} (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
break;;
N|n|No|no)
select_msg "No"
abort_msg "Exiting Telegram Bot setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
### write existing klipper names into user_input array to use them as names for moonraker
if (( moonraker_count > 1 )); then
for name in "${moonraker_names[@]}"; do
user_input+=("${name}")
done
fi
(( telegram_bot_count > 1 )) && status_msg "Installing ${telegram_bot_count} Telegram Bot instances ..."
(( telegram_bot_count == 1 )) && status_msg "Installing Telegram Bot ..."
telegram_bot_setup "${user_input[@]}"
}
function install_telegram_bot_dependencies() {
local packages
local install_script="${TELEGRAM_BOT_DIR}/scripts/install.sh"
### read PKGLIST from official install-script
status_msg "Reading dependencies..."
# shellcheck disable=SC2016
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
### Update system package info
status_msg "Updating package lists..."
if ! sudo apt-get update --allow-releaseinfo-change; then
log_error "failure while updating package lists"
error_msg "Updating package lists failed!"
exit 1
fi
### Install required packages
status_msg "Installing required packages..."
if ! sudo apt-get install --yes "${packages[@]}"; then
log_error "failure while installing required moonraker-telegram-bot packages"
error_msg "Installing required packages failed!"
exit 1
fi
}
function create_telegram_bot_virtualenv() {
status_msg "Installing python virtual environment..."
### always create a clean virtualenv
[[ -d ${TELEGRAM_BOT_ENV} ]] && rm -rf "${TELEGRAM_BOT_ENV}"
if virtualenv -p /usr/bin/python3 --system-site-packages "${TELEGRAM_BOT_ENV}"; then
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
else
log_error "failure while creating python3 moonraker-telegram-bot-env"
error_msg "Creation of Moonraker Telegram Bot virtualenv failed!"
exit 1
fi
}
function telegram_bot_setup() {
local instance_arr=("${@}")
### checking dependencies
local dep=(git virtualenv)
dependency_check "${dep[@]}"
### step 1: clone telegram bot
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
### step 2: install telegram bot dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_telegram_bot_dependencies
create_telegram_bot_virtualenv
### step 3: create telegram.conf
create_telegram_conf "${instance_arr[@]}"
### step 4: create telegram bot instances
create_telegram_bot_service "${instance_arr[@]}"
### step 5: add telegram-bot to the update manager in moonraker.conf
patch_telegram_bot_update_manager
### step 6: enable and start all instances
do_action_service "enable" "moonraker-telegram-bot"
do_action_service "start" "moonraker-telegram-bot"
### confirm message
local confirm=""
(( instance_arr[0] == 1 )) && confirm="Telegram Bot has been set up!"
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Telegram Bot instances have been set up!"
print_confirm "${confirm}" && return
}
function clone_telegram_bot() {
local repo=${1}
status_msg "Cloning Moonraker-Telegram-Bot from ${repo} ..."
### force remove existing Moonraker-Telegram-Bot dir
[[ -d ${repo} ]] && rm -rf "${TELEGRAM_BOT_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${repo}" "${TELEGRAM_BOT_DIR}"; then
print_error "Cloning Moonraker-Telegram-Bot from\n ${repo}\n failed!"
exit 1
fi
}
function create_telegram_conf() {
local input=("${@}")
local telegram_bot_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local log="${KLIPPER_LOGS}"
local cfg cfg_dir
if (( telegram_bot_count == 1 )); then
cfg_dir="${KLIPPER_CONFIG}"
cfg="${cfg_dir}/telegram.conf"
### write single instance config
write_telegram_conf "${cfg_dir}" "${cfg}" "${log}"
elif (( telegram_bot_count > 1 )); then
local j=0 re="^[1-9][0-9]*$"
for (( i=1; i <= telegram_bot_count; i++ )); do
### overwrite config folder if name is only a number
if [[ ${names[j]} =~ ${re} ]]; then
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
else
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
fi
cfg="${cfg_dir}/telegram.conf"
### write multi instance config
write_telegram_conf "${cfg_dir}" "${cfg}" "${log}"
j=$(( j + 1 ))
done && unset j
else
return 1
fi
}
function write_telegram_conf() {
local cfg_dir=${1} cfg=${2} log=${3}
local conf_template="${TELEGRAM_BOT_DIR}/scripts/base_install_template"
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
if [[ ! -f ${cfg} ]]; then
status_msg "Creating telegram.conf in ${cfg_dir} ..."
cp "${conf_template}" "${cfg}"
sed -i "s|some_log_path|${log}|g" "${cfg}"
ok_msg "telegram.conf created!"
else
status_msg "File '${cfg}' already exists!\nSkipping..."
fi
}
function create_telegram_bot_service() {
local input=("${@}")
local instances=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local cfg_dir cfg log service
if (( instances == 1 )); then
cfg_dir="${KLIPPER_CONFIG}"
cfg="${cfg_dir}/telegram.conf"
log="${KLIPPER_LOGS}/telegram.log"
service="${SYSTEMD}/moonraker-telegram-bot.service"
### write single instance service
write_telegram_bot_service "" "${cfg}" "${log}" "${service}"
ok_msg "Single Telegram Bot instance created!"
elif (( instances > 1 )); then
local j=0 re="^[1-9][0-9]*$"
for (( i=1; i <= instances; i++ )); do
### overwrite config folder if name is only a number
if [[ ${names[j]} =~ ${re} ]]; then
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
else
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
fi
cfg="${cfg_dir}/telegram.conf"
log="${KLIPPER_LOGS}/telegram-${names[${j}]}.log"
service="${SYSTEMD}/moonraker-telegram-bot-${names[${j}]}.service"
### write multi instance service
write_telegram_bot_service "${names[${j}]}" "${cfg}" "${log}" "${service}"
ok_msg "Telegram Bot instance moonraker-telegram-bot-${names[${j}]} created!"
j=$(( j + 1 ))
done && unset j
else
return 1
fi
}
function write_telegram_bot_service() {
local i=${1} cfg=${2} log=${3} service=${4}
local service_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.service"
### replace all placeholders
if [[ ! -f ${service} ]]; then
status_msg "Creating Telegram Bot Service ${i} ..."
sudo cp "${service_template}" "${service}"
[[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}"
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%DIR%|${TELEGRAM_BOT_DIR}|" "${service}"
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
fi
}
#===================================================#
#=========== REMOVE MOONRAKERTELEGRAMBOT ===========#
#===================================================#
function remove_telegram_bot_systemd() {
[[ -z $(telegram_bot_systemd) ]] && return
status_msg "Removing Telegram Bot Systemd Services ..."
for service in $(telegram_bot_systemd | cut -d"/" -f5); do
status_msg "Removing ${service} ..."
sudo systemctl stop "${service}"
sudo systemctl disable "${service}"
sudo rm -f "${SYSTEMD}/${service}"
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Telegram Bot Services removed!"
}
function remove_telegram_bot_dir() {
[[ ! -d ${TELEGRAM_BOT_DIR} ]] && return
status_msg "Removing Moonraker-Telegram-Bot directory ..."
rm -rf "${TELEGRAM_BOT_DIR}"
ok_msg "Directory removed!"
}
function remove_telegram_bot_env() {
[[ ! -d ${TELEGRAM_BOT_ENV} ]] && return
status_msg "Removing moonraker-telegram-bot-env directory ..."
rm -rf "${TELEGRAM_BOT_ENV}"
ok_msg "Directory removed!"
}
function remove_telegram_bot_logs() {
local files regex="telegram(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_telegram_bot() {
remove_telegram_bot_systemd
remove_telegram_bot_dir
remove_telegram_bot_env
remove_telegram_bot_logs
local confirm="Moonraker-Telegram-Bot was successfully removed!"
print_confirm "${confirm}" && return
}
#===================================================#
#=========== UPDATE MOONRAKERTELEGRAMBOT ===========#
#===================================================#
function update_telegram_bot() {
do_action_service "stop" "moonraker-telegram-bot"
if [[ ! -d ${TELEGRAM_BOT_DIR} ]]; then
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
else
backup_before_update "moonraker-telegram-bot"
status_msg "Updating Moonraker ..."
cd "${TELEGRAM_BOT_DIR}" && git pull
### read PKGLIST and install possible new dependencies
install_telegram_bot_dependencies
### install possible new python dependencies
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
fi
ok_msg "Update complete!"
do_action_service "start" "moonraker-telegram-bot"
}
#===================================================#
#=========== MOONRAKERTELEGRAMBOT STATUS ===========#
#===================================================#
function get_telegram_bot_status() {
local sf_count status
sf_count="$(telegram_bot_systemd | wc -w)"
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${TELEGRAM_BOT_DIR}" "${TELEGRAM_BOT_ENV}")
(( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]} )); then
status="Installed: ${sf_count}"
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
fi
echo "${status}"
}
function get_local_telegram_bot_commit() {
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
local commit
cd "${TELEGRAM_BOT_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_telegram_bot_commit() {
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
local commit
cd "${TELEGRAM_BOT_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_telegram_bot_versions() {
unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_telegram_bot_commit)"
remote_ver="$(get_remote_telegram_bot_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker-telegram-bot to the update all array for the update all function in the updater
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_telegram_bot)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function patch_telegram_bot_update_manager() {
local moonraker_configs
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager moonraker-telegram-bot\]$" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
### add Moonraker-Telegram-Bot update manager section to moonraker.conf
status_msg "Adding Moonraker-Telegram-Bot to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager moonraker-telegram-bot]
type: git_repo
path: ~/moonraker-telegram-bot
origin: https://github.com/nlef/moonraker-telegram-bot.git
env: ~/moonraker-telegram-bot-env/bin/python
requirements: scripts/requirements.txt
install_script: scripts/install.sh
MOONRAKER_CONF
fi
done
}

577
scripts/moonraker.sh Normal file
View File

@@ -0,0 +1,577 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#================ INSTALL MOONRAKER ================#
#===================================================#
function moonraker_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service" | sort)
echo "${services}"
}
function moonraker_setup_dialog() {
status_msg "Initializing Moonraker installation ..."
### return early if python version check fails
if [[ $(python3_check) == "false" ]]; then
local error="Versioncheck failed! Python 3.7 or newer required!\n"
error="${error} Please upgrade Python."
print_error "${error}" && return
fi
### return early if moonraker already exists
local moonraker_services
moonraker_services=$(moonraker_systemd)
if [[ -n ${moonraker_services} ]]; then
local error="At least one Moonraker service is already installed:"
for s in ${moonraker_services}; do
log_info "Found Moonraker service: ${s}"
error="${error}\n ➔ ${s}"
done
print_error "${error}" && return
fi
### return early if klipper is not installed
local klipper_services
klipper_services=$(klipper_systemd)
if [[ -z ${klipper_services} ]]; then
local error="Klipper not installed! Please install Klipper first!"
log_error "Moonraker setup started without Klipper being installed. Aborting setup."
print_error "${error}" && return
fi
local klipper_count user_input=() klipper_names=()
klipper_count=$(echo "${klipper_services}" | wc -w )
for service in ${klipper_services}; do
klipper_names+=( "$(get_instance_name "${service}")" )
done
local moonraker_count
if (( klipper_count == 1 )); then
ok_msg "Klipper installation found!\n"
moonraker_count=1
elif (( klipper_count > 1 )); then
top_border
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
for name in "${klipper_names[@]}"; do
printf "|${cyan}%-57s${white}|\n" " ● klipper-${name}"
done
blank_line
echo -e "| The setup will apply the same names to Moonraker! |"
blank_line
echo -e "| Please select the number of Moonraker instances to |"
echo -e "| install. Usually one Moonraker instance per Klipper |"
echo -e "| instance is required, but you may not install more |"
echo -e "| Moonraker instances than available Klipper instances. |"
bottom_border
### ask for amount of instances
local re="^[1-9][0-9]*$"
while [[ ! ${moonraker_count} =~ ${re} || ${moonraker_count} -gt ${klipper_count} ]]; do
read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count
### break if input is valid
[[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break
### conditional error messages
[[ ! ${moonraker_count} =~ ${re} ]] && error_msg "Input not a number"
(( moonraker_count > klipper_count )) && error_msg "Number of Moonraker instances larger than installed Klipper instances"
done && select_msg "${moonraker_count}"
else
log_error "Internal error. klipper_count of '${klipper_count}' not equal or grather than one!"
return 1
fi
user_input+=("${moonraker_count}")
### confirm instance amount
local yn
while true; do
(( moonraker_count == 1 )) && local question="Install Moonraker?"
(( moonraker_count > 1 )) && local question="Install ${moonraker_count} Moonraker instances?"
read -p "${cyan}###### ${question} (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
break;;
N|n|No|no)
select_msg "No"
abort_msg "Exiting Moonraker setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
### write existing klipper names into user_input array to use them as names for moonraker
if (( klipper_count > 1 )); then
for name in "${klipper_names[@]}"; do
user_input+=("${name}")
done
fi
(( moonraker_count > 1 )) && status_msg "Installing ${moonraker_count} Moonraker instances ..."
(( moonraker_count == 1 )) && status_msg "Installing Moonraker ..."
moonraker_setup "${user_input[@]}"
}
function install_moonraker_dependencies() {
local packages
local install_script="${MOONRAKER_DIR}/scripts/install-moonraker.sh"
### read PKGLIST from official install-script
status_msg "Reading dependencies..."
# shellcheck disable=SC2016
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
### Update system package info
status_msg "Updating package lists..."
if ! sudo apt-get update --allow-releaseinfo-change; then
log_error "failure while updating package lists"
error_msg "Updating package lists failed!"
exit 1
fi
### Install required packages
status_msg "Installing required packages..."
if ! sudo apt-get install --yes "${packages[@]}"; then
log_error "failure while installing required moonraker packages"
error_msg "Installing required packages failed!"
exit 1
fi
}
function create_moonraker_virtualenv() {
status_msg "Installing python virtual environment..."
### always create a clean virtualenv
[[ -d ${MOONRAKER_ENV} ]] && rm -rf "${MOONRAKER_ENV}"
if virtualenv -p /usr/bin/python3 "${MOONRAKER_ENV}"; then
"${MOONRAKER_ENV}"/bin/pip install -U pip
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
else
log_error "failure while creating python3 moonraker-env"
error_msg "Creation of Moonraker virtualenv failed!"
exit 1
fi
}
function moonraker_setup() {
local instance_arr=("${@}")
### checking dependencies
local dep=(git wget curl unzip dfu-util virtualenv)
### additional required dependencies on armbian
dep+=(libjpeg-dev zlib1g-dev)
dependency_check "${dep[@]}"
### step 1: clone moonraker
clone_moonraker "${MOONRAKER_REPO}"
### step 2: install moonraker dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_moonraker_dependencies
create_moonraker_virtualenv
### step 3: create moonraker.conf
create_moonraker_conf "${instance_arr[@]}"
### step 4: create moonraker instances
create_moonraker_service "${instance_arr[@]}"
### step 5: create polkit rules for moonraker
moonraker_polkit || true
### step 6: enable and start all instances
do_action_service "enable" "moonraker"
do_action_service "start" "moonraker"
### confirm message
local confirm=""
(( instance_arr[0] == 1 )) && confirm="Moonraker has been set up!"
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Moonraker instances have been set up!"
print_confirm "${confirm}" && print_mr_ip_list "${instance_arr[0]}" && return
}
function clone_moonraker() {
local repo=${1}
status_msg "Cloning Moonraker from ${repo} ..."
### force remove existing moonraker dir and clone into fresh moonraker dir
[[ -d ${MOONRAKER_DIR} ]] && rm -rf "${MOONRAKER_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${MOONRAKER_REPO}" "${MOONRAKER_DIR}"; then
print_error "Cloning Moonraker from\n ${repo}\n failed!"
exit 1
fi
}
function create_moonraker_conf() {
local input=("${@}")
local moonraker_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local log="${KLIPPER_LOGS}"
local lan
lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
local port=7125 cfg_dir cfg db uds
if (( moonraker_count == 1 )); then
cfg_dir="${KLIPPER_CONFIG}"
cfg="${cfg_dir}/moonraker.conf"
db="${HOME}/.moonraker_database"
uds="/tmp/klippy_uds"
### write single instance config
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}"
elif (( moonraker_count > 1 )); then
local j=0 re="^[1-9][0-9]*$"
for (( i=1; i <= moonraker_count; i++ )); do
### overwrite config folder if name is only a number
if [[ ${names[j]} =~ ${re} ]]; then
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
else
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
fi
cfg="${cfg_dir}/moonraker.conf"
uds="/tmp/klippy_uds-${names[${j}]}"
db="${HOME}/.moonraker_database_${names[${j}]}"
### write multi instance config
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}"
port=$(( port + 1 ))
j=$(( j + 1 ))
done && unset j
else
return 1
fi
}
function write_moonraker_conf() {
local cfg_dir=${1} cfg=${2} port=${3} log=${4} db=${5} uds=${6} lan=${7}
local conf_template="${KIAUH_SRCDIR}/resources/moonraker.conf"
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
if [[ ! -f ${cfg} ]]; then
status_msg "Creating moonraker.conf in ${cfg_dir} ..."
cp "${conf_template}" "${cfg}"
sed -i "s|%USER%|${USER}|g" "${cfg}"
sed -i "s|%CFG%|${cfg_dir}|; s|%PORT%|${port}|; s|%LOG%|${log}|; s|%DB%|${db}|; s|%UDS%|${uds}|" "${cfg}"
# if host ip is not in the default ip ranges replace placeholder,
# otherwise remove placeholder from config
if ! grep -q "${lan}" "${cfg}"; then
sed -i "s|%LAN%|${lan}|" "${cfg}"
else
sed -i "/%LAN%/d" "${cfg}"
fi
ok_msg "moonraker.conf created!"
else
status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..."
fi
}
function create_moonraker_service() {
local input=("${@}")
local moonraker_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local cfg_dir cfg log service
if (( moonraker_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
i=""
cfg_dir="${KLIPPER_CONFIG}"
cfg="${cfg_dir}/moonraker.conf"
log="${KLIPPER_LOGS}/moonraker.log"
service="${SYSTEMD}/moonraker.service"
### write single instance service
write_moonraker_service "" "${cfg}" "${log}" "${service}"
ok_msg "Moonraker instance created!"
elif (( moonraker_count > 1 )) && [[ ${#names[@]} -gt 0 ]]; then
local j=0 re="^[1-9][0-9]*$"
for (( i=1; i <= moonraker_count; i++ )); do
### overwrite config folder if name is only a number
if [[ ${names[j]} =~ ${re} ]]; then
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
else
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
fi
cfg="${cfg_dir}/moonraker.conf"
log="${KLIPPER_LOGS}/moonraker-${names[${j}]}.log"
service="${SYSTEMD}/moonraker-${names[${j}]}.service"
### write multi instance service
write_moonraker_service "${names[${j}]}" "${cfg}" "${log}" "${service}"
ok_msg "Moonraker instance 'moonraker-${names[${j}]}' created!"
j=$(( j + 1 ))
done && unset i
### enable mainsails remoteMode if mainsail is found
if [[ -d ${MAINSAIL_DIR} ]]; then
status_msg "Mainsail installation found! Enabling Mainsail remote mode ..."
enable_mainsail_remotemode
ok_msg "Mainsails remote mode enabled!"
fi
else
return 1
fi
}
function write_moonraker_service() {
local i=${1} cfg=${2} log=${3} service=${4}
local service_template="${KIAUH_SRCDIR}/resources/moonraker.service"
### replace all placeholders
if [[ ! -f ${service} ]]; then
status_msg "Creating Moonraker Service ${i} ..."
sudo cp "${service_template}" "${service}"
[[ -z ${i} ]] && sudo sed -i "s| for instance moonraker-%INST%||" "${service}"
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}"
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
fi
}
function print_mr_ip_list() {
local ip count=${1} port=7125
ip=$(hostname -I | cut -d" " -f1)
for (( i=1; i <= count; i++ )); do
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
port=$(( port + 1 ))
done && echo
}
### introduced due to
### https://github.com/Arksine/moonraker/issues/349
### https://github.com/Arksine/moonraker/pull/346
function moonraker_polkit() {
local has_sup
### check for required SupplementaryGroups entry in service files
### write it to the service if it doesn't exist
for service in $(moonraker_systemd); do
has_sup="$(grep "SupplementaryGroups=moonraker-admin" "${service}")"
if [[ -z ${has_sup} ]]; then
status_msg "Adding moonraker-admin supplementary group to ${service} ..."
sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "${service}"
ok_msg "Adding moonraker-admin supplementary group successfull!"
fi
done
[[ -z ${has_sup} ]] && echo "reloading services!!!" && sudo systemctl daemon-reload
### execute moonrakers policykit-rules script
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
}
#==================================================#
#================ REMOVE MOONRAKER ================#
#==================================================#
function remove_moonraker_sysvinit() {
[[ ! -e "${INITD}/moonraker" ]] && return
status_msg "Removing Moonraker SysVinit service ..."
sudo systemctl stop moonraker
sudo update-rc.d -f moonraker remove
sudo rm -f "${INITD}/moonraker" "${ETCDEF}/moonraker"
ok_msg "Moonraker SysVinit service removed!"
}
function remove_moonraker_systemd() {
[[ -z $(moonraker_systemd) ]] && return
status_msg "Removing Moonraker Systemd Services ..."
for service in $(moonraker_systemd | cut -d"/" -f5); do
status_msg "Removing ${service} ..."
sudo systemctl stop "${service}"
sudo systemctl disable "${service}"
sudo rm -f "${SYSTEMD}/${service}"
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Moonraker Services removed!"
}
function remove_moonraker_logs() {
local files regex="moonraker(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_moonraker_api_key() {
### remove legacy api key
if [[ -e "${HOME}/.klippy_api_key" ]]; then
status_msg "Removing legacy API Key ..."
rm "${HOME}/.klippy_api_key"
ok_msg "Done!"
fi
### remove api key
if [[ -e "${HOME}/.moonraker_api_key" ]]; then
status_msg "Removing API Key ..."
rm "${HOME}/.moonraker_api_key"
ok_msg "Done!"
fi
}
function remove_moonraker_dir() {
[[ ! -d ${MOONRAKER_DIR} ]] && return
status_msg "Removing Moonraker directory ..."
rm -rf "${MOONRAKER_DIR}"
ok_msg "Directory removed!"
}
function remove_moonraker_env() {
[[ ! -d ${MOONRAKER_ENV} ]] && return
status_msg "Removing moonraker-env directory ..."
rm -rf "${MOONRAKER_ENV}"
ok_msg "Directory removed!"
}
function remove_moonraker_polkit() {
[[ ! -d ${MOONRAKER_DIR} ]] && return
status_msg "Removing all Moonraker PolicyKit rules ..."
"${MOONRAKER_DIR}"/scripts/set-policykit-rules.sh --clear
ok_msg "Done!"
}
function remove_moonraker() {
remove_moonraker_sysvinit
remove_moonraker_systemd
remove_moonraker_logs
remove_moonraker_api_key
remove_moonraker_polkit
remove_moonraker_dir
remove_moonraker_env
print_confirm "Moonraker was successfully removed!"
return
}
#==================================================#
#================ UPDATE MOONRAKER ================#
#==================================================#
function update_moonraker() {
do_action_service "stop" "moonraker"
if [[ ! -d ${MOONRAKER_DIR} ]]; then
clone_moonraker "${MOONRAKER_REPO}"
else
backup_before_update "moonraker"
status_msg "Updating Moonraker ..."
cd "${MOONRAKER_DIR}" && git pull
### read PKGLIST and install possible new dependencies
install_moonraker_dependencies
### install possible new python dependencies
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
fi
### required due to https://github.com/Arksine/moonraker/issues/349
moonraker_polkit
ok_msg "Update complete!"
do_action_service "restart" "moonraker"
}
#==================================================#
#================ MOONRAKER STATUS ================#
#==================================================#
function get_moonraker_status() {
local sf_count status
sf_count="$(moonraker_systemd | wc -w)"
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${MOONRAKER_DIR}" "${MOONRAKER_ENV}")
(( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]} )); then
status="Installed: ${sf_count}"
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
fi
echo "${status}"
}
function get_local_moonraker_commit() {
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
local commit
cd "${MOONRAKER_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_moonraker_commit() {
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
local commit
cd "${MOONRAKER_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_moonraker_versions() {
unset MOONRAKER_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_moonraker_commit)"
remote_ver="$(get_remote_moonraker_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker to the update all array for the update all function in the updater
MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
MOONRAKER_UPDATE_AVAIL="false"
fi
echo "${versions}"
}

347
scripts/nginx.sh Normal file
View File

@@ -0,0 +1,347 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#=================== REMOVE NGINX ==================#
#===================================================#
function remove_nginx() {
if [[ $(dpkg -s nginx 2>/dev/null | grep "Status") = *\ installed ]]; then
status_msg "Stopping NGINX service ..."
if systemctl is-active nginx -q; then
sudo systemctl stop nginx && ok_msg "Service stopped!"
else
warn_msg "NGINX service not active!"
fi
status_msg "Removing NGINX from system ..."
if sudo apt-get remove nginx -y && sudo update-rc.d -f nginx remove; then
ok_msg "NGINX removed!"
else
error_msg "Removing NGINX from system failed!"
fi
else
print_error "Looks like Nginx was already removed!\n Skipping..."
fi
}
#===================================================#
#===================== HELPERS =====================#
#===================================================#
function set_upstream_nginx_cfg() {
local current_date
local upstreams="${NGINX_CONFD}/upstreams.conf"
local common_vars="${NGINX_CONFD}/common_vars.conf"
current_date=$(get_date)
### backup existing nginx configs
[[ ! -d "${BACKUP_DIR}/nginx_cfg" ]] && mkdir -p "${BACKUP_DIR}/nginx_cfg"
if [[ -f ${upstreams} ]]; then
sudo mv "${upstreams}" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf"
fi
if [[ -f ${common_vars} ]]; then
sudo mv "${common_vars}" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf"
fi
### transfer ownership of backed up files from root to ${USER}
local files
files=$(find "${BACKUP_DIR}/nginx_cfg")
for file in ${files}; do
if [[ $(stat -c "%U" "${file}") != "${USER}" ]]; then
log_info "chown for user: ${USER} on file: ${file}"
sudo chown "${USER}" "${file}"
fi
done
### copy nginx configs to target destination
[[ ! -f ${upstreams} ]] && sudo cp "${RESOURCES}/upstreams.conf" "${upstreams}"
[[ ! -f ${common_vars} ]] && sudo cp "${RESOURCES}/common_vars.conf" "${common_vars}"
}
function symlink_webui_nginx_log() {
local interface=${1} path="${KLIPPER_LOGS}"
local access_log="/var/log/nginx/${interface}-access.log"
local error_log="/var/log/nginx/${interface}-error.log"
[[ ! -d ${path} ]] && mkdir -p "${path}"
if [[ -f ${access_log} && ! -L "${path}/${interface}-access.log" ]]; then
status_msg "Creating symlink for ${access_log} ..."
ln -s "${access_log}" "${path}"
ok_msg "Done!"
fi
if [[ -f ${error_log} && ! -L "${path}/${interface}-error.log" ]]; then
status_msg "Creating symlink for ${error_log} ..."
ln -s "${error_log}" "${path}"
ok_msg "Done!"
fi
}
function match_nginx_configs() {
read_kiauh_ini "${FUNCNAME[0]}"
local require_service_restart="false"
local upstreams="${NGINX_CONFD}/upstreams.conf"
local common_vars="${NGINX_CONFD}/common_vars.conf"
local mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail"
local fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd"
local upstreams_webcams mainsail_webcams fluidd_webcams
### reinstall nginx configs if the amount of upstreams don't match anymore
upstreams_webcams=$(grep -Ec "mjpgstreamer" "/etc/nginx/conf.d/upstreams.conf")
mainsail_webcams=$(grep -Ec "mjpgstreamer" "${mainsail_nginx_cfg}" 2>/dev/null || echo "0")
fluidd_webcams=$(grep -Ec "mjpgstreamer" "${fluidd_nginx_cfg}" 2>/dev/null || echo "0")
status_msg "Checking validity of NGINX configurations ..."
### check for outdated upstreams.conf
if (( upstreams_webcams < mainsail_webcams || upstreams_webcams < fluidd_webcams )); then
status_msg "Outdated upstreams.conf found! Updating ..."
sudo rm -f "${upstreams}" "${common_vars}"
set_upstream_nginx_cfg
require_service_restart="true"
fi
### check for outdated mainsail config
if [[ -e ${mainsail_nginx_cfg} ]] && (( upstreams_webcams > mainsail_webcams )); then
status_msg "Outdated Mainsail config found! Updating ..."
sudo rm -f "${mainsail_nginx_cfg}"
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}"
sudo sed -i "s/<<UI>>/mainsail/g" "${mainsail_nginx_cfg}"
sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}"
sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}"
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}"
require_service_restart="true"
fi
### check for outdated fluidd config
if [[ -e ${fluidd_nginx_cfg} ]] && (( upstreams_webcams > fluidd_webcams )); then
status_msg "Outdated Fluidd config found! Updating ..."
sudo rm -f "${fluidd_nginx_cfg}"
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}"
sudo sed -i "s/<<UI>>/fluidd/g" "${fluidd_nginx_cfg}"
sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}"
sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}"
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}"
require_service_restart="true"
fi
### only restart nginx if configs were updated
if [[ ${require_service_restart} == "true" ]]; then
sudo systemctl restart nginx.service
fi
ok_msg "Done!"
}
function remove_conflicting_packages() {
local apache=${1} haproxy=${2}
### disable services before removing them
disable_conflicting_packages "${apache}" "${haproxy}"
if [[ ${apache} == "true" ]]; then
status_msg "Removing Apache2 from system ..."
if sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove; then
ok_msg "Apache2 removed!"
else
error_msg "Removing Apache2 from system failed!"
fi
fi
if [[ ${haproxy} == "true" ]]; then
status_msg "Removing haproxy from system ..."
if sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove; then
ok_msg "Haproxy removed!"
else
error_msg "Removing Haproxy from system failed!"
fi
fi
}
function disable_conflicting_packages() {
local apache=${1} haproxy=${2}
if [[ ${apache} == "true" ]]; then
status_msg "Stopping Apache2 service ..."
if systemctl is-active apache2 -q; then
sudo systemctl stop apache2 && ok_msg "Service stopped!"
else
warn_msg "Apache2 service not active!"
fi
status_msg "Disabling Apache2 service ..."
if sudo systemctl disable apache2; then
ok_msg "Apache2 service disabled!"
else
error_msg "Disabling Apache2 service failed!"
fi
fi
if [[ ${haproxy} == "true" ]]; then
status_msg "Stopping Haproxy service ..."
if systemctl is-active haproxy -q; then
sudo systemctl stop haproxy && ok_msg "Service stopped!"
else
warn_msg "Haproxy service not active!"
fi
status_msg "Disabling Haproxy service ..."
if sudo systemctl disable haproxy; then
ok_msg "Haproxy service disabled!"
else
error_msg "Disabling Haproxy service failed!"
fi
fi
}
function detect_conflicting_packages() {
local apache="false" haproxy="false"
### check system for an installed apache2 service
[[ $(dpkg -s apache2 2>/dev/null | grep "Status") = *\ installed ]] && apache="true"
### check system for an installed haproxy service
[[ $(dpkg -s haproxy 2>/dev/null | grep "Status") = *\ installed ]] && haproxy="true"
#notify user about haproxy or apache2 services found and possible issues
if [[ ${haproxy} == "false" && ${apache} == "false" ]]; then
return
else
while true; do
echo
top_border
echo -e "| ${red}Conflicting package installations found:${white} |"
[[ ${apache} == "true" ]] && \
echo -e "| ${red}● apache2${white} |"
[[ ${haproxy} == "true" ]] && \
echo -e "| ${red}● haproxy${white} |"
blank_line
echo -e "| Having those packages installed can lead to unwanted |"
echo -e "| behaviour. It's recommended to remove those packages. |"
echo -e "| |"
echo -e "| ${green}1) Remove packages (recommend)${white} |"
echo -e "| 2) Disable only (may still cause issues) |"
echo -e "| ${red}3) Skip this step (not recommended)${white} |"
bottom_border
local action
read -p "${cyan}###### Please choose:${white} " action
case "${action}" in
1)
echo -e "###### > Remove packages"
remove_conflicting_packages "${apache}" "${haproxy}"
break;;
2)
echo -e "###### > Disable only"
disable_conflicting_packages "${apache}" "${haproxy}"
break;;
3)
echo -e "###### > Skip"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
function set_nginx_cfg() {
local interface=${1}
if [[ ${SET_NGINX_CFG} == "true" ]]; then
local cfg="${RESOURCES}/${interface}"
#check for dependencies
local dep=(nginx)
dependency_check "${dep[@]}"
status_msg "Creating Nginx configuration for ${interface^} ..."
cat "${RESOURCES}/klipper_webui_nginx.cfg" > "${cfg}"
sed -i "s/<<UI>>/${interface}/g" "${cfg}"
if [[ ${SET_LISTEN_PORT} != "${DEFAULT_PORT}" ]]; then
status_msg "Configuring port for ${interface^} ..."
sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}"
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}"
fi
#set correct user
if [[ ${interface} == "mainsail" || ${interface} == "fluidd" ]]; then
sudo sed -i "/root/s/pi/${USER}/" "${cfg}"
fi
#moving the config file into correct directory
sudo mv "${cfg}" "/etc/nginx/sites-available/${interface}"
ok_msg "Nginx configuration for ${interface^} was set!"
if [[ -n ${SET_LISTEN_PORT} ]]; then
ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!"
else
ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!"
fi
#remove nginx default config
if [[ -e "/etc/nginx/sites-enabled/default" ]]; then
sudo rm "/etc/nginx/sites-enabled/default"
fi
#create symlink for own sites
if [[ ! -e "/etc/nginx/sites-enabled/${interface}" ]]; then
sudo ln -s "/etc/nginx/sites-available/${interface}" "/etc/nginx/sites-enabled/"
fi
sudo systemctl restart nginx.service
fi
}
function set_nginx_permissions() {
local distro_name version_id
distro_name=$(grep -E "^NAME=" /etc/os-release | cut -d'"' -f2)
version_id=$(grep -E "^VERSION_ID=" /etc/os-release | cut -d'"' -f2)
if [[ ${distro_name} == "Ubuntu" && ( ${version_id} == "21.10" || ${version_id} == "22.04") ]]; then
status_msg "Granting NGINX the required permissions ..."
chmod og+x "${HOME}" && ok_msg "Done!"
fi
return
}
function read_listen_port() {
local port interface=${1}
port=$(grep listen "/etc/nginx/sites-enabled/${interface}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
echo "${port}"
}
function detect_enabled_sites() {
MAINSAIL_ENABLED="false" FLUIDD_ENABLED="false"
#check if there is another UI config already installed and reads the port they are listening on
if [[ -e "/etc/nginx/sites-enabled/mainsail" ]]; then
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
MAINSAIL_PORT=$(read_listen_port "mainsail")
fi
if [[ -e "/etc/nginx/sites-enabled/fluidd" ]]; then
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
FLUIDD_PORT=$(read_listen_port "fluidd")
fi
}

401
scripts/octoprint.sh Normal file
View File

@@ -0,0 +1,401 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#=================================================#
#=============== INSTALL OCTOPRINT ===============#
#=================================================#
function octoprint_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[0-9a-zA-Z]+)?.service" | sort)
echo "${services}"
}
function octoprint_setup_dialog() {
status_msg "Initializing OctoPrint installation ..."
local klipper_services klipper_count user_input=() klipper_names=()
klipper_services=$(klipper_systemd)
klipper_count=$(echo "${klipper_services}" | wc -w )
for service in ${klipper_services}; do
klipper_names+=( "$(get_instance_name "${service}")" )
done
local octoprint_count
if (( klipper_count == 1 )); then
ok_msg "Klipper installation found!\n"
octoprint_count=1
elif (( klipper_count > 1 )); then
top_border
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
for name in "${klipper_names[@]}"; do
printf "|${cyan}%-57s${white}|\n" "${name}"
done
blank_line
echo -e "| The setup will apply the same names to OctoPrint! |"
blank_line
echo -e "| Please select the number of OctoPrint instances to |"
echo -e "| install. Usually one OctoPrint instance per Klipper |"
echo -e "| instance is required, but you may not install more |"
echo -e "| OctoPrint instances than available Klipper instances. |"
bottom_border
local re="^[1-9][0-9]*$"
while [[ ! ${octoprint_count} =~ ${re} || ${octoprint_count} -gt ${klipper_count} ]]; do
read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " -i "${klipper_count}" -e octoprint_count
### break if input is valid
[[ ${octoprint_count} =~ ${re} ]] && break
### conditional error messages
[[ ! ${octoprint_count} =~ ${re} ]] && error_msg "Input not a number"
(( octoprint_count > klipper_count )) && error_msg "Number of OctoPrint instances larger than existing Klipper instances"
done && select_msg "${octoprint_count}"
else
log_error "Internal error. octoprint_count of '${octoprint_count}' not equal or grather than one!"
return 1
fi
user_input+=("${octoprint_count}")
### confirm instance amount
local yn
while true; do
(( octoprint_count == 1 )) && local question="Install OctoPrint?"
(( octoprint_count > 1 )) && local question="Install ${octoprint_count} OctoPrint instances?"
read -p "${cyan}###### ${question} (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
break;;
N|n|No|no)
select_msg "No"
abort_msg "Exiting OctoPrint setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
### write existing klipper names into user_input array to use them as names for octoprint
if (( klipper_count > 1 )); then
for name in "${klipper_names[@]}"; do
user_input+=("${name}")
done
fi
(( octoprint_count > 1 )) && status_msg "Installing ${octoprint_count} OctoPrint instances ..."
(( octoprint_count == 1 )) && status_msg "Installing OctoPrint ..."
octoprint_setup "${user_input[@]}"
}
function octoprint_setup() {
local instance_arr=("${@}")
### check and install all dependencies
local dep=(
git
wget
python3-pip
python3-dev
libyaml-dev
build-essential
python3-setuptools
python3-virtualenv
)
dependency_check "${dep[@]}"
### step 1: check for tty and dialout usergroups and add reboot permissions
check_usergroups
add_reboot_permission
### step 2: install octoprint
install_octoprint "${instance_arr[@]}"
### step 3: set up service
create_octoprint_service "${instance_arr[@]}"
### step 4: enable and start all instances
do_action_service "enable" "octoprint"
do_action_service "start" "octoprint"
### confirm message
local confirm=""
(( instance_arr[0] == 1 )) && confirm="OctoPrint has been set up!"
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} OctoPrint instances have been set up!"
print_confirm "${confirm}" && print_op_ip_list "${instance_arr[0]}" && return
}
function install_octoprint() {
function install_octoprint_python_env() {
local tmp="${1}"
### create and activate the virtualenv
status_msg "Installing python virtual environment..."
if [[ ! -d ${tmp} ]]; then
mkdir -p "${tmp}"
else
error_msg "Cannot create temporary directory in ${HOME}!"
error_msg "Folder 'TMP_OCTO_ENV' exists and may not be empty!"
error_msg "Please remove/rename that folder and start again."
return 1
fi
cd "${tmp}"
if virtualenv --python=python3 venv; then
### activate virtualenv
source venv/bin/activate
pip install pip --upgrade
pip install --no-cache-dir octoprint
### leave virtualenv
deactivate
else
log_error "failure while creating python3 OctoPrint env"
error_msg "Creation of OctoPrint virtualenv failed!"
exit 1
fi
cd "${HOME}"
}
local input=("${@}")
local octoprint_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local j=0 octo_env
local tmp="${HOME}/TMP_OCTO_ENV"
### handle single instance installs
if (( octoprint_count == 1 )); then
if install_octoprint_python_env "${tmp}"; then
status_msg "Installing OctoPrint ..."
octo_env="${HOME}/OctoPrint"
### rename the temporary directory to the correct name
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
mv "${tmp}" "${octo_env}"
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
else
error_msg "OctoPrint installation failed!"
return 1
fi
fi
### handle multi instance installs
if (( octoprint_count > 1 )); then
if install_octoprint_python_env "${tmp}"; then
for (( i=1; i <= octoprint_count; i++ )); do
status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..."
octo_env="${HOME}/OctoPrint_${names[${j}]}"
### rename the temporary directory to the correct name
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
cp -r "${tmp}" "${octo_env}"
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
j=$(( j + 1 ))
done && rm -rf "${tmp}"
else
error_msg "OctoPrint installation failed!"
return 1
fi
fi
}
function create_octoprint_service() {
local input=("${@}")
local octoprint_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local j=0 port=5000
local octo_env service basedir tmp_printer config_yaml restart_cmd
for (( i=1; i <= octoprint_count; i++ )); do
if (( octoprint_count == 1 )); then
octo_env="${HOME}/OctoPrint"
service="${SYSTEMD}/octoprint.service"
basedir="${HOME}/.octoprint"
tmp_printer="/tmp/printer"
config_yaml="${basedir}/config.yaml"
restart_cmd="sudo service octoprint restart"
elif (( octoprint_count > 1 )); then
octo_env="${HOME}/OctoPrint_${names[${j}]}"
service="${SYSTEMD}/octoprint-${names[${j}]}.service"
basedir="${HOME}/.octoprint_${names[${j}]}"
tmp_printer="/tmp/printer-${names[${j}]}"
config_yaml="${basedir}/config.yaml"
restart_cmd="sudo service octoprint-${names[${j}]} restart"
fi
(( octoprint_count == 1 )) && status_msg "Creating OctoPrint Service ..."
(( octoprint_count > 1 )) && status_msg "Creating OctoPrint Service ${i}(${names[${j}]}) ..."
sudo /bin/sh -c "cat > ${service}" << OCTOPRINT
[Unit]
Description=Starts OctoPrint 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=${octo_env}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve
[Install]
WantedBy=multi-user.target
OCTOPRINT
port=$(( port + 1 ))
j=$(( j + 1 ))
ok_msg "Ok!"
### create config.yaml
if [[ ! -f ${basedir}/config.yaml ]]; then
[[ ! -d ${basedir} ]] && mkdir "${basedir}"
(( octoprint_count == 1 )) && status_msg "Creating config.yaml ..."
(( octoprint_count > 1 )) && status_msg "Creating config.yaml for instance ${i}(${names[${j}]}) ..."
/bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML
serial:
additionalPorts:
- ${tmp_printer}
disconnectOnErrors: false
port: ${tmp_printer}
server:
commands:
serverRestartCommand: ${restart_cmd}
systemRestartCommand: sudo shutdown -r now
systemShutdownCommand: sudo shutdown -h now
CONFIGYAML
ok_msg "Ok!"
fi
done
}
function add_reboot_permission() {
#create a backup if file already exists
if [[ -f /etc/sudoers.d/octoprint-shutdown ]]; then
sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old
fi
#create new permission file
status_msg "Add reboot permission to user '${USER}' ..."
cd "${HOME}" && echo "${USER} ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
sudo chown 0 octoprint-shutdown
sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown
ok_msg "Permission set!"
}
function print_op_ip_list() {
local ip octoprint_count="${1}" port=5000
ip=$(hostname -I | cut -d" " -f1)
for (( i=1; i <= octoprint_count; i++ )); do
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
port=$(( port + 1 ))
done && echo
}
#=================================================#
#=============== REMOVE OCTOPRINT ================#
#=================================================#
function remove_octoprint_service() {
[[ -z $(octoprint_systemd) ]] && return
###remove all octoprint services
status_msg "Removing OctoPrint Systemd Services ..."
for service in $(octoprint_systemd | cut -d"/" -f5); do
status_msg "Removing ${service} ..."
sudo systemctl stop "${service}"
sudo systemctl disable "${service}"
sudo rm -f "${SYSTEMD}/${service}"
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
}
function remove_octoprint_sudoers() {
[[ ! -f /etc/sudoers.d/octoprint-shutdown ]] && return
### remove sudoers file
sudo rm -f /etc/sudoers.d/octoprint-shutdown
}
function remove_octoprint_env() {
local files
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -rf "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_octoprint_dir() {
local files
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -rf "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_octoprint() {
remove_octoprint_service
remove_octoprint_sudoers
remove_octoprint_env
remove_octoprint_dir
local confirm="OctoPrint was successfully removed!"
print_confirm "${confirm}" && return
}
#=================================================#
#=============== OCTOPRINT STATUS ================#
#=================================================#
function get_octoprint_status() {
local sf_count env_count dir_count status
sf_count="$(octoprint_systemd | wc -w)"
env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | wc -w)
dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | wc -w)
if (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then
status="Not installed!"
elif (( sf_count == env_count )) && (( sf_count == dir_count )); then
status="Installed: ${sf_count}"
else
status="Incomplete!"
fi
echo "${status}"
}

129
scripts/pretty_gcode.sh Normal file
View File

@@ -0,0 +1,129 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#=================================================#
#================== INSTALL PGC ==================#
#=================================================#
function install_pgc_for_klipper() {
local pgconfsrc="${PGC_DIR}/pgcode.local.conf"
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
local pgc_uri pgc_custom_port pgc_default_port="7136"
status_msg "Installing PrettyGCode for Klipper ..."
echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: ${pgc_default_port})${white} "
read -e -p "${cyan}###### Port:${white} " -i "${pgc_default_port}" pgc_custom_port
### check nginx dependency
local dep=(nginx)
dependency_check "${dep[@]}"
[[ -d ${PGC_DIR} ]] && rm -rf "${PGC_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${PGC_REPO}" "${PGC_DIR}"; then
print_error "Cloning PrettyGCode for Klipper from\n ${PGC_REPO}\n failed!"
exit 1
fi
sudo cp "${pgconfsrc}" "${pgconf}"
sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" "${pgconf}"
### replace default port
if (( pgc_custom_port != pgc_default_port )); then
sudo sed -i "s|listen ${pgc_default_port};|listen ${pgc_custom_port};|" "${pgconf}"
sudo sed -i "s|listen \[::\]:${pgc_default_port};|listen \[::\]:${pgc_custom_port};|" "${pgconf}"
fi
[[ ! -L ${pgconfsl} ]] && sudo ln -s "${pgconf}" "${pgconfsl}"
sudo systemctl restart nginx
pgc_uri="http://$(hostname -I | cut -d" " -f1):${pgc_custom_port}"
echo -e "${cyan}\n● Accessible via:${white} ${pgc_uri}"
ok_msg "PrettyGCode for Klipper installed!\n"
}
#=================================================#
#=================== REMOVE PGC ==================#
#=================================================#
function remove_prettygcode() {
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
if [[ -d ${PGC_DIR} || -f ${pgconf} || -L ${pgconfsl} ]]; then
status_msg "Removing PrettyGCode for Klipper ..."
rm -rf "${PGC_DIR}"
sudo rm -f "${pgconf}"
sudo rm -f "${pgconfsl}"
sudo systemctl restart nginx
print_confirm "PrettyGCode for Klipper successfully removed!"
else
print_error "PrettyGCode for Klipper not found!\n Skipping..."
fi
}
#=================================================#
#=================== UPDATE PGC ==================#
#=================================================#
function update_pgc_for_klipper() {
[[ ! -d ${PGC_DIR} ]] && return
status_msg "Updating PrettyGCode for Klipper ..."
cd "${PGC_DIR}" && git pull
ok_msg "Update complete!"
}
#=================================================#
#=================== PGC STATUS ==================#
#=================================================#
function get_local_prettygcode_commit() {
local commit
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
cd "${PGC_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_prettygcode_commit() {
local commit
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
cd "${PGC_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_prettygcode_versions() {
unset PGC_UPDATE_AVAIL
local versions local_ver remote_ver
local_ver="$(get_local_prettygcode_commit)"
remote_ver="$(get_remote_prettygcode_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add prettygcode to the update all array for the update all function in the updater
PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper)
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
PGC_UPDATE_AVAIL="false"
fi
echo "${versions}"
}

View File

@@ -1,145 +0,0 @@
remove_klipper(){
data_arr=(
/etc/init.d/klipper
/etc/default/klipper
$KLIPPER_DIR
$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 update-rc.d -f klipper remove
sudo rm -rf /etc/init.d/klipper /etc/default/klipper && ok_msg "Klipper service removed!"
fi
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then
status_msg "Removing klipper and klippy-env diretory ..."
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
ok_msg "Klipper successfully removed!"
fi
}
remove_dwc2(){
data_arr=(
$DWC2FK_DIR
$TORNADO_DIR1
$TORNADO_DIR2
$WEB_DWC2
$DWC2_DIR
)
print_error "DWC2-for-Klipper &\n DWC2 Web UI" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
if [ -d $DWC2FK_DIR ]; then
status_msg "Removing dwc2-for-klipper directory ..."
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
fi
if [ -d $TORNADO_DIR1 ]; then
status_msg "Removing tornado from klippy-env ..."
rm -rf $TORNADO_DIR1 $TORNADO_DIR2 && ok_msg "Tornado removed!"
fi
if [ -e $WEB_DWC2 ]; then
status_msg "Removing web_dwc2.py symlink from klippy ..."
rm -rf $WEB_DWC2 && ok_msg "File removed!"
fi
if [ -d $DWC2_DIR ]; then
status_msg "Removing dwc2 directory ..."
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
fi
ok_msg "DWC2-for-Klipper & DWC2 Web UI successfully removed!"
fi
}
remove_mainsail(){
data_arr=(
$MAINSAIL_SERVICE1
$MAINSAIL_SERVICE2
$MAINSAIL_DIR
${HOME}/moonraker.log
${HOME}/.klippy_api_key
${HOME}/.moonraker_api_key
${HOME}/moonraker-env
/etc/nginx/sites-available/mainsail
/etc/nginx/sites-enabled/mainsail
/etc/init.d/nginx
/etc/default/nginx
)
print_error "Mainsail" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
stop_moonraker
#remove moonraker services
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then
status_msg "Removing moonraker service ..."
sudo update-rc.d -f moonraker remove
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker service removed!"
fi
#remove mainsail dir
if [ -d $MAINSAIL_DIR ]; then
status_msg "Removing mainsail directory ..."
rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!"
fi
#remove moonraker-env
if [ -d ${HOME}/moonraker-env ]; then
status_msg "Removing moonraker virtualenv ..."
rm -rf ${HOME}/moonraker-env && ok_msg "Directory removed!"
fi
#remove moonraker.log symlink
if [[ -L ${HOME}/moonraker.log || -e /tmp/moonraker.log ]]; then
status_msg "Removing moonraker.log symlink ..."
rm -rf ${HOME}/moonraker.log /tmp/moonraker.log && ok_msg "Symlink removed!"
fi
#remove mainsail cfg
if [ -e /etc/nginx/sites-available/mainsail ]; then
status_msg "Removing mainsail configuration for nginx ..."
sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!"
fi
#remove mainsail symlink
if [ -L /etc/nginx/sites-enabled/mainsail ]; then
status_msg "Removing mainsail symlink for nginx ..."
sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!"
fi
#remove legacy api key
if [ -e ${HOME}/.klippy_api_key ]; then
status_msg "Removing legacy API Key ..."
rm ${HOME}/.klippy_api_key && ok_msg "Done!"
fi
#remove api key
if [ -e ${HOME}/.moonraker_api_key ]; then
status_msg "Removing API Key ..."
rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
fi
remove_nginx
ok_msg "Mainsail successfully removed!"
fi
}
remove_nginx(){
#ask for complete removal of nginx if installed
if [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]] ; then
while true; do
echo
read -p "Do you want to completely remove (purge) nginx? (Y/n): " yn
case "$yn" in
Y|y|Yes|yes|"")
status_msg "Stopping and removing nginx service ..."
if [ -e /etc/init.d/nginx ]; then
sudo /etc/init.d/nginx stop && ok_msg "Nginx service stopped!"
sudo rm /etc/init.d/nginx && ok_msg "Nginx service removed!"
fi
if [ -e /etc/default/nginx ]; then
sudo rm /etc/default/nginx
fi
status_msg "Purging nginx from system ..."
sudo apt-get purge nginx nginx-common -y && ok_msg "Nginx removed!"
break;;
N|n|No|no) break;;
esac
done
fi
}

85
scripts/rollback.sh Executable file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function rollback_menu() {
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") |"
hr
echo -e "| If serious errors occured after updating Klipper or |"
echo -e "| Moonraker, you can use this menu to try and reset the |"
echo -e "| repository to an earlier state. |"
hr
echo -e "| 1) Rollback Klipper |"
echo -e "| 2) Rollback Moonraker |"
back_footer
local action
while true; do
read -p "${cyan}###### Perform action:${white} " action
case "${action}" in
1)
select_msg "Klipper"
rollback_component "klipper"
break;;
2)
select_msg "Moonraker"
rollback_component "moonraker"
break;;
B|b)
clear; advanced_menu; break;;
*)
error_msg "Invalid command!";;
esac
done
}
function rollback_component() {
local component=${1}
if [[ ! -d "${HOME}/${component}" ]]; then
print_error "Rollback not possible! Missing installation?"
return
fi
echo
top_border
echo -e "| Please select how many commits you want to revert. |"
echo -e "| Consider using the information provided by the GitHub |"
echo -e "| commit history to decide how many commits to revert. |"
blank_line
echo -e "| ${red}Warning:${white} |"
echo -e "| ${red}Do not proceed if you are currently in the progress${white} |"
echo -e "| ${red}of printing! Proceeding WILL terminate that print!${white} |"
back_footer
local count
while true; do
read -p "${cyan}###### Revert this amount of commits:${white} " count
if [[ -n ${count} ]] && (( count > 0 )); then
status_msg "Revert ${component^} by ${count} commits ..."
cd "${HOME}/${component}"
if git reset --hard HEAD~"${count}"; then
do_action_service "restart" "${component}"
print_confirm "${component^} was successfully reset!"
else
print_error "Reverting ${component^} failed! Please see the console output above."
fi
break
elif [[ ${count} == "B" || ${count} == "b" ]]; then
clear && print_header && break
else
error_msg "Invalid command!"
fi
done
rollback_menu
}

View File

@@ -1,226 +0,0 @@
klipper_status(){
kcount=0
klipper_data=(
$KLIPPER_DIR
$KLIPPY_ENV_DIR
$KLIPPER_SERVICE1
$KLIPPER_SERVICE2
)
#count+1 for each found data-item from array
for kd in "${klipper_data[@]}"
do
if [ -e $kd ]; then
kcount=$(expr $kcount + 1)
fi
done
if [ "$kcount" == "${#klipper_data[*]}" ]; then
KLIPPER_STATUS="${green}Installed!${default} "
elif [ "$kcount" == 0 ]; then
KLIPPER_STATUS="${red}Not installed!${default} "
else
KLIPPER_STATUS="${yellow}Incomplete!${default} "
fi
}
dwc2_status(){
dcount=0
dwc2_data=(
$DWC2FK_DIR
$WEB_DWC2
$DWC2_DIR
$TORNADO_DIR1
$TORNADO_DIR2
)
#count+1 for each found data-item from array
for dd in "${dwc2_data[@]}"
do
if [ -e $dd ]; then
dcount=$(expr $dcount + 1)
fi
done
if [ "$dcount" == "${#dwc2_data[*]}" ]; then
DWC2_STATUS="${green}Installed!${default} "
elif [ "$dcount" == 0 ]; then
DWC2_STATUS="${red}Not installed!${default} "
else
DWC2_STATUS="${yellow}Incomplete!${default} "
fi
}
mainsail_status(){
mcount=0
mainsail_data=(
$MAINSAIL_SERVICE1
$MAINSAIL_SERVICE2
$MAINSAIL_DIR
#${HOME}/.klippy_api_key
#${HOME}/.moonraker_api_key
#${HOME}/moonraker-env
/etc/nginx/sites-available/mainsail
/etc/nginx/sites-enabled/mainsail
/etc/init.d/nginx
/etc/default/nginx
)
#count+1 for each found data-item from array
for md in "${mainsail_data[@]}"
do
if [ -e $md ]; then
mcount=$(expr $mcount + 1)
fi
done
if [ "$mcount" == "${#mainsail_data[*]}" ]; then
MAINSAIL_STATUS="${green}Installed!${default} "
elif [ "$mcount" == 0 ]; then
MAINSAIL_STATUS="${red}Not installed!${default} "
else
MAINSAIL_STATUS="${yellow}Incomplete!${default} "
fi
}
read_branch(){
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then
cd $KLIPPER_DIR
GET_BRANCH=$(git branch -a | head -1 | cut -d " " -f5 | cut -d ")" -f1)
#if reading the branch gives an empty string
#we are on non-detached HEAD state on origin/master
#and need to set GET_BRANCH to make a non-empty string
if [ -z $GET_BRANCH ]; then
GET_BRANCH="origin/master"
fi
else
GET_BRANCH=""
fi
}
print_branch(){
read_branch
if [ "$GET_BRANCH" == "origin/master" ]; then
PRINT_BRANCH="${cyan}$GET_BRANCH${default} "
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then
PRINT_BRANCH="${cyan}scurve-shaping${default} "
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-smoothing" ]; then
PRINT_BRANCH="${cyan}scurve-smoothing${default} "
elif [ "$GET_BRANCH" == "Arksine/work-web_server-20200131" ]; then
PRINT_BRANCH="${cyan}moonraker${default} "
elif [ "$GET_BRANCH" == "Arksine/dev-moonraker-testing" ]; then
PRINT_BRANCH="${cyan}dev-moonraker${default} "
else
PRINT_BRANCH="${red}----${default} "
fi
}
read_local_klipper_commit(){
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then
cd $KLIPPER_DIR
LOCAL_COMMIT=$(git rev-parse --short=8 HEAD)
else
LOCAL_COMMIT=""
fi
}
read_remote_klipper_commit(){
read_branch
if [ ! -z $GET_BRANCH ];then
REMOTE_COMMIT=$(git rev-parse --short=8 $GET_BRANCH)
else
REMOTE_COMMIT=""
fi
}
compare_klipper_versions(){
read_local_klipper_commit
read_remote_klipper_commit
#echo "Local: $LOCAL_COMMIT"
#echo "Remote: $REMOTE_COMMIT"
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
LOCAL_COMMIT="${yellow}$LOCAL_COMMIT${default}"
REMOTE_COMMIT="${green}$REMOTE_COMMIT${default}"
else
LOCAL_COMMIT="${green}$LOCAL_COMMIT${default}"
REMOTE_COMMIT="${green}$REMOTE_COMMIT${default}"
fi
}
read_dwc2fk_versions(){
if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then
cd $DWC2FK_DIR
LOCAL_DWC2FK_COMMIT=$(git rev-parse --short=8 HEAD)
REMOTE_DWC2FK_COMMIT=$(git rev-parse --short=8 origin/master)
else
LOCAL_DWC2FK_COMMIT=""
REMOTE_DWC2FK_COMMIT=""
fi
}
compare_dwc2fk_versions(){
read_dwc2fk_versions
#echo "Local: $LOCAL_DWC2FK_COMMIT"
#echo "Remote: $REMOTE_DWC2FK_COMMIT"
if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then
LOCAL_DWC2FK_COMMIT="${yellow}$LOCAL_DWC2FK_COMMIT${default}"
REMOTE_DWC2FK_COMMIT="${green}$REMOTE_DWC2FK_COMMIT${default}"
else
LOCAL_DWC2FK_COMMIT="${green}$LOCAL_DWC2FK_COMMIT${default}"
REMOTE_DWC2FK_COMMIT="${green}$REMOTE_DWC2FK_COMMIT${default}"
fi
}
read_local_dwc2_version(){
if [ -e $DWC2_DIR/web/version ]; then
DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/web/version)
else
DWC2_LOCAL_VER=""
fi
}
read_remote_dwc2_version(){
DWC2_REMOTE_VER=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4)
}
compare_dwc2_versions(){
read_local_dwc2_version
read_remote_dwc2_version
#echo "Local: $DWC2_LOCAL_VER"
#echo "Remote: $DWC2_REMOTE_VER"
if [ "$DWC2_LOCAL_VER" != "$DWC2_REMOTE_VER" ]; then
DWC2_LOCAL_VER="${yellow}$DWC2_LOCAL_VER${default}"
DWC2_REMOTE_VER="${green}$DWC2_REMOTE_VER${default}"
else
DWC2_LOCAL_VER="${green}$DWC2_LOCAL_VER${default}"
DWC2_REMOTE_VER="${green}$DWC2_REMOTE_VER${default}"
fi
}
read_local_mainsail_version(){
if [ -e $MAINSAIL_DIR/version ]; then
MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/version)
else
MAINSAIL_LOCAL_VER=""
fi
}
read_remote_mainsail_version(){
get_mainsail_ver
MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION
}
compare_mainsail_versions(){
read_local_mainsail_version
read_remote_mainsail_version
#echo "Local: $MAINSAIL_LOCAL_VER"
#echo "Remote: $MAINSAIL_REMOTE_VER"
if [ "$MAINSAIL_LOCAL_VER" != "$MAINSAIL_REMOTE_VER" ]; then
MAINSAIL_LOCAL_VER="${yellow}$MAINSAIL_LOCAL_VER${default}"
MAINSAIL_REMOTE_VER="${green}$MAINSAIL_REMOTE_VER${default}"
else
MAINSAIL_LOCAL_VER="${green}$MAINSAIL_LOCAL_VER${default}"
MAINSAIL_REMOTE_VER="${green}$MAINSAIL_REMOTE_VER${default}"
fi
}
ui_print_versions(){
compare_klipper_versions
compare_dwc2fk_versions
compare_dwc2_versions
compare_mainsail_versions
}

View File

@@ -1,41 +0,0 @@
switch_to_origin(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
git fetch origin -q && git checkout origin/master -q
}
switch_to_scurve_shaping(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
if ! git remote | grep dmbutyugin -q; then
git remote add dmbutyugin $DMBUTYUGIN_REPO
fi
git fetch dmbutyugin -q && git checkout $BRANCH_SCURVE_SHAPING -q
}
switch_to_scurve_smoothing(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
if ! git remote | grep dmbutyugin -q; then
git remote add dmbutyugin $DMBUTYUGIN_REPO
fi
git fetch dmbutyugin -q && git checkout $BRANCH_SCURVE_SMOOTHING -q
}
switch_to_moonraker(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
if ! git remote | grep Arksine -q; then
git remote add Arksine $ARKSINE_REPO
fi
git fetch Arksine -q && git checkout $BRANCH_MOONRAKER -q
}
switch_to_dev_moonraker(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
if ! git remote | grep Arksine -q; then
git remote add Arksine $ARKSINE_REPO
fi
git fetch Arksine -q && git checkout $BRANCH_DEV_MOONRAKER -q
}

View File

@@ -0,0 +1,138 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function change_klipper_repo_menu() {
local repo_file="${KIAUH_SRCDIR}/klipper_repos.txt"
local repo branch repos=() branches=()
if [[ ! -f ${repo_file} ]]; then
print_error "File not found:\n '${KIAUH_SRCDIR}/klipper_repos.txt'"
return
fi
### generate the repolist from the klipper_repos.txt textfile
while IFS="," read -r repo branch; do
repo=$(echo "${repo}" | sed -r "s/^http(s)?:\/\/github.com\///" | sed "s/\.git$//" )
repos+=("${repo}")
### if branch is not given, default to 'master'
[[ -z ${branch} ]] && branch="master"
branches+=("${branch}")
done < <(grep -E "^[^#]" "${repo_file}")
top_border
echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | "
hr
blank_line
### print repolist
local i=0
for _ in "${repos[@]}"; do
printf "| %s) %-63s|\n" "${i}" "${yellow}${repos[${i}]}${white}${branches[${i}]}"
i=$(( i + 1 ))
done
blank_line
back_help_footer
local option
while true; do
read -p "${cyan}###### Perform action:${white} " option
case "${option}" in
0 | "$(( option < ${#repos[@]} ))")
select_msg "Repo: ${repos[option]} Branch: ${branches[option]}"
if [[ -d ${KLIPPER_DIR} ]]; then
top_border
echo -e "| ${red}!!! ATTENTION !!!${white} |"
echo -e "| Existing Klipper folder found! Proceeding will remove | "
echo -e "| the existing Klipper folder and replace it with a | "
echo -e "| clean copy of the previously selected source repo! | "
bottom_border
local yn
while true; do
read -p "${cyan}###### Proceed? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
switch_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
break;;
N|n|No|no)
select_msg "No"
break;;
*)
error_msg "Invalid command!";;
esac
done
else
status_msg "Set custom Klipper repository to:\n ● Repository: ${repos[${option}]}\n ● Branch: ${branches[${option}]}"
set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
ok_msg "This repo will now be used for new Klipper installations!\n"
fi
break;;
B|b)
clear && print_header
settings_menu
break;;
H|h)
clear && print_header
show_custom_klipper_repo_help
break;;
*)
error_msg "Invalid command!";;
esac
done
change_klipper_repo_menu
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function switch_klipper_repo() {
local repo=${1} branch=${2}
status_msg "Switching Klipper repository..."
do_action_service "stop" "klipper"
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
clone_klipper "${repo}" "${branch}"
do_action_service "start" "klipper"
}
function show_custom_klipper_repo_help() {
top_border
echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |"
hr
echo -e "| With this setting, it is possible to install Klipper |"
echo -e "| from a custom repository. It will also switch an |"
echo -e "| existing Klipper installation to the newly selected |"
echo -e "| source repository. |"
echo -e "| A list of repositories is automatically generated by |"
echo -e "| a 'klipper_repos.txt' textfile in KIAUHs root folder. |"
echo -e "| An example file is provided at the same location. |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
B|b)
clear && print_header
change_klipper_repo_menu
break;;
*)
deny_action "show_settings_help";;
esac
done
}

View File

@@ -1,154 +0,0 @@
### set up some UI stuff
#ui total width = 57 chars
top_border(){
echo -e "/=======================================================\ "
}
bottom_border(){
echo -e "\=======================================================/"
}
hr(){
echo -e "|-------------------------------------------------------|"
}
quit_footer(){
hr
echo -e "| ${red}Q) Quit${default} | "
bottom_border
}
print_header(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |"
echo -e "| $(title_msg " Klipper Installation And Update Helper ") |"
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |"
bottom_border
}
main_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr
echo -e "| 0) [System status] | |"
echo -e "| | Klipper: $KLIPPER_STATUS|"
echo -e "| 1) [Install] | Branch: $PRINT_BRANCH|"
echo -e "| 2) [Update] | |"
echo -e "| 3) [Remove] | DWC2: $DWC2_STATUS|"
echo -e "| | Mainsail: $MAINSAIL_STATUS|"
echo -e "| 4) [Advanced] | Octoprint: #### WIP #### |"
echo -e "| 5) [Backup] | |"
quit_footer
}
install_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~") | "
hr
echo -e "| You need this menu usually only for installing | "
echo -e "| all necessary dependencies for the various | "
echo -e "| functions on a completely fresh system. | "
hr
echo -e "| Firmware: | | "
echo -e "| 1) [Klipper] | | "
echo -e "| | | "
echo -e "| Webinterface: | | "
echo -e "| 2) [DWC2] | | "
echo -e "| 3) [Mainsail] | | "
echo -e "| | | "
quit_footer
}
update_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~") | "
hr
echo -e "| It's a good idea to check the following website | "
echo -e "| for important software changes to the config file | "
echo -e "| BEFORE updating your klipper installation: | "
echo -e "| | "
echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | "
bottom_border
top_border
echo -e "| 0) $BB4U_STATUS| "
hr
echo -e "| | Local Vers: | Remote Vers: | "
echo -e "| Firmware: | | | "
echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | "
echo -e "| | | | "
echo -e "| Webinterface: | | | "
echo -e "| 2) [DWC2-for-Klipper] | $(echo "$LOCAL_DWC2FK_COMMIT") | $(echo "$REMOTE_DWC2FK_COMMIT") | "
echo -e "| 3) [DWC2 Web UI] | $(echo "$DWC2_LOCAL_VER") | $(echo "$DWC2_REMOTE_VER") | "
echo -e "| 4) [Mainsail] | $(echo "$MAINSAIL_LOCAL_VER") | $(echo "$MAINSAIL_REMOTE_VER") | "
echo -e "| | | | "
quit_footer
}
remove_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~") | "
hr
echo -e "| Files and directories which remain untouched: | "
echo -e "| --> ~/printer.cfg | "
echo -e "| --> ~/backup | "
echo -e "| You need remove them manually if you wish so. | "
hr
echo -e "| 1) [Klipper] | | "
echo -e "| 2) [DWC2-for-Klipper] | | "
echo -e "| 3) [Mainsail] | | "
echo -e "| | | "
quit_footer
}
advanced_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~") | "
hr
echo -e "| 1) [Switch Klipper version] | "
echo -e "| | "
echo -e "| 2) [Build Firmware] | "
echo -e "| 3) [Flash MCU] | "
echo -e "| 4) [Get Printer-ID] | "
echo -e "| 5) [Write Printer-ID to printer.cfg] | "
echo -e "| 6) [Write DWC2-for-klipper config] | "
echo -e "| | "
echo -e "| x) [Enable/Disable Octoprint service] | "
echo -e "| | "
quit_footer
}
backup_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | "
hr
echo -e "| | "
hr
echo -e "| 1) [ ] | "
echo -e "| 2) [ ] | "
echo -e "| 3) [ ] | "
echo -e "| 4) [ ] | "
echo -e "| 5) [ ] | "
echo -e "| 6) [ ] | "
echo -e "| 7) [ ] | "
echo -e "| | "
quit_footer
}
switch_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |"
bottom_border
echo
echo -e " $(title_msg "Active branch: ")${green}$GET_BRANCH${default}"
echo
top_border
echo -e "| 1) [--> origin/master] | "
echo -e "| | "
echo -e "| 2) [--> scurve-shaping] | "
echo -e "| 3) [--> scurve-smoothing] | "
echo -e "| | "
echo -e "| 4) [--> moonraker] | "
echo -e "| 5) [--> dev-moonraker] | "
quit_footer
}

69
scripts/ui/advanced_menu.sh Executable file
View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function advanced_ui() {
top_border
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} |"
hr
echo -e "| Klipper & API: | Mainsail: |"
echo -e "| 1) [Rollback] | 6) [Theme installer] |"
echo -e "| | |"
echo -e "| Firmware: | System: |"
echo -e "| 2) [Build only] | 7) [Change hostname] |"
echo -e "| 3) [Flash only] | |"
echo -e "| 4) [Build + Flash] | Extras: |"
echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] |"
back_footer
}
function advanced_menu() {
do_action "" "advanced_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
1)
do_action "rollback_menu" "advanced_menu";;
2)
do_action "build_fw" "advanced_ui";;
3)
clear && print_header
do_action "init_flash_process" "advanced_ui";;
4)
clear && print_header
status_msg "Please wait..."
build_fw && init_flash_process
advanced_ui;;
5)
clear && print_header
select_mcu_connection
print_detected_mcu_to_screen
advanced_ui;;
6)
do_action "ms_theme_installer_menu";;
7)
clear
print_header
set_custom_hostname
advanced_ui;;
8)
do_action "setup_gcode_shell_command" "advanced_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "advanced_ui";;
esac
done
advanced_menu
}

64
scripts/ui/backup_menu.sh Executable file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function backup_ui() {
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") |"
hr
echo -e "| ${yellow}INFO: Backups are located in '~/kiauh-backups'${white} |"
hr
echo -e "| Klipper & API: | Touchscreen GUI: |"
echo -e "| 1) [Klipper] | 7) [KlipperScreen] |"
echo -e "| 2) [Moonraker] | |"
echo -e "| 3) [Configuration Folder] | 3rd Party Webinterface: |"
echo -e "| 4) [Moonraker Database] | 8) [OctoPrint] |"
echo -e "| | |"
echo -e "| Klipper Webinterface: | Other: |"
echo -e "| 5) [Mainsail] | 9) [Telegram Bot] |"
echo -e "| 6) [Fluidd] | |"
back_footer
}
function backup_menu() {
do_action "" "backup_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
1)
do_action "backup_klipper" "backup_ui";;
2)
do_action "backup_moonraker" "backup_ui";;
3)
do_action "backup_klipper_config_dir" "backup_ui";;
4)
do_action "backup_moonraker_database" "backup_ui";;
5)
do_action "backup_mainsail" "backup_ui";;
6)
do_action "backup_fluidd" "backup_ui";;
7)
do_action "backup_klipperscreen" "backup_ui";;
8)
do_action "backup_octoprint" "backup_ui";;
9)
do_action "backup_telegram_bot" "backup_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "backup_ui";;
esac
done
backup_menu
}

70
scripts/ui/general_ui.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#ui total width = 57 chars
function top_border() {
echo -e "/=======================================================\\"
}
function bottom_border() {
echo -e "\=======================================================/"
}
function blank_line() {
echo -e "| |"
}
function hr() {
echo -e "|-------------------------------------------------------|"
}
function quit_footer() {
hr
echo -e "| ${red}Q) Quit${white} |"
bottom_border
}
function back_footer() {
hr
echo -e "| ${green}B) « Back${white} |"
bottom_border
}
function back_help_footer() {
hr
echo -e "| ${green}B) « Back${white} | ${yellow}H) Help [?]${white} |"
bottom_border
}
function print_header() {
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |"
echo -e "| $(title_msg " Klipper Installation And Update Helper ") |"
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |"
bottom_border
}
function 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
}
function deny_action() {
clear && print_header
print_error "Invalid command!"
$1
}

98
scripts/ui/install_menu.sh Executable file
View File

@@ -0,0 +1,98 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function install_ui() {
top_border
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} |"
hr
echo -e "| You need this menu usually only for installing |"
echo -e "| all necessary dependencies for the various |"
echo -e "| functions on a completely fresh system. |"
hr
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
echo -e "| 2) [Moonraker] | |"
echo -e "| | Other: |"
echo -e "| Klipper Webinterface: | 7) [PrettyGCode] |"
echo -e "| 3) [Mainsail] | 8) [Telegram Bot] |"
echo -e "| 4) [Fluidd] | |"
echo -e "| | Webcam Streamer: |"
echo -e "| Touchscreen GUI: | 9) [MJPG-Streamer] |"
echo -e "| 5) [KlipperScreen] | |"
back_footer
}
function install_menu() {
clear && print_header
install_ui
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
1)
do_action "select_klipper_python_version" "install_ui";;
2)
do_action "moonraker_setup_dialog" "install_ui";;
3)
do_action "install_mainsail" "install_ui";;
4)
do_action "install_fluidd" "install_ui";;
5)
do_action "install_klipperscreen" "install_ui";;
6)
do_action "octoprint_setup_dialog" "install_ui";;
7)
do_action "install_pgc_for_klipper" "install_ui";;
8)
do_action "telegram_bot_setup_dialog" "install_ui";;
9)
do_action "install_mjpg-streamer" "install_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "install_ui";;
esac
done
install_menu
}
function select_klipper_python_version() {
top_border
echo -e "| Please select the preferred Python version. | "
echo -e "| The recommended version is Python 2.7. | "
blank_line
echo -e "| Installing Klipper with Python 3 is officially not | "
echo -e "| recommended and should be considered as experimental. | "
hr
echo -e "| 1) [Python 2.7] (recommended) | "
echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | "
back_footer
while true; do
read -p "${cyan}###### Select Python version:${white} " action
case "${action}" in
1)
select_msg "Python 2.7"
klipper_setup_dialog "python2"
break;;
2)
select_msg "Python 3.x"
klipper_setup_dialog "python3"
break;;
B|b)
clear; install_menu; break;;
*)
error_msg "Invalid Input!\n";;
esac
done
}

127
scripts/ui/main_menu.sh Executable file
View File

@@ -0,0 +1,127 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function main_ui() {
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr
echo -e "| 0) [Log-Upload] | Klipper: $(print_status "klipper")|"
echo -e "| | Repo: $(print_klipper_repo)|"
echo -e "| 1) [Install] | |"
echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|"
echo -e "| 3) [Remove] | |"
echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|"
echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|"
echo -e "| | KlipperScreen: $(print_status "klipperscreen")|"
echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|"
echo -e "| | |"
echo -e "| $(print_kiauh_version)| Octoprint: $(print_status "octoprint")|"
quit_footer
}
function get_kiauh_version() {
local version
cd "${KIAUH_SRCDIR}"
version="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${version}"
}
function print_kiauh_version() {
local version
version="$(printf "%-18s" "$(get_kiauh_version)")"
echo "${cyan}${version}${white}"
}
function print_status() {
local status component="${1}"
status=$(get_"${component}"_status)
if [[ ${status} == "Not installed!" ]]; then
status="${red}${status}${white}"
elif [[ ${status} == "Incomplete!" ]]; then
status="${yellow}${status}${white}"
else
status="${green}${status}${white}"
fi
printf "%-28s" "${status}"
}
function print_klipper_repo() {
read_kiauh_ini
local repo klipper_status
klipper_status=$(get_klipper_status)
repo=$(echo "${custom_klipper_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//")
repo="${repo^^}"
if [[ ${klipper_status} == "Not installed!" ]]; then
repo="${red}-${white}"
elif [[ -n ${repo} && ${repo} != "KLIPPER3D/KLIPPER" ]]; then
repo="${cyan}custom${white}"
else
repo="${cyan}Klipper3d/klipper${white}"
fi
printf "%-28s" "${repo}"
}
function main_menu() {
print_header && main_ui
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
"start klipper") do_action_service "start" "klipper"; main_ui;;
"stop klipper") do_action_service "stop" "klipper"; main_ui;;
"restart klipper") do_action_service "restart" "klipper"; main_ui;;
"start moonraker") do_action_service "start" "moonraker"; main_ui;;
"stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
"restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
"start octoprint") do_action_service "start" "octoprint"; main_ui;;
"stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
"restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
update) do_action "update_kiauh" "main_ui";;
0)clear && print_header
upload_selection
break;;
1)clear && print_header
install_menu
break;;
2) clear && print_header
update_menu
break;;
3) clear && print_header
remove_menu
break;;
4)clear && print_header
advanced_menu
break;;
5)clear && print_header
backup_menu
break;;
6)clear && print_header
settings_menu
break;;
Q|q)
echo -e "${green}###### Happy printing! ######${white}"; echo
exit 0;;
*)
deny_action "main_ui";;
esac
done
clear; main_menu
}

67
scripts/ui/remove_menu.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function remove_ui() {
top_border
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} |"
hr
echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |"
hr
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
echo -e "| 2) [Moonraker] | |"
echo -e "| | Webcam Streamer: |"
echo -e "| Klipper Webinterface: | 7) [MJPG-Streamer] |"
echo -e "| 3) [Mainsail] | |"
echo -e "| 4) [Fluidd] | Other: |"
echo -e "| | 8) [PrettyGCode] |"
echo -e "| Touchscreen GUI: | 9) [Telegram Bot] |"
echo -e "| 5) [KlipperScreen] | 10) [NGINX] |"
back_footer
}
function remove_menu() {
do_action "" "remove_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
1)
do_action "remove_klipper" "remove_ui";;
2)
do_action "remove_moonraker" "remove_ui";;
3)
do_action "remove_mainsail" "remove_ui";;
4)
do_action "remove_fluidd" "remove_ui";;
5)
do_action "remove_klipperscreen" "remove_ui";;
6)
do_action "remove_octoprint" "remove_ui";;
7)
do_action "remove_mjpg-streamer" "remove_ui";;
8)
do_action "remove_prettygcode" "remove_ui";;
9)
do_action "remove_telegram_bot" "remove_ui";;
10)
do_action "remove_nginx" "remove_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "remove_ui";;
esac
done
remove_menu
}

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

@@ -0,0 +1,191 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function settings_ui() {
read_kiauh_ini "${FUNCNAME[0]}"
local custom_cfg_loc="${custom_klipper_cfg_loc}"
local custom_repo="${custom_klipper_repo}"
local custom_branch="${custom_klipper_repo_branch}"
local ms_pre_rls="${mainsail_install_unstable}"
local fl_pre_rls="${fluidd_install_unstable}"
local bbu="${backup_before_update}"
### config location
if [[ -z ${custom_cfg_loc} ]]; then
custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}"
else
custom_cfg_loc="${cyan}${custom_cfg_loc}${white}"
fi
### custom repository
custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" )
if [[ -z ${custom_repo} ]]; then
custom_repo="${cyan}Klipper3D/klipper${white}"
else
custom_repo="${cyan}${custom_repo}${white}"
fi
### custom repository branch
if [[ -z ${custom_branch} ]]; then
custom_branch="${cyan}master${white}"
else
custom_branch="${cyan}${custom_branch}${white}"
fi
### webinterface stable toggle
if [[ ${ms_pre_rls} == "false" ]]; then
ms_pre_rls="${red}${ms_pre_rls}${white}"
else
ms_pre_rls="${green}${ms_pre_rls}${white}"
fi
if [[ ${fl_pre_rls} == "false" ]]; then
fl_pre_rls="${red}${fl_pre_rls}${white}"
else
fl_pre_rls="${green}${fl_pre_rls}${white}"
fi
### backup before update toggle
if [[ "${bbu}" == "false" ]]; then
bbu="${red}${bbu}${white}"
else
bbu="${green}${bbu}${white}"
fi
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |"
hr
echo -e "| Klipper: |"
echo -e "| ● Config folder: |"
printf "| %-60s|\n" "${custom_cfg_loc}"
echo -e "| ● Repository: |"
printf "| %-70s|\n" "${custom_repo} (${custom_branch})"
hr
echo -e "| Install unstable releases: |"
printf "| Mainsail: %-29sFluidd: %-27s|\n" "${ms_pre_rls}" "${fl_pre_rls}"
hr
printf "| Backup before updating: %-42s|\n" "${bbu}"
hr
echo -e "| 1) Change Klipper config folder location |"
echo -e "| 2) Set custom Klipper repository |"
blank_line
if [[ ${mainsail_install_unstable} == "false" ]]; then
echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |"
else
echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |"
fi
if [[ ${fluidd_install_unstable} == "false" ]]; then
echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |"
else
echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |"
fi
blank_line
if [[ ${backup_before_update} == "false" ]]; then
echo -e "| 5) ${green}Enable${white} automatic backups before updates |"
else
echo -e "| 5) ${red}Disable${white} automatic backups before updates |"
fi
back_help_footer
}
function show_settings_help() {
local default_cfg="${cyan}${HOME}/klipper_config${white}"
top_border
echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |"
hr
echo -e "| ${cyan}Klipper config folder:${white} |"
echo -e "| The location of your printer.cfg and all other config |"
echo -e "| files that gets used during installation of Klipper |"
echo -e "| and all other components which need that location. |"
echo -e "| It is not recommended to change this location. |"
echo -e "| Be advised, that negative side effects could occur. |"
blank_line
printf "| Default: %-55s|\n" "${default_cfg}"
blank_line
hr
echo -e "| ${cyan}Install unstable releases:${white} |"
echo -e "| If set to ${green}true${white}, KIAUH installs/updates the software |"
echo -e "| with the latest, currently available release. |"
echo -e "| ${yellow}This will include alpha, beta and rc releases!${white} |"
blank_line
echo -e "| If set to ${red}false${white}, KIAUH installs/updates the software |"
echo -e "| with the most recent stable release. |"
blank_line
echo -e "| Default: ${red}false${white} |"
blank_line
hr
echo -e "| ${cyan}Backup before updating:${white} |"
echo -e "| If set to true, KIAUH will automatically create a |"
echo -e "| backup from the corresponding component you are about |"
echo -e "| to update before actually updating it, preserving the |"
echo -e "| current state of the component in a safe location. |"
echo -e "| All backups are stored in '~/kiauh_backups'. |"
blank_line
echo -e "| Default: ${red}false${white} |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
B|b)
clear && print_header
settings_menu
break;;
*)
deny_action "show_settings_help";;
esac
done
}
function settings_menu() {
clear && print_header
settings_ui
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
1)
clear && print_header
change_klipper_cfg_folder
settings_ui;;
2)
clear && print_header
change_klipper_repo_menu
settings_ui;;
3)
switch_mainsail_releasetype
settings_menu;;
4)
switch_fluidd_releasetype
settings_menu;;
5)
toggle_backup_before_update
settings_menu;;
B|b)
clear
main_menu
break;;
H|h)
clear && print_header
show_settings_help
break;;
*)
deny_action "settings_ui";;
esac
done
}

131
scripts/ui/update_menu.sh Executable file
View File

@@ -0,0 +1,131 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function update_ui() {
top_border
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} |"
hr
echo -e "| a) [Update all] | | |"
echo -e "| | Installed: | Latest: |"
echo -e "| Klipper & API: |---------------|--------------|"
echo -e "| 1) [Klipper] |$(compare_klipper_versions)|"
echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)|"
echo -e "| | | |"
echo -e "| Klipper Webinterface: |---------------|--------------|"
echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)|"
echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)|"
echo -e "| | | |"
echo -e "| Touchscreen GUI: |---------------|--------------|"
echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)|"
echo -e "| | | |"
echo -e "| Other: |---------------|--------------|"
echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)|"
echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)|"
echo -e "| |------------------------------|"
echo -e "| 8) [System] | $(check_system_updates) |"
back_footer
}
function update_menu() {
unset update_arr
do_action "" "update_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
0)
do_action "toggle_backups" "update_ui";;
1)
do_action "update_klipper" "update_ui";;
2)
do_action "update_moonraker" "update_ui";;
3)
do_action "update_mainsail" "update_ui";;
4)
do_action "update_fluidd" "update_ui";;
5)
do_action "update_klipperscreen" "update_ui";;
6)
do_action "update_pgc_for_klipper" "update_ui";;
7)
do_action "update_telegram_bot" "update_ui";;
8)
do_action "update_system" "update_ui";;
a)
do_action "update_all" "update_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "update_ui";;
esac
done
update_menu
}
function update_all() {
while true; do
if (( ${#update_arr[@]} == 0 )); then
print_confirm "Everything is already up-to-date!"
echo; break
fi
echo
top_border
echo -e "| The following installations will be updated: |"
if [[ "${KLIPPER_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Klipper${white} |"
fi
if [[ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Moonraker${white} |"
fi
if [[ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Mainsail${white} |"
fi
if [[ "${FLUIDD_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Fluidd${white} |"
fi
if [[ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● KlipperScreen${white} |"
fi
if [[ "${PGC_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● PrettyGCode for Klipper${white} |"
fi
if [[ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● MoonrakerTelegramBot${white} |"
fi
if [[ "${SYS_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● System${white} |"
fi
bottom_border
local yn
if (( ${#update_arr[@]} != 0 )); then
read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
for update in "${update_arr[@]}"
do
#shellcheck disable=SC2250
$update
done
break;;
N|n|No|no)
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
fi
done
}

View File

@@ -1,77 +0,0 @@
#TODO
# - update the correct branch
# - version checks before updating
#WIP
update_check(){
read_local_commit
read_remote_commit
}
update_klipper(){
stop_klipper
bb4u_klipper
if [ ! -d $KLIPPER_DIR ]; then
cd ${HOME} && git clone $KLIPPER_REPO
else
read_branch
status_msg "Updating $GET_BRANCH"
#fetching origin/master -> error
#rewriting origin/master to origin
if [ "$GET_BRANCH" == "origin/master" ]; then
FETCH_BRANCH="origin"
else
FETCH_BRANCH=$(echo "$GET_BRANCH" | cut -d "/" -f1)
fi
status_msg "Fetching from $FETCH_BRANCH"
git fetch $FETCH_BRANCH -q && ok_msg "Fetch successfull!"
status_msg "Checking out $GET_BRANCH"
git checkout $GET_BRANCH -q && ok_msg "Checkout successfull!" && echo; ok_msg "Update complete!"
fi
start_klipper; echo
}
update_dwc2fk(){
stop_klipper
bb4u_dwc2fk
if [ ! -d $DWC2FK_DIR ]; then
cd ${HOME} && git clone $DWC2FK_REPO
else
cd $DWC2FK_DIR && git pull
#create a web_dwc2.py symlink if not already existing
if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -e $WEB_DWC2 ]; then
status_msg "Creating web_dwc2.py symlink ..."
ln -s $DWC2FK_DIR/web_dwc2.py $WEB_DWC2 && ok_msg "Symlink created!"
fi
fi
start_klipper
}
update_dwc2(){
bb4u_dwc2
#check dependencies
dep=(wget gzip tar curl)
dep_check
#execute operation
GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4`
if [ ! -d $DWC2_DIR/web ]; then
mkdir -p $DWC2_DIR/web
fi
cd $DWC2_DIR/web
status_msg "Downloading DWC2 Web UI ..."
wget -q $GET_DWC2_URL && ok_msg "Download complete!"
status_msg "Unzipping archive ..."
unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!"
status_msg "Writing version to file ..."
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!"
status_msg "Do a little cleanup ..."
rm -rf DuetWebControl-SD.zip && ok_msg "Done!"
}
update_mainsail(){
stop_klipper
bb4u_mainsail
status_msg "Updating Mainsail ..."
install_mainsail
start_klipper
}

122
scripts/upload_log.sh Executable file
View File

@@ -0,0 +1,122 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function accept_upload_conditions() {
top_border
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |"
hr
echo -e "| The following function will help to quickly upload |"
echo -e "| logs for debugging purposes. With confirming this |"
echo -e "| dialog, you agree that during that process your logs |"
echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |"
hr
echo -e "| ${red}PLEASE NOTE:${white} |"
echo -e "| Be aware that logs can contain network information, |"
echo -e "| private data like usernames, filenames, or other |"
echo -e "| information you may not want to make public. |"
blank_line
echo -e "| Do ${red}NOT${white} use this function if you don't agree! |"
bottom_border
local yn
while true; do
read -p "${cyan}Do you accept? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
sed -i "/logupload_accepted=/s/false/true/" "${INI_FILE}"
clear && print_header && upload_selection
;;
N|n|No|no)
clear
main_menu
break
;;
*)
error_msg "Invalid command!";;
esac
done
}
function upload_selection() {
read_kiauh_ini "${FUNCNAME[0]}"
local upload_agreed="${logupload_accepted}"
[[ ${upload_agreed} == "false" ]] && accept_upload_conditions
local logfiles
local logs_dir="${KLIPPER_LOGS}"
local webif_logs="/var/log/nginx"
function find_logfile() {
local name=${1} location=${2}
for log in $(find "${location}" -maxdepth 1 -regextype posix-extended -regex "${location}/${name}" | sort -g); do
logfiles+=("${log}")
done
}
find_logfile "kiauh\.log" "/tmp"
find_logfile "klippy(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
find_logfile "moonraker(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
find_logfile "telegram(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
find_logfile "mainsail.*" "${webif_logs}"
find_logfile "fluidd.*" "${webif_logs}"
find_logfile "KlipperScreen.log" "/tmp"
find_logfile "webcamd\.log(\.[0-9]+)?$" "/var/log"
### draw interface
local i=0
top_border
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |"
hr
echo -e "| You can choose the following logfiles for uploading: |"
blank_line
for log in "${logfiles[@]}"; do
log=${log//${HOME}/"~"}
(( i < 10 )) && printf "| ${i}) %-50s|\n" "${log}"
(( i >= 10 )) && printf "| ${i}) %-50s|\n" "${log}"
i=$(( i + 1 ))
done
blank_line
back_footer
local option re="^[0-9]+$"
while true; do
read -p "${cyan}###### Please select:${white} " option
if [[ ${option} =~ ${re} && ${option} -lt ${#logfiles[@]} ]]; then
upload_log "${logfiles[${option}]}"
upload_selection
elif [[ ${option} == "B" || ${option} == "b" ]]; then
return
else
error_msg "Invalid command!"
fi
done
}
function upload_log() {
local link
clear && print_header
status_msg "Uploading ${1} ..."
link=$(curl -s -H "x-random;" --upload-file "${1}" 'http://paste.c-net.org/')
if [[ -n ${link} ]]; then
ok_msg "${1} upload successfull!"
echo -e "\n${cyan}###### Here is your link:${white}"
echo -e ">>>>>> ${link}\n"
else
error_msg "Uploading failed!"
fi
}

654
scripts/utilities.sh Normal file
View File

@@ -0,0 +1,654 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#================================================#
#=================== STARTUP ====================#
#================================================#
function check_euid() {
if [[ ${EUID} -eq 0 ]]; then
echo -e "${red}"
top_border
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
bottom_border
echo -e "${white}"
exit 1
fi
}
#================================================#
#============= MESSAGE FORMATTING ===============#
#================================================#
function select_msg() {
echo -e "${white} [➔] ${1}"
}
function status_msg() {
echo -e "\n${magenta}###### ${1}${white}"
}
function ok_msg() {
echo -e "${green}[✓ OK] ${1}${white}"
}
function warn_msg() {
echo -e "${yellow}>>>>>> ${1}${white}"
}
function error_msg() {
echo -e "${red}>>>>>> ${1}${white}"
}
function abort_msg() {
echo -e "${red}<<<<<< ${1}${white}"
}
function title_msg() {
echo -e "${cyan}${1}${white}"
}
function print_error() {
[[ -z ${1} ]] && return
echo -e "${red}"
echo -e "#=======================================================#"
echo -e " ${1} "
echo -e "#=======================================================#"
echo -e "${white}"
}
function print_confirm() {
[[ -z ${1} ]] && return
echo -e "${green}"
echo -e "#=======================================================#"
echo -e " ${1} "
echo -e "#=======================================================#"
echo -e "${white}"
}
#================================================#
#=================== LOGGING ====================#
#================================================#
function timestamp() {
date +"[%F %T]"
}
function init_logfile() {
local log="/tmp/kiauh.log"
{
echo -e "#================================================================#"
echo -e "# New KIAUH session started on: $(date) #"
echo -e "#================================================================#"
echo -e "KIAUH $(get_kiauh_version)"
echo -e "#================================================================#"
} >> "${log}"
}
function log_info() {
local message="${1}" log="${LOGFILE}"
echo -e "$(timestamp) [INFO]: ${message}" | tr -s " " >> "${log}"
}
function log_warning() {
local message="${1}" log="${LOGFILE}"
echo -e "$(timestamp) [WARN]: ${message}" | tr -s " " >> "${log}"
}
function log_error() {
local message="${1}" log="${LOGFILE}"
echo -e "$(timestamp) [ERR]: ${message}" | tr -s " " >> "${log}"
}
#================================================#
#=============== KIAUH SETTINGS =================#
#================================================#
function read_kiauh_ini() {
local func=${1}
if [[ ! -f ${INI_FILE} ]]; then
log_warning "Reading from .kiauh.ini failed! File not found! Creating default ini file."
init_ini
fi
log_info "Reading from .kiauh.ini ... (${func})"
source "${INI_FILE}"
}
function init_ini() {
### remove pre-version 4 ini files
if [[ -f ${INI_FILE} ]] && ! grep -Eq "^# KIAUH v4\.0\.0$" "${INI_FILE}"; then
rm "${INI_FILE}"
fi
### initialize v4.0.0 ini file
if [[ ! -f ${INI_FILE} ]]; then
{
echo -e "# File creation date: $(date)"
echo -e "#=================================================#"
echo -e "# KIAUH - Klipper Installation And Update Helper #"
echo -e "# https://github.com/th33xitus/kiauh #"
echo -e "# DO NOT edit this file! #"
echo -e "#=================================================#"
echo -e "# KIAUH v4.0.0"
} >> "${INI_FILE}"
fi
if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then
echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^logupload_accepted=." "${INI_FILE}"; then
echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_repo_branch=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_repo_branch=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then
echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^fluidd_install_unstable=" "${INI_FILE}"; then
echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}"
fi
fetch_webui_ports
}
function change_klipper_cfg_folder() {
local current_cfg_loc example_loc recommended_loc new_cfg_loc
current_cfg_loc="$(get_klipper_cfg_dir)"
example_loc=$(printf "%s/<your_config_folder>" "${HOME}")
recommended_loc=$(printf "%s/klipper_config" "${HOME}")
local yn
while true; do
top_border
echo -e "| ${yellow}IMPORTANT:${white} |"
echo -e "| Please enter the new path in the following format: |"
printf "| ${cyan}%-51s${white} |\n" "${example_loc}"
blank_line
echo -e "| ${red}WARNING: ${white} |"
echo -e "| ${red}There will be no validation checks! Make sure to set${white} |"
echo -e "| ${red}a valid directory to prevent possible problems!${white} |"
blank_line
printf "| Recommended: ${cyan}%-38s${white} |\n" "${recommended_loc}"
bottom_border
echo
echo -e "${cyan}###### Please set the new Klipper config directory:${white} "
read -e -i "${current_cfg_loc}" -e new_cfg_loc
echo
read -p "${cyan}###### Set config directory to '${yellow}${new_cfg_loc}${cyan}' ? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
set_klipper_cfg_path "${current_cfg_loc}" "${new_cfg_loc}"
print_confirm "New config directory set!"
break;;
N|n|No|no)
select_msg "No"
break;;
*)
print_error "Invalid command!";;
esac
done
}
function set_klipper_cfg_path() {
local current_cfg_loc="${1}" new_cfg_loc="${2}"
local instance klipper_services moonraker_services moonraker_configs
log_info "Function set_klipper_cfg_path invoked\nCurrent location: ${1}\nNew location: ${2}"
### backup the old config dir
backup_klipper_config_dir
### write new location to .kiauh.ini
sed -i "/^custom_klipper_cfg_loc=/d" "${INI_FILE}"
sed -i '$a'"custom_klipper_cfg_loc=${new_cfg_loc}" "${INI_FILE}"
status_msg "New directory was set to '${new_cfg_loc}'!"
### stop services
do_action_service "stop" "klipper"
do_action_service "stop" "moonraker"
### copy config files to new klipper config folder
if [[ -n ${current_cfg_loc} && -d ${current_cfg_loc} ]]; then
status_msg "Copy config files to '${new_cfg_loc}' ..."
if [[ ! -d ${new_cfg_loc} ]]; then
log_info "Copy process started"
mkdir -p "${new_cfg_loc}"
cd "${current_cfg_loc}"
cp -r -v ./* "${new_cfg_loc}"
ok_msg "Done!"
else
log_warning "Copy process skipped, new config directory already exists and may not be empty!"
warn_msg "New config directory already exists! Copy process skipped!"
fi
fi
klipper_services=$(klipper_systemd)
if [[ -n ${klipper_services} ]]; then
status_msg "Re-writing Klipper services to use new config file location ..."
for service in ${klipper_services}; do
if [[ ${service} = "/etc/systemd/system/klipper.service" ]]; then
if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then
### single instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer\.cfg|CONFIG=${new_cfg_loc}/printer\.cfg|" "${service}"
else
### single instance klipper service installed by kiauh v3
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer\.cfg|" "${service}"
fi
else
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then
### multi instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer_${instance}\/printer\.cfg|CONFIG=${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
else
### multi instance klipper service installed by kiauh v3
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer_${instance}\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
fi
fi
done
ok_msg "OK!"
fi
moonraker_services=$(moonraker_systemd)
if [[ -n ${moonraker_services} ]]; then
### handle multi moonraker instance service file
status_msg "Re-writing Moonraker services to use new config file location ..."
for service in ${moonraker_services}; do
if [[ ${service} = "/etc/systemd/system/moonraker.service" ]]; then
if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then
### single instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/moonraker\.conf|_CONF=${new_cfg_loc}\/moonraker\.conf|" "${service}"
else
### single instance moonraker service installed by kiauh v3
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/moonraker\.conf| -c ${new_cfg_loc}\/moonraker\.conf|" "${service}"
fi
else
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then
### multi instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/printer_${instance}\/moonraker\.conf|_CONF=${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
else
### multi instance moonraker service installed by kiauh v3
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/printer_${instance}\/moonraker\.conf| -c ${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
fi
fi
done
moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf" | sort)
### replace old file path with new one in moonraker.conf
local loc
for conf in ${moonraker_configs}; do
loc=$(echo "${conf}" | rev | cut -d"/" -f2- | rev)
sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${conf}"
done
ok_msg "OK!"
fi
### reloading units
sudo systemctl daemon-reload
### restart services
do_action_service "restart" "klipper"
do_action_service "restart" "moonraker"
}
function switch_mainsail_releasetype() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${mainsail_install_unstable}"
if [[ ${state} == "false" ]]; then
sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}"
log_info "mainsail_install_unstable changed (false -> true) "
else
sed -i '/mainsail_install_unstable=/s/true/false/' "${INI_FILE}"
log_info "mainsail_install_unstable changed (true -> false) "
fi
}
function switch_fluidd_releasetype() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${fluidd_install_unstable}"
if [[ ${state} == "false" ]]; then
sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}"
log_info "fluidd_install_unstable changed (false -> true) "
else
sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}"
log_info "fluidd_install_unstable changed (true -> false) "
fi
}
function toggle_backup_before_update() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${backup_before_update}"
if [[ ${state} = "false" ]]; then
sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}"
else
sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}"
fi
}
function set_custom_klipper_repo() {
read_kiauh_ini "${FUNCNAME[0]}"
local repo=${1} branch=${2}
sed -i "/^custom_klipper_repo=/d" "${INI_FILE}"
sed -i '$a'"custom_klipper_repo=${repo}" "${INI_FILE}"
sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}"
sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}"
}
#================================================#
#=============== HANDLE SERVICES ================#
#================================================#
function do_action_service() {
local services action=${1} service=${2}
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[0-9a-zA-Z]+)?.service" | sort)
if [[ -n ${services} ]]; then
for service in ${services}; do
service=$(echo "${service}" | rev | cut -d"/" -f1 | rev)
status_msg "${action^} ${service} ..."
if sudo systemctl "${action}" "${service}"; then
log_info "${service}: ${action} > success"
ok_msg "${action^} ${service} successfull!"
else
log_warning "${service}: ${action} > failed"
warn_msg "${action^} ${service} failed!"
fi
done
fi
}
#================================================#
#================ DEPENDENCIES ==================#
#================================================#
### returns 'true' if python version >= 3.7
function python3_check() {
local major minor passed
major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1)
minor=$(python3 --version | cut -d"." -f2)
if (( major >= 3 && minor >= 7 )); then
passed="true"
else
passed="false"
fi
echo "${passed}"
}
function dependency_check() {
local dep=( "${@}" )
local packages
status_msg "Checking for the following dependencies:"
#check if package is installed, if not write its name into array
for pkg in "${dep[@]}"; do
echo -e "${cyan}${pkg} ${white}"
[[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]] && \
packages+=("${pkg}")
done
#if array is not empty, install packages from array
if (( ${#packages[@]} > 0 )); then
status_msg "Installing the following dependencies:"
for package in "${packages[@]}"; do
echo -e "${cyan}${package} ${white}"
done
echo
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then
ok_msg "Dependencies installed!"
else
error_msg "Installing dependencies failed!"
return 1 # exit kiauh
fi
else
ok_msg "Dependencies already met!"
return
fi
}
function fetch_webui_ports() {
local port interfaces=("mainsail" "fluidd" "octoprint")
### read ports from possible installed interfaces and write them to ~/.kiauh.ini
for interface in "${interfaces[@]}"; do
if [[ -f "/etc/nginx/sites-available/${interface}" ]]; then
port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2)
if ! grep -Eq "${interface}_port" "${INI_FILE}"; then
sed -i '$a'"${interface}_port=${port}" "${INI_FILE}"
else
sed -i "/^${interface}_port/d" "${INI_FILE}"
sed -i '$a'"${interface}_port=${port}" "${INI_FILE}"
fi
else
sed -i "/^${interface}_port/d" "${INI_FILE}"
fi
done
}
#================================================#
#=================== SYSTEM =====================#
#================================================#
function check_system_updates() {
local updates_avail info_msg
updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d")
if [[ -n ${updates_avail} ]]; then
# add system updates to the update all array for the update all function in the updater
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
info_msg="${yellow}System upgrade available!${white}"
else
SYS_UPDATE_AVAIL="false"
info_msg="${green}System up to date! ${white}"
fi
echo "${info_msg}"
}
function update_system() {
status_msg "Updating System ..."
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y; then
print_confirm "Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}"
else
print_error "System update failed! Please watch for any errors printed above!"
fi
}
function check_usergroups() {
local group_dialout group_tty
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
group_dialout="false"
fi
if grep -q "tty" </etc/group && ! grep -q "tty" <(groups "${USER}"); then
group_tty="false"
fi
if [[ ${group_dialout} == "false" || ${group_tty} == "false" ]] ; then
top_border
echo -e "| ${yellow}WARNING: Your current user is not in group:${white} |"
[[ ${group_tty} == "false" ]] && \
echo -e "| ${yellow}● tty${white} |"
[[ ${group_dialout} == "false" ]] && \
echo -e "| ${yellow}● dialout${white} |"
blank_line
echo -e "| It is possible that you won't be able to successfully |"
echo -e "| connect and/or flash the controller board without |"
echo -e "| your user being a member of that group. |"
echo -e "| If you want to add the current user to the group(s) |"
echo -e "| listed above, answer with 'Y'. Else skip with 'n'. |"
blank_line
echo -e "| ${yellow}INFO:${white} |"
echo -e "| ${yellow}Relog required for group assignments to take effect!${white} |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
status_msg "Adding user '${USER}' to group(s) ..."
if [[ ${group_tty} == "false" ]]; then
sudo usermod -a -G tty "${USER}" && ok_msg "Group 'tty' assigned!"
fi
if [[ ${group_dialout} == "false" ]]; then
sudo usermod -a -G dialout "${USER}" && ok_msg "Group 'dialout' assigned!"
fi
ok_msg "Remember to relog/restart this machine for the group(s) to be applied!"
break;;
N|n|No|no)
select_msg "No"
break;;
*)
print_error "Invalid command!";;
esac
done
fi
}
function set_custom_hostname() {
echo
top_border
echo -e "| Changing the hostname of this machine allows you to |"
echo -e "| access a webinterface that is configured for port 80 |"
echo -e "| by simply typing '<hostname>.local' in the browser. |"
echo -e "| |"
echo -e "| E.g.: If you set the hostname to 'my-printer' you |"
echo -e "| can open Mainsail / Fluidd / Octoprint by |"
echo -e "| browsing to: http://my-printer.local |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
case "${yn}" in
Y|y|Yes|yes)
select_msg "Yes"
change_hostname
break;;
N|n|No|no|"")
select_msg "No"
break;;
*)
error_msg "Invalid command!";;
esac
done
}
function change_hostname() {
local new_hostname regex="^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$"
echo
top_border
echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |"
echo -e "| ${red}No special characters allowed!${white} |"
echo -e "| ${red}No leading or trailing '-' allowed!${white} |"
bottom_border
while true; do
read -p "${cyan}###### Please set the new hostname:${white} " new_hostname
if [[ ${new_hostname} =~ ${regex} ]]; then
local yn
while true; do
echo
read -p "${cyan}###### Do you want '${new_hostname}' to be the new hostname? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
set_hostname "${new_hostname}"
break;;
N|n|No|no)
select_msg "No"
abort_msg "Skip hostname change ..."
break;;
*)
print_error "Invalid command!";;
esac
done
else
warn_msg "'${new_hostname}' is not a valid hostname!"
fi
break
done
}
function set_hostname() {
local new_hostname=${1} current_date
#check for dependencies
local dep=(avahi-daemon)
dependency_check "${dep[@]}"
#create host file if missing or create backup of existing one with current date&time
if [[ -f /etc/hosts ]]; then
current_date=$(get_date)
status_msg "Creating backup of hosts file ..."
sudo cp "/etc/hosts" "/etc/hosts.${current_date}.bak"
ok_msg "Backup done!"
ok_msg "File:'/etc/hosts.${current_date}.bak'"
else
sudo touch /etc/hosts
fi
#set new hostname in /etc/hostname
status_msg "Setting hostname to '${new_hostname}' ..."
status_msg "Please wait ..."
sudo hostnamectl set-hostname "${new_hostname}"
#write new hostname to /etc/hosts
status_msg "Writing new hostname to /etc/hosts ..."
echo "127.0.0.1 ${new_hostname}" | sudo tee -a /etc/hosts &>/dev/null
ok_msg "New hostname successfully configured!"
ok_msg "Remember to reboot for the changes to take effect!"
}
### this function takes in the full path of a systemd service file and returns
### either the instance index or the custom name
### input: /etc/systemd/system/klipper-name.service
### returns: name
function get_instance_name() {
local instance=${1} name
name=$(echo "${instance}" | rev | cut -d"/" -f1 | rev | cut -d"-" -f2 | cut -d"." -f1)
echo "${name}"
}