mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 19:14:27 +05:00
Compare commits
270 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcf059df73 | ||
|
|
4bf9e8f0a8 | ||
|
|
dd58229fee | ||
|
|
6c4635fa4e | ||
|
|
4517415e9d | ||
|
|
5c45bc7617 | ||
|
|
d8ce465126 | ||
|
|
2f8c95a8c7 | ||
|
|
4c083ceade | ||
|
|
259a6919f0 | ||
|
|
4f7a49d85a | ||
|
|
005a5061a7 | ||
|
|
634d795557 | ||
|
|
a14e321df9 | ||
|
|
1682642e47 | ||
|
|
7e9d18b54c | ||
|
|
d049d4c770 | ||
|
|
108cda3cd6 | ||
|
|
d7de58f538 | ||
|
|
572afa0396 | ||
|
|
63a5e1e323 | ||
|
|
8c68eaa995 | ||
|
|
e8c0b3cf39 | ||
|
|
cfad7a1fb0 | ||
|
|
4113732daa | ||
|
|
95808a0d5b | ||
|
|
e551c02507 | ||
|
|
1f40686ea1 | ||
|
|
9b3d96545b | ||
|
|
a632fae8f6 | ||
|
|
4e3a701db4 | ||
|
|
0c760b5aa2 | ||
|
|
3bc2f3b498 | ||
|
|
b92cfc3984 | ||
|
|
01790b5c11 | ||
|
|
8c7891e360 | ||
|
|
852f7c056a | ||
|
|
8cffd07aef | ||
|
|
40745e90df | ||
|
|
a43645cca0 | ||
|
|
4d834db5df | ||
|
|
771191ab69 | ||
|
|
7afe943ecc | ||
|
|
b06c17c184 | ||
|
|
3af46b45ee | ||
|
|
b58e79634c | ||
|
|
1ef9b0f58f | ||
|
|
8333ae1dc4 | ||
|
|
e0ae312a9e | ||
|
|
4ce1ce72d3 | ||
|
|
60842a330d | ||
|
|
05a59e9261 | ||
|
|
36a8757cfd | ||
|
|
fe4625d3e1 | ||
|
|
19ddf3e023 | ||
|
|
ba888b1f97 | ||
|
|
0284a36e7f | ||
|
|
22f705e06c | ||
|
|
4c34245da0 | ||
|
|
f7cb3d6c97 | ||
|
|
aaf4f7dd5c | ||
|
|
26bac791aa | ||
|
|
aa4bdfc7b2 | ||
|
|
311f3be864 | ||
|
|
511df1a889 | ||
|
|
8d3ddc273a | ||
|
|
f231fa9c69 | ||
|
|
9b6925e9c4 | ||
|
|
7f8ee7939c | ||
|
|
4d4c49d4c9 | ||
|
|
7692227946 | ||
|
|
3da993a67c | ||
|
|
6b74c59d15 | ||
|
|
9cd27f7052 | ||
|
|
fc4fe130cd | ||
|
|
2a46b00cda | ||
|
|
560186a40b | ||
|
|
75bca847f8 | ||
|
|
bb1f2eadca | ||
|
|
6d87716b1d | ||
|
|
1e8c379623 | ||
|
|
6a8991d51e | ||
|
|
fb4367bb41 | ||
|
|
9463b719e4 | ||
|
|
65bf3d5251 | ||
|
|
68327262fc | ||
|
|
14ef39b87c | ||
|
|
969d3b5dab | ||
|
|
05842f8e1d | ||
|
|
39219c105e | ||
|
|
7984c28fe5 | ||
|
|
b44e855a98 | ||
|
|
52ab909ba5 | ||
|
|
4d7e10e5c3 | ||
|
|
d3726733e5 | ||
|
|
765f016ea2 | ||
|
|
5deb987b8a | ||
|
|
47d1321979 | ||
|
|
b47a9cf7ed | ||
|
|
a9f23e9b23 | ||
|
|
814acbe92a | ||
|
|
991dd79d01 | ||
|
|
40875dfe49 | ||
|
|
806c6fd275 | ||
|
|
e9706b52d8 | ||
|
|
412e084d6d | ||
|
|
3ebee823ad | ||
|
|
72312422e3 | ||
|
|
54089582e4 | ||
|
|
9fd3f930df | ||
|
|
98f0aa4b8f | ||
|
|
19b37e4dc4 | ||
|
|
d344b1c5f6 | ||
|
|
f804fcb65d | ||
|
|
0edfc746d4 | ||
|
|
02ef0578e3 | ||
|
|
5d11cd212a | ||
|
|
bf33c77db7 | ||
|
|
0815d7778c | ||
|
|
9a3814f480 | ||
|
|
a83585fb06 | ||
|
|
dc27fe47e1 | ||
|
|
11b3d7a961 | ||
|
|
9e0cdb0715 | ||
|
|
8abda56749 | ||
|
|
cf20fc3c48 | ||
|
|
6c8845d7b4 | ||
|
|
fb0a30814d | ||
|
|
87f229c62d | ||
|
|
5b1da45688 | ||
|
|
545b978e80 | ||
|
|
44f5609de6 | ||
|
|
f2a26d9b3d | ||
|
|
bb2cdab02b | ||
|
|
d6596d0a3d | ||
|
|
865fbc07dc | ||
|
|
40ba33eb19 | ||
|
|
49b77162b0 | ||
|
|
adf087e3e5 | ||
|
|
8220647564 | ||
|
|
57075ff525 | ||
|
|
2f9de620bc | ||
|
|
d658c3a4cd | ||
|
|
67f6a2c599 | ||
|
|
f369c132d2 | ||
|
|
cce6ac3c88 | ||
|
|
b9fe29068d | ||
|
|
104089ea3d | ||
|
|
48d97dab01 | ||
|
|
e4a56564a1 | ||
|
|
6de8ce3278 | ||
|
|
b46457328f | ||
|
|
7c7dd4ec3c | ||
|
|
749293dde0 | ||
|
|
85f8ab4f24 | ||
|
|
e894496a6e | ||
|
|
19b220b772 | ||
|
|
a4eaa8952a | ||
|
|
74a9bf783b | ||
|
|
7597e999a1 | ||
|
|
64d73ca86a | ||
|
|
d3283f7ab7 | ||
|
|
cb443f6fee | ||
|
|
7162256e3f | ||
|
|
938b9d24f5 | ||
|
|
38a3517c89 | ||
|
|
0b15cd0d9b | ||
|
|
9d7752a6c5 | ||
|
|
d1dff4d3b5 | ||
|
|
49b7fe395b | ||
|
|
51469d8992 | ||
|
|
16e6dde998 | ||
|
|
431f58af4b | ||
|
|
c3af82745b | ||
|
|
26eecbc94b | ||
|
|
fa8a9ff7ba | ||
|
|
dc08d8e7e3 | ||
|
|
d0b895a469 | ||
|
|
5aaebc2bec | ||
|
|
538c179671 | ||
|
|
dc6fea8c3b | ||
|
|
82227f8d0b | ||
|
|
31c3f344e5 | ||
|
|
a7b7b362f3 | ||
|
|
5f142da1b6 | ||
|
|
99209f97de | ||
|
|
8a64fe495e | ||
|
|
c3468c04e4 | ||
|
|
2ef3273b74 | ||
|
|
47cf96ef74 | ||
|
|
17524bf49b | ||
|
|
0d29bf9f31 | ||
|
|
6105122467 | ||
|
|
55dad5ffb6 | ||
|
|
53aa86d138 | ||
|
|
a0e53655bd | ||
|
|
69d134d9d1 | ||
|
|
7224040f8a | ||
|
|
1570fd588e | ||
|
|
0eb2d066be | ||
|
|
61d1c46694 | ||
|
|
04f204e4c7 | ||
|
|
f8aa88f480 | ||
|
|
0c4f1a5378 | ||
|
|
4652e5c177 | ||
|
|
a6156ebdf3 | ||
|
|
1c92987b42 | ||
|
|
d01140638a | ||
|
|
254e1b8244 | ||
|
|
19aed15db0 | ||
|
|
b2b19f446b | ||
|
|
8ad7f5d47c | ||
|
|
69eb96d006 | ||
|
|
e233d8435a | ||
|
|
fb52c7e4ab | ||
|
|
bc53de626f | ||
|
|
f10a604f97 | ||
|
|
1527d7a25d | ||
|
|
65062bdfda | ||
|
|
e3d242017d | ||
|
|
c14289a8a6 | ||
|
|
d9e697216f | ||
|
|
d958c1ba2a | ||
|
|
fb1d3a8cd9 | ||
|
|
7eb0fe24f8 | ||
|
|
738269adae | ||
|
|
d098eef08e | ||
|
|
598c106c3a | ||
|
|
51207e2eb9 | ||
|
|
ee252d185a | ||
|
|
cf1e37fb2a | ||
|
|
3d9722f877 | ||
|
|
1ef67fa05c | ||
|
|
db856de8e5 | ||
|
|
4748c15424 | ||
|
|
ab9d73b5b5 | ||
|
|
6c33282d43 | ||
|
|
e71f1b9dfd | ||
|
|
e24afa42ac | ||
|
|
2fa975e3c2 | ||
|
|
feb912da8a | ||
|
|
e5ce642018 | ||
|
|
7a4ccfe4df | ||
|
|
6b2175e439 | ||
|
|
dd2a26e2d0 | ||
|
|
cd1489f0e5 | ||
|
|
d705a043c9 | ||
|
|
c1a21c52b6 | ||
|
|
94762727ae | ||
|
|
9cde005e08 | ||
|
|
86e7f37f7b | ||
|
|
4d2eb49e85 | ||
|
|
715ab5f4e2 | ||
|
|
146586f894 | ||
|
|
bd78fa8ef7 | ||
|
|
b12d344b40 | ||
|
|
9ea29bf995 | ||
|
|
d066999d0b | ||
|
|
1ab681e71a | ||
|
|
f782a32e9c | ||
|
|
7dc1bc6cc8 | ||
|
|
2a29716bb9 | ||
|
|
33a9fef676 | ||
|
|
88afa55268 | ||
|
|
65ec2e5e1a | ||
|
|
08c1807cc7 | ||
|
|
218700b63d | ||
|
|
bb1c5c4900 | ||
|
|
08ae57d349 | ||
|
|
61dfab5683 |
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal 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
50
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal 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
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal 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
|
||||
40
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
40
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal 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.
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
kiauh.ini
|
||||
klipper_repos.txt
|
||||
15
.shellcheckrc
Normal file
15
.shellcheckrc
Normal file
@@ -0,0 +1,15 @@
|
||||
source=scripts
|
||||
|
||||
enable=avoid-nullary-conditions
|
||||
enable=deprecate-which
|
||||
enable=quote-safe-variables
|
||||
enable=require-variable-braces
|
||||
enable=require-double-brackets
|
||||
|
||||
# SC2162: `read` without `-r` will mangle backslashes.
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2162
|
||||
disable=SC2162
|
||||
|
||||
# SC2164: Use `cd ... || exit` in case `cd` fails
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2164
|
||||
disable=SC2164
|
||||
191
README.md
191
README.md
@@ -1,140 +1,93 @@
|
||||
# **KIAUH - Klipper Installation And Update Helper**
|
||||
<p align="center">
|
||||
<a>
|
||||
<img src="https://raw.githubusercontent.com/th33xitus/kiauh/master/resources/screenshots/kiauh.png" alt="KIAUH logo" height="181">
|
||||
<h1 align="center">Klipper Installation And Update Helper</h1>
|
||||
</a>
|
||||
</p>
|
||||
|
||||

|
||||
<p align="center">
|
||||
A handy installation script that makes installing Klipper (and more) a breeze!
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
## **📋 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! 🧠**\
|
||||
Feel free to give it a try. If you have suggestions or encounter any problems, please report them.
|
||||
|
||||
---
|
||||
<p align="center">
|
||||
<a><img src="https://img.shields.io/github/license/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/stars/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/forks/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/languages/top/th33xitus/kiauh?logo=gnubash&logoColor=white"></a>
|
||||
<a><img src="https://img.shields.io/github/v/tag/th33xitus/kiauh"></a>
|
||||
<br />
|
||||
<a><img src="https://img.shields.io/github/last-commit/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/contributors/th33xitus/kiauh"></a>
|
||||
</p>
|
||||
|
||||
## **🛠️ Instructions:**
|
||||
|
||||
For downloading this script it is best to have git already installed.\
|
||||
For downloading this script it is necessary to have git installed.\
|
||||
If you haven't, please run `sudo apt-get install git -y` to install git first.\
|
||||
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
|
||||
cd kiauh
|
||||
chmod +x kiauh.sh scripts/*
|
||||
./kiauh.sh
|
||||
|
||||
./kiauh/kiauh.sh
|
||||
```
|
||||
**📢 Disclaimer: Usage of this script happens at your own risk!**
|
||||
|
||||
## Additional Instructions:
|
||||
|
||||
If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website:\
|
||||
[Installing Klipper and Mainsail](https://3dp.tumbleweedlabs.com/firmware/klipper-firmware/installing-klipper-and-mainsail-on-your-raspberry-pi)\
|
||||
Credits for these instructions go to [@tumbleweedlabs](https://github.com/tumbleweedlabs).\
|
||||
Feel free to check out his work.
|
||||
## **❗ Notes:**
|
||||
|
||||
---
|
||||
**📋 Please see the [Changelog](docs/changelog.md) for possible important changes!**
|
||||
|
||||
## **🧰 Functions and Features:**
|
||||
|
||||
### **Core Functions:**
|
||||
|
||||
- **Installing** of the Klipper Firmware to your Raspberry Pi or other Linux Distribution which makes use of init.d.
|
||||
- **Installing** of several different web interfaces such as Duet Web Control, Mainsail, Fluidd or OctoPrint including their dependencies.
|
||||
- **Installing** of the Moonraker API
|
||||
- **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface!
|
||||
- **Removing** of all the listed installations above.
|
||||
- **Backup** of all the listed installations above.
|
||||
|
||||
### **Also possible:**
|
||||
|
||||
- Build the Klipper Firmware
|
||||
- Flash the MCU
|
||||
- Read ID of the currently connected printer (only one at the time)
|
||||
- Write necessary entries to your printer.cfg, some of them customizable right in the CLI.
|
||||
- and more ...
|
||||
|
||||
### **For a list of additional features please see: [Feature List](docs/features.md)**
|
||||
|
||||
---
|
||||
|
||||
## **📝 Notes:**
|
||||
|
||||
- Tested **only** on Raspberry Pi OS Lite (Debian Buster)
|
||||
- Tested **only** on Raspberry Pi OS Lite (Debian 10 Buster)
|
||||
- Other Debian based distributions can work
|
||||
- Reported to work on Armbian too
|
||||
- During the use of this script you might be asked for your sudo password. There are several functions involved which need sudo privileges.
|
||||
|
||||
---
|
||||
## **🌐 Sources & Further Information**
|
||||
|
||||
## **🛈 Sources & Further Information**
|
||||
<table>
|
||||
<tr>
|
||||
<th><h3><a href="https://github.com/Klipper3d/klipper">Klipper</a></h3></th>
|
||||
<th><h3><a href="https://github.com/Arksine/moonraker">Moonraker</a></h3></th>
|
||||
<th><h3><a href="https://github.com/mainsail-crew/mainsail">Mainsail</a></h3></th>
|
||||
<th><h3><a href="https://github.com/fluidd-core/fluidd">Fluidd</a></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><img src="https://raw.githubusercontent.com/Klipper3d/klipper/master/docs/img/klipper-logo.png" alt="Klipper Logo" height="64"></th>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/9563098?v=4" alt="Arksine avatar" height="64"></th>
|
||||
<th><img src="https://raw.githubusercontent.com/mainsail-crew/docs/master/assets/img/logo.png" alt="Mainsail Logo" height="64"></th>
|
||||
<th><img src="https://raw.githubusercontent.com/fluidd-core/fluidd/master/docs/assets/images/logo.svg" alt="Fluidd Logo" height="64"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>by <a href="https://github.com/KevinOConnor">KevinOConnor</a></th>
|
||||
<th>by <a href="https://github.com/Arksine">Arksine</a></th>
|
||||
<th>by <a href="https://github.com/mainsail-crew">mainsail-crew</a></th>
|
||||
<th>by <a href="https://github.com/fluidd-core">fluidd-core</a></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><h3><a href="https://github.com/jordanruthe/KlipperScreen">KlipperScreen</a></h3></th>
|
||||
<th><h3><a href="https://github.com/nlef/moonraker-telegram-bot">Moonraker-Telegram-Bot</a></h3></th>
|
||||
<th><h3><a href="https://github.com/Kragrathea/pgcode">PrettyGCode for Klipper</a></h3></th>
|
||||
<th><h3><a href="https://github.com/OctoPrint/OctoPrint">OctoPrint</a></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/31575189?v=4" alt="jordanruthe avatar" height="64"></th>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/52351624?v=4" alt="nlef avatar" height="64"></th>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/5917231?v=4" alt="Kragrathea avatar" height="64"></th>
|
||||
<th><img src="https://camo.githubusercontent.com/627be7fc67195b626b298af9b9677d7c58e698c67305e54324cffbe06130d4a4/68747470733a2f2f6f63746f7072696e742e6f72672f6173736574732f696d672f6c6f676f2e706e67" alt="OctoPrint Logo" height="64"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>by <a href="https://github.com/jordanruthe">jordanruthe</a></th>
|
||||
<th>by <a href="https://github.com/nlef">nlef</a></th>
|
||||
<th>by <a href="https://github.com/Kragrathea">Kragrathea</a></th>
|
||||
<th>by <a href="https://github.com/OctoPrint">OctoPrint</a></th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
For more information or instructions, please check out the appropriate repositories listed below:
|
||||
## **Credits**
|
||||
|
||||
---
|
||||
|
||||
### **⛵Klipper** by [KevinOConnor](https://github.com/KevinOConnor) :
|
||||
|
||||
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 instancec of Klipper on the same Pi? (Multisession?)_**
|
||||
|
||||
**A:** No, and at the moment i don't plan to implement this function. For multisession installations take a look at this script manu7irl created: https://github.com/manu7irl/klipper-DWC2-installer . Keep in mind that klipper-DWC2-installer and KIAUH are **NOT** compatible with each other.
|
||||
* A 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!
|
||||
|
||||
@@ -2,6 +2,152 @@
|
||||
|
||||
This document covers possible important changes to KIAUH.
|
||||
|
||||
### 2022-04-XX
|
||||
KIAUH has now reached major version 4 !
|
||||
* feat: Klipper can be installed under Python3 (considered as experimental)
|
||||
* feat: Klipper can be installed from custom repositories / inofficial forks
|
||||
* feat: Custom instance name for multi instance installations of Klipper
|
||||
* Any other multi instance will share the same name given to the corresponding Klipper instance
|
||||
* E.g. klipper-voron2 -> moonraker-voron2 -> moonraker-telegram-bot-voron2
|
||||
* feat: Option to only allow the installation of stable Mainsail and Fluidd versions
|
||||
* feat: Multi-Instance OctoPrint installations now each have their own virtual python environment
|
||||
* allows independent installation of plugins for each instance
|
||||
* feat: Implementing the use of shellcheck during development
|
||||
* feat: Implementing a simple logging mechanic
|
||||
* feat: Log-upload function now also allows uploading other logfiles (kiauh.log, webcamd.log etc.)
|
||||
* fix: During Klipper installation, checks for group membership of `tty` and `dialout` are made
|
||||
* refactor: Support for DWC and DWC-for-Klipper has been removed
|
||||
* refactor: The backup before update settings were moved to the KIAUH settings menu
|
||||
* refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature)
|
||||
* refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen were removed from the moonraker.conf template
|
||||
* They will now be individually added during installation of the corresponding interface
|
||||
* refactor: The rollback function was reworked and now also allows rollbacks of Moonraker
|
||||
* It now takes numerical inputs and reverts the corresponding repository by the given amount instead
|
||||
* KIAUH does not save previous states to its config anymore like it did with the previous approach
|
||||
|
||||
|
||||
### 2022-01-29
|
||||
* Starting from the 28th of January, Moonraker can make use of PackageKit and PolicyKit.\
|
||||
More details on that can be found [here](
|
||||
https://github.com/Arksine/moonraker/issues/349) and [here](https://github.com/Arksine/moonraker/pull/346)
|
||||
* KIAUH will install Moonrakers PolicyKit rules by default when __installing__ Moonraker
|
||||
* KIAUH will also install Moonrakers PolicyKit rules when __updating__ Moonraker __via KIAUH__ as of now
|
||||
|
||||
### 2021-12-30
|
||||
* Updated the doc for the usage of the [G-Code Shell Command Extension](docs/gcode_shell_command.md)
|
||||
* It became apparent, that some user groups are missing on some systems. A missing video group \
|
||||
membership for example caused issues when installing mjpg-streamer while not using the default pi user. \
|
||||
Other issues could occur when trying to flash an MCU on Debian or Ubuntu distributions where a user might not be part
|
||||
of the dialout group by default. A check for the tty group is also done. The tty group is needed for setting
|
||||
up a linux MCU (currently not yet supported by KIAUH).
|
||||
* There is an issue when trying to install Mainsail or Fluidd on Ubuntu 21.10. Permissions on that distro seem to have seen a rework
|
||||
in comparison to 20.04 and users will be greeted with an "Error 403 - Permission denied" message after installing one of Klippers webinterfaces.
|
||||
I still have to figure out a viable solution for that.
|
||||
|
||||
### 2021-09-28
|
||||
* New Feature! Added an installer for the Telegram Bot for Moonraker by [nlef](https://github.com/nlef).
|
||||
Checkout his project! Remember to report all issues and/or bugs regarding that project in its corresponding repo and not here 😛.\
|
||||
You can find it here: https://github.com/nlef/moonraker-telegram-bot
|
||||
|
||||
### 2021-09-24
|
||||
* The flashing function got adjusted a bit. It is now possible to also flash controllers which are connected over UART and thus accessible via `/dev/ttyAMA0`. You now have to select a connection methop prior flashing which is either USB or UART.
|
||||
* Due to several requests over time I have now created a Ko-fi account for those who want to support this project and my work with a small donation. Many thanks in advance to all future donors. You can support me on Ko-fi with this link: https://ko-fi.com/th33xitus
|
||||
* As usual, if you find any bugs or issues please report them. I tested the little rework i did with the hardware i have available and haven't encountered any malfunctions of flashing them yet.
|
||||
|
||||
### 2021-08-10
|
||||
* KIAUH now supports the installation of the "PrettyGCode for Klipper" GCode-Viewer created by [Kragrathea](https://github.com/Kragrathea)! Installation, updating and removal are possible with KIAUH. For more details to this cool piece of software, please have a look here: https://github.com/Kragrathea/pgcode
|
||||
|
||||
### 2021-07-10
|
||||
* The NGINX configuration files got updated to be in sync with MainsailOS and FluiddPi. Issues with the NGINX service not starting up due to wrong configuration should be resolved now. To get the updated configuration files, please remove Moonraker and Mainsail / Fluidd with KIAUH first and then re-install it. An automated file check for those configuration files might follow in the future which then automates updating those files if there were important changes.
|
||||
|
||||
* The default `moonraker.conf` was updated to reflect the recent changes to the update manager section. The update channel is set to `dev`.
|
||||
|
||||
### 2021-06-29
|
||||
* KIAUH will now patch the new `log_path` to existing moonraker.conf files when updating Moonraker and the entry is missing. Before that, it was necessary that the user provided that path manually to make Fluidd display the logfiles in its interface. This issue should be resolved now.
|
||||
|
||||
### 2021-06-15
|
||||
|
||||
* Moonraker introduced an optional `log_path` which clients can make use of to show log files located in that folder to their users. More info here: https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a \
|
||||
Client developers agreed upon using `~/klipper_logs` as the new default log path.\
|
||||
That means, from now on, Klipper and Moonraker services installed with KIAUH will place their logfiles in that mentioned folder.
|
||||
* Additionally, KIAUH will now detect Klipper and Moonraker systemd services that still use the old default location of `/tmp/<service>.log` and will update them next time the user updates Klipper and/or Moonraker with the KIAUH update function.
|
||||
* Additional symlinks for the following logfiles will get created along those update procedures to make them accessible through the webinterface once its supported:
|
||||
- webcamd.log
|
||||
- mainsail-access.log
|
||||
- mainsail-error.log
|
||||
- fluidd-access.log
|
||||
- fluidd-error.log
|
||||
* For MainsailOS and FluiddPi users:\
|
||||
MainsailOS and FluiddPi will switch the shipped Klipper service from SysVinit to systemd probably with their next release. KIAUH can already help migrate older MainsailOS (0.4.0 and below) and FluiddPi (v1.13.0) releases to match their new service-, file- and folder-structure so you don't have to re-flash the SD-Card of your Raspberry Pi.\
|
||||
In detail here is what is going to happen when you use the new "CustomPiOS Migration Helper" from the Advanced Menu\
|
||||
`(Main Menu -> 4 -> Enter -> 10 -> Enter)` in a short summary:
|
||||
* The Klipper SysVinit service will get replaced by a Klipper systemd service
|
||||
* Klipper and Moonraker will use the new log-directory `~/klipper_logs`
|
||||
* The webcamd service gets updated
|
||||
* The webcamd script gets updated and moved from `/root/bin/webcamd` to `/usr/local/bin/webcamd`
|
||||
* The NGINX `upstreams.conf` gets updated to be able to configure up to 4 webcams
|
||||
* The `mainsail.txt` / `fluiddpi.txt` gets moved from `/boot` to `~/klipper_config` and renamed to `webcam.txt`
|
||||
* Symlinks for the webcamd.log and various NGINX logs get created in `~/klipper_config`
|
||||
* Configuration files for Klipper, Moonraker and webcamd get added to `/etc/logrotate.d`
|
||||
* If they still exist, two lines will be removed from the mainsail.cfg or client_macros.cfg macro configurations:\
|
||||
`SAVE_GCODE_STATE NAME=PAUSE_state` and `RESTORE_GCODE_STATE NAME=PAUSE_state`
|
||||
* **Please note:**\
|
||||
The "CustomPiOS Migration Helper" is intended to only work on "vanilla" MainsailOS and FluiddPi systems. Do not try to migrate a modified MainsailOS or FluiddPi system (for example if you already used KIAUH to re-install services or to set up a multi-instance installation for Klipper / Moonraker). This won't work.
|
||||
|
||||
### 2021-01-31
|
||||
|
||||
* **This is a big one... KIAUH v3.0 is out.**\
|
||||
With this update you can now install multiple instances of Klipper, Moonraker, Duet Web Control or Octoprint on the same Pi. This was quite a big rework of the whole script. So bugs can appear but with the help of some testers, i think there shouldn't be any critical ones anymore. In this regards thanks to @lixxbox and @zellneralex for testing.
|
||||
|
||||
* Important changes to how installations are set up now: All components get installed as systemd services. Installation via init.d was dropped completely! This shouldn't affect you at all, since the common linux distributions like RaspberryPi OS or custom distributions like MainsailOS, FluiddPi or OctoPi support both ways of installing services. I just wanted to mention it here.
|
||||
|
||||
* Now with KIAUH v3.0 and multi-instance installation capabilities, there are some things to point out. You will now need to tell KIAUH where your printers configurations are located when installing Klipper for the first time. Even though it is not recommended, you can change this location with the help of KIAUH and rewrite Klipper and Moonraker to use the new location.
|
||||
|
||||
* When setting up a multi-instance system, the folder structure will only change slightly. The goal was to keep it as compatible as possible with the custom distributions like mainsailOS and FluiddPi. This should help converting a single-instance setup of mainsailOS/FluiddPi to a multi-instance setup in no time, but keeping single-instance backwards compatibility if needed at a later point in time.
|
||||
|
||||
* The folder structure is as follows when setting up multi-instances:\
|
||||
Each printer instance will get its own folder within your configuration location. The decision to this specific structure was made to make it as painless and easy as possible to convert to a multi-instance setup.
|
||||
Here is an example:
|
||||
```shell
|
||||
/home/<username>
|
||||
└── klipper_config
|
||||
├── printer_1
|
||||
│ ├── printer.cfg
|
||||
│ └── moonraker.conf
|
||||
├── printer_2
|
||||
│ ├── printer.cfg
|
||||
│ └── moonraker.conf
|
||||
└── printer_n
|
||||
├── printer.cfg
|
||||
└── moonraker.conf
|
||||
```
|
||||
* Also when setting up multi-instances of each service, the name of each service slightly changes.
|
||||
Each service gets its corresponding instance added to the service filename.
|
||||
|
||||
**This only applies to multi-instances! Single instance installations with KIAUH will keep their original names!**
|
||||
|
||||
Corresponding to the filetree example from above that would mean:
|
||||
```
|
||||
Klipper services:
|
||||
--> klipper-1.service
|
||||
--> klipper-2.service
|
||||
--> klipper-n.service
|
||||
|
||||
Moonraker services:
|
||||
--> moonraker-1.service
|
||||
--> moonraker-2.service
|
||||
--> moonraker-n.service
|
||||
```
|
||||
* The same service file rules from above apply to OctoPrint even though only Klipper and Moonraker are shown in this example.
|
||||
|
||||
* You can start, stop and restart all Klipper, Moonraker and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on.
|
||||
|
||||
* KIAUH v3.0 relocated its ini-file. It is now a hidden file in the users home-directory calles `.kiauh.ini`. This has the benefit of keeping all values in that file between possible re-installations of KIAUH. Otherwise that file would be lost.
|
||||
|
||||
* The option of adding more trusted clients to the moonraker.conf file was dropped. Since you can edit this file right inside of Mainsail or Fluidd, only some basic entries are made which get you running.
|
||||
|
||||
* I bet i have missed mentioning other stuff as well because it took me quite some time to re-write many functions. So i just hope you like the new version 😄
|
||||
|
||||
### 2020-11-28
|
||||
|
||||
* KIAUH now supports the installation, update and removal of [KlipperScreen](https://github.com/jordanruthe/KlipperScreen). This feature was was provided by [jordanruthe](https://github.com/jordanruthe)! Thank you!
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# Feature List:
|
||||
|
||||
- **Automatic dependency check:**\
|
||||
If packages are missing but needed for the asked task, the script will automatically install them
|
||||
- **Switch between different Klipper Forks:**\
|
||||
[origin/master](https://github.com/KevinOConnor/klipper/tree/master) or [scurve-shaping](https://github.com/dmbutyugin/klipper/tree/scurve-shaping) or [scurve-smoothing](https://github.com/dmbutyugin/klipper/tree/scurve-smoothing)\
|
||||
The update function of the script will always update the currently selected/active fork!
|
||||
- **Toggle auto-create backups before updating:**\
|
||||
When enabled, a backup of the installation you want to update is made prior updating
|
||||
- **Rollback:**\
|
||||
When updating Klipper, KIAUH saves the current commit hash to a local ini-file. In case of an unsuccesfull update you can use this function to quickly revert back to the commit with the hash you updated from.
|
||||
- **Preconfigure OctoPrint:**\
|
||||
When installing OctoPrint, a config is created which preconfigures your installation to be used with Klipper.\
|
||||
That means:
|
||||
- adding the restart/shutdown commands for OctoPrint
|
||||
- adding the serial port `/tmp/printer`
|
||||
- set the behavior to "Cancel any ongoing prints but stay connected to the printer"
|
||||
- **Enable/Disable OctoPrint Service:**\
|
||||
Usefull when using DWC2/Mainsail/Fluidd and OctoPrint at the same time to prevent them interfering with each other
|
||||
- **Set up reverse proxy for DWC2, Mainsail, Fluidd and OctoPrint and changing the hostname:**
|
||||
- The script can install and configure Nginx for the selected webinterface
|
||||
- It also allows you to make your webinterface reachable over an URL like `<hostname>.local` via avahi
|
||||
- Example: If you name the host "my-printer", type `my-printer.local` in your webbrowser to open the installed webinterface
|
||||
- If there is more than one webinterface installed, you have to append the port to that adress
|
||||
|
||||
- **Installing a G-Code Shell Command extension:**\
|
||||
For further information about that extension please see the [G-Code Shell Command Extension Doc](gcode_shell_command.md)
|
||||
|
||||
- **Uploading logfiles:**\
|
||||
You can directly upload logfiles like klippy.log, moonraker.log and dwc2.log from the KIAUH main menu for providing them for troubleshooting purposes.
|
||||
|
||||
|
||||
to be continued...
|
||||
@@ -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.
|
||||
|
||||
166
kiauh.sh
166
kiauh.sh
@@ -1,109 +1,89 @@
|
||||
#!/bin/bash
|
||||
clear
|
||||
set -e
|
||||
#!/usr/bin/env bash
|
||||
|
||||
### set color variables
|
||||
green=$(echo -en "\e[92m")
|
||||
yellow=$(echo -en "\e[93m")
|
||||
red=$(echo -en "\e[91m")
|
||||
cyan=$(echo -en "\e[96m")
|
||||
default=$(echo -en "\e[39m")
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
clear
|
||||
|
||||
### sourcing all additional scripts
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done
|
||||
for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done
|
||||
KIAUH_SRCDIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
for script in "${KIAUH_SRCDIR}/scripts/"*.sh; do . "${script}"; done
|
||||
for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
|
||||
|
||||
### set important directories
|
||||
#klipper
|
||||
KLIPPER_DIR=${HOME}/klipper
|
||||
KLIPPY_ENV_DIR=${HOME}/klippy-env
|
||||
KLIPPER_SERVICE1=/etc/init.d/klipper
|
||||
KLIPPER_SERVICE2=/etc/default/klipper
|
||||
KLIPPER_SERVICE3=/etc/systemd/system/klipper.service
|
||||
#nginx
|
||||
NGINX_SA=/etc/nginx/sites-available
|
||||
NGINX_SE=/etc/nginx/sites-enabled
|
||||
NGINX_CONFD=/etc/nginx/conf.d
|
||||
#moonraker
|
||||
MOONRAKER_DIR=${HOME}/moonraker
|
||||
MOONRAKER_ENV_DIR=${HOME}/moonraker-env
|
||||
MOONRAKER_SERVICE1=/etc/init.d/moonraker
|
||||
MOONRAKER_SERVICE2=/etc/default/moonraker
|
||||
#mainsail
|
||||
MAINSAIL_DIR=${HOME}/mainsail
|
||||
#fluidd
|
||||
FLUIDD_DIR=${HOME}/fluidd
|
||||
#dwc2
|
||||
DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket
|
||||
DWC_ENV_DIR=${HOME}/dwc-env
|
||||
DWC2_DIR=${HOME}/sdcard/web
|
||||
#octoprint
|
||||
OCTOPRINT_DIR=${HOME}/OctoPrint
|
||||
OCTOPRINT_CFG_DIR=${HOME}/.octoprint
|
||||
OCTOPRINT_SERVICE1=/etc/init.d/octoprint
|
||||
OCTOPRINT_SERVICE2=/etc/default/octoprint
|
||||
#KlipperScreen
|
||||
KLIPPERSCREEN_DIR=${HOME}/KlipperScreen
|
||||
KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env
|
||||
#misc
|
||||
INI_FILE=${SRCDIR}/kiauh/kiauh.ini
|
||||
BACKUP_DIR=${HOME}/kiauh-backups
|
||||
#===================================================#
|
||||
#=================== UPDATE KIAUH ==================#
|
||||
#===================================================#
|
||||
|
||||
### set github repos
|
||||
KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git
|
||||
ARKSINE_REPO=https://github.com/Arksine/klipper.git
|
||||
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
|
||||
DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
MOONRAKER_REPO=https://github.com/Arksine/moonraker.git
|
||||
KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git
|
||||
#branches
|
||||
BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing
|
||||
BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping
|
||||
function update_kiauh() {
|
||||
status_msg "Updating KIAUH ..."
|
||||
|
||||
### set some messages
|
||||
warn_msg(){
|
||||
echo -e "${red}<!!!!> $1${default}"
|
||||
}
|
||||
status_msg(){
|
||||
echo; echo -e "${yellow}###### $1${default}"
|
||||
}
|
||||
ok_msg(){
|
||||
echo -e "${green}>>>>>> $1${default}"
|
||||
}
|
||||
title_msg(){
|
||||
echo -e "${cyan}$1${default}"
|
||||
}
|
||||
get_date(){
|
||||
current_date=$(date +"%Y-%m-%d_%H-%M")
|
||||
}
|
||||
print_unkown_cmd(){
|
||||
ERROR_MSG="Invalid command!"
|
||||
cd "${KIAUH_SRCDIR}"
|
||||
git reset --hard && git pull
|
||||
|
||||
ok_msg "Update complete! Please restart KIAUH."
|
||||
exit 0
|
||||
}
|
||||
|
||||
print_msg(){
|
||||
if [[ "$ERROR_MSG" != "" ]]; then
|
||||
echo -e "${red}"
|
||||
echo -e "#########################################################"
|
||||
echo -e " $ERROR_MSG "
|
||||
echo -e "#########################################################"
|
||||
echo -e "${default}"
|
||||
fi
|
||||
if [ "$CONFIRM_MSG" != "" ]; then
|
||||
echo -e "${green}"
|
||||
echo -e "#########################################################"
|
||||
echo -e " $CONFIRM_MSG "
|
||||
echo -e "#########################################################"
|
||||
echo -e "${default}"
|
||||
#===================================================#
|
||||
#=================== KIAUH STATUS ==================#
|
||||
#===================================================#
|
||||
|
||||
function kiauh_update_avail() {
|
||||
[[ ! -d "${KIAUH_SRCDIR}/.git" ]] && return
|
||||
local origin head
|
||||
|
||||
cd "${KIAUH_SRCDIR}"
|
||||
|
||||
### abort if not on master branch
|
||||
! git branch -a | grep -q "\* master" && return
|
||||
|
||||
### compare commit hash
|
||||
git fetch -q
|
||||
origin=$(git rev-parse --short=8 origin/master)
|
||||
head=$(git rev-parse --short=8 HEAD)
|
||||
|
||||
if [[ ${origin} != "${head}" ]]; then
|
||||
echo "true"
|
||||
fi
|
||||
}
|
||||
|
||||
clear_msg(){
|
||||
unset CONFIRM_MSG
|
||||
unset ERROR_MSG
|
||||
function kiauh_update_dialog() {
|
||||
[[ ! $(kiauh_update_avail) == "true" ]] && return
|
||||
top_border
|
||||
echo -e "|${green} New KIAUH update available! ${white}|"
|
||||
hr
|
||||
echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}|"
|
||||
blank_line
|
||||
echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}|"
|
||||
echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|"
|
||||
echo -e "|${yellow} features. Please consider updating! ${white}|"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
read -p "${cyan}###### Do you want to update now? (Y/n):${white} " yn
|
||||
while true; do
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
do_action "update_kiauh"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
deny_action "kiauh_update_dialog";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
check_euid
|
||||
init_logfile
|
||||
set_globals
|
||||
init_ini
|
||||
kiauh_status
|
||||
kiauh_update_dialog
|
||||
main_menu
|
||||
|
||||
18
klipper_repos.txt.example
Normal file
18
klipper_repos.txt.example
Normal file
@@ -0,0 +1,18 @@
|
||||
# This file acts as an example file.
|
||||
#
|
||||
# 1) Make a copy of this file and rename it to 'klipper_repos.txt'
|
||||
# 2) Add your custom Klipper repository to the bottom of that copy
|
||||
# 3) Save the file
|
||||
#
|
||||
# Back in KIAUH you can now go into -> [Settings] and use action '2' to set a different Klipper repository
|
||||
#
|
||||
# Make sure to always separate the repository and the branch with a ','.
|
||||
# <repository>,<branch> -> https://github.com/Klipper3d/klipper,master
|
||||
# If you omit a branch, it will always default to 'master'
|
||||
#
|
||||
# You are allowed to omit the 'https://github.com/' part of the repository URL
|
||||
# Down below are now a few examples of what is considered as valid:
|
||||
https://github.com/Klipper3d/klipper,master
|
||||
https://github.com/Klipper3d/klipper
|
||||
Klipper3d/klipper,master
|
||||
Klipper3d/klipper
|
||||
@@ -1,10 +1,10 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#####################################################################
|
||||
### Please set the paths accordingly. In case you don't have all ###
|
||||
### the listed folders, just keep that line commented out. ###
|
||||
#####################################################################
|
||||
### Path to your config folder you want to backup
|
||||
### Path to your config folder you want to back up
|
||||
#config_folder=~/klipper_config
|
||||
|
||||
### Path to your Klipper folder, by default that is '~/klipper'
|
||||
@@ -26,37 +26,38 @@
|
||||
#####################################################################
|
||||
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
|
||||
#####################################################################
|
||||
grab_version(){
|
||||
if [ ! -z "$klipper_folder" ]; then
|
||||
cd "$klipper_folder"
|
||||
grab_version() {
|
||||
local klipper_commit moonraker_commit
|
||||
local mainsail_ver fluidd_ver
|
||||
|
||||
if [[ -n ${klipper_folder} ]]; then
|
||||
cd "${klipper_folder}"
|
||||
klipper_commit=$(git rev-parse --short=7 HEAD)
|
||||
m1="Klipper on commit: $klipper_commit"
|
||||
cd ..
|
||||
m1="Klipper on commit: ${klipper_commit}"
|
||||
fi
|
||||
if [ ! -z "$moonraker_folder" ]; then
|
||||
cd "$moonraker_folder"
|
||||
if [[ -n ${moonraker_folder} ]]; then
|
||||
cd "${moonraker_folder}"
|
||||
moonraker_commit=$(git rev-parse --short=7 HEAD)
|
||||
m2="Moonraker on commit: $moonraker_commit"
|
||||
cd ..
|
||||
m2="Moonraker on commit: ${moonraker_commit}"
|
||||
fi
|
||||
if [ ! -z "$mainsail_folder" ]; then
|
||||
mainsail_file=$(find $mainsail_folder/js -name "app.*.js" 2>/dev/null)
|
||||
mainsail_ver=$(grep -o -E 'state:{packageVersion:.+' $mainsail_file | cut -d'"' -f2)
|
||||
m3="Mainsail version: $mainsail_ver"
|
||||
if [[ -n ${mainsail_folder} ]]; then
|
||||
mainsail_ver=$(head -n 1 "${mainsail_folder}/.version")
|
||||
m3="Mainsail version: ${mainsail_ver}"
|
||||
fi
|
||||
if [ ! -z "$fluidd_folder" ]; then
|
||||
fluidd_file=$(find $fluidd_folder/js -name "app.*.js" 2>/dev/null)
|
||||
fluidd_ver=$(grep -o -E '"setVersion",".+"' $fluidd_file | cut -d'"' -f4)
|
||||
m4="Fluidd version: $fluidd_ver"
|
||||
if [[ -n ${fluidd_folder} ]]; then
|
||||
fluidd_ver=$(head -n 1 "${fluidd_folder}/.version")
|
||||
m4="Fluidd version: ${fluidd_ver}"
|
||||
fi
|
||||
}
|
||||
|
||||
push_config(){
|
||||
cd $config_folder
|
||||
push_config() {
|
||||
local current_date
|
||||
|
||||
cd "${config_folder}" || exit 1
|
||||
git pull
|
||||
git add .
|
||||
current_date=$(date +"%Y-%m-%d %T")
|
||||
git commit -m "Autocommit from $current_date" -m "$m1" -m "$m2" -m "$m3" -m "$m4"
|
||||
git commit -m "Autocommit from ${current_date}" -m "${m1}" -m "${m2}" -m "${m3}" -m "${m4}"
|
||||
git push
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
upstream dwc2 {
|
||||
server 127.0.0.1:4750;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
#listen [::]:80;
|
||||
|
||||
location / {
|
||||
proxy_pass http://dwc2/;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
#proxy_set_header X-Script-Name /;
|
||||
proxy_http_version 1.1;
|
||||
client_max_body_size 0;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
# /etc/nginx/sites-available/fluidd
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
access_log /var/log/nginx/fluidd-access.log;
|
||||
error_log /var/log/nginx/fluidd-error.log;
|
||||
|
||||
#disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_comp_level 4;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
#web_path from fluidd static files
|
||||
root /home/pi/fluidd;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
#max upload size for gcodes
|
||||
client_max_body_size 0;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /printer {
|
||||
proxy_pass http://apiserver/printer;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://apiserver/api;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /access {
|
||||
proxy_pass http://apiserver/access;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location /machine {
|
||||
proxy_pass http://apiserver/machine;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /server {
|
||||
proxy_pass http://apiserver/server;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /webcam/ {
|
||||
proxy_pass http://mjpgstreamer/;
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class ShellCommand:
|
||||
data = os.read(self.proc_fd, 4096)
|
||||
except Exception:
|
||||
pass
|
||||
data = self.partial_output + data
|
||||
data = self.partial_output + data.decode()
|
||||
if '\n' not in data:
|
||||
self.partial_output = data
|
||||
return
|
||||
@@ -40,14 +40,18 @@ class ShellCommand:
|
||||
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, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
self.command + gcode_params, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
except Exception:
|
||||
logging.exception(
|
||||
"shell_command: Command {%s} failed" % (self.name))
|
||||
|
||||
59
resources/kiauh_macros.cfg
Normal file
59
resources/kiauh_macros.cfg
Normal file
@@ -0,0 +1,59 @@
|
||||
################################################################################
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~ AUTOCREATED WITH KIAUH ~~~~~~~~~~~~~~~~~~~~~~~~~~ #
|
||||
################################################################################
|
||||
# Recommended macros and config entries if you use Mainsail or Fluidd! #
|
||||
# You can edit or delete those macros if you already defined them elsewhere! #
|
||||
################################################################################
|
||||
|
||||
[pause_resume]
|
||||
|
||||
[display_status]
|
||||
|
||||
[gcode_macro CANCEL_PRINT]
|
||||
rename_existing: BASE_CANCEL_PRINT
|
||||
gcode:
|
||||
TURN_OFF_HEATERS
|
||||
CLEAR_PAUSE
|
||||
SDCARD_RESET_FILE
|
||||
BASE_CANCEL_PRINT
|
||||
|
||||
[gcode_macro PAUSE]
|
||||
rename_existing: BASE_PAUSE
|
||||
gcode:
|
||||
##### set defaults #####
|
||||
{% set x = params.X|default(230) %} #edit to your park position
|
||||
{% set y = params.Y|default(230) %} #edit to your park position
|
||||
{% set z = params.Z|default(10)|float %} #edit to your park position
|
||||
{% set e = params.E|default(1) %} #edit to your retract length
|
||||
##### calculate save lift position #####
|
||||
{% set max_z = printer.toolhead.axis_maximum.z|float %}
|
||||
{% set act_z = printer.toolhead.position.z|float %}
|
||||
{% set lift_z = z|abs %}
|
||||
{% if act_z < (max_z - lift_z) %}
|
||||
{% set z_safe = lift_z %}
|
||||
{% else %}
|
||||
{% set z_safe = max_z - act_z %}
|
||||
{% endif %}
|
||||
##### end of definitions #####
|
||||
SAVE_GCODE_STATE NAME=PAUSE_state
|
||||
BASE_PAUSE
|
||||
G91
|
||||
G1 E-{e} F2100
|
||||
G1 Z{z_safe}
|
||||
G90
|
||||
G1 X{x} Y{y} F6000
|
||||
|
||||
|
||||
[gcode_macro RESUME]
|
||||
rename_existing: BASE_RESUME
|
||||
gcode:
|
||||
##### set defaults #####
|
||||
{% set e = params.E|default(1) %} #edit to your retract length
|
||||
G91
|
||||
G1 E{e} F2100
|
||||
G90
|
||||
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
|
||||
BASE_RESUME
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
22
resources/klipper.service
Normal file
22
resources/klipper.service
Normal file
@@ -0,0 +1,22 @@
|
||||
#Systemd Klipper Service
|
||||
|
||||
[Unit]
|
||||
Description=Systemd Klipper Service for instance klipper-%INST%
|
||||
Documentation=https://www.klipper3d.org/
|
||||
After=network.target
|
||||
Wants=udev.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=KLIPPER_CONFIG=%CFG%
|
||||
Environment=KLIPPER_LOG=%LOG%
|
||||
Environment=KLIPPER_SOCKET=%UDS%
|
||||
Environment=KLIPPER_PRINTER=%PRINTER%
|
||||
Type=simple
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
ExecStart=%ENV%/bin/python %DIR%/klippy/klippy.py ${KLIPPER_CONFIG} -I ${KLIPPER_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPER_SOCKET}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
95
resources/klipper_webui_nginx.cfg
Normal file
95
resources/klipper_webui_nginx.cfg
Normal file
@@ -0,0 +1,95 @@
|
||||
# /etc/nginx/sites-available/<<UI>>
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
access_log /var/log/nginx/<<UI>>-access.log;
|
||||
error_log /var/log/nginx/<<UI>>-error.log;
|
||||
|
||||
# disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_comp_level 4;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
# web_path from <<UI>> static files
|
||||
root /home/pi/<<UI>>;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
# disable max upload size checks
|
||||
client_max_body_size 0;
|
||||
|
||||
# disable proxy request buffering
|
||||
proxy_request_buffering off;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location ~ ^/(printer|api|access|machine|server)/ {
|
||||
proxy_pass http://apiserver$request_uri;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /webcam/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer1/;
|
||||
}
|
||||
|
||||
location /webcam2/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer2/;
|
||||
}
|
||||
|
||||
location /webcam3/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer3/;
|
||||
}
|
||||
|
||||
location /webcam4/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer4/;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
# /etc/nginx/sites-available/mainsail
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
access_log /var/log/nginx/mainsail-access.log;
|
||||
error_log /var/log/nginx/mainsail-error.log;
|
||||
|
||||
#disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_comp_level 4;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
#web_path from mainsail static files
|
||||
root /home/pi/mainsail;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
#max upload size for gcodes
|
||||
client_max_body_size 0;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /printer {
|
||||
proxy_pass http://apiserver/printer;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://apiserver/api;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /access {
|
||||
proxy_pass http://apiserver/access;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location /machine {
|
||||
proxy_pass http://apiserver/machine;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /server {
|
||||
proxy_pass http://apiserver/server;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /webcam/ {
|
||||
proxy_pass http://mjpgstreamer/;
|
||||
}
|
||||
}
|
||||
19
resources/moonraker-telegram-bot.service
Normal file
19
resources/moonraker-telegram-bot.service
Normal file
@@ -0,0 +1,19 @@
|
||||
#Systemd service file for Moonraker Telegram Bot
|
||||
|
||||
[Unit]
|
||||
Description=Starts Moonraker Telegram Bot instance %INST% on startup
|
||||
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=TELEGRAM_CONF=%CFG%
|
||||
Environment=TELEGRAM_LOG=%LOG%
|
||||
Type=simple
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
ExecStart=%ENV%/bin/python %DIR%/bot/main.py -c ${TELEGRAM_CONF} -l ${TELEGRAM_LOG}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
@@ -1,10 +1,38 @@
|
||||
[server]
|
||||
host: 0.0.0.0
|
||||
port: 7125
|
||||
enable_debug_logging: True
|
||||
config_path: ~/klipper_config
|
||||
port: %PORT%
|
||||
enable_debug_logging: False
|
||||
klippy_uds_address: %UDS%
|
||||
|
||||
[authorization]
|
||||
enabled: True
|
||||
trusted_clients:
|
||||
127.0.0.1
|
||||
%LAN%
|
||||
10.0.0.0/8
|
||||
127.0.0.0/8
|
||||
169.254.0.0/16
|
||||
172.16.0.0/12
|
||||
192.168.0.0/16
|
||||
FE80::/10
|
||||
::1/128
|
||||
cors_domains:
|
||||
http://*.lan
|
||||
http://*.local
|
||||
https://my.mainsail.xyz
|
||||
http://my.mainsail.xyz
|
||||
https://app.fluidd.xyz
|
||||
http://app.fluidd.xyz
|
||||
|
||||
[database]
|
||||
database_path: %DB%
|
||||
|
||||
[file_manager]
|
||||
config_path: %CFG%
|
||||
log_path: %LOG%
|
||||
|
||||
[octoprint_compat]
|
||||
|
||||
[history]
|
||||
|
||||
[update_manager]
|
||||
channel: dev
|
||||
refresh_interval: 168
|
||||
|
||||
20
resources/moonraker.service
Normal file
20
resources/moonraker.service
Normal file
@@ -0,0 +1,20 @@
|
||||
#Systemd Moonraker Service
|
||||
|
||||
[Unit]
|
||||
Description=Systemd Moonraker Service for instance moonraker-%INST%
|
||||
Documentation=https://moonraker.readthedocs.io/
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=MOONRAKER_CONF=%CFG%
|
||||
Environment=MOONRAKER_LOG=%LOG%
|
||||
Type=simple
|
||||
SupplementaryGroups=moonraker-admin
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
ExecStart=%ENV%/bin/python %DIR%/moonraker/moonraker.py -c ${MOONRAKER_CONF} -l ${MOONRAKER_LOG}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
@@ -1,13 +0,0 @@
|
||||
# /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
|
||||
ip_hash;
|
||||
server 127.0.0.1:8080;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
serial:
|
||||
additionalPorts:
|
||||
- /tmp/printer
|
||||
disconnectOnErrors: false
|
||||
port: /tmp/printer
|
||||
server:
|
||||
commands:
|
||||
serverRestartCommand: sudo service octoprint restart
|
||||
systemRestartCommand: sudo shutdown -r now
|
||||
systemShutdownCommand: sudo shutdown -h now
|
||||
@@ -1,40 +0,0 @@
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
upstream octoprint {
|
||||
server 127.0.0.1:5000;
|
||||
}
|
||||
|
||||
upstream mjpg-streamer {
|
||||
server 127.0.0.1:8080;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
#listen [::]:80;
|
||||
|
||||
location / {
|
||||
proxy_pass http://octoprint/;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
#proxy_set_header X-Script-Name /;
|
||||
proxy_http_version 1.1;
|
||||
client_max_body_size 0;
|
||||
}
|
||||
|
||||
location /webcam {
|
||||
proxy_pass http://mjpg-streamer/;
|
||||
}
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
}
|
||||
7
resources/printer.cfg
Normal file
7
resources/printer.cfg
Normal file
@@ -0,0 +1,7 @@
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/<your-mcu-id>
|
||||
|
||||
[printer]
|
||||
kinematics: none
|
||||
max_velocity: 1000
|
||||
max_accel: 1000
|
||||
BIN
resources/screenshots/kiauh.png
Normal file
BIN
resources/screenshots/kiauh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
7
resources/shell_command.cfg
Normal file
7
resources/shell_command.cfg
Normal file
@@ -0,0 +1,7 @@
|
||||
[gcode_shell_command hello_world]
|
||||
command: echo hello world
|
||||
timeout: 2.
|
||||
verbose: True
|
||||
[gcode_macro HELLO_WORLD]
|
||||
gcode:
|
||||
RUN_SHELL_COMMAND CMD=hello_world
|
||||
25
resources/upstreams.conf
Normal file
25
resources/upstreams.conf
Normal file
@@ -0,0 +1,25 @@
|
||||
# /etc/nginx/conf.d/upstreams.conf
|
||||
upstream apiserver {
|
||||
ip_hash;
|
||||
server 127.0.0.1:7125;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer1 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8080;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer2 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8081;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer3 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8082;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer4 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8083;
|
||||
}
|
||||
15
resources/webcamd.service
Normal file
15
resources/webcamd.service
Normal file
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=Starts mjpg-streamer on startup
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
User=%USER%
|
||||
WorkingDirectory=/usr/local/bin
|
||||
StandardOutput=append:/var/log/webcamd.log
|
||||
StandardError=append:/var/log/webcamd.log
|
||||
ExecStart=/usr/local/bin/webcamd
|
||||
Restart=always
|
||||
@@ -1,38 +0,0 @@
|
||||
### AUTOCREATED WITH KIAUH ###
|
||||
#is required to load the pause_resume module in klipper
|
||||
[pause_resume]
|
||||
|
||||
[gcode_macro PAUSE]
|
||||
rename_existing: BASE_PAUSE
|
||||
default_parameter_X: 230 #edit to your park position
|
||||
default_parameter_Y: 230 #edit to your park position
|
||||
default_parameter_Z: 10 #edit to your park position
|
||||
default_parameter_E: 1 #edit to your retract length
|
||||
gcode:
|
||||
SAVE_GCODE_STATE NAME=PAUSE_state
|
||||
BASE_PAUSE
|
||||
G91
|
||||
G1 E-{E} F2100
|
||||
G1 Z{Z}
|
||||
G90
|
||||
G1 X{X} Y{Y} F6000
|
||||
|
||||
[gcode_macro RESUME]
|
||||
rename_existing: BASE_RESUME
|
||||
default_parameter_E: 1 #edit to your retract length
|
||||
gcode:
|
||||
G91
|
||||
G1 E{E} F2100
|
||||
G90
|
||||
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
|
||||
BASE_RESUME
|
||||
|
||||
[gcode_macro CANCEL_PRINT]
|
||||
rename_existing: BASE_CANCEL_PRINT
|
||||
gcode:
|
||||
TURN_OFF_HEATERS
|
||||
CLEAR_PAUSE
|
||||
SDCARD_RESET_FILE
|
||||
BASE_CANCEL_PRINT
|
||||
##########################
|
||||
##########################
|
||||
@@ -1,152 +1,188 @@
|
||||
check_for_backup_dir(){
|
||||
if [ ! -d $BACKUP_DIR ]; then
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function get_date() {
|
||||
local current_date
|
||||
current_date=$(date +"%y%m%d-%H%M")
|
||||
echo "${current_date}"
|
||||
}
|
||||
|
||||
function check_for_backup_dir() {
|
||||
[[ -d ${BACKUP_DIR} ]] && return
|
||||
|
||||
status_msg "Create KIAUH backup directory ..."
|
||||
mkdir -p $BACKUP_DIR && ok_msg "Directory created!"
|
||||
fi
|
||||
mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
|
||||
}
|
||||
|
||||
backup_printer_cfg(){
|
||||
function backup_before_update() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${backup_before_update}"
|
||||
[[ ${state} = "false" ]] && return
|
||||
backup_"${1}"
|
||||
}
|
||||
|
||||
function backup_klipper_config_dir() {
|
||||
check_for_backup_dir
|
||||
if [ -f $PRINTER_CFG ]; then
|
||||
get_date
|
||||
status_msg "Create backup of printer.cfg ..."
|
||||
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!"
|
||||
local current_date config_folder_name
|
||||
|
||||
if [[ -d "${KLIPPER_CONFIG}" ]]; then
|
||||
current_date=$(get_date)
|
||||
config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)"
|
||||
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
status_msg "Create backup of the Klipper config directory ..."
|
||||
|
||||
mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}"
|
||||
cp -r "${KLIPPER_CONFIG}" "${_}"
|
||||
|
||||
print_confirm "Configuration directory backup complete!"
|
||||
else
|
||||
ok_msg "No printer.cfg found! Skipping backup ..."
|
||||
ok_msg "No config directory found! Skipping backup ..."
|
||||
fi
|
||||
}
|
||||
|
||||
backup_moonraker_conf(){
|
||||
function backup_moonraker_database() {
|
||||
check_for_backup_dir
|
||||
if [ -f ${HOME}/moonraker.conf ]; then
|
||||
get_date
|
||||
status_msg "Create backup of moonraker.conf ..."
|
||||
cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!"
|
||||
local current_date databases target_dir regex=".moonraker_database(_[0-9a-zA-Z]+)?"
|
||||
databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/${regex}" | sort)
|
||||
|
||||
if [[ -n ${databases} ]]; then
|
||||
current_date=$(get_date)
|
||||
target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}"
|
||||
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${target_dir}"
|
||||
|
||||
for database in ${databases}; do
|
||||
status_msg "Create backup of ${database} ..."
|
||||
cp -r "${database}" "${target_dir}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
print_confirm "Moonraker database backup complete!"
|
||||
else
|
||||
ok_msg "No moonraker.conf found! Skipping backup ..."
|
||||
print_error "No Moonraker database found! Skipping backup ..."
|
||||
fi
|
||||
return
|
||||
}
|
||||
|
||||
read_bb4u_stat(){
|
||||
source_ini
|
||||
if [ ! "$backup_before_update" = "true" ]; then
|
||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
||||
else
|
||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
||||
fi
|
||||
}
|
||||
function backup_klipper() {
|
||||
local current_date
|
||||
|
||||
toggle_backups(){
|
||||
source_ini
|
||||
if [ "$backup_before_update" = "true" ]; then
|
||||
sed -i '/backup_before_update=/s/true/false/' $INI_FILE
|
||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
||||
CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !"
|
||||
fi
|
||||
if [ "$backup_before_update" = "false" ]; then
|
||||
sed -i '/backup_before_update=/s/false/true/' $INI_FILE
|
||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
||||
CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !"
|
||||
fi
|
||||
}
|
||||
|
||||
bb4u(){
|
||||
source_ini
|
||||
if [ "$backup_before_update" = "true" ]; then
|
||||
backup_$1
|
||||
fi
|
||||
}
|
||||
|
||||
backup_klipper(){
|
||||
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV_DIR ]; then
|
||||
if [[ -d ${KLIPPER_DIR} && -d ${KLIPPY_ENV} ]]; then
|
||||
status_msg "Creating Klipper backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date"
|
||||
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV_DIR $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}"
|
||||
cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}"
|
||||
print_confirm "Klipper backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!"
|
||||
print_error "Can't back up 'klipper' and/or 'klipper-env' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_dwc2(){
|
||||
if [ -d $DWC2FK_DIR ] && [ -d $DWC_ENV_DIR ] && [ -d $DWC2_DIR ]; then
|
||||
status_msg "Creating DWC2 Web UI backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/dwc2-backups/"$current_date"
|
||||
cp -r $DWC2FK_DIR $_ && cp -r $DWC_ENV_DIR $_ && cp -r $DWC2_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
function backup_mainsail() {
|
||||
local current_date
|
||||
|
||||
backup_mainsail(){
|
||||
if [ -d $MAINSAIL_DIR ]; then
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
status_msg "Creating Mainsail backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date"
|
||||
cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}"
|
||||
cp -r "${MAINSAIL_DIR}" "${_}"
|
||||
print_confirm "Mainsail backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup mainsail directory! Not found!"
|
||||
print_error "Can't back up 'mainsail' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_fluidd(){
|
||||
if [ -d $FLUIDD_DIR ]; then
|
||||
function backup_fluidd() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||
status_msg "Creating Fluidd backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/fluidd-backups/"$current_date"
|
||||
cp -r $FLUIDD_DIR $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}"
|
||||
cp -r "${FLUIDD_DIR}" "${_}"
|
||||
print_confirm "Fluidd backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup fluidd directory! Not found!"
|
||||
print_error "Can't back up 'fluidd' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_moonraker(){
|
||||
if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV_DIR ]; then
|
||||
function backup_moonraker() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${MOONRAKER_DIR} && -d ${MOONRAKER_ENV} ]]; then
|
||||
status_msg "Creating Moonraker backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date"
|
||||
cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV_DIR $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}"
|
||||
cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}"
|
||||
print_confirm "Moonraker backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!"
|
||||
print_error "Can't back up moonraker and/or moonraker-env directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_octoprint(){
|
||||
if [ -d $OCTOPRINT_DIR ] && [ -d $OCTOPRINT_CFG_DIR ]; then
|
||||
function backup_octoprint() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${OCTOPRINT_DIR} && -d ${OCTOPRINT_CFG_DIR} ]]; then
|
||||
status_msg "Creating OctoPrint backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/octoprint-backups/"$current_date"
|
||||
cp -r $OCTOPRINT_DIR $_ && cp -r $OCTOPRINT_CFG_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}"
|
||||
cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
|
||||
print_confirm " OctoPrint backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup OctoPrint and/or .octoprint directory!\n Not found!"
|
||||
print_error "Can't back up OctoPrint and/or .octoprint directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_klipperscreen(){
|
||||
if [ -d $KLIPPERSCREEN_DIR ] ; then
|
||||
function backup_klipperscreen() {
|
||||
local current_date
|
||||
if [[ -d ${KLIPPERSCREEN_DIR} ]] ; then
|
||||
status_msg "Creating KlipperScreen backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/klipperscreen-backups/"$current_date"
|
||||
cp -r $KLIPPERSCREEN_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}"
|
||||
cp -r "${KLIPPERSCREEN_DIR}" "${_}"
|
||||
print_confirm "KlipperScreen backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup KlipperScreen directory!\n Not found!"
|
||||
print_error "Can't back up KlipperScreen directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_telegram_bot() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${TELEGRAM_BOT_DIR} ]] ; then
|
||||
status_msg "Creating MoonrakerTelegramBot backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}"
|
||||
cp -r "${TELEGRAM_BOT_DIR}" "${_}"
|
||||
print_confirm "MoonrakerTelegramBot backup complete!"
|
||||
else
|
||||
print_error "Can't back up MoonrakerTelegramBot directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/sh
|
||||
# System startup script for dwc2-for-klipper-socket
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: dwc2-for-klipper-socket
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: dwc2-for-klipper-socket daemon
|
||||
# Description: Starts the dwc2-for-klipper-socket daemon.
|
||||
### END INIT INFO
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
DESC="dwc2-for-klipper-socket daemon"
|
||||
NAME="dwc2-for-klipper-socket"
|
||||
DEFAULTS_FILE=/etc/default/dwc
|
||||
PIDFILE=/var/run/dwc.pid
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
# Read defaults file
|
||||
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
|
||||
|
||||
case "$1" in
|
||||
start) log_daemon_msg "Starting dwc2-for-klipper-socket" $NAME
|
||||
start-stop-daemon --start --quiet --exec $DWC_EXEC \
|
||||
--background --pidfile $PIDFILE --make-pidfile \
|
||||
--chuid $DWC_USER --user $DWC_USER \
|
||||
-- $DWC_ARGS
|
||||
log_end_msg $?
|
||||
;;
|
||||
stop) log_daemon_msg "Stopping dwc2-for-klipper-socket" $NAME
|
||||
killproc -p $PIDFILE $DWC_EXEC
|
||||
RETVAL=$?
|
||||
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
|
||||
log_end_msg $RETVAL
|
||||
;;
|
||||
restart) log_daemon_msg "Restarting dwc2-for-klipper-socket" $NAME
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
reload|force-reload)
|
||||
log_daemon_msg "Reloading configuration not supported" $NAME
|
||||
log_end_msg 1
|
||||
;;
|
||||
status)
|
||||
status_of_proc -p $PIDFILE $DWC_EXEC $NAME && exit 0 || exit $?
|
||||
;;
|
||||
*) log_action_msg "Usage: /etc/init.d/dwc {start|stop|status|restart|reload|force-reload}"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -1,106 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running
|
||||
# Raspbian/Raspberry Pi OS based distributions.
|
||||
|
||||
# https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
|
||||
PYTHONDIR="${HOME}/dwc-env"
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
DWC_USER=${USER}
|
||||
|
||||
# Step 1: Verify Klipper has been installed
|
||||
check_klipper()
|
||||
{
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
echo "Klipper service found!"
|
||||
else
|
||||
echo "Klipper service not found, please install Klipper first"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Step 2: Install packages
|
||||
install_packages()
|
||||
{
|
||||
PKGLIST="python3-virtualenv python3-dev python3-tornado"
|
||||
|
||||
# Update system package info
|
||||
report_status "Running apt-get update..."
|
||||
sudo apt-get update
|
||||
|
||||
# Install desired packages
|
||||
report_status "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
# Step 3: Create python virtual environment
|
||||
create_virtualenv()
|
||||
{
|
||||
report_status "Updating python virtual environment..."
|
||||
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR}
|
||||
|
||||
# Install/update dependencies
|
||||
${PYTHONDIR}/bin/pip install tornado==6.0.4
|
||||
}
|
||||
|
||||
# Step 4: Install startup script
|
||||
install_script(){
|
||||
report_status "Installing system start script..."
|
||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/dwc.service" << EOF
|
||||
#Systemd service file for DWC
|
||||
[Unit]
|
||||
Description=dwc_webif
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$DWC_USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${PYTHONDIR}/bin/python3 ${SRCDIR}/web_dwc2.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
# Use systemctl to enable the klipper systemd service script
|
||||
sudo systemctl enable dwc.service
|
||||
}
|
||||
|
||||
# Step 5: Start DWC service
|
||||
start_software()
|
||||
{
|
||||
report_status "Launching dwc2-for-klipper-socket..."
|
||||
sudo systemctl start dwc
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
report_status()
|
||||
{
|
||||
echo -e "\n\n###### $1"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Force script to exit if an error occurs
|
||||
set -e
|
||||
|
||||
# Find SRCDIR from the pathname of this script
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
|
||||
# Run installation steps defined above
|
||||
verify_ready
|
||||
check_klipper
|
||||
install_packages
|
||||
create_virtualenv
|
||||
install_script
|
||||
start_software
|
||||
@@ -1,106 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running
|
||||
# Raspbian/Raspberry Pi OS based distributions.
|
||||
|
||||
# https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
|
||||
PYTHONDIR="${HOME}/dwc-env"
|
||||
|
||||
# Step 1: Verify Klipper has been installed
|
||||
check_klipper()
|
||||
{
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
echo "Klipper service found!"
|
||||
else
|
||||
echo "Klipper service not found, please install Klipper first"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Step 2: Install packages
|
||||
install_packages()
|
||||
{
|
||||
PKGLIST="python3-virtualenv python3-dev python3-tornado"
|
||||
|
||||
# Update system package info
|
||||
report_status "Running apt-get update..."
|
||||
sudo apt-get update
|
||||
|
||||
# Install desired packages
|
||||
report_status "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
# Step 3: Create python virtual environment
|
||||
create_virtualenv()
|
||||
{
|
||||
report_status "Updating python virtual environment..."
|
||||
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR}
|
||||
|
||||
# Install/update dependencies
|
||||
${PYTHONDIR}/bin/pip install tornado==6.0.4
|
||||
}
|
||||
|
||||
# Step 4: Install startup script
|
||||
install_script(){
|
||||
report_status "Installing system start script..."
|
||||
sudo cp "${SRCDIR}/scripts/dwc-start.sh" /etc/init.d/dwc
|
||||
sudo update-rc.d dwc defaults
|
||||
}
|
||||
|
||||
# Step 5: Install startup script config
|
||||
install_config(){
|
||||
DEFAULTS_FILE=/etc/default/dwc
|
||||
[ -f $DEFAULTS_FILE ] && return
|
||||
|
||||
report_status "Installing system start configuration..."
|
||||
sudo /bin/sh -c "cat > $DEFAULTS_FILE" <<EOF
|
||||
# Configuration for /etc/init.d/dwc
|
||||
DWC_USER=$USER
|
||||
|
||||
DWC_EXEC=${PYTHONDIR}/bin/python3
|
||||
|
||||
DWC_ARGS="${SRCDIR}/web_dwc2.py"
|
||||
EOF
|
||||
}
|
||||
|
||||
# Step 4: Start server
|
||||
start_software()
|
||||
{
|
||||
report_status "Launching dwc2-for-klipper-socket..."
|
||||
sudo /etc/init.d/klipper stop
|
||||
sudo /etc/init.d/dwc restart
|
||||
sudo /etc/init.d/klipper start
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
report_status()
|
||||
{
|
||||
echo -e "\n\n###### $1"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Force script to exit if an error occurs
|
||||
set -e
|
||||
|
||||
# Find SRCDIR from the pathname of this script
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
|
||||
# Run installation steps defined above
|
||||
verify_ready
|
||||
check_klipper
|
||||
install_packages
|
||||
create_virtualenv
|
||||
install_script
|
||||
install_config
|
||||
start_software
|
||||
@@ -1,41 +0,0 @@
|
||||
stop_service() {
|
||||
# Stop DWC Service
|
||||
echo "#### Stopping DWC Service.."
|
||||
sudo systemctl stop dwc
|
||||
sudo systemctl disable dwc
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove DWC from Services
|
||||
echo
|
||||
echo "#### Removing DWC Service.."
|
||||
sudo rm -f /etc/systemd/system/dwc.service
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
# Remove virtualenv
|
||||
if [ -d ~/dwc-env ]; then
|
||||
echo "Removing virtualenv..."
|
||||
rm -rf ~/dwc-env
|
||||
else
|
||||
echo "No DWC virtualenv found"
|
||||
fi
|
||||
|
||||
# Notify user of method to remove DWC source code
|
||||
echo
|
||||
echo "The DWC system files and virtualenv have been removed."
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
@@ -1,45 +0,0 @@
|
||||
stop_service() {
|
||||
# Stop DWC Service
|
||||
echo "#### Stopping DWC Service.."
|
||||
sudo service dwc stop
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove DWC from Startup
|
||||
echo
|
||||
echo "#### Removing DWC from Startup.."
|
||||
sudo update-rc.d -f dwc remove
|
||||
|
||||
# Remove DWC from Services
|
||||
echo
|
||||
echo "#### Removing DWC Service.."
|
||||
sudo rm -f /etc/init.d/dwc /etc/default/dwc
|
||||
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
# Remove virtualenv
|
||||
if [ -d ~/dwc-env ]; then
|
||||
echo "Removing virtualenv..."
|
||||
rm -rf ~/dwc-env
|
||||
else
|
||||
echo "No DWC virtualenv found"
|
||||
fi
|
||||
|
||||
# Notify user of method to remove DWC source code
|
||||
echo
|
||||
echo "The DWC system files and virtualenv have been removed."
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
409
scripts/flash_klipper.sh
Normal file
409
scripts/flash_klipper.sh
Normal file
@@ -0,0 +1,409 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function init_flash_process() {
|
||||
### step 1: check for required userhgroups (tty & dialout)
|
||||
check_usergroups
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| Please select the flashing method to flash your MCU. |"
|
||||
echo -e "| Make sure to only select a method your MCU supports. |"
|
||||
echo -e "| Not all MCUs support both methods! |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| 1) Regular flashing method |"
|
||||
echo -e "| 2) Updating via SD-Card Update |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice method
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
select_msg "Regular flashing method"
|
||||
method="regular"
|
||||
break;;
|
||||
2)
|
||||
select_msg "SD-Card Update"
|
||||
method="sdcard"
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_flash_method_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### step 2: select how the mcu is connected to the host
|
||||
select_mcu_connection
|
||||
|
||||
### step 3: select which detected mcu should be flashed
|
||||
select_mcu_id "${method}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 2 =====================#
|
||||
#================================================#
|
||||
function select_mcu_connection() {
|
||||
top_border
|
||||
echo -e "| ${yellow}Make sure that the controller board is connected now!${white} |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| How is the controller board connected to the host? |"
|
||||
echo -e "| 1) USB |"
|
||||
echo -e "| 2) UART |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Connection method:${white} " choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
status_msg "Identifying MCU connected via USB ...\n"
|
||||
get_usb_id || true # continue even after exit code 1
|
||||
break;;
|
||||
2)
|
||||
status_msg "Identifying MCU possibly connected via UART ...\n"
|
||||
get_uart_id || true # continue even after exit code 1
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_mcu_connection_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function print_detected_mcu_to_screen() {
|
||||
local i=1
|
||||
|
||||
if (( ${#mcu_list[@]} < 1 )); then
|
||||
print_error "No MCU found!\n MCU eihter not connected or not detected!"
|
||||
return
|
||||
fi
|
||||
|
||||
for mcu in "${mcu_list[@]}"; do
|
||||
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
|
||||
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 3 =====================#
|
||||
#================================================#
|
||||
function select_mcu_id() {
|
||||
local i=0 sel_index=0 method=${1}
|
||||
|
||||
if (( ${#mcu_list[@]} < 1 )); then
|
||||
print_error "No MCU found!\n MCU eihter not connected or not detected!"
|
||||
return
|
||||
fi
|
||||
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${white} |"
|
||||
hr
|
||||
echo -e "| Make sure, to select the correct MCU! |"
|
||||
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### List of available MCU:${white}"
|
||||
|
||||
### list all mcus
|
||||
for mcu in "${mcu_list[@]}"; do
|
||||
i=$(( i + 1 ))
|
||||
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
|
||||
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
|
||||
done
|
||||
|
||||
### verify user input
|
||||
local regex="^[1-9]+$"
|
||||
while [[ ! ${sel_index} =~ ${regex} ]] || [[ ${sel_index} -gt ${i} ]]; do
|
||||
echo
|
||||
read -p "${cyan}###### Select MCU to flash:${white} " sel_index
|
||||
|
||||
if [[ ! ${sel_index} =~ ${regex} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
elif [[ ${sel_index} -lt 1 ]] || [[ ${sel_index} -gt ${i} ]]; then
|
||||
error_msg "Please select a number between 1 and ${i}!"
|
||||
fi
|
||||
|
||||
local mcu_index=$(( sel_index - 1 ))
|
||||
local selected_mcu_id="${mcu_list[${mcu_index}]}"
|
||||
done
|
||||
|
||||
### confirm selection
|
||||
local yn
|
||||
while true; do
|
||||
echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n"
|
||||
read -p "${cyan}###### Continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
status_msg "Flashing ${selected_mcu_id} ..."
|
||||
if [[ ${method} == "regular" ]]; then
|
||||
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
|
||||
start_flash_mcu "${selected_mcu_id}"
|
||||
elif [[ ${method} == "sdcard" ]]; then
|
||||
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
|
||||
start_flash_sd "${selected_mcu_id}"
|
||||
else
|
||||
print_error "No flash method set! Aborting..."
|
||||
log_error "No flash method set!"
|
||||
return
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function start_flash_mcu() {
|
||||
local device=${1}
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
if make flash FLASH_DEVICE="${device}"; then
|
||||
ok_msg "Flashing successfull!"
|
||||
else
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
fi
|
||||
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function start_flash_sd() {
|
||||
local i=0 board_list=() device=${1}
|
||||
local flash_script="${KLIPPER_DIR}/scripts/flash-sdcard.sh"
|
||||
|
||||
### write each supported board to the array to make it selectable
|
||||
for board in $("${flash_script}" -l | tail -n +2); do
|
||||
board_list+=("${board}")
|
||||
done
|
||||
|
||||
top_border
|
||||
echo -e "| Please select the type of board that corresponds to |"
|
||||
echo -e "| the currently selected MCU ID you chose before. |"
|
||||
blank_line
|
||||
echo -e "| The following boards are currently supported: |"
|
||||
hr
|
||||
### display all supported boards to the user
|
||||
for board in "${board_list[@]}"; do
|
||||
if [[ ${i} -lt 10 ]]; then
|
||||
printf "| ${i}) %-50s|\n" "${board_list[${i}]}"
|
||||
else
|
||||
printf "| ${i}) %-49s|\n" "${board_list[${i}]}"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
quit_footer
|
||||
|
||||
### make the user select one of the boards
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select board type:${white} " choice
|
||||
if [[ ${choice} = "q" || ${choice} = "Q" ]]; then
|
||||
clear && advanced_menu && break
|
||||
elif [[ ${choice} -le ${#board_list[@]} ]]; then
|
||||
local selected_board="${board_list[${choice}]}"
|
||||
break
|
||||
else
|
||||
clear && print_header
|
||||
error_msg "Invalid choice!"
|
||||
flash_mcu_sd
|
||||
fi
|
||||
done
|
||||
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| If your board is flashed with firmware that connects |"
|
||||
echo -e "| at a custom baud rate, please change it now. |"
|
||||
blank_line
|
||||
echo -e "| If you are unsure, stick to the default 250000! |"
|
||||
bottom_border
|
||||
|
||||
local baud_rate regex="^[0-9]+$"
|
||||
echo -e "${cyan}###### Please set the baud rate:${white} "
|
||||
while [[ ! ${baud_rate} =~ ${regex} ]]; do
|
||||
read -e -i "250000" -e baud_rate
|
||||
local selected_baud_rate=${baud_rate}
|
||||
break
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
###flash process
|
||||
do_action_service "stop" "klipper"
|
||||
if "${flash_script}" -b "${selected_baud_rate}" "${device}" "${selected_board}"; then
|
||||
print_confirm "Flashing successfull!"
|
||||
log_info "Flash successfull!"
|
||||
else
|
||||
print_error "Flashing failed!\n Please read the console output above!"
|
||||
log_error "Flash failed!"
|
||||
fi
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function build_fw() {
|
||||
local python_version
|
||||
|
||||
if [[ ! -d ${KLIPPER_DIR} || ! -d ${KLIPPY_ENV} ]]; then
|
||||
print_error "Klipper not found!\n Cannot build firmware without Klipper!"
|
||||
return
|
||||
fi
|
||||
|
||||
python_version=$(get_klipper_python_ver)
|
||||
|
||||
cd "${KLIPPER_DIR}"
|
||||
status_msg "Initializing firmware build ..."
|
||||
local dep=(build-essential dpkg-dev make)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
make clean
|
||||
|
||||
status_msg "Building firmware ..."
|
||||
if (( python_version == 3 )); then
|
||||
make PYTHON=python3 menuconfig
|
||||
make PYTHON=python3
|
||||
elif (( python_version == 2 )); then
|
||||
make PYTHON=python2 menuconfig
|
||||
make PYTHON=python2
|
||||
else
|
||||
warn_msg "Error reading Python version!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
ok_msg "Firmware built!"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_usb_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(find /dev/serial/by-id/* 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function get_uart_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty(AMA0|S0)$" 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function show_flash_method_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}Regular flashing method:${white} |"
|
||||
echo -e "| The default method to flash controller boards which |"
|
||||
echo -e "| are connected and updated over USB and not by placing |"
|
||||
echo -e "| a compiled firmware file onto an internal SD-Card. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that get flashed that way are: |"
|
||||
echo -e "| - Arduino Mega 2560 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}Updating via SD-Card Update:${white} |"
|
||||
echo -e "| Many popular controller boards ship with a bootloader |"
|
||||
echo -e "| capable of updating the firmware via SD-Card. |"
|
||||
echo -e "| Choose this method if your controller board supports |"
|
||||
echo -e "| this way of updating. This method ONLY works for up- |"
|
||||
echo -e "| grading firmware. The initial flashing procedure must |"
|
||||
echo -e "| be done manually per the instructions that apply to |"
|
||||
echo -e "| your controller board. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that can be flashed that way are: |"
|
||||
echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |"
|
||||
echo -e "| - Fysetc Spider |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
init_flash_process
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function show_mcu_connection_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}USB:${white} |"
|
||||
echo -e "| Selecting USB as the connection method will scan the |"
|
||||
echo -e "| USB ports for connected controller boards. This will |"
|
||||
echo -e "| be similar to the 'ls /dev/serial/by-id/*' command |"
|
||||
echo -e "| suggested by the official Klipper documentation for |"
|
||||
echo -e "| determining successfull USB connections! |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}UART:${white} |"
|
||||
echo -e "| Selecting UART as the connection method will list all |"
|
||||
echo -e "| possible UART serial ports. Note: This method ALWAYS |"
|
||||
echo -e "| returns something as it seems impossible to determine |"
|
||||
echo -e "| if a valid Klipper controller board is connected or |"
|
||||
echo -e "| not. Because of that, you ${red}MUST${white} know which UART serial |"
|
||||
echo -e "| port your controller board is connected to when using |"
|
||||
echo -e "| this connection method. |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
select_mcu_connection
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
421
scripts/fluidd.sh
Normal file
421
scripts/fluidd.sh
Normal file
@@ -0,0 +1,421 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================== INSTALL FLUIDD =================#
|
||||
#===================================================#
|
||||
|
||||
function install_fluidd() {
|
||||
### exit early if moonraker not found
|
||||
if [[ -z $(moonraker_systemd) ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### checking dependencies
|
||||
local dep=(wget nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
### detect conflicting Haproxy and Apache2 installations
|
||||
detect_conflicting_packages
|
||||
|
||||
status_msg "Initializing Fluidd installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
fluidd_port_check
|
||||
|
||||
### ask user to install mjpg-streamer
|
||||
local install_mjpg_streamer
|
||||
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Install MJGP-Streamer for webcam support? |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please select (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
install_mjpg_streamer="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
install_mjpg_streamer="false"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
### download fluidd
|
||||
download_fluidd
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
install_fluidd_macros
|
||||
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "fluidd"
|
||||
### nginx on ubuntu 21 and above needs special permissions to access the files
|
||||
set_nginx_permissions
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
|
||||
### add fluidd to the update manager in moonraker.conf
|
||||
patch_fluidd_update_manager
|
||||
|
||||
### install mjpg-streamer
|
||||
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
print_confirm "Fluidd has been set up!"
|
||||
}
|
||||
|
||||
function install_fluidd_macros() {
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to have some important macros in |"
|
||||
echo -e "| your printer configuration to have Fluidd fully |"
|
||||
echo -e "| functional and working. |"
|
||||
blank_line
|
||||
echo -e "| The recommended macros for Fluidd can be found here: |"
|
||||
echo -e "| https://docs.fluidd.xyz/configuration/initial_setup |"
|
||||
blank_line
|
||||
echo -e "| If you already have these macros in your config file, |"
|
||||
echo -e "| skip this step and answer with 'no'. |"
|
||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||
echo -e "| add the recommended example macros to your config. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
download_fluidd_macros
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
return
|
||||
}
|
||||
|
||||
function download_fluidd_macros() {
|
||||
local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg"
|
||||
local configs path
|
||||
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
|
||||
|
||||
if [[ -n ${configs} ]]; then
|
||||
for config in ${configs}; do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
if [[ ! -f "${path}/fluidd.cfg" ]]; then
|
||||
status_msg "Downloading fluidd.cfg to ${path} ..."
|
||||
log_info "downloading fluidd.cfg to: ${path}"
|
||||
wget "${fluidd_cfg}" -O "${path}/fluidd.cfg"
|
||||
|
||||
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
||||
log_info "modify fluidd.cfg"
|
||||
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg"
|
||||
|
||||
### write include to the very first line of the printer.cfg
|
||||
if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then
|
||||
log_info "modify printer.cfg"
|
||||
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log_error "execution stopped! reason: no printer.cfg found"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
function download_fluidd() {
|
||||
local url
|
||||
url=$(get_fluidd_download_url)
|
||||
|
||||
status_msg "Downloading Fluidd from ${url} ..."
|
||||
|
||||
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||
rm -rf "${FLUIDD_DIR}"
|
||||
fi
|
||||
|
||||
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
||||
|
||||
if wget "${url}"; then
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf ./*.zip && ok_msg "Done!"
|
||||
else
|
||||
print_error "Downloading Fluidd from\n ${url}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== REMOVE FLUIDD ==================#
|
||||
#===================================================#
|
||||
|
||||
function remove_fluidd_dir() {
|
||||
[[ ! -d ${FLUIDD_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Fluidd directory ..."
|
||||
rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_fluidd_config() {
|
||||
if [[ -e "/etc/nginx/sites-available/fluidd" ]]; then
|
||||
status_msg "Removing Fluidd configuration for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!"
|
||||
fi
|
||||
if [[ -L "/etc/nginx/sites-enabled/fluidd" ]]; then
|
||||
status_msg "Removing Fluidd Symlink for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd_logs() {
|
||||
local files
|
||||
files=$(find /var/log/nginx -name "fluidd*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
sudo rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd_log_symlinks() {
|
||||
local files
|
||||
files=$(find "${KLIPPER_LOGS}" -name "fluidd*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd() {
|
||||
remove_fluidd_dir
|
||||
remove_fluidd_config
|
||||
remove_fluidd_logs
|
||||
remove_fluidd_log_symlinks
|
||||
|
||||
### remove fluidd_port from ~/.kiauh.ini
|
||||
sed -i "/^fluidd_port=/d" "${INI_FILE}"
|
||||
|
||||
print_confirm "Fluidd successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== UPDATE FLUIDD ==================#
|
||||
#===================================================#
|
||||
|
||||
function update_fluidd() {
|
||||
backup_before_update "fluidd"
|
||||
status_msg "Updating Fluidd ..."
|
||||
download_fluidd
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
print_confirm "Fluidd successfully updated!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== FLUIDD STATUS ==================#
|
||||
#===================================================#
|
||||
|
||||
function get_fluidd_status() {
|
||||
local status
|
||||
local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd")
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_fluidd_version() {
|
||||
[[ ! -f "${FLUIDD_DIR}/.version" ]] && return
|
||||
|
||||
local version
|
||||
version=$(head -n 1 "${FLUIDD_DIR}/.version")
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function get_remote_fluidd_version() {
|
||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||
|
||||
local version
|
||||
version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev)
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function compare_fluidd_versions() {
|
||||
unset FLUIDD_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_fluidd_version)"
|
||||
remote_ver="$(get_remote_fluidd_version)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add fluidd to the update all array for the update all function in the updater
|
||||
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
FLUIDD_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_fluidd_download_url() {
|
||||
local tags latest_tag latest_url stable_tag stable_url url
|
||||
tags=$(curl -s "${FLUIDD_TAGS}" | grep "name" | cut -d'"' -f4)
|
||||
|
||||
### latest download url including pre-releases (alpha, beta, rc)
|
||||
latest_tag=$(echo "${tags}" | head -1)
|
||||
latest_url="https://github.com/fluidd-core/fluidd/releases/download/${latest_tag}/fluidd.zip"
|
||||
|
||||
### get stable fluidd download url
|
||||
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
|
||||
stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip"
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
if [[ ${fluidd_install_unstable} == "true" ]]; then
|
||||
url="${latest_url}"
|
||||
echo "${url}"
|
||||
else
|
||||
url="${stable_url}"
|
||||
echo "${url}"
|
||||
fi
|
||||
}
|
||||
|
||||
function fluidd_port_check() {
|
||||
if [[ ${FLUIDD_ENABLED} == "false" ]]; then
|
||||
|
||||
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
|
||||
[[ ${MAINSAIL_ENABLED} == "true" ]] && \
|
||||
echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}"
|
||||
|
||||
if [[ ${MAINSAIL_PORT} == "80" ]]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_fluidd_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
function select_fluidd_port() {
|
||||
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||
echo -e "| ${red}You need to choose a different port for Fluidd!${white} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||
blank_line
|
||||
[[ ${MAINSAIL_PORT} == "80" ]] && echo "| ● Mainsail |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which is already |"
|
||||
echo -e "| assigned to another webinterface! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
|
||||
local new_port re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||
if [[ ${new_port} =~ ${re} && ${new_port} != "${MAINSAIL_PORT}" ]]; then
|
||||
select_msg "Setting port ${new_port} for Fluidd!"
|
||||
SET_LISTEN_PORT=${new_port}
|
||||
break
|
||||
else
|
||||
if [[ ! ${new_port} =~ ${re} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
else
|
||||
error_msg "Port already taken! Select a different one!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function patch_fluidd_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager fluidd\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Fluidds update manager section to moonraker.conf
|
||||
status_msg "Adding Fluidd to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager fluidd]
|
||||
type: web
|
||||
channel: stable
|
||||
repo: fluidd-core/fluidd
|
||||
path: ~/fluidd
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -1,377 +0,0 @@
|
||||
# setting up some frequently used functions
|
||||
check_euid(){
|
||||
if [ "$EUID" -eq 0 ]
|
||||
then
|
||||
echo -e "${red}"
|
||||
top_border
|
||||
echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |"
|
||||
bottom_border
|
||||
echo -e "${default}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
locate_printer_cfg(){
|
||||
unset PRINTER_CFG
|
||||
if [ -e $KLIPPER_SERVICE2 ]; then
|
||||
status_msg "Locating printer.cfg via $KLIPPER_SERVICE2 ..."
|
||||
#reads /etc/default/klipper and gets the default printer.cfg location
|
||||
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)"
|
||||
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
|
||||
i=1
|
||||
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/default/klipper | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg")
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
elif [ -e $KLIPPER_SERVICE3 ]; then
|
||||
status_msg "Locating printer.cfg via $KLIPPER_SERVICE3 ..."
|
||||
#reads /etc/systemd/system/klipper.service and gets the default printer.cfg location
|
||||
KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)"
|
||||
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
|
||||
i=1
|
||||
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/systemd/system/klipper.service | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg")
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
else
|
||||
PRINTER_CFG=""
|
||||
warn_msg "Can't read printer.cfg location!"
|
||||
fi
|
||||
}
|
||||
|
||||
source_ini(){
|
||||
source ${SRCDIR}/kiauh/kiauh.ini
|
||||
}
|
||||
|
||||
start_klipper(){
|
||||
status_msg "Starting Klipper Service ..."
|
||||
sudo systemctl start klipper && ok_msg "Klipper Service started!"
|
||||
}
|
||||
|
||||
stop_klipper(){
|
||||
status_msg "Stopping Klipper Service ..."
|
||||
sudo systemctl stop klipper && ok_msg "Klipper Service stopped!"
|
||||
}
|
||||
|
||||
restart_klipper(){
|
||||
status_msg "Restarting Klipper Service ..."
|
||||
sudo systemctl restart klipper && ok_msg "Klipper Service restarted!"
|
||||
}
|
||||
|
||||
start_dwc(){
|
||||
status_msg "Starting DWC-for-Klipper-Socket Service ..."
|
||||
sudo systemctl start dwc && ok_msg "DWC-for-Klipper-Socket Service started!"
|
||||
}
|
||||
|
||||
stop_dwc(){
|
||||
status_msg "Stopping DWC-for-Klipper-Socket Service ..."
|
||||
sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!"
|
||||
}
|
||||
|
||||
start_moonraker(){
|
||||
status_msg "Starting Moonraker Service ..."
|
||||
sudo systemctl start moonraker && ok_msg "Moonraker Service started!"
|
||||
}
|
||||
|
||||
stop_moonraker(){
|
||||
status_msg "Stopping Moonraker Service ..."
|
||||
sudo systemctl stop moonraker && ok_msg "Moonraker Service stopped!"
|
||||
}
|
||||
|
||||
restart_moonraker(){
|
||||
status_msg "Restarting Moonraker Service ..."
|
||||
sudo systemctl restart moonraker && ok_msg "Moonraker Service restarted!"
|
||||
}
|
||||
|
||||
start_octoprint(){
|
||||
status_msg "Starting OctoPrint Service ..."
|
||||
sudo systemctl start octoprint && ok_msg "OctoPrint Service started!"
|
||||
}
|
||||
|
||||
stop_octoprint(){
|
||||
status_msg "Stopping OctoPrint Service ..."
|
||||
sudo systemctl stop octoprint && ok_msg "OctoPrint Service stopped!"
|
||||
}
|
||||
|
||||
restart_octoprint(){
|
||||
status_msg "Restarting OctoPrint Service ..."
|
||||
sudo systemctl restart octoprint && ok_msg "OctoPrint Service restarted!"
|
||||
}
|
||||
|
||||
enable_octoprint_service(){
|
||||
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
|
||||
status_msg "OctoPrint Service is disabled! Enabling now ..."
|
||||
sudo systemctl enable octoprint -q && sudo systemctl start octoprint
|
||||
fi
|
||||
}
|
||||
|
||||
disable_octoprint(){
|
||||
if [ "$DISABLE_OPRINT" = "true" ]; then
|
||||
disable_octoprint_service
|
||||
fi
|
||||
}
|
||||
|
||||
disable_octoprint_service(){
|
||||
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
|
||||
status_msg "OctoPrint Service is enabled! Disabling now ..."
|
||||
sudo systemctl stop octoprint && sudo systemctl disable octoprint -q
|
||||
fi
|
||||
}
|
||||
|
||||
toggle_octoprint_service(){
|
||||
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
|
||||
if systemctl is-enabled octoprint.service -q; then
|
||||
disable_octoprint_service
|
||||
sleep 2
|
||||
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
|
||||
else
|
||||
enable_octoprint_service
|
||||
sleep 2
|
||||
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
|
||||
fi
|
||||
else
|
||||
ERROR_MSG=" You cannot activate a service that does not exist!"
|
||||
fi
|
||||
}
|
||||
|
||||
read_octoprint_service_status(){
|
||||
if ! systemctl is-enabled octoprint.service -q &>/dev/null; then
|
||||
OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service "
|
||||
else
|
||||
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
|
||||
fi
|
||||
}
|
||||
|
||||
start_klipperscreen(){
|
||||
status_msg "Starting KlipperScreen Service ..."
|
||||
sudo systemctl start KlipperScreen && ok_msg "KlipperScreen Service started!"
|
||||
}
|
||||
|
||||
stop_klipperscreen(){
|
||||
status_msg "Stopping KlipperScreen Service ..."
|
||||
sudo systemctl stop KlipperScreen && ok_msg "KlipperScreen Service stopped!"
|
||||
}
|
||||
|
||||
restart_klipperscreen(){
|
||||
status_msg "Restarting KlipperScreen Service ..."
|
||||
sudo systemctl restart KlipperScreen && ok_msg "KlipperScreen Service restarted!"
|
||||
}
|
||||
|
||||
restart_nginx(){
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then
|
||||
status_msg "Restarting Nginx Service ..."
|
||||
sudo systemctl restart nginx && ok_msg "Nginx Service restarted!"
|
||||
fi
|
||||
}
|
||||
|
||||
dependency_check(){
|
||||
status_msg "Checking for the following dependencies:"
|
||||
#check if package is installed, if not write name into array
|
||||
for pkg in "${dep[@]}"
|
||||
do
|
||||
echo -e "${cyan}● $pkg ${default}"
|
||||
if [[ ! $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then
|
||||
inst+=($pkg)
|
||||
fi
|
||||
done
|
||||
#if array is not empty, install packages from array elements
|
||||
if [ "${#inst[@]}" != "0" ]; then
|
||||
status_msg "Installing the following dependencies:"
|
||||
for element in ${inst[@]}
|
||||
do
|
||||
echo -e "${cyan}● $element ${default}"
|
||||
done
|
||||
echo
|
||||
sudo apt-get install ${inst[@]} -y
|
||||
ok_msg "Dependencies installed!"
|
||||
#clearing the array
|
||||
unset inst
|
||||
else
|
||||
ok_msg "Dependencies already met! Continue..."
|
||||
fi
|
||||
}
|
||||
|
||||
print_error(){
|
||||
for data in "${data_arr[@]}"
|
||||
do
|
||||
if [ ! -e $data ]; then
|
||||
data_count+=(0)
|
||||
else
|
||||
data_count+=(1)
|
||||
fi
|
||||
done
|
||||
sum=$(IFS=+; echo "$((${data_count[*]}))")
|
||||
if [ $sum -eq 0 ]; then
|
||||
ERROR_MSG="Looks like $1 was already removed!\n Skipping..."
|
||||
else
|
||||
ERROR_MSG=""
|
||||
fi
|
||||
}
|
||||
|
||||
setup_gcode_shell_command(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| You are about to install the G-Code Shell Command |"
|
||||
echo -e "| extension. Please make sure to read the instructions |"
|
||||
echo -e "| before you continue and remember that potential risks |"
|
||||
echo -e "| can be involved after installing this extension! |"
|
||||
blank_line
|
||||
echo -e "| ${red}You accept that you are doing this on your own risk!${default} |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
if [ -d $KLIPPER_DIR/klippy/extras ]; then
|
||||
status_msg "Installing gcode shell command extension ..."
|
||||
status_msg "Copy gcode_shell_command.py to '$KLIPPER_DIR/klippy/extras' ..."
|
||||
if [ -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py ]; then
|
||||
warn_msg "There is already a file named 'gcode_shell_command.py'"
|
||||
warn_msg "in the destination location!"
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
rm -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py
|
||||
install_gcode_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
install_gcode_shell_command
|
||||
fi
|
||||
else
|
||||
ERROR_MSG="Folder ~/klipper/klippy/extras not found!"
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
install_gcode_shell_command(){
|
||||
stop_klipper
|
||||
status_msg "Copy 'gcode_shell_command.py' to $KLIPPER_DIR/klippy/extras"
|
||||
cp ${HOME}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
|
||||
echo
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
ADD_SHELL_CMD_MACRO="true"
|
||||
status_msg "Creating example macro ..."
|
||||
locate_printer_cfg
|
||||
read_printer_cfg "gcode_shell_command"
|
||||
write_printer_cfg
|
||||
ok_msg "Example macro created!"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
ok_msg "Shell command extension installed!"
|
||||
restart_klipper
|
||||
}
|
||||
|
||||
create_minimal_cfg(){
|
||||
#create a minimal default config
|
||||
if [ "$SEL_DEF_CFG" = "true" ]; then
|
||||
cat <<- EOF >> $PRINTER_CFG
|
||||
[mcu]
|
||||
serial: </dev/serial/by-id/your-mcu>
|
||||
|
||||
[printer]
|
||||
kinematics: none
|
||||
max_velocity: 1
|
||||
max_accel: 1
|
||||
|
||||
[virtual_sdcard]
|
||||
path: ~/sdcard
|
||||
|
||||
[pause_resume]
|
||||
[display_status]
|
||||
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
|
||||
#Klipper webui related config options
|
||||
if [ "$WEBUI_MACROS" = "false" ] && [ "$ADD_WEBUI_MACROS" = "true" ] && [[ ! $(grep '^\[include webui_macros.cfg]$' $KIAUH_CFG) ]]; then
|
||||
echo -e "\n[include webui_macros.cfg]" >> $KIAUH_CFG
|
||||
fi
|
||||
#G-Code Shell Command extension related config options
|
||||
if [ "$ADD_SHELL_CMD_MACRO" = "true" ] && [[ ! $(grep '^\[gcode_shell_command hello_world]$' $KIAUH_CFG) ]]; then
|
||||
cat <<-EOF >> $KIAUH_CFG
|
||||
[gcode_shell_command hello_world]
|
||||
command: echo hello world
|
||||
timeout: 2.
|
||||
verbose: True
|
||||
[gcode_macro HELLO_WORLD]
|
||||
gcode:
|
||||
RUN_SHELL_COMMAND CMD=hello_world
|
||||
EOF
|
||||
fi
|
||||
#including the kiauh.cfg into printer.cfg if not already done
|
||||
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(){
|
||||
if [ ! -f $INI_FILE ]; then
|
||||
echo -e "#don't edit this file if you don't know what you are doing...\c" > $INI_FILE
|
||||
fi
|
||||
if [ ! $(grep -E "^backup_before_update=." $INI_FILE) ]; then
|
||||
echo -e "\nbackup_before_update=false\c" >> $INI_FILE
|
||||
fi
|
||||
if [ ! $(grep -E "^previous_origin_state=[[:alnum:]]" $INI_FILE) ]; then
|
||||
echo -e "\nprevious_origin_state=0\c" >> $INI_FILE
|
||||
fi
|
||||
if [ ! $(grep -E "^previous_smoothing_state=[[:alnum:]]" $INI_FILE) ]; then
|
||||
echo -e "\nprevious_smoothing_state=0\c" >> $INI_FILE
|
||||
fi
|
||||
if [ ! $(grep -E "^previous_shaping_state=[[:alnum:]]" $INI_FILE) ]; then
|
||||
echo -e "\nprevious_shaping_state=0\c" >> $INI_FILE
|
||||
fi
|
||||
if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then
|
||||
echo -e "\nlogupload_accepted=false\c" >> $INI_FILE
|
||||
fi
|
||||
}
|
||||
122
scripts/gcode_shell_command.sh
Normal file
122
scripts/gcode_shell_command.sh
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#======== INSTALL GCODE_SHELL_COMMAND.PY =========#
|
||||
#=================================================#
|
||||
|
||||
function setup_gcode_shell_command() {
|
||||
top_border
|
||||
echo -e "| You are about to install the 'G-Code Shell Command' |"
|
||||
echo -e "| extension. Please make sure to read the instructions |"
|
||||
echo -e "| before you continue and remember that potential risks |"
|
||||
echo -e "| can be involved after installing this extension! |"
|
||||
blank_line
|
||||
echo -e "| ${red}You accept that you are doing this on your own risk!${white} |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
|
||||
if [[ ! -d "${KLIPPER_DIR}/klippy/extras" ]]; then
|
||||
print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Installing gcode shell command extension ..."
|
||||
|
||||
if [[ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]]; then
|
||||
install_gcode_shell_command
|
||||
else
|
||||
echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!"
|
||||
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py"
|
||||
install_gcode_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
return;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function install_gcode_shell_command() {
|
||||
do_action_service "stop" "klipper"
|
||||
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
|
||||
|
||||
if cp "${KIAUH_SRCDIR}/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then
|
||||
ok_msg "Done!"
|
||||
else
|
||||
error_msg "Cannot copy file to target destination...Exiting!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
create_example_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
do_action_service "restart" "klipper"
|
||||
print_confirm "Shell command extension installed!"
|
||||
return
|
||||
}
|
||||
|
||||
function create_example_shell_command() {
|
||||
### create a backup of the config folder
|
||||
backup_klipper_config_dir
|
||||
|
||||
local printer_cfgs path
|
||||
printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg" | sort)
|
||||
|
||||
for cfg in ${printer_cfgs}; do
|
||||
path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev)
|
||||
|
||||
if [[ ! -f "${path}/shell_command.cfg" ]]; then
|
||||
status_msg "Copy shell_command.cfg to ${path} ..."
|
||||
cp "${KIAUH_SRCDIR}/resources/shell_command.cfg" "${path}"
|
||||
ok_msg "${path}/shell_command.cfg created!"
|
||||
### write include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include shell_command.cfg]" "${cfg}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
73
scripts/globals.sh
Normal file
73
scripts/globals.sh
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
set -e
|
||||
|
||||
function set_globals() {
|
||||
#=================== SYSTEM ===================#
|
||||
SYSTEMD="/etc/systemd/system"
|
||||
INITD="/etc/init.d"
|
||||
ETCDEF="/etc/default"
|
||||
|
||||
#=================== KIAUH ====================#
|
||||
green=$(echo -en "\e[92m")
|
||||
yellow=$(echo -en "\e[93m")
|
||||
magenta=$(echo -en "\e[35m")
|
||||
red=$(echo -en "\e[91m")
|
||||
cyan=$(echo -en "\e[96m")
|
||||
white=$(echo -en "\e[39m")
|
||||
INI_FILE="${HOME}/.kiauh.ini"
|
||||
LOGFILE="/tmp/kiauh.log"
|
||||
RESOURCES="${KIAUH_SRCDIR}/resources"
|
||||
BACKUP_DIR="${HOME}/kiauh-backups"
|
||||
|
||||
#================== KLIPPER ===================#
|
||||
KLIPPY_ENV="${HOME}/klippy-env"
|
||||
KLIPPER_DIR="${HOME}/klipper"
|
||||
KLIPPER_REPO="https://github.com/Klipper3d/klipper.git"
|
||||
KLIPPER_LOGS="${HOME}/klipper_logs"
|
||||
KLIPPER_CONFIG="$(get_klipper_cfg_dir)" # default: ${HOME}/klipper_config
|
||||
|
||||
#================= MOONRAKER ==================#
|
||||
MOONRAKER_ENV="${HOME}/moonraker-env"
|
||||
MOONRAKER_DIR="${HOME}/moonraker"
|
||||
MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
|
||||
|
||||
#================= MAINSAIL ===================#
|
||||
MAINSAIL_DIR="${HOME}/mainsail"
|
||||
MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases"
|
||||
MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags"
|
||||
|
||||
#================== FLUIDD ====================#
|
||||
FLUIDD_DIR="${HOME}/fluidd"
|
||||
FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases"
|
||||
FLUIDD_TAGS="https://api.github.com/repos/fluidd-core/fluidd/tags"
|
||||
|
||||
#=============== KLIPPERSCREEN ================#
|
||||
KLIPPERSCREEN_ENV="${HOME}/.KlipperScreen-env"
|
||||
KLIPPERSCREEN_DIR="${HOME}/KlipperScreen"
|
||||
KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git"
|
||||
|
||||
#========== MOONRAKER-TELEGRAM-BOT ============#
|
||||
TELEGRAM_BOT_ENV="${HOME}/moonraker-telegram-bot-env"
|
||||
TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot"
|
||||
TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git"
|
||||
|
||||
#=============== PRETTY-GCODE =================#
|
||||
PGC_DIR="${HOME}/pgcode"
|
||||
PGC_REPO="https://github.com/Kragrathea/pgcode"
|
||||
|
||||
#================== NGINX =====================#
|
||||
NGINX_SA="/etc/nginx/sites-available"
|
||||
NGINX_SE="/etc/nginx/sites-enabled"
|
||||
NGINX_CONFD="/etc/nginx/conf.d"
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
install_dwc2(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
system_check_dwc2
|
||||
#check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
#ask user for customization
|
||||
get_user_selections_dwc2
|
||||
#dwc2 main installation
|
||||
stop_klipper
|
||||
dwc2_setup
|
||||
#setup config
|
||||
setup_printer_config_dwc2
|
||||
#execute customizations
|
||||
disable_octoprint
|
||||
set_nginx_cfg "dwc2"
|
||||
set_hostname
|
||||
#after install actions
|
||||
restart_klipper
|
||||
else
|
||||
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
system_check_dwc2(){
|
||||
status_msg "Initializing DWC2 installation ..."
|
||||
#check for existing printer.cfg
|
||||
locate_printer_cfg
|
||||
if [ -f $PRINTER_CFG ]; then
|
||||
PRINTER_CFG_FOUND="true"
|
||||
else
|
||||
PRINTER_CFG_FOUND="false"
|
||||
fi
|
||||
#check if octoprint is installed
|
||||
if systemctl is-enabled octoprint.service -q 2>/dev/null; then
|
||||
OCTOPRINT_ENABLED="true"
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selections_dwc2(){
|
||||
#let user choose to install systemd or init.d service
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Do you want to install dwc2-for-klipper-socket as |"
|
||||
echo -e "| 1) Init.d Service (default) |"
|
||||
echo -e "| 2) Systemd Service |"
|
||||
hr
|
||||
echo -e "| Please use the appropriate option for your chosen |"
|
||||
echo -e "| Linux distribution. If you are unsure what to select, |"
|
||||
echo -e "| please do a research before. |"
|
||||
hr
|
||||
echo -e "| If you run Raspberry Pi OS, both options will work. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please choose:${default} " action
|
||||
case "$action" in
|
||||
1|"")
|
||||
echo -e "###### > 1) Init.d"
|
||||
INST_DWC2_INITD="true"
|
||||
INST_DWC2_SYSTEMD="false"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > 1) Systemd"
|
||||
INST_DWC2_INITD="false"
|
||||
INST_DWC2_SYSTEMD="true"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
#user selection for printer.cfg
|
||||
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |"
|
||||
hr
|
||||
echo -e "| KIAUH can create a minimal printer.cfg with only the |"
|
||||
echo -e "| necessary config entries if you wish. |"
|
||||
echo -e "| |"
|
||||
echo -e "| Please be aware, that this option will ${red}NOT${default} create a |"
|
||||
echo -e "| fully working printer.cfg for you! |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Create a default printer.cfg? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
SEL_DEF_CFG="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
SEL_DEF_CFG="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
#ask user to install reverse proxy
|
||||
dwc2_reverse_proxy_dialog
|
||||
#ask to change hostname
|
||||
[ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname
|
||||
#ask user to disable octoprint when such installed service was found
|
||||
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
|
||||
while true; do
|
||||
echo
|
||||
warn_msg "OctoPrint service found!"
|
||||
echo -e "You might consider disabling the OctoPrint service,"
|
||||
echo -e "since an active OctoPrint service may lead to unexpected"
|
||||
echo -e "behavior of the DWC2 Webinterface."
|
||||
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
DISABLE_OPRINT="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
DISABLE_OPRINT="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
status_msg "Installation will start now! Please wait ..."
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
get_dwc2_ver(){
|
||||
DWC2_VERSION=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4)
|
||||
}
|
||||
|
||||
dwc2_setup(){
|
||||
#check dependencies
|
||||
dep=(git wget gzip tar curl)
|
||||
dependency_check
|
||||
#get dwc2-for-klipper
|
||||
status_msg "Cloning DWC2-for-Klipper-Socket repository ..."
|
||||
cd ${HOME} && git clone $DWC2FK_REPO
|
||||
ok_msg "DWC2-for-Klipper successfully cloned!"
|
||||
#copy installers from kiauh srcdir to dwc-for-klipper-socket
|
||||
status_msg "Copy installers to $DWC2FK_DIR"
|
||||
cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts
|
||||
ok_msg "Done!"
|
||||
status_msg "Starting service-installer ..."
|
||||
if [ "$INST_DWC2_INITD" = "true" ]; then
|
||||
$DWC2FK_DIR/scripts/install-octopi.sh
|
||||
elif [ "$INST_DWC2_SYSTEMD" = "true" ]; then
|
||||
$DWC2FK_DIR/scripts/install-debian.sh
|
||||
fi
|
||||
ok_msg "Service installed!"
|
||||
#patch /etc/default/klipper to append the uds argument
|
||||
patch_klipper_sysfile "dwc2"
|
||||
#download Duet Web Control
|
||||
download_dwc2_webui
|
||||
}
|
||||
|
||||
download_dwc2_webui(){
|
||||
#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
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Unzipping archive ..."
|
||||
unzip -q -o *.zip
|
||||
for f_ in $(find . | grep '.gz')
|
||||
do
|
||||
gunzip -f ${f_}
|
||||
done
|
||||
ok_msg "Done!"
|
||||
status_msg "Writing DWC version to file ..."
|
||||
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/version
|
||||
ok_msg "Done!"
|
||||
status_msg "Do a little cleanup ..."
|
||||
rm -rf DuetWebControl-SD.zip
|
||||
ok_msg "Done!"
|
||||
ok_msg "DWC2 Web UI installed!"
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
setup_printer_config_dwc2(){
|
||||
if [ "$PRINTER_CFG_FOUND" = "true" ]; then
|
||||
#check printer.cfg for necessary dwc2 entries
|
||||
read_printer_cfg "dwc2" && write_printer_cfg
|
||||
fi
|
||||
if [ "$SEL_DEF_CFG" = "true" ]; then
|
||||
status_msg "Creating minimal default printer.cfg ..."
|
||||
create_minimal_cfg
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
dwc2_reverse_proxy_dialog(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| If you want to have a nicer URL or simply need/want | "
|
||||
echo -e "| DWC2 to run on port 80 (http's default port) you | "
|
||||
echo -e "| can set up a reverse proxy to run DWC2 on port 80. | "
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to set up a reverse proxy now? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
dwc2_port_check
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
dwc2_port_check(){
|
||||
if [ "$DWC2_ENABLED" = "false" ]; then
|
||||
if [ "$SITE_ENABLED" = "true" ]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
[ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port:$OCTOPRINT_PORT${default}"
|
||||
[ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}"
|
||||
[ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}"
|
||||
if [ "$MAINSAIL_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_dwc2_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/dwc2_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=$DEFAULT_PORT
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
select_dwc2_port(){
|
||||
if [ "$PORT_80_BLOCKED" = "true" ]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${default} |"
|
||||
echo -e "| ${red}You need to choose a different port for DWC2!${default} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${default} |"
|
||||
blank_line
|
||||
[ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |"
|
||||
[ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |"
|
||||
[ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to one of the other web interfaces! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT
|
||||
if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then
|
||||
echo "Setting port $NEW_PORT for DWC2!"
|
||||
SET_LISTEN_PORT=$NEW_PORT
|
||||
break
|
||||
else
|
||||
echo "That port is already taken! Select a different one!"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
install_klipper(){
|
||||
if [ -e $KLIPPER_SERVICE1 ] && [ -e $KLIPPER_SERVICE2 ] || [ -e $KLIPPER_SERVICE3 ]; then
|
||||
ERROR_MSG="Looks like Klipper is already installed!"
|
||||
else
|
||||
get_user_selections_klipper
|
||||
klipper_setup
|
||||
build_fw
|
||||
flash_mcu
|
||||
write_printer_usb
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selections_klipper(){
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
#let user choose to install systemd or init.d service
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Do you want to install Klipper as: |"
|
||||
echo -e "| 1) Init.d Service (default) |"
|
||||
echo -e "| 2) Systemd Service |"
|
||||
hr
|
||||
echo -e "| Please use the appropriate option for your chosen |"
|
||||
echo -e "| Linux distribution. If you are unsure what to select, |"
|
||||
echo -e "| please do some research before. |"
|
||||
hr
|
||||
echo -e "| If you run Raspberry Pi OS, both options will work. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please choose:${default} " action
|
||||
case "$action" in
|
||||
1|"")
|
||||
echo -e "###### > 1) Init.d"
|
||||
INST_KLIPPER_INITD="true"
|
||||
INST_KLIPPER_SYSTEMD="false"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > 2) Systemd"
|
||||
INST_KLIPPER_INITD="false"
|
||||
INST_KLIPPER_SYSTEMD="true"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
#ask user for building firmware
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want to build the Firmware? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
BUILD_FIRMWARE="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
BUILD_FIRMWARE="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
#ask user for flashing mcu
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want to flash your MCU? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
FLASH_FIRMWARE="true"
|
||||
flash_routine
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
FLASH_FIRMWARE="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
klipper_setup(){
|
||||
#check for dependencies
|
||||
dep=(git dbus)
|
||||
dependency_check
|
||||
#execute operation
|
||||
cd ${HOME}
|
||||
status_msg "Cloning Klipper repository ..."
|
||||
git clone $KLIPPER_REPO
|
||||
ok_msg "Klipper successfully cloned!"
|
||||
status_msg "Installing Klipper Service ..."
|
||||
if [ "$INST_KLIPPER_INITD" = "true" ]; then
|
||||
$KLIPPER_DIR/scripts/install-octopi.sh
|
||||
elif [ "$INST_KLIPPER_SYSTEMD" = "true" ]; then
|
||||
$KLIPPER_DIR/scripts/install-debian.sh
|
||||
fi
|
||||
ok_msg "Klipper installation complete!"
|
||||
}
|
||||
|
||||
flash_routine(){
|
||||
if [ "$FLASH_FIRMWARE" = "true" ]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
||||
hr
|
||||
echo -e "| Flashing a Smoothie based board with this script will |"
|
||||
echo -e "| certainly fail. This applies to boards like the BTT |"
|
||||
echo -e "| SKR V1.3 or SKR V1.4(Turbo). You have to copy the |"
|
||||
echo -e "| firmware file to the microSD card manually and rename |"
|
||||
echo -e "| 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"
|
||||
CONFIRM_FLASHING="true"
|
||||
CONFIRM_WRITE_PRINTER_USB="true"
|
||||
get_printer_usb
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
CONFIRM_FLASHING="false"
|
||||
CONFIRM_WRITE_PRINTER_USB="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
flash_mcu(){
|
||||
if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then
|
||||
stop_klipper
|
||||
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
start_klipper
|
||||
fi
|
||||
}
|
||||
|
||||
build_fw(){
|
||||
if [ "$BUILD_FIRMWARE" = "true" ]; then
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Initializing Firmware Setup ..."
|
||||
make menuconfig
|
||||
status_msg "Building Firmware ..."
|
||||
make clean && make && ok_msg "Firmware built!"
|
||||
else
|
||||
warn_msg "Can not build Firmware without a Klipper directory!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
### grab the printers id
|
||||
get_printer_usb(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Please make sure your printer is connected to the Pi! |"
|
||||
echo -e "| If the printer is not connected yet, connect it now. |"
|
||||
hr
|
||||
echo -e "| Also make sure, that it is the only USB device |"
|
||||
echo -e "| connected at for now! Otherwise this step may fail! |"
|
||||
bottom_border
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Press any key to continue ... " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
*)
|
||||
CONFIRM_PRINTER_USB="true"
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
status_msg "Identifying the correct USB port ..."
|
||||
sleep 2
|
||||
unset PRINTER_USB
|
||||
if [ -e /dev/serial/by-id/* ]; then
|
||||
if [ -e /dev/serial/by-id/* ]; then
|
||||
PRINTER_USB=$(ls /dev/serial/by-id/*)
|
||||
status_msg "The ID of your printer is:"
|
||||
title_msg "$PRINTER_USB"
|
||||
else
|
||||
warn_msg "Could not retrieve ID!"
|
||||
fi
|
||||
elif [ -e /dev/serial/by-path/* ]; then
|
||||
if [ -e /dev/serial/by-path/* ]; then
|
||||
PRINTER_USB=$(ls /dev/serial/by-path/*)
|
||||
status_msg "The path of your printer is:"
|
||||
title_msg "$PRINTER_USB"
|
||||
else
|
||||
warn_msg "Could not retrieve path!"
|
||||
fi
|
||||
else
|
||||
warn_msg "Printer not plugged in or not detectable!"
|
||||
fi
|
||||
}
|
||||
|
||||
write_printer_usb(){
|
||||
locate_printer_cfg
|
||||
if [ ! -z "$PRINTER_CFG" ] && [ "$CONFIRM_WRITE_PRINTER_USB" = "true" ]; then
|
||||
SERIAL_OLD=$(grep "serial" $PRINTER_CFG | tail -1 | cut -d" " -f2)
|
||||
SERIAL_NEW=$PRINTER_USB
|
||||
if [ "$SERIAL_OLD" != "$SERIAL_NEW" ]; then
|
||||
unset write_entries
|
||||
backup_printer_cfg
|
||||
write_entries+=("[mcu]\nserial: $SERIAL_NEW")
|
||||
write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################")
|
||||
write_entries=("############################\n" "${write_entries[@]}")
|
||||
#check for a SAVE_CONFIG entry
|
||||
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
|
||||
if [[ $(grep "$SC" $PRINTER_CFG) ]]; then
|
||||
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
|
||||
PRE_SC_LINE=$(expr $SC_LINE - 1)
|
||||
SC_ENTRY="true"
|
||||
else
|
||||
SC_ENTRY="false"
|
||||
fi
|
||||
status_msg "Writing printer ID/path to printer.cfg ..."
|
||||
if [ "$SC_ENTRY" = "true" ]; then
|
||||
PRE_SC_LINE="$(expr $SC_LINE - 1)a"
|
||||
for entry in "${write_entries[@]}"
|
||||
do
|
||||
sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG
|
||||
done
|
||||
fi
|
||||
if [ "$SC_ENTRY" = "false" ]; then
|
||||
LINE_COUNT="$(wc -l < $PRINTER_CFG)a"
|
||||
for entry in "${write_entries[@]}"
|
||||
do
|
||||
sed -i "$LINE_COUNT $entry" $PRINTER_CFG
|
||||
done
|
||||
fi
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
check_moonraker(){
|
||||
status_msg "Checking for Moonraker service ..."
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then
|
||||
ok_msg "Moonraker service found!"; echo
|
||||
MOONRAKER_SERVICE_FOUND="true"
|
||||
else
|
||||
warn_msg "Moonraker service not found!"
|
||||
warn_msg "Please install Moonraker first!"; echo
|
||||
MOONRAKER_SERVICE_FOUND="false"
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selection_webui(){
|
||||
#ask user for webui default macros
|
||||
while true; do
|
||||
unset ADD_WEBUI_MACROS
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to have some important macros to |"
|
||||
echo -e "| have full functionality of the web interface. |"
|
||||
blank_line
|
||||
echo -e "| If you do not have such macros, you can choose to |"
|
||||
echo -e "| install the suggested default macros now. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
ADD_WEBUI_MACROS="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
ADD_WEBUI_MACROS="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
install_mainsail(){
|
||||
get_user_selection_webui
|
||||
#check if moonraker is already installed
|
||||
check_moonraker
|
||||
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
||||
#check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
#check if another site already listens to port 80
|
||||
mainsail_port_check
|
||||
#creating the mainsail nginx cfg
|
||||
set_nginx_cfg "mainsail"
|
||||
#test_nginx "$SET_LISTEN_PORT"
|
||||
locate_printer_cfg && read_printer_cfg "mainsail"
|
||||
install_webui_macros
|
||||
mainsail_setup
|
||||
fi
|
||||
}
|
||||
|
||||
install_fluidd(){
|
||||
get_user_selection_webui
|
||||
#check if moonraker is already installed
|
||||
check_moonraker
|
||||
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
||||
#check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
#check if another site already listens to port 80
|
||||
fluidd_port_check
|
||||
#creating the fluidd nginx cfg
|
||||
set_nginx_cfg "fluidd"
|
||||
#test_nginx "$SET_LISTEN_PORT"
|
||||
locate_printer_cfg && read_printer_cfg "fluidd"
|
||||
install_webui_macros
|
||||
fluidd_setup
|
||||
fi
|
||||
}
|
||||
|
||||
install_webui_macros(){
|
||||
#copy webui_macros.cfg
|
||||
if [ "$ADD_WEBUI_MACROS" = "true" ]; then
|
||||
status_msg "Create webui_macros.cfg ..."
|
||||
if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then
|
||||
cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config
|
||||
ok_msg "File created!"
|
||||
else
|
||||
warn_msg "File already exists! Skipping ..."
|
||||
fi
|
||||
fi
|
||||
write_printer_cfg
|
||||
}
|
||||
|
||||
mainsail_port_check(){
|
||||
if [ "$MAINSAIL_ENABLED" = "false" ]; then
|
||||
if [ "$SITE_ENABLED" = "true" ]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
[ "$OCTOPRINT_ENABLED" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: $OCTOPRINT_PORT${default}"
|
||||
[ "$FLUIDD_ENABLED" = "true" ] && echo -e " ${cyan}● Fluidd - Port: $FLUIDD_PORT${default}"
|
||||
[ "$DWC2_ENABLED" = "true" ] && echo -e " ${cyan}● DWC2 - Port: $DWC2_PORT${default}"
|
||||
if [ "$FLUIDD_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_mainsail_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/mainsail_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=$DEFAULT_PORT
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
fluidd_port_check(){
|
||||
if [ "$FLUIDD_ENABLED" = "false" ]; then
|
||||
if [ "$SITE_ENABLED" = "true" ]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
[ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port: $OCTOPRINT_PORT${default}"
|
||||
[ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port: $MAINSAIL_PORT${default}"
|
||||
[ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port: $DWC2_PORT${default}"
|
||||
if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_fluidd_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/fluidd_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=$DEFAULT_PORT
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
select_mainsail_port(){
|
||||
if [ "$PORT_80_BLOCKED" = "true" ]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${default} |"
|
||||
echo -e "| ${red}You need to choose a different port for Mainsail!${default} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${default} |"
|
||||
blank_line
|
||||
[ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |"
|
||||
[ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |"
|
||||
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to one of the other web interfaces! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT
|
||||
if [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then
|
||||
echo "Setting port $NEW_PORT for Mainsail!"
|
||||
SET_LISTEN_PORT=$NEW_PORT
|
||||
break
|
||||
else
|
||||
echo "That port is already taken! Select a different one!"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
select_fluidd_port(){
|
||||
if [ "$PORT_80_BLOCKED" = "true" ]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${default} |"
|
||||
echo -e "| ${red}You need to choose a different port for Fluidd!${default} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${default} |"
|
||||
blank_line
|
||||
[ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |"
|
||||
[ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |"
|
||||
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to one of the other web interfaces! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT
|
||||
if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then
|
||||
echo "Setting port $NEW_PORT for Fluidd!"
|
||||
SET_LISTEN_PORT=$NEW_PORT
|
||||
break
|
||||
else
|
||||
echo "That port is already taken! Select a different one!"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
get_mainsail_ver(){
|
||||
MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/releases | grep tag_name | cut -d'"' -f4 | cut -d"v" -f2 | head -1)
|
||||
}
|
||||
|
||||
get_fluidd_ver(){
|
||||
FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | cut -d"v" -f2 | head -1)
|
||||
}
|
||||
|
||||
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)
|
||||
#clean up an existing mainsail folder
|
||||
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
|
||||
#create fresh mainsail folder and download mainsail
|
||||
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
|
||||
status_msg "Downloading Mainsail $MAINSAIL_VERSION ..."
|
||||
wget $MAINSAIL_DL_URL && ok_msg "Download complete!"
|
||||
#extract archive
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o *.zip && ok_msg "Done!"
|
||||
#delete downloaded zip
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf *.zip && ok_msg "Done!" && ok_msg "Mainsail installation complete!"
|
||||
echo
|
||||
}
|
||||
|
||||
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)
|
||||
#clean up an existing fluidd folder
|
||||
[ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR
|
||||
#create fresh fluidd folder and download fluidd
|
||||
mkdir $FLUIDD_DIR && cd $FLUIDD_DIR
|
||||
status_msg "Downloading Fluidd $FLUIDD_VERSION ..."
|
||||
wget $FLUIDD_DL_URL && ok_msg "Download complete!"
|
||||
#extract archive
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o *.zip && ok_msg "Done!"
|
||||
#patch moonraker.conf to apply cors domains if needed
|
||||
backup_moonraker_conf
|
||||
patch_moonraker
|
||||
#delete downloaded zip
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!"
|
||||
echo
|
||||
}
|
||||
|
||||
patch_moonraker(){
|
||||
status_msg "Patching moonraker.conf ..."
|
||||
mr_conf=${HOME}/moonraker.conf
|
||||
# remove the now deprecated enable_cors option from moonraker.conf if it still exists
|
||||
if [ "$(grep "^enable_cors:" $mr_conf)" ]; then
|
||||
line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d"
|
||||
sed -i "$line" $mr_conf && mr_restart="true"
|
||||
fi
|
||||
# looking for a cors_domain entry in moonraker.conf
|
||||
if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then
|
||||
#find trusted_clients line number and subtract one, to insert cors_domains later
|
||||
line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i"
|
||||
sed -i "$line cors_domains:" $mr_conf && mr_restart="true"
|
||||
fi
|
||||
if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then
|
||||
hostname=$(hostname -I | cut -d" " -f1)
|
||||
url1="\ \ \ \ http://*.local"
|
||||
url2="\ \ \ \ http://app.fluidd.xyz"
|
||||
url3="\ \ \ \ https://app.fluidd.xyz"
|
||||
url4="\ \ \ \ http://$hostname:*"
|
||||
#find cors_domains line number and add one, to insert urls later
|
||||
line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i"
|
||||
[ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true"
|
||||
[ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true"
|
||||
[ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true"
|
||||
[ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true"
|
||||
fi
|
||||
#restart moonraker service if mr_restart was set to true
|
||||
if [[ $mr_restart == "true" ]]; then
|
||||
ok_msg "Patching done!" && restart_moonraker
|
||||
else
|
||||
ok_msg "No patching was needed!"
|
||||
fi
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
install_klipperscreen(){
|
||||
python3_check
|
||||
if [ $py_chk_ok = "true" ]; then
|
||||
system_check_klipperscreen
|
||||
#ask user for customization
|
||||
get_user_selections_klipperscreen
|
||||
#KlipperScreen main installation
|
||||
klipperscreen_setup
|
||||
#execute customizations
|
||||
symlinks_klipperscreen
|
||||
#after install actions
|
||||
restart_klipperscreen
|
||||
else
|
||||
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
|
||||
print_msg && clear_msg
|
||||
fi
|
||||
}
|
||||
|
||||
python3_check(){
|
||||
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!"
|
||||
py_chk_ok="true"
|
||||
else
|
||||
py_chk_ok="false"
|
||||
fi
|
||||
}
|
||||
|
||||
system_check_klipperscreen(){
|
||||
if [ ! -e ${HOME}/klipper_config/KlipperScreen.log ]; then
|
||||
KLIPPERSCREEN_SL_FOUND="false"
|
||||
else
|
||||
KLIPPERSCREEN_SL_FOUND="true"
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selections_klipperscreen(){
|
||||
#user selection for KlipperScreen.log symlink
|
||||
if [ "$KLIPPERSCREEN_SL_FOUND" = "false" ]; then
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Create KlipperScreen.log symlink? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
SEL_KSLOG_SL="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
SEL_KSLOG_SL="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
klipperscreen_setup(){
|
||||
dep=(wget curl unzip dfu-util)
|
||||
dependency_check
|
||||
status_msg "Downloading KlipperScreen ..."
|
||||
#force remove existing KlipperScreen dir
|
||||
[ -d $KLIPPERSCREEN_DIR ] && rm -rf $KLIPPERSCREEN_DIR
|
||||
#clone into fresh KlipperScreen dir
|
||||
cd ${HOME} && git clone $KLIPPERSCREEN_REPO
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Installing KlipperScreen ..."
|
||||
$KLIPPERSCREEN_DIR/scripts/KlipperScreen-install.sh
|
||||
echo; ok_msg "KlipperScreen successfully installed!"
|
||||
}
|
||||
|
||||
symlinks_klipperscreen(){
|
||||
#create a KlipperScreen.log symlink in klipper_config-dir just for convenience
|
||||
if [ "$SEL_KSLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/KlipperScreen.log ]; then
|
||||
status_msg "Creating KlipperScreen.log symlink ..."
|
||||
ln -s /tmp/KlipperScreen.log ${HOME}/klipper_config
|
||||
ok_msg "Symlink created!"
|
||||
fi
|
||||
}
|
||||
@@ -1,544 +0,0 @@
|
||||
install_moonraker(){
|
||||
python3_check
|
||||
if [ $py_chk_ok = "true" ]; then
|
||||
system_check_moonraker
|
||||
#ask user for customization
|
||||
get_user_selections_moonraker
|
||||
#disable/remove haproxy/lighttpd
|
||||
handle_haproxy_lighttpd
|
||||
#moonraker main installation
|
||||
moonraker_setup
|
||||
check_for_folder_moonraker
|
||||
#setup configs
|
||||
setup_printer_config_moonraker
|
||||
setup_moonraker_conf
|
||||
#execute customizations
|
||||
write_custom_trusted_clients
|
||||
symlinks_moonraker
|
||||
disable_octoprint
|
||||
#after install actions
|
||||
restart_moonraker
|
||||
restart_klipper
|
||||
else
|
||||
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
|
||||
print_msg && clear_msg
|
||||
fi
|
||||
}
|
||||
|
||||
python3_check(){
|
||||
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!"
|
||||
py_chk_ok="true"
|
||||
else
|
||||
py_chk_ok="false"
|
||||
fi
|
||||
}
|
||||
|
||||
system_check_moonraker(){
|
||||
status_msg "Initializing Moonraker installation ..."
|
||||
#check for existing printer.cfg and for the location
|
||||
locate_printer_cfg
|
||||
if [ -f $PRINTER_CFG ]; then
|
||||
PRINTER_CFG_FOUND="true"
|
||||
PRINTER_CFG_LOC=$PRINTER_CFG
|
||||
else
|
||||
PRINTER_CFG_FOUND="false"
|
||||
fi
|
||||
#check for existing klippy.log symlink in /klipper_config
|
||||
[ ! -e ${HOME}/klipper_config/klippy.log ] && KLIPPY_SL_FOUND="false"
|
||||
#check for existing moonraker.log symlink in /klipper_config
|
||||
[ ! -e ${HOME}/klipper_config/moonraker.log ] && MOONRAKER_SL_FOUND="false"
|
||||
#check for existing moonraker.conf
|
||||
if [ ! -f ${HOME}/moonraker.conf ]; then
|
||||
MOONRAKER_CONF_FOUND="false"
|
||||
else
|
||||
MOONRAKER_CONF_FOUND="true"
|
||||
fi
|
||||
#check if octoprint is installed
|
||||
if systemctl is-enabled octoprint.service -q 2>/dev/null; then
|
||||
unset OCTOPRINT_ENABLED
|
||||
OCTOPRINT_ENABLED="true"
|
||||
fi
|
||||
#check if haproxy is installed
|
||||
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
|
||||
HAPROXY_FOUND="true"
|
||||
fi
|
||||
#check if lighttpd is installed
|
||||
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
|
||||
LIGHTTPD_FOUND="true"
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selections_moonraker(){
|
||||
#user selection for printer.cfg
|
||||
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |"
|
||||
hr
|
||||
echo -e "| KIAUH can create a minimal printer.cfg with only the |"
|
||||
echo -e "| recommended Moonraker config entries if you wish. |"
|
||||
echo -e "| |"
|
||||
echo -e "| Please be aware, that this option will ${red}NOT${default} create a |"
|
||||
echo -e "| fully working printer.cfg for you! |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Create a default printer.cfg? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
SEL_DEF_CFG="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
SEL_DEF_CFG="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
#user selection for moonraker.log symlink
|
||||
if [ "$KLIPPY_SL_FOUND" = "false" ]; then
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Create klippy.log symlink? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
SEL_KLIPPYLOG_SL="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
SEL_KLIPPYLOG_SL="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
#user selection for moonraker.log symlink
|
||||
if [ "$MOONRAKER_SL_FOUND" = "false" ]; then
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Create moonraker.log symlink? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
SEL_MRLOG_SL="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
SEL_MRLOG_SL="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
#ask user for more trusted clients
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Apart from devices of your local network, you can add |"
|
||||
echo -e "| additional trusted clients to the moonraker.conf file |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Add additional trusted clients? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
ADD_TRUSTED_CLIENT="true"
|
||||
custom_trusted_clients
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
ADD_TRUSTED_CLIENT="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
#ask user to disable octoprint when such installed service was found
|
||||
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
|
||||
unset DISABLE_OPRINT
|
||||
while true; do
|
||||
echo
|
||||
warn_msg "OctoPrint service found!"
|
||||
echo -e "You might consider disabling the OctoPrint service,"
|
||||
echo -e "since an active OctoPrint service may lead to unexpected"
|
||||
echo -e "behavior of the Mainsail Webinterface."
|
||||
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
DISABLE_OPRINT="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
DISABLE_OPRINT="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
#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="false"
|
||||
REMOVE_HAPROXY="true"
|
||||
fi
|
||||
if [ "$LIGHTTPD_FOUND" = "true" ]; then
|
||||
DISABLE_LIGHTTPD="false"
|
||||
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"
|
||||
DISABLE_LIGHTTPD="false"
|
||||
REMOVE_LIGHTTPD="false"
|
||||
DISABLE_HAPROXY="false"
|
||||
REMOVE_HAPROXY="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
status_msg "Installation will start now! Please wait ..."
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
moonraker_setup(){
|
||||
dep=(wget curl unzip dfu-util libjpeg-dev zlib1g-dev)
|
||||
dependency_check
|
||||
status_msg "Downloading Moonraker ..."
|
||||
#force remove existing moonraker dir
|
||||
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
|
||||
#clone into fresh moonraker dir
|
||||
cd ${HOME} && git clone $MOONRAKER_REPO
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Installing Moonraker ..."
|
||||
$MOONRAKER_DIR/scripts/install-moonraker.sh
|
||||
#copy moonraker configuration for nginx to /etc/nginx/conf.d
|
||||
setup_moonraker_nginx_cfg
|
||||
#backup a possible existing printer.cfg at the old location and before patching in the new location
|
||||
backup_printer_cfg
|
||||
patch_klipper_sysfile "moonraker"
|
||||
#re-run printer.cfg location function to read the new path for the printer.cfg
|
||||
locate_printer_cfg
|
||||
echo; ok_msg "Moonraker successfully installed!"
|
||||
}
|
||||
|
||||
patch_klipper_sysfile(){
|
||||
if [ -e $KLIPPER_SERVICE2 ]; then
|
||||
status_msg "Checking /etc/default/klipper for necessary entries ..."
|
||||
#patching new printer.cfg location to /etc/default/klipper
|
||||
if [ "$1" = "moonraker" ]; then
|
||||
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
|
||||
status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
|
||||
sudo sed -i "/KLIPPY_ARGS=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE2
|
||||
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
|
||||
fi
|
||||
fi
|
||||
#patching new UDS argument to /etc/default/klipper
|
||||
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
|
||||
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then
|
||||
status_msg "Patching unix domain socket to /etc/default/klipper ..."
|
||||
#append the new argument to /tmp/klippy.log argument
|
||||
sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2
|
||||
ok_msg "Patching done!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ -e $KLIPPER_SERVICE3 ]; then
|
||||
status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..."
|
||||
#patching new printer.cfg location to /etc/systemd/system/klipper.service
|
||||
if [ "$1" = "moonraker" ]; then
|
||||
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then
|
||||
status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..."
|
||||
sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3
|
||||
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
|
||||
#set variable if file got edited
|
||||
SERVICE_FILE_PATCHED="true"
|
||||
fi
|
||||
fi
|
||||
#patching new UDS argument to /etc/systemd/system/klipper.service
|
||||
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
|
||||
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then
|
||||
status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..."
|
||||
#append the new argument to /tmp/klippy.log argument
|
||||
sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3
|
||||
ok_msg "Patching done!"
|
||||
#set variable if file got edited
|
||||
SERVICE_FILE_PATCHED="true"
|
||||
fi
|
||||
fi
|
||||
#reloading the units is only needed when the service file was patched.
|
||||
[ "$SERVICE_FILE_PATCHED" = "true" ] && status_msg "Reloading unit ..." && sudo systemctl daemon-reload
|
||||
fi
|
||||
ok_msg "Check complete!"
|
||||
echo
|
||||
}
|
||||
|
||||
check_for_folder_moonraker(){
|
||||
#check for / create sdcard folder
|
||||
if [ ! -d ${HOME}/sdcard ]; then
|
||||
status_msg "Creating sdcard directory ..."
|
||||
mkdir ${HOME}/sdcard
|
||||
ok_msg "sdcard directory created!"
|
||||
fi
|
||||
##check for / create klipper_config folder
|
||||
if [ ! -d ${HOME}/klipper_config ]; then
|
||||
status_msg "Creating klipper_config directory ..."
|
||||
mkdir ${HOME}/klipper_config
|
||||
ok_msg "klipper_config directory created!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
setup_printer_config_moonraker(){
|
||||
if [ "$PRINTER_CFG_FOUND" = "true" ]; then
|
||||
#copy printer.cfg to new location if there is no printer.cfg at the new location already
|
||||
if [ -f ${HOME}/printer.cfg ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then
|
||||
status_msg "Copy printer.cfg to new location ..."
|
||||
cp ${HOME}/printer.cfg $PRINTER_CFG
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
#check printer.cfg for necessary moonraker entries
|
||||
read_printer_cfg "moonraker" && write_printer_cfg
|
||||
fi
|
||||
if [ "$SEL_DEF_CFG" = "true" ]; then
|
||||
status_msg "Creating minimal default printer.cfg ..."
|
||||
create_minimal_cfg
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_moonraker_conf(){
|
||||
if [ "$MOONRAKER_CONF_FOUND" = "false" ]; then
|
||||
status_msg "Creating moonraker.conf ..."
|
||||
cp ${HOME}/kiauh/resources/moonraker.conf ${HOME}
|
||||
ok_msg "moonraker.conf created!"
|
||||
status_msg "Writing trusted clients to config ..."
|
||||
write_default_trusted_clients
|
||||
ok_msg "Trusted clients written!"
|
||||
fi
|
||||
#check for at least one trusted client in an already existing moonraker.conf
|
||||
#if no entry is found, write default trusted client
|
||||
if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then
|
||||
if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then
|
||||
TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1)
|
||||
FIRST_IP_LINE=$(expr $TC_LINE + 1)
|
||||
FIRST_IP=$(sed -n "$FIRST_IP_LINE"p ${HOME}/moonraker.conf | cut -d" " -f5)
|
||||
#if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then
|
||||
if [ "$FIRST_IP" = "" ]; then
|
||||
status_msg "Writing trusted clients to config ..."
|
||||
backup_moonraker_conf && write_default_trusted_clients
|
||||
ok_msg "Trusted clients written!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
setup_moonraker_nginx_cfg(){
|
||||
if [ ! -f $NGINX_CONFD/upstreams.conf ]; then
|
||||
sudo cp ${SRCDIR}/kiauh/resources/moonraker_nginx.cfg $NGINX_CONFD/upstreams.conf
|
||||
fi
|
||||
if [ ! -f $NGINX_CONFD/common_vars.conf ]; then
|
||||
sudo cp ${SRCDIR}/kiauh/resources/common_vars_nginx.cfg $NGINX_CONFD/common_vars.conf
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
write_default_trusted_clients(){
|
||||
DEFAULT_IP=$(hostname -I)
|
||||
status_msg "Your devices current IP adress is:\n${cyan}● $DEFAULT_IP ${default}"
|
||||
#make IP of the device KIAUH is exectuted on as
|
||||
#default trusted client and expand the IP range from 0 - 255
|
||||
DEFAULT_IP_RANGE="$(echo "$DEFAULT_IP" | cut -d"." -f1-3).0/24"
|
||||
status_msg "Writing the following IP range to moonraker.conf:\n${cyan}● $DEFAULT_IP_RANGE ${default}"
|
||||
#write the ip range in the first line below "trusted clients"
|
||||
#example: 192.168.1.0/24
|
||||
sed -i "/trusted_clients\:/a \ \ \ \ $DEFAULT_IP_RANGE" ${HOME}/moonraker.conf
|
||||
ok_msg "IP range of ● $DEFAULT_IP_RANGE written to moonraker.conf!"
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
custom_trusted_clients(){
|
||||
if [ "$ADD_TRUSTED_CLIENT" = "true" ]; then
|
||||
unset trusted_arr
|
||||
echo
|
||||
top_border
|
||||
echo -e "| You can now add additional trusted clients to your |"
|
||||
echo -e "| moonraker.conf file. Be warned, that there is no |"
|
||||
echo -e "| spellcheck to check for valid input. |"
|
||||
echo -e "| Make sure to type the IP correct! |"
|
||||
echo -e "| |"
|
||||
echo -e "| If you want to add IP ranges, you can type in e.g.: |"
|
||||
echo -e "| 192.168.1.0/24 |"
|
||||
echo -e "| This will add the IPs 192.168.1.1 to 192.168.1.254 |"
|
||||
echo -e "|-------------------------------------------------------|"
|
||||
echo -e "| You can add as many IPs / IP ranges as you want. |"
|
||||
echo -e "| When you are done type '${cyan}done${default}' to exit this dialoge. |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Enter IP and press ENTER:${default} " TRUSTED_IP
|
||||
case "$TRUSTED_IP" in
|
||||
done)
|
||||
echo
|
||||
echo -e "List of IPs to add:"
|
||||
for ip in ${trusted_arr[@]}
|
||||
do
|
||||
echo -e "${cyan}● $ip ${default}"
|
||||
done
|
||||
while true; do
|
||||
echo
|
||||
echo -e "Select 'Yes' to confirm, 'No' to start again"
|
||||
echo -e "or 'Q' to abort and skip."
|
||||
read -p "${cyan}###### Confirm writing (Y/n/q):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
TUSTED_CLIENT_CONFIRM="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
custom_trusted_clients
|
||||
break;;
|
||||
Q|q)
|
||||
unset trusted_arr
|
||||
echo -e "###### > Abort"
|
||||
echo -e "${red}Aborting ...${default}"
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
break;;
|
||||
*)
|
||||
trusted_arr+=($TRUSTED_IP);;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
write_custom_trusted_clients(){
|
||||
if [ "$TUSTED_CLIENT_CONFIRM" = "true" ]; then
|
||||
if [ "${#trusted_arr[@]}" != "0" ]; then
|
||||
for ip in ${trusted_arr[@]}
|
||||
do
|
||||
sed -i "/trusted_clients\:/a \ \ \ \ $ip" ${HOME}/moonraker.conf
|
||||
done
|
||||
ok_msg "Custom IPs written to moonraker.conf!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
symlinks_moonraker(){
|
||||
#create a klippy.log/moonraker.log symlink in klipper_config-dir just for convenience
|
||||
if [ "$SEL_KLIPPYLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/klippy.log ]; then
|
||||
status_msg "Creating klippy.log symlink ..."
|
||||
ln -s /tmp/klippy.log ${HOME}/klipper_config
|
||||
ok_msg "Symlink created!"
|
||||
fi
|
||||
if [ "$SEL_MRLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/moonraker.log ]; then
|
||||
status_msg "Creating moonraker.log symlink ..."
|
||||
ln -s /tmp/moonraker.log ${HOME}/klipper_config
|
||||
ok_msg "Symlink created!"
|
||||
fi
|
||||
}
|
||||
|
||||
handle_haproxy_lighttpd(){
|
||||
#handle haproxy
|
||||
if [ "$DISABLE_HAPROXY" = "true" ]; then
|
||||
if systemctl is-active haproxy -q; then
|
||||
status_msg "Stopping haproxy service ..."
|
||||
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
|
||||
fi
|
||||
sudo systemctl disable haproxy
|
||||
ok_msg "Haproxy service disabled!"
|
||||
else
|
||||
if [ "$REMOVE_HAPROXY" = "true" ]; then
|
||||
if systemctl is-active haproxy -q; then
|
||||
status_msg "Stopping haproxy service ..."
|
||||
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
|
||||
fi
|
||||
status_msg "Removing haproxy ..."
|
||||
sudo apt-get remove haproxy -y
|
||||
sudo update-rc.d -f haproxy remove
|
||||
ok_msg "Haproxy removed!"
|
||||
fi
|
||||
fi
|
||||
#handle lighttpd
|
||||
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
|
||||
if systemctl is-active lighttpd -q; then
|
||||
status_msg "Stopping lighttpd service ..."
|
||||
sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!"
|
||||
fi
|
||||
sudo systemctl disable lighttpd
|
||||
ok_msg "Lighttpd service disabled!"
|
||||
else
|
||||
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
|
||||
if systemctl is-active lighttpd -q; then
|
||||
status_msg "Stopping lighttpd service ..."
|
||||
sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!"
|
||||
fi
|
||||
status_msg "Removing lighttpd ..."
|
||||
sudo apt-get remove lighttpd -y
|
||||
sudo update-rc.d -f lighttpd remove
|
||||
ok_msg "Lighttpd removed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
install_octoprint(){
|
||||
#check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
#ask user for customization
|
||||
get_user_selections_octoprint
|
||||
#octoprint main installation
|
||||
octoprint_dependencies
|
||||
octoprint_setup
|
||||
add_groups
|
||||
configure_autostart
|
||||
add_reboot_permission
|
||||
create_config_yaml
|
||||
#execute customizations
|
||||
set_nginx_cfg "octoprint"
|
||||
set_hostname
|
||||
#after install actions
|
||||
load_octoprint_server
|
||||
}
|
||||
|
||||
get_user_selections_octoprint(){
|
||||
status_msg "Initializing OctoPrint installation ..."
|
||||
#ask user to set a reverse proxy
|
||||
octoprint_reverse_proxy_dialog
|
||||
#ask to change hostname
|
||||
[ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname
|
||||
status_msg "Installation will start now! Please wait ..."
|
||||
}
|
||||
|
||||
octoprint_dependencies(){
|
||||
dep=(
|
||||
git
|
||||
wget
|
||||
python-pip
|
||||
python-dev
|
||||
libyaml-dev
|
||||
build-essential
|
||||
python-setuptools
|
||||
python-virtualenv
|
||||
)
|
||||
dependency_check
|
||||
}
|
||||
|
||||
octoprint_setup(){
|
||||
if [ ! -d $OCTOPRINT_DIR ];then
|
||||
status_msg "Create OctoPrint directory ..."
|
||||
mkdir -p $OCTOPRINT_DIR && ok_msg "Directory created!"
|
||||
fi
|
||||
cd $OCTOPRINT_DIR
|
||||
#create the virtualenv
|
||||
status_msg "Set up virtualenv ..."
|
||||
virtualenv venv
|
||||
source venv/bin/activate
|
||||
#install octoprint with pip
|
||||
status_msg "Download and install OctoPrint ..."
|
||||
pip install pip --upgrade
|
||||
pip install --no-cache-dir octoprint
|
||||
ok_msg "Download complete!"
|
||||
#leave virtualenv
|
||||
deactivate
|
||||
}
|
||||
|
||||
add_groups(){
|
||||
if [ ! "$(groups | grep tty)" ]; then
|
||||
status_msg "Adding user '${USER}' to group 'tty' ..."
|
||||
sudo usermod -a -G tty ${USER} && ok_msg "Done!"
|
||||
fi
|
||||
if [ ! "$(groups | grep dialout)" ]; then
|
||||
status_msg "Adding user '${USER}' to group 'dialout' ..."
|
||||
sudo usermod -a -G dialout ${USER} && ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
configure_autostart(){
|
||||
USER=$(whoami)
|
||||
cd $OCTOPRINT_DIR
|
||||
status_msg "Downloading files ..."
|
||||
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init
|
||||
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default
|
||||
ok_msg "Files downloaded successfully!"
|
||||
#make necessary changes in default file
|
||||
status_msg "Configure OctoPrint Service ..."
|
||||
DEFAULT_FILE=$OCTOPRINT_DIR/octoprint.default
|
||||
sed -i "s/pi/$USER/g" $DEFAULT_FILE
|
||||
sed -i "s/#BASEDIR=/BASEDIR=/" $DEFAULT_FILE
|
||||
sed -i "s/#CONFIGFILE=/CONFIGFILE=/" $DEFAULT_FILE
|
||||
sed -i "s/#DAEMON=/DAEMON=/" $DEFAULT_FILE
|
||||
#move files to correct location
|
||||
sudo mv octoprint.init $OCTOPRINT_SERVICE1
|
||||
sudo mv octoprint.default $OCTOPRINT_SERVICE2
|
||||
#make file in init.d executable
|
||||
sudo chmod +x $OCTOPRINT_SERVICE1
|
||||
status_msg "Reload systemd configuration files"
|
||||
sudo update-rc.d octoprint defaults
|
||||
sudo systemctl daemon-reload
|
||||
ok_msg "Configuration complete!"
|
||||
ok_msg "OctoPrint installed!"
|
||||
}
|
||||
|
||||
add_reboot_permission(){
|
||||
USER=$(whoami)
|
||||
#create a backup when file already exists
|
||||
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
|
||||
sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old
|
||||
fi
|
||||
#create new permission file
|
||||
status_msg "Add reboot permission to user '$USER' ..."
|
||||
cd $OCTOPRINT_DIR
|
||||
echo "$USER ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
|
||||
sudo chown 0 octoprint-shutdown
|
||||
sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown
|
||||
ok_msg "Permission set!"
|
||||
sleep 2
|
||||
}
|
||||
|
||||
octoprint_reverse_proxy_dialog(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| If you want to have nicer URLs or simply need | "
|
||||
echo -e "| OctoPrint to run on port 80 (http's default port) | "
|
||||
echo -e "| due to some network restrictions, you can set up a | "
|
||||
echo -e "| reverse proxy instead of configuring OctoPrint to | "
|
||||
echo -e "| run on port 80. | "
|
||||
bottom_border
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to set up a reverse proxy now? (y/N): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
octoprint_port_check
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
octoprint_port_check(){
|
||||
if [ "$OCTOPRINT_ENABLED" = "false" ]; then
|
||||
if [ "$SITE_ENABLED" = "true" ]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
[ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}"
|
||||
[ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}"
|
||||
[ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port:$DWC2_PORT${default}"
|
||||
if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_octoprint_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/octoprint_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=$DEFAULT_PORT
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
select_octoprint_port(){
|
||||
if [ "$PORT_80_BLOCKED" = "true" ]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${default} |"
|
||||
echo -e "| ${red}You need to choose a different port for OctoPrint!${default} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${default} |"
|
||||
blank_line
|
||||
[ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |"
|
||||
[ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |"
|
||||
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to one of the other web interfaces! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT
|
||||
if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ]; then
|
||||
echo "Setting port $NEW_PORT for OctoPrint!"
|
||||
SET_LISTEN_PORT=$NEW_PORT
|
||||
break
|
||||
else
|
||||
echo "That port is already taken! Select a different one!"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
create_config_yaml(){
|
||||
if [ ! -d $OCTOPRINT_CFG_DIR ]; then
|
||||
status_msg "Creating config.yaml ..."
|
||||
mkdir $OCTOPRINT_CFG_DIR
|
||||
cp ${HOME}/kiauh/resources/octoprint_config.cfg $OCTOPRINT_CFG_DIR/config.yaml
|
||||
ok_msg "Config created!"
|
||||
fi
|
||||
}
|
||||
|
||||
load_octoprint_server(){
|
||||
start_octoprint
|
||||
#create an octoprint.log symlink in home-dir just for convenience
|
||||
if [ ! -e ${HOME}/octoprint.log ]; then
|
||||
status_msg "Creating octoprint.log Symlink ..."
|
||||
ln -s ${HOME}/.octoprint/logs/octoprint.log ${HOME}/octoprint.log && ok_msg "Symlink created!"
|
||||
fi
|
||||
ok_msg "OctoPrint is now running on:"
|
||||
ok_msg "$(hostname -I | cut -d " " -f1):5000 or"
|
||||
ok_msg "http://localhost:5000"; echo
|
||||
}
|
||||
599
scripts/klipper.sh
Normal file
599
scripts/klipper.sh
Normal file
@@ -0,0 +1,599 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#================ INSTALL KLIPPER ================#
|
||||
#=================================================#
|
||||
|
||||
### check for existing klipper service installations
|
||||
function klipper_initd() {
|
||||
local services
|
||||
services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function klipper_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function klipper_exists() {
|
||||
local services
|
||||
[[ -n $(klipper_initd) ]] && services+="$(klipper_initd) "
|
||||
[[ -n $(klipper_systemd) ]] && services+="$(klipper_systemd)"
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function klipper_setup_dialog() {
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
|
||||
local klipper_services
|
||||
local python_version="${1}" user_input=()
|
||||
klipper_services=$(klipper_exists)
|
||||
user_input+=("${python_version}")
|
||||
|
||||
### return early if klipper already exists
|
||||
if [[ -n ${klipper_services} ]]; then
|
||||
local error="At least one Klipper service is already installed:"
|
||||
|
||||
for s in ${klipper_services}; do
|
||||
log_info "Found Klipper service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### ask for amount of instances to create
|
||||
top_border
|
||||
echo -e "| Please select the number of Klipper instances to set |"
|
||||
echo -e "| up. The number of Klipper instances will determine |"
|
||||
echo -e "| the amount of printers you can run from this host. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}WARNING:${white} |"
|
||||
echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local klipper_count re="^[1-9][0-9]*$"
|
||||
while [[ ! ${klipper_count} =~ ${re} ]]; do
|
||||
read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e klipper_count
|
||||
### break if input is valid
|
||||
[[ ${klipper_count} =~ ${re} ]] && break
|
||||
### error messages on invalid input
|
||||
error_msg "Input not a number"
|
||||
done && select_msg "${klipper_count}"
|
||||
|
||||
user_input+=("${klipper_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Install ${klipper_count} instance(s)? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting Klipper setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### ask for custom names
|
||||
if (( klipper_count > 1 )); then
|
||||
local custom_names="false"
|
||||
top_border
|
||||
echo -e "| You can give each instance a custom name or skip. |"
|
||||
echo -e "| If skipped, KIAUH will automatically assign an index |"
|
||||
echo -e "| to each instance in ascending order, starting at '1'. |"
|
||||
blank_line
|
||||
echo -e "| Info: |"
|
||||
echo -e "| Only alphanumeric characters will be allowed. |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Use custom names? (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
custom_names="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### get user input for custom names
|
||||
if [[ ${custom_names} == "true" ]]; then
|
||||
local i=1 name re="^[0-9a-zA-Z]+$"
|
||||
while [[ ! ${name} =~ ${re} || ${i} -le ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Name for instance #${i}:${white} " name
|
||||
if [[ ${name} =~ ${re} ]]; then
|
||||
select_msg "Name: ${name}"
|
||||
user_input+=("${name}")
|
||||
i=$(( i + 1 ))
|
||||
else
|
||||
error_msg "Invalid Input!"
|
||||
fi
|
||||
done
|
||||
else
|
||||
### if no custom names are used, add the respective amount of indices to the user_input array
|
||||
for (( i=1; i <= klipper_count; i++ )); do
|
||||
user_input+=("${i}")
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
(( klipper_count > 1 )) && status_msg "Installing ${klipper_count} Klipper instances ..."
|
||||
(( klipper_count == 1 )) && status_msg "Installing single Klipper instance ..."
|
||||
|
||||
klipper_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_klipper_packages() {
|
||||
local packages python_version="${1}"
|
||||
local install_script="${KLIPPER_DIR}/scripts/install-debian.sh"
|
||||
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages=$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')
|
||||
### add dfu-util for octopi-images
|
||||
packages+=" dfu-util"
|
||||
### add dbus requirement for DietPi distro
|
||||
[[ -e "/boot/dietpi/.version" ]] && packages+=" dbus"
|
||||
|
||||
if [[ ${python_version} == "python3" ]]; then
|
||||
### replace python-dev with python3-dev if python3 was selected
|
||||
packages="${packages//python-dev/python3-dev}"
|
||||
else
|
||||
### package name 'python-dev' is deprecated (-> no installation candidate) on more modern linux distros
|
||||
packages="${packages//python-dev/python2-dev}"
|
||||
fi
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Updating package lists..."
|
||||
if ! sudo apt-get update --allow-releaseinfo-change; then
|
||||
log_error "failure while updating package lists"
|
||||
error_msg "Updating package lists failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Install required packages
|
||||
status_msg "Installing required packages..."
|
||||
if ! sudo apt-get install --yes "${packages[@]}"; then
|
||||
log_error "failure while installing required klipper packages"
|
||||
error_msg "Installing required packages failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_klipper_virtualenv() {
|
||||
local python_version="${1}"
|
||||
|
||||
[[ ${python_version} == "python2" ]] && \
|
||||
status_msg "Installing $(python2 -V) virtual environment..."
|
||||
|
||||
[[ ${python_version} == "python3" ]] && \
|
||||
status_msg "Installing $(python3 -V) virtual environment..."
|
||||
|
||||
### remove klippy-env if it already exists
|
||||
[[ -d ${KLIPPY_ENV} ]] && rm -rf "${KLIPPY_ENV}"
|
||||
|
||||
if [[ ${python_version} == "python2" ]]; then
|
||||
if virtualenv -p python2 "${KLIPPY_ENV}"; then
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||
else
|
||||
log_error "failure while creating python2 klippy-env"
|
||||
error_msg "Creation of Klipper virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${python_version} == "python3" ]]; then
|
||||
if virtualenv -p python3 "${KLIPPY_ENV}"; then
|
||||
"${KLIPPY_ENV}"/bin/pip install -U pip
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||
else
|
||||
log_error "failure while creating python3 klippy-env"
|
||||
error_msg "Creation of Klipper virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
function klipper_setup() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
### index 0: python version, index 1: instance count, index 2-n: instance names (optional)
|
||||
local user_input=("${@}")
|
||||
local python_version="${user_input[0]}" && unset "user_input[0]"
|
||||
local instance_arr=("${user_input[@]}") && unset "user_input[@]"
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
### checking dependencies
|
||||
local dep=(git)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone klipper
|
||||
clone_klipper "${custom_repo}" "${custom_branch}"
|
||||
|
||||
### step 2: install klipper dependencies and create python virtualenv
|
||||
install_klipper_packages "${python_version}"
|
||||
create_klipper_virtualenv "${python_version}"
|
||||
|
||||
### step 3: create gcode_files and logs folder
|
||||
[[ ! -d "${HOME}/gcode_files" ]] && mkdir -p "${HOME}/gcode_files"
|
||||
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
|
||||
|
||||
### step 4: create klipper instances
|
||||
create_klipper_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: enable and start all instances
|
||||
do_action_service "enable" "klipper"
|
||||
do_action_service "start" "klipper"
|
||||
|
||||
### step 6: check for dialout group membership
|
||||
check_usergroups
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Klipper has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Klipper instances have been set up!"
|
||||
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
function clone_klipper() {
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
[[ -z ${repo} ]] && repo="${KLIPPER_REPO}"
|
||||
repo=$(echo "${repo}" | sed -r "s/^(http|https):\/\/github\.com\///i; s/\.git$//")
|
||||
repo="https://github.com/${repo}"
|
||||
|
||||
[[ -z ${branch} ]] && branch="master"
|
||||
|
||||
### force remove existing klipper dir and clone into fresh klipper dir
|
||||
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
|
||||
|
||||
status_msg "Cloning Klipper from ${repo} ..."
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if git clone "${repo}" "${KLIPPER_DIR}"; then
|
||||
cd "${KLIPPER_DIR}" && git checkout "${branch}"
|
||||
else
|
||||
print_error "Cloning Klipper from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_klipper_service() {
|
||||
local i=${1} cfg=${2} log=${3} printer=${4} uds=${5} service=${6}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/klipper.service"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Klipper Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
[[ -z ${i} ]] && sudo sed -i "s| for instance klipper-%INST%||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${KLIPPY_ENV}|; s|%DIR%|${KLIPPER_DIR}|" "${service}"
|
||||
sudo sed -i "s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${printer}|; s|%UDS%|${uds}|" "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
function write_example_printer_cfg() {
|
||||
local cfg_dir=${1} cfg=${2}
|
||||
local cfg_template="${KIAUH_SRCDIR}/resources/printer.cfg"
|
||||
|
||||
### create a config directory if it doesn't exist
|
||||
if [[ ! -d ${cfg_dir} ]]; then
|
||||
status_msg "Creating '${cfg_dir}' ..."
|
||||
mkdir -p "${cfg_dir}"
|
||||
fi
|
||||
|
||||
### create a minimal config if there is no printer.cfg
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating minimal example printer.cfg ..."
|
||||
cp "${cfg_template}" "${cfg}"
|
||||
fi
|
||||
}
|
||||
|
||||
function create_klipper_service() {
|
||||
local input=("${@}")
|
||||
local klipper_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local cfg_dir cfg log printer uds service
|
||||
|
||||
if (( klipper_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/printer.cfg"
|
||||
log="${KLIPPER_LOGS}/klippy.log"
|
||||
printer="/tmp/printer"
|
||||
uds="/tmp/klippy_uds"
|
||||
service="${SYSTEMD}/klipper.service"
|
||||
### write single instance service
|
||||
write_klipper_service "" "${cfg}" "${log}" "${printer}" "${uds}" "${service}"
|
||||
write_example_printer_cfg "${cfg_dir}" "${cfg}"
|
||||
ok_msg "Klipper instance created!"
|
||||
|
||||
elif (( klipper_count >= 1 )) && [[ ${#names[@]} -gt 0 ]]; then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= klipper_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/printer.cfg"
|
||||
log="${KLIPPER_LOGS}/klippy-${names[${j}]}.log"
|
||||
printer="/tmp/printer-${names[${j}]}"
|
||||
uds="/tmp/klippy_uds-${names[${j}]}"
|
||||
service="${SYSTEMD}/klipper-${names[${j}]}.service"
|
||||
### write multi instance service
|
||||
write_klipper_service "${names[${j}]}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}"
|
||||
write_example_printer_cfg "${cfg_dir}" "${cfg}"
|
||||
ok_msg "Klipper instance 'klipper-${names[${j}]}' created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ REMOVE KLIPPER ================#
|
||||
#================================================#
|
||||
|
||||
function remove_klipper_sysvinit() {
|
||||
[[ ! -e "${INITD}/klipper" ]] && return
|
||||
|
||||
status_msg "Removing Klipper SysVinit service ..."
|
||||
sudo systemctl stop klipper
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo rm -f "${INITD}/klipper" "${ETCDEF}/klipper"
|
||||
ok_msg "Klipper SysVinit service removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_systemd() {
|
||||
[[ -z $(klipper_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Klipper Systemd Services ..."
|
||||
for service in $(klipper_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Klipper Service removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_logs() {
|
||||
local files regex="klippy(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper_uds() {
|
||||
local files
|
||||
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper_printer() {
|
||||
local files
|
||||
|
||||
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort)
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper_dir() {
|
||||
[[ ! -d ${KLIPPER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Klipper directory ..."
|
||||
rm -rf "${KLIPPER_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_env() {
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
status_msg "Removing klippy-env directory ..."
|
||||
rm -rf "${KLIPPY_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_klipper() {
|
||||
remove_klipper_sysvinit
|
||||
remove_klipper_systemd
|
||||
remove_klipper_logs
|
||||
remove_klipper_uds
|
||||
remove_klipper_printer
|
||||
remove_klipper_dir
|
||||
remove_klipper_env
|
||||
|
||||
local confirm="Klipper was successfully removed!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ UPDATE KLIPPER ================#
|
||||
#================================================#
|
||||
|
||||
function update_klipper() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
if [[ ! -d ${KLIPPER_DIR} ]]; then
|
||||
clone_klipper "${custom_repo}" "${custom_branch}"
|
||||
else
|
||||
backup_before_update "klipper"
|
||||
status_msg "Updating Klipper ..."
|
||||
cd "${KLIPPER_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_klipper_packages
|
||||
### install possible new python dependencies
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "klipper"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ KLIPPER STATUS ================#
|
||||
#================================================#
|
||||
|
||||
function get_klipper_status() {
|
||||
local sf_count status py_ver
|
||||
sf_count="$(klipper_systemd | wc -w)"
|
||||
|
||||
### detect an existing "legacy" klipper init.d installation
|
||||
if [[ $(klipper_systemd | wc -w) -eq 0 ]] \
|
||||
&& [[ $(klipper_initd | wc -w) -ge 1 ]]; then
|
||||
sf_count=1
|
||||
fi
|
||||
|
||||
py_ver=$(get_klipper_python_ver)
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a klipper service is installed
|
||||
local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
if (( py_ver == 3 )); then
|
||||
status="Installed: ${sf_count}(py${py_ver})"
|
||||
else
|
||||
status="Installed: ${sf_count}"
|
||||
fi
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_klipper_commit() {
|
||||
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_klipper_commit() {
|
||||
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_klipper_versions() {
|
||||
unset KLIPPER_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_klipper_commit)"
|
||||
remote_ver="$(get_remote_klipper_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add klipper to the update all array for the update all function in the updater
|
||||
KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
KLIPPER_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_klipper_cfg_dir() {
|
||||
local cfg_dir
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
if [[ -z ${custom_klipper_cfg_loc} ]]; then
|
||||
cfg_dir="${HOME}/klipper_config"
|
||||
else
|
||||
cfg_dir="${custom_klipper_cfg_loc}"
|
||||
fi
|
||||
|
||||
echo "${cfg_dir}"
|
||||
}
|
||||
|
||||
### returns the major python version the klippy-env was created with
|
||||
function get_klipper_python_ver() {
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
local version
|
||||
version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
|
||||
echo "${version}"
|
||||
}
|
||||
230
scripts/klipperscreen.sh
Normal file
230
scripts/klipperscreen.sh
Normal file
@@ -0,0 +1,230 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#============== INSTALL KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function klipperscreen_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/KlipperScreen.service")
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function install_klipperscreen() {
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
### install KlipperScreen
|
||||
klipperscreen_setup
|
||||
|
||||
### add klipperscreen to the update manager in moonraker.conf
|
||||
patch_klipperscreen_update_manager
|
||||
|
||||
do_action_service "restart" "KlipperScreen"
|
||||
}
|
||||
|
||||
function klipperscreen_setup() {
|
||||
local dep=(wget curl unzip dfu-util)
|
||||
dependency_check "${dep[@]}"
|
||||
status_msg "Cloning KlipperScreen from ${KLIPPERSCREEN_REPO} ..."
|
||||
|
||||
# force remove existing KlipperScreen dir
|
||||
[[ -d ${KLIPPERSCREEN_DIR} ]] && rm -rf "${KLIPPERSCREEN_DIR}"
|
||||
|
||||
# clone into fresh KlipperScreen dir
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${KLIPPERSCREEN_REPO}" "${KLIPPERSCREEN_DIR}"; then
|
||||
print_error "Cloning KlipperScreen from\n ${KLIPPERSCREEN_REPO}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
status_msg "Installing KlipperScreen ..."
|
||||
if "${KLIPPERSCREEN_DIR}"/scripts/KlipperScreen-install.sh; then
|
||||
ok_msg "KlipperScreen successfully installed!"
|
||||
else
|
||||
print_error "KlipperScreen installation failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== REMOVE KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function remove_klipperscreen() {
|
||||
### remove KlipperScreen dir
|
||||
if [[ -d ${KLIPPERSCREEN_DIR} ]]; then
|
||||
status_msg "Removing KlipperScreen directory ..."
|
||||
rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen VENV dir
|
||||
if [[ -d ${KLIPPERSCREEN_ENV} ]]; then
|
||||
status_msg "Removing KlipperScreen VENV directory ..."
|
||||
rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen service
|
||||
if [[ -e "${SYSTEMD}/KlipperScreen.service" ]]; then
|
||||
status_msg "Removing KlipperScreen service ..."
|
||||
do_action_service "stop" "KlipperScreen"
|
||||
do_action_service "disable" "KlipperScreen"
|
||||
sudo rm -f "${SYSTEMD}/KlipperScreen.service"
|
||||
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "KlipperScreen Service removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen log
|
||||
if [[ -e "/tmp/KlipperScreen.log" ]]; then
|
||||
status_msg "Removing KlipperScreen log file ..."
|
||||
rm -f "/tmp/KlipperScreen.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen log symlink in config dir
|
||||
if [[ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]]; then
|
||||
status_msg "Removing KlipperScreen log symlink ..."
|
||||
rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
print_confirm "KlipperScreen successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== UPDATE KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function update_klipperscreen() {
|
||||
local old_md5
|
||||
old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
|
||||
|
||||
do_action_service "stop" "KlipperScreen"
|
||||
cd "${KLIPPERSCREEN_DIR}"
|
||||
git pull origin master -q && ok_msg "Fetch successfull!"
|
||||
git checkout -f master && ok_msg "Checkout successfull"
|
||||
|
||||
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
||||
status_msg "New dependecies detected..."
|
||||
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
|
||||
ok_msg "Dependencies have been installed!"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "KlipperScreen"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== KLIPPERSCREEN STATUS ==============#
|
||||
#===================================================#
|
||||
|
||||
function get_klipperscreen_status() {
|
||||
local sf_count status
|
||||
sf_count="$(klipperscreen_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_klipperscreen_commit() {
|
||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPERSCREEN_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_klipperscreen_commit() {
|
||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_klipperscreen_versions() {
|
||||
unset KLIPPERSCREEN_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_klipperscreen_commit)"
|
||||
remote_ver="$(get_remote_klipperscreen_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add klipperscreen to the update all array for the update all function in the updater
|
||||
KLIPPERSCREEN_UPDATE_AVAIL="true" && update_arr+=(update_klipperscreen)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
KLIPPERSCREEN_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_klipperscreen_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager KlipperScreen\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add KlipperScreens update manager section to moonraker.conf
|
||||
status_msg "Adding KlipperScreen to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager KlipperScreen]
|
||||
type: git_repo
|
||||
path: ${HOME}/KlipperScreen
|
||||
origin: https://github.com/jordanruthe/KlipperScreen.git
|
||||
env: ${HOME}/.KlipperScreen-env/bin/python
|
||||
requirements: scripts/KlipperScreen-requirements.txt
|
||||
install_script: scripts/KlipperScreen-install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
577
scripts/mainsail.sh
Normal file
577
scripts/mainsail.sh
Normal file
@@ -0,0 +1,577 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================= INSTALL MAINSAIL ================#
|
||||
#===================================================#
|
||||
|
||||
function install_mainsail() {
|
||||
### exit early if moonraker not found
|
||||
if [[ -z $(moonraker_systemd) ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### checking dependencies
|
||||
local dep=(wget nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
### detect conflicting Haproxy and Apache2 installations
|
||||
detect_conflicting_packages
|
||||
|
||||
status_msg "Initializing Mainsail installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
mainsail_port_check
|
||||
|
||||
### ask user to install mjpg-streamer
|
||||
local install_mjpg_streamer
|
||||
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Install MJGP-Streamer for webcam support? |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please select (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
install_mjpg_streamer="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
install_mjpg_streamer="false"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
### download mainsail
|
||||
download_mainsail
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
install_mainsail_macros
|
||||
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "mainsail"
|
||||
### nginx on ubuntu 21 and above needs special permissions to access the files
|
||||
set_nginx_permissions
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
|
||||
### add mainsail to the update manager in moonraker.conf
|
||||
patch_mainsail_update_manager
|
||||
|
||||
### install mjpg-streamer
|
||||
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
print_confirm "Mainsail has been set up!"
|
||||
}
|
||||
|
||||
function install_mainsail_macros() {
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to have some important macros in |"
|
||||
echo -e "| your printer configuration to have Mainsail fully |"
|
||||
echo -e "| functional and working. |"
|
||||
blank_line
|
||||
echo -e "| The recommended macros for Mainsail can be seen here: |"
|
||||
echo -e "| https://docs.mainsail.xyz/configuration#macros |"
|
||||
blank_line
|
||||
echo -e "| If you already have these macros in your config file, |"
|
||||
echo -e "| skip this step and answer with 'no'. |"
|
||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||
echo -e "| add the recommended example macros to your config. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
download_mainsail_macros
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
return
|
||||
}
|
||||
|
||||
function download_mainsail_macros() {
|
||||
local ms_cfg="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mainsail/filesystem/home/pi/klipper_config/mainsail.cfg"
|
||||
local configs path
|
||||
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
|
||||
|
||||
if [[ -n ${configs} ]]; then
|
||||
for config in ${configs}; do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
if [[ ! -f "${path}/mainsail.cfg" ]]; then
|
||||
status_msg "Downloading mainsail.cfg to ${path} ..."
|
||||
log_info "downloading mainsail.cfg to: ${path}"
|
||||
wget "${ms_cfg}" -O "${path}/mainsail.cfg"
|
||||
|
||||
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
||||
log_info "modify mainsail.cfg"
|
||||
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg"
|
||||
|
||||
### write include to the very first line of the printer.cfg
|
||||
if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then
|
||||
log_info "modify printer.cfg"
|
||||
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log_error "execution stopped! reason: no printer.cfg found"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
function download_mainsail() {
|
||||
local url
|
||||
url=$(get_mainsail_download_url)
|
||||
|
||||
status_msg "Downloading Mainsail from ${url} ..."
|
||||
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
rm -rf "${MAINSAIL_DIR}"
|
||||
fi
|
||||
|
||||
mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}"
|
||||
|
||||
if wget "${url}"; then
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf ./*.zip && ok_msg "Done!"
|
||||
else
|
||||
print_error "Downloading Mainsail from\n ${url}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode
|
||||
if [[ $(moonraker_systemd | wc -w) -gt 1 ]]; then
|
||||
enable_mainsail_remotemode
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= REMOVE MAINSAIL =================#
|
||||
#===================================================#
|
||||
|
||||
function remove_mainsail_dir() {
|
||||
[[ ! -d ${MAINSAIL_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Mainsail directory ..."
|
||||
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_mainsail_config() {
|
||||
if [[ -e "/etc/nginx/sites-available/mainsail" ]]; then
|
||||
status_msg "Removing Mainsail configuration for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!"
|
||||
fi
|
||||
if [[ -L "/etc/nginx/sites-enabled/mainsail" ]]; then
|
||||
status_msg "Removing Mainsail Symlink for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail_logs() {
|
||||
local files
|
||||
files=$(find /var/log/nginx -name "mainsail*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
sudo rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail_log_symlinks() {
|
||||
local files
|
||||
files=$(find "${KLIPPER_LOGS}" -name "mainsail*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail() {
|
||||
remove_mainsail_dir
|
||||
remove_mainsail_config
|
||||
remove_mainsail_logs
|
||||
remove_mainsail_log_symlinks
|
||||
|
||||
### remove mainsail_port from ~/.kiauh.ini
|
||||
sed -i "/^mainsail_port=/d" "${INI_FILE}"
|
||||
|
||||
print_confirm "Mainsail successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= UPDATE MAINSAIL =================#
|
||||
#===================================================#
|
||||
|
||||
function update_mainsail() {
|
||||
backup_before_update "mainsail"
|
||||
status_msg "Updating Mainsail ..."
|
||||
download_mainsail
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
print_confirm "Mainsail successfully updated!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= MAINSAIL STATUS =================#
|
||||
#===================================================#
|
||||
|
||||
function get_mainsail_status() {
|
||||
local status
|
||||
local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail")
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_mainsail_version() {
|
||||
[[ ! -f "${MAINSAIL_DIR}/.version" ]] && return
|
||||
|
||||
local version
|
||||
version=$(head -n 1 "${MAINSAIL_DIR}/.version")
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function get_remote_mainsail_version() {
|
||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||
|
||||
local version
|
||||
version=$(get_mainsail_download_url | rev | cut -d"/" -f2 | rev)
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function compare_mainsail_versions() {
|
||||
unset MAINSAIL_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_mainsail_version)"
|
||||
remote_ver="$(get_remote_mainsail_version)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add mainsail to the update all array for the update all function in the updater
|
||||
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
MAINSAIL_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=========== MAINSAIL THEME INSTALLER ===========#
|
||||
#================================================#
|
||||
|
||||
function print_theme_list() {
|
||||
local i=0 theme_list=${1}
|
||||
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
if [[ ${col1} != "name" ]]; then
|
||||
printf "| ${i}) %-51s|\n" "[${col1}]"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done <<< "${theme_list}"
|
||||
}
|
||||
|
||||
function ms_theme_installer_menu() {
|
||||
local theme_list theme_author theme_repo theme_name theme_note theme_url
|
||||
local theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv"
|
||||
theme_list=$(curl -s -L "${theme_csv_url}")
|
||||
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| ${cyan}A preview of each Mainsail theme can be found here:${white} |"
|
||||
echo -e "| https://docs.mainsail.xyz/theming/themes |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}Important note:${white} |"
|
||||
echo -e "| Installing a theme from this menu will overwrite an |"
|
||||
echo -e "| already installed theme or modified custom.css file! |"
|
||||
hr
|
||||
print_theme_list "${theme_list}"
|
||||
echo -e "| |"
|
||||
echo -e "| R) [Remove Theme] |"
|
||||
back_footer
|
||||
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
theme_name+=("${col1}")
|
||||
theme_note+=("${col2}")
|
||||
theme_author+=("${col3}")
|
||||
theme_repo+=("${col4}")
|
||||
done <<< "${theme_list}"
|
||||
|
||||
local option
|
||||
while true; do
|
||||
read -p "${cyan}Install theme:${white} " option
|
||||
if (( option > 0 && option < ${#theme_name[@]} )); then
|
||||
theme_url="https://github.com/${theme_author[${option}]}/${theme_repo[${option}]}"
|
||||
ms_theme_install "${theme_url}" "${theme_name[${option}]}" "${theme_note[${option}]}"
|
||||
break
|
||||
elif [[ ${option} == "R" || ${option} == "r" ]]; then
|
||||
ms_theme_delete
|
||||
break
|
||||
elif [[ ${option} == "B" || ${option} == "b" ]]; then
|
||||
advanced_menu
|
||||
break
|
||||
else
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
ms_theme_installer_menu
|
||||
}
|
||||
|
||||
function ms_theme_install() {
|
||||
local theme_url=${1} theme_name theme_note
|
||||
theme_name=${2} theme_note=${3}
|
||||
|
||||
local config_folders target_folders=()
|
||||
config_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -maxdepth 1 -type d | sort)
|
||||
|
||||
### build target folder array
|
||||
for folder in ${config_folders}; do
|
||||
target_folders+=("${folder}")
|
||||
done
|
||||
|
||||
if (( ${#target_folders[@]} > 1 )); then
|
||||
top_border
|
||||
echo -e "| Please select the printer you want to apply the theme |"
|
||||
echo -e "| installation to: |"
|
||||
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f1 | rev)
|
||||
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||
done
|
||||
bottom_border
|
||||
|
||||
local target re="^[0-9]*$"
|
||||
while true; do
|
||||
read -p "${cyan}###### Select printer:${white} " target
|
||||
### break while loop if input is valid, else display error
|
||||
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||
error_msg "Invalid command!"
|
||||
done
|
||||
fi
|
||||
|
||||
[[ -d "${target_folders[${target}]}/.theme" ]] && rm -rf "${target_folders[${target}]}/.theme"
|
||||
|
||||
status_msg "Installing '${theme_name}' to ${target_folders[${target}]} ..."
|
||||
cd "${target_folders[${target}]}"
|
||||
|
||||
if git clone "${theme_url}" ".theme"; then
|
||||
ok_msg "Theme installation complete!"
|
||||
[[ -n ${theme_note} ]] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
|
||||
ok_msg "Please remember to delete your browser cache!\n"
|
||||
else
|
||||
error_msg "Theme installation failed!\n"
|
||||
fi
|
||||
}
|
||||
|
||||
function ms_theme_delete() {
|
||||
local theme_folders target_folders=()
|
||||
theme_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -type d -name ".theme" | sort)
|
||||
|
||||
### build target folder array
|
||||
for folder in ${theme_folders}; do
|
||||
target_folders+=("${folder}")
|
||||
done
|
||||
|
||||
if (( ${#target_folders[@]} > 0 )); then
|
||||
top_border
|
||||
echo -e "| Please select the printer you want to remove the |"
|
||||
echo -e "| theme installation from. |"
|
||||
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f2 | rev)
|
||||
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||
done
|
||||
bottom_border
|
||||
|
||||
local target re="^[0-9]*$"
|
||||
while true; do
|
||||
read -p "${cyan}###### Select printer:${white} " target
|
||||
### break while loop if input is valid, else display error
|
||||
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||
error_msg "Invalid command!"
|
||||
done
|
||||
else
|
||||
status_msg "No Themes installed!\n"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Removing ${target_folders[${target}]} ..."
|
||||
rm -rf "${target_folders[${target}]}" && ok_msg "Theme removed!\n"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_mainsail_download_url() {
|
||||
local tags latest_tag latest_url stable_tag stable_url url
|
||||
tags=$(curl -s "${MAINSAIL_TAGS}" | grep "name" | cut -d'"' -f4)
|
||||
|
||||
### latest download url including pre-releases (alpha, beta, rc)
|
||||
latest_tag=$(echo "${tags}" | head -1)
|
||||
latest_url="https://github.com/mainsail-crew/mainsail/releases/download/${latest_tag}/mainsail.zip"
|
||||
|
||||
### get stable mainsail download url
|
||||
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
|
||||
stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip"
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
if [[ ${mainsail_install_unstable} == "true" ]]; then
|
||||
url="${latest_url}"
|
||||
echo "${url}"
|
||||
else
|
||||
url="${stable_url}"
|
||||
echo "${url}"
|
||||
fi
|
||||
}
|
||||
|
||||
function mainsail_port_check() {
|
||||
if [[ ${MAINSAIL_ENABLED} == "false" ]]; then
|
||||
|
||||
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
|
||||
[[ ${FLUIDD_ENABLED} == "true" ]] && \
|
||||
echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${white}"
|
||||
|
||||
if [[ ${FLUIDD_PORT} == "80" ]]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_mainsail_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
function select_mainsail_port() {
|
||||
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||
echo -e "| ${red}You need to choose a different port for Mainsail!${white} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||
blank_line
|
||||
[[ ${FLUIDD_PORT} == "80" ]] && echo "| ● Fluidd |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to another webinterface! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
|
||||
local new_port re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||
if [[ ${new_port} =~ ${re} && ${new_port} != "${FLUIDD_PORT}" ]]; then
|
||||
select_msg "Setting port ${new_port} for Mainsail!"
|
||||
SET_LISTEN_PORT=${new_port}
|
||||
break
|
||||
else
|
||||
if [[ ! ${new_port} =~ ${re} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
else
|
||||
error_msg "Port already taken! Select a different one!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function enable_mainsail_remotemode() {
|
||||
[[ ! -f "${MAINSAIL_DIR}/config.json" ]] && return
|
||||
|
||||
rm -f "${MAINSAIL_DIR}/config.json"
|
||||
echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json"
|
||||
}
|
||||
|
||||
function patch_mainsail_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager mainsail\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Mainsails update manager section to moonraker.conf
|
||||
status_msg "Adding Mainsail to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager mainsail]
|
||||
type: web
|
||||
channel: stable
|
||||
repo: mainsail-crew/mainsail
|
||||
path: ~/mainsail
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
193
scripts/mjpg-streamer.sh
Normal file
193
scripts/mjpg-streamer.sh
Normal file
@@ -0,0 +1,193 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#============= INSTALL MJPG-STREAMER =============#
|
||||
#=================================================#
|
||||
|
||||
function install_mjpg-streamer() {
|
||||
local webcamd="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
|
||||
local webcam_txt="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
|
||||
local repo="https://github.com/jacksonliam/mjpg-streamer.git"
|
||||
local service="${KIAUH_SRCDIR}/resources/webcamd.service"
|
||||
|
||||
### return early if webcamd.service already exists
|
||||
if [[ -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
print_error "Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Initializing MJPG-Streamer installation ..."
|
||||
|
||||
### check and install dependencies if missing
|
||||
local dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg)
|
||||
if apt-cache search libjpeg62-turbo-dev | grep -Eq "^libjpeg62-turbo-dev "; then
|
||||
dep+=(libjpeg62-turbo-dev)
|
||||
elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then
|
||||
dep+=(libjpeg8-dev)
|
||||
fi
|
||||
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone mjpg-streamer
|
||||
status_msg "Cloning MJPG-Streamer from ${repo} ..."
|
||||
[[ -d "${HOME}/mjpg-streamer" ]] && rm -rf "${HOME}/mjpg-streamer"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${repo}" "${HOME}/mjpg-streamer"; then
|
||||
print_error "Cloning MJPG-Streamer from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
ok_msg "Cloning complete!"
|
||||
|
||||
### step 2: compiling mjpg-streamer
|
||||
status_msg "Compiling MJPG-Streamer ..."
|
||||
cd "${HOME}/mjpg-streamer/mjpg-streamer-experimental"
|
||||
if ! make; then
|
||||
print_error "Compiling MJPG-Streamer failed!"
|
||||
exit 1
|
||||
fi
|
||||
ok_msg "Compiling complete!"
|
||||
|
||||
#step 3: install mjpg-streamer
|
||||
status_msg "Installing MJPG-Streamer ..."
|
||||
cd "${HOME}/mjpg-streamer" && mv mjpg-streamer-experimental/* .
|
||||
mkdir www-mjpgstreamer
|
||||
|
||||
cat <<EOT >> ./www-mjpgstreamer/index.html
|
||||
<html>
|
||||
<head><title>mjpg_streamer test page</title></head>
|
||||
<body>
|
||||
<h1>Snapshot</h1>
|
||||
<p>Refresh the page to refresh the snapshot</p>
|
||||
<img src="./?action=snapshot" alt="Snapshot">
|
||||
<h1>Stream</h1>
|
||||
<img src="./?action=stream" alt="Stream">
|
||||
</body>
|
||||
</html>
|
||||
EOT
|
||||
|
||||
sudo wget "${webcamd}" -O "/usr/local/bin/webcamd"
|
||||
sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /usr/local/bin/webcamd
|
||||
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
|
||||
sudo chmod +x /usr/local/bin/webcamd
|
||||
|
||||
### step 4: create webcam.txt config file
|
||||
[[ ! -d ${KLIPPER_CONFIG} ]] && mkdir -p "${KLIPPER_CONFIG}"
|
||||
if [[ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]]; then
|
||||
status_msg "Creating webcam.txt config file ..."
|
||||
wget "${webcam_txt}" -O "${KLIPPER_CONFIG}/webcam.txt"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 5: create systemd service
|
||||
status_msg "Creating MJPG-Streamer service ..."
|
||||
sudo cp "${service}" "${SYSTEMD}/webcamd.service"
|
||||
sudo sed -i "s|%USER%|${USER}|" "${SYSTEMD}/webcamd.service"
|
||||
ok_msg "MJPG-Streamer service created!"
|
||||
|
||||
### step 6: enabling and starting mjpg-streamer service
|
||||
status_msg "Starting MJPG-Streamer service, please wait ..."
|
||||
sudo systemctl enable webcamd.service
|
||||
if sudo systemctl start webcamd.service; then
|
||||
ok_msg "MJPG-Streamer service started!"
|
||||
else
|
||||
status_msg "MJPG-Streamer service couldn't be started! No webcam connected?\n###### You need to manually restart the service once your webcam is set up correctly."
|
||||
fi
|
||||
|
||||
### step 6.1: create webcamd.log symlink
|
||||
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
|
||||
if [[ -f "/var/log/webcamd.log" && ! -L "${KLIPPER_LOGS}/webcamd.log" ]]; then
|
||||
ln -s "/var/log/webcamd.log" "${KLIPPER_LOGS}/webcamd.log"
|
||||
fi
|
||||
|
||||
### step 6.2: add webcamd.log logrotate
|
||||
if [[ ! -f "/etc/logrotate.d/webcamd" ]]; then
|
||||
status_msg "Create logrotate rule ..."
|
||||
sudo /bin/sh -c "cat > /etc/logrotate.d/webcamd" << EOF
|
||||
/var/log/webcamd.log
|
||||
{
|
||||
rotate 2
|
||||
weekly
|
||||
maxsize 32M
|
||||
missingok
|
||||
notifempty
|
||||
compress
|
||||
delaycompress
|
||||
sharedscripts
|
||||
}
|
||||
EOF
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 7: check if user is in group "video"
|
||||
local usergroup_changed="false"
|
||||
if ! groups "${USER}" | grep -q "video"; then
|
||||
status_msg "Adding user '${USER}' to group 'video' ..."
|
||||
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
|
||||
usergroup_changed="true"
|
||||
fi
|
||||
|
||||
### confirm message
|
||||
local confirm_msg="MJPG-Streamer has been set up!"
|
||||
if [[ ${usergroup_changed} == "true" ]]; then
|
||||
confirm_msg="${confirm_msg}\n ${yellow}INFO: Your User was added to a new group!${green}"
|
||||
confirm_msg="${confirm_msg}\n ${yellow}You need to relog/restart for the group to be applied!${green}"
|
||||
fi
|
||||
|
||||
print_confirm "${confirm_msg}"
|
||||
|
||||
### print webcam ip adress/url
|
||||
local ip
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
local cam_url="http://${ip}:8080/?action=stream"
|
||||
local cam_url_alt="http://${ip}/webcam/?action=stream"
|
||||
echo -e " ${cyan}● Webcam URL:${white} ${cam_url}"
|
||||
echo -e " ${cyan}● Webcam URL:${white} ${cam_url_alt}"
|
||||
echo
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#============== REMOVE MJPG-STREAMER =============#
|
||||
#=================================================#
|
||||
|
||||
function remove_mjpg-streamer() {
|
||||
### remove MJPG-Streamer service
|
||||
if [[ -e "${SYSTEMD}/webcamd.service" ]]; then
|
||||
status_msg "Removing MJPG-Streamer service ..."
|
||||
sudo systemctl stop webcamd && sudo systemctl disable webcamd
|
||||
sudo rm -f "${SYSTEMD}/webcamd.service"
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "MJPG-Streamer Service removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd from /usr/local/bin
|
||||
if [[ -e "/usr/local/bin/webcamd" ]]; then
|
||||
sudo rm -f "/usr/local/bin/webcamd"
|
||||
fi
|
||||
|
||||
### remove MJPG-Streamer directory
|
||||
if [[ -d "${HOME}/mjpg-streamer" ]]; then
|
||||
status_msg "Removing MJPG-Streamer directory ..."
|
||||
rm -rf "${HOME}/mjpg-streamer"
|
||||
ok_msg "MJPG-Streamer directory removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd log and symlink
|
||||
[[ -f "/var/log/webcamd.log" ]] && sudo rm -f "/var/log/webcamd.log"
|
||||
[[ -L "${KLIPPER_LOGS}/webcamd.log" ]] && rm -f "${KLIPPER_LOGS}/webcamd.log"
|
||||
|
||||
print_confirm "MJPG-Streamer successfully removed!"
|
||||
}
|
||||
486
scripts/moonraker-telegram-bot.sh
Normal file
486
scripts/moonraker-telegram-bot.sh
Normal file
@@ -0,0 +1,486 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#========== INSTALL MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function telegram_bot_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function telegram_bot_setup_dialog() {
|
||||
### return early if moonraker is not installed
|
||||
local moonraker_services
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
|
||||
if [[ -z ${moonraker_services} ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
status_msg "Initializing Telegram Bot installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
local moonraker_count user_input=() moonraker_names=()
|
||||
moonraker_count=$(echo "${moonraker_services}" | wc -w )
|
||||
for service in ${moonraker_services}; do
|
||||
moonraker_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local telegram_bot_count
|
||||
if (( moonraker_count == 1 )); then
|
||||
ok_msg "Moonraker installation found!\n"
|
||||
telegram_bot_count=1
|
||||
elif (( moonraker_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${moonraker_count} Moonraker instances found!"
|
||||
for name in "${moonraker_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● ${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to Telegram Bot! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of Telegram Bot instances to |"
|
||||
echo -e "| install. Usually one Telegram Bot instance per |"
|
||||
echo -e "| Moonraker instance is required, but you may not |"
|
||||
echo -e "| install more Telegram Bot instances than available |"
|
||||
echo -e "| Moonraker instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${telegram_bot_count} =~ ${re} || ${telegram_bot_count} -gt ${moonraker_count} ]]; do
|
||||
read -p "${cyan}###### Number of Telegram Bot instances to set up:${white} " -i "${moonraker_count}" -e telegram_bot_count
|
||||
### break if input is valid
|
||||
[[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${telegram_bot_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( telegram_bot_count > moonraker_count )) && error_msg "Number of Telegram Bot instances larger than existing Moonraker instances"
|
||||
done && select_msg "${telegram_bot_count}"
|
||||
else
|
||||
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${telegram_bot_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( telegram_bot_count == 1 )) && local question="Install Telegram Bot?"
|
||||
(( telegram_bot_count > 1 )) && local question="Install ${telegram_bot_count} Telegram Bot instances?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting Telegram Bot setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for moonraker
|
||||
if (( moonraker_count > 1 )); then
|
||||
for name in "${moonraker_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( telegram_bot_count > 1 )) && status_msg "Installing ${telegram_bot_count} Telegram Bot instances ..."
|
||||
(( telegram_bot_count == 1 )) && status_msg "Installing Telegram Bot ..."
|
||||
telegram_bot_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_telegram_bot_dependencies() {
|
||||
local packages
|
||||
local install_script="${TELEGRAM_BOT_DIR}/scripts/install.sh"
|
||||
|
||||
### read PKGLIST from official install-script
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Updating package lists..."
|
||||
if ! sudo apt-get update --allow-releaseinfo-change; then
|
||||
log_error "failure while updating package lists"
|
||||
error_msg "Updating package lists failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Install required packages
|
||||
status_msg "Installing required packages..."
|
||||
if ! sudo apt-get install --yes "${packages[@]}"; then
|
||||
log_error "failure while installing required moonraker-telegram-bot packages"
|
||||
error_msg "Installing required packages failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_bot_virtualenv() {
|
||||
status_msg "Installing python virtual environment..."
|
||||
### always create a clean virtualenv
|
||||
[[ -d ${TELEGRAM_BOT_ENV} ]] && rm -rf "${TELEGRAM_BOT_ENV}"
|
||||
if virtualenv -p /usr/bin/python3 --system-site-packages "${TELEGRAM_BOT_ENV}"; then
|
||||
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
|
||||
else
|
||||
log_error "failure while creating python3 moonraker-telegram-bot-env"
|
||||
error_msg "Creation of Moonraker Telegram Bot virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function telegram_bot_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### checking dependencies
|
||||
local dep=(git virtualenv)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone telegram bot
|
||||
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
|
||||
|
||||
### step 2: install telegram bot dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_telegram_bot_dependencies
|
||||
create_telegram_bot_virtualenv
|
||||
|
||||
### step 3: create telegram.conf
|
||||
create_telegram_conf "${instance_arr[@]}"
|
||||
|
||||
### step 4: create telegram bot instances
|
||||
create_telegram_bot_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: add telegram-bot to the update manager in moonraker.conf
|
||||
patch_telegram_bot_update_manager
|
||||
|
||||
### step 6: enable and start all instances
|
||||
do_action_service "enable" "moonraker-telegram-bot"
|
||||
do_action_service "start" "moonraker-telegram-bot"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Telegram Bot has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Telegram Bot instances have been set up!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
function clone_telegram_bot() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning Moonraker-Telegram-Bot from ${repo} ..."
|
||||
### force remove existing Moonraker-Telegram-Bot dir
|
||||
[[ -d ${repo} ]] && rm -rf "${TELEGRAM_BOT_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${repo}" "${TELEGRAM_BOT_DIR}"; then
|
||||
print_error "Cloning Moonraker-Telegram-Bot from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_conf() {
|
||||
local input=("${@}")
|
||||
local telegram_bot_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local log="${KLIPPER_LOGS}"
|
||||
local cfg cfg_dir
|
||||
|
||||
if (( telegram_bot_count == 1 )); then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
### write single instance config
|
||||
write_telegram_conf "${cfg_dir}" "${cfg}" "${log}"
|
||||
|
||||
elif (( telegram_bot_count > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= telegram_bot_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
|
||||
### write multi instance config
|
||||
write_telegram_conf "${cfg_dir}" "${cfg}" "${log}"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_telegram_conf() {
|
||||
local cfg_dir=${1} cfg=${2} log=${3}
|
||||
local conf_template="${TELEGRAM_BOT_DIR}/scripts/base_install_template"
|
||||
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating telegram.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
sed -i "s|some_log_path|${log}|g" "${cfg}"
|
||||
ok_msg "telegram.conf created!"
|
||||
else
|
||||
status_msg "File '${cfg}' already exists!\nSkipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_bot_service() {
|
||||
local input=("${@}")
|
||||
local instances=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local cfg_dir cfg log service
|
||||
|
||||
if (( instances == 1 )); then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log="${KLIPPER_LOGS}/telegram.log"
|
||||
service="${SYSTEMD}/moonraker-telegram-bot.service"
|
||||
### write single instance service
|
||||
write_telegram_bot_service "" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Single Telegram Bot instance created!"
|
||||
|
||||
elif (( instances > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= instances; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log="${KLIPPER_LOGS}/telegram-${names[${j}]}.log"
|
||||
service="${SYSTEMD}/moonraker-telegram-bot-${names[${j}]}.service"
|
||||
### write multi instance service
|
||||
write_telegram_bot_service "${names[${j}]}" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Telegram Bot instance moonraker-telegram-bot-${names[${j}]} created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_telegram_bot_service() {
|
||||
local i=${1} cfg=${2} log=${3} service=${4}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.service"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Telegram Bot Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
[[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%DIR%|${TELEGRAM_BOT_DIR}|" "${service}"
|
||||
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#===================================================#
|
||||
#=========== REMOVE MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function remove_telegram_bot_systemd() {
|
||||
[[ -z $(telegram_bot_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Telegram Bot Systemd Services ..."
|
||||
for service in $(telegram_bot_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Telegram Bot Services removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_dir() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Moonraker-Telegram-Bot directory ..."
|
||||
rm -rf "${TELEGRAM_BOT_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_env() {
|
||||
[[ ! -d ${TELEGRAM_BOT_ENV} ]] && return
|
||||
|
||||
status_msg "Removing moonraker-telegram-bot-env directory ..."
|
||||
rm -rf "${TELEGRAM_BOT_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_logs() {
|
||||
local files regex="telegram(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_telegram_bot() {
|
||||
remove_telegram_bot_systemd
|
||||
remove_telegram_bot_dir
|
||||
remove_telegram_bot_env
|
||||
remove_telegram_bot_logs
|
||||
|
||||
local confirm="Moonraker-Telegram-Bot was successfully removed!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== UPDATE MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function update_telegram_bot() {
|
||||
do_action_service "stop" "moonraker-telegram-bot"
|
||||
|
||||
if [[ ! -d ${TELEGRAM_BOT_DIR} ]]; then
|
||||
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker-telegram-bot"
|
||||
status_msg "Updating Moonraker ..."
|
||||
cd "${TELEGRAM_BOT_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_telegram_bot_dependencies
|
||||
### install possible new python dependencies
|
||||
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "moonraker-telegram-bot"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== MOONRAKERTELEGRAMBOT STATUS ===========#
|
||||
#===================================================#
|
||||
|
||||
function get_telegram_bot_status() {
|
||||
local sf_count status
|
||||
sf_count="$(telegram_bot_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${TELEGRAM_BOT_DIR}" "${TELEGRAM_BOT_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed: ${sf_count}"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_telegram_bot_commit() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${TELEGRAM_BOT_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_telegram_bot_commit() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${TELEGRAM_BOT_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_telegram_bot_versions() {
|
||||
unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_telegram_bot_commit)"
|
||||
remote_ver="$(get_remote_telegram_bot_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker-telegram-bot to the update all array for the update all function in the updater
|
||||
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_telegram_bot)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_telegram_bot_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager moonraker-telegram-bot\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Moonraker-Telegram-Bot update manager section to moonraker.conf
|
||||
status_msg "Adding Moonraker-Telegram-Bot to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager moonraker-telegram-bot]
|
||||
type: git_repo
|
||||
path: ~/moonraker-telegram-bot
|
||||
origin: https://github.com/nlef/moonraker-telegram-bot.git
|
||||
env: ~/moonraker-telegram-bot-env/bin/python
|
||||
requirements: scripts/requirements.txt
|
||||
install_script: scripts/install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
577
scripts/moonraker.sh
Normal file
577
scripts/moonraker.sh
Normal file
@@ -0,0 +1,577 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================ INSTALL MOONRAKER ================#
|
||||
#===================================================#
|
||||
|
||||
function moonraker_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function moonraker_setup_dialog() {
|
||||
status_msg "Initializing Moonraker installation ..."
|
||||
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### return early if moonraker already exists
|
||||
local moonraker_services
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
if [[ -n ${moonraker_services} ]]; then
|
||||
local error="At least one Moonraker service is already installed:"
|
||||
for s in ${moonraker_services}; do
|
||||
log_info "Found Moonraker service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### return early if klipper is not installed
|
||||
local klipper_services
|
||||
klipper_services=$(klipper_systemd)
|
||||
if [[ -z ${klipper_services} ]]; then
|
||||
local error="Klipper not installed! Please install Klipper first!"
|
||||
log_error "Moonraker setup started without Klipper being installed. Aborting setup."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
local klipper_count user_input=() klipper_names=()
|
||||
klipper_count=$(echo "${klipper_services}" | wc -w )
|
||||
for service in ${klipper_services}; do
|
||||
klipper_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local moonraker_count
|
||||
if (( klipper_count == 1 )); then
|
||||
ok_msg "Klipper installation found!\n"
|
||||
moonraker_count=1
|
||||
elif (( klipper_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
|
||||
for name in "${klipper_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● klipper-${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to Moonraker! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of Moonraker instances to |"
|
||||
echo -e "| install. Usually one Moonraker instance per Klipper |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| Moonraker instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${moonraker_count} =~ ${re} || ${moonraker_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count
|
||||
### break if input is valid
|
||||
[[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${moonraker_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( moonraker_count > klipper_count )) && error_msg "Number of Moonraker instances larger than installed Klipper instances"
|
||||
done && select_msg "${moonraker_count}"
|
||||
else
|
||||
log_error "Internal error. klipper_count of '${klipper_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${moonraker_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( moonraker_count == 1 )) && local question="Install Moonraker?"
|
||||
(( moonraker_count > 1 )) && local question="Install ${moonraker_count} Moonraker instances?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting Moonraker setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for moonraker
|
||||
if (( klipper_count > 1 )); then
|
||||
for name in "${klipper_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( moonraker_count > 1 )) && status_msg "Installing ${moonraker_count} Moonraker instances ..."
|
||||
(( moonraker_count == 1 )) && status_msg "Installing Moonraker ..."
|
||||
moonraker_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_moonraker_dependencies() {
|
||||
local packages
|
||||
local install_script="${MOONRAKER_DIR}/scripts/install-moonraker.sh"
|
||||
|
||||
### read PKGLIST from official install-script
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Updating package lists..."
|
||||
if ! sudo apt-get update --allow-releaseinfo-change; then
|
||||
log_error "failure while updating package lists"
|
||||
error_msg "Updating package lists failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Install required packages
|
||||
status_msg "Installing required packages..."
|
||||
if ! sudo apt-get install --yes "${packages[@]}"; then
|
||||
log_error "failure while installing required moonraker packages"
|
||||
error_msg "Installing required packages failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_virtualenv() {
|
||||
status_msg "Installing python virtual environment..."
|
||||
|
||||
### always create a clean virtualenv
|
||||
[[ -d ${MOONRAKER_ENV} ]] && rm -rf "${MOONRAKER_ENV}"
|
||||
|
||||
if virtualenv -p /usr/bin/python3 "${MOONRAKER_ENV}"; then
|
||||
"${MOONRAKER_ENV}"/bin/pip install -U pip
|
||||
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
|
||||
else
|
||||
log_error "failure while creating python3 moonraker-env"
|
||||
error_msg "Creation of Moonraker virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function moonraker_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### checking dependencies
|
||||
local dep=(git wget curl unzip dfu-util virtualenv)
|
||||
### additional required dependencies on armbian
|
||||
dep+=(libjpeg-dev zlib1g-dev)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone moonraker
|
||||
clone_moonraker "${MOONRAKER_REPO}"
|
||||
|
||||
### step 2: install moonraker dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_moonraker_dependencies
|
||||
create_moonraker_virtualenv
|
||||
|
||||
### step 3: create moonraker.conf
|
||||
create_moonraker_conf "${instance_arr[@]}"
|
||||
|
||||
### step 4: create moonraker instances
|
||||
create_moonraker_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: create polkit rules for moonraker
|
||||
moonraker_polkit || true
|
||||
|
||||
### step 6: enable and start all instances
|
||||
do_action_service "enable" "moonraker"
|
||||
do_action_service "start" "moonraker"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Moonraker has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Moonraker instances have been set up!"
|
||||
print_confirm "${confirm}" && print_mr_ip_list "${instance_arr[0]}" && return
|
||||
}
|
||||
|
||||
function clone_moonraker() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning Moonraker from ${repo} ..."
|
||||
|
||||
### force remove existing moonraker dir and clone into fresh moonraker dir
|
||||
[[ -d ${MOONRAKER_DIR} ]] && rm -rf "${MOONRAKER_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${MOONRAKER_REPO}" "${MOONRAKER_DIR}"; then
|
||||
print_error "Cloning Moonraker from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_conf() {
|
||||
local input=("${@}")
|
||||
local moonraker_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local log="${KLIPPER_LOGS}"
|
||||
local lan
|
||||
lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
|
||||
local port=7125 cfg_dir cfg db uds
|
||||
|
||||
if (( moonraker_count == 1 )); then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
db="${HOME}/.moonraker_database"
|
||||
uds="/tmp/klippy_uds"
|
||||
### write single instance config
|
||||
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}"
|
||||
|
||||
elif (( moonraker_count > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= moonraker_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
uds="/tmp/klippy_uds-${names[${j}]}"
|
||||
db="${HOME}/.moonraker_database_${names[${j}]}"
|
||||
### write multi instance config
|
||||
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}"
|
||||
port=$(( port + 1 ))
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_moonraker_conf() {
|
||||
local cfg_dir=${1} cfg=${2} port=${3} log=${4} db=${5} uds=${6} lan=${7}
|
||||
local conf_template="${KIAUH_SRCDIR}/resources/moonraker.conf"
|
||||
|
||||
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating moonraker.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
sed -i "s|%USER%|${USER}|g" "${cfg}"
|
||||
sed -i "s|%CFG%|${cfg_dir}|; s|%PORT%|${port}|; s|%LOG%|${log}|; s|%DB%|${db}|; s|%UDS%|${uds}|" "${cfg}"
|
||||
# if host ip is not in the default ip ranges replace placeholder,
|
||||
# otherwise remove placeholder from config
|
||||
if ! grep -q "${lan}" "${cfg}"; then
|
||||
sed -i "s|%LAN%|${lan}|" "${cfg}"
|
||||
else
|
||||
sed -i "/%LAN%/d" "${cfg}"
|
||||
fi
|
||||
ok_msg "moonraker.conf created!"
|
||||
else
|
||||
status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_service() {
|
||||
local input=("${@}")
|
||||
local moonraker_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local cfg_dir cfg log service
|
||||
|
||||
if (( moonraker_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
|
||||
i=""
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
log="${KLIPPER_LOGS}/moonraker.log"
|
||||
service="${SYSTEMD}/moonraker.service"
|
||||
### write single instance service
|
||||
write_moonraker_service "" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Moonraker instance created!"
|
||||
|
||||
elif (( moonraker_count > 1 )) && [[ ${#names[@]} -gt 0 ]]; then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= moonraker_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
log="${KLIPPER_LOGS}/moonraker-${names[${j}]}.log"
|
||||
service="${SYSTEMD}/moonraker-${names[${j}]}.service"
|
||||
### write multi instance service
|
||||
write_moonraker_service "${names[${j}]}" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Moonraker instance 'moonraker-${names[${j}]}' created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset i
|
||||
|
||||
### enable mainsails remoteMode if mainsail is found
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
status_msg "Mainsail installation found! Enabling Mainsail remote mode ..."
|
||||
enable_mainsail_remotemode
|
||||
ok_msg "Mainsails remote mode enabled!"
|
||||
fi
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_moonraker_service() {
|
||||
local i=${1} cfg=${2} log=${3} service=${4}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker.service"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Moonraker Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
|
||||
[[ -z ${i} ]] && sudo sed -i "s| for instance moonraker-%INST%||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}"
|
||||
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
function print_mr_ip_list() {
|
||||
local ip count=${1} port=7125
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
for (( i=1; i <= count; i++ )); do
|
||||
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
|
||||
port=$(( port + 1 ))
|
||||
done && echo
|
||||
}
|
||||
|
||||
### introduced due to
|
||||
### https://github.com/Arksine/moonraker/issues/349
|
||||
### https://github.com/Arksine/moonraker/pull/346
|
||||
function moonraker_polkit() {
|
||||
local has_sup
|
||||
|
||||
### check for required SupplementaryGroups entry in service files
|
||||
### write it to the service if it doesn't exist
|
||||
for service in $(moonraker_systemd); do
|
||||
has_sup="$(grep "SupplementaryGroups=moonraker-admin" "${service}")"
|
||||
if [[ -z ${has_sup} ]]; then
|
||||
status_msg "Adding moonraker-admin supplementary group to ${service} ..."
|
||||
sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "${service}"
|
||||
ok_msg "Adding moonraker-admin supplementary group successfull!"
|
||||
fi
|
||||
done
|
||||
|
||||
[[ -z ${has_sup} ]] && echo "reloading services!!!" && sudo systemctl daemon-reload
|
||||
|
||||
### execute moonrakers policykit-rules script
|
||||
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ REMOVE MOONRAKER ================#
|
||||
#==================================================#
|
||||
|
||||
function remove_moonraker_sysvinit() {
|
||||
[[ ! -e "${INITD}/moonraker" ]] && return
|
||||
|
||||
status_msg "Removing Moonraker SysVinit service ..."
|
||||
sudo systemctl stop moonraker
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -f "${INITD}/moonraker" "${ETCDEF}/moonraker"
|
||||
ok_msg "Moonraker SysVinit service removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_systemd() {
|
||||
[[ -z $(moonraker_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Moonraker Systemd Services ..."
|
||||
|
||||
for service in $(moonraker_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Moonraker Services removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_logs() {
|
||||
local files regex="moonraker(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_moonraker_api_key() {
|
||||
### remove legacy api key
|
||||
if [[ -e "${HOME}/.klippy_api_key" ]]; then
|
||||
status_msg "Removing legacy API Key ..."
|
||||
rm "${HOME}/.klippy_api_key"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### remove api key
|
||||
if [[ -e "${HOME}/.moonraker_api_key" ]]; then
|
||||
status_msg "Removing API Key ..."
|
||||
rm "${HOME}/.moonraker_api_key"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_moonraker_dir() {
|
||||
[[ ! -d ${MOONRAKER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Moonraker directory ..."
|
||||
rm -rf "${MOONRAKER_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_env() {
|
||||
[[ ! -d ${MOONRAKER_ENV} ]] && return
|
||||
|
||||
status_msg "Removing moonraker-env directory ..."
|
||||
rm -rf "${MOONRAKER_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_polkit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing all Moonraker PolicyKit rules ..."
|
||||
"${MOONRAKER_DIR}"/scripts/set-policykit-rules.sh --clear
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function remove_moonraker() {
|
||||
remove_moonraker_sysvinit
|
||||
remove_moonraker_systemd
|
||||
remove_moonraker_logs
|
||||
remove_moonraker_api_key
|
||||
remove_moonraker_polkit
|
||||
remove_moonraker_dir
|
||||
remove_moonraker_env
|
||||
|
||||
print_confirm "Moonraker was successfully removed!"
|
||||
return
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ UPDATE MOONRAKER ================#
|
||||
#==================================================#
|
||||
|
||||
function update_moonraker() {
|
||||
do_action_service "stop" "moonraker"
|
||||
|
||||
if [[ ! -d ${MOONRAKER_DIR} ]]; then
|
||||
clone_moonraker "${MOONRAKER_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker"
|
||||
status_msg "Updating Moonraker ..."
|
||||
cd "${MOONRAKER_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_moonraker_dependencies
|
||||
### install possible new python dependencies
|
||||
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
|
||||
fi
|
||||
|
||||
### required due to https://github.com/Arksine/moonraker/issues/349
|
||||
moonraker_polkit
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ MOONRAKER STATUS ================#
|
||||
#==================================================#
|
||||
|
||||
function get_moonraker_status() {
|
||||
local sf_count status
|
||||
sf_count="$(moonraker_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${MOONRAKER_DIR}" "${MOONRAKER_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed: ${sf_count}"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_moonraker_commit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOONRAKER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_moonraker_commit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOONRAKER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_moonraker_versions() {
|
||||
unset MOONRAKER_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_moonraker_commit)"
|
||||
remote_ver="$(get_remote_moonraker_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to the update all array for the update all function in the updater
|
||||
MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
MOONRAKER_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
set_nginx_cfg(){
|
||||
if [ "$SET_NGINX_CFG" = "true" ]; then
|
||||
#check for dependencies
|
||||
dep=(nginx)
|
||||
dependency_check
|
||||
#execute operations
|
||||
status_msg "Creating Nginx configuration for $1 ..."
|
||||
#copy content from resources to the respective nginx config file
|
||||
cat ${SRCDIR}/kiauh/resources/$1_nginx.cfg > ${SRCDIR}/kiauh/resources/$1
|
||||
##edit the nginx config file before moving it
|
||||
if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then
|
||||
status_msg "Configuring port for $1 ..."
|
||||
#set listen port ipv4
|
||||
sed -i "s/listen\s[0-9]*;/listen $SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1
|
||||
#set listen port ipv6
|
||||
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1
|
||||
fi
|
||||
#set correct user
|
||||
if [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
|
||||
sudo sed -i "/root/s/pi/${USER}/" ${SRCDIR}/kiauh/resources/$1
|
||||
fi
|
||||
#moving the config file into correct directory
|
||||
sudo mv ${SRCDIR}/kiauh/resources/$1 /etc/nginx/sites-available/$1
|
||||
ok_msg "Nginx configuration for $1 was set!"
|
||||
if [ "$SET_LISTEN_PORT" != "" ]; then
|
||||
ok_msg "$1 listening on port $SET_LISTEN_PORT!"
|
||||
else
|
||||
ok_msg "$1 listening on default port $DEFAULT_PORT!"
|
||||
fi
|
||||
#remove nginx default config
|
||||
[ -e /etc/nginx/sites-enabled/default ] && sudo rm /etc/nginx/sites-enabled/default
|
||||
#create symlink for own sites
|
||||
[ ! -e /etc/nginx/sites-enabled/$1 ] && sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/
|
||||
restart_nginx
|
||||
fi
|
||||
}
|
||||
|
||||
read_listen_port(){
|
||||
LISTEN_PORT=$(grep listen /etc/nginx/sites-enabled/$1 | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
}
|
||||
|
||||
detect_enabled_sites(){
|
||||
#check if there is another UI config already installed
|
||||
#and reads the port they are listening on
|
||||
if [ -e /etc/nginx/sites-enabled/mainsail ]; then
|
||||
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
|
||||
read_listen_port "mainsail"
|
||||
MAINSAIL_PORT=$LISTEN_PORT
|
||||
#echo "debug: Mainsail listens on port: $MAINSAIL_PORT"
|
||||
else
|
||||
MAINSAIL_ENABLED="false"
|
||||
fi
|
||||
if [ -e /etc/nginx/sites-enabled/fluidd ]; then
|
||||
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
|
||||
read_listen_port "fluidd"
|
||||
FLUIDD_PORT=$LISTEN_PORT
|
||||
#echo "debug: Fluidd listens on port: $FLUIDD_PORT"
|
||||
else
|
||||
FLUIDD_ENABLED="false"
|
||||
fi
|
||||
if [ -e /etc/nginx/sites-enabled/dwc2 ]; then
|
||||
SITE_ENABLED="true" && DWC2_ENABLED="true"
|
||||
read_listen_port "dwc2"
|
||||
DWC2_PORT=$LISTEN_PORT
|
||||
#echo "debug: DWC2 listens on port: $DWC2_PORT"
|
||||
else
|
||||
DWC2_ENABLED="false"
|
||||
fi
|
||||
if [ -e /etc/nginx/sites-enabled/octoprint ]; then
|
||||
SITE_ENABLED="true" && OCTOPRINT_ENABLED="true"
|
||||
read_listen_port "octoprint"
|
||||
OCTOPRINT_PORT=$LISTEN_PORT
|
||||
#echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT"
|
||||
else
|
||||
OCTOPRINT_ENABLED="false"
|
||||
fi
|
||||
}
|
||||
|
||||
create_custom_hostname(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| You can change the hostname of this machine to use |"
|
||||
echo -e "| that name to open the Interface in your browser. |"
|
||||
echo -e "| |"
|
||||
echo -e "| E.g.: If you set the hostname to 'my-printer' you |"
|
||||
echo -e "| can open DWC2/Mainsail/Fluidd/Octoprint by |"
|
||||
echo -e "| browsing to: http://my-printer.local |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to change the hostname? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
user_input_hostname
|
||||
break;;
|
||||
N|n|No|no|"") break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
user_input_hostname(){
|
||||
unset NEW_HOSTNAME
|
||||
unset HOSTNAME_VALID
|
||||
unset HOSTENAME_CONFIRM
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |"
|
||||
echo -e "| ${red}No special characters allowed!${default} |"
|
||||
echo -e "| ${red}No leading or trailing '-' allowed!${default} |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Please set the new hostname:${default} " NEW_HOSTNAME
|
||||
if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then
|
||||
ok_msg "'$NEW_HOSTNAME' is a valid hostname!"
|
||||
HOSTNAME_VALID="true"
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
HOSTENAME_CONFIRM="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
echo -e "${red}Skip hostname change ...${default}"
|
||||
HOSTENAME_CONFIRM="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
break
|
||||
else
|
||||
warn_msg "'$NEW_HOSTNAME' is not a valid hostname!"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
set_hostname(){
|
||||
if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then
|
||||
#check for dependencies
|
||||
dep=(avahi-daemon)
|
||||
dependency_check
|
||||
#execute operations
|
||||
#get current hostname and write to variable
|
||||
HOSTNAME=$(hostname)
|
||||
#create host file if missing or create backup of existing one with current date&time
|
||||
if [ -f /etc/hosts ]; then
|
||||
status_msg "Creating backup of hosts file ..."
|
||||
get_date
|
||||
sudo cp /etc/hosts /etc/hosts."$current_date".bak
|
||||
ok_msg "Backup done!"
|
||||
ok_msg "File:'/etc/hosts."$current_date".bak'"
|
||||
else
|
||||
sudo touch /etc/hosts
|
||||
fi
|
||||
#set hostname in /etc/hostname
|
||||
status_msg "Setting hostname to '$NEW_HOSTNAME' ..."
|
||||
status_msg "Please wait ..."
|
||||
sudo hostnamectl set-hostname "$NEW_HOSTNAME"
|
||||
#write new hostname to /etc/hosts
|
||||
status_msg "Writing new hostname to /etc/hosts ..."
|
||||
echo "127.0.0.1 $NEW_HOSTNAME" | sudo tee -a /etc/hosts &>/dev/null
|
||||
ok_msg "New hostname successfully configured!"
|
||||
ok_msg "Remember to reboot for the changes to take effect!"
|
||||
fi
|
||||
}
|
||||
347
scripts/nginx.sh
Normal file
347
scripts/nginx.sh
Normal file
@@ -0,0 +1,347 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#=================== REMOVE NGINX ==================#
|
||||
#===================================================#
|
||||
|
||||
function remove_nginx() {
|
||||
if [[ $(dpkg -s nginx 2>/dev/null | grep "Status") = *\ installed ]]; then
|
||||
status_msg "Stopping NGINX service ..."
|
||||
if systemctl is-active nginx -q; then
|
||||
sudo systemctl stop nginx && ok_msg "Service stopped!"
|
||||
else
|
||||
warn_msg "NGINX service not active!"
|
||||
fi
|
||||
|
||||
status_msg "Removing NGINX from system ..."
|
||||
if sudo apt-get remove nginx -y && sudo update-rc.d -f nginx remove; then
|
||||
ok_msg "NGINX removed!"
|
||||
else
|
||||
error_msg "Removing NGINX from system failed!"
|
||||
fi
|
||||
else
|
||||
print_error "Looks like Nginx was already removed!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#===================== HELPERS =====================#
|
||||
#===================================================#
|
||||
|
||||
function set_upstream_nginx_cfg() {
|
||||
local current_date
|
||||
local upstreams="${NGINX_CONFD}/upstreams.conf"
|
||||
local common_vars="${NGINX_CONFD}/common_vars.conf"
|
||||
|
||||
current_date=$(get_date)
|
||||
|
||||
### backup existing nginx configs
|
||||
[[ ! -d "${BACKUP_DIR}/nginx_cfg" ]] && mkdir -p "${BACKUP_DIR}/nginx_cfg"
|
||||
|
||||
if [[ -f ${upstreams} ]]; then
|
||||
sudo mv "${upstreams}" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf"
|
||||
fi
|
||||
|
||||
if [[ -f ${common_vars} ]]; then
|
||||
sudo mv "${common_vars}" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf"
|
||||
fi
|
||||
|
||||
### transfer ownership of backed up files from root to ${USER}
|
||||
local files
|
||||
files=$(find "${BACKUP_DIR}/nginx_cfg")
|
||||
|
||||
for file in ${files}; do
|
||||
if [[ $(stat -c "%U" "${file}") != "${USER}" ]]; then
|
||||
log_info "chown for user: ${USER} on file: ${file}"
|
||||
sudo chown "${USER}" "${file}"
|
||||
fi
|
||||
done
|
||||
|
||||
### copy nginx configs to target destination
|
||||
[[ ! -f ${upstreams} ]] && sudo cp "${RESOURCES}/upstreams.conf" "${upstreams}"
|
||||
[[ ! -f ${common_vars} ]] && sudo cp "${RESOURCES}/common_vars.conf" "${common_vars}"
|
||||
}
|
||||
|
||||
function symlink_webui_nginx_log() {
|
||||
local interface=${1} path="${KLIPPER_LOGS}"
|
||||
local access_log="/var/log/nginx/${interface}-access.log"
|
||||
local error_log="/var/log/nginx/${interface}-error.log"
|
||||
|
||||
[[ ! -d ${path} ]] && mkdir -p "${path}"
|
||||
|
||||
if [[ -f ${access_log} && ! -L "${path}/${interface}-access.log" ]]; then
|
||||
status_msg "Creating symlink for ${access_log} ..."
|
||||
ln -s "${access_log}" "${path}"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
if [[ -f ${error_log} && ! -L "${path}/${interface}-error.log" ]]; then
|
||||
status_msg "Creating symlink for ${error_log} ..."
|
||||
ln -s "${error_log}" "${path}"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
function match_nginx_configs() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local require_service_restart="false"
|
||||
local upstreams="${NGINX_CONFD}/upstreams.conf"
|
||||
local common_vars="${NGINX_CONFD}/common_vars.conf"
|
||||
local mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail"
|
||||
local fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd"
|
||||
local upstreams_webcams mainsail_webcams fluidd_webcams
|
||||
|
||||
### reinstall nginx configs if the amount of upstreams don't match anymore
|
||||
upstreams_webcams=$(grep -Ec "mjpgstreamer" "/etc/nginx/conf.d/upstreams.conf")
|
||||
mainsail_webcams=$(grep -Ec "mjpgstreamer" "${mainsail_nginx_cfg}" 2>/dev/null || echo "0")
|
||||
fluidd_webcams=$(grep -Ec "mjpgstreamer" "${fluidd_nginx_cfg}" 2>/dev/null || echo "0")
|
||||
|
||||
status_msg "Checking validity of NGINX configurations ..."
|
||||
|
||||
### check for outdated upstreams.conf
|
||||
if (( upstreams_webcams < mainsail_webcams || upstreams_webcams < fluidd_webcams )); then
|
||||
status_msg "Outdated upstreams.conf found! Updating ..."
|
||||
|
||||
sudo rm -f "${upstreams}" "${common_vars}"
|
||||
set_upstream_nginx_cfg
|
||||
|
||||
require_service_restart="true"
|
||||
fi
|
||||
|
||||
### check for outdated mainsail config
|
||||
if [[ -e ${mainsail_nginx_cfg} ]] && (( upstreams_webcams > mainsail_webcams )); then
|
||||
status_msg "Outdated Mainsail config found! Updating ..."
|
||||
|
||||
sudo rm -f "${mainsail_nginx_cfg}"
|
||||
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "s/<<UI>>/mainsail/g" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}"
|
||||
|
||||
require_service_restart="true"
|
||||
fi
|
||||
|
||||
### check for outdated fluidd config
|
||||
if [[ -e ${fluidd_nginx_cfg} ]] && (( upstreams_webcams > fluidd_webcams )); then
|
||||
status_msg "Outdated Fluidd config found! Updating ..."
|
||||
|
||||
sudo rm -f "${fluidd_nginx_cfg}"
|
||||
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "s/<<UI>>/fluidd/g" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}"
|
||||
|
||||
require_service_restart="true"
|
||||
fi
|
||||
|
||||
### only restart nginx if configs were updated
|
||||
if [[ ${require_service_restart} == "true" ]]; then
|
||||
sudo systemctl restart nginx.service
|
||||
fi
|
||||
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function remove_conflicting_packages() {
|
||||
local apache=${1} haproxy=${2}
|
||||
|
||||
### disable services before removing them
|
||||
disable_conflicting_packages "${apache}" "${haproxy}"
|
||||
|
||||
if [[ ${apache} == "true" ]]; then
|
||||
status_msg "Removing Apache2 from system ..."
|
||||
if sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove; then
|
||||
ok_msg "Apache2 removed!"
|
||||
else
|
||||
error_msg "Removing Apache2 from system failed!"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${haproxy} == "true" ]]; then
|
||||
status_msg "Removing haproxy from system ..."
|
||||
if sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove; then
|
||||
ok_msg "Haproxy removed!"
|
||||
else
|
||||
error_msg "Removing Haproxy from system failed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function disable_conflicting_packages() {
|
||||
local apache=${1} haproxy=${2}
|
||||
|
||||
if [[ ${apache} == "true" ]]; then
|
||||
status_msg "Stopping Apache2 service ..."
|
||||
if systemctl is-active apache2 -q; then
|
||||
sudo systemctl stop apache2 && ok_msg "Service stopped!"
|
||||
else
|
||||
warn_msg "Apache2 service not active!"
|
||||
fi
|
||||
|
||||
status_msg "Disabling Apache2 service ..."
|
||||
if sudo systemctl disable apache2; then
|
||||
ok_msg "Apache2 service disabled!"
|
||||
else
|
||||
error_msg "Disabling Apache2 service failed!"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${haproxy} == "true" ]]; then
|
||||
status_msg "Stopping Haproxy service ..."
|
||||
if systemctl is-active haproxy -q; then
|
||||
sudo systemctl stop haproxy && ok_msg "Service stopped!"
|
||||
else
|
||||
warn_msg "Haproxy service not active!"
|
||||
fi
|
||||
|
||||
status_msg "Disabling Haproxy service ..."
|
||||
if sudo systemctl disable haproxy; then
|
||||
ok_msg "Haproxy service disabled!"
|
||||
else
|
||||
error_msg "Disabling Haproxy service failed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function detect_conflicting_packages() {
|
||||
local apache="false" haproxy="false"
|
||||
|
||||
### check system for an installed apache2 service
|
||||
[[ $(dpkg -s apache2 2>/dev/null | grep "Status") = *\ installed ]] && apache="true"
|
||||
### check system for an installed haproxy service
|
||||
[[ $(dpkg -s haproxy 2>/dev/null | grep "Status") = *\ installed ]] && haproxy="true"
|
||||
|
||||
#notify user about haproxy or apache2 services found and possible issues
|
||||
if [[ ${haproxy} == "false" && ${apache} == "false" ]]; then
|
||||
return
|
||||
else
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}Conflicting package installations found:${white} |"
|
||||
[[ ${apache} == "true" ]] && \
|
||||
echo -e "| ${red}● apache2${white} |"
|
||||
[[ ${haproxy} == "true" ]] && \
|
||||
echo -e "| ${red}● haproxy${white} |"
|
||||
blank_line
|
||||
echo -e "| Having those packages installed can lead to unwanted |"
|
||||
echo -e "| behaviour. It's recommended to remove those packages. |"
|
||||
echo -e "| |"
|
||||
echo -e "| ${green}1) Remove packages (recommend)${white} |"
|
||||
echo -e "| 2) Disable only (may still cause issues) |"
|
||||
echo -e "| ${red}3) Skip this step (not recommended)${white} |"
|
||||
bottom_border
|
||||
|
||||
local action
|
||||
read -p "${cyan}###### Please choose:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
echo -e "###### > Remove packages"
|
||||
remove_conflicting_packages "${apache}" "${haproxy}"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > Disable only"
|
||||
disable_conflicting_packages "${apache}" "${haproxy}"
|
||||
break;;
|
||||
3)
|
||||
echo -e "###### > Skip"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function set_nginx_cfg() {
|
||||
local interface=${1}
|
||||
if [[ ${SET_NGINX_CFG} == "true" ]]; then
|
||||
local cfg="${RESOURCES}/${interface}"
|
||||
#check for dependencies
|
||||
local dep=(nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
status_msg "Creating Nginx configuration for ${interface^} ..."
|
||||
cat "${RESOURCES}/klipper_webui_nginx.cfg" > "${cfg}"
|
||||
sed -i "s/<<UI>>/${interface}/g" "${cfg}"
|
||||
|
||||
if [[ ${SET_LISTEN_PORT} != "${DEFAULT_PORT}" ]]; then
|
||||
status_msg "Configuring port for ${interface^} ..."
|
||||
sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}"
|
||||
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}"
|
||||
fi
|
||||
|
||||
#set correct user
|
||||
if [[ ${interface} == "mainsail" || ${interface} == "fluidd" ]]; then
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${cfg}"
|
||||
fi
|
||||
|
||||
#moving the config file into correct directory
|
||||
sudo mv "${cfg}" "/etc/nginx/sites-available/${interface}"
|
||||
ok_msg "Nginx configuration for ${interface^} was set!"
|
||||
if [[ -n ${SET_LISTEN_PORT} ]]; then
|
||||
ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!"
|
||||
else
|
||||
ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!"
|
||||
fi
|
||||
|
||||
#remove nginx default config
|
||||
if [[ -e "/etc/nginx/sites-enabled/default" ]]; then
|
||||
sudo rm "/etc/nginx/sites-enabled/default"
|
||||
fi
|
||||
|
||||
#create symlink for own sites
|
||||
if [[ ! -e "/etc/nginx/sites-enabled/${interface}" ]]; then
|
||||
sudo ln -s "/etc/nginx/sites-available/${interface}" "/etc/nginx/sites-enabled/"
|
||||
fi
|
||||
sudo systemctl restart nginx.service
|
||||
fi
|
||||
}
|
||||
|
||||
function set_nginx_permissions() {
|
||||
local distro_name version_id
|
||||
|
||||
distro_name=$(grep -E "^NAME=" /etc/os-release | cut -d'"' -f2)
|
||||
version_id=$(grep -E "^VERSION_ID=" /etc/os-release | cut -d'"' -f2)
|
||||
|
||||
if [[ ${distro_name} == "Ubuntu" && ( ${version_id} == "21.10" || ${version_id} == "22.04") ]]; then
|
||||
status_msg "Granting NGINX the required permissions ..."
|
||||
chmod og+x "${HOME}" && ok_msg "Done!"
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
function read_listen_port() {
|
||||
local port interface=${1}
|
||||
port=$(grep listen "/etc/nginx/sites-enabled/${interface}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
echo "${port}"
|
||||
}
|
||||
|
||||
function detect_enabled_sites() {
|
||||
MAINSAIL_ENABLED="false" FLUIDD_ENABLED="false"
|
||||
#check if there is another UI config already installed and reads the port they are listening on
|
||||
if [[ -e "/etc/nginx/sites-enabled/mainsail" ]]; then
|
||||
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
|
||||
MAINSAIL_PORT=$(read_listen_port "mainsail")
|
||||
fi
|
||||
if [[ -e "/etc/nginx/sites-enabled/fluidd" ]]; then
|
||||
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
|
||||
FLUIDD_PORT=$(read_listen_port "fluidd")
|
||||
|
||||
fi
|
||||
}
|
||||
401
scripts/octoprint.sh
Normal file
401
scripts/octoprint.sh
Normal file
@@ -0,0 +1,401 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#=============== INSTALL OCTOPRINT ===============#
|
||||
#=================================================#
|
||||
|
||||
function octoprint_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function octoprint_setup_dialog() {
|
||||
status_msg "Initializing OctoPrint installation ..."
|
||||
|
||||
local klipper_services klipper_count user_input=() klipper_names=()
|
||||
klipper_services=$(klipper_systemd)
|
||||
klipper_count=$(echo "${klipper_services}" | wc -w )
|
||||
|
||||
for service in ${klipper_services}; do
|
||||
klipper_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local octoprint_count
|
||||
if (( klipper_count == 1 )); then
|
||||
ok_msg "Klipper installation found!\n"
|
||||
octoprint_count=1
|
||||
|
||||
elif (( klipper_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
|
||||
for name in "${klipper_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● ${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to OctoPrint! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of OctoPrint instances to |"
|
||||
echo -e "| install. Usually one OctoPrint instance per Klipper |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| OctoPrint instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${octoprint_count} =~ ${re} || ${octoprint_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " -i "${klipper_count}" -e octoprint_count
|
||||
### break if input is valid
|
||||
[[ ${octoprint_count} =~ ${re} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${octoprint_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( octoprint_count > klipper_count )) && error_msg "Number of OctoPrint instances larger than existing Klipper instances"
|
||||
done && select_msg "${octoprint_count}"
|
||||
|
||||
else
|
||||
log_error "Internal error. octoprint_count of '${octoprint_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${octoprint_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( octoprint_count == 1 )) && local question="Install OctoPrint?"
|
||||
(( octoprint_count > 1 )) && local question="Install ${octoprint_count} OctoPrint instances?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting OctoPrint setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for octoprint
|
||||
if (( klipper_count > 1 )); then
|
||||
for name in "${klipper_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( octoprint_count > 1 )) && status_msg "Installing ${octoprint_count} OctoPrint instances ..."
|
||||
(( octoprint_count == 1 )) && status_msg "Installing OctoPrint ..."
|
||||
octoprint_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function octoprint_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### check and install all dependencies
|
||||
local dep=(
|
||||
git
|
||||
wget
|
||||
python3-pip
|
||||
python3-dev
|
||||
libyaml-dev
|
||||
build-essential
|
||||
python3-setuptools
|
||||
python3-virtualenv
|
||||
)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: check for tty and dialout usergroups and add reboot permissions
|
||||
check_usergroups
|
||||
add_reboot_permission
|
||||
|
||||
### step 2: install octoprint
|
||||
install_octoprint "${instance_arr[@]}"
|
||||
|
||||
### step 3: set up service
|
||||
create_octoprint_service "${instance_arr[@]}"
|
||||
|
||||
### step 4: enable and start all instances
|
||||
do_action_service "enable" "octoprint"
|
||||
do_action_service "start" "octoprint"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="OctoPrint has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} OctoPrint instances have been set up!"
|
||||
print_confirm "${confirm}" && print_op_ip_list "${instance_arr[0]}" && return
|
||||
}
|
||||
|
||||
function install_octoprint() {
|
||||
|
||||
function install_octoprint_python_env() {
|
||||
local tmp="${1}"
|
||||
### create and activate the virtualenv
|
||||
status_msg "Installing python virtual environment..."
|
||||
|
||||
if [[ ! -d ${tmp} ]]; then
|
||||
mkdir -p "${tmp}"
|
||||
else
|
||||
error_msg "Cannot create temporary directory in ${HOME}!"
|
||||
error_msg "Folder 'TMP_OCTO_ENV' exists and may not be empty!"
|
||||
error_msg "Please remove/rename that folder and start again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd "${tmp}"
|
||||
|
||||
if virtualenv --python=python3 venv; then
|
||||
### activate virtualenv
|
||||
source venv/bin/activate
|
||||
pip install pip --upgrade
|
||||
pip install --no-cache-dir octoprint
|
||||
### leave virtualenv
|
||||
deactivate
|
||||
else
|
||||
log_error "failure while creating python3 OctoPrint env"
|
||||
error_msg "Creation of OctoPrint virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${HOME}"
|
||||
}
|
||||
|
||||
local input=("${@}")
|
||||
local octoprint_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local j=0 octo_env
|
||||
local tmp="${HOME}/TMP_OCTO_ENV"
|
||||
|
||||
### handle single instance installs
|
||||
if (( octoprint_count == 1 )); then
|
||||
if install_octoprint_python_env "${tmp}"; then
|
||||
status_msg "Installing OctoPrint ..."
|
||||
octo_env="${HOME}/OctoPrint"
|
||||
|
||||
### rename the temporary directory to the correct name
|
||||
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
|
||||
mv "${tmp}" "${octo_env}"
|
||||
|
||||
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
|
||||
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
|
||||
else
|
||||
error_msg "OctoPrint installation failed!"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
### handle multi instance installs
|
||||
if (( octoprint_count > 1 )); then
|
||||
if install_octoprint_python_env "${tmp}"; then
|
||||
for (( i=1; i <= octoprint_count; i++ )); do
|
||||
status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..."
|
||||
octo_env="${HOME}/OctoPrint_${names[${j}]}"
|
||||
|
||||
### rename the temporary directory to the correct name
|
||||
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
|
||||
cp -r "${tmp}" "${octo_env}"
|
||||
|
||||
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
|
||||
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
|
||||
j=$(( j + 1 ))
|
||||
done && rm -rf "${tmp}"
|
||||
else
|
||||
error_msg "OctoPrint installation failed!"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function create_octoprint_service() {
|
||||
local input=("${@}")
|
||||
local octoprint_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local j=0 port=5000
|
||||
local octo_env service basedir tmp_printer config_yaml restart_cmd
|
||||
|
||||
for (( i=1; i <= octoprint_count; i++ )); do
|
||||
if (( octoprint_count == 1 )); then
|
||||
octo_env="${HOME}/OctoPrint"
|
||||
service="${SYSTEMD}/octoprint.service"
|
||||
basedir="${HOME}/.octoprint"
|
||||
tmp_printer="/tmp/printer"
|
||||
config_yaml="${basedir}/config.yaml"
|
||||
restart_cmd="sudo service octoprint restart"
|
||||
elif (( octoprint_count > 1 )); then
|
||||
octo_env="${HOME}/OctoPrint_${names[${j}]}"
|
||||
service="${SYSTEMD}/octoprint-${names[${j}]}.service"
|
||||
basedir="${HOME}/.octoprint_${names[${j}]}"
|
||||
tmp_printer="/tmp/printer-${names[${j}]}"
|
||||
config_yaml="${basedir}/config.yaml"
|
||||
restart_cmd="sudo service octoprint-${names[${j}]} restart"
|
||||
fi
|
||||
|
||||
(( octoprint_count == 1 )) && status_msg "Creating OctoPrint Service ..."
|
||||
(( octoprint_count > 1 )) && status_msg "Creating OctoPrint Service ${i}(${names[${j}]}) ..."
|
||||
|
||||
sudo /bin/sh -c "cat > ${service}" << OCTOPRINT
|
||||
[Unit]
|
||||
Description=Starts OctoPrint on startup
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Environment="LC_ALL=C.UTF-8"
|
||||
Environment="LANG=C.UTF-8"
|
||||
Type=simple
|
||||
User=${USER}
|
||||
ExecStart=${octo_env}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
OCTOPRINT
|
||||
|
||||
port=$(( port + 1 ))
|
||||
j=$(( j + 1 ))
|
||||
ok_msg "Ok!"
|
||||
|
||||
### create config.yaml
|
||||
if [[ ! -f ${basedir}/config.yaml ]]; then
|
||||
[[ ! -d ${basedir} ]] && mkdir "${basedir}"
|
||||
|
||||
(( octoprint_count == 1 )) && status_msg "Creating config.yaml ..."
|
||||
(( octoprint_count > 1 )) && status_msg "Creating config.yaml for instance ${i}(${names[${j}]}) ..."
|
||||
|
||||
/bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML
|
||||
serial:
|
||||
additionalPorts:
|
||||
- ${tmp_printer}
|
||||
disconnectOnErrors: false
|
||||
port: ${tmp_printer}
|
||||
server:
|
||||
commands:
|
||||
serverRestartCommand: ${restart_cmd}
|
||||
systemRestartCommand: sudo shutdown -r now
|
||||
systemShutdownCommand: sudo shutdown -h now
|
||||
CONFIGYAML
|
||||
ok_msg "Ok!"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function add_reboot_permission() {
|
||||
#create a backup if file already exists
|
||||
if [[ -f /etc/sudoers.d/octoprint-shutdown ]]; then
|
||||
sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old
|
||||
fi
|
||||
|
||||
#create new permission file
|
||||
status_msg "Add reboot permission to user '${USER}' ..."
|
||||
cd "${HOME}" && echo "${USER} ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
|
||||
sudo chown 0 octoprint-shutdown
|
||||
sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown
|
||||
ok_msg "Permission set!"
|
||||
}
|
||||
|
||||
function print_op_ip_list() {
|
||||
local ip octoprint_count="${1}" port=5000
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
for (( i=1; i <= octoprint_count; i++ )); do
|
||||
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
|
||||
port=$(( port + 1 ))
|
||||
done && echo
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=============== REMOVE OCTOPRINT ================#
|
||||
#=================================================#
|
||||
|
||||
function remove_octoprint_service() {
|
||||
[[ -z $(octoprint_systemd) ]] && return
|
||||
|
||||
###remove all octoprint services
|
||||
status_msg "Removing OctoPrint Systemd Services ..."
|
||||
|
||||
for service in $(octoprint_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
}
|
||||
|
||||
function remove_octoprint_sudoers() {
|
||||
[[ ! -f /etc/sudoers.d/octoprint-shutdown ]] && return
|
||||
|
||||
### remove sudoers file
|
||||
sudo rm -f /etc/sudoers.d/octoprint-shutdown
|
||||
}
|
||||
|
||||
function remove_octoprint_env() {
|
||||
local files
|
||||
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -rf "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoprint_dir() {
|
||||
local files
|
||||
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -rf "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoprint() {
|
||||
remove_octoprint_service
|
||||
remove_octoprint_sudoers
|
||||
remove_octoprint_env
|
||||
remove_octoprint_dir
|
||||
|
||||
local confirm="OctoPrint was successfully removed!"
|
||||
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=============== OCTOPRINT STATUS ================#
|
||||
#=================================================#
|
||||
|
||||
function get_octoprint_status() {
|
||||
local sf_count env_count dir_count status
|
||||
sf_count="$(octoprint_systemd | wc -w)"
|
||||
env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | wc -w)
|
||||
dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | wc -w)
|
||||
|
||||
if (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then
|
||||
status="Not installed!"
|
||||
elif (( sf_count == env_count )) && (( sf_count == dir_count )); then
|
||||
status="Installed: ${sf_count}"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
129
scripts/pretty_gcode.sh
Normal file
129
scripts/pretty_gcode.sh
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#================== INSTALL PGC ==================#
|
||||
#=================================================#
|
||||
|
||||
function install_pgc_for_klipper() {
|
||||
local pgconfsrc="${PGC_DIR}/pgcode.local.conf"
|
||||
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
|
||||
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
|
||||
local pgc_uri pgc_custom_port pgc_default_port="7136"
|
||||
|
||||
status_msg "Installing PrettyGCode for Klipper ..."
|
||||
echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: ${pgc_default_port})${white} "
|
||||
read -e -p "${cyan}###### Port:${white} " -i "${pgc_default_port}" pgc_custom_port
|
||||
|
||||
### check nginx dependency
|
||||
local dep=(nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
[[ -d ${PGC_DIR} ]] && rm -rf "${PGC_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${PGC_REPO}" "${PGC_DIR}"; then
|
||||
print_error "Cloning PrettyGCode for Klipper from\n ${PGC_REPO}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo cp "${pgconfsrc}" "${pgconf}"
|
||||
sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" "${pgconf}"
|
||||
|
||||
### replace default port
|
||||
if (( pgc_custom_port != pgc_default_port )); then
|
||||
sudo sed -i "s|listen ${pgc_default_port};|listen ${pgc_custom_port};|" "${pgconf}"
|
||||
sudo sed -i "s|listen \[::\]:${pgc_default_port};|listen \[::\]:${pgc_custom_port};|" "${pgconf}"
|
||||
fi
|
||||
|
||||
[[ ! -L ${pgconfsl} ]] && sudo ln -s "${pgconf}" "${pgconfsl}"
|
||||
sudo systemctl restart nginx
|
||||
|
||||
pgc_uri="http://$(hostname -I | cut -d" " -f1):${pgc_custom_port}"
|
||||
echo -e "${cyan}\n● Accessible via:${white} ${pgc_uri}"
|
||||
ok_msg "PrettyGCode for Klipper installed!\n"
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=================== REMOVE PGC ==================#
|
||||
#=================================================#
|
||||
|
||||
function remove_prettygcode() {
|
||||
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
|
||||
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
|
||||
|
||||
if [[ -d ${PGC_DIR} || -f ${pgconf} || -L ${pgconfsl} ]]; then
|
||||
status_msg "Removing PrettyGCode for Klipper ..."
|
||||
rm -rf "${PGC_DIR}"
|
||||
sudo rm -f "${pgconf}"
|
||||
sudo rm -f "${pgconfsl}"
|
||||
sudo systemctl restart nginx
|
||||
print_confirm "PrettyGCode for Klipper successfully removed!"
|
||||
else
|
||||
print_error "PrettyGCode for Klipper not found!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=================== UPDATE PGC ==================#
|
||||
#=================================================#
|
||||
|
||||
function update_pgc_for_klipper() {
|
||||
[[ ! -d ${PGC_DIR} ]] && return
|
||||
|
||||
status_msg "Updating PrettyGCode for Klipper ..."
|
||||
cd "${PGC_DIR}" && git pull
|
||||
ok_msg "Update complete!"
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=================== PGC STATUS ==================#
|
||||
#=================================================#
|
||||
|
||||
function get_local_prettygcode_commit() {
|
||||
local commit
|
||||
|
||||
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
|
||||
cd "${PGC_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_prettygcode_commit() {
|
||||
local commit
|
||||
|
||||
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
|
||||
cd "${PGC_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_prettygcode_versions() {
|
||||
unset PGC_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_prettygcode_commit)"
|
||||
remote_ver="$(get_remote_prettygcode_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add prettygcode to the update all array for the update all function in the updater
|
||||
PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
PGC_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
@@ -1,333 +0,0 @@
|
||||
remove_klipper(){
|
||||
data_arr=(
|
||||
/etc/init.d/klipper
|
||||
/etc/default/klipper
|
||||
/etc/systemd/system/klipper.service
|
||||
$KLIPPER_DIR
|
||||
$KLIPPY_ENV_DIR
|
||||
${HOME}/klippy.log
|
||||
)
|
||||
print_error "Klipper" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
stop_klipper
|
||||
if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then
|
||||
status_msg "Removing Klipper Service ..."
|
||||
sudo rm -rf /etc/init.d/klipper /etc/default/klipper
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo systemctl disable klipper
|
||||
sudo systemctl daemon-reload
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
if [ -e /etc/systemd/system/klipper.service ]; then
|
||||
status_msg "Removing Klipper Service ..."
|
||||
sudo rm -rf /etc/systemd/system/klipper.service
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo systemctl disable klipper
|
||||
sudo systemctl daemon-reload
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then
|
||||
status_msg "Removing Klipper and klippy-env directory ..."
|
||||
rm -rf $KLIPPER_DIR $KLIPPY_ENV_DIR && ok_msg "Directories removed!"
|
||||
fi
|
||||
if [[ -L ${HOME}/klippy.log || -e /tmp/klippy.log ]]; then
|
||||
status_msg "Removing klippy.log Symlink ..."
|
||||
rm -rf ${HOME}/klippy.log /tmp/klippy.log && ok_msg "Symlink removed!"
|
||||
fi
|
||||
CONFIRM_MSG=" Klipper successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_dwc2(){
|
||||
data_arr=(
|
||||
/etc/init.d/dwc
|
||||
/etc/default/dwc
|
||||
/etc/systemd/system/dwc.service
|
||||
$DWC2FK_DIR
|
||||
$DWC_ENV_DIR
|
||||
$DWC2_DIR
|
||||
/etc/nginx/sites-available/dwc2
|
||||
/etc/nginx/sites-enabled/dwc2
|
||||
)
|
||||
print_error "DWC2-for-Klipper-Socket &\n DWC2 Web UI" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
if systemctl is-active dwc -q; then
|
||||
status_msg "Stopping DWC2-for-Klipper-Socket Service ..."
|
||||
sudo systemctl stop dwc && sudo systemctl disable dwc
|
||||
ok_msg "Service stopped!"
|
||||
fi
|
||||
#remove if init.d service
|
||||
if [[ -e /etc/init.d/dwc || -e /etc/default/dwc ]]; then
|
||||
status_msg "Init.d Service found ..."
|
||||
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
|
||||
sudo rm -rf /etc/init.d/dwc /etc/default/dwc
|
||||
sudo update-rc.d -f dwc remove
|
||||
ok_msg "DWC2-for-Klipper-Socket Service removed!"
|
||||
fi
|
||||
#remove if systemd service
|
||||
if [ -e /etc/systemd/system/dwc.service ]; then
|
||||
status_msg "Systemd Service found ..."
|
||||
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
|
||||
sudo rm -rf /etc/systemd/system/dwc.service
|
||||
ok_msg "DWC2-for-Klipper-Socket Service removed!"
|
||||
fi
|
||||
if [ -d $DWC2FK_DIR ]; then
|
||||
status_msg "Removing DWC2-for-Klipper-Socket directory ..."
|
||||
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
if [ -d $DWC_ENV_DIR ]; then
|
||||
status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..."
|
||||
rm -rf $DWC_ENV_DIR && ok_msg "File removed!"
|
||||
fi
|
||||
if [ -d $DWC2_DIR ]; then
|
||||
status_msg "Removing DWC2 directory ..."
|
||||
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
#remove dwc2 config for nginx
|
||||
if [ -e /etc/nginx/sites-available/dwc2 ]; then
|
||||
status_msg "Removing DWC2 configuration for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-available/dwc2 && ok_msg "File removed!"
|
||||
fi
|
||||
#remove dwc2 symlink for nginx
|
||||
if [ -L /etc/nginx/sites-enabled/dwc2 ]; then
|
||||
status_msg "Removing DWC2 Symlink for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-enabled/dwc2 && ok_msg "File removed!"
|
||||
fi
|
||||
CONFIRM_MSG=" DWC2-for-Klipper-Socket & DWC2 successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_moonraker(){
|
||||
data_arr=(
|
||||
$MOONRAKER_SERVICE1
|
||||
$MOONRAKER_SERVICE2
|
||||
$MOONRAKER_DIR
|
||||
$MOONRAKER_ENV_DIR
|
||||
$NGINX_CONFD/upstreams.conf
|
||||
$NGINX_CONFD/common_vars.conf
|
||||
${HOME}/moonraker.conf
|
||||
${HOME}/moonraker.log
|
||||
${HOME}/klipper_config/moonraker.log
|
||||
${HOME}/klipper_config/klippy.log
|
||||
${HOME}/.klippy_api_key
|
||||
${HOME}/.moonraker_api_key
|
||||
)
|
||||
print_error "Moonraker" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
if [ -e ${HOME}/moonraker.conf ]; then
|
||||
unset REMOVE_MOONRAKER_CONF
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Delete moonraker.conf? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
REMOVE_MOONRAKER_CONF="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
REMOVE_MOONRAKER_CONF="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
status_msg "Processing ..."
|
||||
stop_moonraker
|
||||
#remove moonraker services
|
||||
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then
|
||||
status_msg "Removing Moonraker Service ..."
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker Service removed!"
|
||||
fi
|
||||
#remove moonraker and moonraker-env dir
|
||||
if [[ -d $MOONRAKER_DIR || -d $MOONRAKER_ENV_DIR ]]; then
|
||||
status_msg "Removing Moonraker and moonraker-env directory ..."
|
||||
rm -rf $MOONRAKER_DIR $MOONRAKER_ENV_DIR && ok_msg "Directories removed!"
|
||||
fi
|
||||
#remove moonraker.conf
|
||||
if [ "$REMOVE_MOONRAKER_CONF" = "true" ]; then
|
||||
status_msg "Removing moonraker.conf ..."
|
||||
rm -rf ${HOME}/moonraker.conf && ok_msg "File removed!"
|
||||
fi
|
||||
#remove moonraker.log and symlink
|
||||
if [[ -L ${HOME}/moonraker.log || -L ${HOME}/klipper_config/moonraker.log || -L ${HOME}/klipper_config/klippy.log || -e /tmp/moonraker.log ]]; then
|
||||
status_msg "Removing Logs and Symlinks ..."
|
||||
rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log ${HOME}/klipper_config/klippy.log /tmp/moonraker.log
|
||||
ok_msg "Files removed!"
|
||||
fi
|
||||
#remove moonraker nginx config
|
||||
if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then
|
||||
status_msg "Removing Moonraker NGINX configuration ..."
|
||||
sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!"
|
||||
fi
|
||||
#remove legacy api key
|
||||
if [ -e ${HOME}/.klippy_api_key ]; then
|
||||
status_msg "Removing legacy API Key ..."
|
||||
rm ${HOME}/.klippy_api_key && ok_msg "Done!"
|
||||
fi
|
||||
#remove api key
|
||||
if [ -e ${HOME}/.moonraker_api_key ]; then
|
||||
status_msg "Removing API Key ..."
|
||||
rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
|
||||
fi
|
||||
CONFIRM_MSG="Moonraker successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_mainsail(){
|
||||
data_arr=(
|
||||
$MAINSAIL_DIR
|
||||
/etc/nginx/sites-available/mainsail
|
||||
/etc/nginx/sites-enabled/mainsail
|
||||
)
|
||||
print_error "Mainsail" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
#remove mainsail dir
|
||||
if [ -d $MAINSAIL_DIR ]; then
|
||||
status_msg "Removing Mainsail directory ..."
|
||||
rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
#remove mainsail config for nginx
|
||||
if [ -e /etc/nginx/sites-available/mainsail ]; then
|
||||
status_msg "Removing Mainsail configuration for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!"
|
||||
fi
|
||||
#remove mainsail symlink for nginx
|
||||
if [ -L /etc/nginx/sites-enabled/mainsail ]; then
|
||||
status_msg "Removing Mainsail Symlink for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!"
|
||||
fi
|
||||
CONFIRM_MSG="Mainsail successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_fluidd(){
|
||||
data_arr=(
|
||||
$FLUIDD_DIR
|
||||
/etc/nginx/sites-available/fluidd
|
||||
/etc/nginx/sites-enabled/fluidd
|
||||
)
|
||||
print_error "Fluidd" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
#remove fluidd dir
|
||||
if [ -d $FLUIDD_DIR ]; then
|
||||
status_msg "Removing Fluidd directory ..."
|
||||
rm -rf $FLUIDD_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
#remove fluidd config for nginx
|
||||
if [ -e /etc/nginx/sites-available/fluidd ]; then
|
||||
status_msg "Removing Fluidd configuration for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!"
|
||||
fi
|
||||
#remove fluidd symlink for nginx
|
||||
if [ -L /etc/nginx/sites-enabled/fluidd ]; then
|
||||
status_msg "Removing Fluidd Symlink for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!"
|
||||
fi
|
||||
CONFIRM_MSG="Fluidd successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_octoprint(){
|
||||
data_arr=(
|
||||
$OCTOPRINT_SERVICE1
|
||||
$OCTOPRINT_SERVICE2
|
||||
$OCTOPRINT_DIR
|
||||
$OCTOPRINT_CFG_DIR
|
||||
${HOME}/octoprint.log
|
||||
/etc/sudoers.d/octoprint-shutdown
|
||||
/etc/nginx/sites-available/octoprint
|
||||
/etc/nginx/sites-enabled/octoprint
|
||||
)
|
||||
print_error "OctoPrint" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
stop_octoprint
|
||||
if [[ -e $OCTOPRINT_SERVICE1 || -e $OCTOPRINT_SERVICE2 ]]; then
|
||||
status_msg "Removing OctoPrint Service ..."
|
||||
sudo update-rc.d -f octoprint remove
|
||||
sudo rm -rf $OCTOPRINT_SERVICE1 $OCTOPRINT_SERVICE2 && ok_msg "OctoPrint Service removed!"
|
||||
fi
|
||||
if [[ -d $OCTOPRINT_DIR || -d $OCTOPRINT_CFG_DIR ]]; then
|
||||
status_msg "Removing OctoPrint and .octoprint directory ..."
|
||||
rm -rf $OCTOPRINT_DIR $OCTOPRINT_CFG_DIR && ok_msg "Directories removed!"
|
||||
fi
|
||||
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
|
||||
sudo rm -rf /etc/sudoers.d/octoprint-shutdown
|
||||
fi
|
||||
if [ -L ${HOME}/octoprint.log ]; then
|
||||
status_msg "Removing octoprint.log Symlink ..."
|
||||
rm -rf ${HOME}/octoprint.log && ok_msg "Symlink removed!"
|
||||
fi
|
||||
#remove octoprint config for nginx
|
||||
if [ -e /etc/nginx/sites-available/octoprint ]; then
|
||||
status_msg "Removing OctoPrint configuration for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-available/octoprint && ok_msg "File removed!"
|
||||
fi
|
||||
#remove octoprint symlink for nginx
|
||||
if [ -L /etc/nginx/sites-enabled/octoprint ]; then
|
||||
status_msg "Removing OctoPrint Symlink for Nginx ..."
|
||||
sudo rm /etc/nginx/sites-enabled/octoprint && ok_msg "File removed!"
|
||||
fi
|
||||
CONFIRM_MSG=" OctoPrint successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
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
|
||||
status_msg "Purging Nginx from system ..."
|
||||
sudo apt-get purge nginx nginx-common -y
|
||||
sudo update-rc.d -f nginx remove
|
||||
CONFIRM_MSG=" Nginx successfully removed!"
|
||||
else
|
||||
ERROR_MSG=" Looks like Nginx was already removed!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
remove_klipperscreen(){
|
||||
data_arr=(
|
||||
$KLIPPERSCREEN_DIR
|
||||
$KLIPPERSCREEN_ENV_DIR
|
||||
/etc/systemd/system/KlipperScreen.service
|
||||
)
|
||||
print_error "KlipperScreen" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
#remove KlipperScreen dir
|
||||
if [ -d $KLIPPERSCREEN_DIR ]; then
|
||||
status_msg "Removing KlipperScreen directory ..."
|
||||
rm -rf $KLIPPERSCREEN_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
if [ -d $KLIPPERSCREEN_ENV_DIR ]; then
|
||||
status_msg "Removing KlipperScreen VENV directory ..."
|
||||
rm -rf $KLIPPERSCREEN_ENV_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
#remove KlipperScreen systemd file
|
||||
if [ -e /etc/systemd/system/KlipperScreen.service ]; then
|
||||
status_msg "Removing KlipperScreen Service ..."
|
||||
sudo rm /etc/systemd/system/KlipperScreen.service && ok_msg "File removed!"
|
||||
fi
|
||||
CONFIRM_MSG="KlipperScreen successfully removed!"
|
||||
fi
|
||||
}
|
||||
@@ -1,92 +1,85 @@
|
||||
save_klipper_state(){
|
||||
source_ini
|
||||
#read current klipper state
|
||||
cd $KLIPPER_DIR
|
||||
COMMIT_STATE=$(git rev-parse --short HEAD)
|
||||
if [ "$GET_BRANCH" = "master" ]; then
|
||||
ORI_OLD=$previous_origin_state
|
||||
ORI_NEW=$COMMIT_STATE
|
||||
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE
|
||||
elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
|
||||
SHA_OLD=$previous_shaping_state
|
||||
SHA_NEW=$COMMIT_STATE
|
||||
sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE
|
||||
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
|
||||
SMO_OLD=$previous_smoothing_state
|
||||
SMO_NEW=$COMMIT_STATE
|
||||
sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE
|
||||
fi
|
||||
}
|
||||
#!/usr/bin/env bash
|
||||
|
||||
load_klipper_state(){
|
||||
source_ini
|
||||
print_branch
|
||||
cd $KLIPPER_DIR
|
||||
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD)
|
||||
if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then
|
||||
PREVIOUS_COMMIT=$previous_origin_state
|
||||
elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
|
||||
PREVIOUS_COMMIT=$previous_shaping_state
|
||||
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
|
||||
PREVIOUS_COMMIT=$previous_smoothing_state
|
||||
fi
|
||||
CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT)
|
||||
if [ "$PREVIOUS_COMMIT" != "0" ]; then
|
||||
PREVIOUS_COMMIT_DATE=$(git show -s --format=%cd --date=short $PREVIOUS_COMMIT)
|
||||
fi
|
||||
if [ "$PREVIOUS_COMMIT" = "0" ]; then
|
||||
CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}")
|
||||
PREV_UI=$(echo -e "${red}None${default} ")
|
||||
else
|
||||
if [ "$CURRENT_COMMIT" = "$PREVIOUS_COMMIT" ]; then
|
||||
CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}")
|
||||
PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}")
|
||||
else
|
||||
CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}")
|
||||
PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}")
|
||||
fi
|
||||
fi
|
||||
rollback_ui
|
||||
rollback_klipper
|
||||
}
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
rollback_klipper(){
|
||||
if [ "$PREVIOUS_COMMIT" != "0" ] && [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then
|
||||
set -e
|
||||
|
||||
function rollback_menu() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| If serious errors occured after updating Klipper or |"
|
||||
echo -e "| Moonraker, you can use this menu to try and reset the |"
|
||||
echo -e "| repository to an earlier state. |"
|
||||
hr
|
||||
echo -e "| 1) Rollback Klipper |"
|
||||
echo -e "| 2) Rollback Moonraker |"
|
||||
back_footer
|
||||
|
||||
local action
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to rollback to $PREVIOUS_COMMIT? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
clear
|
||||
print_header
|
||||
status_msg "Rolling back to $PREVIOUS_COMMIT ..."
|
||||
git reset --hard $PREVIOUS_COMMIT -q
|
||||
ok_msg "Rollback complete!"; echo
|
||||
load_klipper_state
|
||||
read -p "${cyan}###### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
select_msg "Klipper"
|
||||
rollback_component "klipper"
|
||||
break;;
|
||||
N|n|No|no) clear; advanced_menu; break;;
|
||||
Q|q) clear; advanced_menu; break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "Perform action: " action; echo
|
||||
echo -e "${default}"
|
||||
case "$action" in
|
||||
Q|q)
|
||||
2)
|
||||
select_msg "Moonraker"
|
||||
rollback_component "moonraker"
|
||||
break;;
|
||||
B|b)
|
||||
clear; advanced_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
rollback_ui;;
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function rollback_component() {
|
||||
local component=${1}
|
||||
|
||||
if [[ ! -d "${HOME}/${component}" ]]; then
|
||||
print_error "Rollback not possible! Missing installation?"
|
||||
return
|
||||
fi
|
||||
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Please select how many commits you want to revert. |"
|
||||
echo -e "| Consider using the information provided by the GitHub |"
|
||||
echo -e "| commit history to decide how many commits to revert. |"
|
||||
blank_line
|
||||
echo -e "| ${red}Warning:${white} |"
|
||||
echo -e "| ${red}Do not proceed if you are currently in the progress${white} |"
|
||||
echo -e "| ${red}of printing! Proceeding WILL terminate that print!${white} |"
|
||||
back_footer
|
||||
|
||||
local count
|
||||
while true; do
|
||||
read -p "${cyan}###### Revert this amount of commits:${white} " count
|
||||
if [[ -n ${count} ]] && (( count > 0 )); then
|
||||
status_msg "Revert ${component^} by ${count} commits ..."
|
||||
cd "${HOME}/${component}"
|
||||
if git reset --hard HEAD~"${count}"; then
|
||||
do_action_service "restart" "${component}"
|
||||
print_confirm "${component^} was successfully reset!"
|
||||
else
|
||||
print_error "Reverting ${component^} failed! Please see the console output above."
|
||||
fi
|
||||
break
|
||||
elif [[ ${count} == "B" || ${count} == "b" ]]; then
|
||||
clear && print_header && break
|
||||
else
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
rollback_menu
|
||||
}
|
||||
@@ -1,489 +0,0 @@
|
||||
kiauh_status(){
|
||||
if [ -d "${SRCDIR}/kiauh/.git" ]; then
|
||||
cd ${HOME}/kiauh
|
||||
git fetch -q
|
||||
if git branch -a | grep "* master" -q; then
|
||||
if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then
|
||||
KIAUH_UPDATE_AVAIL="true"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
klipper_status(){
|
||||
kcount=0
|
||||
klipper_data=(
|
||||
SERVICE
|
||||
$KLIPPER_DIR
|
||||
$KLIPPY_ENV_DIR
|
||||
)
|
||||
#remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
|
||||
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && unset klipper_data[0]
|
||||
#count+1 for each found data-item from array
|
||||
for kd in "${klipper_data[@]}"
|
||||
do
|
||||
if [ -e $kd ]; then
|
||||
kcount=$(expr $kcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$kcount" == "${#klipper_data[*]}" ]; then
|
||||
KLIPPER_STATUS="${green}Installed!${default} "
|
||||
elif [ "$kcount" == 0 ]; then
|
||||
KLIPPER_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
KLIPPER_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
dwc2_status(){
|
||||
dcount=0
|
||||
dwc2_data=(
|
||||
$DWC2FK_DIR
|
||||
$DWC_ENV_DIR
|
||||
$DWC2_DIR
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for dd in "${dwc2_data[@]}"
|
||||
do
|
||||
if [ -e $dd ]; then
|
||||
dcount=$(expr $dcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$dcount" == "${#dwc2_data[*]}" ]; then
|
||||
DWC2_STATUS="${green}Installed!${default} "
|
||||
elif [ "$dcount" == 0 ]; then
|
||||
DWC2_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
DWC2_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
moonraker_status(){
|
||||
mrcount=0
|
||||
moonraker_data=(
|
||||
SERVICE
|
||||
$MOONRAKER_DIR
|
||||
$MOONRAKER_ENV_DIR
|
||||
$NGINX_CONFD/upstreams.conf
|
||||
$NGINX_CONFD/common_vars.conf
|
||||
)
|
||||
#remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
|
||||
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] && unset moonraker_data[0]
|
||||
#count+1 for each found data-item from array
|
||||
for mrd in "${moonraker_data[@]}"
|
||||
do
|
||||
if [ -e $mrd ]; then
|
||||
mrcount=$(expr $mrcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$mrcount" == "${#moonraker_data[*]}" ]; then
|
||||
MOONRAKER_STATUS="${green}Installed!${default} "
|
||||
elif [ "$mrcount" == 0 ]; then
|
||||
MOONRAKER_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
MOONRAKER_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
mainsail_status(){
|
||||
mcount=0
|
||||
mainsail_data=(
|
||||
$MAINSAIL_DIR
|
||||
$NGINX_SA/mainsail
|
||||
$NGINX_SE/mainsail
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for md in "${mainsail_data[@]}"
|
||||
do
|
||||
if [ -e $md ]; then
|
||||
mcount=$(expr $mcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$mcount" == "${#mainsail_data[*]}" ]; then
|
||||
MAINSAIL_STATUS="${green}Installed!${default} "
|
||||
elif [ "$mcount" == 0 ]; then
|
||||
MAINSAIL_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
MAINSAIL_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
fluidd_status(){
|
||||
fcount=0
|
||||
fluidd_data=(
|
||||
$FLUIDD_DIR
|
||||
$NGINX_SA/fluidd
|
||||
$NGINX_SE/fluidd
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for fd in "${fluidd_data[@]}"
|
||||
do
|
||||
if [ -e $fd ]; then
|
||||
fcount=$(expr $fcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$fcount" == "${#fluidd_data[*]}" ]; then
|
||||
FLUIDD_STATUS="${green}Installed!${default} "
|
||||
elif [ "$fcount" == 0 ]; then
|
||||
FLUIDD_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
FLUIDD_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
octoprint_status(){
|
||||
ocount=0
|
||||
octoprint_data=(
|
||||
$OCTOPRINT_DIR
|
||||
$OCTOPRINT_CFG_DIR
|
||||
$OCTOPRINT_SERVICE1
|
||||
$OCTOPRINT_SERVICE2
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for op in "${octoprint_data[@]}"
|
||||
do
|
||||
if [ -e $op ]; then
|
||||
ocount=$(expr $ocount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$ocount" == "${#octoprint_data[*]}" ]; then
|
||||
OCTOPRINT_STATUS="${green}Installed!${default} "
|
||||
elif [ "$ocount" == 0 ]; then
|
||||
OCTOPRINT_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
OCTOPRINT_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
klipperscreen_status(){
|
||||
klsccount=0
|
||||
klipperscreen_data=(
|
||||
SERVICE
|
||||
$KLIPPERSCREEN_DIR
|
||||
$KLIPPERSCREEN_ENV_DIR
|
||||
)
|
||||
#remove the "SERVICE" entry from the klipperscreen_data array if a klipperscreen service is installed
|
||||
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "KlipperScreen.service")" ] && unset klipperscreen_data[0]
|
||||
#count+1 for each found data-item from array
|
||||
for klscd in "${klipperscreen_data[@]}"
|
||||
do
|
||||
if [ -e $klscd ]; then
|
||||
klsccount=$(expr $klsccount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$klsccount" == "${#klipperscreen_data[*]}" ]; then
|
||||
KLIPPERSCREEN_STATUS="${green}Installed!${default} "
|
||||
elif [ "$klsccount" == 0 ]; then
|
||||
KLIPPERSCREEN_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
KLIPPERSCREEN_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
### reading the klipper branch the user is currently on
|
||||
read_branch(){
|
||||
if [ -d $KLIPPER_DIR/.git ]; then
|
||||
cd $KLIPPER_DIR
|
||||
GET_BRANCH="$(git branch | grep "*" | cut -d"*" -f2 | cut -d" " -f2)"
|
||||
### try to fix a detached HEAD state and read the correct branch from the output you get
|
||||
if [ "$(echo $GET_BRANCH | grep "HEAD" )" ]; then
|
||||
DETACHED_HEAD="true"
|
||||
GET_BRANCH=$(git branch | grep "HEAD" | rev | cut -d" " -f1 | rev | cut -d")" -f1 | cut -d"/" -f2)
|
||||
### try to identify the branch when the HEAD was detached at a single commit
|
||||
### will only work if its either master, scurve-shaping or scurve-smoothing branch
|
||||
if [[ $GET_BRANCH =~ [[:alnum:]] ]]; then
|
||||
if [ "$(git branch -r --contains $GET_BRANCH | grep "master")" ]; then
|
||||
GET_BRANCH="master"
|
||||
elif [ "$(git branch -r --contains $GET_BRANCH | grep "scurve-shaping")" ]; then
|
||||
GET_BRANCH="scurve-shaping"
|
||||
elif [ "$(git branch -r --contains $GET_BRANCH | grep "scurve-smoothing")" ]; then
|
||||
GET_BRANCH="scurve-smoothing"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
GET_BRANCH=""
|
||||
fi
|
||||
}
|
||||
|
||||
#prints the current klipper branch in the main menu
|
||||
print_branch(){
|
||||
read_branch
|
||||
if [ ! -z "$GET_BRANCH" ]; then
|
||||
PRINT_BRANCH="$(printf "%-16s" "$GET_BRANCH")"
|
||||
else
|
||||
PRINT_BRANCH="${red}--------------${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_klipper_commit(){
|
||||
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then
|
||||
cd $KLIPPER_DIR
|
||||
LOCAL_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
else
|
||||
LOCAL_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_klipper_commit(){
|
||||
read_branch
|
||||
if [ ! -z "$GET_BRANCH" ];then
|
||||
if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then
|
||||
git fetch origin -q
|
||||
REMOTE_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
|
||||
git fetch dmbutyugin scurve-shaping -q
|
||||
REMOTE_COMMIT=$(git describe dmbutyugin/scurve-shaping --always --tags | cut -d "-" -f 1,2)
|
||||
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
|
||||
git fetch dmbutyugin scurve-smoothing -q
|
||||
REMOTE_COMMIT=$(git describe dmbutyugin/scurve-smoothing --always --tags | cut -d "-" -f 1,2)
|
||||
fi
|
||||
else
|
||||
REMOTE_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
compare_klipper_versions(){
|
||||
unset KLIPPER_UPDATE_AVAIL
|
||||
read_local_klipper_commit && read_remote_klipper_commit
|
||||
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)
|
||||
else
|
||||
LOCAL_COMMIT="${green}$(printf "%-12s" "$LOCAL_COMMIT")${default}"
|
||||
REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}"
|
||||
KLIPPER_UPDATE_AVAIL="false"
|
||||
fi
|
||||
#if detached head was found, force the user with warn message to update klipper
|
||||
if [ "$DETACHED_HEAD" == "true" ]; then
|
||||
LOCAL_COMMIT="${red}$(printf "%-12s" "Need update!")${default}"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
read_dwc2fk_versions(){
|
||||
if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then
|
||||
cd $DWC2FK_DIR
|
||||
git fetch origin master -q
|
||||
LOCAL_DWC2FK_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
REMOTE_DWC2FK_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
else
|
||||
LOCAL_DWC2FK_COMMIT=$NONE
|
||||
REMOTE_DWC2FK_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
compare_dwc2fk_versions(){
|
||||
unset DWC2FK_UPDATE_AVAIL
|
||||
read_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)
|
||||
else
|
||||
LOCAL_DWC2FK_COMMIT="${green}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}"
|
||||
REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}"
|
||||
DWC2FK_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_dwc2_version(){
|
||||
unset DWC2_VER_FOUND
|
||||
if [ -e $DWC2_DIR/version ]; then
|
||||
DWC2_VER_FOUND="true"
|
||||
DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/version)
|
||||
else
|
||||
DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_dwc2_version(){
|
||||
#remote checks don't work without curl installed!
|
||||
if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then
|
||||
DWC2_REMOTE_VER=$NONE
|
||||
else
|
||||
get_dwc2_ver
|
||||
DWC2_REMOTE_VER=$DWC2_VERSION
|
||||
fi
|
||||
}
|
||||
|
||||
compare_dwc2_versions(){
|
||||
unset DWC2_UPDATE_AVAIL
|
||||
read_local_dwc2_version && read_remote_dwc2_version
|
||||
if [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER == $DWC2_REMOTE_VER ]]; then
|
||||
#printf fits the string for displaying it in the ui to a total char length of 12
|
||||
DWC2_LOCAL_VER="${green}$(printf "v%-11s" "$DWC2_LOCAL_VER")${default}"
|
||||
DWC2_REMOTE_VER="${green}$(printf "v%-11s" "$DWC2_REMOTE_VER")${default}"
|
||||
elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then
|
||||
DWC2_LOCAL_VER="${yellow}$(printf "v%-11s" "$DWC2_LOCAL_VER")${default}"
|
||||
DWC2_REMOTE_VER="${green}$(printf "v%-11s" "$DWC2_REMOTE_VER")${default}"
|
||||
# set flag for the multi update function
|
||||
DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2)
|
||||
else
|
||||
DWC2_LOCAL_VER=$NONE
|
||||
DWC2_REMOTE_VER="${green}$(printf "v%-11s" "$DWC2_REMOTE_VER")${default}"
|
||||
DWC2_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
read_moonraker_versions(){
|
||||
if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_DIR/.git ]; then
|
||||
cd $MOONRAKER_DIR
|
||||
git fetch origin master -q
|
||||
LOCAL_MOONRAKER_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
REMOTE_MOONRAKER_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
else
|
||||
LOCAL_MOONRAKER_COMMIT=$NONE
|
||||
REMOTE_MOONRAKER_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
compare_moonraker_versions(){
|
||||
unset MOONRAKER_UPDATE_AVAIL
|
||||
read_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)
|
||||
else
|
||||
LOCAL_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_COMMIT")${default}"
|
||||
REMOTE_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_COMMIT")${default}"
|
||||
MOONRAKER_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_mainsail_version(){
|
||||
unset MAINSAIL_VER_FOUND
|
||||
MAINSAIL_APP_FILE=$(find $MAINSAIL_DIR/js -name "app.*.js" 2>/dev/null)
|
||||
if [ ! -z $MAINSAIL_APP_FILE ]; then
|
||||
MAINSAIL_LOCAL_VER=$(grep -o -E 'state:{packageVersion:.+' $MAINSAIL_APP_FILE | cut -d'"' -f2)
|
||||
MAINSAIL_VER_FOUND="true"
|
||||
else
|
||||
MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_mainsail_version(){
|
||||
#remote checks don't work without curl installed!
|
||||
if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then
|
||||
MAINSAIL_REMOTE_VER=$NONE
|
||||
else
|
||||
get_mainsail_ver
|
||||
MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION
|
||||
fi
|
||||
}
|
||||
|
||||
compare_mainsail_versions(){
|
||||
unset MAINSAIL_UPDATE_AVAIL
|
||||
read_local_mainsail_version && read_remote_mainsail_version
|
||||
if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then
|
||||
#printf fits the string for displaying it in the ui to a total char length of 12
|
||||
MAINSAIL_LOCAL_VER="${green}$(printf "v%-11s" "$MAINSAIL_LOCAL_VER")${default}"
|
||||
MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}"
|
||||
elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then
|
||||
MAINSAIL_LOCAL_VER="${yellow}$(printf "v%-11s" "$MAINSAIL_LOCAL_VER")${default}"
|
||||
MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}"
|
||||
# set flag for the multi update function
|
||||
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
|
||||
else
|
||||
MAINSAIL_LOCAL_VER=$NONE
|
||||
MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}"
|
||||
MAINSAIL_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_fluidd_version(){
|
||||
unset FLUIDD_VER_FOUND
|
||||
FLUIDD_APP_FILE=$(find $FLUIDD_DIR/js -name "app.*.js" 2>/dev/null)
|
||||
if [ ! -z $FLUIDD_APP_FILE ]; then
|
||||
FLUIDD_LOCAL_VER=$(grep -o -E '"version/setVersion",".+"' $FLUIDD_APP_FILE | cut -d'"' -f4)
|
||||
FLUIDD_VER_FOUND="true"
|
||||
else
|
||||
FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_fluidd_version(){
|
||||
#remote checks don't work without curl installed!
|
||||
if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then
|
||||
FLUIDD_REMOTE_VER=$NONE
|
||||
else
|
||||
get_fluidd_ver
|
||||
FLUIDD_REMOTE_VER=$FLUIDD_VERSION
|
||||
fi
|
||||
}
|
||||
|
||||
compare_fluidd_versions(){
|
||||
unset FLUIDD_UPDATE_AVAIL
|
||||
read_local_fluidd_version && read_remote_fluidd_version
|
||||
if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then
|
||||
#printf fits the string for displaying it in the ui to a total char length of 12
|
||||
FLUIDD_LOCAL_VER="${green}$(printf "v%-11s" "$FLUIDD_LOCAL_VER")${default}"
|
||||
FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}"
|
||||
elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then
|
||||
FLUIDD_LOCAL_VER="${yellow}$(printf "v%-11s" "$FLUIDD_LOCAL_VER")${default}"
|
||||
FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}"
|
||||
# set flag for the multi update function
|
||||
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
|
||||
else
|
||||
FLUIDD_LOCAL_VER=$NONE
|
||||
FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}"
|
||||
FLUIDD_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
read_klipperscreen_versions(){
|
||||
if [ -d $KLIPPERSCREEN_DIR ] && [ -d $KLIPPERSCREEN_DIR/.git ]; then
|
||||
cd $KLIPPERSCREEN_DIR
|
||||
git fetch origin master -q
|
||||
LOCAL_KLIPPERSCREEN_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
REMOTE_KLIPPERSCREEN_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
else
|
||||
LOCAL_KLIPPERSCREEN_COMMIT=$NONE
|
||||
REMOTE_KLIPPERSCREEN_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
compare_klipperscreen_versions(){
|
||||
unset KLIPPERSCREEN_UPDATE_AVAIL
|
||||
read_klipperscreen_versions
|
||||
if [ "$LOCAL_KLIPPERSCREEN_COMMIT" != "$REMOTE_KLIPPERSCREEN_COMMIT" ]; then
|
||||
LOCAL_KLIPPERSCREEN_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_KLIPPERSCREEN_COMMIT")${default}"
|
||||
REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "$REMOTE_KLIPPERSCREEN_COMMIT")${default}"
|
||||
KLIPPERSCREEN_UPDATE_AVAIL="true"
|
||||
update_arr+=(update_klipperscreen)
|
||||
else
|
||||
LOCAL_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "$LOCAL_KLIPPERSCREEN_COMMIT")${default}"
|
||||
REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "$REMOTE_KLIPPERSCREEN_COMMIT")${default}"
|
||||
KLIPPERSCREEN_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
#display this as placeholder if no version/commit could be fetched
|
||||
NONE="${red}$(printf "%-12s" "--------")${default}"
|
||||
|
||||
ui_print_versions(){
|
||||
unset update_arr
|
||||
compare_klipper_versions
|
||||
compare_dwc2fk_versions
|
||||
compare_dwc2_versions
|
||||
compare_moonraker_versions
|
||||
compare_mainsail_versions
|
||||
compare_fluidd_versions
|
||||
compare_klipperscreen_versions
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
switch_to_master(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
git fetch origin -q && git checkout master; echo
|
||||
}
|
||||
|
||||
switch_to_scurve_shaping(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep dmbutyugin -q; then
|
||||
git remote add dmbutyugin $DMBUTYUGIN_REPO
|
||||
fi
|
||||
git fetch dmbutyugin -q && git checkout scurve-shaping; echo
|
||||
}
|
||||
|
||||
switch_to_scurve_smoothing(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep dmbutyugin -q; then
|
||||
git remote add dmbutyugin $DMBUTYUGIN_REPO
|
||||
fi
|
||||
git fetch dmbutyugin -q && git checkout scurve-smoothing; echo
|
||||
}
|
||||
138
scripts/switch_klipper_repo.sh
Normal file
138
scripts/switch_klipper_repo.sh
Normal file
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function change_klipper_repo_menu() {
|
||||
local repo_file="${KIAUH_SRCDIR}/klipper_repos.txt"
|
||||
local repo branch repos=() branches=()
|
||||
|
||||
if [[ ! -f ${repo_file} ]]; then
|
||||
print_error "File not found:\n '${KIAUH_SRCDIR}/klipper_repos.txt'"
|
||||
return
|
||||
fi
|
||||
|
||||
### generate the repolist from the klipper_repos.txt textfile
|
||||
while IFS="," read -r repo branch; do
|
||||
repo=$(echo "${repo}" | sed -r "s/^http(s)?:\/\/github.com\///" | sed "s/\.git$//" )
|
||||
repos+=("${repo}")
|
||||
### if branch is not given, default to 'master'
|
||||
[[ -z ${branch} ]] && branch="master"
|
||||
branches+=("${branch}")
|
||||
done < <(grep -E "^[^#]" "${repo_file}")
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | "
|
||||
hr
|
||||
blank_line
|
||||
### print repolist
|
||||
local i=0
|
||||
for _ in "${repos[@]}"; do
|
||||
printf "| %s) %-63s|\n" "${i}" "${yellow}${repos[${i}]}${white} → ${branches[${i}]}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local option
|
||||
while true; do
|
||||
read -p "${cyan}###### Perform action:${white} " option
|
||||
case "${option}" in
|
||||
0 | "$(( option < ${#repos[@]} ))")
|
||||
select_msg "Repo: ${repos[option]} Branch: ${branches[option]}"
|
||||
if [[ -d ${KLIPPER_DIR} ]]; then
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${white} |"
|
||||
echo -e "| Existing Klipper folder found! Proceeding will remove | "
|
||||
echo -e "| the existing Klipper folder and replace it with a | "
|
||||
echo -e "| clean copy of the previously selected source repo! | "
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Proceed? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
switch_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
|
||||
set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
status_msg "Set custom Klipper repository to:\n ● Repository: ${repos[${option}]}\n ● Branch: ${branches[${option}]}"
|
||||
set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
|
||||
ok_msg "This repo will now be used for new Klipper installations!\n"
|
||||
fi
|
||||
break;;
|
||||
B|b)
|
||||
clear && print_header
|
||||
settings_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_custom_klipper_repo_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
change_klipper_repo_menu
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function switch_klipper_repo() {
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
status_msg "Switching Klipper repository..."
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
|
||||
clone_klipper "${repo}" "${branch}"
|
||||
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function show_custom_klipper_repo_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |"
|
||||
hr
|
||||
echo -e "| With this setting, it is possible to install Klipper |"
|
||||
echo -e "| from a custom repository. It will also switch an |"
|
||||
echo -e "| existing Klipper installation to the newly selected |"
|
||||
echo -e "| source repository. |"
|
||||
echo -e "| A list of repositories is automatically generated by |"
|
||||
echo -e "| a 'klipper_repos.txt' textfile in KIAUHs root folder. |"
|
||||
echo -e "| An example file is provided at the same location. |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
change_klipper_repo_menu
|
||||
break;;
|
||||
*)
|
||||
deny_action "show_settings_help";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -1,188 +1,69 @@
|
||||
advanced_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function advanced_ui() {
|
||||
top_border
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| 0) $OPRINT_SERVICE_STATUS| "
|
||||
hr
|
||||
echo -e "| | | "
|
||||
echo -e "| Klipper: | System: | "
|
||||
echo -e "| 1) [Switch Version] | 6) [Change hostname] | "
|
||||
echo -e "| 2) [Rollback] | | "
|
||||
echo -e "| | Extensions: | "
|
||||
echo -e "| Firmware: | 7) [Shell Command] | "
|
||||
echo -e "| 3) [Build only] | | "
|
||||
echo -e "| 4) [Build + Flash MCU] | | "
|
||||
echo -e "| 5) [Get Printer-USB] | | "
|
||||
echo -e "| | | "
|
||||
quit_footer
|
||||
echo -e "| Klipper & API: | Mainsail: |"
|
||||
echo -e "| 1) [Rollback] | 6) [Theme installer] |"
|
||||
echo -e "| | |"
|
||||
echo -e "| Firmware: | System: |"
|
||||
echo -e "| 2) [Build only] | 7) [Change hostname] |"
|
||||
echo -e "| 3) [Flash only] | |"
|
||||
echo -e "| 4) [Build + Flash] | Extras: |"
|
||||
echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
advanced_menu(){
|
||||
print_header
|
||||
print_msg && clear_msg
|
||||
read_octoprint_service_status
|
||||
advanced_ui
|
||||
function advanced_menu() {
|
||||
do_action "" "advanced_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
0)
|
||||
clear
|
||||
print_header
|
||||
toggle_octoprint_service
|
||||
read_octoprint_service_status
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
switch_menu
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
do_action "rollback_menu" "advanced_menu";;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
load_klipper_state
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
do_action "build_fw" "advanced_ui";;
|
||||
3)
|
||||
clear
|
||||
print_header
|
||||
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
|
||||
build_fw
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
clear && print_header
|
||||
do_action "init_flash_process" "advanced_ui";;
|
||||
4)
|
||||
clear
|
||||
print_header
|
||||
unset FLASH_FIRMWARE && FLASH_FIRMWARE="true"
|
||||
flash_routine
|
||||
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
|
||||
build_fw
|
||||
unset CONFIRM_FLASHING && CONFIRM_FLASHING="true"
|
||||
flash_mcu
|
||||
print_msg && clear_msg
|
||||
clear && print_header
|
||||
status_msg "Please wait..."
|
||||
build_fw && init_flash_process
|
||||
advanced_ui;;
|
||||
5)
|
||||
clear
|
||||
print_header
|
||||
get_printer_usb
|
||||
print_msg && clear_msg
|
||||
clear && print_header
|
||||
select_mcu_connection
|
||||
print_detected_mcu_to_screen
|
||||
advanced_ui;;
|
||||
6)
|
||||
clear
|
||||
print_header
|
||||
create_custom_hostname && set_hostname
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
do_action "ms_theme_installer_menu";;
|
||||
7)
|
||||
clear
|
||||
print_header
|
||||
setup_gcode_shell_command
|
||||
print_msg && clear_msg
|
||||
set_custom_hostname
|
||||
advanced_ui;;
|
||||
Q|q)
|
||||
8)
|
||||
do_action "setup_gcode_shell_command" "advanced_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
deny_action "advanced_ui";;
|
||||
esac
|
||||
done
|
||||
advanced_menu
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
switch_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |"
|
||||
bottom_border
|
||||
echo
|
||||
echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}"
|
||||
echo
|
||||
top_border
|
||||
echo -e "| | "
|
||||
echo -e "| KevinOConnor: | "
|
||||
echo -e "| 1) [--> master] | "
|
||||
echo -e "| | "
|
||||
echo -e "| dmbutyugin: | "
|
||||
echo -e "| 2) [--> scurve-shaping] | "
|
||||
echo -e "| 3) [--> scurve-smoothing] | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
switch_menu(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
read_branch
|
||||
print_msg && clear_msg
|
||||
switch_ui
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
switch_to_master
|
||||
read_branch
|
||||
print_msg && clear_msg
|
||||
switch_ui;;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
switch_to_scurve_shaping
|
||||
read_branch
|
||||
print_msg && clear_msg
|
||||
switch_ui;;
|
||||
3)
|
||||
clear
|
||||
print_header
|
||||
switch_to_scurve_smoothing
|
||||
read_branch
|
||||
print_msg && clear_msg
|
||||
switch_ui;;
|
||||
4)
|
||||
clear
|
||||
print_header
|
||||
switch_to_moonraker
|
||||
read_branch
|
||||
print_msg && clear_msg
|
||||
switch_ui;;
|
||||
Q|q)
|
||||
clear; advanced_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
switch_ui;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
ERROR_MSG="No Klipper directory found! Download Klipper first!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,84 +1,63 @@
|
||||
backup_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function backup_ui() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | "
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | "
|
||||
echo -e "| ${yellow}INFO: Backups are located in '~/kiauh-backups'${white} |"
|
||||
hr
|
||||
echo -e "| Firmware: | "
|
||||
echo -e "| 1) [Klipper] | "
|
||||
echo -e "| | "
|
||||
echo -e "| Klipper API: | "
|
||||
echo -e "| 2) [Moonraker] | "
|
||||
echo -e "| | "
|
||||
echo -e "| Webinterface: | "
|
||||
echo -e "| 3) [Mainsail] | "
|
||||
echo -e "| 4) [Fluidd] | "
|
||||
echo -e "| 5) [DWC2 Web UI] | "
|
||||
echo -e "| 6) [OctoPrint] | "
|
||||
echo -e "| | "
|
||||
echo -e "| HDMI Screen: | "
|
||||
echo -e "| 7) [KlipperScreen] | "
|
||||
echo -e "| | "
|
||||
quit_footer
|
||||
echo -e "| Klipper & API: | Touchscreen GUI: |"
|
||||
echo -e "| 1) [Klipper] | 7) [KlipperScreen] |"
|
||||
echo -e "| 2) [Moonraker] | |"
|
||||
echo -e "| 3) [Configuration Folder] | 3rd Party Webinterface: |"
|
||||
echo -e "| 4) [Moonraker Database] | 8) [OctoPrint] |"
|
||||
echo -e "| | |"
|
||||
echo -e "| Klipper Webinterface: | Other: |"
|
||||
echo -e "| 5) [Mainsail] | 9) [Telegram Bot] |"
|
||||
echo -e "| 6) [Fluidd] | |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
backup_menu(){
|
||||
print_header
|
||||
print_msg && clear_msg
|
||||
backup_ui
|
||||
function backup_menu() {
|
||||
do_action "" "backup_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
backup_klipper
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
do_action "backup_klipper" "backup_ui";;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
backup_moonraker
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
do_action "backup_moonraker" "backup_ui";;
|
||||
3)
|
||||
clear
|
||||
print_header
|
||||
backup_mainsail
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
do_action "backup_klipper_config_dir" "backup_ui";;
|
||||
4)
|
||||
clear
|
||||
print_header
|
||||
backup_fluidd
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
do_action "backup_moonraker_database" "backup_ui";;
|
||||
5)
|
||||
clear
|
||||
print_header
|
||||
backup_dwc2
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
do_action "backup_mainsail" "backup_ui";;
|
||||
6)
|
||||
clear
|
||||
print_header
|
||||
backup_octoprint
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
do_action "backup_fluidd" "backup_ui";;
|
||||
7)
|
||||
clear
|
||||
print_header
|
||||
backup_klipperscreen
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
Q|q)
|
||||
do_action "backup_klipperscreen" "backup_ui";;
|
||||
8)
|
||||
do_action "backup_octoprint" "backup_ui";;
|
||||
9)
|
||||
do_action "backup_telegram_bot" "backup_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
backup_ui;;
|
||||
deny_action "backup_ui";;
|
||||
esac
|
||||
done
|
||||
backup_menu
|
||||
|
||||
@@ -1,27 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#ui total width = 57 chars
|
||||
top_border(){
|
||||
echo -e "/=======================================================\ "
|
||||
function top_border() {
|
||||
echo -e "/=======================================================\\"
|
||||
}
|
||||
|
||||
bottom_border(){
|
||||
function bottom_border() {
|
||||
echo -e "\=======================================================/"
|
||||
}
|
||||
|
||||
blank_line(){
|
||||
echo -e "| | "
|
||||
function blank_line() {
|
||||
echo -e "| |"
|
||||
}
|
||||
|
||||
hr(){
|
||||
function hr() {
|
||||
echo -e "|-------------------------------------------------------|"
|
||||
}
|
||||
|
||||
quit_footer(){
|
||||
function quit_footer() {
|
||||
hr
|
||||
echo -e "| ${red}Q) Quit${default} | "
|
||||
echo -e "| ${red}Q) Quit${white} |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
print_header(){
|
||||
function back_footer() {
|
||||
hr
|
||||
echo -e "| ${green}B) « Back${white} |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
function back_help_footer() {
|
||||
hr
|
||||
echo -e "| ${green}B) « Back${white} | ${yellow}H) Help [?]${white} |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
function print_header() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |"
|
||||
echo -e "| $(title_msg " Klipper Installation And Update Helper ") |"
|
||||
@@ -29,12 +54,17 @@ print_header(){
|
||||
bottom_border
|
||||
}
|
||||
|
||||
kiauh_update_msg(){
|
||||
top_border
|
||||
echo -e "| ${yellow}There is a newer version of this script available!${default} | "
|
||||
echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | "
|
||||
blank_line
|
||||
echo -e "| ${yellow}Check out the KIAUH changelog for important changes${default} | "
|
||||
echo -e "| ${yellow}either to the script or the installable components!${default} | "
|
||||
bottom_border
|
||||
function do_action() {
|
||||
clear && print_header
|
||||
### $1 is the action the user wants to fire
|
||||
$1
|
||||
# print_msg && clear_msg
|
||||
### $2 is the menu the user usually gets directed back to after an action is completed
|
||||
$2
|
||||
}
|
||||
|
||||
function deny_action() {
|
||||
clear && print_header
|
||||
print_error "Invalid command!"
|
||||
$1
|
||||
}
|
||||
|
||||
@@ -1,79 +1,98 @@
|
||||
install_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function install_ui() {
|
||||
top_border
|
||||
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| You need this menu usually only for installing | "
|
||||
echo -e "| all necessary dependencies for the various | "
|
||||
echo -e "| functions on a completely fresh system. | "
|
||||
echo -e "| You need this menu usually only for installing |"
|
||||
echo -e "| all necessary dependencies for the various |"
|
||||
echo -e "| functions on a completely fresh system. |"
|
||||
hr
|
||||
echo -e "| Firmware: | Webinterface: | "
|
||||
echo -e "| 1) [Klipper] | 3) [DWC2] | "
|
||||
echo -e "| | 4) [Mainsail] | "
|
||||
echo -e "| Klipper API: | 5) [Fluidd] | "
|
||||
echo -e "| 2) [Moonraker] | 6) [Octoprint] | "
|
||||
echo -e "| | | "
|
||||
echo -e "| | HDMI Screen | "
|
||||
echo -e "| | 7) [KlipperScreen] | "
|
||||
quit_footer
|
||||
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
|
||||
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
|
||||
echo -e "| 2) [Moonraker] | |"
|
||||
echo -e "| | Other: |"
|
||||
echo -e "| Klipper Webinterface: | 7) [PrettyGCode] |"
|
||||
echo -e "| 3) [Mainsail] | 8) [Telegram Bot] |"
|
||||
echo -e "| 4) [Fluidd] | |"
|
||||
echo -e "| | Webcam Streamer: |"
|
||||
echo -e "| Touchscreen GUI: | 9) [MJPG-Streamer] |"
|
||||
echo -e "| 5) [KlipperScreen] | |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
install_menu(){
|
||||
print_header
|
||||
function install_menu() {
|
||||
clear && print_header
|
||||
install_ui
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
install_klipper
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
do_action "select_klipper_python_version" "install_ui";;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
install_moonraker
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
do_action "moonraker_setup_dialog" "install_ui";;
|
||||
3)
|
||||
clear
|
||||
print_header
|
||||
install_dwc2
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
do_action "install_mainsail" "install_ui";;
|
||||
4)
|
||||
clear
|
||||
print_header
|
||||
install_mainsail
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
do_action "install_fluidd" "install_ui";;
|
||||
5)
|
||||
clear
|
||||
print_header
|
||||
install_fluidd
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
do_action "install_klipperscreen" "install_ui";;
|
||||
6)
|
||||
clear
|
||||
print_header
|
||||
install_octoprint
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
do_action "octoprint_setup_dialog" "install_ui";;
|
||||
7)
|
||||
clear
|
||||
print_header
|
||||
install_klipperscreen
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
Q|q)
|
||||
do_action "install_pgc_for_klipper" "install_ui";;
|
||||
8)
|
||||
do_action "telegram_bot_setup_dialog" "install_ui";;
|
||||
9)
|
||||
do_action "install_mjpg-streamer" "install_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
deny_action "install_ui";;
|
||||
esac
|
||||
done
|
||||
install_menu
|
||||
}
|
||||
|
||||
function select_klipper_python_version() {
|
||||
top_border
|
||||
echo -e "| Please select the preferred Python version. | "
|
||||
echo -e "| The recommended version is Python 2.7. | "
|
||||
blank_line
|
||||
echo -e "| Installing Klipper with Python 3 is officially not | "
|
||||
echo -e "| recommended and should be considered as experimental. | "
|
||||
hr
|
||||
echo -e "| 1) [Python 2.7] (recommended) | "
|
||||
echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | "
|
||||
back_footer
|
||||
while true; do
|
||||
read -p "${cyan}###### Select Python version:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
select_msg "Python 2.7"
|
||||
klipper_setup_dialog "python2"
|
||||
break;;
|
||||
2)
|
||||
select_msg "Python 3.x"
|
||||
klipper_setup_dialog "python3"
|
||||
break;;
|
||||
B|b)
|
||||
clear; install_menu; break;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
@@ -1,89 +1,126 @@
|
||||
main_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function main_ui() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|"
|
||||
echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|"
|
||||
echo -e "| 0) [Log-Upload] | Klipper: $(print_status "klipper")|"
|
||||
echo -e "| | Repo: $(print_klipper_repo)|"
|
||||
echo -e "| 1) [Install] | |"
|
||||
echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|"
|
||||
echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|"
|
||||
echo -e "| 3) [Remove] | |"
|
||||
echo -e "| | DWC2: $DWC2_STATUS|"
|
||||
echo -e "| 4) [Advanced] | Fluidd: $FLUIDD_STATUS|"
|
||||
echo -e "| 5) [Backup] | Mainsail: $MAINSAIL_STATUS|"
|
||||
echo -e "| | Octoprint: $OCTOPRINT_STATUS|"
|
||||
echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|"
|
||||
echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|"
|
||||
echo -e "| | KlipperScreen: $(print_status "klipperscreen")|"
|
||||
echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|"
|
||||
echo -e "| | |"
|
||||
echo -e "| ${cyan}$KIAUH_VER${default}| KlipperScreen: $KLIPPERSCREEN_STATUS|"
|
||||
echo -e "| $(print_kiauh_version)| Octoprint: $(print_status "octoprint")|"
|
||||
quit_footer
|
||||
}
|
||||
|
||||
print_kiauh_version(){
|
||||
cd ${SRCDIR}/kiauh
|
||||
KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")"
|
||||
function get_kiauh_version() {
|
||||
local version
|
||||
cd "${KIAUH_SRCDIR}"
|
||||
version="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
main_menu(){
|
||||
print_header
|
||||
#print KIAUH update msg if update available
|
||||
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
|
||||
kiauh_update_msg
|
||||
function print_kiauh_version() {
|
||||
local version
|
||||
version="$(printf "%-18s" "$(get_kiauh_version)")"
|
||||
echo "${cyan}${version}${white}"
|
||||
}
|
||||
|
||||
function print_status() {
|
||||
local status component="${1}"
|
||||
status=$(get_"${component}"_status)
|
||||
|
||||
if [[ ${status} == "Not installed!" ]]; then
|
||||
status="${red}${status}${white}"
|
||||
elif [[ ${status} == "Incomplete!" ]]; then
|
||||
status="${yellow}${status}${white}"
|
||||
else
|
||||
status="${green}${status}${white}"
|
||||
fi
|
||||
#check install status
|
||||
print_kiauh_version
|
||||
klipper_status
|
||||
moonraker_status
|
||||
dwc2_status
|
||||
fluidd_status
|
||||
mainsail_status
|
||||
octoprint_status
|
||||
klipperscreen_status
|
||||
print_branch
|
||||
print_msg && clear_msg
|
||||
main_ui
|
||||
|
||||
printf "%-28s" "${status}"
|
||||
}
|
||||
|
||||
function print_klipper_repo() {
|
||||
read_kiauh_ini
|
||||
|
||||
local repo klipper_status
|
||||
klipper_status=$(get_klipper_status)
|
||||
repo=$(echo "${custom_klipper_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//")
|
||||
repo="${repo^^}"
|
||||
|
||||
if [[ ${klipper_status} == "Not installed!" ]]; then
|
||||
repo="${red}-${white}"
|
||||
elif [[ -n ${repo} && ${repo} != "KLIPPER3D/KLIPPER" ]]; then
|
||||
repo="${cyan}custom${white}"
|
||||
else
|
||||
repo="${cyan}Klipper3d/klipper${white}"
|
||||
fi
|
||||
|
||||
printf "%-28s" "${repo}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function main_menu() {
|
||||
print_header && main_ui
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
update)
|
||||
clear
|
||||
print_header
|
||||
update_kiauh
|
||||
print_msg && clear_msg
|
||||
main_ui;;
|
||||
0)
|
||||
clear
|
||||
print_header
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
"start klipper") do_action_service "start" "klipper"; main_ui;;
|
||||
"stop klipper") do_action_service "stop" "klipper"; main_ui;;
|
||||
"restart klipper") do_action_service "restart" "klipper"; main_ui;;
|
||||
"start moonraker") do_action_service "start" "moonraker"; main_ui;;
|
||||
"stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
|
||||
"restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
|
||||
"start octoprint") do_action_service "start" "octoprint"; main_ui;;
|
||||
"stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
|
||||
"restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
|
||||
update) do_action "update_kiauh" "main_ui";;
|
||||
0)clear && print_header
|
||||
upload_selection
|
||||
print_msg && clear_msg
|
||||
main_ui;;
|
||||
1)
|
||||
clear
|
||||
break;;
|
||||
1)clear && print_header
|
||||
install_menu
|
||||
break;;
|
||||
2)
|
||||
clear
|
||||
2) clear && print_header
|
||||
update_menu
|
||||
break;;
|
||||
3)
|
||||
clear
|
||||
3) clear && print_header
|
||||
remove_menu
|
||||
break;;
|
||||
4)
|
||||
clear
|
||||
4)clear && print_header
|
||||
advanced_menu
|
||||
break;;
|
||||
5)
|
||||
clear
|
||||
5)clear && print_header
|
||||
backup_menu
|
||||
break;;
|
||||
6)clear && print_header
|
||||
settings_menu
|
||||
break;;
|
||||
Q|q)
|
||||
echo -e "${green}###### Happy printing! ######${default}"; echo
|
||||
exit -1;;
|
||||
echo -e "${green}###### Happy printing! ######${white}"; echo
|
||||
exit 0;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
main_ui;;
|
||||
deny_action "main_ui";;
|
||||
esac
|
||||
done
|
||||
clear; main_menu
|
||||
|
||||
@@ -1,89 +1,66 @@
|
||||
remove_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function remove_ui() {
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| Files and directories which remain untouched: | "
|
||||
echo -e "| --> ~/printer.cfg | "
|
||||
echo -e "| --> ~/klipper_config | "
|
||||
echo -e "| --> ~/kiauh-backups | "
|
||||
echo -e "| You need remove them manually if you wish so. | "
|
||||
echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |"
|
||||
hr
|
||||
echo -e "| Firmware: | Webinterface: | "
|
||||
echo -e "| 1) [Klipper] | 3) [DWC2] | "
|
||||
echo -e "| | 4) [Mainsail] | "
|
||||
echo -e "| Klipper API: | 5) [Fluidd] | "
|
||||
echo -e "| 2) [Moonraker] | 6) [Octoprint] | "
|
||||
echo -e "| | | "
|
||||
echo -e "| | Webserver: | "
|
||||
echo -e "| | 7) [Nginx] | "
|
||||
echo -e "| | | "
|
||||
echo -e "| | HDMI Screen: | "
|
||||
echo -e "| | 8) [KlipperScreen] | "
|
||||
quit_footer
|
||||
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
|
||||
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
|
||||
echo -e "| 2) [Moonraker] | |"
|
||||
echo -e "| | Webcam Streamer: |"
|
||||
echo -e "| Klipper Webinterface: | 7) [MJPG-Streamer] |"
|
||||
echo -e "| 3) [Mainsail] | |"
|
||||
echo -e "| 4) [Fluidd] | Other: |"
|
||||
echo -e "| | 8) [PrettyGCode] |"
|
||||
echo -e "| Touchscreen GUI: | 9) [Telegram Bot] |"
|
||||
echo -e "| 5) [KlipperScreen] | 10) [NGINX] |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
remove_menu(){
|
||||
print_header
|
||||
remove_ui
|
||||
function remove_menu() {
|
||||
do_action "" "remove_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
remove_klipper
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_klipper" "remove_ui";;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
remove_moonraker
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_moonraker" "remove_ui";;
|
||||
3)
|
||||
clear
|
||||
print_header
|
||||
remove_dwc2
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_mainsail" "remove_ui";;
|
||||
4)
|
||||
clear
|
||||
print_header
|
||||
remove_mainsail
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_fluidd" "remove_ui";;
|
||||
5)
|
||||
clear
|
||||
print_header
|
||||
remove_fluidd
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_klipperscreen" "remove_ui";;
|
||||
6)
|
||||
clear
|
||||
print_header
|
||||
remove_octoprint
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_octoprint" "remove_ui";;
|
||||
7)
|
||||
clear
|
||||
print_header
|
||||
remove_nginx
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
do_action "remove_mjpg-streamer" "remove_ui";;
|
||||
8)
|
||||
clear
|
||||
print_header
|
||||
remove_klipperscreen
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
Q|q)
|
||||
do_action "remove_prettygcode" "remove_ui";;
|
||||
9)
|
||||
do_action "remove_telegram_bot" "remove_ui";;
|
||||
10)
|
||||
do_action "remove_nginx" "remove_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
remove_ui;;
|
||||
deny_action "remove_ui";;
|
||||
esac
|
||||
done
|
||||
remove_menu
|
||||
|
||||
191
scripts/ui/settings_menu.sh
Executable file
191
scripts/ui/settings_menu.sh
Executable file
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function settings_ui() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
local custom_cfg_loc="${custom_klipper_cfg_loc}"
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
local ms_pre_rls="${mainsail_install_unstable}"
|
||||
local fl_pre_rls="${fluidd_install_unstable}"
|
||||
local bbu="${backup_before_update}"
|
||||
|
||||
### config location
|
||||
if [[ -z ${custom_cfg_loc} ]]; then
|
||||
custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}"
|
||||
else
|
||||
custom_cfg_loc="${cyan}${custom_cfg_loc}${white}"
|
||||
fi
|
||||
|
||||
### custom repository
|
||||
custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" )
|
||||
if [[ -z ${custom_repo} ]]; then
|
||||
custom_repo="${cyan}Klipper3D/klipper${white}"
|
||||
else
|
||||
custom_repo="${cyan}${custom_repo}${white}"
|
||||
fi
|
||||
|
||||
### custom repository branch
|
||||
if [[ -z ${custom_branch} ]]; then
|
||||
custom_branch="${cyan}master${white}"
|
||||
else
|
||||
custom_branch="${cyan}${custom_branch}${white}"
|
||||
fi
|
||||
|
||||
### webinterface stable toggle
|
||||
if [[ ${ms_pre_rls} == "false" ]]; then
|
||||
ms_pre_rls="${red}● ${ms_pre_rls}${white}"
|
||||
else
|
||||
ms_pre_rls="${green}● ${ms_pre_rls}${white}"
|
||||
fi
|
||||
|
||||
if [[ ${fl_pre_rls} == "false" ]]; then
|
||||
fl_pre_rls="${red}● ${fl_pre_rls}${white}"
|
||||
else
|
||||
fl_pre_rls="${green}● ${fl_pre_rls}${white}"
|
||||
fi
|
||||
|
||||
### backup before update toggle
|
||||
if [[ "${bbu}" == "false" ]]; then
|
||||
bbu="${red}● ${bbu}${white}"
|
||||
else
|
||||
bbu="${green}● ${bbu}${white}"
|
||||
fi
|
||||
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| Klipper: |"
|
||||
echo -e "| ● Config folder: |"
|
||||
printf "| %-60s|\n" "${custom_cfg_loc}"
|
||||
echo -e "| ● Repository: |"
|
||||
printf "| %-70s|\n" "${custom_repo} (${custom_branch})"
|
||||
hr
|
||||
echo -e "| Install unstable releases: |"
|
||||
printf "| Mainsail: %-29sFluidd: %-27s|\n" "${ms_pre_rls}" "${fl_pre_rls}"
|
||||
hr
|
||||
printf "| Backup before updating: %-42s|\n" "${bbu}"
|
||||
hr
|
||||
echo -e "| 1) Change Klipper config folder location |"
|
||||
echo -e "| 2) Set custom Klipper repository |"
|
||||
blank_line
|
||||
if [[ ${mainsail_install_unstable} == "false" ]]; then
|
||||
echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |"
|
||||
else
|
||||
echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |"
|
||||
fi
|
||||
if [[ ${fluidd_install_unstable} == "false" ]]; then
|
||||
echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |"
|
||||
else
|
||||
echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |"
|
||||
fi
|
||||
blank_line
|
||||
if [[ ${backup_before_update} == "false" ]]; then
|
||||
echo -e "| 5) ${green}Enable${white} automatic backups before updates |"
|
||||
else
|
||||
echo -e "| 5) ${red}Disable${white} automatic backups before updates |"
|
||||
fi
|
||||
back_help_footer
|
||||
}
|
||||
|
||||
function show_settings_help() {
|
||||
local default_cfg="${cyan}${HOME}/klipper_config${white}"
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}Klipper config folder:${white} |"
|
||||
echo -e "| The location of your printer.cfg and all other config |"
|
||||
echo -e "| files that gets used during installation of Klipper |"
|
||||
echo -e "| and all other components which need that location. |"
|
||||
echo -e "| It is not recommended to change this location. |"
|
||||
echo -e "| Be advised, that negative side effects could occur. |"
|
||||
blank_line
|
||||
printf "| Default: %-55s|\n" "${default_cfg}"
|
||||
blank_line
|
||||
hr
|
||||
echo -e "| ${cyan}Install unstable releases:${white} |"
|
||||
echo -e "| If set to ${green}true${white}, KIAUH installs/updates the software |"
|
||||
echo -e "| with the latest, currently available release. |"
|
||||
echo -e "| ${yellow}This will include alpha, beta and rc releases!${white} |"
|
||||
blank_line
|
||||
echo -e "| If set to ${red}false${white}, KIAUH installs/updates the software |"
|
||||
echo -e "| with the most recent stable release. |"
|
||||
blank_line
|
||||
echo -e "| Default: ${red}false${white} |"
|
||||
blank_line
|
||||
hr
|
||||
echo -e "| ${cyan}Backup before updating:${white} |"
|
||||
echo -e "| If set to true, KIAUH will automatically create a |"
|
||||
echo -e "| backup from the corresponding component you are about |"
|
||||
echo -e "| to update before actually updating it, preserving the |"
|
||||
echo -e "| current state of the component in a safe location. |"
|
||||
echo -e "| All backups are stored in '~/kiauh_backups'. |"
|
||||
blank_line
|
||||
echo -e "| Default: ${red}false${white} |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
settings_menu
|
||||
break;;
|
||||
*)
|
||||
deny_action "show_settings_help";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function settings_menu() {
|
||||
clear && print_header
|
||||
settings_ui
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
clear && print_header
|
||||
change_klipper_cfg_folder
|
||||
settings_ui;;
|
||||
2)
|
||||
clear && print_header
|
||||
change_klipper_repo_menu
|
||||
settings_ui;;
|
||||
3)
|
||||
switch_mainsail_releasetype
|
||||
settings_menu;;
|
||||
4)
|
||||
switch_fluidd_releasetype
|
||||
settings_menu;;
|
||||
5)
|
||||
toggle_backup_before_update
|
||||
settings_menu;;
|
||||
B|b)
|
||||
clear
|
||||
main_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_settings_help
|
||||
break;;
|
||||
*)
|
||||
deny_action "settings_ui";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -1,107 +1,131 @@
|
||||
update_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function update_ui() {
|
||||
top_border
|
||||
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| Check the following website for important software | "
|
||||
echo -e "| changes to the config file before updating Klipper: | "
|
||||
echo -e "| | "
|
||||
echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | "
|
||||
bottom_border
|
||||
top_border
|
||||
echo -e "| 0) $BB4U_STATUS| "
|
||||
hr
|
||||
echo -e "| a) [Update all] | Local Vers: | Remote Vers: | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| Firmware: | | | "
|
||||
echo -e "| 1) [Klipper] | $LOCAL_COMMIT | $REMOTE_COMMIT | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| Webinterface: |---------------|--------------| "
|
||||
echo -e "| 2) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | "
|
||||
echo -e "| 3) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | "
|
||||
echo -e "| |---------------|--------------| "
|
||||
echo -e "| 4) [Moonraker] | $LOCAL_MOONRAKER_COMMIT | $REMOTE_MOONRAKER_COMMIT | "
|
||||
echo -e "| 5) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | "
|
||||
echo -e "| 6) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| HDMI Screen: |---------------|--------------| "
|
||||
echo -e "| 7) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | "
|
||||
quit_footer
|
||||
echo -e "| a) [Update all] | | |"
|
||||
echo -e "| | Installed: | Latest: |"
|
||||
echo -e "| Klipper & API: |---------------|--------------|"
|
||||
echo -e "| 1) [Klipper] |$(compare_klipper_versions)|"
|
||||
echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)|"
|
||||
echo -e "| | | |"
|
||||
echo -e "| Klipper Webinterface: |---------------|--------------|"
|
||||
echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)|"
|
||||
echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)|"
|
||||
echo -e "| | | |"
|
||||
echo -e "| Touchscreen GUI: |---------------|--------------|"
|
||||
echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)|"
|
||||
echo -e "| | | |"
|
||||
echo -e "| Other: |---------------|--------------|"
|
||||
echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)|"
|
||||
echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)|"
|
||||
echo -e "| |------------------------------|"
|
||||
echo -e "| 8) [System] | $(check_system_updates) |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
update_menu(){
|
||||
print_header
|
||||
#compare versions
|
||||
ui_print_versions
|
||||
print_msg && clear_msg
|
||||
read_bb4u_stat
|
||||
update_ui
|
||||
function update_menu() {
|
||||
unset update_arr
|
||||
do_action "" "update_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
0)
|
||||
clear
|
||||
print_header
|
||||
toggle_backups
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "toggle_backups" "update_ui";;
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
update_klipper && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_klipper" "update_ui";;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
update_dwc2fk && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_moonraker" "update_ui";;
|
||||
3)
|
||||
clear
|
||||
print_header
|
||||
update_dwc2 && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_mainsail" "update_ui";;
|
||||
4)
|
||||
clear
|
||||
print_header
|
||||
update_moonraker && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_fluidd" "update_ui";;
|
||||
5)
|
||||
clear
|
||||
print_header
|
||||
update_mainsail && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_klipperscreen" "update_ui";;
|
||||
6)
|
||||
clear
|
||||
print_header
|
||||
update_fluidd && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_pgc_for_klipper" "update_ui";;
|
||||
7)
|
||||
clear
|
||||
print_header
|
||||
update_klipperscreen && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
do_action "update_telegram_bot" "update_ui";;
|
||||
8)
|
||||
do_action "update_system" "update_ui";;
|
||||
a)
|
||||
clear
|
||||
print_header
|
||||
update_all && ui_print_versions
|
||||
print_msg && clear_msg
|
||||
update_ui;;
|
||||
Q|q)
|
||||
do_action "update_all" "update_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
ui_print_versions
|
||||
update_ui;;
|
||||
deny_action "update_ui";;
|
||||
esac
|
||||
done
|
||||
update_menu
|
||||
}
|
||||
|
||||
function update_all() {
|
||||
while true; do
|
||||
if (( ${#update_arr[@]} == 0 )); then
|
||||
print_confirm "Everything is already up-to-date!"
|
||||
echo; break
|
||||
fi
|
||||
|
||||
echo
|
||||
top_border
|
||||
echo -e "| The following installations will be updated: |"
|
||||
if [[ "${KLIPPER_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Klipper${white} |"
|
||||
fi
|
||||
if [[ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Moonraker${white} |"
|
||||
fi
|
||||
if [[ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Mainsail${white} |"
|
||||
fi
|
||||
if [[ "${FLUIDD_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Fluidd${white} |"
|
||||
fi
|
||||
if [[ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● KlipperScreen${white} |"
|
||||
fi
|
||||
if [[ "${PGC_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● PrettyGCode for Klipper${white} |"
|
||||
fi
|
||||
if [[ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● MoonrakerTelegramBot${white} |"
|
||||
fi
|
||||
if [[ "${SYS_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● System${white} |"
|
||||
fi
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
if (( ${#update_arr[@]} != 0 )); then
|
||||
read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
for update in "${update_arr[@]}"
|
||||
do
|
||||
#shellcheck disable=SC2250
|
||||
$update
|
||||
done
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
update_kiauh(){
|
||||
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
|
||||
status_msg "Updating KIAUH ..."
|
||||
cd ${HOME}/kiauh
|
||||
### force reset kiauh before updating
|
||||
git reset --hard
|
||||
git pull && ok_msg "Update complete! Please restart KIAUH."
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
update_all(){
|
||||
while true; do
|
||||
if [ "${#update_arr[@]}" = "0" ]; then
|
||||
CONFIRM_MSG="Everything is already up to date!"
|
||||
echo; break
|
||||
fi
|
||||
echo
|
||||
top_border
|
||||
echo -e "| The following installations will be updated: |"
|
||||
if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● Klipper${default} |"
|
||||
fi
|
||||
if [ "$DWC2FK_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● DWC2-for-Klipper-Socket${default} |"
|
||||
fi
|
||||
if [ "$DWC2_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● Duet Web Control${default} |"
|
||||
fi
|
||||
if [ "$MOONRAKER_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● Moonraker${default} |"
|
||||
fi
|
||||
if [ "$MAINSAIL_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● Mainsail${default} |"
|
||||
fi
|
||||
if [ "$FLUIDD_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● Fluidd${default} |"
|
||||
fi
|
||||
if [ "$KLIPPERSCREEN_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● KlipperScreen${default} |"
|
||||
fi
|
||||
bottom_border
|
||||
if [ "${#update_arr[@]}" != "0" ]; then
|
||||
read -p "${cyan}###### Do you want to proceed? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
for update in ${update_arr[@]}
|
||||
do
|
||||
$update
|
||||
done
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
update_klipper(){
|
||||
stop_klipper
|
||||
if [ ! -d $KLIPPER_DIR ]; then
|
||||
cd ${HOME} && git clone $KLIPPER_REPO
|
||||
else
|
||||
bb4u "klipper"
|
||||
read_branch
|
||||
save_klipper_state
|
||||
status_msg "Updating $GET_BRANCH"
|
||||
cd $KLIPPER_DIR
|
||||
if [ "$DETACHED_HEAD" == "true" ]; then
|
||||
git checkout $GET_BRANCH
|
||||
unset DETACHED_HEAD
|
||||
fi
|
||||
git pull && ok_msg "Update successfull!"
|
||||
|
||||
#check for possible new dependencies and install them
|
||||
status_msg "Checking for possible new dependencies ..."
|
||||
PKGLIST=$(grep "PKGLIST=" ~/klipper/scripts/install-octopi.sh | cut -d'"' -f2- | cut -d'"' -f1 | cut -d"}" -f2)
|
||||
PYTHONDIR="${HOME}/klippy-env"
|
||||
sudo apt-get update && sudo apt-get install --yes $PKGLIST
|
||||
$PYTHONDIR/bin/pip install -r ~/klipper/scripts/klippy-requirements.txt
|
||||
ok_msg "Dependencies already met or have been installed!"
|
||||
ok_msg "Update complete!"
|
||||
fi
|
||||
start_klipper
|
||||
}
|
||||
|
||||
update_dwc2fk(){
|
||||
stop_dwc
|
||||
bb4u "dwc2"
|
||||
if [ ! -d $DWC2FK_DIR ]; then
|
||||
cd ${HOME} && git clone $DWC2FK_REPO
|
||||
else
|
||||
cd $DWC2FK_DIR && git pull
|
||||
fi
|
||||
start_dwc
|
||||
}
|
||||
|
||||
update_dwc2(){
|
||||
bb4u "dwc2"
|
||||
download_dwc2_webui
|
||||
}
|
||||
|
||||
update_mainsail(){
|
||||
bb4u "mainsail"
|
||||
status_msg "Updating Mainsail ..."
|
||||
mainsail_setup
|
||||
}
|
||||
|
||||
update_fluidd(){
|
||||
bb4u "fluidd"
|
||||
status_msg "Updating Fluidd ..."
|
||||
fluidd_setup
|
||||
}
|
||||
|
||||
update_moonraker(){
|
||||
bb4u "moonraker"
|
||||
status_msg "Updating Moonraker ..."
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| You can now choose how you want to update Moonraker. |"
|
||||
blank_line
|
||||
echo -e "| Changes made to the Moonraker code and/or its depen- |"
|
||||
echo -e "| dencies might require a rebuild of the python virtual |"
|
||||
echo -e "| environment or downloading of additional packages. |"
|
||||
blank_line
|
||||
echo -e "| ${red}Check the docs in the Moonraker repository to see if${default} |"
|
||||
echo -e "| ${red}rebuilding is necessary (user_changes.md)!${default} |"
|
||||
blank_line
|
||||
echo -e "| 1) Update Moonraker (default) |"
|
||||
echo -e "| 2) Update Moonraker + rebuild virtualenv/dependencies |"
|
||||
quit_footer
|
||||
read -p "${cyan}###### Please choose:${default} " action
|
||||
case "$action" in
|
||||
1|"")
|
||||
echo -e "###### > Update Moonraker"
|
||||
update_mr="true" && rebuild_env="false"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > Update Moonraker + rebuild virtualenv/dependencies"
|
||||
update_mr="true" && rebuild_env="true"
|
||||
break;;
|
||||
Q|q)
|
||||
clear; update_menu; break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
stop_moonraker; echo
|
||||
if [[ $update_mr = "true" ]] && [[ $rebuild_env = "false" ]]; then
|
||||
unset update_mr && unset rebuild_env
|
||||
cd $MOONRAKER_DIR && git pull
|
||||
fi
|
||||
if [[ $update_mr = "true" ]] && [[ $rebuild_env = "true" ]]; then
|
||||
unset update_mr && unset rebuild_env
|
||||
cd $MOONRAKER_DIR && git pull && ./scripts/install-moonraker.sh -r
|
||||
fi
|
||||
#read printer.cfg location and patch /etc/default/klipper if entries don't match
|
||||
locate_printer_cfg && patch_klipper_sysfile
|
||||
ok_msg "Update complete!"
|
||||
restart_moonraker
|
||||
}
|
||||
|
||||
update_klipperscreen(){
|
||||
stop_klipperscreen
|
||||
cd $KLIPPERSCREEN_DIR
|
||||
KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1)
|
||||
git pull origin master -q && ok_msg "Fetch successfull!"
|
||||
git checkout -f origin/master && ok_msg "Checkout successfull"
|
||||
#KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt)
|
||||
if [[ $(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1) != $KLIPPERSCREEN_OLDREQ_MD5SUM ]]; then
|
||||
status_msg "New dependecies detected..."
|
||||
PYTHONDIR="${HOME}/.KlipperScreen-env"
|
||||
$PYTHONDIR/bin/pip install -r $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt
|
||||
ok_msg "Dependencies have been installed!"
|
||||
fi
|
||||
ok_msg "Update complete!"
|
||||
start_klipperscreen
|
||||
}
|
||||
@@ -1,24 +1,39 @@
|
||||
accept_upload_conditions(){
|
||||
while true; do
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function accept_upload_conditions() {
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${default} |"
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| The following function will help to quickly upload |"
|
||||
echo -e "| logs for debugging purposes. With confirming this |"
|
||||
echo -e "| dialog, you agree that during that process your logs |"
|
||||
echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${default} |"
|
||||
echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |"
|
||||
hr
|
||||
echo -e "| ${red}PLEASE NOTE:${default} |"
|
||||
echo -e "| ${red}PLEASE NOTE:${white} |"
|
||||
echo -e "| Be aware that logs can contain network information, |"
|
||||
echo -e "| private data like usernames, filenames, or other |"
|
||||
echo -e "| information you may not want to make public. |"
|
||||
blank_line
|
||||
echo -e "| Do ${red}NOT${default} use this function if you don't agree! |"
|
||||
echo -e "| Do ${red}NOT${white} use this function if you don't agree! |"
|
||||
bottom_border
|
||||
read -p "${cyan}Do you accept? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}Do you accept? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
sed -i "/logupload_accepted=/s/false/true/" $INI_FILE
|
||||
sed -i "/logupload_accepted=/s/false/true/" "${INI_FILE}"
|
||||
clear && print_header && upload_selection
|
||||
;;
|
||||
N|n|No|no)
|
||||
@@ -27,63 +42,81 @@ accept_upload_conditions(){
|
||||
break
|
||||
;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
accept_upload_conditions;;
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
upload_selection(){
|
||||
source_ini
|
||||
[ "$logupload_accepted" = "false" ] && accept_upload_conditions
|
||||
KLIPPY_LOG=/tmp/klippy.log
|
||||
MOONRAKER_LOG=/tmp/moonraker.log
|
||||
DWC2_LOG=/tmp/dwc2.log
|
||||
function upload_selection() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
local upload_agreed="${logupload_accepted}"
|
||||
[[ ${upload_agreed} == "false" ]] && accept_upload_conditions
|
||||
|
||||
local logfiles
|
||||
local logs_dir="${KLIPPER_LOGS}"
|
||||
local webif_logs="/var/log/nginx"
|
||||
|
||||
function find_logfile() {
|
||||
local name=${1} location=${2}
|
||||
for log in $(find "${location}" -maxdepth 1 -regextype posix-extended -regex "${location}/${name}" | sort -g); do
|
||||
logfiles+=("${log}")
|
||||
done
|
||||
}
|
||||
|
||||
find_logfile "kiauh\.log" "/tmp"
|
||||
find_logfile "klippy(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
|
||||
find_logfile "moonraker(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
|
||||
find_logfile "telegram(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
|
||||
find_logfile "mainsail.*" "${webif_logs}"
|
||||
find_logfile "fluidd.*" "${webif_logs}"
|
||||
find_logfile "KlipperScreen.log" "/tmp"
|
||||
find_logfile "webcamd\.log(\.[0-9]+)?$" "/var/log"
|
||||
|
||||
### draw interface
|
||||
local i=0
|
||||
top_border
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |"
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| You can choose the following files for uploading: |"
|
||||
echo -e "| 1) klippy.log |"
|
||||
echo -e "| 2) moonraker.log |"
|
||||
echo -e "| 3) dwc2.log |"
|
||||
quit_footer
|
||||
echo -e "| You can choose the following logfiles for uploading: |"
|
||||
blank_line
|
||||
|
||||
for log in "${logfiles[@]}"; do
|
||||
log=${log//${HOME}/"~"}
|
||||
(( i < 10 )) && printf "| ${i}) %-50s|\n" "${log}"
|
||||
(( i >= 10 )) && printf "| ${i}) %-50s|\n" "${log}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local option re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please select:${default} " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
clear && print_header
|
||||
upload_log "$KLIPPY_LOG"
|
||||
read -p "${cyan}###### Please select:${white} " option
|
||||
|
||||
if [[ ${option} =~ ${re} && ${option} -lt ${#logfiles[@]} ]]; then
|
||||
upload_log "${logfiles[${option}]}"
|
||||
upload_selection
|
||||
;;
|
||||
2)
|
||||
clear && print_header
|
||||
upload_log "$MOONRAKER_LOG"
|
||||
upload_selection
|
||||
;;
|
||||
3)
|
||||
clear && print_header
|
||||
upload_log "$DWC2_LOG"
|
||||
upload_selection
|
||||
;;
|
||||
q | Q) clear; main_menu; break;;
|
||||
esac
|
||||
elif [[ ${option} == "B" || ${option} == "b" ]]; then
|
||||
return
|
||||
else
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
upload_log(){
|
||||
if [ -f "$1" ]; then
|
||||
status_msg "Uploading $1 ..."
|
||||
LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/')
|
||||
[ ! -z "$LINK" ] && ok_msg "$1 upload successfull!"
|
||||
echo -e "\n${cyan}###### Here is your link:${default}"
|
||||
echo -e ">>>>>> $LINK\n"
|
||||
unset LINK
|
||||
else
|
||||
function upload_log() {
|
||||
local link
|
||||
clear && print_header
|
||||
ERROR_MSG="$1 not found!" && print_msg && clear_msg
|
||||
upload_selection
|
||||
status_msg "Uploading ${1} ..."
|
||||
link=$(curl -s -H "x-random;" --upload-file "${1}" 'http://paste.c-net.org/')
|
||||
|
||||
if [[ -n ${link} ]]; then
|
||||
ok_msg "${1} upload successfull!"
|
||||
echo -e "\n${cyan}###### Here is your link:${white}"
|
||||
echo -e ">>>>>> ${link}\n"
|
||||
else
|
||||
error_msg "Uploading failed!"
|
||||
fi
|
||||
}
|
||||
654
scripts/utilities.sh
Normal file
654
scripts/utilities.sh
Normal file
@@ -0,0 +1,654 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#================================================#
|
||||
#=================== STARTUP ====================#
|
||||
#================================================#
|
||||
|
||||
function check_euid() {
|
||||
if [[ ${EUID} -eq 0 ]]; then
|
||||
echo -e "${red}"
|
||||
top_border
|
||||
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
|
||||
bottom_border
|
||||
echo -e "${white}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#============= MESSAGE FORMATTING ===============#
|
||||
#================================================#
|
||||
|
||||
function select_msg() {
|
||||
echo -e "${white} [➔] ${1}"
|
||||
}
|
||||
function status_msg() {
|
||||
echo -e "\n${magenta}###### ${1}${white}"
|
||||
}
|
||||
function ok_msg() {
|
||||
echo -e "${green}[✓ OK] ${1}${white}"
|
||||
}
|
||||
function warn_msg() {
|
||||
echo -e "${yellow}>>>>>> ${1}${white}"
|
||||
}
|
||||
function error_msg() {
|
||||
echo -e "${red}>>>>>> ${1}${white}"
|
||||
}
|
||||
function abort_msg() {
|
||||
echo -e "${red}<<<<<< ${1}${white}"
|
||||
}
|
||||
function title_msg() {
|
||||
echo -e "${cyan}${1}${white}"
|
||||
}
|
||||
|
||||
function print_error() {
|
||||
[[ -z ${1} ]] && return
|
||||
|
||||
echo -e "${red}"
|
||||
echo -e "#=======================================================#"
|
||||
echo -e " ${1} "
|
||||
echo -e "#=======================================================#"
|
||||
echo -e "${white}"
|
||||
}
|
||||
|
||||
function print_confirm() {
|
||||
[[ -z ${1} ]] && return
|
||||
|
||||
echo -e "${green}"
|
||||
echo -e "#=======================================================#"
|
||||
echo -e " ${1} "
|
||||
echo -e "#=======================================================#"
|
||||
echo -e "${white}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== LOGGING ====================#
|
||||
#================================================#
|
||||
|
||||
function timestamp() {
|
||||
date +"[%F %T]"
|
||||
}
|
||||
|
||||
function init_logfile() {
|
||||
local log="/tmp/kiauh.log"
|
||||
{
|
||||
echo -e "#================================================================#"
|
||||
echo -e "# New KIAUH session started on: $(date) #"
|
||||
echo -e "#================================================================#"
|
||||
echo -e "KIAUH $(get_kiauh_version)"
|
||||
echo -e "#================================================================#"
|
||||
} >> "${log}"
|
||||
}
|
||||
|
||||
function log_info() {
|
||||
local message="${1}" log="${LOGFILE}"
|
||||
echo -e "$(timestamp) [INFO]: ${message}" | tr -s " " >> "${log}"
|
||||
}
|
||||
|
||||
function log_warning() {
|
||||
local message="${1}" log="${LOGFILE}"
|
||||
echo -e "$(timestamp) [WARN]: ${message}" | tr -s " " >> "${log}"
|
||||
}
|
||||
|
||||
function log_error() {
|
||||
local message="${1}" log="${LOGFILE}"
|
||||
echo -e "$(timestamp) [ERR]: ${message}" | tr -s " " >> "${log}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=============== KIAUH SETTINGS =================#
|
||||
#================================================#
|
||||
|
||||
function read_kiauh_ini() {
|
||||
local func=${1}
|
||||
|
||||
if [[ ! -f ${INI_FILE} ]]; then
|
||||
log_warning "Reading from .kiauh.ini failed! File not found! Creating default ini file."
|
||||
init_ini
|
||||
fi
|
||||
|
||||
log_info "Reading from .kiauh.ini ... (${func})"
|
||||
source "${INI_FILE}"
|
||||
}
|
||||
|
||||
function init_ini() {
|
||||
### remove pre-version 4 ini files
|
||||
if [[ -f ${INI_FILE} ]] && ! grep -Eq "^# KIAUH v4\.0\.0$" "${INI_FILE}"; then
|
||||
rm "${INI_FILE}"
|
||||
fi
|
||||
|
||||
### initialize v4.0.0 ini file
|
||||
if [[ ! -f ${INI_FILE} ]]; then
|
||||
{
|
||||
echo -e "# File creation date: $(date)"
|
||||
echo -e "#=================================================#"
|
||||
echo -e "# KIAUH - Klipper Installation And Update Helper #"
|
||||
echo -e "# https://github.com/th33xitus/kiauh #"
|
||||
echo -e "# DO NOT edit this file! #"
|
||||
echo -e "#=================================================#"
|
||||
echo -e "# KIAUH v4.0.0"
|
||||
} >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then
|
||||
echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^logupload_accepted=." "${INI_FILE}"; then
|
||||
echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then
|
||||
echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then
|
||||
echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^custom_klipper_repo_branch=" "${INI_FILE}"; then
|
||||
echo -e "\ncustom_klipper_repo_branch=\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then
|
||||
echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^fluidd_install_unstable=" "${INI_FILE}"; then
|
||||
echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
fetch_webui_ports
|
||||
}
|
||||
|
||||
function change_klipper_cfg_folder() {
|
||||
local current_cfg_loc example_loc recommended_loc new_cfg_loc
|
||||
current_cfg_loc="$(get_klipper_cfg_dir)"
|
||||
example_loc=$(printf "%s/<your_config_folder>" "${HOME}")
|
||||
recommended_loc=$(printf "%s/klipper_config" "${HOME}")
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
top_border
|
||||
echo -e "| ${yellow}IMPORTANT:${white} |"
|
||||
echo -e "| Please enter the new path in the following format: |"
|
||||
printf "| ${cyan}%-51s${white} |\n" "${example_loc}"
|
||||
blank_line
|
||||
echo -e "| ${red}WARNING: ${white} |"
|
||||
echo -e "| ${red}There will be no validation checks! Make sure to set${white} |"
|
||||
echo -e "| ${red}a valid directory to prevent possible problems!${white} |"
|
||||
blank_line
|
||||
printf "| Recommended: ${cyan}%-38s${white} |\n" "${recommended_loc}"
|
||||
bottom_border
|
||||
echo
|
||||
echo -e "${cyan}###### Please set the new Klipper config directory:${white} "
|
||||
read -e -i "${current_cfg_loc}" -e new_cfg_loc
|
||||
echo
|
||||
read -p "${cyan}###### Set config directory to '${yellow}${new_cfg_loc}${cyan}' ? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
set_klipper_cfg_path "${current_cfg_loc}" "${new_cfg_loc}"
|
||||
print_confirm "New config directory set!"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function set_klipper_cfg_path() {
|
||||
local current_cfg_loc="${1}" new_cfg_loc="${2}"
|
||||
local instance klipper_services moonraker_services moonraker_configs
|
||||
|
||||
log_info "Function set_klipper_cfg_path invoked\nCurrent location: ${1}\nNew location: ${2}"
|
||||
### backup the old config dir
|
||||
backup_klipper_config_dir
|
||||
### write new location to .kiauh.ini
|
||||
sed -i "/^custom_klipper_cfg_loc=/d" "${INI_FILE}"
|
||||
sed -i '$a'"custom_klipper_cfg_loc=${new_cfg_loc}" "${INI_FILE}"
|
||||
status_msg "New directory was set to '${new_cfg_loc}'!"
|
||||
|
||||
### stop services
|
||||
do_action_service "stop" "klipper"
|
||||
do_action_service "stop" "moonraker"
|
||||
|
||||
### copy config files to new klipper config folder
|
||||
if [[ -n ${current_cfg_loc} && -d ${current_cfg_loc} ]]; then
|
||||
status_msg "Copy config files to '${new_cfg_loc}' ..."
|
||||
|
||||
if [[ ! -d ${new_cfg_loc} ]]; then
|
||||
log_info "Copy process started"
|
||||
mkdir -p "${new_cfg_loc}"
|
||||
cd "${current_cfg_loc}"
|
||||
cp -r -v ./* "${new_cfg_loc}"
|
||||
ok_msg "Done!"
|
||||
else
|
||||
log_warning "Copy process skipped, new config directory already exists and may not be empty!"
|
||||
warn_msg "New config directory already exists! Copy process skipped!"
|
||||
fi
|
||||
fi
|
||||
|
||||
klipper_services=$(klipper_systemd)
|
||||
|
||||
if [[ -n ${klipper_services} ]]; then
|
||||
status_msg "Re-writing Klipper services to use new config file location ..."
|
||||
|
||||
for service in ${klipper_services}; do
|
||||
if [[ ${service} = "/etc/systemd/system/klipper.service" ]]; then
|
||||
|
||||
if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then
|
||||
### single instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer\.cfg|CONFIG=${new_cfg_loc}/printer\.cfg|" "${service}"
|
||||
else
|
||||
### single instance klipper service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer\.cfg|" "${service}"
|
||||
fi
|
||||
|
||||
else
|
||||
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
|
||||
|
||||
if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then
|
||||
### multi instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer_${instance}\/printer\.cfg|CONFIG=${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
|
||||
else
|
||||
### multi instance klipper service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer_${instance}\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
|
||||
if [[ -n ${moonraker_services} ]]; then
|
||||
### handle multi moonraker instance service file
|
||||
status_msg "Re-writing Moonraker services to use new config file location ..."
|
||||
|
||||
for service in ${moonraker_services}; do
|
||||
if [[ ${service} = "/etc/systemd/system/moonraker.service" ]]; then
|
||||
|
||||
if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then
|
||||
### single instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/moonraker\.conf|_CONF=${new_cfg_loc}\/moonraker\.conf|" "${service}"
|
||||
else
|
||||
### single instance moonraker service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/moonraker\.conf| -c ${new_cfg_loc}\/moonraker\.conf|" "${service}"
|
||||
fi
|
||||
|
||||
else
|
||||
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
|
||||
|
||||
if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then
|
||||
### multi instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/printer_${instance}\/moonraker\.conf|_CONF=${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
|
||||
else
|
||||
### multi instance moonraker service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/printer_${instance}\/moonraker\.conf| -c ${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
### replace old file path with new one in moonraker.conf
|
||||
local loc
|
||||
for conf in ${moonraker_configs}; do
|
||||
loc=$(echo "${conf}" | rev | cut -d"/" -f2- | rev)
|
||||
sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${conf}"
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
### restart services
|
||||
do_action_service "restart" "klipper"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
function switch_mainsail_releasetype() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${mainsail_install_unstable}"
|
||||
|
||||
if [[ ${state} == "false" ]]; then
|
||||
sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}"
|
||||
log_info "mainsail_install_unstable changed (false -> true) "
|
||||
else
|
||||
sed -i '/mainsail_install_unstable=/s/true/false/' "${INI_FILE}"
|
||||
log_info "mainsail_install_unstable changed (true -> false) "
|
||||
fi
|
||||
}
|
||||
|
||||
function switch_fluidd_releasetype() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${fluidd_install_unstable}"
|
||||
|
||||
if [[ ${state} == "false" ]]; then
|
||||
sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}"
|
||||
log_info "fluidd_install_unstable changed (false -> true) "
|
||||
else
|
||||
sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}"
|
||||
log_info "fluidd_install_unstable changed (true -> false) "
|
||||
fi
|
||||
}
|
||||
|
||||
function toggle_backup_before_update() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${backup_before_update}"
|
||||
|
||||
if [[ ${state} = "false" ]]; then
|
||||
sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}"
|
||||
else
|
||||
sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}"
|
||||
fi
|
||||
}
|
||||
|
||||
function set_custom_klipper_repo() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
sed -i "/^custom_klipper_repo=/d" "${INI_FILE}"
|
||||
sed -i '$a'"custom_klipper_repo=${repo}" "${INI_FILE}"
|
||||
sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}"
|
||||
sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=============== HANDLE SERVICES ================#
|
||||
#================================================#
|
||||
|
||||
function do_action_service() {
|
||||
local services action=${1} service=${2}
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
|
||||
if [[ -n ${services} ]]; then
|
||||
for service in ${services}; do
|
||||
service=$(echo "${service}" | rev | cut -d"/" -f1 | rev)
|
||||
status_msg "${action^} ${service} ..."
|
||||
|
||||
if sudo systemctl "${action}" "${service}"; then
|
||||
log_info "${service}: ${action} > success"
|
||||
ok_msg "${action^} ${service} successfull!"
|
||||
else
|
||||
log_warning "${service}: ${action} > failed"
|
||||
warn_msg "${action^} ${service} failed!"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ DEPENDENCIES ==================#
|
||||
#================================================#
|
||||
|
||||
### returns 'true' if python version >= 3.7
|
||||
function python3_check() {
|
||||
local major minor passed
|
||||
|
||||
major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1)
|
||||
minor=$(python3 --version | cut -d"." -f2)
|
||||
|
||||
if (( major >= 3 && minor >= 7 )); then
|
||||
passed="true"
|
||||
else
|
||||
passed="false"
|
||||
fi
|
||||
|
||||
echo "${passed}"
|
||||
}
|
||||
|
||||
function dependency_check() {
|
||||
local dep=( "${@}" )
|
||||
local packages
|
||||
status_msg "Checking for the following dependencies:"
|
||||
|
||||
#check if package is installed, if not write its name into array
|
||||
for pkg in "${dep[@]}"; do
|
||||
echo -e "${cyan}● ${pkg} ${white}"
|
||||
[[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]] && \
|
||||
packages+=("${pkg}")
|
||||
done
|
||||
|
||||
#if array is not empty, install packages from array
|
||||
if (( ${#packages[@]} > 0 )); then
|
||||
status_msg "Installing the following dependencies:"
|
||||
for package in "${packages[@]}"; do
|
||||
echo -e "${cyan}● ${package} ${white}"
|
||||
done
|
||||
echo
|
||||
|
||||
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then
|
||||
ok_msg "Dependencies installed!"
|
||||
else
|
||||
error_msg "Installing dependencies failed!"
|
||||
return 1 # exit kiauh
|
||||
fi
|
||||
else
|
||||
ok_msg "Dependencies already met!"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
function fetch_webui_ports() {
|
||||
local port interfaces=("mainsail" "fluidd" "octoprint")
|
||||
|
||||
### read ports from possible installed interfaces and write them to ~/.kiauh.ini
|
||||
for interface in "${interfaces[@]}"; do
|
||||
if [[ -f "/etc/nginx/sites-available/${interface}" ]]; then
|
||||
port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2)
|
||||
if ! grep -Eq "${interface}_port" "${INI_FILE}"; then
|
||||
sed -i '$a'"${interface}_port=${port}" "${INI_FILE}"
|
||||
else
|
||||
sed -i "/^${interface}_port/d" "${INI_FILE}"
|
||||
sed -i '$a'"${interface}_port=${port}" "${INI_FILE}"
|
||||
fi
|
||||
else
|
||||
sed -i "/^${interface}_port/d" "${INI_FILE}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== SYSTEM =====================#
|
||||
#================================================#
|
||||
|
||||
function check_system_updates() {
|
||||
local updates_avail info_msg
|
||||
updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d")
|
||||
|
||||
if [[ -n ${updates_avail} ]]; then
|
||||
# add system updates to the update all array for the update all function in the updater
|
||||
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
|
||||
info_msg="${yellow}System upgrade available!${white}"
|
||||
else
|
||||
SYS_UPDATE_AVAIL="false"
|
||||
info_msg="${green}System up to date! ${white}"
|
||||
fi
|
||||
|
||||
echo "${info_msg}"
|
||||
}
|
||||
|
||||
function update_system() {
|
||||
status_msg "Updating System ..."
|
||||
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y; then
|
||||
print_confirm "Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}"
|
||||
else
|
||||
print_error "System update failed! Please watch for any errors printed above!"
|
||||
fi
|
||||
}
|
||||
|
||||
function check_usergroups() {
|
||||
local group_dialout group_tty
|
||||
|
||||
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
|
||||
group_dialout="false"
|
||||
fi
|
||||
|
||||
if grep -q "tty" </etc/group && ! grep -q "tty" <(groups "${USER}"); then
|
||||
group_tty="false"
|
||||
fi
|
||||
|
||||
if [[ ${group_dialout} == "false" || ${group_tty} == "false" ]] ; then
|
||||
top_border
|
||||
echo -e "| ${yellow}WARNING: Your current user is not in group:${white} |"
|
||||
[[ ${group_tty} == "false" ]] && \
|
||||
echo -e "| ${yellow}● tty${white} |"
|
||||
[[ ${group_dialout} == "false" ]] && \
|
||||
echo -e "| ${yellow}● dialout${white} |"
|
||||
blank_line
|
||||
echo -e "| It is possible that you won't be able to successfully |"
|
||||
echo -e "| connect and/or flash the controller board without |"
|
||||
echo -e "| your user being a member of that group. |"
|
||||
echo -e "| If you want to add the current user to the group(s) |"
|
||||
echo -e "| listed above, answer with 'Y'. Else skip with 'n'. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}INFO:${white} |"
|
||||
echo -e "| ${yellow}Relog required for group assignments to take effect!${white} |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
status_msg "Adding user '${USER}' to group(s) ..."
|
||||
if [[ ${group_tty} == "false" ]]; then
|
||||
sudo usermod -a -G tty "${USER}" && ok_msg "Group 'tty' assigned!"
|
||||
fi
|
||||
if [[ ${group_dialout} == "false" ]]; then
|
||||
sudo usermod -a -G dialout "${USER}" && ok_msg "Group 'dialout' assigned!"
|
||||
fi
|
||||
ok_msg "Remember to relog/restart this machine for the group(s) to be applied!"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function set_custom_hostname() {
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Changing the hostname of this machine allows you to |"
|
||||
echo -e "| access a webinterface that is configured for port 80 |"
|
||||
echo -e "| by simply typing '<hostname>.local' in the browser. |"
|
||||
echo -e "| |"
|
||||
echo -e "| E.g.: If you set the hostname to 'my-printer' you |"
|
||||
echo -e "| can open Mainsail / Fluidd / Octoprint by |"
|
||||
echo -e "| browsing to: http://my-printer.local |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
change_hostname
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function change_hostname() {
|
||||
local new_hostname regex="^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$"
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |"
|
||||
echo -e "| ${red}No special characters allowed!${white} |"
|
||||
echo -e "| ${red}No leading or trailing '-' allowed!${white} |"
|
||||
bottom_border
|
||||
|
||||
while true; do
|
||||
read -p "${cyan}###### Please set the new hostname:${white} " new_hostname
|
||||
|
||||
if [[ ${new_hostname} =~ ${regex} ]]; then
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want '${new_hostname}' to be the new hostname? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
set_hostname "${new_hostname}"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Skip hostname change ..."
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
warn_msg "'${new_hostname}' is not a valid hostname!"
|
||||
fi
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
function set_hostname() {
|
||||
local new_hostname=${1} current_date
|
||||
#check for dependencies
|
||||
local dep=(avahi-daemon)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
#create host file if missing or create backup of existing one with current date&time
|
||||
if [[ -f /etc/hosts ]]; then
|
||||
current_date=$(get_date)
|
||||
status_msg "Creating backup of hosts file ..."
|
||||
sudo cp "/etc/hosts" "/etc/hosts.${current_date}.bak"
|
||||
ok_msg "Backup done!"
|
||||
ok_msg "File:'/etc/hosts.${current_date}.bak'"
|
||||
else
|
||||
sudo touch /etc/hosts
|
||||
fi
|
||||
|
||||
#set new hostname in /etc/hostname
|
||||
status_msg "Setting hostname to '${new_hostname}' ..."
|
||||
status_msg "Please wait ..."
|
||||
sudo hostnamectl set-hostname "${new_hostname}"
|
||||
|
||||
#write new hostname to /etc/hosts
|
||||
status_msg "Writing new hostname to /etc/hosts ..."
|
||||
echo "127.0.0.1 ${new_hostname}" | sudo tee -a /etc/hosts &>/dev/null
|
||||
ok_msg "New hostname successfully configured!"
|
||||
ok_msg "Remember to reboot for the changes to take effect!"
|
||||
}
|
||||
|
||||
### this function takes in the full path of a systemd service file and returns
|
||||
### either the instance index or the custom name
|
||||
### input: /etc/systemd/system/klipper-name.service
|
||||
### returns: name
|
||||
function get_instance_name() {
|
||||
local instance=${1} name
|
||||
name=$(echo "${instance}" | rev | cut -d"/" -f1 | rev | cut -d"-" -f2 | cut -d"." -f1)
|
||||
echo "${name}"
|
||||
}
|
||||
Reference in New Issue
Block a user