Compare commits

..

103 Commits
v3.1.0 ... v3

Author SHA1 Message Date
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
44 changed files with 1842 additions and 1220 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.

3
.gitignore vendored
View File

@@ -1 +1,2 @@
kiauh.ini
.idea
.shellcheckrc

112
README.md
View File

@@ -1,47 +1,34 @@
# **KIAUH - Klipper Installation And Update Helper**
![main_menu](resources/screenshots/kiauh.png)
# Klipper Installation And Update Helper
![GitHub](https://img.shields.io/github/license/th33xitus/kiauh) ![GitHub Repo stars](https://img.shields.io/github/stars/th33xitus/kiauh) ![GitHub forks](https://img.shields.io/github/forks/th33xitus/kiauh) ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/th33xitus/kiauh) ![GitHub last commit](https://img.shields.io/github/last-commit/th33xitus/kiauh) ![GitHub contributors](https://img.shields.io/github/contributors/th33xitus/kiauh)
![main_menu](resources/screenshots/main_v3.png)
### **📋 Please see the [Changelog](docs/changelog.md) for possible important information !**
---
**📢 Disclaimer: Usage of this script happens at your own risk!**
## **📋 Please see the [Changelog](docs/changelog.md) for possible important information !**
---
## **📢 Disclaimer: Usage of this script happens at your own risk!**
This script acts as a helping hand for you to get set up in a fast and comfortable way.\
**This does not mean, it will relieve you of using your brain.exe! 🧠**\
Please also always pay attention to the individual component repositories (all linked below).\
Feel free to give it a try. If you have suggestions or encounter any problems, please report them.
---
## **🛠️ Instructions:**
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.\
You will need it anyways! 😄
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
```
---
## **🧰 Functions and Features:**
- **New in v3.0.0:** You can now install multiple instances (Klipper/Moonraker/DWC/Octoprint) on the same Pi!
---
### **Core Functions:**
- **Installing** Klipper to your Raspberry Pi or other Debian based Linux Distribution.
- **Installing** of the Moonraker API (needed for Mainsail, Fluidd and KlipperScreen)
- **Installing** several different web interfaces such as Mainsail, Fluidd, Duet Web Control or OctoPrint including their dependencies.
- **Installing** several web interfaces such as Mainsail, Fluidd, Duet Web Control or OctoPrint including their dependencies.
- **Installing** of KlipperScreen (OctoScreen but for Klipper!)
- **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface!
- **Removing** of all the listed installations above.
@@ -56,81 +43,30 @@ git clone https://github.com/th33xitus/kiauh.git
### **For a list of additional features please see: [Feature List](docs/features.md)**
---
## **📝 Notes:**
## **❗ Notes:**
- 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**
## **🌐 Sources & Further Information**
For more information or instructions to the various components KIAUH can install, please check out the corresponding repositories listed below:
---
* ⛵[Klipper](https://github.com/Klipper3d/klipper) by [KevinOConnor](https://github.com/KevinOConnor)
* 🌙[Moonraker](https://github.com/Arksine/moonraker) by [Arksine](https://github.com/Arksine)
* 💨[Mainsail](https://github.com/mainsail-crew/mainsail) by [mainsail-crew](https://github.com/mainsail-crew)
* 🌊[Fluidd](https://github.com/fluidd-core/fluidd) by [fluidd-core](https://github.com/fluidd-core)
* 🕸️[Duet Web Control](https://github.com/Duet3D/DuetWebControl) by [Duet3D](https://github.com/Duet3D)
* 🕸️[DWC2-for-Klipper-Socket](https://github.com/Stephan3/dwc2-for-klipper-socket) by [Stephan3](https://github.com/Stephan3)
* 🖥️[KlipperScreen](https://github.com/jordanruthe/KlipperScreen) by [jordanruthe](https://github.com/jordanruthe)
* 🐙[OctoPrint](https://github.com/OctoPrint/OctoPrint) by [OctoPrint](https://github.com/OctoPrint)
* 🔬[PrettyGCode](https://github.com/Kragrathea/pgcode) by [Kragrathea](https://github.com/Kragrathea)
* 🤖[Moonraker-Telegram-Bot](https://github.com/nlef/moonraker-telegram-bot) by [nlef](https://github.com/nlef)
### **⛵Klipper** by [KevinOConnor](https://github.com/KevinOConnor) :
## **Credits**
https://github.com/KevinOConnor/klipper
---
### **⛵Klipper S-Curve fork** by [dmbutyugin](https://github.com/dmbutyugin) :
https://github.com/dmbutyugin/klipper/tree/scurve-smoothing \
https://github.com/dmbutyugin/klipper/tree/scurve-shaping
---
### **🌙Moonraker** by [Arksine](https://github.com/Arksine) :
https://github.com/Arksine/moonraker
---
### **💨Mainsail Webinterface** by [meteyou](https://github.com/meteyou) :
https://github.com/meteyou/mainsail
---
### **🌊Fluidd Webinterface** by [cadriel](https://github.com/cadriel) :
https://github.com/cadriel/fluidd
---
### **🕸Duet Web Control** by [Duet3D](https://github.com/Duet3D) :
https://github.com/Duet3D/DuetWebControl
---
### **🕸DWC2-for-Klipper-Socket** by [Stephan3](https://github.com/Stephan3) :
https://github.com/Stephan3/dwc2-for-klipper-socket
---
### **🖥KlipperScreen** by [jordanruthe](https://github.com/jordanruthe) :
https://github.com/jordanruthe/KlipperScreen
---
### **🐙OctoPrint Webinterface** by [OctoPrint](https://github.com/OctoPrint) :
https://octoprint.org \
https://github.com/OctoPrint/OctoPrint
---
## **❓ FAQ**
**_Q: Can i use this script to install multiple instances of Klipper on the same Pi? (Multisession?)_**
**A:** Yes, it is finally possible 🙂
* 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!

View File

@@ -2,6 +2,45 @@
This document covers possible important changes to KIAUH.
### 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 \
@@ -16,18 +55,18 @@ That means, from now on, Klipper and Moonraker services installed with KIAUH wil
- fluidd-error.log
* For MainsailOS and FluiddPi users:\
MainsailOS and FluiddPi will switch the shipped Klipper service from SysVinit to systemd probably with their next release. KIAUH can already help migrate older MainsailOS (0.4.0 and below) and FluiddPi (v1.13.0) releases to match their new service-, file- and folder-structure so you don't have to re-flash the SD-Card of your Raspberry Pi.\
In detail here is what is going to happen when you use the new "CustomPiOS Migration Helper" from the Advanced Menu `(Main Menu -> 4 -> Enter -> 10 -> Enter)` in a short summary:
1) The Klipper SysVinit service will get replaced by a Klipper systemd service
2) Klipper and Moonraker will use the new log-directory `~/klipper_logs`
3) The webcamd service gets updated
4) The webcamd script gets updated and moved from `/root/bin/webcamd` to `/usr/local/bin/webcamd`
5) The NGINX `upstreams.conf` gets updated to be able to configure up to 4 webcams
6) The `mainsail.txt` / `fluiddpi.txt` gets moved from `/boot` to `~/klipper_config` and renamed to `webcam.txt`
7) Symlinks for the webcamd.log and various NGINX logs get created in `~/klipper_config`
8) Configuration files for Klipper, Moonraker and webcamd get added to `/etc/logrotate.d`
9) If they still exist, two lines will be removed from the mainsail.cfg or client_macros.cfg macro configurations:\
`SAVE_GCODE_STATE NAME=PAUSE_state` and
`RESTORE_GCODE_STATE NAME=PAUSE_state`\
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.

View File

@@ -40,6 +40,34 @@ 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.

View File

@@ -35,19 +35,24 @@ DWC_ENV_DIR=${HOME}/dwc-env
DWC2_DIR=${HOME}/duetwebcontrol
#octoprint
OCTOPRINT_DIR=${HOME}/OctoPrint
OCTOPRINT_CFG_DIR=${HOME}/.octoprint
#KlipperScreen
KLIPPERSCREEN_DIR=${HOME}/KlipperScreen
KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env
#MoonrakerTelegramBot
MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot
MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env
#misc
INI_FILE=${HOME}/.kiauh.ini
BACKUP_DIR=${HOME}/kiauh-backups
### set github repos
KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git
KLIPPER_REPO=https://github.com/Klipper3d/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-socket.git
KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git
NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git
#branches
BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing
BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping

View File

@@ -1,83 +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
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]
self.gcode.respond_info(data)
cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command"
def cmd_RUN_SHELL_COMMAND(self, params):
reactor = self.printer.get_reactor()
try:
proc = subprocess.Popen(
self.command, 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)
# 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

@@ -14,7 +14,7 @@ server {
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
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>>;
@@ -49,6 +49,8 @@ server {
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;
@@ -56,6 +58,38 @@ server {
}
location /webcam/ {
proxy_pass http://mjpgstreamer/;
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

@@ -2,43 +2,55 @@
host: 0.0.0.0
port: %PORT%
enable_debug_logging: False
config_path: %CFG%
log_path: %LOG%
database_path: %MR_DB%
klippy_uds_address: %UDS%
[database]
database_path: %MR_DB%
[authorization]
trusted_clients:
127.0.0.1
%LAN%
::1/128
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:
*.lan
*.local
*://my.mainsail.xyz
*://app.fluidd.xyz
http://*.lan
http://*.local
https://my.mainsail.xyz
http://my.mainsail.xyz
https://app.fluidd.xyz
http://app.fluidd.xyz
[file_manager]
config_path: %CFG%
log_path: %LOG%
[octoprint_compat]
[history]
[update_manager]
channel: dev
refresh_interval: 168
[update_manager client mainsail]
[update_manager mainsail]
type: web
repo: meteyou/mainsail
repo: mainsail-crew/mainsail
path: ~/mainsail
[update_manager client fluidd]
[update_manager fluidd]
type: web
repo: cadriel/fluidd
repo: fluidd-core/fluidd
path: ~/fluidd
#[update_manager client KlipperScreen]
#[update_manager KlipperScreen]
#type: git_repo
#path: /home/%USER%/KlipperScreen
#origin: https://github.com/jordanruthe/KlipperScreen.git
#env: /home/%USER%/.KlipperScreen-env/bin/python
#requirements: scripts/KlipperScreen-requirements.txt
#install_script: scripts/KlipperScreen-install.sh
#install_script: scripts/KlipperScreen-install.sh

View File

@@ -8,6 +8,7 @@ WantedBy=multi-user.target
[Service]
Type=simple
SupplementaryGroups=moonraker-admin
User=%USER%
RemainAfterExit=yes
ExecStart=%MR_ENV%/bin/python %MR_DIR%/moonraker/moonraker.py -l %MR_LOG% -c %MR_CONF%

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -1,13 +1,25 @@
# /etc/nginx/conf.d/upstreams.conf
upstream apiserver {
#edit your api port here
ip_hash;
server 127.0.0.1:7125;
}
upstream mjpgstreamer {
#edit your webcam port here
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;
}

View File

@@ -12,5 +12,4 @@ WorkingDirectory=/usr/local/bin
StandardOutput=append:/var/log/webcamd.log
StandardError=append:/var/log/webcamd.log
ExecStart=/usr/local/bin/webcamd
Restart=always
RestartSec=10
Restart=always

View File

@@ -179,3 +179,17 @@ backup_klipperscreen(){
ERROR_MSG=" Can't backup KlipperScreen directory!\n Not found!"
fi
}
backup_MoonrakerTelegramBot(){
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] ; then
status_msg "Creating MoonrakerTelegramBot backup ..."
check_for_backup_dir
get_date
status_msg "Timestamp: $current_date"
mkdir -p $BACKUP_DIR/MoonrakerTelegramBot-backups/"$current_date"
cp -r $MOONRAKER_TELEGRAM_BOT_DIR $_
ok_msg "Backup complete!"
else
ERROR_MSG=" Can't backup MoonrakerTelegramBot directory!\n Not found!"
fi
}

View File

@@ -27,7 +27,7 @@ install_packages()
# Update system package info
report_status "Running apt-get update..."
sudo apt-get update
sudo apt-get update --allow-releaseinfo-change
# Install desired packages
report_status "Installing packages..."

View File

@@ -25,7 +25,7 @@ install_packages()
# Update system package info
report_status "Running apt-get update..."
sudo apt-get update
sudo apt-get update --allow-releaseinfo-change
# Install desired packages
report_status "Installing packages..."

334
scripts/flash_mcu.sh Executable file
View File

@@ -0,0 +1,334 @@
#!/bin/bash
show_flash_method_help(){
top_border
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
hr
echo -e "| ${cyan}Regular flashing method:${default} |"
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:${default} |"
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
while true; do
read -p "${cyan}###### Please select:${default} " choice
case "$choice" in
B|b)
clear && print_header
select_flash_method
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
select_flash_method(){
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
while true; do
read -p "${cyan}###### Please select:${default} " choice
case "$choice" in
1)
echo -e "###### > Regular flashing method"
select_mcu_connection
select_mcu_id
[[ "$CONFIRM_FLASH" == true ]] && flash_mcu
break;;
2)
echo -e "###### > SD-Card Update"
select_mcu_connection
select_mcu_id
[[ "$CONFIRM_FLASH" == true ]] && flash_mcu_sd
break;;
B|b)
advanced_menu
break;;
H|h)
clear && print_header
show_flash_method_help
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
select_mcu_id(){
if [ ${#mcu_list[@]} -ge 1 ]; then
top_border
echo -e "| ${red}!!! ATTENTION !!!${default} |"
hr
echo -e "| Make sure, to select the correct MCU! |"
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
bottom_border
echo -e "${cyan}###### List of available MCU:${default}"
### list all mcus
id=0
for mcu in ${mcu_list[@]}; do
let id++
echo -e " $id) $mcu"
done
### verify user input
sel_index=""
while [[ ! ($sel_index =~ ^[1-9]+$) ]] || [ "$sel_index" -gt "$id" ]; do
echo
read -p "${cyan}###### Select MCU to flash:${default} " sel_index
if [[ ! ($sel_index =~ ^[1-9]+$) ]]; then
warn_msg "Invalid input!"
elif [ "$sel_index" -lt 1 ] || [ "$sel_index" -gt "$id" ]; then
warn_msg "Please select a number between 1 and $id!"
fi
mcu_index=$(echo $((sel_index - 1)))
selected_mcu_id="${mcu_list[$mcu_index]}"
done
### confirm selection
while true; do
echo -e "\n###### You selected:\n ● MCU #$sel_index: $selected_mcu_id\n"
read -p "${cyan}###### Continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Flashing $selected_mcu_id ..."
CONFIRM_FLASH=true
break;;
N|n|No|no)
echo -e "###### > No"
CONFIRM_FLASH=false
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
flash_mcu(){
do_action_service "stop" "klipper"
make flash FLASH_DEVICE="${mcu_list[$mcu_index]}"
### evaluate exit code of make flash
if [ ! $? -eq 0 ]; then
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
else
ok_msg "Flashing successfull!"
fi
do_action_service "start" "klipper"
}
flash_mcu_sd(){
flash_script="${HOME}/klipper/scripts/flash-sdcard.sh"
### write each supported board to the array to make it selectable
board_list=()
for board in $("$flash_script" -l | tail -n +2); do
board_list+=($board)
done
i=0
top_border
echo -e "| Please select the type of board that corresponds to |"
echo -e "| the currently selected MCU ID you chose before. |"
blank_line
echo -e "| The following boards are currently supported: |"
hr
### display all supported boards to the user
for board in ${board_list[@]}; do
if [ $i -lt 10 ]; then
printf "| $i) %-50s|\n" "${board_list[$i]}"
else
printf "| $i) %-49s|\n" "${board_list[$i]}"
fi
i=$((i + 1))
done
quit_footer
### make the user select one of the boards
while true; do
read -p "${cyan}###### Please select board type:${default} " choice
if [ "$choice" = "q" ] || [ "$choice" = "Q" ]; then
clear && advanced_menu && break
elif [ "$choice" -le ${#board_list[@]} ]; then
selected_board="${board_list[$choice]}"
break
else
clear && print_header
ERROR_MSG="Invalid choice!" && print_msg && clear_msg
flash_mcu_sd
fi
done
while true; do
top_border
echo -e "| If your board is flashed with firmware that connects |"
echo -e "| at a custom baud rate, please change it now. |"
blank_line
echo -e "| If you are unsure, stick to the default 250000! |"
bottom_border
echo -e "${cyan}###### Please set the baud rate:${default} "
unset baud_rate
while [[ ! $baud_rate =~ ^[0-9]+$ ]]; do
read -e -i "250000" -e baud_rate
selected_baud_rate=$baud_rate
break
done
break
done
###flash process
do_action_service "stop" "klipper"
"$flash_script" -b "$selected_baud_rate" "$selected_mcu_id" "$selected_board"
### evaluate exit code of flash-sdcard.sh execution
if [ ! $? -eq 0 ]; then
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
else
ok_msg "Flashing successfull!"
fi
do_action_service "start" "klipper"
}
build_fw(){
if [ -d "$KLIPPER_DIR" ]; then
cd "$KLIPPER_DIR"
status_msg "Initializing firmware build ..."
dep=(build-essential dpkg-dev make)
dependency_check
make clean && make menuconfig
status_msg "Building firmware ..."
make && ok_msg "Firmware built!"
else
ERROR_MSG="Klipper was not found!\n Can not build firmware without Klipper!"
print_msg && clear_msg && return 1
fi
}
select_mcu_connection(){
echo
top_border
echo -e "| ${yellow}Make sure to have the controller board connected now!${default} |"
blank_line
echo -e "| How is the controller board connected to the host? |"
echo -e "| 1) USB |"
echo -e "| 2) UART |"
bottom_border
while true; do
read -p "${cyan}###### Connection method:${default} " choice
case "$choice" in
1)
retrieve_id "USB"
break;;
2)
retrieve_id "UART"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
unset mcu_count
if [[ "${#mcu_list[@]}" -lt 1 ]]; then
warn_msg "No MCU found!"
warn_msg "MCU not plugged in or not detectable!"
echo
fi
}
retrieve_id(){
status_msg "Identifying MCU ..."
sleep 1
mcu_list=()
mcu_count=1
[ "$1" = "USB" ] && path="/dev/serial/by-id/*"
[ "$1" = "UART" ] && path="/dev/ttyAMA0"
if [[ "$(ls $path)" != "" ]] ; then
for mcu in $path; do
declare "mcu_id_$mcu_count"="$mcu"
mcu_id="mcu_id_$mcu_count"
mcu_list+=("${!mcu_id}")
echo -e " ● ($1) MCU #$mcu_count: ${cyan}$mcu${default}\n"
let mcu_count++
done
fi 2>/dev/null
}
check_usergroup_dialout(){
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
group_dialout=false
else
group_dialout=true
fi
if grep -q "tty" </etc/group && ! grep -q "tty" <(groups "${USER}"); then
group_tty=false
else
group_tty=true
fi
if [ "$group_dialout" == "false" ] || [ "$group_tty" == "false" ] ; then
top_border
echo -e "| ${yellow}WARNING: Your current user is not in group:${default} |"
[ "$group_tty" == "false" ] && echo -e "| ${yellow}● tty${default} |"
[ "$group_dialout" == "false" ] && echo -e "| ${yellow}● dialout${default} |"
blank_line
echo -e "| It is possible that you won't be able to successfully |"
echo -e "| flash without 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:${default} |"
echo -e "| ${yellow}Relog required for group assignments to take effect!${default} |"
bottom_border
while true; do
read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > 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 "You need to relog/restart for the group(s) to be applied!" && exit 0;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}

View File

@@ -82,34 +82,36 @@ change_klipper_cfg_path(){
set_klipper_cfg_path(){
### stop services
klipper_service "stop" && moonraker_service "stop"
do_action_service "stop" "klipper"
do_action_service "stop" "moonraker"
### copy config files to new klipper config folder
if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then
if [ ! -d "$new_klipper_cfg_loc" ]; then
status_msg "Copy config files to '$new_klipper_cfg_loc' ..."
mkdir -p $new_klipper_cfg_loc
mkdir -p "$new_klipper_cfg_loc"
cd $old_klipper_cfg_loc
cp -r -v ./* $new_klipper_cfg_loc
cp -r -v ./* "$new_klipper_cfg_loc"
ok_msg "Done!"
fi
fi
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])+[0-9]*.service")
### handle single klipper instance service file
if [ -f $SYSTEMDDIR/klipper.service ]; then
status_msg "Configuring Klipper for new path ..."
sudo sed -i -r "/ExecStart=/ s| (.+)\/printer.cfg| $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service
sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer.cfg|klippy.py $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service
ok_msg "OK!"
fi
### handle multi klipper instance service file
if ls $SYSTEMDDIR/klipper-*.service 2>/dev/null 1>&2; then
elif [ -n "$SERVICE_FILES" ]; then
### handle multi klipper instance service file
status_msg "Configuring Klipper for new path ..."
for service in $(find $SYSTEMDDIR/klipper-*.service); do
sudo sed -i -r "/ExecStart=/ s| (.+)\/printer_| $new_klipper_cfg_loc/printer_|" $service
for service in $SERVICE_FILES; do
sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer_|klippy.py $new_klipper_cfg_loc/printer_|" "$service"
done
ok_msg "OK!"
fi
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])+[0-9]*.service")
### handle single moonraker instance service and moonraker.conf file
if [ -f $SYSTEMDDIR/moonraker.service ]; then
status_msg "Configuring Moonraker for new path ..."
@@ -118,17 +120,17 @@ set_klipper_cfg_path(){
### replace old file path with new one in moonraker.conf
sed -i -r "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
ok_msg "OK!"
fi
### handle multi moonraker instance service file
if ls $SYSTEMDDIR/moonraker-*.service 2>/dev/null 1>&2; then
elif [ -n "$SERVICE_FILES" ]; then
### handle multi moonraker instance service file
status_msg "Configuring Moonraker for new path ..."
for service in $(find $SYSTEMDDIR/moonraker-*.service); do
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" $service
for service in $SERVICE_FILES; do
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" "$service"
done
MR_CONFS=$(find "$new_klipper_cfg_loc" -regextype posix-extended -regex "$new_klipper_cfg_loc/printer_[1-9]+/moonraker.conf")
### replace old file path with new one in moonraker.conf
for moonraker_conf in $(find $new_klipper_cfg_loc/printer_*/moonraker.conf); do
for moonraker_conf in $MR_CONFS; do
loc=$(echo "$moonraker_conf" | rev | cut -d"/" -f2- | rev)
sed -i -r "/config_path:/ s|config_path:.*|config_path: $loc|" $moonraker_conf
sed -i -r "/config_path:/ s|config_path:.*|config_path: $loc|" "$moonraker_conf"
done
ok_msg "OK!"
fi
@@ -137,77 +139,17 @@ set_klipper_cfg_path(){
sudo systemctl daemon-reload
### restart services
klipper_service "restart" && moonraker_service "restart"
do_action_service "restart" "klipper"
do_action_service "restart" "moonraker"
}
source_kiauh_ini(){
source $INI_FILE
}
klipper_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Klipper Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 klipper-$INSTANCE && ok_msg "Klipper Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper.service")" ]; then
status_msg "$ACTION2 Klipper Service ..."
sudo systemctl $1 klipper && ok_msg "Klipper Service $ACTION1!"
fi
}
moonraker_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Moonraker Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 moonraker-$INSTANCE && ok_msg "Moonraker Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker.service")" ]; then
status_msg "$ACTION2 Moonraker Service ..."
sudo systemctl $1 moonraker && ok_msg "Moonraker Service $ACTION1!"
fi
}
dwc_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/dwc-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT DWC-for-Klipper-Socket Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 dwc-$INSTANCE && ok_msg "DWC-for-Klipper-Socket Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc.service")" ]; then
status_msg "$ACTION2 DWC-for-Klipper-Socket Service ..."
sudo systemctl $1 dwc && ok_msg "DWC-for-Klipper-Socket Service $ACTION1!"
fi
}
octoprint_service(){
do_action_service(){
shopt -s extglob # enable extended globbing
SERVICES="$SYSTEMDDIR/$2?(-*([0-9])).service"
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
@@ -215,30 +157,25 @@ octoprint_service(){
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling"
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling"
if ls /etc/systemd/system/octoprint-*.service 2>/dev/null 1>&2; then
INSTANCE=1
INSTANCE_COUNT=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l)
status_msg "$ACTION2 $INSTANCE_COUNT OctoPrint Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 octoprint-$INSTANCE && ok_msg "OctoPrint Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
if ls $SERVICES 2>/dev/null 1>&2; then
for service in $(ls $SERVICES | rev | cut -d"/" -f1 | rev); do
status_msg "$ACTION2 $service ..."
sudo systemctl $1 "$service"
ok_msg "$service $ACTION1!"
done
elif [ "$(systemctl list-unit-files | grep -E "octoprint.*")" ]; then
status_msg "$ACTION2 OctoPrint Service ..."
sudo systemctl $1 octoprint && ok_msg "OctoPrint Service $ACTION1!"
fi
shopt -u extglob # disable extended globbing
}
toggle_octoprint_service(){
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
octoprint_service "stop"
octoprint_service "disable"
do_action_service "stop" "octoprint"
do_action_service "disable" "octoprint"
sleep 2
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
octoprint_service "enable"
octoprint_service "start"
do_action_service "enable" "octoprint"
do_action_service "start" "octoprint"
sleep 2
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
else
@@ -273,8 +210,23 @@ restart_klipperscreen(){
sudo systemctl restart KlipperScreen && ok_msg "KlipperScreen Service restarted!"
}
start_MoonrakerTelegramBot(){
status_msg "Starting MoonrakerTelegramBot Service ..."
sudo systemctl start moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service started!"
}
stop_MoonrakerTelegramBot(){
status_msg "Stopping MoonrakerTelegramBot Service ..."
sudo systemctl stop moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service stopped!"
}
restart_MoonrakerTelegramBot(){
status_msg "Restarting MoonrakerTelegramBot Service ..."
sudo systemctl restart moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service restarted!"
}
restart_nginx(){
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then
if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then
status_msg "Restarting NGINX Service ..."
sudo systemctl restart nginx && ok_msg "NGINX Service restarted!"
fi
@@ -298,7 +250,7 @@ dependency_check(){
echo -e "${cyan}$element ${default}"
done
echo
sudo apt-get update && sudo apt-get install ${inst[@]} -y
sudo apt-get update --allow-releaseinfo-change && sudo apt-get install ${inst[@]} -y
ok_msg "Dependencies installed!"
#clearing the array
unset inst
@@ -370,7 +322,7 @@ setup_gcode_shell_command(){
}
install_gcode_shell_command(){
klipper_service "stop"
do_action_service "stop" "klipper"
status_msg "Copy 'gcode_shell_command.py' to '$KLIPPER_DIR/klippy/extras' ..."
cp ${SRCDIR}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
while true; do
@@ -412,7 +364,7 @@ install_gcode_shell_command(){
esac
done
ok_msg "Shell command extension installed!"
klipper_service "restart"
do_action_service "restart" "klipper"
}
create_minimal_cfg(){
@@ -436,49 +388,6 @@ EOF
fi
}
read_printer_cfg(){
KIAUH_CFG="$(dirname $PRINTER_CFG)/kiauh.cfg"
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true"
if [ -f $PRINTER_CFG ]; then
if [ "$1" = "moonraker" ]; then
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
[ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false" && EDIT_CFG="true"
[ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false" && EDIT_CFG="true"
elif [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
[ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false" && EDIT_CFG="true"
elif [ "$1" = "dwc2" ]; then
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
fi
fi
}
write_printer_cfg(){
#backup printer.cfg if edits will be written
[ "$EDIT_CFG" = "true" ] && backup_printer_cfg
#create kiauh.cfg if its needed and doesn't exist
if [ "$KIAUH_CFG_FOUND" = "false" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Creating kiauh.cfg ..."
echo -e "##### AUTOCREATED BY KIAUH #####" > $KIAUH_CFG
fi
#write each entry to kiauh.cfg if it doesn't exist
#Moonraker/DWC2 related config options
if [ "$VSD" = "false" ] && [[ ! $(grep '^\[virtual_sdcard\]$' $KIAUH_CFG) ]]; then
echo -e "\n[virtual_sdcard]\npath: ~/sdcard" >> $KIAUH_CFG
fi
if [ "$PAUSE_RESUME" = "false" ] && [[ ! $(grep '^\[pause_resume]$' $KIAUH_CFG) ]]; then
echo -e "\n[pause_resume]" >> $KIAUH_CFG
fi
if [ "$DISPLAY_STATUS" = "false" ] && [[ ! $(grep '^\[display_status]$' $KIAUH_CFG) ]]; then
echo -e "\n[display_status]" >> $KIAUH_CFG
fi
#including the kiauh.cfg into printer.cfg if not already done
if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Writing [include kiauh.cfg] to printer.cfg ..."
sed -i '1 i ##### AUTOCREATED BY KIAUH #####\n[include kiauh.cfg]' $PRINTER_CFG
fi
ok_msg "Done!"
}
init_ini(){
### copy an existing kiauh.ini to its new location to keep all possible saved values
if [ -f ${SRCDIR}/kiauh/kiauh.ini ] && [ ! -f $INI_FILE ]; then
@@ -506,4 +415,5 @@ init_ini(){
if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then
echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE
fi
fetch_webui_ports
}

View File

@@ -33,13 +33,13 @@ dwc_setup_dialog(){
### ask user how to handle OctoPrint, Haproxy and Lighttpd
process_octoprint_dialog_dwc2
process_haproxy_lighttpd_dialog
process_services_dialog
### instance confirmation dialog
while true; do
echo
top_border
if [ $INSTANCE_COUNT -gt 1 ]; then
if [ "$INSTANCE_COUNT" -gt 1 ]; then
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
else
echo -e "| 1 Klipper instance was found! | "
@@ -118,7 +118,7 @@ dwc_setup(){
### step 1: get dwc2-for-klipper
status_msg "Downloading DWC2-for-Klipper-Socket ..."
cd ${HOME} && git clone $DWC2FK_REPO
cd "${HOME}" && git clone "$DWC2FK_REPO"
ok_msg "Download complete!"
### step 2: install dwc2 dependencies and create python virtualenv
@@ -127,7 +127,7 @@ dwc_setup(){
create_dwc_virtualenv
### step 3: create dwc2.cfg folder and dwc2.cfg
[ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC
[ ! -d "$DWC_CONF_LOC" ] && mkdir -p "$DWC_CONF_LOC"
dwc_cfg_creation
### step 4: download Duet Web Control
@@ -135,7 +135,7 @@ dwc_setup(){
### step 5: create dwc instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
if [ "$INSTANCE_COUNT" -eq $INSTANCE ]; then
create_single_dwc_instance
else
#create_multi_dwc_instance
@@ -147,18 +147,18 @@ download_dwc_webui(){
#get Duet Web Control
GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4)
status_msg "Downloading DWC2 Web UI ..."
[ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR
cd $DWC2_DIR && wget $GET_DWC2_URL
[ ! -d "$DWC2_DIR" ] && mkdir -p "$DWC2_DIR"
cd "$DWC2_DIR" && wget "$GET_DWC2_URL"
ok_msg "Download complete!"
status_msg "Extracting archive ..."
unzip -q -o *.zip
for f_ in $(find . | grep '.gz')
do
gunzip -f ${f_}
gunzip -f "${f_}"
done
ok_msg "Done!"
status_msg "Writing DWC version to file ..."
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/.version
echo "$GET_DWC2_URL" | cut -d/ -f8 > "$DWC2_DIR/.version"
ok_msg "Done!"
status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!" && ok_msg "Duet Web Control installed!"
@@ -174,11 +174,11 @@ install_dwc_packages()
# Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
sudo apt-get update --allow-releaseinfo-change
# Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGLIST}
sudo apt-get install --yes "${PKGLIST}"
}
create_dwc_virtualenv()
@@ -186,10 +186,10 @@ create_dwc_virtualenv()
status_msg "Installing python virtual environment..."
# Create virtualenv if it doesn't already exist
[ ! -d ${DWC_ENV} ] && virtualenv -p /usr/bin/python3 ${DWC_ENV}
[ ! -d "${DWC_ENV}" ] && virtualenv -p /usr/bin/python3 "${DWC_ENV}"
# Install/update dependencies
${DWC_ENV}/bin/pip install tornado==6.0.4
"${DWC_ENV}"/bin/pip install tornado==6.0.4
}
create_single_dwc_startscript(){
@@ -303,7 +303,7 @@ create_single_dwc_instance(){
create_multi_dwc_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
while [ $INSTANCE -le "$INSTANCE_COUNT" ]; do
### multi instance variables
DWC_LOG=/tmp/dwc-$INSTANCE.log
DWC_CFG="$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg"
@@ -348,7 +348,7 @@ dwc_cfg_creation(){
dwc_ip_list=()
### create single instance dwc2.cfg file
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
if [ "$INSTANCE_COUNT" -eq $INSTANCE ]; then
### set port
PORT=$DEFAULT_PORT
@@ -356,8 +356,8 @@ dwc_cfg_creation(){
dwc_ip_list+=("$HOSTNAME:$PORT")
status_msg "Creating dwc2.cfg in $DWC_CONF_LOC"
[ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC
if [ ! -f $DWC_CONF_LOC/dwc2.cfg ]; then
[ ! -d "$DWC_CONF_LOC" ] && mkdir -p "$DWC_CONF_LOC"
if [ ! -f "$DWC_CONF_LOC/dwc2.cfg" ]; then
create_single_dwcfk_cfg && ok_msg "dwc2.cfg created!"
else
warn_msg "There is already a file called 'dwc2.cfg'!"
@@ -366,7 +366,7 @@ dwc_cfg_creation(){
### create multi instance moonraker.conf files
else
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
while [ $INSTANCE -le "$INSTANCE_COUNT" ]; do
### set each instance to its own port
PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1)
@@ -375,8 +375,8 @@ dwc_cfg_creation(){
### start the creation of each instance
status_msg "Creating dwc2.cfg for instance #$INSTANCE"
[ ! -d $DWC_CONF_LOC/printer_$INSTANCE ] && mkdir -p $DWC_CONF_LOC/printer_$INSTANCE
if [ ! -f $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg ]; then
[ ! -d "$DWC_CONF_LOC/printer_$INSTANCE" ] && mkdir -p "$DWC_CONF_LOC/printer_$INSTANCE"
if [ ! -f "$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" ]; then
create_multi_dwcfk_cfg && ok_msg "dwc2.cfg created!"
else
warn_msg "There is already a file called 'dwc2.cfg'!"

View File

@@ -2,37 +2,49 @@
SYSTEMDDIR="/etc/systemd/system"
KLIPPY_ENV="${HOME}/klippy-env"
KLIPPER_DIR="${HOME}/klipper"
KLIPPER_REPO="https://github.com/Klipper3d/klipper.git"
klipper_setup_dialog(){
status_msg "Initializing Klipper installation ..."
### check for existing klipper service files
INITD=$(ls /etc/init.d | grep -E "^klipper(\-[[:digit:]]+)?$")
SYSTEMD=$(ls /etc/systemd/system | grep -E "^klipper(\-[[:digit:]]+)?\.service$")
if [ ! -z "$INITD" ] || [ ! -z "$SYSTEMD" ]; then
echo "${red}$INITD${default}" && echo "${red}$SYSTEMD${default}"
ERROR_MSG="At least one Klipper service is already installed!\n Please remove Klipper first, before installing it again." && return 0
### check for existing klipper service installations
SERVICE_FILES=""
INITD_SERVICE_FILES=$(find "/etc/init.d" -regextype posix-extended -regex "/etc/init.d/klipper(-[^0])?[0-9]*")
SYSTEMD_SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])?[0-9]*.service")
[ -n "$INITD_SERVICE_FILES" ] && SERVICE_FILES+="${INITD_SERVICE_FILES}"
[ -n "$SYSTEMD_SERVICE_FILES" ] && SERVICE_FILES+=" ${SYSTEMD_SERVICE_FILES}"
if [ -n "$SERVICE_FILES" ]; then
ERROR_MSG="At least one Klipper service is already installed:"
for service in $SERVICE_FILES; do
ERROR_MSG="${ERROR_MSG}\n ➔ $service"
done && return
fi
status_msg "Initializing Klipper installation ..."
### initial printer.cfg path check
check_klipper_cfg_path
### ask for amount of instances to create
INSTANCE_COUNT=""
while [[ ! ($INSTANCE_COUNT =~ ^[1-9]+$) ]]; do
echo
read -p "${cyan}###### Number of Klipper instances to set up:${default} " INSTANCE_COUNT
if [[ ! ($INSTANCE_COUNT =~ ^[1-9]+$) ]]; then
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 machine. |"
blank_line
echo -e "| ${yellow}WARNING: There is no limit on the number of instances${default} |"
echo -e "| ${yellow}you can set up with this script.${default} |"
bottom_border
count=""
while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do
read -p "${cyan}###### Number of Klipper instances to set up:${default} " count
if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then
warn_msg "Invalid Input!" && echo
else
echo
read -p "${cyan}###### Install $INSTANCE_COUNT instance(s)? (Y/n):${default} " yn
read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Installing $INSTANCE_COUNT Klipper instance(s) ..."
klipper_setup
status_msg "Installing $count Klipper instance(s) ..."
klipper_setup "$count"
break;;
N|n|No|no)
echo -e "###### > No"
@@ -51,37 +63,44 @@ install_klipper_packages(){
### read PKGLIST from official install script
status_msg "Reading dependencies..."
install_script="${HOME}/klipper/scripts/install-octopi.sh"
PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g')
### rewrite packages into new array
unset PKGARR
for PKG in $PKGLIST; do PKGARR+=($PKG); done
#PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g')
PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n')
### add dbus requirement for DietPi distro
PKGARR+=("dbus")
echo "${cyan}${PKGARR[@]}${default}"
[ -e "/boot/dietpi/.version" ] && PKGLIST+=" dbus"
for pkg in $PKGLIST; do
echo "${cyan}$pkg${default}"
done
read -r -a PKGLIST <<< "$PKGLIST"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
sudo apt-get update --allow-releaseinfo-change
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGARR[@]}
sudo apt-get install --yes "${PKGLIST[@]}"
}
create_klipper_virtualenv(){
status_msg "Installing python virtual environment..."
# Create virtualenv if it doesn't already exist
[ ! -d ${KLIPPY_ENV} ] && virtualenv -p python2 ${KLIPPY_ENV}
[ ! -d "${KLIPPY_ENV}" ] && virtualenv -p python2 "${KLIPPY_ENV}"
# Install/update dependencies
${KLIPPY_ENV}/bin/pip install -r ${KLIPPER_DIR}/scripts/klippy-requirements.txt
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
}
klipper_setup(){
INSTANCE_COUNT=$1
### checking dependencies
dep=(git)
dependency_check
### step 1: clone klipper
status_msg "Downloading Klipper ..."
### force remove existing klipper dir and clone into fresh klipper dir
[ -d $KLIPPER_DIR ] && rm -rf $KLIPPER_DIR
cd ${HOME} && git clone $KLIPPER_REPO
[ -d "$KLIPPER_DIR" ] && rm -rf "$KLIPPER_DIR"
cd "${HOME}" && git clone "$KLIPPER_REPO"
status_msg "Download complete!"
### step 2: install klipper dependencies and create python virtualenv
@@ -90,16 +109,18 @@ klipper_setup(){
create_klipper_virtualenv
### step 3: create shared gcode_files and logs folder
[ ! -d ${HOME}/gcode_files ] && mkdir -p ${HOME}/gcode_files
[ ! -d ${HOME}/klipper_logs ] && mkdir -p ${HOME}/klipper_logs
[ ! -d "${HOME}"/gcode_files ] && mkdir -p "${HOME}"/gcode_files
[ ! -d "${HOME}"/klipper_logs ] && mkdir -p "${HOME}"/klipper_logs
### step 4: create klipper instances
create_klipper_service
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
[ $INSTANCE_COUNT -eq 1 ] && CONFIRM_MSG="Klipper has been set up!"
print_msg && clear_msg
if [[ $INSTANCE_COUNT -eq 1 ]]; then
CONFIRM_MSG="Klipper has been set up!"
elif [[ $INSTANCE_COUNT -gt 1 ]]; then
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
fi && print_msg && clear_msg
}
create_klipper_service(){
@@ -120,13 +141,13 @@ create_klipper_service(){
KL_SERV_TARGET="$SYSTEMDDIR/klipper.service"
write_kl_service(){
[ ! -d $CFG_PATH ] && mkdir -p $CFG_PATH
[ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH"
### create a minimal config if there is no printer.cfg
[ ! -f $P_CFG ] && cp $P_CFG_SRC $P_CFG
[ ! -f "$P_CFG" ] && cp "$P_CFG_SRC" "$P_CFG"
### replace placeholder
if [ ! -f $KL_SERV_TARGET ]; then
status_msg "Creating Klipper Service $i ..."
sudo cp $KL_SERV_SRC $KL_SERV_TARGET
sudo cp "$KL_SERV_SRC" $KL_SERV_TARGET
sudo sed -i "s|%INST%|$i|" $KL_SERV_TARGET
sudo sed -i "s|%USER%|${USER}|" $KL_SERV_TARGET
sudo sed -i "s|%KL_ENV%|$KL_ENV|" $KL_SERV_TARGET
@@ -138,7 +159,7 @@ create_klipper_service(){
fi
}
if [ $SINGLE_INST -eq $INSTANCE_COUNT ]; then
if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then
### write single instance service
write_kl_service
### enable instance
@@ -149,7 +170,7 @@ create_klipper_service(){
sudo systemctl start klipper
else
i=1
while [ $i -le $INSTANCE_COUNT ]; do
while [[ $i -le $INSTANCE_COUNT ]]; do
### rewrite default variables for multi instance cases
CFG_PATH="$klipper_cfg_loc/printer_$i"
KL_SERV_TARGET="$SYSTEMDDIR/klipper-$i.service"
@@ -172,247 +193,3 @@ create_klipper_service(){
unset i
fi
}
flash_routine(){
echo
top_border
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
hr
echo -e "| Flashing a Smoothie based board with this method will |"
echo -e "| certainly fail. This applies to boards like the SKR |"
echo -e "| V1.3 / V1.4. You have to copy the firmware file to |"
echo -e "| the SD card manually and rename it to 'firmware.bin'. |"
hr
echo -e "| You can find the file in: ~/klipper/out/klipper.bin |"
bottom_border
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
FLASH_FIRMWARE="true"
get_mcu_id
break;;
N|n|No|no)
echo -e "###### > No"
FLASH_FIRMWARE="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
flash_routine_sd(){
echo
top_border
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
hr
echo -e "| If you have a Smoothie based board with an already |"
echo -e "| flashed Klipper Firmware, you can now choose to flash |"
echo -e "| directly from the internal SD if your control board |"
echo -e "| is supported by that function. |"
bottom_border
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
FLASH_FW_SD="true"
get_mcu_id
break;;
N|n|No|no)
echo -e "###### > No"
FLASH_FW_SD="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
select_mcu_id(){
if [ ${#mcu_list[@]} -ge 1 ]; then
top_border
echo -e "| ${red}!!! IMPORTANT WARNING !!!${default} |"
hr
echo -e "| Make sure, that you select the correct ID for the MCU |"
echo -e "| you have build the firmware for in the previous step! |"
blank_line
echo -e "| This is especially important if you use different MCU |"
echo -e "| models which each require their own firmware! |"
blank_line
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
bottom_border
### list all mcus
i=1
for mcu in ${mcu_list[@]}; do
echo -e "$i) ${cyan}$mcu${default}"
i=$(expr $i + 1)
done
while true; do
echo
read -p "${cyan}###### Please select the ID for flashing:${default} " selected_index
mcu_index=$(echo $((selected_index - 1)))
selected_mcu_id="${mcu_list[$mcu_index]}"
echo -e "\nYou have selected to flash:\n● MCU #$selected_index: $selected_mcu_id\n"
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Flashing $selected_mcu_id ..."
if [ "$FLASH_FIRMWARE" = "true" ]; then
flash_mcu
fi
if [ "$FLASH_FW_SD" = "true" ]; then
flash_mcu_sd
fi
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
break
done
fi
}
flash_mcu(){
klipper_service "stop"
if ! make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" ; then
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
else
ok_msg "Flashing successfull!"
fi
klipper_service "start"
}
flash_mcu_sd(){
klipper_service "stop"
### write each supported board to the array to make it selectable
board_list=()
for board in $(~/klipper/scripts/flash-sdcard.sh -l | tail -n +2); do
board_list+=($board)
done
i=0
top_border
echo -e "| Please select the type of board that corresponds to |"
echo -e "| the currently selected MCU ID you chose before. |"
blank_line
echo -e "| The following boards are currently supported: |"
hr
### display all supported boards to the user
for board in ${board_list[@]}; do
if [ $i -lt 10 ]; then
printf "| $i) %-50s|\n" "${board_list[$i]}"
else
printf "| $i) %-49s|\n" "${board_list[$i]}"
fi
i=$((i + 1))
done
quit_footer
### make the user select one of the boards
while true; do
read -p "${cyan}###### Please select board type:${default} " choice
if [ $choice = "q" ] || [ $choice = "Q" ]; then
clear && advanced_menu && break
elif [ $choice -le ${#board_list[@]} ]; then
selected_board="${board_list[$choice]}"
break
else
clear && print_header
ERROR_MSG="Invalid choice!" && print_msg && clear_msg
flash_mcu_sd
fi
done
while true; do
top_border
echo -e "| If your board is flashed with firmware that connects |"
echo -e "| at a custom baud rate, please change it now. |"
blank_line
echo -e "| If you are unsure, stick to the default 250000! |"
bottom_border
echo -e "${cyan}###### Please set the baud rate:${default} "
unset baud_rate
while [[ ! $baud_rate =~ ^[0-9]+$ ]]; do
read -e -i "250000" -e baud_rate
selected_baud_rate=$baud_rate
break
done
break
done
if ! ${HOME}/klipper/scripts/flash-sdcard.sh -b "$selected_baud_rate" "$selected_mcu_id" "$selected_board" ; then
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
else
ok_msg "Flashing successfull!"
fi
klipper_service "start"
}
build_fw(){
if [ -d $KLIPPER_DIR ]; then
cd $KLIPPER_DIR
status_msg "Initializing firmware build ..."
make clean
make menuconfig
status_msg "Building firmware ..."
make && ok_msg "Firmware built!"
else
warn_msg "Can not build firmware without a Klipper directory!"
fi
}
### grab the mcu id
get_mcu_id(){
echo
top_border
echo -e "| Please make sure your MCU is connected to the Pi! |"
echo -e "| If the MCU is not connected yet, connect it now. |"
bottom_border
while true; do
echo -e "${cyan}"
read -p "###### Press ENTER to continue ... " yn
echo -e "${default}"
case "$yn" in
*)
break;;
esac
done
status_msg "Identifying the ID of your MCU ..."
sleep 2
unset MCU_ID
### if there are devices found, continue, else show warn message
if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then
mcu_count=1
mcu_list=()
status_msg "The ID of your printers MCU is:"
### loop over the IDs, write every ID as an item of the array 'mcu_list'
for mcu in /dev/serial/by-id/*; do
declare "mcu_id_$mcu_count"="$mcu"
mcu_id="mcu_id_$mcu_count"
mcu_list+=("${!mcu_id}")
echo " ● MCU #$mcu_count: ${cyan}$mcu${default}"
mcu_count=$(expr $mcu_count + 1)
done
unset mcu_count
else
warn_msg "Could not retrieve ID!"
warn_msg "Printer not plugged in or not detectable!"
fi
}

View File

@@ -1,10 +1,33 @@
check_moonraker(){
status_msg "Checking for Moonraker service ..."
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases"
FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases"
system_check_webui(){
### check system for installed moonraker service
if ls /etc/systemd/system/moonraker.service 2>/dev/null 1>&2 || ls /etc/systemd/system | grep -q -E "moonraker-[[:digit:]]+.service"; then
moonraker_chk_ok="true"
else
moonraker_chk_ok="false"
fi
### check system for an installed and enabled octoprint service
if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
OCTOPRINT_ENABLED="true"
fi
### check system for an installed haproxy service
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true"
fi
### check system for an installed lighttpd service
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
LIGHTTPD_FOUND="true"
fi
### check system for an installed apache2 service
if [[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]]; then
APACHE2_FOUND="true"
fi
}
get_user_selection_mjpg-streamer(){
@@ -69,21 +92,28 @@ get_user_selection_kiauh_macros(){
}
install_webui(){
source_kiauh_ini
### checking dependencies
dep=(nginx)
dependency_check
### check if moonraker is already installed
check_moonraker
system_check_webui
### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found
process_octoprint_dialog
process_services_dialog
### process possible disruptive services
process_disruptive_services
[ $1 == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail "
[ $1 == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd "
[ "$1" == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail "
[ "$1" == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd "
### exit mainsail/fluidd setup if moonraker not found
if [ $moonraker_chk_ok = "false" ]; then
ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!"
print_msg && clear_msg && return 0
else
ok_msg "Moonraker service found!"
status_msg "Initializing $IF_NAME1 installation ..."
fi
status_msg "Initializing $IF_NAME1 installation ..."
### check for other enabled web interfaces
unset SET_LISTEN_PORT
detect_enabled_sites
@@ -92,12 +122,17 @@ install_webui(){
$1_port_check
### ask user to install mjpg-streamer
get_user_selection_mjpg-streamer
if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then
get_user_selection_mjpg-streamer
fi
### ask user to install the recommended webinterface macros
get_user_selection_kiauh_macros "$IF_NAME2"
### creating the mainsail/fluidd nginx cfg
if ! ls "$klipper_cfg_loc"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "$klipper_cfg_loc"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then
get_user_selection_kiauh_macros "$IF_NAME2"
fi
### create /etc/nginx/conf.d/upstreams.conf
set_upstream_nginx_cfg
### create /etc/nginx/sites-available/<interface config>
set_nginx_cfg "$1"
### symlink nginx log
@@ -112,6 +147,8 @@ install_webui(){
### install mjpg-streamer
[ "$INSTALL_MJPG" = "true" ] && install_mjpg-streamer
fetch_webui_ports #WIP
### confirm message
CONFIRM_MSG="$IF_NAME1 has been set up!"
print_msg && clear_msg
@@ -124,12 +161,12 @@ symlink_webui_nginx_log(){
[ ! -d "$LPATH" ] && mkdir -p "$LPATH"
if [ -f "$UI_ACCESS_LOG" ] && [ ! -L "$LPATH/$1-access.log" ]; then
status_msg "Creating symlink for $UI_ACCESS_LOG ..."
ln -s $UI_ACCESS_LOG "$LPATH"
ln -s "$UI_ACCESS_LOG" "$LPATH"
ok_msg "OK!"
fi
if [ -f "$UI_ERROR_LOG" ] && [ ! -L "$LPATH/$1-error.log" ]; then
status_msg "Creating symlink for $UI_ERROR_LOG ..."
ln -s $UI_ERROR_LOG "$LPATH"
ln -s "$UI_ERROR_LOG" "$LPATH"
ok_msg "OK!"
fi
}
@@ -141,29 +178,29 @@ install_kiauh_macros(){
### create a backup of the config folder
backup_klipper_config_dir
### handle multi printer.cfg
if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then
if ls "$klipper_cfg_loc"/printer_* 2>/dev/null 1>&2; then
for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do
path=$(echo $config | rev | cut -d"/" -f2- | rev)
if [ ! -f $path/kiauh_macros.cfg ]; then
path=$(echo "$config" | rev | cut -d"/" -f2- | rev)
if [ ! -f "$path/kiauh_macros.cfg" ]; then
### copy kiauh_macros.cfg to config location
status_msg "Creating macro config file ..."
cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $path
cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$path"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" "$path/printer.cfg"
ok_msg "$path/kiauh_macros.cfg created!"
fi
done
### handle single printer.cfg
elif [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/kiauh_macros.cfg ]; then
elif [ -f "$klipper_cfg_loc/printer.cfg" ] && [ ! -f "$klipper_cfg_loc/kiauh_macros.cfg" ]; then
### copy kiauh_macros.cfg to config location
status_msg "Creating macro config file ..."
cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc
cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$klipper_cfg_loc"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" $klipper_cfg_loc/printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" "$klipper_cfg_loc/printer.cfg"
ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!"
fi
### restart klipper service to parse the modified printer.cfg
klipper_service "restart"
do_action_service "restart" "klipper"
fi
}
@@ -179,7 +216,7 @@ mainsail_port_check(){
select_mainsail_port
fi
else
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
SET_LISTEN_PORT=$DEFAULT_PORT
fi
SET_NGINX_CFG="true"
@@ -200,7 +237,7 @@ fluidd_port_check(){
select_fluidd_port
fi
else
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
SET_LISTEN_PORT=$DEFAULT_PORT
fi
SET_NGINX_CFG="true"
@@ -274,22 +311,22 @@ select_fluidd_port(){
}
get_mainsail_ver(){
MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/releases | grep tag_name | cut -d'"' -f4 | head -1)
MAINSAIL_VERSION=$(curl -s $MAINSAIL_REPO_API | grep tag_name | cut -d'"' -f4 | head -1)
}
get_fluidd_ver(){
FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | head -1)
FLUIDD_VERSION=$(curl -s $FLUIDD_REPO_API | grep tag_name | cut -d'"' -f4 | head -1)
}
mainsail_setup(){
### get mainsail download url
MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1)
MAINSAIL_DL_URL=$(curl -s $MAINSAIL_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1)
### remove existing and create fresh mainsail folder, then download mainsail
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
[ -d "$MAINSAIL_DIR" ] && rm -rf "$MAINSAIL_DIR"
mkdir "$MAINSAIL_DIR" && cd $MAINSAIL_DIR
status_msg "Downloading Mainsail $MAINSAIL_VERSION ..."
wget $MAINSAIL_DL_URL && ok_msg "Download complete!"
wget "$MAINSAIL_DL_URL" && ok_msg "Download complete!"
### extract archive
status_msg "Extracting archive ..."
@@ -300,25 +337,25 @@ mainsail_setup(){
rm -rf *.zip && ok_msg "Done!"
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode
if [ $(ls /etc/systemd/system/moonraker* | wc -l) -gt 1 ]; then
if [ $(ls /etc/systemd/system/moonraker* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then
enable_mainsail_remotemode
fi
}
enable_mainsail_remotemode(){
rm -f $MAINSAIL_DIR/config.json
echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json
rm -f "$MAINSAIL_DIR/config.json"
echo -e "{\n \"remoteMode\":true\n}" >> "$MAINSAIL_DIR/config.json"
}
fluidd_setup(){
### get fluidd download url
FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4)
FLUIDD_DL_URL=$(curl -s $FLUIDD_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1)
### remove existing and create fresh fluidd folder, then download fluidd
[ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR
mkdir $FLUIDD_DIR && cd $FLUIDD_DIR
[ -d "$FLUIDD_DIR" ] && rm -rf "$FLUIDD_DIR"
mkdir "$FLUIDD_DIR" && cd $FLUIDD_DIR
status_msg "Downloading Fluidd $FLUIDD_VERSION ..."
wget $FLUIDD_DL_URL && ok_msg "Download complete!"
wget "$FLUIDD_DL_URL" && ok_msg "Download complete!"
### extract archive
status_msg "Extracting archive ..."
@@ -327,4 +364,240 @@ fluidd_setup(){
### delete downloaded zip
status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!"
}
}
set_upstream_nginx_cfg(){
get_date
### backup existing nginx configs
[ ! -d "$BACKUP_DIR/nginx_cfg" ] && mkdir -p "$BACKUP_DIR/nginx_cfg"
[ -f "$NGINX_CONFD/upstreams.conf" ] && sudo mv "$NGINX_CONFD/upstreams.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_upstreams.conf"
[ -f "$NGINX_CONFD/common_vars.conf" ] && sudo mv "$NGINX_CONFD/common_vars.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_common_vars.conf"
### transfer ownership of backed up files from root to ${USER}
for log in $(ls "$BACKUP_DIR/nginx_cfg"); do
sudo chown "${USER}" "$BACKUP_DIR/nginx_cfg/$log"
done
### copy nginx configs to target destination
if [ ! -f "$NGINX_CONFD/upstreams.conf" ]; then
sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "$NGINX_CONFD"
fi
if [ ! -f "$NGINX_CONFD/common_vars.conf" ]; then
sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "$NGINX_CONFD"
fi
}
fetch_webui_ports(){
### read listen ports from possible installed interfaces
### and write them to ~/.kiauh.ini
WEBIFS=(mainsail fluidd octoprint dwc2)
for interface in "${WEBIFS[@]}"; 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 [ ! -n "$(grep -E "${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
}
match_nginx_configs(){
### reinstall nginx configs if the amount of upstreams don't match anymore
source_kiauh_ini
cfg_updated="false"
mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail"
fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd"
upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l)
status_msg "Checking validity of NGINX configurations ..."
if [ -e "$mainsail_nginx_cfg" ]; then
mainsail_webcams=$(grep -E "mjpgstreamer" "$mainsail_nginx_cfg" | wc -l)
fi
if [ -e "$fluidd_nginx_cfg" ]; then
fluidd_webcams=$(grep -E "mjpgstreamer" "$fluidd_nginx_cfg" | wc -l)
fi
### check for outdated upstreams.conf
if [[ "$upstreams_webcams" -lt "$mainsail_webcams" ]] || [[ "$upstreams_webcams" -lt "$fluidd_webcams" ]]; then
status_msg "Outdated upstreams.conf found! Updating ..."
sudo rm -f "$NGINX_CONFD/upstreams.conf"
sudo rm -f "$NGINX_CONFD/common_vars.conf"
set_upstream_nginx_cfg
cfg_updated="true"
fi
### check for outdated mainsail config
if [ -e "$mainsail_nginx_cfg" ]; then
if [[ "$upstreams_webcams" -gt "$mainsail_webcams" ]]; then
status_msg "Outdated Mainsail config found! Updating ..."
sudo rm -f "$mainsail_nginx_cfg"
sudo cp "${SRCDIR}/kiauh/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"
cfg_updated="true" && ok_msg "Done!"
fi
fi
### check for outdated fluidd config
if [ -e "$fluidd_nginx_cfg" ]; then
if [[ "$upstreams_webcams" -gt "$fluidd_webcams" ]]; then
status_msg "Outdated Fluidd config found! Updating ..."
sudo rm -f "$fluidd_nginx_cfg"
sudo cp "${SRCDIR}/kiauh/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"
cfg_updated="true" && ok_msg "Done!"
fi
fi
### only restart nginx if configs were updated
if [ "$cfg_updated" == "true" ]; then
restart_nginx && unset cfg_updated
fi
}
process_octoprint_dialog(){
#ask user to disable octoprint when its service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
hr
echo -e "| You might consider disabling the OctoPrint service, |"
echo -e "| since an active OctoPrint service may lead to unex- |"
echo -e "| pected behavior of the Klipper Webinterfaces. |"
bottom_border
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Stopping OctoPrint ..."
do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!"
status_msg "Disabling OctoPrint ..."
do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!"
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
process_disruptive_services(){
#handle haproxy service
if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo systemctl stop haproxy && ok_msg "Service stopped!"
fi
### disable haproxy
if [ "$DISABLE_HAPROXY" = "true" ]; then
status_msg "Disabling haproxy ..."
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
### remove haproxy
if [ "$REMOVE_HAPROXY" = "true" ]; then
status_msg "Removing haproxy ..."
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!"
fi
fi
fi
### handle lighttpd service
if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo systemctl stop lighttpd && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!"
### remove lighttpd
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
status_msg "Removing lighttpd ..."
sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!"
fi
fi
fi
### handle apache2 service
if [ "$DISABLE_APACHE2" = "true" ] || [ "$REMOVE_APACHE2" = "true" ]; then
if systemctl is-active apache2 -q; then
status_msg "Stopping apache2 service ..."
sudo systemctl stop apache2 && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "$DISABLE_APACHE2" = "true" ]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!"
### remove lighttpd
if [ "$REMOVE_APACHE2" = "true" ]; then
status_msg "Removing apache2 ..."
sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!"
fi
fi
fi
}
process_services_dialog(){
#notify user about haproxy or lighttpd services found and possible issues
if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ] || [ "$APACHE2_FOUND" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |"
hr
if [ "$HAPROXY_FOUND" = "true" ]; then
echo -e "| ● haproxy |"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
echo -e "| ● lighttpd |"
fi
if [ "$APACHE2_FOUND" = "true" ]; then
echo -e "| ● apache2 |"
fi
hr
echo -e "| Having those packages installed can lead to unwanted |"
echo -e "| behaviour. It is recommend to remove those packages. |"
echo -e "| |"
echo -e "| 1) Remove packages (recommend) |"
echo -e "| 2) Disable only (may cause issues) |"
echo -e "| ${red}3) Skip this step (not recommended)${default} |"
bottom_border
read -p "${cyan}###### Please choose:${default} " action
case "$action" in
1)
echo -e "###### > Remove packages"
REMOVE_HAPROXY="true"
REMOVE_LIGHTTPD="true"
REMOVE_APACHE2="true"
break;;
2)
echo -e "###### > Disable only"
DISABLE_HAPROXY="true"
DISABLE_LIGHTTPD="true"
DISABLE_APACHE2="true"
break;;
3)
echo -e "###### > Skip"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}

View File

@@ -1,11 +1,11 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
WEBCAM_TXT_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
WEBCAMD_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
WEBCAM_TXT_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
install_mjpg-streamer(){
### checking dependencies
check_klipper_cfg_path
source_kiauh_ini
### set default values
MJPG_SERV_SRC="${SRCDIR}/kiauh/resources/webcamd.service"
@@ -15,26 +15,31 @@ install_mjpg-streamer(){
### if there is a webcamd.service -> exit
if [ -f $MJPG_SERV_TARGET ]; then
ERROR_MSG="Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
print_msg && clear_msg && return 0
print_msg && clear_msg && return
fi
### check and install dependencies if missing
dep=(build-essential git imagemagick libv4l-dev libjpeg-dev libjpeg62-turbo-dev cmake)
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
### step 1: clone moonraker
status_msg "Downloading MJPG-Streamer ..."
cd ${HOME} && git clone https://github.com/jacksonliam/mjpg-streamer.git
cd "${HOME}" && git clone https://github.com/jacksonliam/mjpg-streamer.git
ok_msg "Download complete!"
### step 2: compiling mjpg-streamer
status_msg "Compiling MJPG-Streamer ..."
cd ${HOME}/mjpg-streamer/mjpg-streamer-experimental && make
cd "${HOME}"/mjpg-streamer/mjpg-streamer-experimental && make
ok_msg "Compiling complete!"
#step 3: install mjpg-streamer
status_msg "Installing MJPG-Streamer ..."
cd ${HOME}/mjpg-streamer && mv mjpg-streamer-experimental/* .
cd "${HOME}"/mjpg-streamer && mv mjpg-streamer-experimental/* .
mkdir www-mjpgstreamer
cat <<EOT >> ./www-mjpgstreamer/index.html
<html>
@@ -54,16 +59,16 @@ EOT
sudo chmod +x /usr/local/bin/webcamd
### step 4: create webcam.txt config file
[ ! -d $klipper_cfg_loc ] && mkdir -p $klipper_cfg_loc
if [ ! -f $WEBCAM_TXT ]; then
[ ! -d "$klipper_cfg_loc" ] && mkdir -p "$klipper_cfg_loc"
if [ ! -f "$WEBCAM_TXT" ]; then
status_msg "Creating webcam.txt config file ..."
wget $WEBCAM_TXT_SRC -O $WEBCAM_TXT
wget $WEBCAM_TXT_SRC -O "$WEBCAM_TXT"
ok_msg "Done!"
fi
### step 5: create systemd service
status_msg "Creating MJPG-Streamer service ..."
sudo cp $MJPG_SERV_SRC $MJPG_SERV_TARGET
sudo cp "$MJPG_SERV_SRC" $MJPG_SERV_TARGET
sudo sed -i "s|%USER%|${USER}|" $MJPG_SERV_TARGET
ok_msg "MJPG-Streamer service created!"
@@ -74,13 +79,47 @@ EOT
ok_msg "MJPG-Streamer service started!"
### step 6.1: create webcamd.log symlink
[ ! -d ${HOME}/klipper_logs ] && mkdir -p "${HOME}/klipper_logs"
[ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs"
if [ -f "/var/log/webcamd.log" ] && [ ! -L "${HOME}/klipper_logs/webcamd.log" ]; then
ln -s "/var/log/webcamd.log" "${HOME}/klipper_logs/webcamd.log"
fi
### 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"
usergroup_changed=false
USER_IN_VIDEO_GROUP=$(groups "${USER}" | grep "video")
if [ -z "$USER_IN_VIDEO_GROUP" ]; then
status_msg "Adding user ${USER} to group 'video' ..."
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
usergroup_changed=true
else
ok_msg "User ${USER} already in group 'video'!"
fi
### confirm message
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_msg && clear_msg
### print webcam ip adress/url

View File

@@ -0,0 +1,23 @@
install_MoonrakerTelegramBot(){
source_kiauh_ini
#MoonrakerTelegramBot main installation
MoonrakerTelegramBot_setup
#after install actions
restart_MoonrakerTelegramBot
}
MoonrakerTelegramBot_setup(){
source_kiauh_ini
export klipper_cfg_loc
dep=(virtualenv)
dependency_check
status_msg "Downloading MoonrakerTelegramBot ..."
#force remove existing MoonrakerTelegramBot dir
[ -d $MOONRAKER_TELEGRAM_BOT_DIR ] && rm -rf $MOONRAKER_TELEGRAM_BOT_DIR
#clone into fresh MoonrakerTelegramBot dir
cd ${HOME} && git clone $NLEF_REPO
ok_msg "Download complete!"
status_msg "Installing MoonrakerTelegramBot ..."
$MOONRAKER_TELEGRAM_BOT_DIR/scripts/install.sh
echo; ok_msg "MoonrakerTelegramBot successfully installed!"
}

View File

@@ -9,105 +9,86 @@ system_check_moonraker(){
status_msg "Your Python 3 version is: $(python3 --version)"
major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1)
minor=$(python3 --version | cut -d"." -f2)
if [ $major -ge 3 ] && [ $minor -ge 7 ]; then
ok_msg "Python version ok!"
if [ "$major" -ge 3 ] && [ "$minor" -ge 7 ]; then
py_chk_ok="true"
else
warn_msg "Python version not ok!"
py_chk_ok="false"
fi
### check system for an installed and enabled octoprint service
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
OCTOPRINT_ENABLED="true"
fi
### check system for an installed haproxy service
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true"
fi
### check system for an installed lighttpd service
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
LIGHTTPD_FOUND="true"
fi
}
moonraker_setup_dialog(){
status_msg "Initializing Moonraker installation ..."
### check system for several requirements before initializing the moonraker installation
system_check_moonraker
### exit moonraker setup if python version is not ok
if [ $py_chk_ok = "false" ]; then
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
print_msg && clear_msg && return 0
fi
shopt -s extglob # enable extended globbing
### check for existing moonraker service installations
FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service"
if ls $FILE 2>/dev/null 1>&2; then
ERROR_MSG="At least one Moonraker service is already installed!" && return 0
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service")
if [ -n "$SERVICE_FILES" ]; then
ERROR_MSG="At least one Moonraker service is already installed:"
for service in $SERVICE_FILES; do
ERROR_MSG="${ERROR_MSG}\n ➔ $service"
done && return
fi
### check for existing klipper service installations
FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service"
if ! ls $FILE 2>/dev/null 1>&2; then
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
status_msg "Initializing Moonraker installation ..."
### checking system for python3.7+
system_check_moonraker
### exit moonraker setup if python versioncheck fails
if [ $py_chk_ok = "false" ]; then
ERROR_MSG="Versioncheck failed! Python 3.7 or newer required!\n"
ERROR_MSG="${ERROR_MSG} Please upgrade Python."
print_msg && clear_msg && return
fi
shopt -u extglob # disable extended globbing
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])+[0-9]*.service")
if [ -f /etc/init.d/klipper ] || [ -f /etc/systemd/system/klipper.service ]; then
KLIPPER_COUNT=1
elif [ -n "$SERVICE_FILES" ]; then
KLIPPER_COUNT=$(echo "$SERVICE_FILES" | wc -l)
fi
### initial moonraker.conf path check
check_klipper_cfg_path
### ask user how to handle OctoPrint, Haproxy and Lighttpd
process_octoprint_dialog
process_haproxy_lighttpd_dialog
### instance confirmation dialog
while true; do
top_border
if [[ $KLIPPER_COUNT -eq 1 ]]; then
printf "|${green}%-55s${default}|\n" " 1 Klipper instance was found!"
elif [[ $KLIPPER_COUNT -gt 1 ]]; then
printf "|${green}%-55s${default}|\n" " $KLIPPER_COUNT Klipper instances were found!"
else
echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |"
fi
echo -e "| Usually you need one Moonraker instance per Klipper |"
echo -e "| instance. Though you can install as many as you wish. |"
bottom_border
echo
count=""
while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do
read -p "${cyan}###### Number of Moonraker instances to set up:${default} " count
if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then
warn_msg "Invalid Input!\n"
else
echo
top_border
if [ $INSTANCE_COUNT -gt 1 ]; then
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
else
echo -e "| 1 Klipper instance was found! | "
fi
echo -e "| You need one Moonraker instance per Klipper instance. | "
bottom_border
echo
read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn
read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT Moonraker instances ..."
moonraker_setup
status_msg "Installing Moonraker ...\n"
moonraker_setup "$count"
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting Moonraker setup ..."
echo
warn_msg "Exiting Moonraker setup ...\n"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
esac
fi
done
}
moonraker_setup(){
INSTANCE_COUNT=$1
### checking dependencies
dep=(wget curl unzip dfu-util)
dep=(wget curl unzip dfu-util virtualenv)
### additional deps for kiauh compatibility for armbian
dep+=(libjpeg-dev zlib1g-dev)
dependency_check
@@ -115,8 +96,8 @@ moonraker_setup(){
### step 1: clone moonraker
status_msg "Downloading Moonraker ..."
### force remove existing moonraker dir and clone into fresh moonraker dir
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
cd ${HOME} && git clone $MOONRAKER_REPO
[ -d "$MOONRAKER_DIR" ] && rm -rf "$MOONRAKER_DIR"
cd "${HOME}" && git clone $MOONRAKER_REPO
ok_msg "Download complete!"
### step 2: install moonraker dependencies and create python virtualenv
@@ -127,19 +108,18 @@ moonraker_setup(){
### step 3: create moonraker.conf folder and moonraker.confs
create_moonraker_conf
### step 4: set up moonrakers nginx configs
setup_moonraker_nginx_cfg
### step 5: process possible disruptive services
process_haproxy_lighttpd_services
# ### step 6: create final moonraker instances
### step 4: create final moonraker instances
create_moonraker_service
### step 5: create polkit rules for moonraker
moonraker_polkit
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
[ $INSTANCE_COUNT -eq 1 ] && CONFIRM_MSG="Moonraker has been set up!"
print_msg && clear_msg
if [[ $INSTANCE_COUNT -eq 1 ]]; then
CONFIRM_MSG="Moonraker has been set up!"
elif [[ $INSTANCE_COUNT -gt 1 ]]; then
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
fi && print_msg && clear_msg
### display moonraker ips to the user
print_mr_ip_list; echo
@@ -149,37 +129,36 @@ install_moonraker_packages(){
### read PKGLIST from official install script
status_msg "Reading dependencies..."
install_script="${HOME}/moonraker/scripts/install-moonraker.sh"
PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g')
### rewrite packages into new array
unset PKGARR
for PKG in $PKGLIST; do PKGARR+=($PKG); done
echo "${cyan}${PKGARR[@]}${default}"
PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n')
for pkg in $PKGLIST; do
echo "${cyan}$pkg${default}"
done
read -r -a PKGLIST <<< "$PKGLIST"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
sudo apt-get update --allow-releaseinfo-change
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGARR[@]}
sudo apt-get install --yes "${PKGLIST[@]}"
}
create_moonraker_virtualenv(){
status_msg "Installing python virtual environment..."
### If venv exists and user prompts a rebuild, then do so
if [ -d ${MOONRAKER_ENV} ] && [ $REBUILD_ENV = "y" ]; then
if [ -d "$MOONRAKER_ENV" ] && [ "$REBUILD_ENV" = "y" ]; then
status_msg "Removing old virtualenv"
rm -rf ${MOONRAKER_ENV}
rm -rf "$MOONRAKER_ENV"
fi
if [ ! -d ${MOONRAKER_ENV} ]; then
virtualenv -p /usr/bin/python3 ${MOONRAKER_ENV}
ln -s /usr/lib/python3/dist-packages/gpiod* ${MOONRAKER_ENV}/lib/python*/site-packages
if [ ! -d "$MOONRAKER_ENV" ]; then
virtualenv -p /usr/bin/python3 "$MOONRAKER_ENV"
fi
### Install/update dependencies
${MOONRAKER_ENV}/bin/pip install -r ${MOONRAKER_DIR}/scripts/moonraker-requirements.txt
"$MOONRAKER_ENV"/bin/pip install -r "$MOONRAKER_DIR"/scripts/moonraker-requirements.txt
}
create_moonraker_service(){
@@ -199,7 +178,7 @@ create_moonraker_service(){
write_mr_service(){
if [ ! -f $MR_SERV_TARGET ]; then
status_msg "Creating Moonraker Service $i ..."
sudo cp $MR_SERV_SRC $MR_SERV_TARGET
sudo cp "$MR_SERV_SRC" $MR_SERV_TARGET
sudo sed -i "s|%INST%|$i|" $MR_SERV_TARGET
sudo sed -i "s|%USER%|${USER}|" $MR_SERV_TARGET
sudo sed -i "s|%MR_ENV%|$MR_ENV|" $MR_SERV_TARGET
@@ -209,18 +188,17 @@ create_moonraker_service(){
fi
}
if [ $SINGLE_INST -eq $INSTANCE_COUNT ]; then
if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then
### write single instance service
write_mr_service
### enable instance
sudo systemctl enable moonraker.service
do_action_service "enable" "moonraker"
ok_msg "Single Moonraker instance created!"
### launching instance
status_msg "Launching Moonraker instance ..."
sudo systemctl start moonraker
do_action_service "start" "moonraker"
else
i=1
while [ $i -le $INSTANCE_COUNT ]; do
while [[ $i -le $INSTANCE_COUNT ]]; do
### rewrite default variables for multi instance cases
CFG_PATH="$klipper_cfg_loc/printer_$i"
MR_SERV_TARGET="$SYSTEMDDIR/moonraker-$i.service"
@@ -229,19 +207,17 @@ create_moonraker_service(){
### write multi instance service
write_mr_service
### enable instance
sudo systemctl enable moonraker-$i.service
do_action_service "enable" "moonraker-$i"
ok_msg "Moonraker instance #$i created!"
### launching instance
status_msg "Launching Moonraker instance #$i ..."
sudo systemctl start moonraker-$i
do_action_service "start" "moonraker-$i"
### raise values by 1
i=$((i+1))
done
unset i
### enable mainsails remoteMode if mainsail is found
if [ -d $MAINSAIL_DIR ]; then
if [ -d "$MAINSAIL_DIR" ]; then
status_msg "Mainsail installation found!"
status_msg "Enabling Mainsail remoteMode ..."
enable_mainsail_remotemode
@@ -260,7 +236,7 @@ create_moonraker_conf(){
CFG_PATH="$klipper_cfg_loc"
LOG_PATH="${HOME}/klipper_logs"
MR_CONF="$CFG_PATH/moonraker.conf"
MR_DB="~/.moonraker_database"
MR_DB="${HOME}/.moonraker_database"
KLIPPY_UDS="/tmp/klippy_uds"
MR_CONF_SRC="${SRCDIR}/kiauh/resources/moonraker.conf"
mr_ip_list=()
@@ -268,17 +244,23 @@ create_moonraker_conf(){
LAN="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
write_mr_conf(){
[ ! -d $CFG_PATH ] && mkdir -p $CFG_PATH
if [ ! -f $MR_CONF ]; then
[ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH"
if [ ! -f "$MR_CONF" ]; then
status_msg "Creating moonraker.conf in $CFG_PATH ..."
cp $MR_CONF_SRC $MR_CONF
sed -i "s|%PORT%|$PORT|" $MR_CONF
sed -i "s|%CFG%|$CFG_PATH|" $MR_CONF
sed -i "s|%LOG%|$LOG_PATH|" $MR_CONF
sed -i "s|%MR_DB%|$MR_DB|" $MR_CONF
sed -i "s|%UDS%|$KLIPPY_UDS|" $MR_CONF
sed -i "s|%LAN%|$LAN|" $MR_CONF
sed -i "s|%USER%|${USER}|g" $MR_CONF
cp "$MR_CONF_SRC" "$MR_CONF"
sed -i "s|%PORT%|$PORT|" "$MR_CONF"
sed -i "s|%CFG%|$CFG_PATH|" "$MR_CONF"
sed -i "s|%LOG%|$LOG_PATH|" "$MR_CONF"
sed -i "s|%MR_DB%|$MR_DB|" "$MR_CONF"
sed -i "s|%UDS%|$KLIPPY_UDS|" "$MR_CONF"
# if host ip is not in the default ip ranges, replace placeholder
# otherwise remove placeholder from config
if ! grep -q "$LAN" "$MR_CONF"; then
sed -i "s|%LAN%|$LAN|" "$MR_CONF"
else
sed -i "/%LAN%/d" "$MR_CONF"
fi
sed -i "s|%USER%|${USER}|g" "$MR_CONF"
ok_msg "moonraker.conf created!"
else
warn_msg "There is already a file called 'moonraker.conf'!"
@@ -286,17 +268,17 @@ create_moonraker_conf(){
fi
}
if [ $SINGLE_INST -eq $INSTANCE_COUNT ]; then
if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then
### write single instance config
write_mr_conf
mr_ip_list+=("$IP:$PORT")
else
i=1
while [ $i -le $INSTANCE_COUNT ]; do
while [[ $i -le $INSTANCE_COUNT ]]; do
### rewrite default variables for multi instance cases
CFG_PATH="$klipper_cfg_loc/printer_$i"
MR_CONF="$CFG_PATH/moonraker.conf"
MR_DB="~/.moonraker_database_$i"
MR_DB="${HOME}/.moonraker_database_$i"
KLIPPY_UDS="/tmp/klippy_uds-$i"
### write multi instance config
@@ -313,155 +295,27 @@ create_moonraker_conf(){
print_mr_ip_list(){
i=1
for ip in ${mr_ip_list[@]}; do
for ip in "${mr_ip_list[@]}"; do
echo -e " ${cyan}● Instance $i:${default} $ip"
i=$((i + 1))
done
}
setup_moonraker_nginx_cfg(){
get_date
### backup existing nginx configs
[ -f $NGINX_CONFD/upstreams.conf ] && sudo mv $NGINX_CONFD/upstreams.conf $NGINX_CONFD/$current_date_upstreams.conf
[ -f $NGINX_CONFD/common_vars.conf ] && sudo mv $NGINX_CONFD/common_vars.conf $NGINX_CONFD/$current_date_common_vars.conf
### copy nginx configs to target destination
if [ ! -f $NGINX_CONFD/upstreams.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/upstreams.conf $NGINX_CONFD
fi
if [ ! -f $NGINX_CONFD/common_vars.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/common_vars.conf $NGINX_CONFD
fi
}
process_octoprint_dialog(){
#ask user to disable octoprint when its service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
hr
echo -e "| You might consider disabling the OctoPrint service, |"
echo -e "| since an active OctoPrint service may lead to unex- |"
echo -e "| pected behavior of the Klipper Webinterfaces. |"
bottom_border
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Stopping OctoPrint ..."
octoprint_service "stop" && ok_msg "OctoPrint service stopped!"
status_msg "Disabling OctoPrint ..."
octoprint_service "disable" && ok_msg "OctoPrint service disabled!"
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
process_haproxy_lighttpd_services(){
#handle haproxy service
if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo systemctl stop haproxy && ok_msg "Service stopped!"
### introduced due to
### https://github.com/Arksine/moonraker/issues/349
### https://github.com/Arksine/moonraker/pull/346
moonraker_polkit(){
SYSTEMDDIR="/etc/systemd/system"
MOONRAKER_SERVICES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service")
for service in $MOONRAKER_SERVICES; do
HAS_SUPP="$( grep -cm1 "SupplementaryGroups=moonraker-admin" "$service" || true )"
if [ "$HAS_SUPP" -eq 0 ]; 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
### disable haproxy
if [ "$DISABLE_HAPROXY" = "true" ]; then
status_msg "Disabling haproxy ..."
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
### remove haproxy
if [ "$REMOVE_HAPROXY" = "true" ]; then
status_msg "Removing haproxy ..."
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!"
fi
fi
fi
### handle lighttpd service
if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo systemctl stop lighttpd && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!"
### remove lighttpd
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
status_msg "Removing lighttpd ..."
sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!"
fi
fi
fi
}
process_haproxy_lighttpd_dialog(){
#notify user about haproxy or lighttpd services found and possible issues
if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |"
hr
if [ "$HAPROXY_FOUND" = "true" ]; then
echo -e "| ● haproxy |"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
echo -e "| ● lighttpd |"
fi
hr
echo -e "| Having those packages installed can lead to unwanted |"
echo -e "| behaviour. It is recommend to remove those packages. |"
echo -e "| |"
echo -e "| 1) Remove packages (recommend) |"
echo -e "| 2) Disable only (may cause issues) |"
echo -e "| ${red}3) Skip this step (not recommended)${default} |"
bottom_border
read -p "${cyan}###### Please choose:${default} " action
case "$action" in
1)
echo -e "###### > Remove packages"
if [ "$HAPROXY_FOUND" = "true" ]; then
DISABLE_HAPROXY="true"
REMOVE_HAPROXY="true"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
DISABLE_LIGHTTPD="true"
REMOVE_LIGHTTPD="true"
fi
break;;
2)
echo -e "###### > Disable only"
if [ "$HAPROXY_FOUND" = "true" ]; then
DISABLE_HAPROXY="true"
REMOVE_HAPROXY="false"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
DISABLE_LIGHTTPD="true"
REMOVE_LIGHTTPD="false"
fi
break;;
3)
echo -e "###### > Skip"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
done
### execute moonrakers policykit-rules script
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
sudo systemctl daemon-reload
}

View File

@@ -0,0 +1,37 @@
### base variables
PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode"
PGC_DIR="${HOME}/pgcode"
install_pgc_for_klipper(){
pgconfsrc="$PGC_DIR/pgcode.local.conf"
pgconf="/etc/nginx/sites-available/pgcode.local.conf"
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
pgc_default_port="7136"
status_msg "Installing PrettyGCode for Klipper ..."
### let the user decide which port is used
echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: $pgc_default_port)${default} "
read -e -p "${cyan}###### Port:${default} " -i "$pgc_default_port" pgc_custom_port
### check nginx dependency
dep=(nginx)
dependency_check
### clone repo
[ -d $PGC_DIR ] && rm -rf $PGC_DIR
cd ${HOME} && git clone $PGC_FOR_KLIPPER_REPO
### copy nginx config into destination directory
sudo cp $pgconfsrc $pgconf
### replace default pi user in case the user is called different
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
### create symlink
[ ! -L $pgconfsl ] && sudo ln -s $pgconf $pgconfsl
sudo systemctl restart nginx
### show URI
pgc_uri="http://$(hostname -I | cut -d" " -f1):$pgc_custom_port"
echo -e "${cyan}\n● Accessible via:${default} $pgc_uri"
ok_msg "PrettyGCode for Klipper installed!\n"
}

View File

@@ -1,6 +1,64 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
get_theme_list(){
theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv"
theme_csv=$(curl -s -L $theme_csv_url)
unset t_name
unset t_note
unset t_auth
unset t_url
i=0
while IFS="," read -r col1 col2 col3 col4; do
t_name+=("$col1")
t_note+=("$col2")
t_auth+=("$col3")
t_url+=("$col4")
if [ ! "$col1" == "name" ]; then
printf "| $i) %-50s|\n" "[$col1]"
fi
i=$((i+1))
done <<< "$theme_csv"
}
ms_theme_ui(){
top_border
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | "
hr
echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | "
echo -e "| https://docs.mainsail.xyz/theming/themes | "
blank_line
echo -e "| ${yellow}Important note:${default} | "
echo -e "| Installing a theme from this menu will overwrite an | "
echo -e "| already installed theme or modified custom.css file! | "
hr
get_theme_list # dynamically generate the themelist from a csv file
echo -e "| | "
echo -e "| R) [Remove Theme] | "
back_footer
}
ms_theme_menu(){
ms_theme_ui
while true; do
read -p "${cyan}Install theme:${default} " a; echo
if [ "$a" = "b" ] || [ "$a" = "B" ]; then
clear && advanced_menu && break
elif [ "$a" = "r" ] || [ "$a" = "R" ]; then
ms_theme_delete
ms_theme_menu
elif [ "$a" -le ${#t_url[@]} ]; then
ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}"
ms_theme_menu
else
clear && print_header
ERROR_MSG="Invalid command!" && print_msg && clear_msg
ms_theme_menu
fi
done
ms_theme_menu
}
check_select_printer(){
unset printer_num
@@ -10,8 +68,8 @@ check_select_printer(){
### check if there is more than one moonraker instance and if yes
### ask the user to select the printer he wants to install/remove the theme
printer_count=$(ls /etc/systemd/system/moonraker*.service | wc -l)
if [ $printer_count -gt 1 ]; then
MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l)
if [[ $MR_SERVICE_COUNT -gt 1 ]]; then
top_border
echo -e "| More than one printer was found on this system! | "
echo -e "| Please select the printer to which you want to | "
@@ -24,14 +82,29 @@ check_select_printer(){
fi
### create the cfg folder if there is none yet
[ ! -d $THEME_PATH ] && mkdir -p $THEME_PATH
[ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH"
}
ms_theme_delete(){
ms_theme_install(){
THEME_URL="https://github.com/$1/$2"
### check and select printer if there is more than 1
check_select_printer
### remove .theme folder
### download all files
status_msg "Installing $3 ..."
status_msg "Please wait ..."
[ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme"
cd "$THEME_PATH" && git clone "$THEME_URL" ".theme"
ok_msg "Theme installation complete!"
[ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}"
ok_msg "Please remember to delete your browser cache!\n"
}
ms_theme_delete(){
check_select_printer
if [ -d "$THEME_PATH/.theme" ]; then
status_msg "Removing Theme ..."
rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n"
@@ -39,37 +112,3 @@ ms_theme_delete(){
status_msg "No Theme installed!\n"
fi
}
ms_theme_dracula(){
THEME_URL="https://github.com/steadyjaw/dracula-mainsail-theme"
### check and select printer if there is more than 1
check_select_printer
### download all files
status_msg "Installing Dracula theme ..."
status_msg "Please wait ..."
[ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme"
cd $THEME_PATH && git clone "$THEME_URL" ".theme"
ok_msg "Theme installation complete!"
ok_msg "Please remember to delete your browser cache!\n"
}
ms_theme_cyberpunk(){
THEME_URL="https://github.com/Dario-Ciceri/cp2077-mainsail-theme"
### check and select printer if there is more than 1
check_select_printer
### download all files
status_msg "Installing Cyberpunk theme ..."
status_msg "Please wait ..."
[ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme"
cd $THEME_PATH && git clone "$THEME_URL" ".theme"
ok_msg "Theme installation complete!"
ok_msg "Please remember to delete your browser cache!\n"
}

View File

@@ -240,6 +240,9 @@ remove_dwc2(){
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
fi
### remove dwc2_port from ~/.kiauh.ini
sed -i "/^dwc2_port=/d" $INI_FILE
CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!"
}
@@ -273,6 +276,9 @@ remove_mainsail(){
rm -f $log
done
### remove mainsail_port from ~/.kiauh.ini
sed -i "/^mainsail_port=/d" $INI_FILE
CONFIRM_MSG="Mainsail successfully removed!"
}
@@ -303,6 +309,9 @@ remove_fluidd(){
rm -f $log
done
### remove fluidd_port from ~/.kiauh.ini
sed -i "/^fluidd_port=/d" $INI_FILE
CONFIRM_MSG="Fluidd successfully removed!"
}
@@ -345,6 +354,9 @@ remove_octoprint(){
done
fi
### remove octoprint_port from ~/.kiauh.ini
sed -i "/^octoprint_port=/d" $INI_FILE
CONFIRM_MSG=" OctoPrint successfully removed!"
}
@@ -352,12 +364,10 @@ remove_octoprint(){
#############################################################
remove_nginx(){
if [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]] ; then
if systemctl is-active nginx -q; then
status_msg "Stopping Nginx service ..."
sudo service nginx stop && sudo systemctl disable nginx
ok_msg "Service stopped!"
fi
if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then
status_msg "Stopping Nginx service ..."
sudo systemctl stop nginx && sudo systemctl disable nginx
ok_msg "Service stopped and disabled!"
status_msg "Purging Nginx from system ..."
sudo apt-get purge nginx nginx-common -y
sudo update-rc.d -f nginx remove
@@ -386,7 +396,7 @@ remove_klipperscreen(){
if [ -e /etc/systemd/system/KlipperScreen.service ]; then
status_msg "Removing KlipperScreen service ..."
sudo systemctl stop KlipperScreen
sudo systemctl disable moonraker
sudo systemctl disable KlipperScreen
sudo rm -f $SYSTEMDDIR/KlipperScreen.service
###reloading units
sudo systemctl daemon-reload
@@ -410,6 +420,49 @@ remove_klipperscreen(){
CONFIRM_MSG="KlipperScreen successfully removed!"
}
remove_MoonrakerTelegramBot(){
source_kiauh_ini
### remove MoonrakerTelegramBot dir
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ]; then
status_msg "Removing MoonrakerTelegramBot directory ..."
rm -rf $MOONRAKER_TELEGRAM_BOT_DIR && ok_msg "Directory removed!"
fi
### remove MoonrakerTelegramBot VENV dir
if [ -d $MOONRAKER_TELEGRAM_BOT_ENV_DIR ]; then
status_msg "Removing MoonrakerTelegramBot VENV directory ..."
rm -rf $MOONRAKER_TELEGRAM_BOT_ENV_DIR && ok_msg "Directory removed!"
fi
### remove MoonrakerTelegramBot service
if [ -e /etc/systemd/system/moonraker-telegram-bot.service ]; then
status_msg "Removing MoonrakerTelegramBot service ..."
sudo systemctl stop moonraker-telegram-bot
sudo systemctl disable moonraker-telegram-bot
sudo rm -f $SYSTEMDDIR/moonraker-telegram-bot.service
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "MoonrakerTelegramBot Service removed!"
fi
### remove MoonrakerTelegramBot log
if [ -e /tmp/telegram.log ] || [ -e ${HOME}/klipper_logs/telegram.log ]; then
status_msg "Removing MoonrakerTelegramBot log file ..."
rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" && ok_msg "File removed!"
fi
### remove MoonrakerTelegramBot log symlink in config dir
if [ -e $klipper_cfg_loc/telegram.log ]; then
status_msg "Removing MoonrakerTelegramBot log symlink ..."
rm -f $klipper_cfg_loc/telegram.log && ok_msg "File removed!"
fi
CONFIRM_MSG="MoonrakerTelegramBot successfully removed!"
}
remove_mjpg-streamer(){
### remove MJPG-Streamer service
if [ -e $SYSTEMDDIR/webcamd.service ]; then
@@ -439,4 +492,19 @@ remove_mjpg-streamer(){
[ -L "${HOME}/klipper_logs/webcamd.log" ] && rm -f "${HOME}/klipper_logs/webcamd.log"
CONFIRM_MSG="MJPG-Streamer successfully removed!"
}
}
remove_prettygcode(){
pgconf="/etc/nginx/sites-available/pgcode.local.conf"
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
if [ -d ${HOME}/pgcode ] || [ -f $pgconf ] || [ -L $pgconfsl ]; then
status_msg "Removing PrettyGCode for Klipper ..."
rm -rf ${HOME}/pgcode
sudo rm -f $pgconf
sudo rm -f $pgconfsl
sudo systemctl restart nginx
CONFIRM_MSG="PrettyGCode for Klipper successfully removed!"
else
ERROR_MSG="PrettyGCode for Klipper not found!\n Skipping..."
fi
}

View File

@@ -50,6 +50,25 @@ load_klipper_state(){
rollback_klipper
}
rollback_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | "
hr
echo -e "| If serious errors occured after updating Klipper, | "
echo -e "| you can use this menu to return to the previously | "
echo -e "| used commit from which you have updated. | "
bottom_border
top_border
echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | "
hr
echo -e "| Currently on commit: | "
echo -e "| $CURR_UI | "
hr
echo -e "| Commit last updated from: | "
echo -e "| $PREV_UI | "
back_footer
}
rollback_klipper(){
if [ "$PREVIOUS_COMMIT" != "0" ] && [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then
while true; do
@@ -66,7 +85,7 @@ rollback_klipper(){
load_klipper_state
break;;
N|n|No|no) clear; advanced_menu; break;;
Q|q) clear; advanced_menu; break;;
B|b) clear; advanced_menu; break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
@@ -78,7 +97,7 @@ rollback_klipper(){
read -p "Perform action: " action; echo
echo -e "${default}"
case "$action" in
Q|q)
B|b)
clear; advanced_menu; break;;
*)
clear
@@ -89,4 +108,4 @@ rollback_klipper(){
esac
done
fi
}
}

View File

@@ -13,7 +13,8 @@ kiauh_status(){
check_system_updates(){
SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d")
if [ ! -z "$SYS_UPDATE" ]; then
SYS_UPDATE_AVAIL="true"
# add system updates to the update all array for the update all function in the updater
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${default}"
else
SYS_UPDATE_AVAIL="false"
@@ -228,6 +229,36 @@ klipperscreen_status(){
fi
}
MoonrakerTelegramBot_status(){
mtbcount=0
MoonrakerTelegramBot_data=(
SERVICE
$MOONRAKER_TELEGRAM_BOT_DIR
$MOONRAKER_TELEGRAM_BOT_ENV_DIR
)
### count amount of MoonrakerTelegramBot_data service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker-telegram-bot" | wc -l)
### remove the "SERVICE" entry from the MoonrakerTelegramBot_data array if a MoonrakerTelegramBot service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset MoonrakerTelegramBot_data[0]
#count+1 for each found data-item from array
for mtbd in "${MoonrakerTelegramBot_data[@]}"
do
if [ -e $mtbd ]; then
mtbcount=$(expr $mtbcount + 1)
fi
done
if [ "$mtbcount" == "${#MoonrakerTelegramBot_data[*]}" ]; then
MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${default} "
elif [ "$mtbcount" == 0 ]; then
MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${default} "
else
MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${default} "
fi
}
#############################################################
#############################################################
@@ -300,8 +331,8 @@ compare_klipper_versions(){
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
LOCAL_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_COMMIT")${default}"
REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}"
KLIPPER_UPDATE_AVAIL="true"
update_arr+=(update_klipper)
# add klipper to the update all array for the update all function in the updater
KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper)
else
LOCAL_COMMIT="${green}$(printf "%-12s" "$LOCAL_COMMIT")${default}"
REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}"
@@ -334,8 +365,8 @@ compare_dwc2fk_versions(){
if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then
LOCAL_DWC2FK_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}"
REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}"
DWC2FK_UPDATE_AVAIL="true"
update_arr+=(update_dwc2fk)
# add dwc2fk to the update all array for the update all function in the updater
DWC2FK_UPDATE_AVAIL="true" && update_arr+=(update_dwc2fk)
else
LOCAL_DWC2FK_COMMIT="${green}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}"
REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}"
@@ -373,7 +404,7 @@ compare_dwc2_versions(){
elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then
DWC2_LOCAL_VER="${yellow}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}"
DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}"
# set flag for the multi update function
# add dwc to the update all array for the update all function in the updater
DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2)
else
DWC2_LOCAL_VER=$NONE
@@ -403,8 +434,8 @@ compare_moonraker_versions(){
if [ "$LOCAL_MOONRAKER_COMMIT" != "$REMOTE_MOONRAKER_COMMIT" ]; then
LOCAL_MOONRAKER_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_MOONRAKER_COMMIT")${default}"
REMOTE_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_COMMIT")${default}"
MOONRAKER_UPDATE_AVAIL="true"
update_arr+=(update_moonraker)
# add moonraker to the update all array for the update all function in the updater
MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker)
else
LOCAL_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_COMMIT")${default}"
REMOTE_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_COMMIT")${default}"
@@ -442,7 +473,7 @@ compare_mainsail_versions(){
elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then
MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}"
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
# set flag for the multi update function
# add mainsail to the update all array for the update all function in the updater
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
else
MAINSAIL_LOCAL_VER=$NONE
@@ -481,7 +512,7 @@ compare_fluidd_versions(){
elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then
FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}"
FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}"
# set flag for the multi update function
# add fluidd to the update all array for the update all function in the updater
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
else
FLUIDD_LOCAL_VER=$NONE
@@ -517,6 +548,65 @@ compare_klipperscreen_versions(){
fi
}
read_MoonrakerTelegramBot_versions(){
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] && [ -d $MOONRAKER_TELEGRAM_BOT_DIR/.git ]; then
cd $MOONRAKER_TELEGRAM_BOT_DIR
git fetch origin master -q
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
else
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$NONE
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$NONE
fi
}
compare_MoonrakerTelegramBot_versions(){
unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL
read_MoonrakerTelegramBot_versions
if [ "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT" != "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT" ]; then
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
# 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_MoonrakerTelegramBot)
else
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false"
fi
}
#############################################################
#############################################################
read_pgc_versions(){
PGC_DIR="${HOME}/pgcode"
if [ -d $PGC_DIR ] && [ -d $PGC_DIR/.git ]; then
cd $PGC_DIR
git fetch origin main -q
LOCAL_PGC_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
REMOTE_PGC_COMMIT=$(git describe origin/main --always --tags | cut -d "-" -f 1,2)
else
LOCAL_PGC_COMMIT=$NONE
REMOTE_PGC_COMMIT=$NONE
fi
}
compare_pgc_versions(){
unset PGC_UPDATE_AVAIL
read_pgc_versions
if [ "$LOCAL_PGC_COMMIT" != "$REMOTE_PGC_COMMIT" ]; then
LOCAL_PGC_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_PGC_COMMIT")${default}"
REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "$REMOTE_PGC_COMMIT")${default}"
# add PGC to the update all array for the update all function in the updater
PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper)
else
LOCAL_PGC_COMMIT="${green}$(printf "%-12s" "$LOCAL_PGC_COMMIT")${default}"
REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "$REMOTE_PGC_COMMIT")${default}"
PGC_UPDATE_AVAIL="false"
fi
}
#############################################################
#############################################################
@@ -533,4 +623,6 @@ ui_print_versions(){
compare_mainsail_versions
compare_fluidd_versions
compare_klipperscreen_versions
compare_MoonrakerTelegramBot_versions
compare_pgc_versions
}

View File

@@ -13,12 +13,12 @@ advanced_ui(){
echo -e "| | System: | "
echo -e "| Firmware: | 8) [Change hostname] | "
echo -e "| 3) [Build only] | | "
echo -e "| 4) [Build + Flash] | Extensions: | "
echo -e "| 5) [Build + SD Flash] | 9) [Shell Command] | "
echo -e "| 4) [Flash only] | Extensions: | "
echo -e "| 5) [Build + Flash] | 9) [Shell Command] | "
echo -e "| 6) [Get MCU ID] | | "
echo -e "| | CustomPiOS: | "
echo -e "| | 10) [Migration Helper] | "
quit_footer
back_footer
}
advanced_menu(){
@@ -42,24 +42,17 @@ advanced_menu(){
do_action "build_fw" "advanced_ui";;
4)
clear && print_header
flash_routine
if [ $FLASH_FIRMWARE = "true" ]; then
status_msg "Please wait..." && sleep 5 && build_fw
select_mcu_id
fi
print_msg && clear_msg
advanced_ui;;
check_usergroup_dialout
do_action "select_flash_method" "advanced_ui";;
5)
clear && print_header
flash_routine_sd
if [ $FLASH_FW_SD = "true" ]; then
status_msg "Please wait..." && sleep 5 && build_fw
select_mcu_id
fi
check_usergroup_dialout
status_msg "Please wait..."
build_fw && select_flash_method
print_msg && clear_msg
advanced_ui;;
6)
do_action "get_mcu_id" "advanced_ui";;
do_action "select_mcu_connection" "advanced_ui";;
7)
do_action "ms_theme_menu";;
8)
@@ -72,7 +65,7 @@ advanced_menu(){
do_action "setup_gcode_shell_command" "advanced_ui";;
10)
do_action "migration_menu";;
Q|q)
B|b)
clear; main_menu; break;;
*)
deny_action "advanced_ui";;
@@ -99,7 +92,7 @@ switch_ui(){
echo -e "| dmbutyugin: | "
echo -e "| 2) [--> scurve-shaping] | "
echo -e "| 3) [--> scurve-smoothing] | "
quit_footer
back_footer
}
switch_menu(){
@@ -137,7 +130,7 @@ switch_menu(){
read_branch
print_msg && clear_msg
switch_ui;;
Q|q)
B|b)
clear; advanced_menu; break;;
*)
deny_action "switch_ui";;
@@ -151,28 +144,6 @@ switch_menu(){
#############################################################
#############################################################
rollback_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | "
hr
echo -e "| If serious errors occured after updating Klipper, | "
echo -e "| you can use this menu to return to the previously | "
echo -e "| used commit from which you have updated. | "
bottom_border
top_border
echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | "
hr
echo -e "| Currently on commit: | "
echo -e "| $CURR_UI | "
hr
echo -e "| Commit last updated from: | "
echo -e "| $PREV_UI | "
quit_footer
}
#############################################################
#############################################################
migration_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~ [ CustomPiOS Migration ] ~~~~~~~~~~") | "
@@ -190,7 +161,7 @@ migration_ui(){
echo -e "| 1) [Migrate MainsailOS] | "
echo -e "| 2) [Migrate FluiddPi] | "
echo -e "| | "
quit_footer
back_footer
}
migration_menu(){
@@ -201,8 +172,8 @@ migration_menu(){
case "$action" in
1) migrate_custompios "mainsail"; migration_menu;;
2) migrate_custompios "fluiddpi"; migration_menu;;
Q|q) clear; advanced_menu; break;;
B|b) clear; advanced_menu; break;;
*) print_unkown_cmd; migration_menu;;
esac
done
}
}

View File

@@ -14,7 +14,8 @@ backup_ui(){
echo -e "| 2) [Moonraker] | Other: | "
echo -e "| 3) [Moonraker DB] | 7) [Duet Web Control] | "
echo -e "| | 8) [OctoPrint] | "
quit_footer
echo -e "| | 9) [MoonrakerTelegramBot] | "
back_footer
}
backup_menu(){
@@ -40,11 +41,13 @@ backup_menu(){
do_action "backup_dwc2" "backup_ui";;
8)
do_action "backup_octoprint" "backup_ui";;
Q|q)
9)
do_action "backup_MoonrakerTelegramBot" "backup_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "backup_ui";;
esac
done
backup_menu
}
}

View File

@@ -1,6 +1,6 @@
#ui total width = 57 chars
top_border(){
echo -e "/=======================================================\ "
echo -e "/=======================================================\\"
}
bottom_border(){
@@ -8,7 +8,7 @@ bottom_border(){
}
blank_line(){
echo -e "| | "
echo -e "| |"
}
hr(){
@@ -17,7 +17,19 @@ hr(){
quit_footer(){
hr
echo -e "| ${red}Q) Quit${default} | "
echo -e "| ${red}Q) Quit${default} |"
bottom_border
}
back_footer(){
hr
echo -e "| ${green}B) « Back${default} |"
bottom_border
}
back_help_footer(){
hr
echo -e "| ${green}B) « Back${default} | ${yellow}H) Help [?]${default} |"
bottom_border
}
@@ -60,4 +72,4 @@ deny_action(){
print_unkown_cmd
print_msg && clear_msg
$1
}
}

View File

@@ -12,11 +12,12 @@ install_ui(){
echo -e "| Klipper API: | Other: | "
echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Klipper Webinterface: | | "
echo -e "| 3) [Mainsail] | Webcam: | "
echo -e "| 4) [Fluidd] | 8) [MJPG-Streamer] | "
echo -e "| | | "
quit_footer
echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | "
echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | "
echo -e "| 4) [Fluidd] | | "
echo -e "| | Webcam: | "
echo -e "| | 10) [MJPG-Streamer] | "
back_footer
}
install_menu(){
@@ -39,8 +40,12 @@ install_menu(){
7)
do_action "octoprint_setup_dialog" "install_ui";;
8)
do_action "install_pgc_for_klipper" "install_ui";;
9)
do_action "install_MoonrakerTelegramBot" "install_ui";;
10)
do_action "install_mjpg-streamer" "install_ui";;
Q|q)
B|b)
clear; main_menu; break;;
*)
deny_action "install_ui";;

View File

@@ -11,7 +11,8 @@ main_ui(){
echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|"
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|"
echo -e "| 6) [Settings] | |"
echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|"
echo -e "| | |"
echo -e "| | DWC2: $DWC2_STATUS|"
echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|"
quit_footer
@@ -53,52 +54,33 @@ main_menu(){
mainsail_status
octoprint_status
klipperscreen_status
MoonrakerTelegramBot_status
print_branch
print_msg && clear_msg
main_ui
while true; do
read -p "${cyan}Perform action:${default} " action; echo
case "$action" in
"start klipper")
do_action "klipper_service start" "main_ui";;
"stop klipper")
do_action "klipper_service stop" "main_ui";;
"restart klipper")
do_action "klipper_service restart" "main_ui";;
"start moonraker")
do_action "moonraker_service start" "main_ui";;
"stop moonraker")
do_action "moonraker_service stop" "main_ui";;
"restart moonraker")
do_action "moonraker_service restart" "main_ui";;
"start dwc")
do_action "dwc_service start" "main_ui";;
"stop dwc")
do_action "dwc_service stop" "main_ui";;
"restart dwc")
do_action "dwc_service restart" "main_ui";;
"start octoprint")
do_action "octoprint_service start" "main_ui";;
"stop octoprint")
do_action "octoprint_service stop" "main_ui";;
"restart octoprint")
do_action "octoprint_service restart" "main_ui";;
update)
do_action "update_kiauh" "main_ui";;
0)
do_action "upload_selection" "main_ui";;
1)
clear && install_menu && break;;
2)
clear && update_menu && break;;
3)
clear && remove_menu && break;;
4)
clear && advanced_menu && break;;
5)
clear && backup_menu && break;;
6)
clear && settings_menu && break;;
"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 dwc") do_action_service "start" "dwc"; main_ui;;
"stop dwc") do_action_service "stop" "dwc"; main_ui;;
"restart dwc") do_action_service "restart" "dwc"; 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) do_action "upload_selection" "main_ui";;
1) clear && install_menu && break;;
2) clear && update_menu && break;;
3) clear && remove_menu && break;;
4) clear && advanced_menu && break;;
5) clear && backup_menu && break;;
6) clear && settings_menu && break;;
Q|q)
echo -e "${green}###### Happy printing! ######${default}"; echo
exit -1;;

View File

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

View File

@@ -13,11 +13,12 @@ remove_ui(){
echo -e "| Klipper API: | Other: | "
echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Klipper Webinterface: | 8) [NGINX] | "
echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] | "
echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | "
echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | "
echo -e "| 4) [Fluidd] | | "
echo -e "| | | "
quit_footer
echo -e "| | 10) [MJPG-Streamer] | "
echo -e "| | 11) [NGINX] | "
back_footer
}
remove_menu(){
@@ -40,10 +41,14 @@ remove_menu(){
7)
do_action "remove_octoprint" "remove_ui";;
8)
do_action "remove_nginx" "remove_ui";;
do_action "remove_prettygcode" "remove_ui";;
9)
do_action "remove_MoonrakerTelegramBot" "remove_ui";;
10)
do_action "remove_mjpg-streamer" "remove_ui";;
Q|q)
11)
do_action "remove_nginx" "remove_ui";;
B|b)
clear; main_menu; break;;
*)
deny_action "remove_ui";;

View File

@@ -20,7 +20,7 @@ settings_ui(){
else
echo -e "| 1) Change config folder | "
fi
quit_footer
back_footer
}
settings_menu(){
@@ -34,7 +34,7 @@ settings_menu(){
else
deny_action "settings_ui"
fi;;
Q|q)
B|b)
clear; main_menu; break;;
*)
deny_action "settings_ui";;

View File

@@ -21,9 +21,11 @@ update_ui(){
echo -e "| Other: |---------------|--------------| "
echo -e "| 6) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | "
echo -e "| 7) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | "
echo -e "| 8) [PrettyGCode] | $LOCAL_PGC_COMMIT | $REMOTE_PGC_COMMIT | "
echo -e "| 9) [Telegram Bot] | $LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT | $REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT | "
echo -e "| |------------------------------| "
echo -e "| 8) [System] | $DISPLAY_SYS_UPDATE | "
quit_footer
echo -e "| 10) [System] | $DISPLAY_SYS_UPDATE | "
back_footer
}
update_menu(){
@@ -49,10 +51,14 @@ update_menu(){
7)
do_action "update_dwc2" "update_ui";;
8)
do_action "update_pgc_for_klipper" "update_ui";;
9)
do_action "update_MoonrakerTelegramBot" "update_ui";;
10)
do_action "update_system" "update_ui";;
a)
do_action "update_all" "update_ui";;
Q|q)
B|b)
clear; main_menu; break;;
*)
deny_action "update_ui";;

View File

@@ -39,6 +39,12 @@ update_all(){
if [ "$KLIPPERSCREEN_UPDATE_AVAIL" = "true" ]; then
echo -e "| ${cyan}● KlipperScreen${default} |"
fi
if [ "$PGC_UPDATE_AVAIL" = "true" ]; then
echo -e "| ${cyan}● PrettyGCode for Klipper${default} |"
fi
if [ "$MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL" = "true" ]; then
echo -e "| ${cyan}● MoonrakerTelegramBot${default} |"
fi
if [ "$SYS_UPDATE_AVAIL" = "true" ]; then
echo -e "| ${cyan}● System${default} |"
fi
@@ -66,6 +72,7 @@ update_log_paths(){
### update services to make use of moonrakers new log_path option
### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a
shopt -s extglob # enable extended globbing
source_kiauh_ini
LPATH="${HOME}/klipper_logs"
[ ! -d "$LPATH" ] && mkdir -p "$LPATH"
FILE="$SYSTEMDDIR/$1?(-*([0-9])).service"
@@ -84,6 +91,17 @@ update_log_paths(){
done
sudo systemctl daemon-reload
# patch log_path entry if not found
dir1="$klipper_cfg_loc"
dir2="$klipper_cfg_loc/printer_*"
for conf in $(find $dir1 $dir2 -name "moonraker.conf" 2> /dev/null); do
if ! grep -q "log_path" $conf; then
status_msg "Patching $conf"
sed -i "/^config_path/a log_path: $LPATH" $conf
ok_msg "OK!"
fi
done
# create symlink for mainsail and fluidd nginx logs
symlink_webui_nginx_log "mainsail"
symlink_webui_nginx_log "fluidd"
@@ -202,7 +220,7 @@ migrate_custompios(){
}
update_klipper(){
klipper_service "stop"
do_action_service "stop" "klipper"
if [ ! -d $KLIPPER_DIR ]; then
cd ${HOME} && git clone $KLIPPER_REPO
else
@@ -211,47 +229,32 @@ update_klipper(){
save_klipper_state
status_msg "Updating $GET_BRANCH"
cd $KLIPPER_DIR
if [ "$DETACHED_HEAD" == "true" ]; then
git checkout $GET_BRANCH
unset DETACHED_HEAD
fi
### get current klippy-requirements.txt md5sum
KLIPPER_OLDREQ_MD5SUM="$(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1)"
### pull latest files from github
git pull
### read PKGLIST and install possible new dependencies
install_klipper_packages
### get possible new klippy-requirements.txt md5sum
KLIPPER_NEWREQ_MD5SUM="$(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1)"
### check for possible new dependencies and install them
if [[ $KLIPPER_NEWREQ_MD5SUM != $KLIPPER_OLDREQ_MD5SUM ]]; then
PYTHONDIR="${HOME}/klippy-env"
status_msg "New dependecies detected..."
### always rebuild the pythondir from scratch if new dependencies were detected
rm -rf ${PYTHONDIR}
virtualenv -p python2 ${PYTHONDIR}
$PYTHONDIR/bin/pip install -r $KLIPPER_DIR/scripts/klippy-requirements.txt
ok_msg "Dependencies have been installed!"
fi
### install possible new python dependencies
KLIPPER_REQ_TXT="$KLIPPER_DIR/scripts/klippy-requirements.txt"
$KLIPPY_ENV/bin/pip install -r $KLIPPER_REQ_TXT
fi
update_log_paths "klipper"
ok_msg "Update complete!"
klipper_service "restart"
do_action_service "restart" "klipper"
}
update_dwc2fk(){
dwc_service "stop"
do_action_service "stop" "dwc"
bb4u "dwc2"
if [ ! -d $DWC2FK_DIR ]; then
cd ${HOME} && git clone $DWC2FK_REPO
else
cd $DWC2FK_DIR && git pull
fi
dwc_service "start"
do_action_service "start" "dwc"
}
update_dwc2(){
@@ -263,6 +266,7 @@ update_mainsail(){
bb4u "mainsail"
status_msg "Updating Mainsail ..."
mainsail_setup
match_nginx_configs
symlink_webui_nginx_log "mainsail"
}
@@ -270,38 +274,28 @@ update_fluidd(){
bb4u "fluidd"
status_msg "Updating Fluidd ..."
fluidd_setup
match_nginx_configs
symlink_webui_nginx_log "fluidd"
}
update_moonraker(){
moonraker_service "stop"
do_action_service "stop" "moonraker"
bb4u "moonraker"
status_msg "Updating Moonraker ..."
cd $MOONRAKER_DIR
### get current moonraker-requirements.txt md5sum
MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
### pull latest files from github
git pull
cd "$MOONRAKER_DIR" && git pull
### read PKGLIST and install possible new dependencies
install_moonraker_packages
### get possible new moonraker-requirements.txt md5sum
MOONRAKER_NEWREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
### check for possible new dependencies and install them
if [[ $MOONRAKER_NEWREQ_MD5SUM != $MOONRAKER_OLDREQ_MD5SUM ]]; then
PYTHONDIR="${HOME}/moonraker-env"
status_msg "New dependecies detected..."
### always rebuild the pythondir from scratch if new dependencies were detected
rm -rf ${PYTHONDIR}
virtualenv -p /usr/bin/python3 ${PYTHONDIR}
ln -s /usr/lib/python3/dist-packages/gpiod* ${PYTHONDIR}/lib/python*/site-packages
${PYTHONDIR}/bin/pip install -r $MOONRAKER_DIR/scripts/moonraker-requirements.txt
ok_msg "Dependencies have been installed!"
fi
### install possible new python dependencies
MR_REQ_TXT="$MOONRAKER_DIR/scripts/moonraker-requirements.txt"
"$MOONRAKER_ENV"/bin/pip install -r "$MR_REQ_TXT"
update_log_paths "moonraker"
### required due to https://github.com/Arksine/moonraker/issues/349
moonraker_polkit
ok_msg "Update complete!"
moonraker_service "restart"
do_action_service "restart" "moonraker"
}
update_klipperscreen(){
@@ -321,9 +315,27 @@ update_klipperscreen(){
start_klipperscreen
}
update_pgc_for_klipper(){
PGC_DIR="${HOME}/pgcode"
status_msg "Updating PrettyGCode for Klipper ..."
cd $PGC_DIR && git pull
ok_msg "Update complete!"
}
update_MoonrakerTelegramBot(){
source_kiauh_ini
export klipper_cfg_loc
stop_MoonrakerTelegramBot
cd $MOONRAKER_TELEGRAM_BOT_DIR
git pull
./scripts/install.sh
ok_msg "Update complete!"
start_MoonrakerTelegramBot
}
update_system(){
status_msg "Updating System ..."
sudo apt-get update && sudo apt-get upgrade -y
ok_msg "Update complete! Check the log above!"
ok_msg "KIAUH won't do any dist-upgrades!\n"
sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y
CONFIRM_MSG="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}"
print_msg && clear_msg
}

View File

@@ -71,10 +71,10 @@ upload_selection(){
printf "| $i) %-50s|\n" "${logfiles[$i]}"
i=$((i + 1))
done
quit_footer
back_footer
while true; do
read -p "${cyan}Please select:${default} " choice
if [ $choice = "q" ] || [ $choice = "Q" ]; then
if [ $choice = "b" ] || [ $choice = "B" ]; then
clear && main_menu && break
elif [ $choice -le ${#logfiles[@]} ]; then
upload_log "${logfiles[$choice]}"
@@ -101,4 +101,4 @@ upload_log(){
ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection
fi
}
}