Compare commits

...

419 Commits

Author SHA1 Message Date
dw-0
d0854c63ad chore: this is the last commit for KIAUH v5 2025-10-11 16:35:16 +02:00
dw-0
8851bd68f8 feat(ui): update messaging for KIAUH v6 to reflect RC.2 status and encourage migration from v5 2025-10-05 17:20:30 +02:00
dw-0
9168ad88a6 refactor(backup): migrate backup_printer_config_dir to BackupService and update references accordingly 2025-09-30 21:11:48 +02:00
dw-0
03c0d46a2e feat(backup): add fallback to search printer data directories in home directory if no instances found 2025-09-30 20:59:04 +02:00
dw-0
8a8afc60ee feat(backup): integrate backup functionality into multiple extensions and config management 2025-09-30 20:36:42 +02:00
dw-0
5b68710b23 feat(backup): add specific backup methods for Klipper and Moonraker configs 2025-09-29 21:21:55 +02:00
dw-0
6cee0252ee feat(moonraker): sync moonraker changes to SysDepsParser
206fd4828d

72b89d905e
2025-09-29 20:29:38 +02:00
dw-0
aff63665de refactor: replace backup_manager with backup_service 2025-09-28 16:14:58 +02:00
dw-0
1ed1e0fc4c chore(dev): replace pyright with mypy and configure mypy rules 2025-09-27 22:44:03 +02:00
dw-0
81ac102644 fix(v5): add back example file for custom Klipper repository management 2025-09-20 15:17:37 +02:00
dw-0
89b48168f4 fix: do not drop SAVE_CONFIG block when editing and writing config files (#723)
Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 4a6e5f2..f5eee99

f5eee99 feat: add support for parsing and handling `SAVE_CONFIG` blocks (#4)
8170583 refactor(api)!: `getval` now returns a string, `getvals` returns list of strings

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: f5eee99b0f04717c6bbf30c1256d70ad019223d5
2025-09-06 13:12:20 +02:00
Oleg Gurev
195b7fa926 fix: add moonraker-hmi and moonraker-telegram-bot to the blacklist (#720)
* Add moonraker-hmi and moonraker-telegram-bot to the blacklist of moonraker service detection function

* fix: add "hmi" to SUFFIX_BLACKLIST to prevent instance name conflicts

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2025-08-31 11:30:16 +02:00
dw-0
12919c7140 feat(extension): add website and repo metadata for extensions, update links formatting in menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-30 22:02:12 +02:00
dw-0
e590f668e6 fix(common): return default version if no tags exist in get_kiauh_version
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-28 18:28:40 +02:00
Tovi
075f2d384b docs(readme): add chinese readme instructions (#707)
* add chinese readme

* translated raspberry pi to chinese
2025-08-28 17:45:39 +02:00
dw-0
afdde34721 feat(core): add repository management to settings (#718)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-28 16:22:02 +02:00
dw-0
393dd1d5bf feat(extension): add OctoPrint installer (#716)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-28 16:21:42 +02:00
dw-0
8170057434 fix(moonraker): correctly patch trusted_clients options
fixes #711 #709

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-03 10:07:13 +02:00
Maksym Pyrozhok
985b66d41f chore: fix typos (#695)
Fix typo.
2025-07-12 19:36:38 +02:00
dw-0
f95d2586bf fix(webclient): add config.json to moonraker persistent files (#699)
fixes #694

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-06-28 10:12:28 +02:00
dw-0
f5141e7eff fix(mainsail): check for json configured as instanceDB (#698)
fix(mainsail): check for json configures as instanceDB

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-06-27 22:37:44 +02:00
dw-0
33113e72e9 fix: exception raised on pip warning (#688)
pip seems to write to stderr on warnings, caused by retries. even if the process exits with 0.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-05-31 17:44:02 +02:00
dw-0
6f59fd06aa fix: do not upgrade pip before installing packages (#680)
pip 25 seems to introduce some compatibility issues.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-05-02 20:08:32 +02:00
dw-0
56ea43ccb6 refactor: improve typesafety KiauhSettings
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-14 21:19:38 +02:00
dw-0
25e22c993f chore(scp): update SimpleConfigParser
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-14 21:15:12 +02:00
dw-0
ead521b377 refactor: replace mypy with pyright
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-14 21:07:56 +02:00
dw-0
3c952ccc12 refactor: use sane fallbacks on missing kiauh config options
for some options a warning is print if the fallback is used

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-12 15:12:11 +02:00
dw-0
c8f713c00e fix: no validation of optional_speedups option
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-12 00:36:34 +02:00
Pavel Sorejs
95cf809378 feat: add option to customize python binary for Klipper and Moonraker, add option to not install Moonraker speedups (#671)
Add option to cusomize python binary for klipper and moonraker. Add option to not install moonraker speedups.
2025-04-06 22:23:39 +02:00
dw-0
c91816d13f feat(extension): add Spoolman Docker installer (#669)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-30 17:57:46 +02:00
dw-0
1a6f06eaf2 refactor(moonraker): move setup functions into MoonrakerSetupService
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-29 23:00:06 +01:00
dw-0
ea8621af0c refactor(git_utils): remove unnecessary url parameter in git_pull_wrapper
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-29 16:49:08 +01:00
dw-0
88742ab496 feat: allow configuration of multiple repos in kiauh.cfg (#668)
* remove existing simple_config_parser directory

* Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit da22e6a

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: da22e6ad9ca4bc121c39dc3bc6c63175a72e78a2

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from da22e6a..9ae5749

9ae5749 fix: comment out file writing in test
1ac4e3d refactor: improve section writing

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 9ae574930dfe82107a3712c7c72b3aa777588996

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 9ae5749..53e8408

53e8408 fix: do not add a blank line before writing a section header
dc77569 test: add test for removing option before writing

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 53e840853f12318dcac68196fb74c1843cb75808

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 53e8408..4a6e5f2

4a6e5f2 refactor: full rework of the internal storage of the parsed config

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 4a6e5f23cb1f298f0a3efbf042186b16c91763c7

* refactor!: switching repos now offers list of repositories to choose from

this rework aligns more with the feature provided in kiauh v5.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-29 16:18:20 +01:00
dw-0
b99e6612e2 feat(ci): add automated release workflow for fast-forward and tagging
Adds a new GitHub Actions workflow that:
- Fast-forwards master branch from develop
- Creates and pushes a new release tag
- Requires manual trigger with tag name input

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-19 21:43:09 +01:00
dw-0
cf4e915430 cicd: restrict worflow runs to develop branch
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-13 18:26:23 +01:00
CODeRUS
c901cd1fdf feat(advanced): install input shaper dependencies (#662)
* feat(advanced): install input shaper dependencies

Signed-off-by: Andrey Kozhevnikov <coderusinbox@gmail.com>

* chore: fix formatting/wording

also add a quick check if the klipper env exists

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Andrey Kozhevnikov <coderusinbox@gmail.com>
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2025-03-13 18:26:23 +01:00
Aleksei Sviridkin
da3c37a872 feat(git_utils): Support for blolbless clone mode in git_cmd_clone (#640)
* feat(git_utils): enhance git_cmd_clone with depth and single-branch options

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* fix(git_utils): add a newline for better readability in git_cmd_clone

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* feat(git_utils): enhance git_cmd_clone with optional depth and single-branch parameters

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* feat(git_utils): update git_cmd_clone to support blolbless cloning option

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* revert formatting changes

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* fix another formatting changes

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* fix(git_utils): correct indentation for improved readability in get_local_tags function

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* fix(git_utils): rename blolbless parameter to blobless and update documentation for clarity

Signed-off-by: Aleksei Sviridkin <f@lex.la>

* refactor: enable the blobless clone feature for all regular clones

skip checkout step if brach is master or main

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Aleksei Sviridkin <f@lex.la>
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2025-03-13 18:26:23 +01:00
dw-0
8f436646cd cicd: add action for fast-forward check and merge (#660)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-09 12:45:46 +01:00
dw-0
760f131d1c fix(klipper): handle file access exception for dietpi version file (#658)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-09 08:32:14 +01:00
dw-0
41804f0eaa style: ruff format
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-09 08:32:14 +01:00
dw-0
d3c9bcc38c refactor(klipper): move setup functions into KlipperSetupService
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-09 08:32:14 +01:00
dw-0
7fc36f3e68 feat(moonraker): display moonraker ip address after install
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-03-08 11:41:29 +01:00
CODeRUS
a4942b9404 fix: Add pkg-config to klipper packages (#655)
Signed-off-by: Andrey Kozhevnikov <coderusinbox@gmail.com>
2025-03-08 11:41:29 +01:00
dw-0
9e0a8a0081 Release v5.1.3
Release v5.1.3
2025-02-23 12:42:44 +01:00
dw-0
6082528628 Merge pull request #648 from Arksine/dev-v5-moonraker-deps-fix
fix: add support for Moonraker's dependency requirement specifiers to V5
2025-02-23 12:32:17 +01:00
Eric Callahan
9e92e4a36a fix: parse moonraker deps with requirement specifiers
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2025-02-22 16:50:28 -05:00
dw-0
7e8f1f3d81 Release v6.0.0-alpha.16
Merge develop into master (Release v6.0.0-alpha.16)
2025-02-22 16:25:49 +01:00
dw-0
234cf2c751 chore(copyright): update year (#645)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-02-22 16:21:34 +01:00
dw-0
3bc98eed13 fix(moonraker): adapt to new moonraker system_dependency.json syntax (#644)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-02-22 16:19:00 +01:00
dw-0
777f5e45e7 master -> develop
master -> develop
2025-02-20 21:00:21 +01:00
Paul Fertser
acf0faf158 fix: add ULA to trusted_clients in moonraker.conf (#637)
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
2025-02-16 16:47:00 +01:00
dw-0
5c219ec544 master -> develop (#635) 2025-02-15 11:26:04 +01:00
dw-0
70055e891e Release v6.0.0-alpha.15 2025-02-15 11:17:54 +01:00
dw-0
e3a0a9dec0 Release v6.0.0-alpha.15
fixes #632
2025-02-15 11:15:45 +01:00
dw-0
1cf81377ee Release v6.0.0-alpha.14
fixes #632
2025-02-15 11:11:04 +01:00
dw-0
aa4ea99c5c fix(moonraker): use os-release file to get distro info (#633)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-02-15 11:09:32 +01:00
marbocub
20ffc82a04 feat: add .internal as a CORS domain in moonraker.conf (#631)
This adds .internal as a CORS domain in moonraker.conf, which is reserved by ICANN as a domain name for private top-level domains (TLDs).

Co-authored-by: dw-0 <th33xitus@gmail.com>
Co-authored-by: dw-0 <domwil1091+github@gmail.com>
2025-02-13 16:21:47 +01:00
dw-0
0becf9d574 Release v6.0.0-alpha.14
fixes #607
fixes #615
fixes #618
fixes #619
fixes #620
fixes #623
fixes #627
2025-02-09 21:15:42 +01:00
dw-0
ed1bfcdeb4 fix(moonraker): correctly install ubuntu 24.10 dependencies (#630)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-02-09 21:12:59 +01:00
dw-0
033916216c refactor: skip build firmware dependency screen if all are met (#629)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-02-09 17:04:46 +01:00
CODeRUS
d8f47c0960 feature: save and select kconfig (#621)
* feature: save and select kconfig

Signed-off-by: Andrey Kozhevnikov <coderusinbox@gmail.com>

* chore: clean up and sort imports

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: replace os.path with Pathlib

- use config paths as type Paths instead of strings.
- tweak some menu visuals.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Andrey Kozhevnikov <coderusinbox@gmail.com>
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2025-02-09 15:45:05 +01:00
Mathijs Groothuis
4978f22101 fix(typo): Successfull > Successful
Co-authored-by: dw-0 <th33xitus@gmail.com>
Co-authored-by: dw-0 <domwil1091+github@gmail.com>
2025-02-08 13:30:37 +01:00
Mathijs Groothuis
8330f90b56 Fix typo: tyoing > typing
Fix typo: tyoing > typing

Co-authored-by: dw-0 <th33xitus@gmail.com>
Co-authored-by: dw-0 <domwil1091+github@gmail.com>
2025-02-05 19:07:19 +01:00
dw-0
2a08e3eb15 refactor: omit port 80 for IP in success message after webclient installation (#618)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-01-18 17:38:40 +01:00
dw-0
a2a3e92b50 refactor: remove BASE_USER argument from crowsnest install command (#617)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-01-18 17:38:00 +01:00
dw-0
a58288e7e3 Release v6.0.0-alpha.13
Merge develop into master (Release v6.0.0-alpha.13)
2025-01-03 22:13:12 +01:00
dw-0
3852464ab7 fix: use raw strings for regex parameter in get_string_input (#612)
fixes #602

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-01-03 22:10:39 +01:00
dw-0
d9626adc98 Release v6.0.0-alpha.12
Merge develop into master (Release v6.0.0-alpha.12)
2024-11-28 19:38:23 +01:00
dw-0
4ae5a37ec6 fix: most recent tag not shown correctly in main menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-24 21:43:10 +01:00
dw-0
935f81aab6 fix: backup fails in case of dangling symlink
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-24 21:26:12 +01:00
dw-0
b02df9a1e0 Release v6.0.0-alpha.11
Merge develop into master (Release v6.0.0-alpha.11)
2024-11-24 15:55:04 +01:00
nlef
dbbc87f18e fix: use correct telegram bot config path (#600)
* fix telegram bot config path

* use _post)init_value

---------

Co-authored-by: dw-0 <th33xitus@gmail.com>
Co-authored-by: dw-0 <domwil1091+github@gmail.com>
2024-11-24 15:53:49 +01:00
dw-0
243ea6582a Release v6.0.0-alpha.10
Merge develop into master (Release v6.0.0-alpha.10)
2024-11-23 21:17:51 +01:00
dw-0
91cba3637e readme: update README.md
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-23 21:12:35 +01:00
dw-0
3fc190ff25 fix: actually raise exception on empty config value
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-10 21:15:08 +01:00
dw-0
6ff45aab41 refactor: implement basic input validation for repo switch feature
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-10 20:58:37 +01:00
dw-0
b9c9feef3c refactor: clone repo in repo switch routine only if there is already a repo present
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-10 20:14:47 +01:00
dw-0
d37d047aaa refactor: fallback to config settings for repos in settings menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-10 19:56:47 +01:00
dw-0
a3fb57aee3 refactor: return - if branch cannot be read
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-10 19:54:26 +01:00
dw-0
8aee23830a feat: implement completion message for webclient config remove process
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 22:31:43 +01:00
dw-0
dd14de9a41 fix: test if checks is empty
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 22:31:43 +01:00
dw-0
1ca1e8ff6f feat: rework completion message for webclient remove process
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 22:31:43 +01:00
dw-0
12127efa21 fix: remove extra newline
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 22:31:43 +01:00
dw-0
66a5cdf9b1 feat: implement completion message for webclient remove process
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 22:31:37 +01:00
dw-0
9b1aba207c feat: implement completion message for klipper remove process
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 22:30:54 +01:00
dw-0
e274e3c00d refactor: add defaults to Message and center property
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 10:57:47 +01:00
dw-0
dd99b0e1a6 refactor: make run_remove_routines return boolean
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-27 10:56:54 +01:00
dw-0
a616876ace feat: implement message service
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-26 20:41:34 +02:00
dw-0
4925021aa8 fix: ensure encoding
Use an alternative approach as in #587 as it introduces an unexpected behavior in printing output

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-26 18:14:56 +02:00
dw-0
e63d9d67ec refactor: overhaul color mechanics
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-26 18:14:56 +02:00
dw-0
106bf7675f fix: port reconfiguration menu displays wrong port
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-25 13:01:12 +02:00
dw-0
a63cf8c9d9 Release v6.0.0-alpha.9
Merge develop into master (Release v6.0.0-alpha.9)
2024-10-24 12:29:24 +02:00
dw-0
02ed3e7da0 feat: show actual current branch in settings menu (#588)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-24 12:26:18 +02:00
dw-0
4427ae94af fix: make sure all output is utf-8 encoded (#587)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-24 12:26:01 +02:00
dw-0
81b7b156b9 feat: implement port reconfiguration for webclients (#586)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-24 12:25:44 +02:00
dw-0
2df364512b fix: Path.rename() not working across devices (#584)
causes `[Errno 18] Invalid cross-device link` on tmpfs filesystems

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-24 12:25:22 +02:00
dw-0
dfa0036326 refactor: don't clear scrollback on clear
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-24 12:24:05 +02:00
dw-0
425d86a12f Release v6.0.0-alpha.8
Merge develop into master (Release v6.0.0-alpha.8)
2024-10-21 19:45:55 +02:00
dw-0
ff6162d799 refactor: do not silently configure Fluidd for port 81 (#582)
* refactor: use port 80 as default for fluidd

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: improve port selection logic, write last port selection for client to kiauh.cfg

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-21 19:30:03 +02:00
dw-0
674c174224 fix: correctly add Spoolman to moonraker.asvc (#581)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-20 18:11:30 +02:00
CODeRUS
a368331693 feat(flashing): Flash RP2040 in Boot Mode (#580)
* feat(flashing): Flash RP2040 in Boot Mode

* docs: add info about STM32 DFU and RP2040 boot modes
2024-10-18 18:56:21 +02:00
Pedro Lamas
406b64d1e5 refactor: add client name to Moonraker not found dialog (#574)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2024-10-14 17:18:10 +02:00
dw-0
1b5691f2f5 Release v6.0.0-alpha.7
Merge develop into master (v6.0.0-alpha.7)

fixes #561
fixes #564
fixes #565
2024-10-13 11:51:19 +02:00
dw-0
e7eae5a0d1 fix: correctly handle IPs in nginx config files when parsing ports (#568)
* chore: add jupyter files to .gitignore

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* fix: correctly handle IPs in nginx config files when parsing ports

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-13 11:21:18 +02:00
dw-0
dc561a562c fix: always return string tuple from get_repo_name() (#567)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-13 10:27:31 +02:00
dw-0
55cfe124b2 feat: add SimplyPrint extension (#566)
* refactor: correctly sort extensions in extension menu

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: use different name for printer_data backup dir

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: change return type to List for moonraker_exists function

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* feat: add SimplyPrint extension

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-13 09:35:15 +02:00
Christian Würthner
43d6598be6 fix: remove octoapp_store dir when uninstalling (#562)
Co-authored-by: dw-0 <th33xitus@gmail.com>
2024-10-05 12:35:14 +02:00
dw-0
dc026a7a2b Release v6.0.0-alpha.6
Merge develop into master (v6.0.0-alpha.6)

fixes #545
fixes #553
fixes #557
2024-10-05 08:29:40 +02:00
dw-0
ac54d04b40 fix: correctly find connected UART devices (#559)
fixes #557

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-05 08:21:39 +02:00
dw-0
c19364360c fix: correctly find connected USB DFU devices (#555)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-05 08:07:47 +02:00
dw-0
2e6c66e524 fix: allow moonraker-telegram-bot-env access to systems site-packages dir (#556)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-10-03 10:22:32 +02:00
Christian Würthner
cd8003add9 feat(extension): add OctoApp (#554)
* Add OctoApp to v6

* fix: set correct index to new extension

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2024-10-03 08:51:38 +02:00
Kenneth Jiang
1f75395063 fix: self.cfg_file is already a full path (#552)
Signed-off-by: Kenneth Jiang <kenneth.jiang@gmail.com>
2024-09-29 20:33:54 +02:00
Kenneth Jiang
6e1bffa975 fix: remove "obico" from the suffix_blacklist so that it can discover its own instances. (#551)
Signed-off-by: Kenneth Jiang <kenneth.jiang@gmail.com>
2024-09-29 16:41:20 +02:00
dw-0
a8a73249a5 Release v6.0.0-alpha.5
Merge develop into master (v6.0.0-alpha.5)
2024-09-26 20:55:22 +02:00
dw-0
4138c71920 fix: fix section adding and exception handling (#548)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-26 20:52:19 +02:00
dw-0
ec3f93eeda Release v6.0.0-alpha.4
Merge develop into master (v6.0.0-alpha.4)
2024-09-22 09:43:04 +02:00
dw-0
afeb2bf02e feat: implement update all feature (#541)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-22 09:38:15 +02:00
dw-0
4b17c68454 fix: trunc owner and repo name if they would overflow (#540)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-22 08:58:44 +02:00
dw-0
df414ce37e fix: run umask 022 at launch (#538)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-21 21:01:19 +02:00
dw-0
975629f097 refactor: rework client config conflict detection (#537)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-21 18:42:19 +02:00
dw-0
fd2910ba67 fix: remove klipper.env and moonraker.env during removal (#536)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-21 15:10:30 +02:00
dw-0
6b6607c5ab fix: update scp integration for more robust config handling (#535)
* chore: remove scp

* Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit abee21c

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: abee21c08658be4529028844304df60650c09afa

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from abee21c..aa0302b

aa0302b fix: fix missing newline chars in raw strings

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: aa0302b02b56b252ed88fd2db88ee878a5bb7b5b

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from aa0302b..ef52958

ef52958 refactor: conditionally add empty line when adding new section

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: ef529580f469ef020135cb03e250fcd4e0d70acf

* fix: update scp integration for more robust cfg modification

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-21 13:55:30 +02:00
CODeRUS
b604d93d0c fix: RP2040 firmware detection (#533)
Co-authored-by: dw-0 <th33xitus@gmail.com>
2024-09-21 12:10:20 +02:00
dw-0
7e87f8af32 refactor: implement Mobileraker and OctoEverywhere as community extensions (#532)
* refactor: move mobileraker to extensions

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: move octoeverywhere to extensions

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-20 12:05:29 +02:00
dw-0
29b5ab00cd fix: correctly point to printers config dir (#531)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-15 08:36:49 +02:00
dw-0
4cf523a758 Merge pull request #524 from dw-0/develop
Merge develop into master
2024-09-08 19:04:19 +02:00
dw-0
694a4c20c5 fix: typo in "origin" and "managed_services" (#520)
* fix: typo in "origin" and "managed_services" for klipperscreen update manager config

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* fix: typo in "origin" for moonraker telegram bot update manager config

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-08 18:58:07 +02:00
dw-0
a54514c400 fix: fix switching of repositories (#519)
* fix: fix repo switching

Extend the functionality of repo switching by creating a backup before the switch. Also implement a rollback mechanic in case of an error.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: fail when installing requirements fails

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

* refactor: display owner and repo in main menu on separate lines

long owner and repo names would case the menu to be too wide

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-05 20:31:38 +02:00
dw-0
1d06bf76f3 Merge pull request #511 from dw-0/develop
Merge develop into master
2024-09-01 19:02:48 +02:00
dw-0
e438081c35 fix: update SimpleConfigParser submodule (#510) 2024-09-01 18:51:25 +02:00
dw-0
9f50f6fdd7 fix: y and n are invalid selections in KlipperFlashOverviewMenu (#508)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-01 18:31:15 +02:00
dw-0
0ee0fa3325 feat: KIAUH v6 - full rewrite of KIAUH in Python (#428) 2024-08-31 19:16:52 +02:00
Henrik Fransson
8547942986 readme: fix broken OctoApp plugin link (#494) 2024-08-06 16:41:18 +02:00
dw-0
d33ac6b15a fix: parse moonraker dependencies from system-dependencies.json (#492)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-08-03 13:30:34 +02:00
dw-0
6cd9133a15 fix: detect RatOS 2.1+ as operating system and exit (#490)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-07-31 20:30:33 +02:00
Beans Baxter
a929c6983d refactor: don't check spoolman version if not installed (#487) 2024-06-28 23:07:20 +02:00
breakheart
bce92001a6 fix: use correct Spoolman directory name (#486) 2024-06-28 17:46:19 +02:00
Alessandro Maggi
7993b98ee1 fix: replace jq by grep to check Spoolman update (#482)
* fix: remove extra space in remove menu

* fix(spoolman): replace jq with grep
jq isn't included in some minimal installations
2024-06-26 07:04:09 +02:00
Alessandro Maggi
62296e112e feat: add Spoolman support (#477) 2024-06-25 20:10:14 +02:00
Justin Otherguy
a374ac8fac fix: add unzip to dependencies for Mainsail and Fluidd 2024-05-09 20:56:16 +02:00
Christian Würthner
f2691f33d3 feat: add OctoApp support (#454)
* Add OctoApp support

* Update scripts/octoapp.sh

Co-authored-by: dw-0 <domwil1091+github@gmail.com>

* Remove duplicate clone function

* Update Readme link

* Use "OctoApp for Klipper" in install menu

---------

Co-authored-by: dw-0 <domwil1091+github@gmail.com>
2024-03-31 17:15:47 +02:00
dw-0
d800d356ca fix(backups): backup config folder only if it exists
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-03-24 19:45:02 +01:00
dw-0
b6c6edb622 refactor(Mobileraker): update companion install script (#431) (#433) 2024-02-24 14:53:41 +01:00
dw-0
099d47df2f fix: revert "refactor(Mobileraker): update companion install script (#431)" (#432)
This reverts commit ba1cdb3739.
2024-01-29 17:17:09 +01:00
Patrick Schmidt
ba1cdb3739 refactor(Mobileraker): update companion install script (#431) 2024-01-29 17:09:30 +01:00
Anna
8e7d4db988 fix: OctoPrint logo in README.md (#424)
* Fix OctoPrint logo in Readme

Fixed the broken link to the OctoPrint logo in the Readme under the Sources section. Now uses the logo present in the octoprint docs directory.

* Update OctoPrint logo to "raw" cdn link

* Changed ?raw=true link to raw.githubusercontent.com

---------

Co-authored-by: dw-0 <th33xitus@gmail.com>
2024-01-23 22:47:37 +01:00
jneilliii
8f960495ba fix: OctoPrint logo in README.md (#423) 2024-01-22 17:57:37 +01:00
dw-0
095823bf28 chore(kiauh): update FUNDING.yml
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-01-01 20:02:29 +01:00
dw-0
397038e43e chore(kiauh): add .idea to .gitignore
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-01-01 19:55:47 +01:00
dw-0
061e222664 chore(kiauh): update copyright
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-01-01 19:54:13 +01:00
dw-0
3f5ff50d69 refactor(kiauh): use sudo true instead of sudo -v to prevent password prompts
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-01-01 19:51:56 +01:00
dw-0
5ebe941125 readme: don't recommend a specific architecture anymore
Fixes #403 

Both 32bit and 64bit images were reported to work fine. So we don't need a strict 32bit recommendation anymore which may confuses users, why they should pick 32bit over 64bit.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-12-17 12:18:04 +01:00
dw-0
f5eb9486cc refactor(kiauh): use sudo true instead of sudo -v to prevent password prompts
Fixes #395 

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-12-17 12:10:36 +01:00
Stefan Dej
7a9e752f9c fix: fix typo in example.printer.cfg (#412)
rename virtual_sd_card to virtual_sdcard

Signed-off-by: Stefan Dej <meteyou@gmail.com>
2023-12-12 08:21:51 +01:00
CODeRUS
30bc56b198 feat(advanced): add selection between flash/serialflash methods (#410) 2023-12-10 16:57:59 +01:00
dw-0
b2567995de feat(klipper): add virtual_sd_card_block to example printer.cfg (#411) 2023-12-10 15:12:28 +01:00
dw-0
6fcd7a3f08 refactor(klipper): improve disruptive package handling
fix #293

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-10-31 15:09:31 +01:00
dw-0
25dfbb83df fix(kiauh): display custom repo dialog again after user interaction
fix #394

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-10-28 20:48:57 +02:00
Sineos
899b204dc7 refactor: show full path of mcu (#391) 2023-10-15 10:08:41 +02:00
Kenneth Jiang
5cf4b018fc refactor: change wording now that moonraker-obico can link printer using auto-discovery (#389) 2023-10-12 20:26:30 +02:00
dw-0
ae9d1b98da feat(klipper): remove/disable brltty and ModemManager during installation (#387) 2023-10-01 18:30:01 +02:00
Kenneth Jiang
16d3388ff2 refactor: make the 'Obico for Klipper' name consistent (#385) 2023-09-29 20:20:21 +02:00
th33xitus
b88d0085ba fix(backups): fix broken config target folder name
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-09-04 21:17:10 +02:00
th33xitus
0b6613e464 fix(backups): fix broken moonraker database target folder name
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-09-04 21:02:22 +02:00
th33xitus
d99cda544a fix(backups): add backup before update function for KlipperScreen
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-08-30 19:48:55 +02:00
th33xitus
a50dce20de fix(backups): add backup function for OctoEverywhere
fix #380

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-08-30 19:48:53 +02:00
th33xitus
f45da66e9e fix(crowsnest): uninstaller exited KIAUH if crowsnest not installed
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-08-26 18:31:37 +02:00
th33xitus
2822499344 refactor(copyright): update copyright comment
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-08-26 18:11:00 +02:00
th33xitus
c777ba3e6b refactor(log-upload): update log upload functions and re-enable access
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-08-26 18:06:14 +02:00
th33xitus
9f410450d7 refactor(backups): update backup functions for config and moonraker database and enable backup-before-update again
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-08-23 23:22:23 +02:00
dw-0
0497d49066 Update README.md 2023-08-15 16:42:38 +02:00
dw-0
229da227b0 Update FUNDING.yml
use updated ko-fi username
2023-08-14 23:06:44 +02:00
th33xitus
65854c8da6 fix(updates): make update all function also update system again
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-07-22 23:24:29 +02:00
Kenneth Jiang
5985646633 refactor(obico): move dependency handling to obico's own install script (#361) 2023-07-10 17:44:05 +02:00
th33xitus
979c39dc02 refactor(mainsail/fluidd): allow reading of version from release_info.json
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-07-01 20:59:46 +02:00
th33xitus
197058bd00 changelog: update Changelog
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-06-17 21:19:49 +02:00
th33xitus
d3b5122ebb refactor(UI): move version and added changelog link to own row in main menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-06-17 21:11:23 +02:00
th33xitus
8ce4daf403 refactor(klipper): pre-select python3 for klipper install
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-06-17 19:51:41 +02:00
th33xitus
b0a65fe14e refactor(UI): remove warn message
more than half a year is gone, the warning should not be that important anymore

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-06-17 19:49:57 +02:00
Patrick Schmidt
98866caefa feat: add Mobileraker (#343)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2023-06-17 19:34:26 +02:00
phizev
345b7b66a3 refactor: use service specific directories in templates (#355) 2023-06-17 18:22:16 +02:00
cravl-dev
8eb2924832 refactor: update package lists only when stale (#346)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2023-06-17 18:08:24 +02:00
Kyriel Abad
5d7debd65e readme: fix typos in README.md (#352) 2023-06-10 23:00:23 +02:00
th33xitus
7df3dd489f fix(mainsail/fluidd): show correct version number in update menu
fixes #350

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-06-07 21:48:17 +02:00
marbocub
0cd058320f feat: allow to install Mainsail/Fluidd without Moonraker (#347)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2023-06-06 21:09:47 +02:00
th33xitus
bcbb185bd7 readme: update README.md
also fixes #327
2023-06-04 21:57:56 +02:00
CODeRUS
477f3ca72c feat: flash DFU device in HID mode (#337)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2023-06-04 21:23:32 +02:00
th33xitus
c19acb1694 fix(mainsail/fluidd): fall back to latest stable url if fetching tags fails (#348) 2023-06-04 19:12:53 +02:00
Jookia
8228943850 fix(klipper): if set, use custom branch to check for update (#332) 2023-04-16 08:56:18 +02:00
Stefan Dej
5b890fb0fb refactor(mainsail): update themes.csv url for mainsail themes (#329) 2023-04-13 17:59:14 +02:00
Piotr Banasik
7989cec8d4 fix(crowsnest): override installers BASE_USER to current user (#317) 2023-03-19 11:50:06 +01:00
th33xitus
858301aa9a fix: temporary disable backup_before_update
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-03-18 18:15:11 +01:00
Quinn Damerell
ae9e79c579 feat(octoeverywhere): add OE to the "update all" action (#311) 2023-03-11 23:52:46 +01:00
th33xitus
1215446a6c feat(octoeverywhere): implement update function (#310) 2023-03-11 20:25:17 +01:00
th33xitus
8526acf8b6 chore: update copyright notice
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-03-10 20:06:06 +01:00
th33xitus
cc27aaec7c readme: add prerequisites to readme (#309) 2023-03-08 20:07:00 +01:00
Quinn Damerell
1e9493461c feat: add OctoEverywhere for Klipper (#300)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2023-03-05 17:19:20 +01:00
th33xitus
31616ebad5 fix(crowsnest): silence grep error output in main menu
fixes #308

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-03-04 16:01:06 +01:00
Stephan Wendel
faf56ed1b1 refactor(crowsnest): improve performance in crowsnest.sh (#306) 2023-02-28 18:37:43 +01:00
th33xitus
d6837af2a2 refactor(klipper): implement blacklisted service names (#304) 2023-02-28 18:29:21 +01:00
Pedro Lamas
afe6f7499a feat(fluidd): use fluidd-config repo for downloading fluidd macros (#305) 2023-02-28 16:33:32 +01:00
Pedro Lamas
e3ed223b5c fix: always use system home directory (#303) 2023-02-28 15:30:42 +01:00
th33xitus
fd27db28d4 feat(mainsail): use mainsail-config repo for downloading mainsail macros (#301) 2023-02-26 16:29:01 +01:00
Michael Bravo
68a02ad3f5 fix(mainsail): set increased read timeout on API endpoint (#294) 2023-02-25 12:59:31 +01:00
CODeRUS
99b7672dc9 fix(telegram bot): Fix service restart (#296) 2023-02-14 19:40:11 +01:00
th33xitus
bb3ec79756 revert(mjpg-streamer): re-add uninstall option for mjpg-streamer
fix #291

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-02-05 08:57:15 +01:00
Kenneth Jiang
ce595abd60 refactor(obico): remove "-s" option from moonraker-obico/install.sh invocation (#292) 2023-02-05 08:50:06 +01:00
th33xitus
c79dc280e3 refactor(moonraker): update cors domains in moonraker.conf template
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-02-05 08:47:46 +01:00
Stephan Wendel
7aa186e8b9 feat: replace mjpg-streamer with crowsnest (#286)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2023-02-03 21:59:59 +01:00
th33xitus
8493269c6f refactor: hide currently still disabled functions from the menus
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2023-01-08 11:05:14 +01:00
th33xitus
150ef0142f refactor(mainsail/fluidd): move tag urls from globals to respective files
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-12-14 19:40:12 +01:00
th33xitus
f70faa52cc fix(klipper): update python dialog description
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-12-08 19:25:58 +01:00
CODeRUS
e796f74640 refactor(klipper): recommend Python3 for Klipper installation (#246) 2022-12-07 18:42:51 +01:00
Thomas Lété
2c9f5bed60 fix: pull mainsail.cfg from correct location (#272) 2022-12-07 17:34:01 +01:00
th33xitus
e9c23ca93e fix(klipper): use correct value for py_ver variable in update function
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-11-14 19:50:55 +01:00
th33xitus
67afa26ed7 refactor(klipper): full refactor of klipper install/remove part (#264) 2022-11-13 15:51:22 +01:00
th33xitus
54be7e4e21 refactor(obico): update obico installer (#254) 2022-10-31 16:06:45 +01:00
th33xitus
811c071b74 refactor(telegram-bot): update telegram-bot installer (#251) 2022-10-30 18:30:20 +01:00
th33xitus
6116fc92cf fix: allow for any amount of whitespaces after config section in update manager
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-10-30 18:27:13 +01:00
th33xitus
5524a40f04 refactor(klipperscreen): re-enable klipperscreen installer
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-10-25 15:24:25 +02:00
th33xitus
cb3661b8b5 refactor(prettygcode): re-enable pretty gcode installer
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-10-25 15:23:57 +02:00
th33xitus
2cec90b29c refactor(octoprint): update octoprint installer
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-10-24 10:35:30 +02:00
th33xitus
d2c009df9a fix(klipper): network.target is now network-online.target
Signed-off-by: Dominik Willner th33xitus@gmail.com
2022-10-22 23:28:01 +02:00
th33xitus
046178f801 refactor!: update KIAUH for recent moonraker changes (#245) 2022-10-20 11:20:34 +02:00
cobyn
442980dbd0 fix(flash_klipper): spelling mistake (#242) 2022-10-05 17:22:31 +02:00
th33xitus
798e56f4dc refactor(mainsail): replace deprecated remote mode with new instanceDB
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-09-18 23:45:02 +02:00
th33xitus
9d90daec7f fix(switch_klipper_repo): use of case didn't allow selections of 2 and above
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-09-10 20:25:05 +02:00
megapro17
f25726cfed fix: typo in mjpg-streamer dialog (#239) 2022-09-08 09:15:24 +02:00
th33xitus
f46b099b74 refactor(klipper): more verbose error message if SysVinit script is detected
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-09-03 14:14:37 +02:00
th33xitus
03be46f012 refactor(moonraker): skip polkit script execution if polkit rules already installed
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-09-03 13:41:02 +02:00
th33xitus
c11e628c55 fix(moonraker): do not exit if moonraker_polkit exits with an error during moonraker update
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-09-03 11:34:45 +02:00
th33xitus
4c8d43e365 refactor: use OS independent method to check/set for correct home folder permissions
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-08-27 22:08:01 +02:00
Kenneth Jiang
9d7144b493 feat: add Obico for Klipper to KIAUH (#227)
Co-authored-by: th33xitus <th33xitus@googlemail.com>
2022-08-15 19:44:04 +02:00
th33xitus
6df388f42b refactor: install webcamd from self provided resources
with the upcoming release of a new MainsailOS image, mjpg-streamer is replaced by crowsnest. it is therefore not possible anymore to pull the files from the mainsailOS repository. hence adding them to the KIAUH repository.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-29 19:46:39 +02:00
th33xitus
1d7fb010af refactor: remove unused kiauh_macros.cfg
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-24 08:51:48 +02:00
th33xitus
d4207d710c fix: restart moonraker after moonraker.conf patch (fixes #225)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-22 10:16:00 +02:00
th33xitus
6cb8d70b63 fix: replace generic nginx webui cfg by their respective ones
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-22 10:06:35 +02:00
th33xitus
ae011963da fix: install mainsail theme to correct folder (fixes #222)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-20 22:41:42 +02:00
th33xitus
491d6f40bb refactor: move ini initialization to main_menu()
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-20 22:34:07 +02:00
th33xitus
8bbe2f79ea feat: save multi instance klipper names/identifier to kiauh.ini
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2022-07-20 22:33:33 +02:00
th33xitus
0bdf61a714 fix: do not install py2 packages if venv is py3 (fixes #211)
Signed-off-by: Dominik Willner th33xitus@gmail.com
2022-06-30 20:41:36 +02:00
th33xitus
b07a83c8ad fix: update all function (#204) (#217)
* fix: update all function (fixes #204)
* fix: replace non-existing `print_unkown_cmd` function

Signed-off-by: Dominik Willner th33xitus@gmail.com
2022-06-30 11:08:09 +02:00
th33xitus
39e22acbed fix(octoprint.sh): script exiting without error message (fixes #216)
- the script was exiting without notifying the user that klipper has to be installed first

Signed-off-by: Dominik Willner th33xitus@gmail.com
2022-06-26 08:48:38 +02:00
th33xitus
8ba46fa4ac fix(pretty_gcode.sh): use main instead of master (fixes #203)
- pgc uses main instead of master. so checking for origin/master leads to an error

Signed-off-by: Dominik Willner th33xitus@gmail.com
2022-05-31 17:27:52 +02:00
th33xitus
d6b95c9d10 refactor(nginx.sh): refactor set_nginx_cfg()
- implements two dedicated nginx configs for mainsail and fluidd

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

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

refactor: creating $PKGLIST

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

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

script: first implementation of a little help page
2021-09-24 11:59:50 +02:00
th33xitus
9463b719e4 script: update klipper github repository URL 2021-09-24 08:31:11 +02:00
th33xitus
65bf3d5251 fix: fix of previous commit and small refactor 2021-09-12 20:46:39 +02:00
AKA "Thom Wiley
68327262fc chore: change submenu "quit" to "back"
Changing the "Quit" option to "Back" as it is more intuitive, causes less confusion and is in fact the more fitting description of what is happening.
2021-09-12 20:41:27 +02:00
th33xitus
14ef39b87c fix: typo and missing function call for PrettyGCode 2021-08-25 10:14:05 +02:00
th33xitus
969d3b5dab script: add --allow-releaseinfo-change option to apt-get update 2021-08-25 10:05:31 +02:00
th33xitus
05842f8e1d feat: add PrettyGCode for Klipper 2021-08-10 12:25:05 +02:00
th33xitus
39219c105e script: add additional dependency check - should fix #97
Before starting the firmware building process, check for dependencies again.
2021-07-25 18:42:22 +02:00
th33xitus
7984c28fe5 script: add more default trusted_clients to moonraker.conf template
the previous method of adding the host network range was too unreliable in some cases and didn't cover some popular usecases
2021-07-11 19:13:37 +02:00
th33xitus
b44e855a98 script: simplify python dependency installation during klipper and moonraker update 2021-07-11 14:45:58 +02:00
th33xitus
52ab909ba5 script: update moonraker.conf, apply recent changes to the update manager section 2021-07-10 09:27:13 +02:00
th33xitus
4d7e10e5c3 script: update nginx configurations 2021-07-10 09:22:43 +02:00
th33xitus
d3726733e5 fix: small flash routine rework + user input validation 2021-07-04 20:09:25 +02:00
th33xitus
765f016ea2 fix: menu action for removing mainsail theme was missing 2021-07-01 21:38:14 +02:00
th33xitus
5deb987b8a script: patch log_path to moonraker.conf if missing 2021-06-29 22:58:21 +02:00
th33xitus
47d1321979 script: mainsail theme installer overhaul 2021-06-22 17:12:38 +02:00
th33xitus
b47a9cf7ed feat: add voron toolhead theme to mainsail theme installer 2021-06-22 12:07:27 +02:00
th33xitus
a9f23e9b23 script: remove else statement from do_action_service
Caused spamming of error messages when starting from a complete new Pi image.
2021-06-21 20:43:01 +02:00
th33xitus
814acbe92a script: add virtualenv to the moonraker dependency check #95 2021-06-21 08:44:37 +02:00
th33xitus
991dd79d01 script: add simple check for DietPi distro when creating the klipper dependency array 2021-06-18 18:28:27 +02:00
th33xitus
40875dfe49 script: simplify service action methods 2021-06-18 18:03:47 +02:00
th33xitus
806c6fd275 Update changelog.md 2021-06-15 17:36:08 +02:00
th33xitus
e9706b52d8 Update changelog.md 2021-06-15 17:22:39 +02:00
th33xitus
412e084d6d script: add short changelog url to kiauh update message 2021-06-15 16:40:10 +02:00
th33xitus
3ebee823ad script: remove KlipperScreen.log symlink dialog. 2021-06-15 16:12:58 +02:00
th33xitus
72312422e3 fix: performance improvement for loading the advanced menu ui 2021-06-15 15:56:13 +02:00
th33xitus
54089582e4 script: rewrite the auto mainsailOS/fluiddPi migration function
No auto update anymore when updating Klipper. The user now must start this function. It's available in the Advanced Menu.
2021-06-15 15:56:13 +02:00
th33xitus
9fd3f930df script: advanced_menu.sh, switch version becomes switch branch 2021-06-15 15:56:13 +02:00
th33xitus
98f0aa4b8f script: update log-upload function 2021-06-15 15:56:13 +02:00
th33xitus
19b37e4dc4 script: update klipper.service raw file link 2021-06-15 15:56:13 +02:00
th33xitus
d344b1c5f6 feat: auto mainsailOS / fluiddPi migration
script: make use of moonrakers new log_path configuration option

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

f10247a498
2021-05-21 08:55:11 +02:00
th33xitus
44f5609de6 script: remove deprecated moonraker.conf entries 2021-04-20 21:53:13 +02:00
th33xitus
f2a26d9b3d fix: false positive error message during klipper setup
add fix some status.sh functions too
2021-04-15 13:03:36 +02:00
Evgenii Shavrin
bb2cdab02b script: better moonraker service detection (#79)
More accurate service search
2021-04-13 12:21:16 +02:00
th33xitus
d6596d0a3d script: change kiauh update notification to a dialog 2021-04-08 18:07:30 +02:00
th33xitus
865fbc07dc script: updating webui nginx config and moonraker.conf template 2021-04-05 08:59:19 +02:00
th33xitus
40ba33eb19 fix: fix a bug that potentially caused writing a wrong config directory path to the moonraker.service file under special conditions 2021-04-03 19:29:59 +02:00
th33xitus
49b77162b0 fix: typo 2021-03-31 10:06:11 +02:00
th33xitus
adf087e3e5 script: activate [history] in moonraker.conf template 2021-03-31 09:16:31 +02:00
th33xitus
8220647564 script: rework mjpg-streamer service setup 2021-03-28 17:00:25 +02:00
th33xitus
57075ff525 script: rework klipper service setup 2021-03-28 16:45:16 +02:00
th33xitus
2f9de620bc script: rework moonraker service setup 2021-03-28 15:51:50 +02:00
th33xitus
d658c3a4cd fix: update nginx config 2021-03-28 15:46:48 +02:00
th33xitus
67f6a2c599 fix: broken update menu 2021-03-27 00:04:25 +01:00
th33xitus
f369c132d2 fix #74 - remove leftovers 2021-03-26 21:48:12 +01:00
th33xitus
cce6ac3c88 feat: add system upgrade 2021-03-26 18:36:05 +01:00
th33xitus
b9fe29068d script: apt-get update before apt-get install in dependency_check() 2021-03-25 21:40:16 +01:00
th33xitus
104089ea3d feat: add mjpg-streamer installer 2021-03-25 21:35:24 +01:00
th33xitus
48d97dab01 feat: backup moonraker database 2021-03-24 11:19:50 +01:00
th33xitus
e4a56564a1 fix: command for removing .octoprint dirs while uninstalling OctoPrint 2021-03-24 11:04:43 +01:00
th33xitus
6de8ce3278 script: add database_path to moonraker.conf template 2021-03-22 22:04:27 +01:00
th33xitus
b46457328f feat: followup to 7c7dd4e 2021-03-22 13:34:52 +01:00
th33xitus
7c7dd4ec3c feat: add mainsail theme installer 2021-03-22 10:55:24 +01:00
th33xitus
749293dde0 fix: visual bug 2021-03-17 16:13:53 +01:00
th33xitus
85f8ab4f24 fix: typo 2021-03-17 16:11:56 +01:00
th33xitus
e894496a6e script: add [history] to moonraker.conf template 2021-03-14 21:30:03 +01:00
th33xitus
19b220b772 fix: #71 2021-03-14 21:15:02 +01:00
th33xitus
a4eaa8952a script: remove unnecessary cors domains from moonraker.conf template 2021-03-12 11:20:38 +01:00
th33xitus
74a9bf783b script: deactivate moonrakers debug logging in moonraker.conf template 2021-03-11 22:08:05 +01:00
th33xitus
7597e999a1 fix: add 'octoprint_compat' entry to moonraker.conf template to enable slicer uploads 2021-03-05 09:12:00 +01:00
th33xitus
64d73ca86a refactor: determine installed services, combine single and multi remove into one step 2021-02-19 11:09:46 +01:00
th33xitus
d3283f7ab7 fix: try to fix a bug where the script errors out, telling that there is already a moonraker service installed but actually there isn't 2021-02-19 11:05:43 +01:00
th33xitus
cb443f6fee fix: rework remove processes 2021-02-17 20:50:36 +01:00
th33xitus
7162256e3f fix: remove klipperscreen log from tmp and user defined config folder 2021-02-17 20:31:26 +01:00
th33xitus
938b9d24f5 feature: add sdcard updates 2021-02-06 14:56:57 +01:00
th33xitus
38a3517c89 fix: autocommit.sh example uses .version files for getting mainsail and fluidd version 2021-02-06 12:16:04 +01:00
th33xitus
0b15cd0d9b fix: delete doubled status_msg in gcode_shell_command extension setup 2021-02-06 12:16:04 +01:00
th33xitus
9d7752a6c5 fix: typo in example pause macro 2021-02-04 19:36:57 +01:00
th33xitus
d1dff4d3b5 fix: logic error in build+flash function 2021-02-01 20:48:05 +01:00
th33xitus
49b7fe395b fix: detect an existing "legacy" klipper init.d installation 2021-01-31 18:34:05 +01:00
th33xitus
51469d8992 Update screenshot for KIAUH v3.0 2021-01-31 16:28:43 +01:00
88 changed files with 10944 additions and 5375 deletions

15
.editorconfig Normal file
View File

@@ -0,0 +1,15 @@
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf
[*.py]
max_line_length = 88
[*.{sh,yml,yaml,json}]
indent_size = 2

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

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: dw__0
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: https://paypal.me/dwillner0

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

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

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

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

View File

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

View File

@@ -0,0 +1,33 @@
name: Release - Fast-Forward and Tag
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Provide a tag name (e.g. v1.0.0)'
required: true
type: string
jobs:
ff-and-tag:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 'master'
- name: Merge Fast Forward
uses: MaximeHeckel/github-action-merge-fast-forward@v1.1.0
with:
branchtomerge: origin/develop
branch: master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create and Push Tag
run: |
git tag ${{ inputs.tag_name }}
git push origin ${{ inputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

14
.gitignore vendored
View File

@@ -1 +1,13 @@
kiauh.ini .idea
.vscode
.pytest_cache
.jupyter
*.ipynb
*.ipynb_checkpoints
*.tmp
__pycache__
.kiauh-env
*.code-workspace
*.iml
kiauh.cfg
klipper_repos.txt

15
.shellcheckrc Normal file
View File

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

288
README.md
View File

@@ -1,146 +1,214 @@
# **KIAUH - Klipper Installation And Update Helper** <p align="center">
<a>
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/kiauh.png" alt="KIAUH logo" height="181">
<h1 align="center">Klipper Installation And Update Helper</h1>
</a>
</p>
![main_menu](resources/screenshots/main.png) <p align="center">
A handy installation script that makes installing Klipper (and more) a breeze!
</p>
--- <p align="center">
<a><img src="https://img.shields.io/github/license/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/stars/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/forks/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/languages/top/dw-0/kiauh?logo=gnubash&logoColor=white"></a>
<a><img src="https://img.shields.io/github/v/tag/dw-0/kiauh"></a>
<br />
<a><img src="https://img.shields.io/github/last-commit/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/contributors/dw-0/kiauh"></a>
</p>
## **📋 Please see the [Changelog](docs/changelog.md) for possible important information !** <hr>
--- <h2 align="center">
📄️ Instructions 📄
</h2>
## **📢 Disclaimer: Usage of this script happens at your own risk!** ### 📋 Prerequisites
KIAUH is a script that assists you in installing Klipper on a Linux operating system that has
already been flashed to your Raspberry Pi's (or other SBC's) SD card. As a result, you must ensure
that you have a functional Linux system on hand. `Raspberry Pi OS Lite (either 32bit or 64bit)` is a recommended Linux image
if you are using a Raspberry Pi. The [official Raspberry Pi Imager](https://www.raspberrypi.com/software/)
is the simplest way to flash an image like this to an SD card.
This script acts as a helping hand for you to get set up in a fast and comfortable way.\ * Once you have downloaded, installed and launched the Raspberry Pi Imager,
**This does not mean, it will relieve you of using your brain.exe! 🧠**\ select `Choose OS -> Raspberry Pi OS (other)`: \
Please also always pay attention to the individual component repositories (all linked below).\ <p align="center">
Feel free to give it a try. If you have suggestions or encounter any problems, please report them. <img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager1.png" alt="KIAUH logo" height="350">
</p>
--- * Then select `Raspberry Pi OS Lite (32bit)` (or 64bit if you want to use that instead):
<p align="center">
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager2.png" alt="KIAUH logo" height="350">
</p>
## **🛠️ Instructions:** * Back in the Raspberry Pi Imager's main menu, select the corresponding SD card to which
you want to flash the image.
For downloading this script it is necessary to have git installed.\ * Make sure to go into the Advanced Option (the cog icon in the lower left corner of the main menu)
If you haven't, please run `sudo apt-get install git -y` to install git first.\ and enable SSH and configure Wi-Fi.
You will need it anyways! 😄
After git is installed, use the following commands in the given order to download and execute the script: * If you need more help for using the Raspberry Pi Imager, please visit the [official documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html).
These steps **only** apply if you are actually using a Raspberry Pi. In case you want
to use a different SBC (like an Orange Pi or any other Pi derivates), please look up on how to get an appropriate Linux image flashed
to the SD card before proceeding further (usually done with Balena Etcher in those cases). Also make sure that KIAUH will be able to run
and operate on the Linux Distribution you are going to flash. You likely will have the most success with
distributions based on Debian 11 Bullseye. Read the notes further down below in this document.
### 💾 Download and use KIAUH
**📢 Disclaimer: Usage of this script happens at your own risk!**
* **Step 1:** \
To download this script, it is necessary to have git installed. If you don't have git already installed, or if you are unsure, run the following command:
```shell
sudo apt-get update && sudo apt-get install git -y
```
* **Step 2:** \
Once git is installed, use the following command to download KIAUH into your home-directory:
```shell
cd ~ && git clone https://github.com/dw-0/kiauh.git
```
* **Step 3:** \
Finally, start KIAUH by running the next command:
```shell ```shell
cd ~
git clone https://github.com/th33xitus/kiauh.git
./kiauh/kiauh.sh ./kiauh/kiauh.sh
``` ```
## Additional Instructions: * **Step 4:** \
You should now find yourself in the main menu of KIAUH. You will see several actions to choose from depending
on what you want to do. To choose an action, simply type the corresponding number into the "Perform action"
prompt and confirm by hitting ENTER.
If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website:\ <hr>
[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.
--- <h2 align="center">❗ Notes ❗</h2>
## **🧰 Functions and Features:** ### **📋 Please see the [Changelog](docs/changelog.md) for possible important changes!**
- **New in v3.0** You can now install multiple instances (Klipper/Moonraker/DWC/Octoprint) on the same Pi! - Mainly tested on Raspberry Pi OS Lite (Debian 10 Buster / Debian 11 Bullseye)
--- - Other Debian based distributions (like Ubuntu 20 to 22) likely work too
### **Core Functions:** - Reported to work on Armbian as well but not tested in detail
- During the use of this script you will be asked for your sudo password. There are several functions involved which need sudo privileges.
- **Installing** Klipper to your Raspberry Pi or other Debian based Linux Distribution. <hr>
- **Installing** of the Moonraker API (needed for Mainsail, Fluidd and KlipperScreen)
- **Installing** several different web interfaces such as Mainsail, Fluidd, Duet Web Control or OctoPrint including their dependencies.
- **Installing** of KlipperScreen (OctoScreen but for Klipper!)
- **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface!
- **Removing** of all the listed installations above.
- **Backup** of all the listed installations above.
### **Also possible:** <h2 align="center">🌐 Sources & Further Information</h2>
- Build the Klipper Firmware <table align="center">
- Flash the MCU <tr>
- Read ID of the currently connected MCU <th><h3><a href="https://github.com/Klipper3d/klipper">Klipper</a></h3></th>
- and more ... <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>
</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>
</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>
</tr>
### **For a list of additional features please see: [Feature List](docs/features.md)** <tr>
<th><h3><a href="https://github.com/fluidd-core/fluidd">Fluidd</a></h3></th>
<th><h3><a href="https://github.com/jordanruthe/KlipperScreen">KlipperScreen</a></h3></th>
<th><h3><a href="https://github.com/OctoPrint/OctoPrint">OctoPrint</a></h3></th>
</tr>
<tr>
<th><img src="https://raw.githubusercontent.com/fluidd-core/fluidd/master/docs/assets/images/logo.svg" alt="Fluidd Logo" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/31575189?v=4" alt="jordanruthe avatar" height="64"></th>
<th><img src="https://raw.githubusercontent.com/OctoPrint/OctoPrint/master/docs/images/octoprint-logo.png" alt="OctoPrint Logo" height="64"></th>
</tr>
<tr>
<th>by <a href="https://github.com/fluidd-core">fluidd-core</a></th>
<th>by <a href="https://github.com/jordanruthe">jordanruthe</a></th>
<th>by <a href="https://github.com/OctoPrint">OctoPrint</a></th>
</tr>
--- <tr>
<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/TheSpaghettiDetective/moonraker-obico">Obico for Klipper</a></h3></th>
</tr>
<tr>
<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://avatars.githubusercontent.com/u/46323662?s=200&v=4" alt="Obico logo" height="64"></th>
</tr>
<tr>
<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/TheSpaghettiDetective">Obico</a></th>
</tr>
## **📝 Notes:** <tr>
<th><h3><a href="https://github.com/Clon1998/mobileraker_companion">Mobileraker's Companion</a></h3></th>
<th><h3><a href="https://octoeverywhere.com/?source=kiauh_readme">OctoEverywhere For Klipper</a></h3></th>
<th><h3><a href="https://github.com/crysxd/OctoApp-Plugin">OctoApp For Klipper</a></h3></th>
</tr>
<tr>
<th><a href="https://github.com/Clon1998/mobileraker_companion"><img src="https://raw.githubusercontent.com/Clon1998/mobileraker/master/assets/icon/mr_appicon.png" alt="Mobileraker Logo" height="64"></a></th>
<th><a href="https://octoeverywhere.com/?source=kiauh_readme"><img src="https://octoeverywhere.com/img/logo.svg" alt="OctoEverywhere Logo" height="64"></a></th>
<th><a href="https://octoapp.eu/?source=kiauh_readme"><img src="https://octoapp.eu/octoapp.webp" alt="OctoApp Logo" height="64"></a></th>
</tr>
<tr>
<th>by <a href="https://github.com/Clon1998">Patrick Schmidt</a></th>
<th>by <a href="https://github.com/QuinnDamerell">Quinn Damerell</a></th>
<th>by <a href="https://github.com/crysxd">Christian Würthner</a></th>
</tr>
- Tested **only** on Raspberry Pi OS Lite (Debian Buster) <tr>
- ( Although similar Debian based distributions might also work... ) <th><h3><a href="https://github.com/staubgeborener/klipper-backup">Klipper-Backup</a></h3></th>
- During the use of this script you might be asked for your sudo password. There are several functions involved which need sudo privileges. <th><h3><a href="https://simplyprint.io/">SimplyPrint for Klipper</a></h3></th>
</tr>
<tr>
<th><a href="https://github.com/staubgeborener/klipper-backup"><img src="https://avatars.githubusercontent.com/u/28908603?v=4" alt="Staubgeroner Avatar" height="64"></a></th>
<th><a href="https://github.com/SimplyPrint"><img src="https://avatars.githubusercontent.com/u/64896552?s=200&v=4" alt="" height="64"></a></th>
</tr>
<tr>
<th>by <a href="https://github.com/Staubgeborener">Staubgeborener</a></th>
<th>by <a href="https://github.com/SimplyPrint">SimplyPrint</a></th>
</tr>
</table>
--- <hr>
## **🛈 Sources & Further Information** <h2 align="center">🎖️ Contributors 🎖️</h2>
If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website:\ <div align="center">
[Installing Klipper and Mainsail](https://3dp.tumbleweedlabs.com/firmware/klipper-firmware/installing-klipper-and-mainsail-on-your-raspberry-pi)\ <a href="https://github.com/dw-0/kiauh/graphs/contributors">
Credits for these instructions go to [@tumbleweedlabs](https://github.com/tumbleweedlabs). <img src="https://contrib.rocks/image?repo=dw-0/kiauh" alt=""/>
</a>
</div>
For more information or instructions to the various components KIAUH can install, please check out the corresponding repositories listed below: <hr>
--- <div align="center">
<img src="https://repobeats.axiom.co/api/embed/a1afbda9190c04a90cf4bd3061e5573bc836cb05.svg" alt="Repobeats analytics image"/>
</div>
### **⛵Klipper** by [KevinOConnor](https://github.com/KevinOConnor) : <hr>
https://github.com/KevinOConnor/klipper <h2 align="center">✨ Credits ✨</h2>
--- * 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/dw__0) !
* Last but not least: Thank you to all contributors and members of the Klipper Community who like and share this project!
### **⛵Klipper S-Curve fork** by [dmbutyugin](https://github.com/dmbutyugin) : <hr>
https://github.com/dmbutyugin/klipper/tree/scurve-smoothing \ <h4 align="center">A special thank you to JetBrains for sponsoring this project with their incredible software!</h4>
https://github.com/dmbutyugin/klipper/tree/scurve-shaping <p align="center">
<a href="https://www.jetbrains.com/community/opensource/#support" target="_blank">
--- <img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main) logo." height="128">
</a>
### **🌙Moonraker** by [Arksine](https://github.com/Arksine) : </p>
https://github.com/Arksine/moonraker
---
### **💨Mainsail Webinterface** by [meteyou](https://github.com/meteyou) :
https://github.com/meteyou/mainsail
---
### **🌊Fluidd Webinterface** by [cadriel](https://github.com/cadriel) :
https://github.com/cadriel/fluidd
---
### **🕸Duet Web Control** by [Duet3D](https://github.com/Duet3D) :
https://github.com/Duet3D/DuetWebControl
---
### **🕸DWC2-for-Klipper-Socket** by [Stephan3](https://github.com/Stephan3) :
https://github.com/Stephan3/dwc2-for-klipper-socket
---
### **🖥KlipperScreen** by [jordanruthe](https://github.com/jordanruthe) :
https://github.com/jordanruthe/KlipperScreen
---
### **🐙OctoPrint Webinterface** by [OctoPrint](https://github.com/OctoPrint) :
https://octoprint.org \
https://github.com/OctoPrint/OctoPrint
---
## **❓ FAQ**
**_Q: Can i use this script to install multiple instances of Klipper on the same Pi? (Multisession?)_**
**A:** Yes, it is finally possible 🙂

206
README_zh.md Normal file
View File

@@ -0,0 +1,206 @@
# KIAUH - Klipper 安装与更新助手
<p align="center">
<a>
<img src="https://raw.githubusercontent.com/dw-0/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">
一个方便的安装脚本让安装Klipper以及更多组件变得轻松
</p>
<p align="center">
<a><img src="https://img.shields.io/github/license/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/stars/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/forks/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/languages/top/dw-0/kiauh?logo=gnubash&logoColor=white"></a>
<a><img src="https://img.shields.io/github/v/tag/dw-0/kiauh"></a>
<br />
<a><img src="https://img.shields.io/github/last-commit/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/contributors/dw-0/kiauh"></a>
</p>
## 📄 使用说明
### 📋 系统要求
KIAUH 是一个帮助您在 Linux 系统上安装 Klipper 的脚本工具,
它需要一个已经写入树莓派或其他单板计算机SD 卡的 Linux 系统。
如果您使用树莓派,推荐使用 `Raspberry Pi OS Lite (32位或64位)` 系统镜像。
[官方 Raspberry Pi Imager](https://www.raspberrypi.com/software/) 是将此类镜像写入 SD 卡的最简单方式。
* 下载、安装并启动 Raspberry Pi Imager 后,
选择 `Choose OS -> Raspberry Pi OS (other)`:
<p align="center">
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager1.png" alt="KIAUH logo" height="350">
</p>
* 然后选择 `Raspberry Pi OS Lite (32位)` (或如果您想使用64位版本):
<p align="center">
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager2.png" alt="KIAUH logo" height="350">
</p>
* 返回 Raspberry Pi Imager 主界面,选择对应的 SD 卡作为写入目标。
* 确保点击左下角的齿轮图标(在主菜单中)
启用 SSH 并配置 Wi-Fi。
* 如果您需要更多关于使用 Raspberry Pi Imager 的帮助,请访问 [官方文档](https://www.raspberrypi.com/documentation/computers/getting-started.html)。
这些步骤**仅适用于**您实际使用树莓派的情况。如果您想使用其他单板计算机(如香橙派或其他 Pi 衍生产品),
请查找如何将合适的 Linux 镜像写入 SD 卡(通常使用 Balena Etcher
同时确保 KIAUH 能够在您要安装的 Linux 发行版上运行。
您在使用基于 Debian 11 Bullseye 的系统时可能会获得最佳体验。
请阅读本文档下方的注意事项。
### 💾 下载并使用 KIAUH
**📢 免责声明:使用此脚本的风险由您自行承担!**
* **第一步:**
要下载此脚本,需要先安装 git。
如果您不确定是否已安装 git请运行以下命令
```shell
sudo apt-get update && sudo apt-get install git -y
```
* **第二步:**
安装完 git 后,
使用以下命令将 KIAUH 下载到您的主目录:
```shell
cd ~ && git clone https://github.com/dw-0/kiauh.git
```
* **第三步:**
最后,通过运行以下命令启动 KIAUH
```shell
./kiauh/kiauh.sh
```
* **第四步:**
您现在应该会看到 KIAUH 的主菜单。
根据您的选择,
您会看到几个可选操作。
要选择某个操作,只需在 "Perform action" 提示后输入对应的数字并按回车键确认。
## ❗ 注意事项
### **📋 请查看 [更新日志](docs/changelog.md) 以了解可能的重要更新!**
- 主要在 Raspberry Pi OS Lite (Debian 10 Buster / Debian 11 Bullseye) 上测试
- 其他基于 Debian 的发行版(如 Ubuntu 20 到 22也可能正常工作
- 据报告在 Armbian 上也可用,但未进行详细测试
- 在使用此脚本的过程中,
您会被要求输入 sudo 密码。
因为有几个功能需要 sudo 权限。
## 🌐 相关资源与更多信息
<table align="center">
<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>
</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>
</tr>
<tr>
<th>由 <a href="https://github.com/KevinOConnor">KevinOConnor</a></th>
<th>由 <a href="https://github.com/Arksine">Arksine</a></th>
<th>由 <a href="https://github.com/mainsail-crew">mainsail-crew</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/fluidd-core/fluidd">Fluidd</a></h3></th>
<th><h3><a href="https://github.com/jordanruthe/KlipperScreen">KlipperScreen</a></h3></th>
<th><h3><a href="https://github.com/OctoPrint/OctoPrint">OctoPrint</a></h3></th>
</tr>
<tr>
<th><img src="https://raw.githubusercontent.com/fluidd-core/fluidd/master/docs/assets/images/logo.svg" alt="Fluidd Logo" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/31575189?v=4" alt="jordanruthe avatar" height="64"></th>
<th><img src="https://raw.githubusercontent.com/OctoPrint/OctoPrint/master/docs/images/octoprint-logo.png" alt="OctoPrint Logo" height="64"></th>
</tr>
<tr>
<th>由 <a href="https://github.com/fluidd-core">fluidd-core</a></th>
<th>由 <a href="https://github.com/jordanruthe">jordanruthe</a></th>
<th>由 <a href="https://github.com/OctoPrint">OctoPrint</a></th>
</tr>
<tr>
<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/TheSpaghettiDetective/moonraker-obico">Obico for Klipper</a></h3></th>
</tr>
<tr>
<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://avatars.githubusercontent.com/u/46323662?s=200&v=4" alt="Obico logo" height="64"></th>
</tr>
<tr>
<th>由 <a href="https://github.com/nlef">nlef</a></th>
<th>由 <a href="https://github.com/Kragrathea">Kragrathea</a></th>
<th>由 <a href="https://github.com/TheSpaghettiDetective">Obico</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/Clon1998/mobileraker_companion">Mobileraker's Companion</a></h3></th>
<th><h3><a href="https://octoeverywhere.com/?source=kiauh_readme">OctoEverywhere For Klipper</a></h3></th>
<th><h3><a href="https://github.com/crysxd/OctoApp-Plugin">OctoApp For Klipper</a></h3></th>
</tr>
<tr>
<th><a href="https://github.com/Clon1998/mobileraker_companion"><img src="https://raw.githubusercontent.com/Clon1998/mobileraker/master/assets/icon/mr_appicon.png" alt="Mobileraker Logo" height="64"></a></th>
<th><a href="https://octoeverywhere.com/?source=kiauh_readme"><img src="https://octoeverywhere.com/img/logo.svg" alt="OctoEverywhere Logo" height="64"></a></th>
<th><a href="https://octoapp.eu/?source=kiauh_readme"><img src="https://octoapp.eu/octoapp.webp" alt="OctoApp Logo" height="64"></a></th>
</tr>
<tr>
<th>由 <a href="https://github.com/Clon1998">Patrick Schmidt</a></th>
<th>由 <a href="https://github.com/QuinnDamerell">Quinn Damerell</a></th>
<th>由 <a href="https://github.com/crysxd">Christian Würthner</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/staubgeborener/klipper-backup">Klipper-Backup</a></h3></th>
<th><h3><a href="https://simplyprint.io/">SimplyPrint for Klipper</a></h3></th>
</tr>
<tr>
<th><a href="https://github.com/staubgeborener/klipper-backup"><img src="https://avatars.githubusercontent.com/u/28908603?v=4" alt="Staubgeroner Avatar" height="64"></a></th>
<th><a href="https://github.com/SimplyPrint"><img src="https://avatars.githubusercontent.com/u/64896552?s=200&v=4" alt="" height="64"></a></th>
</tr>
<tr>
<th>由 <a href="https://github.com/Staubgeborener">Staubgeborener</a></th>
<th>由 <a href="https://github.com/SimplyPrint">SimplyPrint</a></th>
</tr>
</table>
## 🎖️ 贡献者
<div align="center">
<a href="https://github.com/dw-0/kiauh/graphs/contributors">
<img src="https://contrib.rocks/image?repo=dw-0/kiauh" alt=""/>
</a>
</div>
<div align="center">
<img src="https://repobeats.axiom.co/api/embed/a1afbda9190c04a90cf4bd3061e5573bc836cb05.svg" alt="Repobeats analytics image"/>
</div>
## ✨ 特别感谢
* 非常感谢 [lixxbox](https://github.com/lixxbox) 设计了如此出色的 KIAUH 标志!
* 同时,非常感谢所有通过 [Ko-fi](https://ko-fi.com/dw__0) 支持我的工作的人!
* 最后但同样重要的是:感谢所有为 Klipper 社区做出贡献的成员,以及喜欢和分享这个项目的朋友们!
<h4 align="center">特别感谢 JetBrains 为本项目提供其出色的软件赞助!</h4>
<p align="center">
<a href="https://www.jetbrains.com/community/opensource/#support" target="_blank">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main) logo." height="128">
</a>
</p>

View File

@@ -2,6 +2,214 @@
This document covers possible important changes to KIAUH. This document covers possible important changes to KIAUH.
### 2024-08-31 (v6.0.0-alpha.1)
Long time no see, but here we are again!
A lot has happened in the background, but now it is time to take it out into the wild.
#### KIAUH has now reached version 6! Well, at least in an alpha state...
The project has seen a complete rewrite of the script from scratch in Python.
It requires Python 3.8 or newer to run. Because this update is still in an alpha state, bugs may or will occur.
During startup, you will be asked if you want to start the new version 6 or the old version 5.
As long as version 6 is in a pre-release state, version 5 will still be available. If there are any critical issues
with the new version that were overlooked, you can always switch back to the old version.
In case you selected not to get asked about which version to start (option 3 or 4 in the startup dialog) and you want to
revert that decision, you will find a line called `version_to_launch=` within the `.kiauh.ini` file in your home directory.
Just delete that line, save the file and restart KIAUH. KIAUH will then ask you again which version you want to start.
Here is a list of the most important changes to KIAUH in regard to version 6:
- The majority of features available in KIAUH v5 are still available; they just got migrated from Bash to Python.
- It is now possible to add new/remove instances to/from existing multi-instance installations of Klipper and Moonraker
- KIAUH now has an Extension-System. This allows contributors to add new installers to KIAUH without having to modify the main script.
- You will now find some of the features that were previously available in the Installer-Menu in the Extensions-Menu.
- The current extensions are:
- G-Code Shell Command (previously found in the Advanced-Menu)
- Mainsail Theme Installer (previously found in the Advanced-Menu)
- Klipper-Backup (new in v6!)
- Moonraker Telegram Bot (previously found in the Installer-Menu)
- PrettyGCode for Klipper (previously found in the Installer-Menu)
- Obico for Klipper (previously found in the Installer-Menu)
- The following additional extensions are planned, but not yet available:
- Spoolman (available in v5 in the Installer-Menu)
- OctoApp (available in v5 in the Installer-Menu)
- KIAUH has its own config file now
- The file has some default values for the currently supported options
- There might be more options in the future
- It is located in KIAUH's root directory and is called `default.kiauh.cfg`
- DO NOT EDIT the default file directly, instead make a copy of it and call it `kiauh.cfg`
- Settings changed via the Advanced-Menu will be written to the `kiauh.cfg`
- Support for OctoPrint was removed
Feel free to give version 6 a try and report any bugs or issues you encounter! Every feedback is appreciated.
### 2023-06-17
KIAUH has now added support for installing Mobileraker's companion!
Mobileraker is a free and Open Source Android and iOS App for Klipper, utilizing the Moonraker API, allowing you
to control your printer. Thank you to [Clon1998](https://github.com/Clon1998) for adding this feature!
### 2023-02-03
The installer for MJPG-Streamer got replaced by crowsnest. It is an improved webcam service, utilizing ustreamer.
Please have a look here for additional info about crowsnest and how to configure it: https://github.com/mainsail-crew/crowsnest \
It's unsure if the previous MJPG-Streamer installer will be updated and make its way back into KIAUH.
A big thanks to [KwadFan](https://github.com/KwadFan) for writing the crowsnest implementation.
### 2022-10-31
Some functions got updated, though not all of them.
The following functions are still currently unavailable:
- Installation of: MJPG-Streamer
- All backup functions and the Log-Upload
### 2022-10-20
KIAUH has now reached major version 5 !
Recently Moonraker introduced some changes which makes it necessary to change the folder structure of printer setups.
If you are interested in the details, check out this PR: https://github.com/Arksine/moonraker/pull/491 \
Although Moonraker has some mechanics available to migrate existing setups to the new file structure with the use of symlinks, fresh and clean installs
should be considered.
The version jump of KIAUH to v5 is a breaking change due to those major changes! That means v4 and v5 are not compatible with each other!
This is also the reason why you will currently be greeted by a yellow notification in the main menu of KIAUH leading to this changelog.
I decided to disable a few functions of the script and focus on releasing the required changes to the core components of this script.
I will work on updating the other parts of the script piece by piece during the next days/weeks.
So I am already sorry in advance if one of your desired components you wanted to install or use temporarily cannot be installed or used right now.
The following functions are currently unavailable:
- Installation of: KlipperScreen, Obico, Octoprint, MJPG-Streamer, Telegram Bot and PrettyGCode
- All backup functions and the Log-Upload
**So what is working?**\
Installation of Klipper, Moonraker, Mainsail and Fluidd. Both, single and multi-instance setups work!\
As already said, the rest will follow in the near future. Updating and removal of already installed components should continue to work.
**What was removed?**\
The option to change Klippers configuration directory got removed. From now on it will not be possible anymore to change
the configuration directory from within KIAUH and the new filestructure is enforced.
**What if I don't have an existing Klipper/Moonraker install right now?**\
Nothing important to think about, install Klipper and Moonraker. KIAUH will install both of them with the new filestructure.
**What if I have an existing Klipper/Moonraker install?**\
First of all: Backups! Please copy all of your config files and the Moonraker database (it is a hidden folder, usually `~/.moonraker_database`) to a safe location.
After that, uninstall Klipper and Moonraker with KIAUH. You can then proceed and re-install both of them with KIAUH again. It is important that you are on KIAUH v5 for that!
Once everything is installed again, you need to manually copy your configuration files from the old `~/klipper_config` folder to the new `~/printer_data/config` folder.
Previous, by Moonraker created symlinks to folder of the old filestructure will not work anymore, you need to move the files to their new location now!
Do the same with the two files inside of `~/.moonraker_database`. Move/copy them into `~/printer_data/database`. If `~/printer_data/database` is already populated with a `data.mdb` and `lock.mdb`
delete them or simply overwrite them. Nothing should be lost as those should be empty database files. Anyway, you made backups, right?
You can now proceed and restart Moonraker. Either from within Mainsail or Fluidd, or use SSH and execute `sudo systemctl restart moonraker`.
If everything went smooth, you should be good to go again. If you see some Moonraker warnings about deprecated options in the `moonraker.conf`, go ahead and resolve them.
I will not cover them in detail here. A good source is the Moonraker documentation: https://moonraker.readthedocs.io/en/latest/configuration/
**What if I have an existing Klipper/Moonraker multi-instance install?**\
Pretty much the same steps that are required for single instance installs apply to multi-instance setups. So please go ahead and read the previous paragraph if you didn't already.
Make backups of everything first. Then remove and install the desired amount of Klipper and Moonraker instances again.
Now you need to move all config and database files to their new locations.\
Example with an instance called `printer_1`:\
The config files go from `~/klipper_config/printer_1` to `~/printer_1_data/config`.
The database files go from `~/.moonraker_database_1` to `~/printer_1_data/database`.
Now restart all Moonraker services. You can restart all of them at once if you launch KIAUH, and in the main menu type `restart moonraker` and hit Enter.
I hope I have covered the most important things. In case you need further support, the official Klipper Discord is a good place to ask for help.
### 2022-08-15
Support for "Obico for Klipper" was added! Huge thanks to [kennethjiang](https://github.com/kennethjiang) for helping me with the implementation!
### 2022-05-29
KIAUH has now reached major version 4 !
* feat: Klipper can be installed under Python3 (still 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 allow installation of / updating to unstable Mainsail and Fluidd versions
* by default only stable versions get installed/updated
* 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.)
* feat: added several new help dialogs which try to explain various functions
* fix: During Klipper installation, checks for group membership of `tty` and `dialout` are made
* refactor: rework of the settings menu for better control the new KIAUH features
* 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 ### 2021-01-31
* **This is a big one... KIAUH v3.0 is out.**\ * **This is a big one... KIAUH v3.0 is out.**\
@@ -46,9 +254,9 @@ Each service gets its corresponding instance added to the service filename.
--> moonraker-2.service --> moonraker-2.service
--> moonraker-n.service --> moonraker-n.service
``` ```
* The same service file rules from above apply to DWC and OctoPrint even though only Klipper and Moonraker are shown in this example. * 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, DWC and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on. * 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. * 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.

View File

@@ -1,28 +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
- **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...

View File

@@ -40,6 +40,34 @@ verbose: True
Execute with: Execute with:
`RUN_SHELL_COMMAND CMD=hello_world` `RUN_SHELL_COMMAND CMD=hello_world`
### Passing parameters:
As of commit [f231fa9](https://github.com/dw-0/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 ## 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. 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.

142
kiauh.sh
View File

@@ -1,101 +1,71 @@
#!/bin/bash #!/usr/bin/env bash
clear
set -e
### set color variables #=======================================================================#
green=$(echo -en "\e[92m") # Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
yellow=$(echo -en "\e[93m") # #
red=$(echo -en "\e[91m") # This file is part of KIAUH - Klipper Installation And Update Helper #
cyan=$(echo -en "\e[96m") # https://github.com/dw-0/kiauh #
default=$(echo -en "\e[39m") # #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
clear -x
# make sure we have the correct permissions while running the script
umask 022
### sourcing all additional scripts ### sourcing all additional scripts
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" KIAUH_SRCDIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done for script in "${KIAUH_SRCDIR}/scripts/"*.sh; do . "${script}"; done
for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
### set important directories #===================================================#
#klipper #=================== UPDATE KIAUH ==================#
KLIPPER_DIR=${HOME}/klipper #===================================================#
KLIPPY_ENV=${HOME}/klippy-env
#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=${HOME}/moonraker-env
#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}/duetwebcontrol
#octoprint
OCTOPRINT_DIR=${HOME}/OctoPrint
#KlipperScreen
KLIPPERSCREEN_DIR=${HOME}/KlipperScreen
KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env
#misc
INI_FILE=${HOME}/.kiauh.ini
BACKUP_DIR=${HOME}/kiauh-backups
### set github repos function update_kiauh() {
KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git status_msg "Updating KIAUH ..."
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
### set some messages cd "${KIAUH_SRCDIR}"
warn_msg(){ git reset --hard && git pull
echo -e "${red}<!!!!> $1${default}"
} ok_msg "Update complete! Please restart KIAUH."
status_msg(){ exit 0
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!"
} }
print_msg(){ #===================================================#
if [[ "$ERROR_MSG" != "" ]]; then #=================== KIAUH STATUS ==================#
echo -e "${red}" #===================================================#
echo -e "#########################################################"
echo -e " $ERROR_MSG " function kiauh_update_avail() {
echo -e "#########################################################" [[ ! -d "${KIAUH_SRCDIR}/.git" ]] && return
echo -e "${default}" local origin head
fi
if [ "$CONFIRM_MSG" != "" ]; then cd "${KIAUH_SRCDIR}"
echo -e "${green}"
echo -e "#########################################################" ### abort if not on master branch
echo -e " $CONFIRM_MSG " ! git branch -a | grep -q "\* master" && return
echo -e "#########################################################"
echo -e "${default}" ### 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 fi
} }
clear_msg(){ function main() {
unset CONFIRM_MSG read_kiauh_ini "${FUNCNAME[0]}"
unset ERROR_MSG main_menu
} }
check_if_ratos
check_euid check_euid
init_logfile
set_globals
read_kiauh_ini
init_ini init_ini
kiauh_status main
main_menu

18
klipper_repos.txt.example Normal file
View File

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

View File

@@ -1,10 +1,10 @@
#!/bin/bash #!/usr/bin/env bash
##################################################################### #####################################################################
### Please set the paths accordingly. In case you don't have all ### ### Please set the paths accordingly. In case you don't have all ###
### the listed folders, just keep that line commented out. ### ### 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 #config_folder=~/klipper_config
### Path to your Klipper folder, by default that is '~/klipper' ### Path to your Klipper folder, by default that is '~/klipper'
@@ -26,37 +26,38 @@
##################################################################### #####################################################################
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################ ################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
##################################################################### #####################################################################
grab_version(){ grab_version() {
if [ ! -z "$klipper_folder" ]; then local klipper_commit moonraker_commit
cd "$klipper_folder" local mainsail_ver fluidd_ver
if [[ -n ${klipper_folder} ]]; then
cd "${klipper_folder}"
klipper_commit=$(git rev-parse --short=7 HEAD) klipper_commit=$(git rev-parse --short=7 HEAD)
m1="Klipper on commit: $klipper_commit" m1="Klipper on commit: ${klipper_commit}"
cd ..
fi fi
if [ ! -z "$moonraker_folder" ]; then if [[ -n ${moonraker_folder} ]]; then
cd "$moonraker_folder" cd "${moonraker_folder}"
moonraker_commit=$(git rev-parse --short=7 HEAD) moonraker_commit=$(git rev-parse --short=7 HEAD)
m2="Moonraker on commit: $moonraker_commit" m2="Moonraker on commit: ${moonraker_commit}"
cd ..
fi fi
if [ ! -z "$mainsail_folder" ]; then if [[ -n ${mainsail_folder} ]]; then
mainsail_file=$(find $mainsail_folder/js -name "app.*.js" 2>/dev/null) mainsail_ver=$(head -n 1 "${mainsail_folder}/.version")
mainsail_ver=$(grep -o -E 'state:{packageVersion:.+' $mainsail_file | cut -d'"' -f2) m3="Mainsail version: ${mainsail_ver}"
m3="Mainsail version: $mainsail_ver"
fi fi
if [ ! -z "$fluidd_folder" ]; then if [[ -n ${fluidd_folder} ]]; then
fluidd_file=$(find $fluidd_folder/js -name "app.*.js" 2>/dev/null) fluidd_ver=$(head -n 1 "${fluidd_folder}/.version")
fluidd_ver=$(grep -o -E '"setVersion",".+"' $fluidd_file | cut -d'"' -f4) m4="Fluidd version: ${fluidd_ver}"
m4="Fluidd version: $fluidd_ver"
fi fi
} }
push_config(){ push_config() {
cd $config_folder local current_date
cd "${config_folder}" || exit 1
git pull git pull
git add . git add .
current_date=$(date +"%Y-%m-%d %T") 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 git push
} }

View File

@@ -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;
}
}

View File

@@ -0,0 +1,11 @@
[mcu]
serial: /dev/serial/by-id/<your-mcu-id>
[virtual_sdcard]
path: %GCODES_DIR%
on_error_gcode: CANCEL_PRINT
[printer]
kinematics: none
max_velocity: 1000
max_accel: 1000

96
resources/fluidd Normal file
View File

@@ -0,0 +1,96 @@
# /etc/nginx/sites-available/fluidd
server {
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/javascript application/x-javascript application/json application/xml;
# web_path from fluidd static files
root /home/pi/fluidd;
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;
proxy_read_timeout 600;
}
location /webcam/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer1/;
}
location /webcam2/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer2/;
}
location /webcam3/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer3/;
}
location /webcam4/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer4/;
}
}

View File

@@ -8,22 +8,26 @@ import shlex
import subprocess import subprocess
import logging import logging
class ShellCommand: class ShellCommand:
def __init__(self, config): def __init__(self, config):
self.name = config.get_name().split()[-1] self.name = config.get_name().split()[-1]
self.printer = config.get_printer() self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object("gcode")
cmd = config.get('command') cmd = config.get("command")
cmd = os.path.expanduser(cmd) cmd = os.path.expanduser(cmd)
self.command = shlex.split(cmd) self.command = shlex.split(cmd)
self.timeout = config.getfloat('timeout', 2., above=0.) self.timeout = config.getfloat("timeout", 2.0, above=0.0)
self.verbose = config.getboolean('verbose', True) self.verbose = config.getboolean("verbose", True)
self.proc_fd = None self.proc_fd = None
self.partial_output = "" self.partial_output = ""
self.gcode.register_mux_command( self.gcode.register_mux_command(
"RUN_SHELL_COMMAND", "CMD", self.name, "RUN_SHELL_COMMAND",
"CMD",
self.name,
self.cmd_RUN_SHELL_COMMAND, self.cmd_RUN_SHELL_COMMAND,
desc=self.cmd_RUN_SHELL_COMMAND_help) desc=self.cmd_RUN_SHELL_COMMAND_help,
)
def _process_output(self, eventime): def _process_output(self, eventime):
if self.proc_fd is None: if self.proc_fd is None:
@@ -32,25 +36,32 @@ class ShellCommand:
data = os.read(self.proc_fd, 4096) data = os.read(self.proc_fd, 4096)
except Exception: except Exception:
pass pass
data = self.partial_output + data data = self.partial_output + data.decode()
if '\n' not in data: if "\n" not in data:
self.partial_output = data self.partial_output = data
return return
elif data[-1] != '\n': elif data[-1] != "\n":
split = data.rfind('\n') + 1 split = data.rfind("\n") + 1
self.partial_output = data[split:] self.partial_output = data[split:]
data = data[:split] data = data[:split]
else:
self.partial_output = ""
self.gcode.respond_info(data) self.gcode.respond_info(data)
cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command" cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command"
def cmd_RUN_SHELL_COMMAND(self, params): def cmd_RUN_SHELL_COMMAND(self, params):
gcode_params = params.get("PARAMS", "")
gcode_params = shlex.split(gcode_params)
reactor = self.printer.get_reactor() reactor = self.printer.get_reactor()
try: try:
proc = subprocess.Popen( proc = subprocess.Popen(
self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) self.command + gcode_params,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
except Exception: except Exception:
logging.exception( logging.exception("shell_command: Command {%s} failed" % (self.name))
"shell_command: Command {%s} failed" % (self.name))
raise self.gcode.error("Error running command {%s}" % (self.name)) raise self.gcode.error("Error running command {%s}" % (self.name))
if self.verbose: if self.verbose:
self.proc_fd = proc.stdout.fileno() self.proc_fd = proc.stdout.fileno()
@@ -60,7 +71,7 @@ class ShellCommand:
endtime = eventtime + self.timeout endtime = eventtime + self.timeout
complete = False complete = False
while eventtime < endtime: while eventtime < endtime:
eventtime = reactor.pause(eventtime + .05) eventtime = reactor.pause(eventtime + 0.05)
if proc.poll() is not None: if proc.poll() is not None:
complete = True complete = True
break break

View File

@@ -1,60 +0,0 @@
#########################################################################################
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AUTOCREATED WITH KIAUH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
#########################################################################################
# Those are the recommended macros and config entries if you use Mainsail or Fluidd! #
# Feel free to edit or delete those macros if you already have them defined 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
# change this if you need more or less extrusion
variable_extrude: 1.0
gcode:
##### read E from pause macro #####
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
##### set park positon for x and y #####
# default is your max posion from your printer.cfg
{% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %}
{% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
##### calculate save lift position #####
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.x|float %}
{% if act_z < (max_z - 2.0) %}
{% set z_safe = 2.0 %}
{% 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} F900
G90
G1 X{x_park} Y{y_park} F6000
[gcode_macro RESUME]
rename_existing: BASE_RESUME
gcode:
##### read E from pause macro #####
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
##### end of definitions #####
G91
G1 E{E} F2100
RESTORE_GCODE_STATE NAME=PAUSE_state
BASE_RESUME
#########################################################################################
#########################################################################################

1
resources/klipper.env Normal file
View File

@@ -0,0 +1 @@
KLIPPER_ARGS="%KLIPPER_DIR%/klippy/klippy.py %CFG% -I %PRINTER% -l %LOG% -a %UDS%"

18
resources/klipper.service Normal file
View File

@@ -0,0 +1,18 @@
[Unit]
Description=Klipper 3D Printer Firmware SV1
Documentation=https://www.klipper3d.org/
After=network-online.target
Wants=udev.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=%USER%
RemainAfterExit=yes
WorkingDirectory=%KLIPPER_DIR%
EnvironmentFile=%ENV_FILE%
ExecStart=%ENV%/bin/python $KLIPPER_ARGS
Restart=always
RestartSec=10

View File

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

96
resources/mainsail Normal file
View File

@@ -0,0 +1,96 @@
# /etc/nginx/sites-available/mainsail
server {
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/javascript application/x-javascript application/json application/xml;
# web_path from mainsail static files
root /home/pi/mainsail;
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;
proxy_read_timeout 600;
}
location /webcam/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer1/;
}
location /webcam2/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer2/;
}
location /webcam3/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer3/;
}
location /webcam4/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer4/;
}
}

View File

@@ -0,0 +1,79 @@
### Windows users: To edit this file use Notepad++, VSCode, Atom or SublimeText.
### Do not use Notepad or WordPad.
### MacOSX users: If you use Textedit to edit this file make sure to use
### "plain text format" and "disable smart quotes" in "Textedit > Preferences"
### Configure which camera to use
#
# Available options are:
# - auto: tries first usb webcam, if that's not available tries raspi cam
# - usb: only tries usb webcam
# - raspi: only tries raspi cam
#
# Defaults to auto
#
#camera="auto"
### Additional options to supply to MJPG Streamer for the USB camera
#
# See https://faq.octoprint.org/mjpg-streamer-config for available options
#
# Defaults to a resolution of 640x480 px and a framerate of 10 fps
#
#camera_usb_options="-r 640x480 -f 10"
### Additional webcam devices known to cause problems with -f
#
# Apparently there a some devices out there that with the current
# mjpg_streamer release do not support the -f parameter (for specifying
# the capturing framerate) and will just refuse to output an image if it
# is supplied.
#
# The webcam daemon will detect those devices by their USB Vendor and Product
# ID and remove the -f parameter from the options provided to mjpg_streamer.
#
# By default, this is done for the following devices:
# Logitech C170 (046d:082b)
# GEMBIRD (1908:2310)
# Genius F100 (0458:708c)
# Cubeternet GL-UPC822 UVC WebCam (1e4e:0102)
#
# Using the following option it is possible to add additional devices. If
# your webcam happens to show above symptoms, try determining your cam's
# vendor and product id via lsusb, activating the line below by removing # and
# adding it, e.g. for two broken cameras "aabb:ccdd" and "aabb:eeff"
#
# additional_brokenfps_usb_devices=("aabb:ccdd" "aabb:eeff")
#
#
#additional_brokenfps_usb_devices=()
### Additional options to supply to MJPG Streamer for the RasPi Cam
#
# See https://faq.octoprint.org/mjpg-streamer-config for available options
#
# Defaults to 10fps
#
#camera_raspi_options="-fps 10"
### Configuration of camera HTTP output
#
# Usually you should NOT need to change this at all! Only touch if you
# know what you are doing and what the parameters mean.
#
# Below settings are used in the mjpg-streamer call like this:
#
# -o "output_http.so -w $camera_http_webroot $camera_http_options"
#
# Current working directory is the mjpg-streamer base directory.
#
#camera_http_webroot="./www-mainsail"
#camera_http_options="-n"
### EXPERIMENTAL
# Support for different streamer types.
#
# Available options:
# mjpeg [default] - stable MJPG-streamer
#camera_streamer=mjpeg

View File

@@ -0,0 +1,303 @@
#!/bin/bash
########################################################################
### DO NOT EDIT THIS FILE TO CHANGE THE CONFIG!!! ###
### ---------------------------------------------------------------- ###
### There is no need to edit this file for changing resolution, ###
### frame rates or any other mjpg-streamer parameters. Please edit ###
### /home/pi/klipper_config/webcam.txt instead - that's what it's ###
### there for! You can even do this with your Pi powered down by ###
### directly accessing the file when using the SD card as thumb ###
### drive in your regular computer. ###
########################################################################
MJPGSTREAMER_HOME=/home/pi/mjpg-streamer
MJPGSTREAMER_INPUT_USB="input_uvc.so"
MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"
brokenfps_usb_devices=("046d:082b" "1908:2310" "0458:708c" "1e4e:0102" "0471:0311" "038f:6001" "046d:0804" "046d:0825" "046d:0994" "0ac8:3450")
config_dir="/home/pi/klipper_config"
echo "Starting up webcamDaemon..."
echo ""
cfg_files=()
#cfg_files+=/boot/mainsail.txt
if [[ -d ${config_dir} ]]; then
cfg_files+=( `ls ${config_dir}/webcam*.txt` )
fi
array_camera_config=()
array_camera=()
array_camera_usb_options=()
array_camera_usb_device=()
array_camera_raspi_options=()
array_camera_http_webroot=()
array_camera_http_options=()
array_additional_brokenfps_usb_devices=()
array_camera_device=()
array_assigned_device=()
echo "--- Configuration: ----------------------------"
for cfg_file in ${cfg_files[@]}; do
# init configuration - DO NOT EDIT, USE /home/pi/klipper_config/webcam*.txt INSTEAD!
camera="auto"
camera_usb_options="-r 640x480 -f 10"
camera_raspi_options="-fps 10"
camera_http_webroot="./www-mjpgstreamer"
camera_http_options="-n"
additional_brokenfps_usb_devices=()
if [[ -e ${cfg_file} ]]; then
source "$cfg_file"
fi
usb_options="$camera_usb_options"
# if webcam device is explicitly given in /home/pi/klipper_config/webcam*.txt, save the path of the device
# to a variable and remove its parameter from usb_options
extracted_device=`echo $usb_options | sed 's@.*-d \(/dev/\(video[0-9]\+\|v4l/[^ ]*\)\).*@\1@'`
if [ "$extracted_device" != "$usb_options" ]
then
# the camera options refer to a device, save it in a variable
# replace video device parameter with empty string and strip extra whitespace
usb_options=`echo $usb_options | sed 's/\-d \/dev\/\(video[0-9]\+\|v4l\/[^ ]*\)//g' | awk '$1=$1'`
else
extracted_device=""
fi
# echo configuration
echo "cfg_file: $cfg_file"
echo "camera: $camera"
echo "usb options: $camera_usb_options"
echo "raspi options: $camera_raspi_options"
echo "http options: -w $camera_http_webroot $camera_http_options"
echo ""
echo "Explicitly USB device: $extracted_device"
echo "-----------------------------------------------"
echo ""
array_camera_config+=( $cfg_file )
array_camera+=( $camera )
array_camera_usb_options+=("$usb_options")
array_camera_usb_device+=("$extracted_device")
array_camera_raspi_options+=("$camera_raspi_options")
array_camera_http_webroot+=("$camera_http_webroot")
array_camera_http_options+=("$camera_http_options")
array_camera_brokenfps_usb_devices+=("${brokenfps_usb_devices[*]} ${additional_brokenfps_usb_devices[*]}")
array_camera_device+=("")
done
# check if array contains a string
function containsString() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
# cleans up when the script receives a SIGINT or SIGTERM
function cleanup() {
# make sure that all child processed die when we die
local pids=$(jobs -pr)
[ -n "$pids" ] && kill $pids
exit 0
}
# says goodbye when the script shuts down
function goodbye() {
# say goodbye
echo ""
echo "Goodbye..."
echo ""
}
# runs MJPG Streamer, using the provided input plugin + configuration
function runMjpgStreamer {
input=$1
# There are problems with 0x000137ab firmware on VL805 (Raspberry Pi 4}).
# Try to autodetect offending firmware and temporarily fix the issue
# by changing power management mode
echo "Checking for VL805 (Raspberry Pi 4)..."
if [[ -f /usr/bin/vl805 ]]; then
VL805_VERSION=$(/usr/bin/vl805)
VL805_VERSION=${VL805_VERSION#*: }
echo " - version 0x${VL805_VERSION} detected"
case "$VL805_VERSION" in
00013701)
echo " - nothing to be done. It shouldn't cause USB problems."
;;
000137ab)
echo -e " - \e[31mThis version is known to cause problems with USB cameras.\e[39m"
echo -e " You may want to downgrade to 0x0013701."
echo -e " - [FIXING] Trying the setpci -s 01:00.0 0xD4.B=0x41 hack to mitigate the"
echo -e " issue. It disables ASPM L1 on the VL805. Your board may (or may not) get"
echo -e " slightly hotter. For details see:"
echo -e " https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=244421"
setpci -s 01:00.0 0xD4.B=0x41
;;
*)
echo " - unknown firmware version. Doing nothing."
;;
esac
else
echo " - It seems that you don't have VL805 (Raspberry Pi 4)."
echo " There should be no problems with USB (a.k.a. select() timeout)"
fi
pushd $MJPGSTREAMER_HOME > /dev/null 2>&1
echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input"
LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input" &
sleep 1 &
sleep_pid=$!
wait ${sleep_pid}
popd > /dev/null 2>&1
}
# starts up the RasPiCam
function startRaspi {
logger -s "Starting Raspberry Pi camera"
runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
}
# starts up the USB webcam
function startUsb {
options="$usb_options"
device="video0"
# check for parameter and set the device if it is given as a parameter
input=$1
if [[ -n $input ]]; then
device=`basename "$input"`
fi
# add video device into options
options="$options -d /dev/$device"
uevent_file="/sys/class/video4linux/$device/device/uevent"
if [ -e $uevent_file ]; then
# let's see what kind of webcam we have here, fetch vid and pid...
product=`cat $uevent_file | grep PRODUCT | cut -d"=" -f2`
vid=`echo $product | cut -d"/" -f1`
pid=`echo $product | cut -d"/" -f2`
vidpid=`printf "%04x:%04x" "0x$vid" "0x$pid"`
# ... then look if it is in our list of known broken-fps-devices and if so remove
# the -f parameter from the options (if it's in there, else that's just a no-op)
for identifier in ${brokenfps_usb_devices[@]};
do
if [ "$vidpid" = "$identifier" ]; then
echo
echo "Camera model $vidpid is known to not work with -f parameter, stripping it out"
echo
options=`echo $options | sed -e "s/\(\s\+\|^\)-f\s\+[0-9]\+//g"`
fi
done
fi
logger -s "Starting USB webcam"
runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $options"
}
# make sure our cleanup function gets called when we receive SIGINT, SIGTERM
trap "cleanup" SIGINT SIGTERM
# say goodbye when we EXIT
trap "goodbye" EXIT
# we need this to prevent the later calls to vcgencmd from blocking
# I have no idea why, but that's how it is...
vcgencmd version > /dev/null 2>&1
# keep mjpg streamer running if some camera is attached
while true; do
# get list of usb video devices into an array
video_devices=($(find /dev -regextype sed -regex '\/dev/video[0-9]\+' | sort -nk1.11 2> /dev/null))
# add list of raspi camera into an array
if [ "`vcgencmd get_camera`" = "supported=1 detected=1" ]; then
video_devices+=( "raspi" )
fi
echo "Found video devices:"
printf '%s\n' "${video_devices[@]}"
for scan_mode in "usb" "usb-auto" "raspi" "auto"; do
camera=$scan_mode
if [[ "usb-auto" == "$scan_mode" ]]; then
camera="usb"
fi
for ((i=0;i<${#array_camera[@]};i++)); do
if [[ -z ${array_camera_device[${i}]} ]] && [[ $camera == ${array_camera[${i}]} ]]; then
camera_config="${array_camera_config[${i}]}"
usb_options="${array_camera_usb_options[${i}]}"
camera_usb_device="${array_camera_usb_device[${i}]}"
camera_raspi_options="${array_camera_raspi_options[${i}]}"
camera_http_webroot="${array_camera_http_webroot[${i}]}"
camera_http_options="${array_camera_http_options[${i}]}"
brokenfps_usb_devices="${array_camera_brokenfps_usb_devices[${i}]}"
if [[ ${camera_usb_device} ]] && { [[ "usb" == ${scan_mode} ]] || [[ "auto" == ${scan_mode} ]]; }; then
# usb device is explicitly set in options
usb_device_path=`readlink -f ${camera_usb_device}`
if containsString "$usb_device_path" "${array_camera_device[@]}"; then
if [[ "auto" != ${scan_mode} ]]; then
array_camera_device[${i}]="alredy_in_use"
echo "config file='$camera_config':Video device already in use."
continue
fi
elif containsString "$usb_device_path" "${video_devices[@]}"; then
array_camera_device[${i}]="$usb_device_path"
# explicitly set usb device was found in video_devices array, start usb with the found device
echo "config file='$camera_config':USB device was set in options and found in devices, start MJPG-streamer with the configured USB video device: $usb_device_path"
startUsb "$usb_device_path"
continue
fi
elif [[ -z ${camera_usb_device} ]] && { [[ "usb-auto" == ${scan_mode} ]] || [[ "auto" == ${scan_mode} ]]; }; then
for video_device in "${video_devices[@]}"; do
if [[ "raspi" != "$video_device" ]]; then
if containsString "$video_device" "${array_camera_device[@]}"; then
: #already in use
else
array_camera_device[${i}]="$video_device"
# device is not set explicitly in options, start usb with first found usb camera as the device
echo "config file='$camera_config':USB device was not set in options, start MJPG-streamer with the first found video device: ${video_device}"
startUsb "${video_device}"
break
fi
fi
done
if [[ -n ${array_camera_device[${i}]} ]]; then
continue
fi
fi
if [[ "raspi" == ${scan_mode} ]] || [[ "auto" == ${scan_mode} ]]; then
video_device="raspi"
if containsString "$video_device" "${array_camera_device[@]}"; then
if [[ "auto" != ${scan_mode} ]]; then
array_camera_device[${i}]="alredy_in_use"
echo "config file='$camera_config':RasPiCam device already in use."
fi
elif containsString "$video_device" "${video_devices[@]}"; then
array_camera_device[${i}]="$video_device"
echo "config file='$camera_config':Start MJPG-streamer with video device: ${video_device}"
startRaspi
sleep 30 &
sleep_pid=$!
wait ${sleep_pid}
fi
fi
fi
done
done
array_assigned_device=( ${array_camera_device[*]} )
if [[ ${#array_camera[@]} -eq ${#array_assigned_device[@]} ]]; then
echo "Done bring up all configured video device"
exit 0
else
echo "Scan again in two minutes"
sleep 120 &
sleep_pid=$!
wait ${sleep_pid}
fi
done

View File

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

View File

@@ -0,0 +1 @@
TELEGRAM_BOT_ARGS="%TELEGRAM_BOT_DIR%/bot/main.py -c %CFG% -l %LOG%"

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Moonraker Telegram Bot SV1 %INST%
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
After=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=%USER%
WorkingDirectory=%TELEGRAM_BOT_DIR%
EnvironmentFile=%ENV_FILE%
ExecStart=%ENV%/bin/python $TELEGRAM_BOT_ARGS
Restart=always
RestartSec=10

31
resources/moonraker.conf Normal file
View File

@@ -0,0 +1,31 @@
[server]
host: 0.0.0.0
port: %PORT%
klippy_uds_address: %UDS%
[authorization]
trusted_clients:
%LAN%
10.0.0.0/8
127.0.0.0/8
169.254.0.0/16
172.16.0.0/12
192.168.0.0/16
FE80::/10
::1/128
cors_domains:
*.lan
*.local
*.internal
*://localhost
*://localhost:*
*://my.mainsail.xyz
*://app.fluidd.xyz
[octoprint_compat]
[history]
[update_manager]
channel: dev
refresh_interval: 168

1
resources/moonraker.env Normal file
View File

@@ -0,0 +1 @@
MOONRAKER_ARGS="%MOONRAKER_DIR%/moonraker/moonraker.py -d %PRINTER_DATA%"

View File

@@ -0,0 +1,19 @@
[Unit]
Description=API Server for Klipper SV1 %INST%
Documentation=https://moonraker.readthedocs.io/
Requires=network-online.target
After=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=%USER%
SupplementaryGroups=moonraker-admin
RemainAfterExit=yes
WorkingDirectory=%MOONRAKER_DIR%
EnvironmentFile=%ENV_FILE%
ExecStart=%ENV%/bin/python $MOONRAKER_ARGS
Restart=always
RestartSec=10

View File

@@ -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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -1,13 +1,25 @@
# /etc/nginx/conf.d/upstreams.conf # /etc/nginx/conf.d/upstreams.conf
upstream apiserver { upstream apiserver {
#edit your api port here
ip_hash; ip_hash;
server 127.0.0.1:7125; server 127.0.0.1:7125;
} }
upstream mjpgstreamer { upstream mjpgstreamer1 {
#edit your webcam port here
ip_hash; ip_hash;
server 127.0.0.1:8080; server 127.0.0.1:8080;
} }
upstream mjpgstreamer2 {
ip_hash;
server 127.0.0.1:8081;
}
upstream mjpgstreamer3 {
ip_hash;
server 127.0.0.1:8082;
}
upstream mjpgstreamer4 {
ip_hash;
server 127.0.0.1:8083;
}

View File

@@ -1,177 +1,231 @@
check_for_backup_dir(){ #!/usr/bin/env bash
if [ ! -d $BACKUP_DIR ]; then
status_msg "Create KIAUH backup directory ..." #=======================================================================#
mkdir -p $BACKUP_DIR && ok_msg "Directory created!" # Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
fi # #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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}"
} }
toggle_backups(){ function check_for_backup_dir() {
source_kiauh_ini [[ -d ${BACKUP_DIR} ]] && return
if [ "$backup_before_update" = "true" ]; then
sed -i '/backup_before_update=/s/true/false/' $INI_FILE status_msg "Create KIAUH backup directory ..."
BB4U_STATUS="${green}[Enable]${default} backups before updating " mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
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(){ function backup_before_update() {
source_kiauh_ini read_kiauh_ini "${FUNCNAME[0]}"
if [ "$backup_before_update" = "true" ]; then local state="${backup_before_update}"
backup_$1 [[ ${state} = "false" ]] && return
fi backup_"${1}"
} }
read_bb4u_stat(){ function backup_config_dir() {
source_kiauh_ini
if [ ! "$backup_before_update" = "true" ]; then
BB4U_STATUS="${green}[Enable]${default} backups before updating "
else
BB4U_STATUS="${red}[Disable]${default} backups before updating "
fi
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
backup_printer_cfg(){
check_for_backup_dir check_for_backup_dir
if [ -f $PRINTER_CFG ]; then local current_date config_pathes
get_date
status_msg "Timestamp: $current_date"
status_msg "Create backup of printer.cfg ..."
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!"
else
ok_msg "No printer.cfg found! Skipping backup ..."
fi
}
backup_klipper_config_dir(){ config_pathes=$(get_config_folders)
source_kiauh_ini
check_for_backup_dir if [[ -n "${config_pathes}" ]]; then
if [ -d "$klipper_cfg_loc" ]; then current_date=$(get_date)
get_date status_msg "Timestamp: ${current_date}"
status_msg "Timestamp: $current_date"
status_msg "Create backup of the Klipper config directory ..." local i=0 folder folder_name target_dir
config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" for folder in ${config_pathes}; do
mkdir -p $BACKUP_DIR/$config_folder_name/$current_date if [[ -d ${folder} ]]; then
cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!" status_msg "Create backup of ${folder} ..."
echo
folder_name=$(echo "${folder}" | rev | cut -d"/" -f2 | rev)
target_dir="${BACKUP_DIR}/configs/${current_date}/${folder_name}"
mkdir -p "${target_dir}"
cp -r "${folder}" "${target_dir}"
i=$(( i + 1 ))
ok_msg "Backup created in:\n${target_dir}"
fi
done
else else
ok_msg "No config directory found! Skipping backup ..." ok_msg "No config directory found! Skipping backup ..."
echo
fi fi
} }
function backup_moonraker_database() {
###TODO re-evaluate if this function is still needed (just backup the full klipper_config dir instead?)
backup_moonraker_conf(){
check_for_backup_dir check_for_backup_dir
if [ -f ${HOME}/moonraker.conf ]; then local current_date db_pathes
get_date
status_msg "Timestamp: $current_date" db_pathes=$(get_instance_folder_path "database")
status_msg "Create backup of moonraker.conf ..."
cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!" if [[ -n ${db_pathes} ]]; then
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
local i=0 database folder_name target_dir
for database in ${db_pathes}; do
status_msg "Create backup of ${database} ..."
folder_name=$(echo "${database}" | rev | cut -d"/" -f2 | rev)
target_dir="${BACKUP_DIR}/moonraker_databases/${current_date}/${folder_name}"
mkdir -p "${target_dir}"
cp -r "${database}" "${target_dir}"
i=$(( i + 1 ))
ok_msg "Backup created in:\n${target_dir}"
done
else else
ok_msg "No moonraker.conf found! Skipping backup ..." print_error "No Moonraker database found! Skipping backup ..."
fi fi
} }
backup_klipper(){ function backup_klipper() {
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then local current_date
if [[ -d ${KLIPPER_DIR} && -d ${KLIPPY_ENV} ]]; then
status_msg "Creating Klipper backup ..." status_msg "Creating Klipper backup ..."
check_for_backup_dir check_for_backup_dir
get_date current_date=$(get_date)
status_msg "Timestamp: $current_date" status_msg "Timestamp: ${current_date}"
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date" mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}"
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!" cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}"
print_confirm "Klipper backup complete!"
else 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 fi
} }
backup_dwc2(){ function backup_mainsail() {
if [ -d $DWC2FK_DIR ] && [ -d $DWC_ENV_DIR ] && [ -d $DWC2_DIR ]; then local current_date
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
}
backup_mainsail(){ if [[ -d ${MAINSAIL_DIR} ]]; then
if [ -d $MAINSAIL_DIR ]; then
status_msg "Creating Mainsail backup ..." status_msg "Creating Mainsail backup ..."
check_for_backup_dir check_for_backup_dir
get_date current_date=$(get_date)
status_msg "Timestamp: $current_date" status_msg "Timestamp: ${current_date}"
mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date" mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}"
cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!" cp -r "${MAINSAIL_DIR}" "${_}"
print_confirm "Mainsail backup complete!"
else else
ERROR_MSG=" Can't backup mainsail directory! Not found!" print_error "Can't back up 'mainsail' directory! Not found!"
fi fi
} }
backup_fluidd(){ function backup_fluidd() {
if [ -d $FLUIDD_DIR ]; then local current_date
if [[ -d ${FLUIDD_DIR} ]]; then
status_msg "Creating Fluidd backup ..." status_msg "Creating Fluidd backup ..."
check_for_backup_dir check_for_backup_dir
get_date current_date=$(get_date)
status_msg "Timestamp: $current_date" status_msg "Timestamp: ${current_date}"
mkdir -p $BACKUP_DIR/fluidd-backups/"$current_date" mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}"
cp -r $FLUIDD_DIR $_ && ok_msg "Backup complete!" cp -r "${FLUIDD_DIR}" "${_}"
print_confirm "Fluidd backup complete!"
else else
ERROR_MSG=" Can't backup fluidd directory! Not found!" print_error "Can't back up 'fluidd' directory! Not found!"
fi fi
} }
backup_moonraker(){ function backup_moonraker() {
if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV ]; then local current_date
if [[ -d ${MOONRAKER_DIR} && -d ${MOONRAKER_ENV} ]]; then
status_msg "Creating Moonraker backup ..." status_msg "Creating Moonraker backup ..."
check_for_backup_dir check_for_backup_dir
get_date current_date=$(get_date)
status_msg "Timestamp: $current_date" status_msg "Timestamp: ${current_date}"
mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date" mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}"
cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV $_ && ok_msg "Backup complete!" cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}"
print_confirm "Moonraker backup complete!"
else 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 fi
} }
backup_octoprint(){ function backup_octoprint() {
if [ -d $OCTOPRINT_DIR ] && [ -d $OCTOPRINT_CFG_DIR ]; then local current_date
if [[ -d ${OCTOPRINT_DIR} && -d ${OCTOPRINT_CFG_DIR} ]]; then
status_msg "Creating OctoPrint backup ..." status_msg "Creating OctoPrint backup ..."
check_for_backup_dir check_for_backup_dir
get_date current_date=$(get_date)
status_msg "Timestamp: $current_date" status_msg "Timestamp: ${current_date}"
mkdir -p $BACKUP_DIR/octoprint-backups/"$current_date" mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}"
cp -r $OCTOPRINT_DIR $_ && cp -r $OCTOPRINT_CFG_DIR $_ cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
ok_msg "Backup complete!" print_confirm " OctoPrint backup complete!"
else 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 fi
} }
backup_klipperscreen(){ function backup_klipperscreen() {
if [ -d $KLIPPERSCREEN_DIR ] ; then local current_date
if [[ -d ${KLIPPERSCREEN_DIR} ]] ; then
status_msg "Creating KlipperScreen backup ..." status_msg "Creating KlipperScreen backup ..."
check_for_backup_dir check_for_backup_dir
get_date current_date=$(get_date)
status_msg "Timestamp: $current_date" status_msg "Timestamp: ${current_date}"
mkdir -p $BACKUP_DIR/klipperscreen-backups/"$current_date" mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}"
cp -r $KLIPPERSCREEN_DIR $_ cp -r "${KLIPPERSCREEN_DIR}" "${_}"
ok_msg "Backup complete!" print_confirm "KlipperScreen backup complete!"
else 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
}
function backup_octoeverywhere() {
local current_date
if [[ -d ${OCTOEVERYWHERE_DIR} ]] ; then
status_msg "Creating OctoEverywhere backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/OctoEverywhere-backups/${current_date}"
cp -r "${OCTOEVERYWHERE_DIR}" "${_}" && cp -r "${OCTOEVERYWHERE_ENV}" "${_}"
print_confirm "OctoEverywhere backup complete!"
else
print_error "Can't back up OctoEverywhere directory!\n Not found!"
fi
}
function backup_spoolman() {
local current_date
if [[ -d ${SPOOLMAN_DIR} ]] ; then
status_msg "Creating Spoolman backup ..."
check_for_backup_dir
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/Spoolman-backups/${current_date}"
cp -r "${SPOOLMAN_DIR}" "${_}" && cp -r "${SPOOLMAN_DB_DIR}/spoolman.db" "${_}"
print_confirm "Spoolman backup complete!"
else
print_error "Can't back up Spoolman directory!\n Not found!"
fi fi
} }

235
scripts/crowsnest.sh Normal file
View File

@@ -0,0 +1,235 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
#=======================================================================#
# Crowsnest Installer brought to you by KwadFan <me@stephanwe.de> #
# Copyright (C) 2022 KwadFan <me@stephanwe.de> #
# https://github.com/KwadFan/crowsnest #
#=======================================================================#
# Error Handling
set -e
# Helper messages
function multi_instance_message(){
echo -e "Crowsnest is NOT designed to support multi instances."
echo -e "A workaround for this is to choose the most used instance as a 'master'"
echo -e "Use this instance to set up your 'crowsnest.conf' and steering it's service.\n"
echo -e "Found the following instances:\n"
for i in ${1}; do
select_msg "${i}"
done
echo -e "\nLaunching crowsnest's configuration tool ..."
continue_config
}
# Helper funcs
function clone_crowsnest(){
$(command -v git) clone "${CROWSNEST_REPO}" -b master "${CROWSNEST_DIR}"
}
function check_multi_instance(){
local -a instances
readarray -t instances < <(find "${HOME}" -regex "${HOME}/[a-zA-Z0-9_]+_data/*" -printf "%P\n" 2> /dev/null | sort)
if [[ "${#instances[@]}" -gt 1 ]]; then
status_msg "Multi instance install detected ..."
multi_instance_message "${instances[*]}"
if [[ -d "${HOME}/crowsnest" ]]; then
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
if ! make config ;then
error_msg "Something went wrong! Please try again..."
if [[ -f "tools/.config" ]]; then
rm -f tools/.config
fi
exit 1
fi
if [[ ! -f "tools/.config" ]]; then
log_error "failure while generating .config"
error_msg "Generating .config failed, installation aborted"
exit 1
fi
popd &> /dev/null || exit 1
fi
fi
}
function continue_config() {
local reply
while true; do
read -erp "${cyan}###### Continue with configuration? (y/N):${white} " reply
case "${reply}" in
Y|y|Yes|yes)
select_msg "Yes"
break;;
N|n|No|no|"")
select_msg "No"
warn_msg "Installation aborted by user ... Exiting!"
exit 1;;
*)
error_msg "Invalid Input!\n";;
esac
done
return 0
}
# Install func
function install_crowsnest(){
# Step 1: jump to home directory
pushd "${HOME}" &> /dev/null || exit 1
# Step 2: Clone crowsnest repo
status_msg "Cloning 'crowsnest' repository ..."
if [[ ! -d "${HOME}/crowsnest" && -z "$(ls -A "${HOME}/crowsnest" 2> /dev/null)" ]]; then
clone_crowsnest
else
ok_msg "crowsnest repository already exists ..."
fi
# Step 3: Install dependencies
dependency_check git make
# Step 4: Check for Multi Instance
check_multi_instance
# Step 5: Launch crowsnest installer
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
title_msg "Installer will prompt you for sudo password!"
status_msg "Launching crowsnest installer ..."
if ! sudo make install; then
error_msg "Something went wrong! Please try again..."
exit 1
fi
# Step 5: Leave directory (twice due two pushd)
popd &> /dev/null || exit 1
popd &> /dev/null || exit 1
}
# Remove func
function remove_crowsnest(){
if [[ -d "${CROWSNEST_DIR}" ]]; then
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
title_msg "Uninstaller will prompt you for sudo password!"
status_msg "Launching crowsnest uninstaller ..."
if ! make uninstall; then
error_msg "Something went wrong! Please try again..."
exit 1
fi
status_msg "Removing crowsnest directory ..."
rm -rf "${CROWSNEST_DIR}"
ok_msg "Directory removed!"
fi
print_confirm "Crowsnest successfully removed!"
}
# Status funcs
get_crowsnest_status(){
local -a files
local env_file
env_file="$(grep "EnvironmentFile" /etc/systemd/system/crowsnest.service 2>/dev/null | cut -d "=" -f2)"
files=(
"${CROWSNEST_DIR}"
"/usr/local/bin/crowsnest"
"/etc/logrotate.d/crowsnest"
"/etc/systemd/system/crowsnest.service"
"${env_file}"
)
local count
count=0
for file in "${files[@]}"; do
[[ -e "${file}" ]] && count=$(( count +1 ))
done
if [[ "${count}" -eq "${#files[*]}" ]]; then
echo "Installed"
elif [[ "${count}" -gt 0 ]]; then
echo "Incomplete!"
else
echo "Not installed!"
fi
}
# Update funcs
# Shameless stolen from KlipperScreen.sh
function get_local_crowsnest_commit() {
[[ ! -d ${CROWSNEST_DIR} || ! -d "${CROWSNEST_DIR}/.git" ]] && return
local commit
cd "${CROWSNEST_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_crowsnest_commit() {
[[ ! -d ${CROWSNEST_DIR} || ! -d "${CROWSNEST_DIR}/.git" ]] && return
local commit
cd "${CROWSNEST_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_crowsnest_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_crowsnest_commit)"
remote_ver="$(get_remote_crowsnest_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker to application_updates_available in kiauh.ini
add_to_application_updates "crowsnest"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
function install_crowsnest_dependencies() {
local packages log_name="Crowsnest"
local install_script="${CROWSNEST_DIR}/tools/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 lists if stale
update_system_package_lists
### Install required packages
install_system_packages "${log_name}" "packages[@]"
}
function update_crowsnest() {
do_action_service "stop" "crowsnest"
if [[ ! -d ${CROWSNEST_DIR} ]]; then
clone_crowsnest
else
status_msg "Updating Crowsnest ..."
cd "${CROWSNEST_DIR}" && git pull
### read PKGLIST and install possible new dependencies
install_crowsnest_dependencies
fi
ok_msg "Update complete!"
do_action_service "restart" "crowsnest"
}

View File

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

View File

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

View File

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

View File

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

View File

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

494
scripts/flash_klipper.sh Normal file
View File

@@ -0,0 +1,494 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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 flashed (flash/serialflash)
select_flash_command
### step 3: select how the mcu is connected to the host
select_mcu_connection
### step 4: select which detected mcu should be flashed
select_mcu_id "${method}"
}
#================================================#
#=================== STEP 2 =====================#
#================================================#
function select_flash_command() {
unset flash_command
top_border
echo -e "| How to flash MCU? |"
echo -e "| 1) make flash (default) |"
echo -e "| 2) make serialflash (stm32flash) |"
blank_line
back_help_footer
local choice
while true; do
read -p "${cyan}###### Flashing command:${white} " -i "1" -e choice
case "${choice}" in
1)
select_msg "Selected 'make flash' command"
flash_command="flash"
break;;
2)
select_msg "Selected 'make serialflash' command"
flash_command="serialflash"
break;;
B|b)
advanced_menu
break;;
H|h)
clear && print_header
show_mcu_flash_command_help
break;;
*)
error_msg "Invalid command!";;
esac
done
}
#================================================#
#=================== STEP 3 =====================#
#================================================#
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 |"
echo -e "| 3) USB (DFU mode) |"
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;;
3)
status_msg "Identifying MCU connected via USB in DFU mode ...\n"
get_dfu_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 either not connected or not detected!"
return
fi
for mcu in "${mcu_list[@]}"; do
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
i=$(( i + 1 ))
done
echo
}
#================================================#
#=================== STEP 4 =====================#
#================================================#
function select_mcu_id() {
local i=0 sel_index=0 method=${1}
if (( ${#mcu_list[@]} < 1 )); then
print_error "No MCU found!\n MCU either 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_command} 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 get_dfu_id() {
unset mcu_list
sleep 1
mcus=$(lsusb | grep "DFU" | cut -d " " -f 6 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_flash_command_help() {
top_border
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
hr
echo -e "| ${cyan}make flash:${white} |"
echo -e "| The default command to flash controller board, it |"
echo -e "| will detect selected microcontroller and use suitable |"
echo -e "| tool for flashing it. |"
blank_line
echo -e "| ${cyan}make serialflash:${white} |"
echo -e "| Special command to flash STM32 microcontrollers in |"
echo -e "| DFU mode but connected via serial. stm32flash command |"
echo -e "| will be used internally. |"
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_flash_command
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
}

510
scripts/fluidd.sh Normal file
View File

@@ -0,0 +1,510 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#================== INSTALL FLUIDD =================#
#===================================================#
function install_fluidd() {
if [[ -z $(moonraker_systemd) ]]; then
local error="Moonraker not installed! It's recommended to install Moonraker first!"
print_error "${error}"
while true; do
local yn
read -p "${cyan}###### Proceed to install Fluidd without installing Moonraker? (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 Fluidd setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
fi
### checking dependencies
local dep=(wget nginx unzip)
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_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
### 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
fetch_webui_ports #WIP
### confirm message
print_confirm "Fluidd has been set up!"
}
function install_fluidd_macros() {
local yn
while true; do
echo
top_border
echo -e "| It is recommended to use special macros in order to |"
echo -e "| have Fluidd fully functional and working. |"
blank_line
echo -e "| The recommended macros for Fluidd can be found here: |"
echo -e "| https://github.com/fluidd-core/fluidd-config |"
blank_line
echo -e "| If you already use these macros skip this step. |"
echo -e "| Otherwise you should consider to answer with 'yes' to |"
echo -e "| download the recommended macros. |"
bottom_border
read -p "${cyan}###### Download 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 ms_cfg_repo path configs regex line gcode_dir
ms_cfg_repo="https://github.com/fluidd-core/fluidd-config.git"
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
if [[ -z ${configs} ]]; then
print_error "No printer.cfg found! Installation of Macros will be skipped ..."
log_error "execution stopped! reason: no printer.cfg found"
return
fi
status_msg "Cloning fluidd-config ..."
[[ -d "${HOME}/fluidd-config" ]] && rm -rf "${HOME}/fluidd-config"
if git clone --recurse-submodules "${ms_cfg_repo}" "${HOME}/fluidd-config"; then
for config in ${configs}; do
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
if [[ -e "${path}/fluidd.cfg" && ! -h "${path}/fluidd.cfg" ]]; then
warn_msg "Attention! Existing fluidd.cfg detected!"
warn_msg "The file will be renamed to 'fluidd.bak.cfg' to be able to continue with the installation."
if ! mv "${path}/fluidd.cfg" "${path}/fluidd.bak.cfg"; then
error_msg "Renaming fluidd.cfg failed! Aborting installation ..."
return
fi
fi
if [[ -h "${path}/fluidd.cfg" ]]; then
warn_msg "Recreating symlink in ${path} ..."
rm -rf "${path}/fluidd.cfg"
fi
if ! ln -sf "${HOME}/fluidd-config/client.cfg" "${path}/fluidd.cfg"; then
error_msg "Creating symlink failed! Aborting installation ..."
return
fi
if ! grep -Eq "^\[include fluidd.cfg\]$" "${path}/printer.cfg"; then
log_info "${path}/printer.cfg"
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
fi
line=$(($(grep -n "\[include fluidd.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1))
gcode_dir=${path/config/gcodes}
if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then
log_info "${path}/printer.cfg"
sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg"
fi
done
else
print_error "Cloning failed! Aborting installation ..."
log_error "execution stopped! reason: cloning failed"
return
fi
patch_fluidd_config_update_manager
ok_msg "Done!"
}
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_nginx_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 regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/fluidd-.*"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_legacy_fluidd_log_symlinks() {
local files
files=$(find "${HOME}/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_config() {
if [[ -d "${HOME}/fluidd-config" ]]; then
status_msg "Removing ${HOME}/fluidd-config ..."
rm -rf "${HOME}/fluidd-config"
ok_msg "${HOME}/fluidd-config removed!"
print_confirm "Fluidd-Config successfully removed!"
fi
}
function remove_fluidd() {
remove_fluidd_dir
remove_fluidd_nginx_config
remove_fluidd_logs
remove_fluidd_log_symlinks
remove_legacy_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() {
local versionfile="${FLUIDD_DIR}/.version"
local relinfofile="${FLUIDD_DIR}/release_info.json"
local version
if [[ -f ${relinfofile} ]]; then
version=$(grep -o '"version":"[^"]*' "${relinfofile}" | grep -o '[^"]*$')
elif [[ -f ${versionfile} ]]; then
version=$(head -n 1 "${versionfile}")
fi
echo "${version}"
}
function get_remote_fluidd_version() {
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
local tags
tags=$(curl -s "https://api.github.com/repos/fluidd-core/fluidd/tags" | grep "name" | cut -d'"' -f4)
echo "${tags}" | head -1
}
function compare_fluidd_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_fluidd_version)"
remote_ver="$(get_remote_fluidd_version)"
if [[ ${local_ver} != "${remote_ver}" && ${local_ver} != "" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker to application_updates_available in kiauh.ini
add_to_application_updates "fluidd"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function get_fluidd_download_url() {
local releases_by_tag tags tag unstable_url url
### latest stable download url
url="https://github.com/fluidd-core/fluidd/releases/latest/download/fluidd.zip"
read_kiauh_ini "${FUNCNAME[0]}"
if [[ ${fluidd_install_unstable} == "true" ]]; then
releases_by_tag="https://api.github.com/repos/fluidd-core/fluidd/tags"
tags=$(curl -s "${releases_by_tag}" | grep "name" | cut -d'"' -f4)
tag=$(echo "${tags}" | head -1)
### latest unstable download url including pre-releases (alpha, beta, rc)
unstable_url="https://github.com/fluidd-core/fluidd/releases/download/${tag}/fluidd.zip"
if [[ ${unstable_url} == *"download//"* ]]; then
warn_msg "Download URL broken! Falling back to URL of latest stable release!"
else
url=${unstable_url}
fi
fi
echo "${url}"
}
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/fluidd" | 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 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} != "${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 patched moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
patched="false"
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager fluidd\]\s*$" "${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
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}
function patch_fluidd_config_update_manager() {
local patched moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
patched="false"
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager fluidd-config\]\s*$" "${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-Config to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager fluidd-config]
type: git_repo
primary_branch: master
path: ~/fluidd-config
origin: https://github.com/fluidd-core/fluidd-config.git
managed_services: klipper
MOONRAKER_CONF
fi
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}

View File

@@ -1,504 +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
}
check_klipper_cfg_path(){
source_kiauh_ini
if [ -z $klipper_cfg_loc ]; then
echo
top_border
echo -e "| ${red}!!! WARNING !!!${default} |"
echo -e "| ${red}No Klipper configuration directory set!${default} |"
hr
echo -e "| Before we can continue, KIAUH needs to know where |"
echo -e "| you want your printer configuration to be. |"
blank_line
echo -e "| Please specify a folder where your Klipper configu- |"
echo -e "| ration is stored or, if you don't have one yet, in |"
echo -e "| which it should be saved after the installation. |"
bottom_border
change_klipper_cfg_path
fi
}
change_klipper_cfg_path(){
source_kiauh_ini
old_klipper_cfg_loc="$klipper_cfg_loc"
EXAMPLE_FOLDER=$(printf "%s/your_config_folder" "${HOME}")
while true; do
top_border
echo -e "| ${red}IMPORTANT:${default} |"
echo -e "| Please enter the new path in the following format: |"
printf "| ${yellow}%-51s${default} |\n" "$EXAMPLE_FOLDER"
blank_line
echo -e "| By default 'klipper_config' is recommended! |"
bottom_border
echo
echo -e "${cyan}###### Please set the Klipper config directory:${default} "
if [ -z "$old_klipper_cfg_loc" ]; then
read -e -i "/home/${USER}/klipper_config" -e new_klipper_cfg_loc
else
read -e -i "$old_klipper_cfg_loc" -e new_klipper_cfg_loc
fi
echo
read -p "${cyan}###### Set config directory to '${yellow}$new_klipper_cfg_loc${cyan}' ? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
### backup the old config dir
backup_klipper_config_dir
### write new location to kiauh.ini
sed -i "s|klipper_cfg_loc=$old_klipper_cfg_loc|klipper_cfg_loc=$new_klipper_cfg_loc|" $INI_FILE
status_msg "Directory set to '$new_klipper_cfg_loc'!"
### write new location to klipper and moonraker service
set_klipper_cfg_path
echo; ok_msg "Config directory changed!"
break;;
N|n|No|no)
echo -e "###### > No"
change_klipper_cfg_path
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
###? if path was changed in 'change_klipper_cfg_path', we need to edit the service files
###? and set the new path. after that, rename the old folder and reload service units.
###! users shouldn't try and move the files into subfolders with this function! as the mv command will fail
###! but the new path still gets written to the service files. if they really need to, they need to move all
###! config files or printer folder into that subfolder (still not recommended!)
set_klipper_cfg_path(){
### stop services
klipper_service "stop" && moonraker_service "stop"
### rename the klipper config folder
if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then
status_msg "Renaming '$old_klipper_cfg_loc' to '$new_klipper_cfg_loc'!"; echo
mv -v "$old_klipper_cfg_loc" "$new_klipper_cfg_loc" && ok_msg "Done!"
fi
### handle single klipper instance service file
if [ -f /etc/systemd/system/klipper.service ]; then
status_msg "Configuring Klipper for new path ..."
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer.cfg|$new_klipper_cfg_loc/printer.cfg|" /etc/systemd/system/klipper.service
ok_msg "OK!"
fi
### handle multi klipper instance service file
if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; then
status_msg "Configuring Klipper for new path ..."
for service in $(find /etc/systemd/system/klipper-*.service); do
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer_|$new_klipper_cfg_loc/printer_|" $service
done
ok_msg "OK!"
fi
### handle single moonraker instance service and moonraker.conf file
if [ -f /etc/systemd/system/moonraker.service ]; then
status_msg "Configuring Moonraker for new path ..."
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/moonraker.conf|$new_klipper_cfg_loc/moonraker.conf|" /etc/systemd/system/moonraker.service
### replace old file path with new one in moonraker.conf
sed -i "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
ok_msg "OK!"
fi
### handle multi moonraker instance service file
if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then
status_msg "Configuring Moonraker for new path ..."
for service in $(find /etc/systemd/system/moonraker-*.service); do
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer_|$new_klipper_cfg_loc/printer_|" $service
done
### replace old file path with new one in moonraker.conf
for moonraker_conf in $(find $new_klipper_cfg_loc/printer_*/moonraker.conf); do
loc=$(echo "$moonraker_conf" | rev | cut -d"/" -f2- | rev)
sed -i "/config_path:/ s|config_path:.*|config_path: $loc|" $moonraker_conf
done
ok_msg "OK!"
fi
### reloading units
sudo systemctl daemon-reload
### restart services
klipper_service "restart" && moonraker_service "restart"
}
source_kiauh_ini(){
source $INI_FILE
}
klipper_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Klipper Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 klipper-$INSTANCE && ok_msg "Klipper Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper.service")" ]; then
status_msg "$ACTION2 Klipper Service ..."
sudo systemctl $1 klipper && ok_msg "Klipper Service $ACTION1!"
fi
}
moonraker_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Moonraker Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 moonraker-$INSTANCE && ok_msg "Moonraker Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker.service")" ]; then
status_msg "$ACTION2 Moonraker Service ..."
sudo systemctl $1 moonraker && ok_msg "Moonraker Service $ACTION1!"
fi
}
dwc_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if ls /etc/systemd/system/dwc-*.service 2>/dev/null 1>&2; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT DWC-for-Klipper-Socket Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 dwc-$INSTANCE && ok_msg "DWC-for-Klipper-Socket Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc.service")" ]; then
status_msg "$ACTION2 DWC-for-Klipper-Socket Service ..."
sudo systemctl $1 dwc && ok_msg "DWC-for-Klipper-Socket Service $ACTION1!"
fi
}
octoprint_service(){
### set a variable for the ok and status messages
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling"
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling"
if ls /etc/systemd/system/octoprint-*.service 2>/dev/null 1>&2; then
INSTANCE=1
INSTANCE_COUNT=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l)
status_msg "$ACTION2 $INSTANCE_COUNT OctoPrint Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 octoprint-$INSTANCE && ok_msg "OctoPrint Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-unit-files | grep -E "octoprint.*")" ]; then
status_msg "$ACTION2 OctoPrint Service ..."
sudo systemctl $1 octoprint && ok_msg "OctoPrint Service $ACTION1!"
fi
}
toggle_octoprint_service(){
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
octoprint_service "stop"
octoprint_service "disable"
sleep 2
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
octoprint_service "enable"
octoprint_service "start"
sleep 2
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
else
ERROR_MSG=" You cannot activate a service that does not exist!"
fi
}
read_octoprint_service_status(){
unset OPRINT_SERVICE_STATUS
if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
else
OPRINT_SERVICE_STATUS="${green}[Enable]${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(){
klipper_service "stop"
status_msg "Copy 'gcode_shell_command.py' to $KLIPPER_DIR/klippy/extras"
cp ${SRCDIR}/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|"")
status_msg "Copy shell_command.cfg ..."
### create a backup of the config folder
backup_klipper_config_dir
### handle single printer.cfg
if [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/shell_command.cfg ]; then
### copy shell_command.cfg to config location
cp ${SRCDIR}/kiauh/resources/shell_command.cfg $klipper_cfg_loc
ok_msg "$klipper_cfg_loc/shell_command.cfg created!"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" $klipper_cfg_loc/printer.cfg
fi
### handle multi printer.cfg
if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then
for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do
path=$(echo $config | rev | cut -d"/" -f2- | rev)
if [ ! -f $path/shell_command.cfg ]; then
### copy shell_command.cfg to config location
cp ${SRCDIR}/kiauh/resources/shell_command.cfg $path
ok_msg "$path/shell_command.cfg created!"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" $path/printer.cfg
fi
done
fi
break;;
N|n|No|no)
break;;
esac
done
ok_msg "Shell command extension installed!"
klipper_service "restart"
}
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
#including the kiauh.cfg into printer.cfg if not already done
if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Writing [include kiauh.cfg] to printer.cfg ..."
sed -i '1 i ##### AUTOCREATED BY KIAUH #####\n[include kiauh.cfg]' $PRINTER_CFG
fi
ok_msg "Done!"
}
init_ini(){
### copy an existing kiauh.ini to its new location to keep all possible saved values
if [ -f ${SRCDIR}/kiauh/kiauh.ini ] && [ ! -f $INI_FILE ]; then
cp ${SRCDIR}/kiauh/kiauh.ini $INI_FILE
fi
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
###add empty klipper config path if missing
if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then
echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE
fi
}

View File

@@ -0,0 +1,123 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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_config_dir
local configs regex path
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
for cfg in ${configs}; 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
}

95
scripts/globals.sh Normal file
View File

@@ -0,0 +1,95 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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"
#================= MOONRAKER ==================#
MOONRAKER_ENV="${HOME}/moonraker-env"
MOONRAKER_DIR="${HOME}/moonraker"
MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
#================= MAINSAIL ===================#
MAINSAIL_DIR="${HOME}/mainsail"
#================== FLUIDD ====================#
FLUIDD_DIR="${HOME}/fluidd"
#=============== 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"
#=============== MOONRAKER-OBICO ================#
MOONRAKER_OBICO_DIR="${HOME}/moonraker-obico"
MOONRAKER_OBICO_REPO="https://github.com/TheSpaghettiDetective/moonraker-obico.git"
#=============== OCTOEVERYWHERE ================#
OCTOEVERYWHERE_ENV="${HOME}/octoeverywhere-env"
OCTOEVERYWHERE_DIR="${HOME}/octoeverywhere"
OCTOEVERYWHERE_REPO="https://github.com/QuinnDamerell/OctoPrint-OctoEverywhere.git"
#=============== Crowsnest ================#
CROWSNEST_DIR="${HOME}/crowsnest"
CROWSNEST_REPO="https://github.com/mainsail-crew/crowsnest.git"
#=============== Mobileraker ================#
MOBILERAKER_ENV="${HOME}/mobileraker-env"
MOBILERAKER_DIR="${HOME}/mobileraker_companion"
MOBILERAKER_REPO="https://github.com/Clon1998/mobileraker_companion.git"
#=============== OCTOAPP ================#
OCTOAPP_ENV="${HOME}/octoapp-env"
OCTOAPP_DIR="${HOME}/octoapp"
OCTOAPP_REPO="https://github.com/crysxd/OctoApp-Plugin.git"
#=============== Spoolman ================#
SPOOLMAN_DIR="${HOME}/Spoolman"
SPOOLMAN_DB_DIR="${HOME}/.local/share/spoolman"
SPOOLMAN_REPO="https://api.github.com/repos/Donkie/Spoolman/releases/latest"
}

View File

@@ -1,390 +0,0 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
DWC_ENV="${HOME}/dwc-env"
DWC2_DIR="${HOME}/duetwebcontrol"
system_check_dwc(){
### check system for an installed octoprint service
if systemctl is-enabled octoprint.service -q 2>/dev/null; then
OCTOPRINT_ENABLED="true"
fi
}
dwc_setup_dialog(){
status_msg "Initializing Duet Web Control installation ..."
### check system for several requirements before initializing the dwc2 installation
system_check_dwc
### check for existing klipper service installations
if [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
fi
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### initial config path check
check_klipper_cfg_path
### ask user how to handle OctoPrint, Haproxy and Lighttpd
process_octoprint_dialog_dwc2
process_haproxy_lighttpd_dialog
### instance confirmation dialog
while true; do
echo
top_border
if [ $INSTANCE_COUNT -gt 1 ]; then
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
else
echo -e "| 1 Klipper instance was found! | "
fi
echo -e "| You need one DWC instance per Klipper instance. | "
bottom_border
echo
read -p "${cyan}###### Create $INSTANCE_COUNT DWC instances? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT DWC instances ..."
dwc_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting DWC setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
###TODO for future: should be some kind of shared function between moonraker and this installer, since it does the same
process_octoprint_dialog_dwc2(){
### ask user to disable octoprint when its service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
hr
echo -e "| You might consider disabling the OctoPrint service, |"
echo -e "| since an active OctoPrint service may lead to unex- |"
echo -e "| pected behavior of Duet Web Control for Klipper. |"
bottom_border
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Stopping OctoPrint ..."
sudo systemctl stop octoprint && ok_msg "OctoPrint service stopped!"
status_msg "Disabling OctoPrint ..."
sudo systemctl disable octoprint && ok_msg "OctoPrint service disabled!"
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
status_msg "Installation will start now! Please wait ..."
}
#############################################################
#############################################################
get_dwc_ver(){
DWC2_VERSION=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4)
}
dwc_setup(){
### get printer config directory
source_kiauh_ini
DWC_CONF_LOC="$klipper_cfg_loc"
### check dependencies
dep=(git wget gzip tar curl)
dependency_check
### step 1: get dwc2-for-klipper
status_msg "Downloading DWC2-for-Klipper-Socket ..."
cd ${HOME} && git clone $DWC2FK_REPO
ok_msg "Download complete!"
### step 2: install dwc2 dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_dwc_packages
create_dwc_virtualenv
### step 3: create dwc2.cfg folder and dwc2.cfg
[ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC
dwc_cfg_creation
### step 4: download Duet Web Control
download_dwc_webui
### step 5: create dwc instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_dwc_instance
else
#create_multi_dwc_instance
create_multi_dwc_instance
fi
}
download_dwc_webui(){
#get Duet Web Control
GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4)
status_msg "Downloading DWC2 Web UI ..."
[ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR
cd $DWC2_DIR && wget $GET_DWC2_URL
ok_msg "Download complete!"
status_msg "Extracting 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 "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!" && ok_msg "Duet Web Control installed!"
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
install_dwc_packages()
{
PKGLIST="python3-virtualenv python3-dev python3-tornado"
# Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
# Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGLIST}
}
create_dwc_virtualenv()
{
status_msg "Installing python virtual environment..."
# Create virtualenv if it doesn't already exist
[ ! -d ${DWC_ENV} ] && virtualenv -p /usr/bin/python3 ${DWC_ENV}
# Install/update dependencies
${DWC_ENV}/bin/pip install tornado==6.0.4
}
create_single_dwc_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC
[Unit]
Description=DuetWebControl
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=${USER}
RemainAfterExit=yes
ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG}
Restart=always
RestartSec=10
DWC
}
create_multi_dwc_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc-$INSTANCE.service" << DWC
[Unit]
Description=DuetWebControl
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=${USER}
RemainAfterExit=yes
ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG}
Restart=always
RestartSec=10
DWC
}
create_single_dwcfk_cfg(){
### create single instance config file
/bin/sh -c "cat > $DWC_CONF_LOC/dwc2.cfg" << DWCCFG
[webserver]
listen_adress: 0.0.0.0
web_root: ${HOME}/duetwebcontrol
port: ${PORT}
[reply_filters]
regex:
max_accel: \d+.\d+
max_accel_to_decel: \d+.\d+
square_corner_velocity: \d+.\d+
max_velocity: \d+.\d+
DWCCFG
}
create_multi_dwcfk_cfg(){
### create single instance config file
/bin/sh -c "cat > $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" << DWCCFG
[webserver]
listen_adress: 0.0.0.0
web_root: ${HOME}/duetwebcontrol
port: ${PORT}
[reply_filters]
regex:
max_accel: \d+.\d+
max_accel_to_decel: \d+.\d+
square_corner_velocity: \d+.\d+
max_velocity: \d+.\d+
DWCCFG
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
print_dwc_ip_list(){
i=1
for ip in ${dwc_ip_list[@]}; do
echo -e " ${cyan}● Instance $i:${default} $ip"
i=$((i + 1))
done
}
create_single_dwc_instance(){
status_msg "Setting up 1 Duet Web Control instance ..."
### single instance variables
DWC_LOG=/tmp/dwc.log
DWC_CFG="$DWC_CONF_LOC/dwc2.cfg"
### create instance
status_msg "Creating single DWC instance ..."
create_single_dwc_startscript
### enable instance
sudo systemctl enable dwc.service
ok_msg "Single DWC instance created!"
### launching instance
status_msg "Launching DWC instance ..."
sudo systemctl start dwc
### confirm message
CONFIRM_MSG="Single DWC instance has been set up!"
print_msg && clear_msg
### display moonraker ip to the user
print_dwc_ip_list; echo
}
create_multi_dwc_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
DWC_LOG=/tmp/dwc-$INSTANCE.log
DWC_CFG="$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_dwc_startscript
### enable instance
sudo systemctl enable dwc-$INSTANCE.service
ok_msg "DWC instance $INSTANCE created!"
### launching instance
status_msg "Launching DWC instance $INSTANCE ..."
sudo systemctl start dwc-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT DWC instances has been set up!"
print_msg && clear_msg
### display moonraker ip to the user
print_dwc_ip_list; echo
}
dwc_cfg_creation(){
### default dwc port
DEFAULT_PORT=4750
### get printer config directory
source_kiauh_ini
DWC_CONF_LOC="$klipper_cfg_loc"
### reset instances back to 1 again
INSTANCE=1
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
dwc_ip_list=()
### create single instance dwc2.cfg file
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
### set port
PORT=$DEFAULT_PORT
### write the ip and port to the ip list for displaying it later to the user
dwc_ip_list+=("$HOSTNAME:$PORT")
status_msg "Creating dwc2.cfg in $DWC_CONF_LOC"
[ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC
if [ ! -f $DWC_CONF_LOC/dwc2.cfg ]; then
create_single_dwcfk_cfg && ok_msg "dwc2.cfg created!"
else
warn_msg "There is already a file called 'dwc2.cfg'!"
warn_msg "Skipping..."
fi
### create multi instance moonraker.conf files
else
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### set each instance to its own port
PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1)
### write the ip and port to the ip list for displaying it later to the user
dwc_ip_list+=("$HOSTNAME:$PORT")
### start the creation of each instance
status_msg "Creating dwc2.cfg for instance #$INSTANCE"
[ ! -d $DWC_CONF_LOC/printer_$INSTANCE ] && mkdir -p $DWC_CONF_LOC/printer_$INSTANCE
if [ ! -f $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg ]; then
create_multi_dwcfk_cfg && ok_msg "dwc2.cfg created!"
else
warn_msg "There is already a file called 'dwc2.cfg'!"
warn_msg "Skipping..."
fi
### raise instance counter by 1
INSTANCE=$(expr $INSTANCE + 1)
done
fi
}

View File

@@ -1,371 +0,0 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
KLIPPY_ENV="${HOME}/klippy-env"
KLIPPER_DIR="${HOME}/klipper"
klipper_setup_dialog(){
status_msg "Initializing Klipper installation ..."
### check for existing klipper service installations
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
ERROR_MSG="At least one Klipper service is already installed!\n Please remove Klipper first, before installing it again." && return 0
fi
### initial printer.cfg path check
check_klipper_cfg_path
### ask for amount of instances to create
while true; do
echo
read -p "${cyan}###### How many Klipper instances do you want to set up?:${default} " INSTANCE_COUNT
echo
if [ $INSTANCE_COUNT == 1 ]; then
read -p "${cyan}###### Create $INSTANCE_COUNT single instance? (Y/n):${default} " yn
else
read -p "${cyan}###### Create $INSTANCE_COUNT instances? (Y/n):${default} " yn
fi
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT Klipper instances ..."
klipper_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting Klipper setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
install_klipper_packages(){
### Packages for python cffi
PKGLIST="python-virtualenv virtualenv python-dev libffi-dev build-essential"
### kconfig requirements
PKGLIST="${PKGLIST} libncurses-dev"
### hub-ctrl
PKGLIST="${PKGLIST} libusb-dev"
### AVR chip installation and building
PKGLIST="${PKGLIST} avrdude gcc-avr binutils-avr avr-libc"
### ARM chip installation and building
PKGLIST="${PKGLIST} stm32flash libnewlib-arm-none-eabi"
PKGLIST="${PKGLIST} gcc-arm-none-eabi binutils-arm-none-eabi libusb-1.0"
### dbus requirement for DietPi
PKGLIST="${PKGLIST} dbus"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGLIST}
}
create_klipper_virtualenv(){
status_msg "Installing python virtual environment..."
# Create virtualenv if it doesn't already exist
[ ! -d ${KLIPPY_ENV} ] && virtualenv -p python2 ${KLIPPY_ENV}
# Install/update dependencies
${KLIPPY_ENV}/bin/pip install -r ${KLIPPER_DIR}/scripts/klippy-requirements.txt
}
create_single_klipper_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << SINGLE_STARTSCRIPT
#Systemd service file for klipper
[Unit]
Description=Starts klipper on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=$USER
RemainAfterExit=yes
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
Restart=always
RestartSec=10
SINGLE_STARTSCRIPT
}
create_multi_klipper_startscript(){
### create multi instance systemd service file
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << MULTI_STARTSCRIPT
#Systemd service file for klipper
[Unit]
Description=Starts klipper instance $INSTANCE on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=$USER
RemainAfterExit=yes
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -I ${TMP_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
Restart=always
RestartSec=10
MULTI_STARTSCRIPT
}
create_minimal_printer_cfg(){
/bin/sh -c "cat > $1" << MINIMAL_CFG
[mcu]
serial: /dev/serial/by-id/<your-mcu-id>
[pause_resume]
[display_status]
[virtual_sdcard]
path: ~/gcode_files
[printer]
kinematics: none
max_velocity: 1000
max_accel: 1000
MINIMAL_CFG
}
klipper_setup(){
### get printer config directory
source_kiauh_ini
PRINTER_CFG_LOC="$klipper_cfg_loc"
### clone klipper
cd ${HOME}
status_msg "Downloading Klipper ..."
[ -d $KLIPPER_DIR ] && rm -rf $KLIPPER_DIR
git clone $KLIPPER_REPO
status_msg "Download complete!"
### install klipper dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_klipper_packages
create_klipper_virtualenv
### create shared gcode_files folder
[ ! -d ${HOME}/gcode_files ] && mkdir -p ${HOME}/gcode_files
### create shared config folder
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
### create klipper instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_klipper_instance
else
create_multi_klipper_instance
fi
}
create_single_klipper_instance(){
status_msg "Setting up 1 Klipper instance ..."
### single instance variables
KLIPPER_LOG=/tmp/klippy.log
KLIPPY_UDS=/tmp/klippy_uds
PRINTER_CFG="$PRINTER_CFG_LOC/printer.cfg"
### create instance
status_msg "Creating single Klipper instance ..."
status_msg "Installing system start script ..."
create_single_klipper_startscript
### create printer config directory if missing
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
### create basic configs if missing
[ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG"
### enable instance
sudo systemctl enable klipper.service
ok_msg "Single Klipper instance created!"
### launching instance
status_msg "Launching Klipper instance ..."
sudo systemctl start klipper
### confirm message
CONFIRM_MSG="Single Klipper instance has been set up!"
print_msg && clear_msg
}
create_multi_klipper_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of Klipper ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
KLIPPER_LOG=/tmp/klippy-$INSTANCE.log
KLIPPY_UDS=/tmp/klippy_uds-$INSTANCE
TMP_PRINTER=/tmp/printer-$INSTANCE
PRINTER_CFG="$PRINTER_CFG_LOC/printer_$INSTANCE/printer.cfg"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_klipper_startscript
### create printer config directory if missing
[ ! -d $PRINTER_CFG_LOC/printer_$INSTANCE ] && mkdir -p $PRINTER_CFG_LOC/printer_$INSTANCE
### create basic configs if missing
[ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG"
### enable instance
sudo systemctl enable klipper-$INSTANCE.service
ok_msg "Klipper instance $INSTANCE created!"
### launching instance
status_msg "Launching Klipper instance $INSTANCE ..."
sudo systemctl start klipper-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
print_msg && clear_msg
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
flash_routine(){
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"
get_mcu_id
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
flash_mcu(){
if [ ${#mcu_list[@]} -ge 1 ]; then
top_border
echo -e "| ${red}!!! IMPORTANT WARNING !!!${default} |"
hr
echo -e "| Make sure, that you select the correct ID for the MCU |"
echo -e "| you have build the firmware for in the previous step! |"
blank_line
echo -e "| This is especially important if you use different MCU |"
echo -e "| models which each require their own firmware! |"
blank_line
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
bottom_border
### list all mcus
i=1
for mcu in ${mcu_list[@]}; do
echo -e "$i) ${cyan}$mcu${default}"
i=$(expr $i + 1)
done
while true; do
echo
read -p "${cyan}###### Please select the ID for flashing:${default} " selected_id
mcu_index=$(echo $((selected_id - 1)))
echo -e "\nYou have selected to flash:\n● MCU #$selected_id: ${mcu_list[$mcu_index]}\n"
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Flashing ${mcu_list[$mcu_index]} ..."
klipper_service "stop"
if ! make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" ; then
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
else
ok_msg "Flashing successfull!"
fi
klipper_service "start"
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
break
done
fi
}
build_fw(){
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
}
### grab the mcu id
get_mcu_id(){
echo
top_border
echo -e "| Please make sure your MCU is connected to the Pi! |"
echo -e "| If the MCU is not connected yet, connect it now. |"
bottom_border
while true; do
echo -e "${cyan}"
read -p "###### Press any key to continue ... " yn
echo -e "${default}"
case "$yn" in
*)
break;;
esac
done
status_msg "Identifying the ID of your MCU ..."
sleep 2
unset MCU_ID
### if there are devices found, continue, else show warn message
if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then
mcu_count=1
mcu_list=()
status_msg "The ID of your printers MCU is:"
### loop over the IDs, write every ID as an item of the array 'mcu_list'
for mcu in /dev/serial/by-id/*; do
declare "mcu_id_$mcu_count"="$mcu"
mcu_id="mcu_id_$mcu_count"
mcu_list+=("${!mcu_id}")
echo " ● MCU #$mcu_count: ${cyan}$mcu${default}"
mcu_count=$(expr $mcu_count + 1)
done
unset mcu_count
else
warn_msg "Could not retrieve ID!"
warn_msg "Printer not plugged in or not detectable!"
fi
}

View File

@@ -1,277 +0,0 @@
check_moonraker(){
status_msg "Checking for Moonraker service ..."
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
moonraker_chk_ok="true"
else
moonraker_chk_ok="false"
fi
}
get_user_selection_kiauh_macros(){
#ask user for webui default macros
while true; do
unset ADD_KIAUH_MACROS
echo
top_border
echo -e "| It is recommended to have some important macros set |"
echo -e "| up in your printer configuration to have $1|"
echo -e "| fully functional and working. |"
blank_line
echo -e "| Those macros are: |"
echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |"
echo -e "| ${cyan}● [gcode_macro RESUME]${default} |"
echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |"
blank_line
echo -e "| If you already have these macros in your config file |"
echo -e "| you can skip this step and choose 'no'. |"
echo -e "| Otherwise you should consider to answer with 'yes' to |"
echo -e "| add the recommended example macros to your config. |"
bottom_border
read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
ADD_KIAUH_MACROS="true"
break;;
N|n|No|no)
echo -e "###### > No"
ADD_KIAUH_MACROS="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
install_webui(){
### check if moonraker is already installed
check_moonraker
[ $1 == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail "
[ $1 == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd "
### exit mainsail/fluidd setup if moonraker not found
if [ $moonraker_chk_ok = "false" ]; then
ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!"
print_msg && clear_msg && return 0
else
ok_msg "Moonraker service found!"
status_msg "Initializing $IF_NAME1 installation ..."
fi
### check for other enabled web interfaces
unset SET_LISTEN_PORT
detect_enabled_sites
### check if another site already listens to port 80
$1_port_check
### ask user to install the recommended webinterface macros
get_user_selection_kiauh_macros "$IF_NAME2"
### creating the mainsail/fluidd nginx cfg
set_nginx_cfg "$1"
### copy the kiauh_macros.cfg to the config location
install_kiauh_macros
### install mainsail/fluidd
$1_setup
}
install_kiauh_macros(){
source_kiauh_ini
### copy kiauh_macros.cfg
if [ "$ADD_KIAUH_MACROS" = "true" ]; then
### create a backup of the config folder
backup_klipper_config_dir
### handle multi printer.cfg
if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then
for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do
path=$(echo $config | rev | cut -d"/" -f2- | rev)
if [ ! -f $path/kiauh_macros.cfg ]; then
### copy kiauh_macros.cfg to config location
cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $path
ok_msg "$path/kiauh_macros.cfg created!"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg
fi
done
### handle single printer.cfg
elif [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/kiauh_macros.cfg ]; then
### copy kiauh_macros.cfg to config location
cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc
ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!"
### write the include to the very first line of the printer.cfg
sed -i "1 i [include kiauh_macros.cfg]" $klipper_cfg_loc/printer.cfg
fi
### restart klipper service to parse the modified printer.cfg
klipper_service "restart"
fi
}
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/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
}
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/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
}
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 webinterfaces and do ${red}NOT${default} |"
echo -e "| use ports in the range of 4750 or above! |"
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 webinterfaces and do ${red}NOT${default} |"
echo -e "| use ports in the range of 4750 or above! |"
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 | head -1)
}
get_fluidd_ver(){
FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | head -1)
}
mainsail_setup(){
### get mainsail download url
MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1)
### remove existing and create fresh mainsail folder, then download mainsail
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
status_msg "Downloading Mainsail $MAINSAIL_VERSION ..."
wget $MAINSAIL_DL_URL && ok_msg "Download complete!"
### 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!"
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode
if [ $(ls /etc/systemd/system/moonraker* | wc -l) -gt 1 ]; then
enable_mainsail_remotemode
fi
ok_msg "Mainsail installation complete!\n"
}
enable_mainsail_remotemode(){
rm -f $MAINSAIL_DIR/config.json
echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json
}
fluidd_setup(){
### get fluidd download url
FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4)
### remove existing and create fresh fluidd folder, then download fluidd
[ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR
mkdir $FLUIDD_DIR && cd $FLUIDD_DIR
status_msg "Downloading Fluidd $FLUIDD_VERSION ..."
wget $FLUIDD_DL_URL && ok_msg "Download complete!"
### 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 "Fluidd installation complete!"
echo
}

View File

@@ -1,85 +0,0 @@
install_klipperscreen(){
python3_check
if [ $py_chk_ok = "true" ]; then
source_kiauh_ini
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(){
source_kiauh_ini
if [ ! -e $klipper_cfg_loc/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 $klipper_cfg_loc/KlipperScreen.log ]; then
status_msg "Creating KlipperScreen.log symlink ..."
ln -s /tmp/KlipperScreen.log $klipper_cfg_loc
ok_msg "Symlink created!"
fi
}

View File

@@ -1,598 +0,0 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
MOONRAKER_ENV="${HOME}/moonraker-env"
MOONRAKER_DIR="${HOME}/moonraker"
system_check_moonraker(){
### python 3 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
warn_msg "Python version not ok!"
py_chk_ok="false"
fi
### check system for an installed and enabled octoprint service
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
OCTOPRINT_ENABLED="true"
fi
### check system for an installed haproxy service
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true"
fi
### check system for an installed lighttpd service
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
LIGHTTPD_FOUND="true"
fi
}
moonraker_setup_dialog(){
status_msg "Initializing Moonraker installation ..."
### check system for several requirements before initializing the moonraker installation
system_check_moonraker
### exit moonraker setup if python version is not ok
if [ $py_chk_ok = "false" ]; then
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
print_msg && clear_msg && return 0
fi
### check for existing moonraker service installations
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
ERROR_MSG="At least one Moonraker service is already installed!" && return 0
fi
### check for existing klipper service installations
if [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
fi
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### initial moonraker.conf path check
check_klipper_cfg_path
### ask user how to handle OctoPrint, Haproxy and Lighttpd
process_octoprint_dialog
process_haproxy_lighttpd_dialog
### instance confirmation dialog
while true; do
echo
top_border
if [ $INSTANCE_COUNT -gt 1 ]; then
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
else
echo -e "| 1 Klipper instance was found! | "
fi
echo -e "| You need one Moonraker instance per Klipper instance. | "
bottom_border
echo
read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT Moonraker instances ..."
moonraker_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting Moonraker setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
moonraker_setup(){
### get printer config directory
source_kiauh_ini
MOONRAKER_CONF_LOC="$klipper_cfg_loc"
### checking dependencies
dep=(wget curl unzip dfu-util)
### additional deps for kiauh compatibility for armbian
dep+=(libjpeg-dev zlib1g-dev)
dependency_check
### step 1: clone moonraker
status_msg "Downloading Moonraker ..."
### force remove existing moonraker dir and clone into fresh moonraker dir
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
cd ${HOME} && git clone $MOONRAKER_REPO
ok_msg "Download complete!"
### step 2: install moonraker dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_moonraker_packages
create_moonraker_virtualenv
### step 3: create moonraker.conf folder and moonraker.confs
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
moonraker_conf_creation
### step 4: set up moonrakers nginx configs
setup_moonraker_nginx_cfg
### step 5: process possible disruptive services
process_haproxy_lighttpd_services
### step 6: create final moonraker instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_moonraker_instance
else
create_multi_moonraker_instance
### step 6.5: enable mainsails remoteMode if its already installed
if [ -d $MAINSAIL_DIR ]; then
enable_mainsail_remotemode
fi
fi
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
install_moonraker_packages(){
PKGLIST="python3-virtualenv python3-dev nginx libopenjp2-7 python3-libgpiod"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGLIST}
}
create_moonraker_virtualenv(){
status_msg "Installing python virtual environment..."
### If venv exists and user prompts a rebuild, then do so
if [ -d ${MOONRAKER_ENV} ] && [ $REBUILD_ENV = "y" ]; then
status_msg "Removing old virtualenv"
rm -rf ${MOONRAKER_ENV}
fi
[ ! -d ${MOONRAKER_ENV} ] && virtualenv -p /usr/bin/python3 --system-site-packages ${MOONRAKER_ENV}
### Install/update dependencies
${MOONRAKER_ENV}/bin/pip install -r ${MOONRAKER_DIR}/scripts/moonraker-requirements.txt
}
create_single_moonraker_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/moonraker.service" << EOF
#Systemd service file for moonraker
[Unit]
Description=Starts Moonraker on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=${USER}
RemainAfterExit=yes
ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF}
Restart=always
RestartSec=10
EOF
}
create_multi_moonraker_startscript(){
### create multi instance systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/moonraker-$INSTANCE.service" << EOF
#Systemd service file for moonraker
[Unit]
Description=Starts Moonraker instance $INSTANCE on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=${USER}
RemainAfterExit=yes
ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF}
Restart=always
RestartSec=10
EOF
}
create_single_moonraker_conf(){
HOSTNAME=$(hostname -I | cut -d" " -f1)
LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF
[server]
host: 0.0.0.0
port: $PORT
enable_debug_logging: True
config_path: $PRINTER_CFG_LOC
klippy_uds_address: /tmp/klippy_uds
[authorization]
enabled: True
api_key_file: ~/.moonraker_api_key
trusted_clients:
127.0.0.1
$LOCAL_NETWORK
::1/128
FE80::/10
cors_domains:
http://*.local
http://my.mainsail.xyz
https://my.mainsail.xyz
http://app.fluidd.xyz
https://app.fluidd.xyz
http://$HOSTNAME
http://$HOSTNAME:*
[update_manager]
[update_manager client mainsail]
type: web
repo: meteyou/mainsail
path: ~/mainsail
[update_manager client fluidd]
type: web
repo: cadriel/fluidd
path: ~/fluidd
#[update_manager client KlipperScreen]
#type: git_repo
#path: /home/${HOME}/KlipperScreen
#origin: https://github.com/jordanruthe/KlipperScreen.git
#env: /home/${HOME}/.KlipperScreen-env/bin/python
#requirements: scripts/KlipperScreen-requirements.txt
#install_script: scripts/KlipperScreen-install.sh
MOONRAKERCONF
}
create_multi_moonraker_conf(){
HOSTNAME=$(hostname -I | cut -d" " -f1)
LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF
[server]
host: 0.0.0.0
port: $PORT
enable_debug_logging: True
config_path: $PRINTER_CFG_LOC/printer_$INSTANCE
klippy_uds_address: /tmp/klippy_uds-$INSTANCE
[authorization]
enabled: True
api_key_file: ~/.moonraker_api_key
trusted_clients:
127.0.0.1
$LOCAL_NETWORK
::1/128
FE80::/10
cors_domains:
http://*.local
https://*.local
http://my.mainsail.xyz
https://my.mainsail.xyz
http://app.fluidd.xyz
https://app.fluidd.xyz
http://$HOSTNAME
http://$HOSTNAME:*
[update_manager]
[update_manager client mainsail]
type: web
repo: meteyou/mainsail
path: ~/mainsail
[update_manager client fluidd]
type: web
repo: cadriel/fluidd
path: ~/fluidd
#[update_manager client KlipperScreen]
#type: git_repo
#path: /home/${USER}/KlipperScreen
#origin: https://github.com/jordanruthe/KlipperScreen.git
#env: /home/${USER}/.KlipperScreen-env/bin/python
#requirements: scripts/KlipperScreen-requirements.txt
#install_script: scripts/KlipperScreen-install.sh
MOONRAKERCONF
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
print_mr_ip_list(){
i=1
for ip in ${mr_ip_list[@]}; do
echo -e " ${cyan}● Instance $i:${default} $ip"
i=$((i + 1))
done
}
create_single_moonraker_instance(){
status_msg "Setting up 1 Moonraker instance ..."
### single instance variables
MOONRAKER_LOG=/tmp/moonraker.log
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker.conf"
### create instance
status_msg "Creating single Moonraker instance ..."
create_single_moonraker_startscript
### enable instance
sudo systemctl enable moonraker.service
ok_msg "Single Moonraker instance created!"
### launching instance
status_msg "Launching Moonraker instance ..."
sudo systemctl start moonraker
### confirm message
CONFIRM_MSG="Single Moonraker instance has been set up!"
print_msg && clear_msg
### display moonraker ip to the user
print_mr_ip_list; echo
}
create_multi_moonraker_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of Moonraker ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_moonraker_startscript
### enable instance
sudo systemctl enable moonraker-$INSTANCE.service
ok_msg "Moonraker instance $INSTANCE created!"
### launching instance
status_msg "Launching Moonraker instance $INSTANCE ..."
sudo systemctl start moonraker-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
print_msg && clear_msg
### display all moonraker ips to the user
print_mr_ip_list; echo
}
setup_moonraker_nginx_cfg(){
get_date
### backup existing nginx configs
[ -f $NGINX_CONFD/upstreams.conf ] && sudo mv $NGINX_CONFD/upstreams.conf $NGINX_CONFD/$current_date_upstreams.conf
[ -f $NGINX_CONFD/common_vars.conf ] && sudo mv $NGINX_CONFD/common_vars.conf $NGINX_CONFD/$current_date_common_vars.conf
### copy nginx configs to target destination
if [ ! -f $NGINX_CONFD/upstreams.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/upstreams.conf $NGINX_CONFD
fi
if [ ! -f $NGINX_CONFD/common_vars.conf ]; then
sudo cp ${SRCDIR}/kiauh/resources/common_vars.conf $NGINX_CONFD
fi
}
moonraker_conf_creation(){
### default moonraker port
DEFAULT_PORT=7125
### get printer and moonraker config directory
source_kiauh_ini
PRINTER_CFG_LOC="$klipper_cfg_loc"
MOONRAKER_CONF_LOC="$klipper_cfg_loc"
### reset instances back to 1 again
INSTANCE=1
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
mr_ip_list=()
### create single instance moonraker.conf file
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
### set port
PORT=$DEFAULT_PORT
### write the ip and port to the ip list for displaying it later to the user
mr_ip_list+=("$HOSTNAME:$PORT")
status_msg "Creating moonraker.conf in $MOONRAKER_CONF_LOC"
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
if [ ! -f $MOONRAKER_CONF_LOC/moonraker.conf ]; then
create_single_moonraker_conf && ok_msg "moonraker.conf created!"
else
warn_msg "There is already a file called 'moonraker.conf'!"
warn_msg "Skipping..."
fi
### create multi instance moonraker.conf files
else
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### set each instance to its own port
PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1)
### write the ip and port to the ip list for displaying it later to the user
mr_ip_list+=("$HOSTNAME:$PORT")
### start the creation of each instance
status_msg "Creating moonraker.conf for instance #$INSTANCE"
[ ! -d $MOONRAKER_CONF_LOC/printer_$INSTANCE ] && mkdir -p $MOONRAKER_CONF_LOC/printer_$INSTANCE
if [ ! -f $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf ]; then
create_multi_moonraker_conf && ok_msg "moonraker.conf created!"
else
warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!"
warn_msg "Skipping..."
fi
### raise instance counter by 1
INSTANCE=$(expr $INSTANCE + 1)
done
fi
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
process_octoprint_dialog(){
#ask user to disable octoprint when its service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
hr
echo -e "| You might consider disabling the OctoPrint service, |"
echo -e "| since an active OctoPrint service may lead to unex- |"
echo -e "| pected behavior of the Klipper Webinterfaces. |"
bottom_border
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Stopping OctoPrint ..."
octoprint_service "stop" && ok_msg "OctoPrint service stopped!"
status_msg "Disabling OctoPrint ..."
octoprint_service "disable" && ok_msg "OctoPrint service disabled!"
break;;
N|n|No|no)
echo -e "###### > No"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}
process_haproxy_lighttpd_services(){
#handle haproxy service
if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo systemctl stop haproxy && ok_msg "Service stopped!"
fi
### disable haproxy
if [ "$DISABLE_HAPROXY" = "true" ]; then
status_msg "Disabling haproxy ..."
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
### remove haproxy
if [ "$REMOVE_HAPROXY" = "true" ]; then
status_msg "Removing haproxy ..."
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!"
fi
fi
fi
### handle lighttpd service
if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo systemctl stop lighttpd && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!"
### remove lighttpd
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
status_msg "Removing lighttpd ..."
sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!"
fi
fi
fi
}
process_haproxy_lighttpd_dialog(){
#notify user about haproxy or lighttpd services found and possible issues
if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then
while true; do
echo
top_border
echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |"
hr
if [ "$HAPROXY_FOUND" = "true" ]; then
echo -e "| ● haproxy |"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
echo -e "| ● lighttpd |"
fi
hr
echo -e "| Having those packages installed can lead to unwanted |"
echo -e "| behaviour. It is recommend to remove those packages. |"
echo -e "| |"
echo -e "| 1) Remove packages (recommend) |"
echo -e "| 2) Disable only (may cause issues) |"
echo -e "| ${red}3) Skip this step (not recommended)${default} |"
bottom_border
read -p "${cyan}###### Please choose:${default} " action
case "$action" in
1)
echo -e "###### > Remove packages"
if [ "$HAPROXY_FOUND" = "true" ]; then
DISABLE_HAPROXY="true"
REMOVE_HAPROXY="true"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
DISABLE_LIGHTTPD="true"
REMOVE_LIGHTTPD="true"
fi
break;;
2)
echo -e "###### > Disable only"
if [ "$HAPROXY_FOUND" = "true" ]; then
DISABLE_HAPROXY="true"
REMOVE_HAPROXY="false"
fi
if [ "$LIGHTTPD_FOUND" = "true" ]; then
DISABLE_LIGHTTPD="true"
REMOVE_LIGHTTPD="false"
fi
break;;
3)
echo -e "###### > Skip"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
}

View File

@@ -1,276 +0,0 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
OCTOPRINT_ENV="${HOME}/OctoPrint"
octoprint_setup_dialog(){
status_msg "Initializing OctoPrint installation ..."
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### instance confirmation dialog
while true; do
echo
top_border
if [ $INSTANCE_COUNT -gt 1 ]; then
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
else
echo -e "| 1 Klipper instance was found! | "
fi
echo -e "| You need one OctoPrint instance per Klipper instance. | "
bottom_border
echo
read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT OctoPrint instances ..."
octoprint_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting OctoPrint setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
octoprint_dependencies(){
dep=(
git
wget
python-pip
python-dev
libyaml-dev
build-essential
python-setuptools
python-virtualenv
)
dependency_check
}
octoprint_setup(){
### check and install all dependencies
octoprint_dependencies
### add user to usergroups and add reboot permissions
add_to_groups
add_reboot_permission
### create and activate the virtualenv
[ ! -d $OCTOPRINT_ENV ] && mkdir -p $OCTOPRINT_ENV
status_msg "Set up virtualenv ..."
cd $OCTOPRINT_ENV
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
### set up instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_octoprint_instance
else
create_multi_octoprint_instance
fi
}
add_to_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
}
create_single_octoprint_startscript(){
### create single instance systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint.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=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve
[Install]
WantedBy=multi-user.target
OCTOPRINT
}
create_multi_octoprint_startscript(){
### create multi instance systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint-$INSTANCE.service" << OCTOPRINT
[Unit]
Description=Starts OctoPrint instance $INSTANCE on startup
After=network-online.target
Wants=network-online.target
[Service]
Environment="LC_ALL=C.UTF-8"
Environment="LANG=C.UTF-8"
Type=simple
User=$USER
ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve
[Install]
WantedBy=multi-user.target
OCTOPRINT
}
create_config_yaml(){
### create multi instance config.yaml file
/bin/sh -c "cat > ${BASEDIR}/config.yaml" << CONFIGYAML
serial:
additionalPorts:
- ${TMP_PRINTER}
disconnectOnErrors: false
port: ${TMP_PRINTER}
server:
commands:
serverRestartCommand: ${RESTART_COMMAND}
systemRestartCommand: sudo shutdown -r now
systemShutdownCommand: sudo shutdown -h now
CONFIGYAML
}
create_single_octoprint_instance(){
status_msg "Setting up 1 OctoPrint instance ..."
### single instance variables
PORT=5000
BASEDIR="${HOME}/.octoprint"
TMP_PRINTER="/tmp/printer"
CONFIG_YAML="$BASEDIR/config.yaml"
RESTART_COMMAND="sudo service octoprint restart"
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
op_ip_list=()
### create instance
status_msg "Creating single OctoPrint instance ..."
create_single_octoprint_startscript
op_ip_list+=("$HOSTNAME:$PORT")
### create the config.yaml
if [ ! -f $BASEDIR/config.yaml ]; then
status_msg "Creating config.yaml ..."
[ ! -d $BASEDIR ] && mkdir $BASEDIR
create_config_yaml
ok_msg "Config created!"
fi
### enable instance
sudo systemctl enable octoprint.service
ok_msg "Single OctoPrint instance created!"
### launching instance
status_msg "Launching OctoPrint instance ..."
sudo systemctl start octoprint
### confirm message
CONFIRM_MSG="Single OctoPrint instance has been set up!"
print_msg && clear_msg
### display all octoprint ips to the user
print_op_ip_list; echo
}
create_multi_octoprint_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of OctoPrint ..."
### declare empty array for ips which get displayed to the user at the end of the setup
HOSTNAME=$(hostname -I | cut -d" " -f1)
op_ip_list=()
### default port
PORT=5000
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
BASEDIR="${HOME}/.octoprint-$INSTANCE"
TMP_PRINTER="/tmp/printer-$INSTANCE"
CONFIG_YAML="$BASEDIR/config.yaml"
RESTART_COMMAND="sudo service octoprint restart"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_octoprint_startscript
op_ip_list+=("$HOSTNAME:$PORT")
### create the config.yaml
if [ ! -f $BASEDIR/config.yaml ]; then
status_msg "Creating config.yaml for instance #$INSTANCE..."
[ ! -d $BASEDIR ] && mkdir $BASEDIR
create_config_yaml
ok_msg "Config #$INSTANCE created!"
fi
### enable instance
sudo systemctl enable octoprint-$INSTANCE.service
ok_msg "OctoPrint instance $INSTANCE created!"
### launching instance
status_msg "Launching OctoPrint instance $INSTANCE ..."
sudo systemctl start octoprint-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
### port +1
PORT=$(expr $PORT + 1)
done
### confirm message
CONFIRM_MSG="$INSTANCE_COUNT OctoPrint instances have been set up!"
print_msg && clear_msg
### display all moonraker ips to the user
print_op_ip_list; echo
}
add_reboot_permission(){
USER=${USER}
#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 ${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!"
}
print_op_ip_list(){
i=1
for ip in ${op_ip_list[@]}; do
echo -e " ${cyan}● Instance $i:${default} $ip"
i=$((i + 1))
done
}

664
scripts/klipper.sh Normal file
View File

@@ -0,0 +1,664 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#TODO (multi instance):
# if the klipper installer is started another time while other klipper
# instances are detected, ask if new instances should be added
#=================================================#
#================ INSTALL KLIPPER ================#
#=================================================#
###
# this function detects all installed klipper
# systemd instances and returns their absolute path
function klipper_systemd() {
local services
local blacklist
local ignore
local match
###
# any service that uses "klipper" in its own name but isn't a full klipper service must be blacklisted using
# this variable, otherwise they will be falsely recognized as klipper instances. E.g. "klipper-mcu.service"
# is not a klipper service, but related to klippers linux mcu, which also requires its own service file, hence
# it must be blacklisted.
blacklist="mcu"
ignore="${SYSTEMD}/klipper-(${blacklist}).service"
match="${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service"
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype awk ! -regex "${ignore}" -regex "${match}" | sort)
echo "${services}"
}
function start_klipper_setup() {
local klipper_systemd_services
local python_version
local instance_count
local instance_names
local use_custom_names
local input
local regex
local blacklist
local error
status_msg "Initializing Klipper installation ...\n"
### return early if klipper already exists
klipper_systemd_services=$(klipper_systemd)
if [[ -n ${klipper_systemd_services} ]]; then
error="At least one Klipper service is already installed:"
for s in ${klipper_systemd_services}; do
log_info "Found Klipper service: ${s}"
error="${error}\n ➔ ${s}"
done
fi
[[ -n ${error} ]] && print_error "${error}" && return
### user selection for python version
print_dialog_user_select_python_version
while true; do
read -p "${cyan}###### Select Python version:${white} " -i "1" -e input
case "${input}" in
1)
select_msg "Python 3.x\n"
python_version=3
break;;
2)
select_msg "Python 2.7\n"
python_version=2
break;;
B|b)
clear; install_menu; break;;
*)
error_msg "Invalid Input!\n";;
esac
done && input=""
### user selection for instance count
print_dialog_user_select_instance_count
regex="^[1-9][0-9]*$"
while [[ ! ${input} =~ ${regex} ]]; do
read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e input
if [[ ${input} =~ ${regex} ]]; then
instance_count="${input}"
select_msg "Instance count: ${instance_count}\n"
break
elif [[ ${input} == "B" || ${input} == "b" ]]; then
install_menu
else
error_msg "Invalid Input!\n"
fi
done && input=""
### user selection for custom names
use_custom_names="false"
if (( instance_count > 1 )); then
print_dialog_user_select_custom_name_bool
while true; do
read -p "${cyan}###### Assign custom names? (y/N):${white} " input
case "${input}" in
Y|y|Yes|yes)
select_msg "Yes\n"
use_custom_names="true"
break;;
N|n|No|no|"")
select_msg "No\n"
break;;
B|b)
clear; install_menu; break;;
*)
error_msg "Invalid Input!\n";;
esac
done && input=""
else
instance_names+=("printer")
fi
### user selection for setting the actual custom names
shopt -s nocasematch
if (( instance_count > 1 )) && [[ ${use_custom_names} == "true" ]]; then
local i
i=1
regex="^[0-9a-zA-Z]+$"
blacklist="mcu"
while [[ ! ${input} =~ ${regex} || ${input} =~ ${blacklist} || ${i} -le ${instance_count} ]]; do
read -p "${cyan}###### Name for instance #${i}:${white} " input
if [[ ${input} =~ ${blacklist} ]]; then
error_msg "Name not allowed! You are trying to use a reserved name."
elif [[ ${input} =~ ${regex} && ! ${input} =~ ${blacklist} ]]; then
select_msg "Name: ${input}\n"
if [[ ${input} =~ ^[0-9]+$ ]]; then
instance_names+=("printer_${input}")
else
instance_names+=("${input}")
fi
i=$(( i + 1 ))
else
error_msg "Invalid Input!\n"
fi
done && input=""
elif (( instance_count > 1 )) && [[ ${use_custom_names} == "false" ]]; then
for (( i=1; i <= instance_count; i++ )); do
instance_names+=("printer_${i}")
done
fi
shopt -u nocasematch
(( instance_count > 1 )) && status_msg "Installing ${instance_count} Klipper instances ..."
(( instance_count == 1 )) && status_msg "Installing single Klipper instance ..."
run_klipper_setup "${python_version}" "${instance_names[@]}"
}
function print_dialog_user_select_python_version() {
top_border
echo -e "| Please select your preferred Python version. | "
echo -e "| The recommended version is Python 3.x. | "
hr
echo -e "| 1) [Python 3.x] (recommended) | "
echo -e "| 2) [Python 2.7] ${yellow}(legacy)${white} | "
back_footer
}
function print_dialog_user_select_instance_count() {
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} |"
back_footer
}
function print_dialog_user_select_custom_name_bool() {
top_border
echo -e "| You can now assign a custom name to each instance. |"
echo -e "| If skipped, each instance will get an index assigned |"
echo -e "| in ascending order, starting at index '1'. |"
blank_line
echo -e "| Info: |"
echo -e "| Only alphanumeric characters for names are allowed! |"
back_footer
}
function run_klipper_setup() {
read_kiauh_ini "${FUNCNAME[0]}"
local python_version=${1}
local instance_names
local confirm
local custom_repo
local custom_branch
local dep
shift 1
read -r -a instance_names <<< "${@}"
custom_repo="${custom_klipper_repo}"
custom_branch="${custom_klipper_repo_branch}"
dep=(git)
### checking dependencies
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 klipper instances
for instance in "${instance_names[@]}"; do
create_klipper_service "${instance}"
done
### step 4: enable and start all instances
do_action_service "enable" "klipper"
do_action_service "start" "klipper"
### step 5: check for dialout group membership
check_usergroups
### confirm message
(( ${#instance_names[@]} == 1 )) && confirm="Klipper has been set up!"
(( ${#instance_names[@]} > 1 )) && confirm="${#instance_names[@]} Klipper instances have been set up!"
### finalizing the setup with writing instance names to the kiauh.ini
set_multi_instance_names
mask_disrupting_services
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 create_klipper_virtualenv() {
local python_version="${1}"
[[ -d ${KLIPPY_ENV} ]] && rm -rf "${KLIPPY_ENV}"
status_msg "Installing $("python${python_version}" -V) virtual environment..."
if virtualenv -p "python${python_version}" "${KLIPPY_ENV}"; then
"${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
}
###
# extracts the required packages from the
# install-debian.sh script and installs them
#
# @param {string}: python_version - klipper-env python version
#
function install_klipper_packages() {
local packages log_name="Klipper" 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 pkg-config for rp2040 build
packages+=" pkg-config"
### add dbus requirement for DietPi distro
[[ -e "/boot/dietpi/.version" ]] && packages+=" dbus"
if (( python_version == 3 )); then
### replace python-dev with python3-dev if python3 was selected
packages="${packages//python-dev/python3-dev}"
elif (( python_version == 2 )); then
### package name 'python-dev' is deprecated (-> no installation candidate) on more modern linux distros
packages="${packages//python-dev/python2-dev}"
else
log_error "Internal Error: missing parameter 'python_version' during function call of ${FUNCNAME[0]}"
error_msg "Internal Error: missing parameter 'python_version' during function call of ${FUNCNAME[0]}"
exit 1
fi
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
### Update system package lists if stale
update_system_package_lists
### Install required packages
install_system_packages "${log_name}" "packages[@]"
}
function create_klipper_service() {
local instance_name=${1}
local printer_data
local cfg_dir
local gcodes_dir
local cfg
local log
local klippy_serial
local klippy_socket
local env_file
local service
local service_template
local env_template
local suffix
printer_data="${HOME}/${instance_name}_data"
cfg_dir="${printer_data}/config"
gcodes_dir="${printer_data}/gcodes"
cfg="${cfg_dir}/printer.cfg"
log="${printer_data}/logs/klippy.log"
klippy_serial="${printer_data}/comms/klippy.serial"
klippy_socket="${printer_data}/comms/klippy.sock"
env_file="${printer_data}/systemd/klipper.env"
if [[ ${instance_name} == "printer" ]]; then
suffix="${instance_name//printer/}"
else
suffix="-${instance_name//printer_/}"
fi
create_required_folders "${printer_data}"
service_template="${KIAUH_SRCDIR}/resources/klipper.service"
env_template="${KIAUH_SRCDIR}/resources/klipper.env"
service="${SYSTEMD}/klipper${suffix}.service"
if [[ ! -f ${service} ]]; then
status_msg "Create Klipper service file ..."
sudo cp "${service_template}" "${service}"
sudo cp "${env_template}" "${env_file}"
sudo sed -i "s|%USER%|${USER}|g; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%ENV%|${KLIPPY_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
sudo sed -i "s|%USER%|${USER}|; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${klippy_serial}|; s|%UDS%|${klippy_socket}|" "${env_file}"
ok_msg "Klipper service file created!"
fi
if [[ ! -f ${cfg} ]]; then
write_example_printer_cfg "${cfg}" "${gcodes_dir}"
fi
}
function write_example_printer_cfg() {
local cfg=${1}
local gcodes_dir=${2}
local cfg_template
cfg_template="${KIAUH_SRCDIR}/resources/example.printer.cfg"
status_msg "Creating minimal example printer.cfg ..."
if cp "${cfg_template}" "${cfg}"; then
sed -i "s|%GCODES_DIR%|${gcodes_dir}|" "${cfg}"
ok_msg "Minimal example printer.cfg created!"
else
error_msg "Couldn't create minimal example printer.cfg!"
fi
}
#================================================#
#================ REMOVE KLIPPER ================#
#================================================#
function remove_klipper_service() {
[[ -z $(klipper_systemd) ]] && return
status_msg "Removing Klipper 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}"
sudo systemctl daemon-reload
sudo systemctl reset-failed
done
ok_msg "All Klipper services removed!"
}
function find_instance_files() {
local target_folder=${1}
local target_name=${2}
local files
readarray -t files < <(find "${HOME}" -regex "${HOME}/[A-Za-z0-9_]+_data/${target_folder}/${target_name}" | sort)
echo -e "${files[@]}"
}
function find_legacy_klipper_logs() {
local files
local regex="klippy(-[0-9a-zA-Z]+)?\.log(.*)?"
readarray -t files < <(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/${regex}" 2> /dev/null | sort)
echo -e "${files[@]}"
}
function find_legacy_klipper_uds() {
local files
readarray -t files < <(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
echo -e "${files[@]}"
}
function find_legacy_klipper_printer() {
local files
readarray -t files < <(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort)
echo -e "${files[@]}"
}
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!"
}
###
# takes in a string of space separated absolute
# filepaths and removes those files one after another
#
function remove_files() {
local files
read -r -a files <<< "${@}"
if (( ${#files[@]} > 0 )); then
for file in "${files[@]}"; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_klipper() {
remove_klipper_service
remove_files "$(find_instance_files "systemd" "klipper.env")"
remove_files "$(find_instance_files "logs" "klippy.log.*")"
remove_files "$(find_instance_files "comms" "klippy.sock")"
remove_files "$(find_instance_files "comms" "klippy.serial")"
remove_files "$(find_legacy_klipper_logs)"
remove_files "$(find_legacy_klipper_uds)"
remove_files "$(find_legacy_klipper_printer)"
remove_klipper_dir
remove_klipper_env
print_confirm "Klipper was successfully removed!" && return
}
#================================================#
#================ UPDATE KLIPPER ================#
#================================================#
###
# stops klipper, performs a git pull, installs
# possible new dependencies, then restarts klipper
#
function update_klipper() {
read_kiauh_ini "${FUNCNAME[0]}"
local py_ver
local custom_repo="${custom_klipper_repo}"
local custom_branch="${custom_klipper_repo_branch}"
py_ver=$(get_klipper_python_ver)
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 "${py_ver}"
### 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)"
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
local branch
read_kiauh_ini "${FUNCNAME[0]}"
branch="${custom_klipper_repo_branch}"
[[ -z ${branch} ]] && branch="master"
cd "${KLIPPER_DIR}" && git fetch origin -q
commit=$(git describe "origin/${branch}" --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_klipper_versions() {
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 application_updates_available in kiauh.ini
add_to_application_updates "klipper"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
###
# reads the python version from the klipper virtual environment
#
# @output: writes the python major version to STDOUT
#
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}"
}
function mask_disrupting_services() {
local brltty="false"
local brltty_udev="false"
local modem_manager="false"
[[ $(dpkg -s brltty 2>/dev/null | grep "Status") = *\ installed ]] && brltty="true"
[[ $(dpkg -s brltty-udev 2>/dev/null | grep "Status") = *\ installed ]] && brltty_udev="true"
[[ $(dpkg -s ModemManager 2>/dev/null | grep "Status") = *\ installed ]] && modem_manager="true"
status_msg "Installed brltty package detected, masking brltty service ..."
if [[ ${brltty} == "true" ]]; then
sudo systemctl stop brltty
sudo systemctl mask brltty
fi
ok_msg "brltty service masked!"
status_msg "Installed brltty-udev package detected, masking brltty-udev service ..."
if [[ ${brltty_udev} == "true" ]]; then
sudo systemctl stop brltty-udev
sudo systemctl mask brltty-udev
fi
ok_msg "brltty-udev service masked!"
status_msg "Installed ModemManager package detected, masking ModemManager service ..."
if [[ ${modem_manager} == "true" ]]; then
sudo systemctl stop ModemManager
sudo systemctl mask ModemManager
fi
ok_msg "ModemManager service masked!"
}

237
scripts/klipperscreen.sh Normal file
View File

@@ -0,0 +1,237 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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_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"
backup_before_update "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 dependencies 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() {
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 moonraker to application_updates_available in kiauh.ini
add_to_application_updates "klipperscreen"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function patch_klipperscreen_update_manager() {
local patched="false"
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\]\s*$" "${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
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}

690
scripts/mainsail.sh Normal file
View File

@@ -0,0 +1,690 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#================= INSTALL MAINSAIL ================#
#===================================================#
function install_mainsail() {
if [[ -z $(moonraker_systemd) ]]; then
local error="Moonraker not installed! It's recommended to install Moonraker first!"
print_error "${error}"
while true; do
local yn
read -p "${cyan}###### Proceed to install Mainsail without installing Moonraker? (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 Mainsail setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
fi
### checking dependencies
local dep=(wget nginx unzip)
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_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
### 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
fetch_webui_ports #WIP
### confirm message
print_confirm "Mainsail has been set up!"
}
function install_mainsail_macros() {
local yn
while true; do
echo
top_border
echo -e "| It is recommended to use special macros in order to |"
echo -e "| have Mainsail fully functional and working. |"
blank_line
echo -e "| The recommended macros for Mainsail can be seen here: |"
echo -e "| https://github.com/mainsail-crew/mainsail-config |"
blank_line
echo -e "| If you already use these macros skip this step. |"
echo -e "| Otherwise you should consider to answer with 'yes' to |"
echo -e "| download the recommended macros. |"
bottom_border
read -p "${cyan}###### Download 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_repo path configs regex line gcode_dir
ms_cfg_repo="https://github.com/mainsail-crew/mainsail-config.git"
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
if [[ -z ${configs} ]]; then
print_error "No printer.cfg found! Installation of Macros will be skipped ..."
log_error "execution stopped! reason: no printer.cfg found"
return
fi
status_msg "Cloning mainsail-config ..."
[[ -d "${HOME}/mainsail-config" ]] && rm -rf "${HOME}/mainsail-config"
if git clone "${ms_cfg_repo}" "${HOME}/mainsail-config"; then
for config in ${configs}; do
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
if [[ -e "${path}/mainsail.cfg" && ! -h "${path}/mainsail.cfg" ]]; then
warn_msg "Attention! Existing mainsail.cfg detected!"
warn_msg "The file will be renamed to 'mainsail.bak.cfg' to be able to continue with the installation."
if ! mv "${path}/mainsail.cfg" "${path}/mainsail.bak.cfg"; then
error_msg "Renaming mainsail.cfg failed! Aborting installation ..."
return
fi
fi
if [[ -h "${path}/mainsail.cfg" ]]; then
warn_msg "Recreating symlink in ${path} ..."
rm -rf "${path}/mainsail.cfg"
fi
if ! ln -sf "${HOME}/mainsail-config/client.cfg" "${path}/mainsail.cfg"; then
error_msg "Creating symlink failed! Aborting installation ..."
return
fi
if ! grep -Eq "^\[include mainsail.cfg\]$" "${path}/printer.cfg"; then
log_info "${path}/printer.cfg"
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
fi
line=$(($(grep -n "\[include mainsail.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1))
gcode_dir=${path/config/gcodes}
if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then
log_info "${path}/printer.cfg"
sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg"
fi
done
else
print_error "Cloning failed! Aborting installation ..."
log_error "execution stopped! reason: cloning failed"
return
fi
patch_mainsail_config_update_manager
ok_msg "Done!"
}
function download_mainsail() {
local services
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 no-instance or multi-instance was found, enable mainsails remoteMode
services=$(moonraker_systemd)
if [[ ( -z "${services}" ) || ( $(echo "${services}" | 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_nginx_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 regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/mainsail-.*"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_legacy_mainsail_log_symlinks() {
local files
files=$(find "${HOME}/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_config() {
if [[ -d "${HOME}/mainsail-config" ]]; then
status_msg "Removing ${HOME}/mainsail-config ..."
rm -rf "${HOME}/mainsail-config"
ok_msg "${HOME}/mainsail-config removed!"
print_confirm "Mainsail-Config successfully removed!"
fi
}
function remove_mainsail() {
remove_mainsail_dir
remove_mainsail_nginx_config
remove_mainsail_logs
remove_mainsail_log_symlinks
remove_legacy_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() {
local versionfile="${MAINSAIL_DIR}/.version"
local relinfofile="${MAINSAIL_DIR}/release_info.json"
local version
if [[ -f ${relinfofile} ]]; then
version=$(grep -o '"version":"[^"]*' "${relinfofile}" | grep -o '[^"]*$')
elif [[ -f ${versionfile} ]]; then
version=$(head -n 1 "${versionfile}")
fi
echo "${version}"
}
function get_remote_mainsail_version() {
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
local tags
tags=$(curl -s "https://api.github.com/repos/mainsail-crew/mainsail/tags" | grep "name" | cut -d'"' -f4)
echo "${tags}" | head -1
}
function compare_mainsail_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_mainsail_version)"
remote_ver="$(get_remote_mainsail_version)"
if [[ ${local_ver} != "${remote_ver}" && ${local_ver} != "" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker to application_updates_available in kiauh.ini
add_to_application_updates "mainsail"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
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/gb-docs/main/_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() {
read_kiauh_ini "${FUNCNAME[0]}"
local theme_url
local theme_name
local theme_note
theme_url=${1}
theme_name=${2}
theme_note=${3}
local folder_arr
local folder_names="${multi_instance_names}"
local target_folders=()
IFS=',' read -r -a folder_arr <<< "${folder_names}"
### build theme target folder array
if (( ${#folder_arr[@]} > 1 )); then
for folder in "${folder_arr[@]}"; do
### instance names/identifier of only numbers need to be prefixed with 'printer_'
if [[ ${folder} =~ ^[0-9]+$ ]]; then
target_folders+=("${HOME}/printer_${folder}_data/config")
else
target_folders+=("${HOME}/${folder}_data/config")
fi
done
else
target_folders+=("${HOME}/printer_data/config")
fi
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 "/" -f2 | 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
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 regex theme_folders target_folders=()
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/\.theme"
theme_folders=$(find "${HOME}" -maxdepth 3 -type d -regextype posix-extended -regex "${regex}" | sort)
# 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
status_msg "No Themes installed!\n"
return
elif (( ${#target_folders[@]} > 1 )); 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
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 releases_by_tag tags tag unstable_url url
### latest stable download url
url="https://github.com/mainsail-crew/mainsail/releases/latest/download/mainsail.zip"
read_kiauh_ini "${FUNCNAME[0]}"
if [[ ${mainsail_install_unstable} == "true" ]]; then
releases_by_tag="https://api.github.com/repos/mainsail-crew/mainsail/tags"
tags=$(curl -s "${releases_by_tag}" | grep "name" | cut -d'"' -f4)
tag=$(echo "${tags}" | head -1)
### latest unstable download url including pre-releases (alpha, beta, rc)
unstable_url="https://github.com/mainsail-crew/mainsail/releases/download/${tag}/mainsail.zip"
if [[ ${unstable_url} == *"download//"* ]]; then
warn_msg "Download URL broken! Falling back to URL of latest stable release!"
else
url=${unstable_url}
fi
fi
echo "${url}"
}
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/mainsail" | 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
status_msg "Setting instance storage location to 'browser' ..."
sed -i 's|"instancesDB": "moonraker"|"instancesDB": "browser"|' "${MAINSAIL_DIR}/config.json"
ok_msg "Done!"
}
function patch_mainsail_update_manager() {
local patched moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
patched="false"
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager mainsail\]\s*$" "${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
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}
function patch_mainsail_config_update_manager() {
local patched moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
patched="false"
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager mainsail-config\]\s*$" "${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-Config to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager mainsail-config]
type: git_repo
primary_branch: master
path: ~/mainsail-config
origin: https://github.com/mainsail-crew/mainsail-config.git
managed_services: klipper
MOONRAKER_CONF
fi
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}

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

@@ -0,0 +1,193 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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="${KIAUH_SRCDIR}/resources/mjpg-streamer/webcamd"
local webcam_txt="${KIAUH_SRCDIR}/resources/mjpg-streamer/webcam.txt"
local service="${KIAUH_SRCDIR}/resources/mjpg-streamer/webcamd.service"
local repo="https://github.com/jacksonliam/mjpg-streamer.git"
### 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 cp "${webcamd}" "/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 ..."
cp "${webcam_txt}" "${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!"
}

247
scripts/mobileraker.sh Normal file
View File

@@ -0,0 +1,247 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
#
# This file is written and maintained by Patrick Schmidt author of Mobileraker
# It is based of the kliperscreen.sh install script!
set -e
#===================================================#
#========== INSTALL MOBILERAKER COMPANION ==========#
#===================================================#
function mobileraker_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/mobileraker.service")
echo "${services}"
}
function install_mobileraker() {
### 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_config_dir
### install Mobileraker's Companion
mobileraker_setup
### add Mobileraker's Companion to the update manager in moonraker.conf
patch_mobileraker_update_manager
do_action_service "restart" "mobileraker"
}
function mobileraker_setup() {
local dep=(wget curl unzip dfu-util)
dependency_check "${dep[@]}"
status_msg "Cloning Mobileraker's companion from ${MOBILERAKER_REPO} ..."
# force remove existing Mobileraker's companion dir
[[ -d ${MOBILERAKER_DIR} ]] && rm -rf "${MOBILERAKER_DIR}"
# clone into fresh Mobileraker's companion dir
cd "${HOME}" || exit 1
if ! git clone "${MOBILERAKER_REPO}" "${MOBILERAKER_DIR}"; then
print_error "Cloning mobileraker's companion from\n ${MOBILERAKER_REPO}\n failed!"
exit 1
fi
status_msg "Starting installer of Mobileraker's companion ..."
if "${MOBILERAKER_DIR}"/scripts/install.sh; then
ok_msg "Mobileraker's companion successfully installed!"
else
print_error "Mobileraker's companion installation failed!"
exit 1
fi
}
#===================================================#
#=========== REMOVE MOBILERAKER COMPANION ==========#
#===================================================#
function remove_mobileraker() {
### remove Mobileraker's companion dir
if [[ -d ${MOBILERAKER_DIR} ]]; then
status_msg "Removing Mobileraker's companion directory ..."
rm -rf "${MOBILERAKER_DIR}" && ok_msg "Directory removed!"
fi
### remove Mobileraker's companion VENV dir
if [[ -d ${MOBILERAKER_ENV} ]]; then
status_msg "Removing Mobileraker's companion VENV directory ..."
rm -rf "${MOBILERAKER_ENV}" && ok_msg "Directory removed!"
fi
### remove Mobileraker's companion service
if [[ -e "${SYSTEMD}/mobileraker.service" ]]; then
status_msg "Removing mobileraker service ..."
do_action_service "stop" "mobileraker"
do_action_service "disable" "mobileraker"
sudo rm -f "${SYSTEMD}/mobileraker.service"
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Mobileraker's companion Service removed!"
fi
remove_mobileraker_logs
print_confirm "Mobileraker's companion successfully removed!"
}
function remove_mobileraker_logs() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/mobileraker\.log.*"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
#===================================================#
#=========== UPDATE MOBILERAKER COMPANION ==========#
#===================================================#
function update_mobileraker() {
local old_md5
old_md5=$(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1)
do_action_service "stop" "mobileraker"
cd "${MOBILERAKER_DIR}"
git pull origin main -q && ok_msg "Fetch successfull!"
git checkout -f main && ok_msg "Checkout successfull"
if [[ $(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
status_msg "New dependencies detected..."
"${MOBILERAKER_ENV}"/bin/pip install -r "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt"
ok_msg "Dependencies have been installed!"
fi
ok_msg "Update complete!"
do_action_service "start" "mobileraker"
}
#===================================================#
#=========== MOBILERAKER COMPANION STATUS ==========#
#===================================================#
function get_mobileraker_status() {
local sf_count status
sf_count="$(mobileraker_systemd | wc -w)"
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${MOBILERAKER_DIR}" "${MOBILERAKER_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_mobileraker_commit() {
[[ ! -d ${MOBILERAKER_DIR} || ! -d "${MOBILERAKER_DIR}/.git" ]] && return
local commit
cd "${MOBILERAKER_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_mobileraker_commit() {
[[ ! -d ${MOBILERAKER_DIR} || ! -d "${MOBILERAKER_DIR}/.git" ]] && return
local commit
cd "${MOBILERAKER_DIR}" && git fetch origin -q
commit=$(git describe origin/main --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_mobileraker_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_mobileraker_commit)"
remote_ver="$(get_remote_mobileraker_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker to application_updates_available in kiauh.ini
add_to_application_updates "mobileraker"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function patch_mobileraker_update_manager() {
local patched moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
patched="false"
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager mobileraker\]\s*$" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
### add Mobileraker's Companion update manager section to moonraker.conf
status_msg "Adding Mobileraker's Companion to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
[update_manager mobileraker]
type: git_repo
path: ${HOME}/mobileraker_companion
origin: https://github.com/Clon1998/mobileraker_companion.git
primary_branch:main
managed_services: mobileraker
env: ${HOME}/mobileraker-env/bin/python
requirements: scripts/mobileraker-requirements.txt
install_script: scripts/install.sh
MOONRAKER_CONF
fi
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}

View File

@@ -0,0 +1,542 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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_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 log_name="Telegram Bot"
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 lists if stale
update_system_package_lists
### Install required packages
install_system_packages "${log_name}" "packages[@]"
}
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 printer_data log_dir cfg cfg_dir
if (( telegram_bot_count == 1 )); then
printer_data="${HOME}/printer_data"
log_dir="${printer_data}/logs"
cfg_dir="${printer_data}/config"
cfg="${cfg_dir}/telegram.conf"
### create required folder structure
create_required_folders "${printer_data}"
### write single instance config
write_telegram_conf "${cfg_dir}" "${cfg}"
elif (( telegram_bot_count > 1 )); then
local j=0 re="^[1-9][0-9]*$"
for (( i=1; i <= telegram_bot_count; i++ )); do
printer_data="${HOME}/${names[${j}]}_data"
### prefix instance name with "printer_" if it is only a number
[[ ${names[j]} =~ ${re} ]] && printer_data="${HOME}/printer_${names[${j}]}_data"
cfg_dir="${printer_data}/config"
cfg="${cfg_dir}/telegram.conf"
log_dir="${printer_data}/logs"
### create required folder structure
create_required_folders "${printer_data}"
### write multi instance config
write_telegram_conf "${cfg_dir}" "${cfg}"
j=$(( j + 1 ))
done && unset j
else
return 1
fi
}
function write_telegram_conf() {
local cfg_dir=${1} cfg=${2}
local conf_template="${TELEGRAM_BOT_DIR}/scripts/base_install_template"
if [[ ! -f ${cfg} ]]; then
status_msg "Creating telegram.conf in ${cfg_dir} ..."
cp "${conf_template}" "${cfg}"
ok_msg "telegram.conf created!"
else
ok_msg "File '${cfg}' already exists! Skipping..."
fi
}
function create_telegram_bot_service() {
local input=("${@}")
local instances=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local printer_data cfg_dir cfg log service env_file
if (( instances == 1 )); then
printer_data="${HOME}/printer_data"
cfg_dir="${printer_data}/config"
cfg="${cfg_dir}/telegram.conf"
log="${printer_data}/logs/telegram.log"
service="${SYSTEMD}/moonraker-telegram-bot.service"
env_file="${printer_data}/systemd/moonraker-telegram-bot.env"
### create required folder structure
create_required_folders "${printer_data}"
### write single instance service
write_telegram_bot_service "" "${cfg}" "${log}" "${service}" "${env_file}"
ok_msg "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
printer_data="${HOME}/printer_${names[${j}]}_data"
else
printer_data="${HOME}/${names[${j}]}_data"
fi
cfg_dir="${printer_data}/config"
cfg="${cfg_dir}/telegram.conf"
log="${printer_data}/logs/telegram.log"
service="${SYSTEMD}/moonraker-telegram-bot-${names[${j}]}.service"
env_file="${printer_data}/systemd/moonraker-telegram-bot.env"
### create required folder structure
create_required_folders "${printer_data}"
### write multi instance service
if write_telegram_bot_service "${names[${j}]}" "${cfg}" "${log}" "${service}" "${env_file}"; then
ok_msg "Telegram Bot instance moonraker-telegram-bot-${names[${j}]} created!"
else
error_msg "An error occured during creation of instance moonraker-telegram-bot-${names[${j}]}!"
fi
j=$(( j + 1 ))
done && unset j
else
return 1
fi
}
function write_telegram_bot_service() {
local i=${1} cfg=${2} log=${3} service=${4} env_file=${5}
local service_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.service"
local env_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.env"
### replace all placeholders
if [[ ! -f ${service} ]]; then
status_msg "Creating service file for instance ${i} ..."
sudo cp "${service_template}" "${service}"
if [[ -z ${i} ]]; then
sudo sed -i "s| %INST%||" "${service}"
else
sudo sed -i "s|%INST%|${i}|" "${service}"
fi
sudo sed -i "s|%USER%|${USER}|g; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
status_msg "Creating environment file for instance ${i} ..."
cp "${env_template}" "${env_file}"
sed -i "s|%USER%|${USER}|; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${env_file}"
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_env_file() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/systemd\/moonraker-telegram-bot\.env"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_logs() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/telegram\.log.*"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_legacy_telegram_bot_logs() {
local files regex="telegram(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/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_telegram_bot() {
remove_telegram_bot_systemd
remove_telegram_bot_dir
remove_telegram_bot_env
remove_telegram_bot_env_file
remove_telegram_bot_logs
remove_legacy_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() {
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 to application_updates_available in kiauh.ini
add_to_application_updates "telegram_bot"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function patch_telegram_bot_update_manager() {
local patched moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
patched="false"
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager moonraker-telegram-bot\]\s*$" "${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
patched="true"
done
if [[ ${patched} == "true" ]]; then
do_action_service "restart" "moonraker"
fi
}

824
scripts/moonraker.sh Normal file
View File

@@ -0,0 +1,824 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#================ INSTALL MOONRAKER ================#
#===================================================#
###
# this function detects all installed moonraker
# systemd instances and returns their absolute path
function moonraker_systemd() {
local services
local blacklist
local ignore
local match
###
# any moonraker client that uses "moonraker" in its own name must be blacklisted using
# this variable, otherwise they will be falsely recognized as moonraker instances
blacklist="obico|hmi|telegram-bot"
ignore="${SYSTEMD}/moonraker-(${blacklist}).service"
match="${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service"
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype awk ! -regex "${ignore}" -regex "${match}" | 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 log_name="Moonraker"
local package_json="${MOONRAKER_DIR}/scripts/system-dependencies.json"
### read PKGLIST from official install-script
status_msg "Reading dependencies..."
# shellcheck disable=SC2016
packages=$(python3 - << EOF
from __future__ import annotations
import shlex
import re
import pathlib
import logging
from typing import Tuple, Dict, List, Any
def _get_distro_info() -> Dict[str, Any]:
try:
import distro
except ModuleNotFoundError:
pass
else:
return dict(
distro_id=distro.id(),
distro_version=distro.version(),
aliases=distro.like().split()
)
release_file = pathlib.Path("/etc/os-release")
release_info: Dict[str, str] = {}
with release_file.open("r") as f:
lexer = shlex.shlex(f, posix=True)
lexer.whitespace_split = True
for item in list(lexer):
if "=" in item:
key, val = item.split("=", maxsplit=1)
release_info[key] = val
return dict(
distro_id=release_info.get("ID", ""),
distro_version=release_info.get("VERSION_ID", ""),
aliases=release_info.get("ID_LIKE", "").split()
)
def _convert_version(version: str) -> Tuple[str | int, ...]:
version = version.strip()
ver_match = re.match(r"\d+(\.\d+)*((?:-|\.).+)?", version)
if ver_match is not None:
return tuple([
int(part) if part.isdigit() else part
for part in re.split(r"\.|-", version)
])
return (version,)
class SysDepsParser:
def __init__(self, distro_info: Dict[str, Any] | None = None) -> None:
if distro_info is None:
distro_info = _get_distro_info()
self.distro_id: str = distro_info.get("distro_id", "")
self.aliases: List[str] = distro_info.get("aliases", [])
self.distro_version: Tuple[int | str, ...] = tuple()
version = distro_info.get("distro_version")
if version:
self.distro_version = _convert_version(version)
self.vendor: str = ""
if pathlib.Path("/etc/rpi-issue").is_file():
self.vendor = "raspberry-pi"
def _parse_spec(self, full_spec: str) -> str | None:
parts = full_spec.split(";", maxsplit=1)
if len(parts) == 1:
return full_spec
pkg_name = parts[0].strip()
expressions = re.split(r"( and | or )", parts[1].strip())
if not len(expressions) & 1:
logging.info(
f"Requirement specifier is missing an expression "
f"between logical operators : {full_spec}"
)
return None
last_result: bool = True
last_logical_op: str | None = "and"
for idx, exp in enumerate(expressions):
if idx & 1:
if last_logical_op is not None:
logging.info(
"Requirement specifier contains sequential logical "
f"operators: {full_spec}"
)
return None
logical_op = exp.strip()
if logical_op not in ("and", "or"):
logging.info(
f"Invalid logical operator {logical_op} in requirement "
f"specifier: {full_spec}")
return None
last_logical_op = logical_op
continue
elif last_logical_op is None:
logging.info(
f"Requirement specifier contains two seqential expressions "
f"without a logical operator: {full_spec}")
return None
dep_parts = re.split(r"(==|!=|<=|>=|<|>)", exp.strip())
req_var = dep_parts[0].strip().lower()
if len(dep_parts) != 3:
logging.info(f"Invalid comparison, must be 3 parts: {full_spec}")
return None
elif req_var == "distro_id":
left_op: str | Tuple[int | str, ...] = self.distro_id
right_op = dep_parts[2].strip().strip("\"'")
elif req_var == "vendor":
left_op = self.vendor
right_op = dep_parts[2].strip().strip("\"'")
elif req_var == "distro_version":
if not self.distro_version:
logging.info(
"Distro Version not detected, cannot satisfy requirement: "
f"{full_spec}"
)
return None
left_op = self.distro_version
right_op = _convert_version(dep_parts[2].strip().strip("\"'"))
else:
logging.info(f"Invalid requirement specifier: {full_spec}")
return None
operator = dep_parts[1].strip()
try:
compfunc = {
"<": lambda x, y: x < y,
">": lambda x, y: x > y,
"==": lambda x, y: x == y,
"!=": lambda x, y: x != y,
">=": lambda x, y: x >= y,
"<=": lambda x, y: x <= y
}.get(operator, lambda x, y: False)
result = compfunc(left_op, right_op)
if last_logical_op == "and":
last_result &= result
else:
last_result |= result
last_logical_op = None
except Exception:
logging.exception(f"Error comparing requirements: {full_spec}")
return None
if last_result:
return pkg_name
return None
def parse_dependencies(self, sys_deps: Dict[str, List[str]]) -> List[str]:
if not self.distro_id:
logging.info(
"Failed to detect current distro ID, cannot parse dependencies"
)
return []
all_ids = [self.distro_id] + self.aliases
for distro_id in all_ids:
if distro_id in sys_deps:
if not sys_deps[distro_id]:
logging.info(
f"Dependency data contains an empty package definition "
f"for linux distro '{distro_id}'"
)
continue
processed_deps: List[str] = []
for dep in sys_deps[distro_id]:
parsed_dep = self._parse_spec(dep)
if parsed_dep is not None:
processed_deps.append(parsed_dep)
return processed_deps
else:
logging.info(
f"Dependency data has no package definition for linux "
f"distro '{self.distro_id}'"
)
return []
# *** SYSTEM DEPENDENCIES START ***
system_deps = {
"debian": [
"python3-virtualenv", "python3-dev", "libopenjp2-7", "libsodium-dev",
"zlib1g-dev", "libjpeg-dev", "packagekit",
"wireless-tools; distro_id != 'ubuntu' or distro_version <= '24.04'",
"iw; distro_id == 'ubuntu' and distro_version >= '24.10'",
"python3-libcamera; vendor == 'raspberry-pi' and distro_version >= '11'",
"curl", "build-essential"
],
}
# *** SYSTEM DEPENDENCIES END ***
parser = SysDepsParser()
pkgs = parser.parse_dependencies(system_deps)
if pkgs:
print(' '.join(pkgs), end="")
exit(0)
EOF
)
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
### Update system package lists if stale
update_system_package_lists
### Install required packages
install_system_packages "${log_name}" "packages[@]"
}
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 -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
configure_moonraker_service "${instance_arr[@]}"
### step 5: create polkit rules for moonraker
install_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 port lan printer_data cfg_dir cfg uds
port=7125
lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
if (( moonraker_count == 1 )); then
printer_data="${HOME}/printer_data"
cfg_dir="${printer_data}/config"
cfg="${cfg_dir}/moonraker.conf"
uds="${printer_data}/comms/klippy.sock"
### write single instance config
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${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
printer_data="${HOME}/printer_${names[${j}]}_data"
else
printer_data="${HOME}/${names[${j}]}_data"
fi
cfg_dir="${printer_data}/config"
cfg="${cfg_dir}/moonraker.conf"
uds="${printer_data}/comms/klippy.sock"
### write multi instance config
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${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} uds=${4} lan=${5}
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; s|%PORT%|${port}|; 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 configure_moonraker_service() {
local input=("${@}")
local moonraker_count=${input[0]} && unset "input[0]"
local names=("${input[@]}") && unset "input[@]"
local printer_data cfg_dir service env_file
if (( moonraker_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
i=""
printer_data="${HOME}/printer_data"
cfg_dir="${printer_data}/config"
service="${SYSTEMD}/moonraker.service"
env_file="${printer_data}/systemd/moonraker.env"
### create required folder structure
create_required_folders "${printer_data}"
### write single instance service
write_moonraker_service "" "${printer_data}" "${service}" "${env_file}"
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
printer_data="${HOME}/printer_${names[${j}]}_data"
else
printer_data="${HOME}/${names[${j}]}_data"
fi
cfg_dir="${printer_data}/config"
service="${SYSTEMD}/moonraker-${names[${j}]}.service"
env_file="${printer_data}/systemd/moonraker.env"
### create required folder structure
create_required_folders "${printer_data}"
### write multi instance service
write_moonraker_service "${names[${j}]}" "${printer_data}" "${service}" "${env_file}"
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
enable_mainsail_remotemode
fi
else
return 1
fi
}
function write_moonraker_service() {
local i=${1} printer_data=${2} service=${3} env_file=${4}
local service_template="${KIAUH_SRCDIR}/resources/moonraker.service"
local env_template="${KIAUH_SRCDIR}/resources/moonraker.env"
### replace all placeholders
if [[ ! -f ${service} ]]; then
status_msg "Creating Moonraker Service ${i} ..."
sudo cp "${service_template}" "${service}"
sudo cp "${env_template}" "${env_file}"
[[ -z ${i} ]] && sudo sed -i "s| %INST%||" "${service}"
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
sudo sed -i "s|%USER%|${USER}|g; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%ENV%|${MOONRAKER_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
sudo sed -i "s|%USER%|${USER}|; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%PRINTER_DATA%|${printer_data}|" "${env_file}"
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 install_moonraker_polkit() {
local POLKIT_LEGACY_FILE="/etc/polkit-1/localauthority/50-local.d/10-moonraker.pkla"
local POLKIT_FILE="/etc/polkit-1/rules.d/moonraker.rules"
local POLKIT_USR_FILE="/usr/share/polkit-1/rules.d/moonraker.rules"
local legacy_file_exists
local file_exists
local usr_file_exists
local has_sup
local require_daemon_reload="false"
legacy_file_exists=$(sudo find "${POLKIT_LEGACY_FILE}" 2> /dev/null)
file_exists=$(sudo find "${POLKIT_FILE}" 2> /dev/null)
usr_file_exists=$(sudo find "${POLKIT_USR_FILE}" 2> /dev/null)
### 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}"
require_daemon_reload="true"
ok_msg "Adding moonraker-admin supplementary group successfull!"
fi
done
if [[ ${require_daemon_reload} == "true" ]]; then
status_msg "Reloading unit files ..."
sudo systemctl daemon-reload
ok_msg "Unit files reloaded!"
fi
### execute moonrakers policykit-rules script only if rule files do not already exist
if [[ -z ${legacy_file_exists} && ( -z ${file_exists} || -z ${usr_file_exists} ) ]]; then
status_msg "Installing Moonraker policykit rules ..."
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
ok_msg "Moonraker policykit rules installed!"
fi
return
}
#==================================================#
#================ 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_env_file() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/systemd\/moonraker\.env"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_moonraker_logs() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/moonraker\.log.*"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_legacy_moonraker_logs() {
local files regex="moonraker(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/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_env_file
remove_moonraker_logs
remove_legacy_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
install_moonraker_polkit || true
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() {
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 application_updates_available in kiauh.ini
add_to_application_updates "moonraker"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}

View File

@@ -1,172 +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/klipper_webui_nginx.cfg > ${SRCDIR}/kiauh/resources/$1
##edit the nginx config file before moving it
sed -i "s/<<UI>>/$1/g" ${SRCDIR}/kiauh/resources/$1
if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then
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
}

360
scripts/nginx.sh Normal file
View File

@@ -0,0 +1,360 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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 path access_log error_log regex logpaths
interface=${1}
access_log="/var/log/nginx/${interface}-access.log"
error_log="/var/log/nginx/${interface}-error.log"
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs"
logpaths=$(find "${HOME}" -maxdepth 2 -type d -regextype posix-extended -regex "${regex}" | sort)
for path in ${logpaths}; do
[[ ! -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 "Symlink created: ${path}/${interface}-access.log"
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 "Symlink created: ${path}/${interface}-error.log"
fi
done
}
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
local mainsail_webcams
local 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}/mainsail" "${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}/fluidd" "${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;;
*)
error_msg "Invalid command!";;
esac
done
fi
}
function set_nginx_cfg() {
local interface=${1}
if [[ ${SET_NGINX_CFG} == "true" ]]; then
#check for dependencies
local dep=(nginx)
dependency_check "${dep[@]}"
local cfg_src="${RESOURCES}/${interface}"
local cfg_dest="/etc/nginx/sites-available/${interface}"
status_msg "Creating NGINX configuration for ${interface^} ..."
# copy config to destination and set correct username
[[ -f ${cfg_dest} ]] && sudo rm -f "${cfg_dest}"
sudo cp "${cfg_src}" "${cfg_dest}"
sudo sed -i "/root/s/pi/${USER}/" "${cfg_dest}"
if [[ ${SET_LISTEN_PORT} != "${DEFAULT_PORT}" ]]; then
sudo sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg_dest}"
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg_dest}"
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
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
sudo systemctl restart nginx.service
ok_msg "NGINX configuration for ${interface^} was set!"
fi
}
###
# check if permissions of the users home directory
# grant execution rights to group and other which is
# required for NGINX to be able to serve Mainsail/Fluidd
#
function set_nginx_permissions() {
local homedir_perm
local exec_perms_count
homedir_perm=$(ls -ld "${HOME}")
exec_perms_count=$(echo "${homedir_perm}" | cut -d" " -f1 | grep -c "x")
if (( exec_perms_count < 3 )); 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
}

489
scripts/obico.sh Normal file
View File

@@ -0,0 +1,489 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#===================================================#
#============== INSTALL MOONRAKER-OBICO ============#
#===================================================#
function moonraker_obico_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-obico(-[0-9a-zA-Z]+)?.service")
echo "${services}"
}
function moonraker_obico_config() {
local moonraker_cfg_dirs
read -r -a moonraker_cfg_dirs <<< "$(get_instance_folder_path "config")"
if (( ${#moonraker_cfg_dirs[@]} > 0 )); then
echo "${moonraker_cfg_dirs[${1}]}/moonraker-obico.cfg"
else
echo ""
fi
}
function moonraker_obico_needs_linking() {
local moonraker_obico_cfg=${1}
if [[ ! -f "${moonraker_obico_cfg}" ]]; then
return 1
fi
if grep -s -E "^[^#]" "${moonraker_obico_cfg}" | grep -q 'auth_token'; then
return 1
else
return 0
fi
}
function obico_server_url_prompt() {
top_border
printf "|${green}%-55s${white}|\n" " Obico Server URL"
blank_line
echo -e "| You can use a self-hosted Obico Server or the Obico |"
echo -e "| Cloud. For more information, please visit: |"
echo -e "| https://obico.io. |"
blank_line
echo -e "| For the Obico Cloud, leave it as the default: |"
printf "|${cyan}%-55s${white}|\n" " https://app.obico.io"
blank_line
echo -e "| For self-hosted server, specify: |"
printf "|${cyan}%-55s${white}|\n" " http://server_ip:port"
echo -e "| For instance, 'http://192.168.0.5:3334'. |"
bottom_border
}
function moonraker_obico_setup_dialog() {
status_msg "Initializing Obico installation ..."
local moonraker_count
local moonraker_names
moonraker_count=$(moonraker_systemd | wc -w)
if (( moonraker_count == 0 )); then
### return early if moonraker is not installed
local error="Moonraker not installed! Please install Moonraker first!"
log_error "Obico setup started without Moonraker being installed. Aborting setup."
print_error "${error}" && return
elif (( moonraker_count > 1 )); then
# moonraker_names is valid only in case of multi-instance
read -r -a moonraker_names <<< "$(get_multi_instance_names)"
fi
local moonraker_obico_services
local existing_moonraker_obico_count
moonraker_obico_services=$(moonraker_obico_systemd)
existing_moonraker_obico_count=$(echo "${moonraker_obico_services}" | wc -w )
local allowed_moonraker_obico_count=$(( moonraker_count - existing_moonraker_obico_count ))
# Allow user to reinstall an incomplete installation.
if (( allowed_moonraker_obico_count == 0 && moonraker_count > 0 )) && [[ $(get_moonraker_obico_status) != "Not linked!" ]]; then
local yn
while true; do
echo "${yellow}Obico is already installed.${white}"
echo "It is safe to run the install again to repair any issues."
echo ""
local question="Do you want to reinstall Obico?"
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 Obico installation...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
# The user responded yes, allow the install to run again.
allowed_moonraker_obico_count=1
fi
if (( allowed_moonraker_obico_count > 0 )); then
local new_moonraker_obico_count
### Step 1: Ask for the number of moonraker-obico instances to install
if (( moonraker_count == 1 )); then
ok_msg "Moonraker installation found!\n"
new_moonraker_obico_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" " ● moonraker-${name}"
done
blank_line
if (( existing_moonraker_obico_count > 0 )); then
printf "|${green}%-55s${white}|\n" " ${existing_moonraker_obico_count} Obico instances already installed!"
for svc in ${moonraker_obico_services}; do
printf "|${cyan}%-57s${white}|\n" " ● moonraker-obco-$(get_instance_name "${svc}")"
done
fi
blank_line
echo -e "| The setup will apply the same names to Obico! |"
blank_line
echo -e "| Please select the number of Obico instances |"
echo -e "| to install. Usually one Obico instance per |"
echo -e "| Moonraker instance is required, but you may not |"
echo -e "| install more Obico instances than available |"
echo -e "| Moonraker instances. |"
bottom_border
### ask for amount of instances
local re="^[1-9][0-9]*$"
while [[ ! ${new_moonraker_obico_count} =~ ${re} || ${new_moonraker_obico_count} -gt ${allowed_moonraker_obico_count} ]]; do
read -p "${cyan}###### Number of new Obico instances to set up:${white} " -i "${allowed_moonraker_obico_count}" -e new_moonraker_obico_count
### break if input is valid
[[ ${new_moonraker_obico_count} =~ ${re} && ${new_moonraker_obico_count} -le ${allowed_moonraker_obico_count} ]] && break
### conditional error messages
[[ ! ${new_moonraker_obico_count} =~ ${re} ]] && error_msg "Input not a number"
(( new_moonraker_obico_count > allowed_moonraker_obico_count )) && error_msg "Number of Obico instances larger than installed Moonraker instances"
done && select_msg "${new_moonraker_obico_count}"
else
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
return 1
fi # (( moonraker_count == 1 ))
### Step 2: Confirm instance amount
local yn
while true; do
(( new_moonraker_obico_count == 1 )) && local question="Install Obico?"
(( new_moonraker_obico_count > 1 )) && local question="Install ${new_moonraker_obico_count} Obico 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 Obico setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
fi # (( allowed_moonraker_obico_count > 0 ))
if (( new_moonraker_obico_count > 0 )); then
### Step 3: Ask for the Obico server URL
obico_server_url_prompt
local obico_server_url
while true; do
read -p "${cyan}###### Obico Server URL:${white} " -i "https://app.obico.io" -e obico_server_url
if echo "${obico_server_url}" | grep -qE "^(http|https)://[a-zA-Z0-9./?=_%:-]*"; then
break
else
error_msg "Invalid server URL!"
fi
done
(( new_moonraker_obico_count > 1 )) && status_msg "Installing ${new_moonraker_obico_count} Obico instances ..."
(( new_moonraker_obico_count == 1 )) && status_msg "Installing Obico ..."
### Step 5: Clone the moonraker-obico repo
clone_moonraker_obico "${MOONRAKER_OBICO_REPO}"
### step 6: call moonrake-obico/install.sh with the correct params
local port=7125
local instance_cfg_dirs
local instance_log_dirs
read -r -a instance_cfg_dirs <<< "$(get_instance_folder_path "config")"
read -r -a instance_log_dirs <<< "$(get_instance_folder_path "logs")"
if (( moonraker_count == 1 )); then
"${MOONRAKER_OBICO_DIR}/install.sh"\
-C "${instance_cfg_dirs[0]}/moonraker.conf"\
-p "${port}" -H 127.0.0.1 -l\
"${instance_log_dirs[0]}"\
-L -S "${obico_server_url}"
elif (( moonraker_count > 1 )); then
local j=${existing_moonraker_obico_count}
for (( i=1; i <= new_moonraker_obico_count; i++ )); do
"${MOONRAKER_OBICO_DIR}/install.sh"\
-n "${moonraker_names[${j}]}"\
-C "${instance_cfg_dirs[${j}]}/moonraker.conf"\
-p $((port+j))\
-H 127.0.0.1\
-l "${instance_log_dirs[${j}]}"\
-L -S "${obico_server_url}"
j=$(( j + 1 ))
done && unset j
fi # (( moonraker_count == 1 ))
fi # (( new_moonraker_obico_count > 0 ))
### Step 7: Link to the Obico server if necessary
local not_linked_instances=()
if (( moonraker_count == 1 )); then
if moonraker_obico_needs_linking "$(moonraker_obico_config 0)"; then
not_linked_instances+=("0")
fi
elif (( moonraker_count > 1 )); then
for (( i=0; i <= moonraker_count; i++ )); do
if moonraker_obico_needs_linking "$(moonraker_obico_config "${i}")"; then
not_linked_instances+=("${i}")
fi
done
fi # (( moonraker_count == 1 ))
if (( ${#not_linked_instances[@]} > 0 )); then
top_border
if (( moonraker_count == 1 )); then
printf "|${green}%-55s${white}|\n" " Obico not linked to the server!"
else
printf "|${green}%-55s${white}|\n" " ${#not_linked_instances[@]} Obico instances not linked to the server!"
for i in "${not_linked_instances[@]}"; do
printf "|${cyan}%-57s${white}|\n" " ● moonraker-obico-${moonraker_names[${i}]}"
done
fi
blank_line
echo -e "| It will take only 10 seconds to link printer to Obico.|"
echo -e "| For more information, visit: |"
echo -e "| https://www.obico.io/docs/user-guides/klipper-setup/ |"
blank_line
echo -e "| If you don't want to link the printer now, you can |"
echo -e "| restart the linking process later by: |"
echo -e "| 1. 'cd ~/kiauh && ./kiauh.sh' to launch KIAUH. |"
echo -e "| 2. Select ${green}[Install]${white} |"
echo -e "| 3. Select ${green}[Link to Obico Server]${white} |"
bottom_border
while true; do
read -p "${cyan}###### Link to your Obico Server account now? (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 Obico setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
if (( moonraker_count == 1 )); then
status_msg "Link moonraker-obico to the Obico Server..."
"${MOONRAKER_OBICO_DIR}/scripts/link.sh" -q -c "$(moonraker_obico_config 0)"
elif (( moonraker_count > 1 )); then
for i in "${not_linked_instances[@]}"; do
local name="${moonraker_names[i]}"
status_msg "Link moonraker-obico-${name} to the Obico Server..."
"${MOONRAKER_OBICO_DIR}/scripts/link.sh" -q -n "${name}" -c "$(moonraker_obico_config "${i}")"
done
fi # (( moonraker_count == 1 ))
fi # (( ${#not_linked_instances[@]} > 0 ))
}
function clone_moonraker_obico() {
local repo=${1}
status_msg "Cloning Obico from ${repo} ..."
### force remove existing Obico dir
[[ -d "${MOONRAKER_OBICO_DIR}" ]] && rm -rf "${MOONRAKER_OBICO_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${repo}" "${MOONRAKER_OBICO_DIR}"; then
print_error "Cloning Obico from\n ${repo}\n failed!"
exit 1
fi
}
function moonraker_obico_install() {
"${MOONRAKER_OBICO_DIR}/install.sh" "$@"
}
#===================================================#
#============= REMOVE MOONRAKER-OBICO ==============#
#===================================================#
function remove_moonraker_obico_systemd() {
[[ -z $(moonraker_obico_systemd) ]] && return
status_msg "Removing Obico Systemd Services ..."
for service in $(moonraker_obico_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 "Obico Services removed!"
}
function remove_moonraker_obico_logs() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/moonraker-obico(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_legacy_moonraker_obico_logs() {
local files regex="moonraker-obico(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/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_obico_dir() {
[[ ! -d ${MOONRAKER_OBICO_DIR} ]] && return
status_msg "Removing Obico directory ..."
rm -rf "${MOONRAKER_OBICO_DIR}"
ok_msg "Directory removed!"
}
function remove_moonraker_obico_env() {
[[ ! -d "${HOME}/moonraker-obico-env" ]] && return
status_msg "Removing moonraker-obico-env directory ..."
rm -rf "${HOME}/moonraker-obico-env"
ok_msg "Directory removed!"
}
function remove_moonraker_obico() {
remove_moonraker_obico_systemd
remove_moonraker_obico_logs
remove_moonraker_obico_dir
remove_moonraker_obico_env
print_confirm "Obico was successfully removed!"
return
}
#===================================================#
#============= UPDATE MOONRAKER-OBICO ==============#
#===================================================#
function update_moonraker_obico() {
do_action_service "stop" "moonraker-obico"
if [[ ! -d ${MOONRAKER_OBICO_DIR} ]]; then
clone_moonraker_obico "${MOONRAKER_OBICO_REPO}"
else
status_msg "Updating Obico ..."
cd "${MOONRAKER_OBICO_DIR}" && git pull
fi
"${MOONRAKER_OBICO_DIR}/install.sh" -U
ok_msg "Update complete!"
do_action_service "restart" "moonraker-obico"
}
#===================================================#
#============= MOONRAKER-OBICO STATUS ==============#
#===================================================#
function get_moonraker_obico_status() {
local status
local service_count
local is_linked
local moonraker_obico_services
moonraker_obico_services=$(moonraker_obico_systemd)
service_count=$(echo "${moonraker_obico_services}" | wc -w )
is_linked="true"
if [[ -n ${moonraker_obico_services} ]]; then
for cfg_dir in $(get_instance_folder_path "config"); do
if moonraker_obico_needs_linking "${cfg_dir}/moonraker-obico.cfg"; then
is_linked="false"
fi
done
fi
if (( service_count == 0 )); then
status="Not installed!"
elif [[ ! -d "${MOONRAKER_OBICO_DIR}" ]]; then
status="Incomplete!"
elif [[ ${is_linked} == "false" ]]; then
status="Not linked!"
else
status="Installed!"
fi
echo "${status}"
}
function get_local_moonraker_obico_commit() {
[[ ! -d ${MOONRAKER_OBICO_DIR} || ! -d "${MOONRAKER_OBICO_DIR}/.git" ]] && return
local commit
cd "${MOONRAKER_OBICO_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_moonraker_obico_commit() {
[[ ! -d ${MOONRAKER_OBICO_DIR} || ! -d "${MOONRAKER_OBICO_DIR}/.git" ]] && return
local commit
cd "${MOONRAKER_OBICO_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_moonraker_obico_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_moonraker_obico_commit)"
remote_ver="$(get_remote_moonraker_obico_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add moonraker to application_updates_available in kiauh.ini
add_to_application_updates "moonraker_obico"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}
###
# it is possible, that moonraker_obico is installed in a so called
# "non-linked" state. the linking can be achieved by running the
# installation script again. this function will check the obico
# installation status and returns the correctly formulated menu title
#
function obico_install_title() {
if [[ $(get_moonraker_obico_status) == "Not linked!" ]]; then
echo "[Link to Obico Server]"
else
echo "[Obico for Klipper] "
fi
}

369
scripts/octoapp.sh Normal file
View File

@@ -0,0 +1,369 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
#
# This file is written and maintained by Christian Würthner from OctoApp
# Please contact me if you need any help!
# hello@octoapp.eu
#
set -e
#===================================================#
#============== Install ============#
#===================================================#
function octoapp_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoapp(-[0-9a-zA-Z]+)?.service")
echo "${services}"
}
function octoapp_setup_dialog() {
status_msg "Initializing OctoApp for Klipper installation ..."
# First, check for moonraker service instances.
local moonraker_count
local moonraker_names
moonraker_count=$(moonraker_systemd | wc -w)
if (( moonraker_count == 0 )); then
### return early if moonraker is not installed
local error="Moonraker not installed! Please install Moonraker first!"
log_error "OctoApp setup started without Moonraker being installed. Aborting setup."
print_error "${error}" && return
elif (( moonraker_count > 1 )); then
# moonraker_names is valid only in case of multi-instance
read -r -a moonraker_names <<< "$(get_multi_instance_names)"
fi
# Next, check for any existing OctoApp services.
local octoapp_services
local existing_octoapp_count
octoapp_services=$(octoapp_systemd)
existing_octoapp_count=$(echo "${octoapp_services}" | wc -w )
# We need to make the moonraker instance count to the OctoApp service count.
local allowed_octoapp_count=$(( moonraker_count - existing_octoapp_count ))
if (( allowed_octoapp_count > 0 )); then
local new_octoapp_count
### Step 1: Ask for the number of OctoApp instances to install
if (( moonraker_count == 1 )); then
ok_msg "Moonraker installation found!\n"
new_octoapp_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" " ● moonraker-${name}"
done
blank_line
if (( existing_octoapp_count > 0 )); then
printf "|${green}%-55s${white}|\n" " ${existing_octoapp_count} OctoApp instances already installed!"
for svc in ${octoapp_services}; do
printf "|${cyan}%-57s${white}|\n" " ● octoapp-$(get_instance_name "${svc}")"
done
fi
blank_line
echo -e "| The setup will apply the same names to OctoApp |"
blank_line
echo -e "| Please select the number of OctoApp instances to |"
echo -e "| install. Usually one OctoApp instance per Moonraker |"
echo -e "| instance is required, but you may not install more |"
echo -e "| OctoApp instances than available Moonraker instances. |"
bottom_border
### ask for amount of instances
local re="^[1-9][0-9]*$"
while [[ ! ${new_octoapp_count} =~ ${re} || ${new_octoapp_count} -gt ${allowed_octoapp_count} ]]; do
read -p "${cyan}###### Number of new OctoApp instances to set up:${white} " -i "${allowed_octoapp_count}" -e new_octoapp_count
### break if input is valid
[[ ${new_octoapp_count} =~ ${re} && ${new_octoapp_count} -le ${allowed_octoapp_count} ]] && break
### conditional error messages
[[ ! ${new_octoapp_count} =~ ${re} ]] && error_msg "Input not a number"
(( new_octoapp_count > allowed_octoapp_count )) && error_msg "Number of OctoApp instances larger than installed Moonraker instances"
done && select_msg "${new_octoapp_count}"
else
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grater than one!"
return 1
fi # (( moonraker_count == 1 ))
fi # (( allowed_octoapp_count > 0 ))
# Special case for one moonraker instance with OctoApp already installed.
# If the user selects the install option again, they might be trying to recover the install
# or complete a printer link they didn't finish in the past.
# So in this case, we will allow them to run the install script again, since it's safe to run
# if the service is already installed, it will repair any missing issues.
if (( allowed_octoapp_count == 0 && moonraker_count == 1 )); then
local yn
while true; do
echo "${yellow}OctoApp is already installed.${white}"
echo "It is safe to run the install again to repair any issues or if the printer isn't linked, run the printer linking logic again."
echo ""
local question="Do you want to run the OctoApp recovery or linking logic again?"
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 OctoApp setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
# The user responded yes, allow the install to run again.
allowed_octoapp_count=1
fi
# If there's something to install, do it!
if (( allowed_octoapp_count > 0 )); then
(( new_octoapp_count > 1 )) && status_msg "Installing ${new_octoapp_count} OctoApp instances ..."
(( new_octoapp_count == 1 )) && status_msg "Installing OctoApp ..."
# Ensure the basic system dependencies are installed.
local dep=(git dfu-util virtualenv python3 python3-pip python3-venv)
dependency_check "${dep[@]}"
# Close the repo
clone_octoapp "${OCTOAPP_REPO}"
# Call install with the correct args.
local instance_cfg_dirs
read -r -a instance_cfg_dirs <<< "$(get_instance_folder_path "config")"
echo instance_cfg_dirs[0]
if (( moonraker_count == 1 )); then
"${OCTOAPP_DIR}/install.sh" "${instance_cfg_dirs[0]}/moonraker.conf"
elif (( moonraker_count > 1 )); then
local j=${existing_octoapp_count}
for (( i=1; i <= new_octoapp_count; i++ )); do
"${OCTOAPP_DIR}/install.sh" "${instance_cfg_dirs[${j}]}/moonraker.conf"
j=$(( j + 1 ))
done && unset j
fi # (( moonraker_count == 1 ))
fi # (( allowed_octoapp_count > 0 ))
}
function octoapp_install() {
"${OCTOAPP_DIR}/install.sh" "$@"
}
#===================================================#
#============= Remove ==============#
#===================================================#
function remove_octoapp_systemd() {
[[ -z $(octoapp_systemd) ]] && return
status_msg "Removing OctoApp Systemd Services ..."
for service in $(octoapp_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 "OctoApp Services removed!"
}
function remove_octoapp_logs() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/octoapp(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_octoapp_dir() {
[[ ! -d ${OCTOAPP_DIR} ]] && return
status_msg "Removing OctoApp directory ..."
rm -rf "${OCTOAPP_DIR}"
ok_msg "Directory removed!"
}
function remove_octoapp_config() {
# Remove the system config but not the main config, so the printer id doesn't get lost.
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/octoapp-system(-[0-9a-zA-Z]+)?\.cfg(.*)?"
files=$(find "${HOME}" -maxdepth 4 -regextype posix-extended -regex "${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_octoapp_store_dir() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/octoapp-store"
files=$(find "${HOME}" -maxdepth 2 -type d -regextype posix-extended -regex "${regex}" | 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_octoapp_env() {
[[ ! -d "${HOME}/octoapp-env" ]] && return
status_msg "Removing octoapp-env directory ..."
rm -rf "${HOME}/octoapp-env"
ok_msg "Directory removed!"
}
function remove_octoapp()
{
remove_octoapp_systemd
remove_octoapp_logs
remove_octoapp_dir
remove_octoapp_env
remove_octoapp_config
remove_octoapp_store_dir
print_confirm "OctoApp was successfully removed!"
return
}
#===================================================#
#============= UPDATE ==============#
#===================================================#
function update_octoapp() {
do_action_service "stop" "octoapp"
if [[ ! -d ${OCTOAPP_DIR} ]]; then
clone_octoapp "${OCTOAPP_REPO}"
else
backup_before_update "octoapp"
status_msg "Updating OctoApp for Klipper ..."
cd "${OCTOAPP_DIR}" && git pull
### read PKGLIST and install possible new dependencies
install_octoapp_dependencies
### install possible new python dependencies
"${OCTOAPP_ENV}"/bin/pip install -r "${OCTOAPP_DIR}/requirements.txt"
fi
ok_msg "Update complete!"
do_action_service "restart" "octoapp"
}
function clone_octoapp() {
local repo=${1}
status_msg "Cloning OctoApp from ${repo} ..."
### force remove existing octoapp dir and clone into fresh octoapp dir
[[ -d ${OCTOAPP_DIR} ]] && rm -rf "${OCTOAPP_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${OCTOAPP_REPO}" "${OCTOAPP_DIR}"; then
print_error "Cloning OctoApp from\n ${repo}\n failed!"
exit 1
fi
}
function install_octoapp_dependencies() {
local packages log_name="OctoApp"
local install_script="${OCTOAPP_DIR}/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 lists if stale
update_system_package_lists
### Install required packages
install_system_packages "${log_name}" "packages[@]"
}
#===================================================#
#============= STATUS ==============#
#===================================================#
function get_octoapp_status() {
local status
local service_count
local octoapp_services
octoapp_services=$(octoapp_systemd)
service_count=$(echo "${octoapp_services}" | wc -w )
if (( service_count == 0 )); then
status="Not installed!"
elif [[ ! -d "${OCTOAPP_DIR}" ]]; then
status="Incomplete!"
else
status="Installed!"
fi
echo "${status}"
}
function get_local_octoapp_commit() {
[[ ! -d ${OCTOAPP_DIR} || ! -d "${OCTOAPP_DIR}/.git" ]] && return
local commit
cd "${OCTOAPP_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_octoapp_commit() {
[[ ! -d ${OCTOAPP_DIR} || ! -d "${OCTOAPP_DIR}/.git" ]] && return
local commit
cd "${OCTOAPP_DIR}" && git fetch origin -q
commit=$(git describe origin/release --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_octoapp_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_octoapp_commit)"
remote_ver="$(get_remote_octoapp_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# Add us to the update file, so if the user selects "update all" it includes us.
add_to_application_updates "octoapp"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}

385
scripts/octoeverywhere.sh Normal file
View File

@@ -0,0 +1,385 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
#
# This file is written and maintained by Quinn Damerell from OctoEverywhere
# Please contact our support team if you need any help!
# https://octoeverywhere.com/support
#
set -e
#===================================================#
#============== Install ============#
#===================================================#
function octoeverywhere_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoeverywhere(-[0-9a-zA-Z]+)?.service")
echo "${services}"
}
function octoeverywhere_setup_dialog() {
status_msg "Initializing OctoEverywhere for Klipper installation ..."
# First, check for moonraker service instances.
local moonraker_count
local moonraker_names
moonraker_count=$(moonraker_systemd | wc -w)
if (( moonraker_count == 0 )); then
### return early if moonraker is not installed
local error="Moonraker not installed! Please install Moonraker first!"
log_error "OctoEverywhere setup started without Moonraker being installed. Aborting setup."
print_error "${error}" && return
elif (( moonraker_count > 1 )); then
# moonraker_names is valid only in case of multi-instance
read -r -a moonraker_names <<< "$(get_multi_instance_names)"
fi
# Next, check for any existing OctoEverywhere services.
local octoeverywhere_services
local existing_octoeverywhere_count
octoeverywhere_services=$(octoeverywhere_systemd)
existing_octoeverywhere_count=$(echo "${octoeverywhere_services}" | wc -w )
# We need to make the moonraker instance count to the OctoEverywhere service count.
local allowed_octoeverywhere_count=$(( moonraker_count - existing_octoeverywhere_count ))
if (( allowed_octoeverywhere_count > 0 )); then
local new_octoeverywhere_count
### Step 1: Ask for the number of OctoEverywhere instances to install
if (( moonraker_count == 1 )); then
ok_msg "Moonraker installation found!\n"
new_octoeverywhere_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" " ● moonraker-${name}"
done
blank_line
if (( existing_octoeverywhere_count > 0 )); then
printf "|${green}%-55s${white}|\n" " ${existing_octoeverywhere_count} OctoEverywhere instances already installed!"
for svc in ${octoeverywhere_services}; do
printf "|${cyan}%-57s${white}|\n" " ● octoeverywhere-$(get_instance_name "${svc}")"
done
fi
blank_line
echo -e "| The setup will apply the same names to |"
echo -e "| OctoEverywhere |"
blank_line
echo -e "| Please select the number of OctoEverywhere instances |"
echo -e "| to install. Usually one OctoEverywhere instance per |"
echo -e "| Moonraker instance is required, but you may not |"
echo -e "| install more OctoEverywhere instances than available |"
echo -e "| Moonraker instances. |"
bottom_border
### ask for amount of instances
local re="^[1-9][0-9]*$"
while [[ ! ${new_octoeverywhere_count} =~ ${re} || ${new_octoeverywhere_count} -gt ${allowed_octoeverywhere_count} ]]; do
read -p "${cyan}###### Number of new OctoEverywhere instances to set up:${white} " -i "${allowed_octoeverywhere_count}" -e new_octoeverywhere_count
### break if input is valid
[[ ${new_octoeverywhere_count} =~ ${re} && ${new_octoeverywhere_count} -le ${allowed_octoeverywhere_count} ]] && break
### conditional error messages
[[ ! ${new_octoeverywhere_count} =~ ${re} ]] && error_msg "Input not a number"
(( new_octoeverywhere_count > allowed_octoeverywhere_count )) && error_msg "Number of OctoEverywhere instances larger than installed Moonraker instances"
done && select_msg "${new_octoeverywhere_count}"
else
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grater than one!"
return 1
fi # (( moonraker_count == 1 ))
fi # (( allowed_octoeverywhere_count > 0 ))
# Special case for one moonraker instance with OctoEverywhere already installed.
# If the user selects the install option again, they might be trying to recover the install
# or complete a printer link they didn't finish in the past.
# So in this case, we will allow them to run the install script again, since it's safe to run
# if the service is already installed, it will repair any missing issues.
if (( allowed_octoeverywhere_count == 0 && moonraker_count == 1 )); then
local yn
while true; do
echo "${yellow}OctoEverywhere is already installed.${white}"
echo "It is safe to run the install again to repair any issues or if the printer isn't linked, run the printer linking logic again."
echo ""
local question="Do you want to run the OctoEverywhere recovery or linking logic again?"
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 OctoEverywhere setup ...\n"
return;;
*)
error_msg "Invalid Input!";;
esac
done
# The user responded yes, allow the install to run again.
allowed_octoeverywhere_count=1
fi
# If there's something to install, do it!
if (( allowed_octoeverywhere_count > 0 )); then
(( new_octoeverywhere_count > 1 )) && status_msg "Installing ${new_octoeverywhere_count} OctoEverywhere instances ..."
(( new_octoeverywhere_count == 1 )) && status_msg "Installing OctoEverywhere ..."
# Ensure the basic system dependencies are installed.
local dep=(git dfu-util virtualenv python3 python3-pip python3-venv)
dependency_check "${dep[@]}"
# Close the repo
clone_octoeverywhere "${OCTOEVERYWHERE_REPO}"
# Call install with the correct args.
local instance_cfg_dirs
read -r -a instance_cfg_dirs <<< "$(get_instance_folder_path "config")"
echo instance_cfg_dirs[0]
if (( moonraker_count == 1 )); then
"${OCTOEVERYWHERE_DIR}/install.sh" "${instance_cfg_dirs[0]}/moonraker.conf"
elif (( moonraker_count > 1 )); then
local j=${existing_octoeverywhere_count}
for (( i=1; i <= new_octoeverywhere_count; i++ )); do
"${OCTOEVERYWHERE_DIR}/install.sh" "${instance_cfg_dirs[${j}]}/moonraker.conf"
j=$(( j + 1 ))
done && unset j
fi # (( moonraker_count == 1 ))
fi # (( allowed_octoeverywhere_count > 0 ))
}
function clone_octoeverywhere() {
local repo=${1}
status_msg "Cloning OctoEverywhere..."
### force remove existing repos
[[ -d "${OCTOEVERYWHERE_DIR}" ]] && rm -rf "${OCTOEVERYWHERE_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${repo}" "${OCTOEVERYWHERE_DIR}"; then
print_error "Cloning OctoEverywhere from\n ${repo}\n failed!"
exit 1
fi
}
function octoeverywhere_install() {
"${OCTOEVERYWHERE_DIR}/install.sh" "$@"
}
#===================================================#
#============= Remove ==============#
#===================================================#
function remove_octoeverywhere_systemd() {
[[ -z $(octoeverywhere_systemd) ]] && return
status_msg "Removing OctoEverywhere Systemd Services ..."
for service in $(octoeverywhere_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 "OctoEverywhere Services removed!"
}
function remove_octoeverywhere_logs() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/octoeverywhere(-[0-9a-zA-Z]+)?\.log(.*)?"
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${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_octoeverywhere_dir() {
[[ ! -d ${OCTOEVERYWHERE_DIR} ]] && return
status_msg "Removing OctoEverywhere directory ..."
rm -rf "${OCTOEVERYWHERE_DIR}"
ok_msg "Directory removed!"
}
function remove_octoeverywhere_config() {
# Remove the system config but not the main config, so the printer id doesn't get lost.
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/octoeverywhere-system(-[0-9a-zA-Z]+)?\.cfg(.*)?"
files=$(find "${HOME}" -maxdepth 4 -regextype posix-extended -regex "${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_octoeverywhere_store_dir() {
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/octoeverywhere-store"
files=$(find "${HOME}" -maxdepth 2 -type d -regextype posix-extended -regex "${regex}" | 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_octoeverywhere_env() {
[[ ! -d "${HOME}/octoeverywhere-env" ]] && return
status_msg "Removing octoeverywhere-env directory ..."
rm -rf "${HOME}/octoeverywhere-env"
ok_msg "Directory removed!"
}
function remove_octoeverywhere()
{
remove_octoeverywhere_systemd
remove_octoeverywhere_logs
remove_octoeverywhere_dir
remove_octoeverywhere_env
remove_octoeverywhere_config
remove_octoeverywhere_store_dir
print_confirm "OctoEverywhere was successfully removed!"
return
}
#===================================================#
#============= UPDATE ==============#
#===================================================#
function update_octoeverywhere() {
do_action_service "stop" "octoeverywhere"
if [[ ! -d ${OCTOEVERYWHERE_DIR} ]]; then
clone_octoeverywhere "${OCTOEVERYWHERE_REPO}"
else
backup_before_update "octoeverywhere"
status_msg "Updating OctoEverywhere for Klipper ..."
cd "${OCTOEVERYWHERE_DIR}" && git pull
### read PKGLIST and install possible new dependencies
install_octoeverywhere_dependencies
### install possible new python dependencies
"${OCTOEVERYWHERE_ENV}"/bin/pip install -r "${OCTOEVERYWHERE_DIR}/requirements.txt"
fi
ok_msg "Update complete!"
do_action_service "restart" "octoeverywhere"
}
function clone_octoeverywhere() {
local repo=${1}
status_msg "Cloning OctoEverywhere from ${repo} ..."
### force remove existing octoeverywhere dir and clone into fresh octoeverywhere dir
[[ -d ${OCTOEVERYWHERE_DIR} ]] && rm -rf "${OCTOEVERYWHERE_DIR}"
cd "${HOME}" || exit 1
if ! git clone "${OCTOEVERYWHERE_REPO}" "${OCTOEVERYWHERE_DIR}"; then
print_error "Cloning OctoEverywhere from\n ${repo}\n failed!"
exit 1
fi
}
function install_octoeverywhere_dependencies() {
local packages log_name="OctoEverywhere"
local install_script="${OCTOEVERYWHERE_DIR}/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 lists if stale
update_system_package_lists
### Install required packages
install_system_packages "${log_name}" "packages[@]"
}
#===================================================#
#============= STATUS ==============#
#===================================================#
function get_octoeverywhere_status() {
local status
local service_count
local octoeverywhere_services
octoeverywhere_services=$(octoeverywhere_systemd)
service_count=$(echo "${octoeverywhere_services}" | wc -w )
if (( service_count == 0 )); then
status="Not installed!"
elif [[ ! -d "${OCTOEVERYWHERE_DIR}" ]]; then
status="Incomplete!"
else
status="Installed!"
fi
echo "${status}"
}
function get_local_octoeverywhere_commit() {
[[ ! -d ${OCTOEVERYWHERE_DIR} || ! -d "${OCTOEVERYWHERE_DIR}/.git" ]] && return
local commit
cd "${OCTOEVERYWHERE_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_octoeverywhere_commit() {
[[ ! -d ${OCTOEVERYWHERE_DIR} || ! -d "${OCTOEVERYWHERE_DIR}/.git" ]] && return
local commit
cd "${OCTOEVERYWHERE_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_octoeverywhere_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_octoeverywhere_commit)"
remote_ver="$(get_remote_octoeverywhere_commit)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# Add us to the update file, so if the user selects "update all" it includes us.
add_to_application_updates "octoeverywhere"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}

416
scripts/octoprint.sh Normal file
View File

@@ -0,0 +1,416 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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_services=$(klipper_systemd)
if [[ -z ${klipper_services} ]]; then
local error="Klipper not installed! Please install Klipper first!"
log_error "OctoPrint 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 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. klipper_count of '${klipper_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 printer_data octo_env service basedir printer config_yaml restart_cmd
for (( i=1; i <= octoprint_count; i++ )); do
if (( octoprint_count == 1 )); then
printer_data="${HOME}/printer_data"
octo_env="${HOME}/OctoPrint"
service="${SYSTEMD}/octoprint.service"
basedir="${HOME}/.octoprint"
printer="${printer_data}/comms/klippy.serial"
config_yaml="${basedir}/config.yaml"
restart_cmd="sudo service octoprint restart"
elif (( octoprint_count > 1 )); then
local re="^[1-9][0-9]*$"
if [[ ${names[j]} =~ ${re} ]]; then
printer_data="${HOME}/printer_${names[${j}]}_data"
else
printer_data="${HOME}/${names[${j}]}_data"
fi
octo_env="${HOME}/OctoPrint_${names[${j}]}"
service="${SYSTEMD}/octoprint-${names[${j}]}.service"
basedir="${HOME}/.octoprint_${names[${j}]}"
printer="${printer_data}/comms/klippy.serial"
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:
- ${printer}
disconnectOnErrors: false
port: ${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}"
}

127
scripts/pretty_gcode.sh Normal file
View File

@@ -0,0 +1,127 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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}/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/main --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
}
function compare_prettygcode_versions() {
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 moonraker to application_updates_available in kiauh.ini
add_to_application_updates "pgc_for_klipper"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}

View File

@@ -1,403 +0,0 @@
remove_klipper(){
### ask the user if he wants to uninstall moonraker too.
###? currently usefull if the user wants to switch from single-instance to multi-instance
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker*.")" ]; then
while true; do
unset REM_MR
top_border
echo -e "| Do you want to remove Moonraker afterwards? |"
echo -e "| |"
echo -e "| This is useful in case you want to switch from a |"
echo -e "| single-instance to a multi-instance installation, |"
echo -e "| which makes a re-installation of Moonraker necessary. |"
echo -e "| |"
echo -e "| If for any other reason you only want to uninstall |"
echo -e "| Klipper, please select 'No' and continue. |"
bottom_border
read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn
case "$yn" in
Y|y|Yes|yes)
echo -e "###### > Yes"
REM_MR="true"
break;;
N|n|No|no|"")
echo -e "###### > No"
REM_MR="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
fi
### remove "legacy" klipper init.d service
if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then
status_msg "Removing Klipper Service ..."
sudo systemctl stop klipper
sudo systemctl disable klipper
sudo rm -rf /etc/init.d/klipper /etc/default/klipper
sudo update-rc.d -f klipper remove
sudo systemctl daemon-reload
ok_msg "Klipper Service removed!"
fi
###remove single instance
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
status_msg "Removing Klipper Service ..."
sudo systemctl stop klipper
sudo systemctl disable klipper
sudo rm -f $SYSTEMDDIR/klipper.service
ok_msg "Klipper Service removed!"
fi
if [ -f /tmp/klippy.log ]; then
status_msg "Removing /tmp/klippy.log ..." && rm -f /tmp/klippy.log && ok_msg "Done!"
fi
if [ -e /tmp/klippy_uds ]; then
status_msg "Removing /tmp/klippy_uds ..." && rm -f /tmp/klippy_uds && ok_msg "Done!"
fi
if [ -h /tmp/printer ]; then
status_msg "Removing /tmp/printer ..." && rm -f /tmp/printer && ok_msg "Done!"
fi
###remove multi instance services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
status_msg "Removing Klipper Services ..."
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "klipper-*.service" | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
fi
###remove multi instance logfiles
if [ "$(find /tmp -maxdepth 1 -name "klippy-*.log")" ]; then
for logfile in $(find /tmp -maxdepth 1 -name "klippy-*.log")
do
status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
done
fi
###remove multi instance UDS
if [ "$(find /tmp -maxdepth 1 -name "klippy_uds-*")" ]; then
for uds in $(find /tmp -maxdepth 1 -name "klippy_uds-*")
do
status_msg "Removing $uds ..." && rm -f $uds && ok_msg "Done!"
done
fi
###remove multi instance tmp-printer
if [ "$(find /tmp -maxdepth 1 -name "printer-*")" ]; then
for tmp_printer in $(find /tmp -maxdepth 1 -name "printer-*")
do
status_msg "Removing $tmp_printer ..." && rm -f $tmp_printer && ok_msg "Done!"
done
fi
###reloading units
sudo systemctl daemon-reload
###removing klipper and klippy-env folders
if [ -d $KLIPPER_DIR ]; then
status_msg "Removing Klipper directory ..."
rm -rf $KLIPPER_DIR && ok_msg "Directory removed!"
fi
if [ -d $KLIPPY_ENV ]; then
status_msg "Removing klippy-env directory ..."
rm -rf $KLIPPY_ENV && ok_msg "Directory removed!"
fi
CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg
if [ "$REM_MR" == "true" ]; then
remove_moonraker
fi
}
#############################################################
#############################################################
remove_dwc2(){
### remove "legacy" init.d service
if [[ -e /etc/init.d/dwc || -e /etc/default/dwc ]]; then
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
sudo systemctl stop dwc
sudo systemctl disable dwc
sudo rm -rf /etc/init.d/dwc /etc/default/dwc
sudo update-rc.d -f dwc remove
sudo systemctl daemon-reload
ok_msg "DWC2-for-Klipper-Socket Service removed!"
fi
### remove single instance
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "dwc.service")" ]; then
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
sudo systemctl stop dwc
sudo systemctl disable dwc
sudo rm -f $SYSTEMDDIR/dwc.service
ok_msg "DWC2-for-Klipper-Socket Service removed!"
fi
if [ -f /tmp/dwc.log ]; then
status_msg "Removing /tmp/dwc.log ..." && rm -f /tmp/dwc.log && ok_msg "Done!"
fi
### remove multi instance services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service")" ]; then
status_msg "Removing DWC2-for-Klipper-Socket Services ..."
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "dwc-*.service" | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
fi
### remove multi instance logfiles
if [ "$(find /tmp -maxdepth 1 -name "dwc-*.log")" ]; then
for logfile in $(find /tmp -maxdepth 1 -name "dwc-*.log")
do
status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
done
fi
### reloading units
sudo systemctl daemon-reload
### removing the rest of the folders
if [ -d $DWC2FK_DIR ]; then
status_msg "Removing DWC2-for-Klipper-Socket directory ..."
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
fi
if [ -d $DWC_ENV_DIR ]; then
status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..."
rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!"
fi
if [ -d $DWC2_DIR ]; then
status_msg "Removing DWC2 directory ..."
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
fi
CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!"
}
#############################################################
#############################################################
remove_moonraker(){
### remove "legacy" moonraker init.d service
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then
status_msg "Removing Moonraker Service ..."
sudo systemctl stop moonraker
sudo systemctl disable moonraker
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker
sudo update-rc.d -f moonraker remove
sudo systemctl daemon-reload
ok_msg "Moonraker Service removed!"
fi
###remove single instance
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then
status_msg "Removing Moonraker Service ..."
sudo systemctl stop moonraker
sudo systemctl disable moonraker
sudo rm -f $SYSTEMDDIR/moonraker.service
ok_msg "Moonraker Service removed!"
fi
if [ -f /tmp/moonraker.log ]; then
status_msg "Removing /tmp/moonraker.log ..." && rm -f /tmp/moonraker.log && ok_msg "Done!"
fi
###remove multi instance services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
status_msg "Removing Moonraker Services ..."
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "moonraker-*.service" | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
fi
###remove multi instance logfiles
if [ "$(find /tmp -maxdepth 1 -name "moonraker-*.log")" ]; then
for logfile in $(find /tmp -maxdepth 1 -name "moonraker-*.log")
do
status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
done
fi
###reloading units
sudo systemctl daemon-reload
#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
###removing moonraker and moonraker-env folder
if [ -d $MOONRAKER_DIR ]; then
status_msg "Removing Moonraker directory ..."
rm -rf $MOONRAKER_DIR && ok_msg "Directory removed!"
fi
if [ -d $MOONRAKER_ENV ]; then
status_msg "Removing moonraker-env directory ..."
rm -rf $MOONRAKER_ENV && ok_msg "Directory removed!"
fi
CONFIRM_MSG=" Moonraker was successfully removed!"
}
#############################################################
#############################################################
remove_mainsail(){
### 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!"
}
remove_fluidd(){
### 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!"
}
#############################################################
#############################################################
remove_octoprint(){
###remove single instance
if [ "$(systemctl list-unit-files | grep -F "octoprint.service")" ]; then
status_msg "Removing OctoPrint Service ..."
sudo systemctl stop octoprint
sudo systemctl disable octoprint
sudo rm -f $SYSTEMDDIR/octoprint.service
ok_msg "OctoPrint Service removed!"
fi
###remove multi instance services
if [ "$(systemctl list-unit-files | grep -E "octoprint-[[:digit:]].service")" ]; then
status_msg "Removing OctoPrint Services ..."
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "octoprint-*.service" | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "OctoPrint Service removed!"
done
fi
###reloading units
sudo systemctl daemon-reload
### remove sudoers file
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
sudo rm -rf /etc/sudoers.d/octoprint-shutdown
fi
### remove OctoPrint directory
if [ -d ${HOME}/OctoPrint ]; then
status_msg "Removing OctoPrint directory ..."
rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!"
fi
###remove .octoprint directories
if [ "$(find ${HOME} -maxdepth 1 -name ".octoprint*")" ]; then
for folder in $(find ${HOME} -maxdepth 1 -name ".octoprint*")
do
status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!"
done
fi
CONFIRM_MSG=" OctoPrint successfully removed!"
}
#############################################################
#############################################################
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(){
### 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_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!"
}

View File

@@ -1,92 +1,85 @@
save_klipper_state(){ #!/usr/bin/env bash
source_kiauh_ini
#read current klipper state #=======================================================================#
cd $KLIPPER_DIR # Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
COMMIT_STATE=$(git rev-parse --short HEAD) # #
if [ "$GET_BRANCH" = "master" ]; then # This file is part of KIAUH - Klipper Installation And Update Helper #
ORI_OLD=$previous_origin_state # https://github.com/dw-0/kiauh #
ORI_NEW=$COMMIT_STATE # #
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE # This file may be distributed under the terms of the GNU GPLv3 license #
elif [ "$GET_BRANCH" = "scurve-shaping" ]; then #=======================================================================#
SHA_OLD=$previous_shaping_state
SHA_NEW=$COMMIT_STATE set -e
sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then function rollback_menu() {
SMO_OLD=$previous_smoothing_state top_border
SMO_NEW=$COMMIT_STATE echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") |"
sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE hr
fi echo -e "| If serious errors occured after updating Klipper or |"
echo -e "| Moonraker, you can use this menu to try and reset the |"
echo -e "| repository to an earlier state. |"
hr
echo -e "| 1) Rollback Klipper |"
echo -e "| 2) Rollback Moonraker |"
back_footer
local action
while true; do
read -p "${cyan}###### Perform action:${white} " action
case "${action}" in
1)
select_msg "Klipper"
rollback_component "klipper"
break;;
2)
select_msg "Moonraker"
rollback_component "moonraker"
break;;
B|b)
clear; advanced_menu; break;;
*)
error_msg "Invalid command!";;
esac
done
} }
load_klipper_state(){ function rollback_component() {
source_kiauh_ini local component=${1}
print_branch
cd $KLIPPER_DIR if [[ ! -d "${HOME}/${component}" ]]; then
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) print_error "Rollback not possible! Missing installation?"
if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then return
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 fi
CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT)
if [ "$PREVIOUS_COMMIT" != "0" ]; then echo
PREVIOUS_COMMIT_DATE=$(git show -s --format=%cd --date=short $PREVIOUS_COMMIT) top_border
fi echo -e "| Please select how many commits you want to revert. |"
if [ "$PREVIOUS_COMMIT" = "0" ]; then echo -e "| Consider using the information provided by the GitHub |"
CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") echo -e "| commit history to decide how many commits to revert. |"
PREV_UI=$(echo -e "${red}None${default} ") blank_line
else echo -e "| ${red}Warning:${white} |"
if [ "$CURRENT_COMMIT" = "$PREVIOUS_COMMIT" ]; then echo -e "| ${red}Do not proceed if you are currently in the progress${white} |"
CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") echo -e "| ${red}of printing! Proceeding WILL terminate that print!${white} |"
PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}") 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 else
CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") error_msg "Invalid command!"
PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}")
fi fi
fi done
rollback_ui rollback_menu
rollback_klipper
}
rollback_klipper(){
if [ "$PREVIOUS_COMMIT" != "0" ] && [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then
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
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)
clear; advanced_menu; break;;
*)
clear
print_header
print_unkown_cmd
print_msg && clear_msg
rollback_ui;;
esac
done
fi
} }

281
scripts/spoolman.sh Normal file
View File

@@ -0,0 +1,281 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
# Error Handling
set -e
function install_spoolman() {
pushd "${HOME}" &> /dev/null || exit 1
dependency_check curl jq
if [[ ! -d "${SPOOLMAN_DIR}" && -z "$(ls -A "${SPOOLMAN_DIR}" 2> /dev/null)" ]]; then
status_msg "Downloading spoolman..."
setup_spoolman_folder
status_msg "Downloading complete"
start_install_script
advanced_config_prompt
else
### In case spoolman is "incomplete" rerun install script
if get_spoolman_status | grep -q "Incomplete!"; then
start_install_script
exit 1
fi
ok_msg "Spoolman already installed"
exit 1
fi
enable_moonraker_integration_prompt
patch_spoolman_update_manager
do_action_service "restart" "moonraker"
}
function update_spoolman() {
### stop and disable old spoolman service
do_action_service "stop" "Spoolman"
do_action_service "disable" "Spoolman"
mv "${SPOOLMAN_DIR}" "${SPOOLMAN_DIR}_old"
setup_spoolman_folder
cp "${SPOOLMAN_DIR}_old/.env" "${SPOOLMAN_DIR}/.env"
start_install_script
rm -rf "${SPOOLMAN_DIR}_old"
}
function remove_spoolman(){
if [[ -d "${SPOOLMAN_DIR}" ]]; then
status_msg "Removing spoolman service..."
do_action_service "stop" "Spoolman"
do_action_service "disable" "Spoolman"
sudo rm -f "${SYSTEMD}/Spoolman.service"
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "Spoolman service removed!"
status_msg "Removing spoolman directory..."
rm -rf "${SPOOLMAN_DIR}"
ok_msg "Spoolman directory removed!"
fi
print_confirm "Spoolman successfully removed!"
}
function update_moonraker_configs() {
local moonraker_configs regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
for conf in ${moonraker_configs}; do
if ! grep -Eq "^\[update_manager Spoolman\]\s*$" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
${1}
MOONRAKER_CONF
fi
done
}
function enable_moonraker_integration() {
local integration_str env_port
# get spoolman port from .env
env_port=$(grep "^SPOOLMAN_PORT=" "${SPOOLMAN_DIR}/.env" | cut -d"=" -f2)
integration_str="
[spoolman]
server: http://$(hostname -I | cut -d" " -f1):${env_port}
"
status_msg "Adding Spoolman integration..."
update_moonraker_configs "${integration_str}"
}
function patch_spoolman_update_manager() {
local updater_str
updater_str="
[update_manager Spoolman]
type: zip
channel: stable
repo: Donkie/Spoolman
path: ${SPOOLMAN_DIR}
virtualenv: .venv
requirements: requirements.txt
persistent_files:
.venv
.env
managed_services: Spoolman
"
update_moonraker_configs "${updater_str}"
# add spoolman service to moonraker.asvc
local moonraker_asvc regex
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/moonraker\.asvc"
moonraker_asvc=$(find "${HOME}" -maxdepth 2 -type f -regextype posix-extended -regex "${regex}" | sort)
if ! grep -q "^Spoolman$" "${moonraker_asvc}"; then
status_msg "Adding Spoolman service to moonraker.asvc..."
sed -i '$a''Spoolman' "${moonraker_asvc}"
fi
}
function advanced_config_prompt() {
local reply
while true; do
read -erp "${cyan}###### Continue with default configuration? (Y/n):${white} " reply
case "${reply}" in
Y|y|Yes|yes|"")
select_msg "Yes"
break;;
N|n|No|no)
select_msg "No"
advanced_config
break;;
*)
error_msg "Invalid Input!\n";;
esac
done
return 0
}
function enable_moonraker_integration_prompt() {
local reply
while true; do
read -erp "${cyan}###### Enable Moonraker integration? (Y/n):${white} " reply
case "${reply}" in
Y|y|Yes|yes|"")
select_msg "Yes"
enable_moonraker_integration
break;;
N|n|No|no)
select_msg "No"
break;;
*)
error_msg "Invalid Input!\n";;
esac
done
return 0
}
function advanced_config() {
status_msg "###### Advanced configuration"
local reply
while true; do
read -erp "${cyan}###### Select spoolman port (7912):${white} " reply
### set default
if [[ -z "${reply}" ]]; then
reply="7912"
fi
select_msg "${reply}"
### check if port is valid
if ! [[ "${reply}" =~ ^[0-9]+$ && "${reply}" -ge 1024 && "${reply}" -le 65535 ]]; then
error_msg "Invalid port number!\n"
continue
fi
### update .env
sed -i "s/^SPOOLMAN_PORT=.*$/SPOOLMAN_PORT=${reply}/" "${SPOOLMAN_DIR}/.env"
do_action_service "restart" "Spoolman"
break
done
return 0
}
function setup_spoolman_folder() {
local source_url
### get latest spoolman release url
source_url="$(curl -s "${SPOOLMAN_REPO}" | jq -r '.assets[] | select(.name == "spoolman.zip").browser_download_url')"
mkdir -p "${SPOOLMAN_DIR}"
curl -sSL "${source_url}" -o /tmp/temp.zip
unzip /tmp/temp.zip -d "${SPOOLMAN_DIR}" &> /dev/null
rm /tmp/temp.zip
chmod +x "${SPOOLMAN_DIR}"/scripts/install.sh
}
function start_install_script() {
pushd "${SPOOLMAN_DIR}" &> /dev/null || exit 1
if bash ./scripts/install.sh; then
ok_msg "Spoolman successfully installed!"
else
print_error "Spoolman installation failed!"
exit 1
fi
}
function get_spoolman_status() {
local -a files
files=(
"${SPOOLMAN_DIR}"
"${SYSTEMD}/Spoolman.service"
"${SPOOLMAN_DB_DIR}"
)
local count
count=0
for file in "${files[@]}"; do
[[ -e "${file}" ]] && count=$(( count +1 ))
done
if [[ "${count}" -eq "${#files[*]}" ]]; then
echo "Installed"
elif [[ "${count}" -gt 0 ]]; then
echo "Incomplete!"
else
echo "Not installed!"
fi
}
function get_local_spoolman_version() {
[[ ! -d "${SPOOLMAN_DIR}" ]] && return
local version
version=$(grep -o '"version":\s*"[^"]*' "${SPOOLMAN_DIR}"/release_info.json | cut -d'"' -f4)
echo "${version}"
}
function get_remote_spoolman_version() {
[[ ! -d "${SPOOLMAN_DIR}" ]] && return
local version
version=$(curl -s "${SPOOLMAN_REPO}" | grep -o '"tag_name":\s*"v[^"]*"' | cut -d'"' -f4)
echo "${version}"
}
function compare_spoolman_versions() {
local local_ver remote_ver
local_ver="$(get_local_spoolman_version)"
remote_ver="$(get_remote_spoolman_version)"
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add spoolman to application_updates_available in kiauh.ini
add_to_application_updates "spoolman"
else
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
fi
echo "${versions}"
}

View File

@@ -1,519 +0,0 @@
kiauh_status(){
if [ -d "${SRCDIR}/kiauh/.git" ]; then
cd ${SRCDIR}/kiauh
if git branch -a | grep "* master" -q; then
git fetch -q
if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then
KIAUH_UPDATE_AVAIL="true"
fi
fi
fi
}
klipper_status(){
kcount=0
klipper_data=(
SERVICE
$KLIPPER_DIR
$KLIPPY_ENV_DIR
)
### count amount of klipper service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "klipper" | wc -l)
### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0]
### count+1 for each found data-item from array
for kd in "${klipper_data[@]}"
do
if [ -e $kd ]; then
kcount=$(expr $kcount + 1)
fi
done
### display status
if [ "$kcount" == "${#klipper_data[*]}" ]; then
KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
elif [ "$kcount" == 0 ]; then
KLIPPER_STATUS="${red}Not installed!${default} "
else
KLIPPER_STATUS="${yellow}Incomplete!${default} "
fi
}
dwc2_status(){
dcount=0
dwc_data=(
SERVICE
$DWC2_DIR
$DWC2FK_DIR
$DWC_ENV_DIR
)
### count amount of dwc service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "dwc" | wc -l)
### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0]
#count+1 for each found data-item from array
for dd in "${dwc_data[@]}"
do
if [ -e $dd ]; then
dcount=$(expr $dcount + 1)
fi
done
if [ "$dcount" == "${#dwc_data[*]}" ]; then
DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
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
)
### count amount of moonraker service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker" | wc -l)
### remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset moonraker_data[0]
### count+1 for each found data-item from array
for mrd in "${moonraker_data[@]}"
do
if [ -e $mrd ]; then
mrcount=$(expr $mrcount + 1)
fi
done
### display status
if [ "$mrcount" == "${#moonraker_data[*]}" ]; then
MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
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=(
SERVICE
$OCTOPRINT_DIR
)
### count amount of octoprint service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "octoprint" | wc -l)
### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0]
#count+1 for each found data-item from array
for op in "${octoprint_data[@]}"
do
if [ -e $op ]; then
ocount=$(expr $ocount + 1)
fi
done
### display status
if [ "$ocount" == "${#octoprint_data[*]}" ]; then
OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)"
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
)
### count amount of klipperscreen_data service files in /etc/systemd/system
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l)
### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed
[ $SERVICE_FILE_COUNT -gt 0 ] && unset klipperscreen_data[0]
#count+1 for each found data-item from array
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_dwc_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
if [ -e $MAINSAIL_DIR/.version ]; then
MAINSAIL_VER_FOUND="true"
MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/.version)
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 "%-12s" "$MAINSAIL_LOCAL_VER")${default}"
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then
MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}"
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
# set flag for the multi update function
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
else
MAINSAIL_LOCAL_VER=$NONE
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}"
MAINSAIL_UPDATE_AVAIL="false"
fi
}
read_local_fluidd_version(){
unset FLUIDD_VER_FOUND
if [ -e $FLUIDD_DIR/.version ]; then
FLUIDD_VER_FOUND="true"
FLUIDD_LOCAL_VER=$(head -n 1 $FLUIDD_DIR/.version)
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 "%-12s" "$FLUIDD_LOCAL_VER")${default}"
FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}"
elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then
FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}"
FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}"
# set flag for the multi update function
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
else
FLUIDD_LOCAL_VER=$NONE
FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$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
}

View File

@@ -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
}

View File

@@ -0,0 +1,144 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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
local num="^[0-9]+$"
local back="^(B|b)$"
local help="^(H|h)$"
while true; do
read -p "${cyan}###### Perform action:${white} " option
if [[ ${option} =~ ${num} && ${option} -lt ${#repos[@]} ]]; then
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
break
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"
break
fi
elif [[ ${option} =~ ${back} ]]; then
clear && print_header
settings_menu
elif [[ ${option} =~ ${help} ]]; then
clear && print_header
show_custom_klipper_repo_help
else
error_msg "Invalid command!"
fi
done
change_klipper_repo_menu
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function switch_klipper_repo() {
local repo=${1} branch=${2}
status_msg "Switching Klipper repository..."
do_action_service "stop" "klipper"
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
clone_klipper "${repo}" "${branch}"
do_action_service "start" "klipper"
}
function show_custom_klipper_repo_help() {
top_border
echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |"
hr
echo -e "| With this setting, it is possible to install Klipper |"
echo -e "| from a custom repository. It will also switch an |"
echo -e "| existing Klipper installation to the newly selected |"
echo -e "| source repository. |"
echo -e "| A list of repositories is automatically generated by |"
echo -e "| a 'klipper_repos.txt' textfile in KIAUHs root folder. |"
echo -e "| An example file is provided at the same location. |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
B|b)
clear && print_header
change_klipper_repo_menu
break;;
*)
deny_action "show_settings_help";;
esac
done
}

View File

@@ -1,62 +1,65 @@
advanced_ui(){ #!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function advanced_ui() {
top_border top_border
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} |"
hr hr
echo -e "| 0) $OPRINT_SERVICE_STATUS| " echo -e "| Klipper & API: | Mainsail: |"
hr echo -e "| 1) [Rollback] | 6) [Theme installer] |"
echo -e "| | | " echo -e "| | |"
echo -e "| Klipper: | System: | " echo -e "| Firmware: | System: |"
echo -e "| 1) [Switch Version] | 6) [Change hostname] | " echo -e "| 2) [Build only] | 7) [Change hostname] |"
echo -e "| 2) [Rollback] | | " echo -e "| 3) [Flash only] | |"
echo -e "| | Extensions: | " echo -e "| 4) [Build + Flash] | Extras: |"
echo -e "| Firmware: | 7) [Shell Command] | " echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] |"
echo -e "| 3) [Build only] | | " back_footer
echo -e "| 4) [Build + Flash MCU] | | "
echo -e "| 5) [Get MCU ID] | | "
echo -e "| | | "
quit_footer
} }
advanced_menu(){ function advanced_menu() {
read_octoprint_service_status
do_action "" "advanced_ui" do_action "" "advanced_ui"
local action
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}####### Perform action:${white} " action
case "$action" in case "${action}" in
0)
clear
print_header
toggle_octoprint_service
read_octoprint_service_status
print_msg && clear_msg
advanced_ui;;
1) 1)
do_action "switch_menu" "advanced_ui";; do_action "rollback_menu" "advanced_menu";;
2) 2)
do_action "load_klipper_state" "advanced_ui";;
3)
do_action "build_fw" "advanced_ui";; do_action "build_fw" "advanced_ui";;
3)
clear && print_header
do_action "init_flash_process" "advanced_ui";;
4) 4)
clear clear && print_header
print_header status_msg "Please wait..."
flash_routine build_fw && init_flash_process
### build in a sleep to give the user a chance to have a look at the
### MCU IDs before directly starting to build the klipper firmware
status_msg "Please wait..." && sleep 10 && build_fw
flash_mcu
print_msg && clear_msg
advanced_ui;; advanced_ui;;
5) 5)
do_action "get_mcu_id" "advanced_ui";; clear && print_header
select_mcu_connection
print_detected_mcu_to_screen
advanced_ui;;
6) 6)
do_action "ms_theme_installer_menu";;
7)
clear clear
print_header print_header
create_custom_hostname && set_hostname set_custom_hostname
print_msg && clear_msg
advanced_ui;; advanced_ui;;
7) 8)
do_action "setup_gcode_shell_command" "advanced_ui";; do_action "setup_gcode_shell_command" "advanced_ui";;
Q|q) B|b)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
deny_action "advanced_ui";; deny_action "advanced_ui";;
@@ -64,92 +67,3 @@ advanced_menu(){
done done
advanced_menu 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
do_action "" "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;;
*)
deny_action "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
}

View File

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

View File

@@ -1,27 +1,52 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#ui total width = 57 chars #ui total width = 57 chars
top_border(){ function top_border() {
echo -e "/=======================================================\ " echo -e "/=======================================================\\"
} }
bottom_border(){ function bottom_border() {
echo -e "\=======================================================/" echo -e "\=======================================================/"
} }
blank_line(){ function blank_line() {
echo -e "| | " echo -e "| |"
} }
hr(){ function hr() {
echo -e "|-------------------------------------------------------|" echo -e "|-------------------------------------------------------|"
} }
quit_footer(){ function quit_footer() {
hr hr
echo -e "| ${red}Q) Quit${default} | " echo -e "| ${red}Q) Quit${white} |"
bottom_border 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 top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |" echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |"
echo -e "| $(title_msg " Klipper Installation And Update Helper ") |" echo -e "| $(title_msg " Klipper Installation And Update Helper ") |"
@@ -29,33 +54,17 @@ print_header(){
bottom_border bottom_border
} }
kiauh_update_msg(){ function do_action() {
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
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
### TODO: rework other menus to make use of the following functions too and make them more readable
do_action(){
clear && print_header clear && print_header
### $1 is the action the user wants to fire ### $1 is the action the user wants to fire
$1 $1
print_msg && clear_msg # print_msg && clear_msg
### $2 is the menu the user usually gets directed back to after an action is completed ### $2 is the menu the user usually gets directed back to after an action is completed
$2 $2
} }
deny_action(){ function deny_action() {
clear && print_header clear && print_header
print_unkown_cmd print_error "Invalid command!"
print_msg && clear_msg
$1 $1
} }

View File

@@ -1,44 +1,84 @@
install_ui(){ #!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function install_ui() {
top_border top_border
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} |"
hr hr
echo -e "| You need this menu usually only for installing | " echo -e "| You need this menu usually only for installing |"
echo -e "| all necessary dependencies for the various | " echo -e "| all necessary dependencies for the various |"
echo -e "| functions on a completely fresh system. | " echo -e "| functions on a completely fresh system. |"
hr hr
echo -e "| Firmware: | Klipper Webinterface: | " echo -e "| Firmware & API: | Other: |"
echo -e "| 1) [Klipper] | 3) [Mainsail] | " echo -e "| 1) [Klipper] | 7) [PrettyGCode] |"
echo -e "| | 4) [Fluidd] | " echo -e "| 2) [Moonraker] | 8) [Telegram Bot] |"
echo -e "| Klipper API: | | " echo -e "| | 9) $(obico_install_title) |"
echo -e "| 2) [Moonraker] | HDMI Screen: | " echo -e "| Klipper Webinterface: | 10) [OctoEverywhere] |"
echo -e "| | 5) [KlipperScreen] | " echo -e "| 3) [Mainsail] | 11) [Mobileraker] |"
echo -e "| | | " echo -e "| 4) [Fluidd] | 12) [OctoApp for Klipper] |"
echo -e "| | Other: | " echo -e "| | 13) [Spoolman] |"
echo -e "| | 6) [Duet Web Control] | " echo -e "| Touchscreen GUI: | |"
echo -e "| | 7) [OctoPrint] | " echo -e "| 5) [KlipperScreen] | Webcam Streamer: |"
quit_footer echo -e "| | 14) [Crowsnest] |"
echo -e "| 3rd Party Webinterface: | |"
echo -e "| 6) [OctoPrint] | |"
back_footer
} }
install_menu(){ function install_menu() {
do_action "" "install_ui" clear -x && sudo true && clear -x # (re)cache sudo credentials so password prompt doesn't bork ui
print_header
install_ui
### save all installed webinterface ports to the ini file
fetch_webui_ports
### save all klipper multi-instance names to the ini file
set_multi_instance_names
local action
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}####### Perform action:${white} " action
case "$action" in case "${action}" in
1) 1)
do_action "klipper_setup_dialog" "install_ui";; do_action "start_klipper_setup" "install_ui";;
2) 2)
do_action "moonraker_setup_dialog" "install_ui";; do_action "moonraker_setup_dialog" "install_ui";;
3) 3)
do_action "install_webui mainsail" "install_ui";; do_action "install_mainsail" "install_ui";;
4) 4)
do_action "install_webui fluidd" "install_ui";; do_action "install_fluidd" "install_ui";;
5) 5)
do_action "install_klipperscreen" "install_ui";; do_action "install_klipperscreen" "install_ui";;
6) 6)
do_action "dwc_setup_dialog" "install_ui";;
7)
do_action "octoprint_setup_dialog" "install_ui";; do_action "octoprint_setup_dialog" "install_ui";;
Q|q) 7)
do_action "install_pgc_for_klipper" "install_ui";;
8)
do_action "telegram_bot_setup_dialog" "install_ui";;
9)
do_action "moonraker_obico_setup_dialog" "install_ui";;
10)
do_action "octoeverywhere_setup_dialog" "install_ui";;
11)
do_action "install_mobileraker" "install_ui";;
12)
do_action "octoapp_setup_dialog" "install_ui";;
13)
do_action "install_spoolman" "install_ui";;
14)
do_action "install_crowsnest" "install_ui";;
B|b)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
deny_action "install_ui";; deny_action "install_ui";;

View File

@@ -1,94 +1,142 @@
main_ui(){ #!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function main_ui() {
top_border top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr hr
echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|" echo -e "| 0) [Log-Upload] | Klipper: $(print_status "klipper")|"
echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|" echo -e "| | Repo: $(print_klipper_repo)|"
echo -e "| 1) [Install] | |" 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 "| 3) [Remove] | |"
echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|"
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|"
echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" echo -e "| | KlipperScreen: $(print_status "klipperscreen")|"
echo -e "| 6) [Settings] | |" echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|"
echo -e "| | DWC2: $DWC2_STATUS|" echo -e "| | Crowsnest: $(print_status "crowsnest")|"
echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" echo -e "| | Obico: $(print_status "moonraker_obico")|"
echo -e "| | OctoEverywhere: $(print_status "octoeverywhere")|"
echo -e "| | Mobileraker: $(print_status "mobileraker")|"
echo -e "| | OctoApp: $(print_status "octoapp")|"
echo -e "| | Spoolman: $(print_status "spoolman")|"
echo -e "| | |"
echo -e "| | Octoprint: $(print_status "octoprint")|"
hr
echo -e "| $(print_kiauh_version)| Changelog: ${magenta}https://git.io/JnmlX${white} |"
quit_footer quit_footer
} }
print_kiauh_version(){ function get_kiauh_version() {
cd ${SRCDIR}/kiauh local version
KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) cd "${KIAUH_SRCDIR}"
KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")" version="$(git tag -l 'v5*' | tail -1)"
echo "${version}"
} }
main_menu(){ function print_kiauh_version() {
print_header local version
#print KIAUH update msg if update available version="$(printf "%-16s" "$(get_kiauh_version)")"
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then echo "${cyan}${version}${white}"
kiauh_update_msg }
fi
#check install status function print_status() {
print_kiauh_version local status component="${1}"
klipper_status status=$(get_"${component}"_status)
moonraker_status
dwc2_status if [[ ${status} == "Not installed!" ]]; then
fluidd_status status="${red}${status}${white}"
mainsail_status elif [[ ${status} == "Incomplete!" ]]; then
octoprint_status status="${yellow}${status}${white}"
klipperscreen_status elif [[ ${status} == "Not linked!" ]]; then
print_branch ### "Not linked!" is only required for Obico for Klipper
print_msg && clear_msg status="${yellow}${status}${white}"
else
status="${green}${status}${white}"
fi
printf "%-28s" "${status}"
}
function print_klipper_repo() {
read_kiauh_ini
local repo klipper_status
klipper_status=$(get_klipper_status)
repo=$(echo "${custom_klipper_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//")
repo="${repo^^}"
if [[ ${klipper_status} == "Not installed!" ]]; then
repo="${red}-${white}"
elif [[ -n ${repo} && ${repo} != "KLIPPER3D/KLIPPER" ]]; then
repo="${cyan}custom${white}"
else
repo="${cyan}Klipper3d/klipper${white}"
fi
printf "%-28s" "${repo}"
}
function main_menu() {
clear && print_header
main_ui main_ui
local action
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}####### Perform action:${white} " action
case "$action" in case "${action}" in
"start klipper") "start klipper") do_action_service "start" "klipper"; main_ui;;
do_action "klipper_service start" "main_ui";; "stop klipper") do_action_service "stop" "klipper"; main_ui;;
"stop klipper") "restart klipper") do_action_service "restart" "klipper"; main_ui;;
do_action "klipper_service stop" "main_ui";; "start moonraker") do_action_service "start" "moonraker"; main_ui;;
"restart klipper") "stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
do_action "klipper_service restart" "main_ui";; "restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
"start moonraker") "start octoprint") do_action_service "start" "octoprint"; main_ui;;
do_action "moonraker_service start" "main_ui";; "stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
"stop moonraker") "restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
do_action "moonraker_service stop" "main_ui";; "start crowsnest") do_action_service "start" "crowsnest"; main_ui;;
"restart moonraker") "stop crowsnest") do_action_service "stop" "crowsnest"; main_ui;;
do_action "moonraker_service restart" "main_ui";; "restart crowsnest") do_action_service "restart" "crowsnest"; main_ui;;
"start dwc") update) do_action "update_kiauh" "main_ui";;
do_action "dwc_service start" "main_ui";; 0)clear && print_header
"stop dwc") upload_selection
do_action "dwc_service stop" "main_ui";; main_ui;;
"restart dwc") 1)clear && print_header
do_action "dwc_service restart" "main_ui";; install_menu
"start octoprint") break;;
do_action "octoprint_service start" "main_ui";; 2) clear && print_header
"stop octoprint") update_menu
do_action "octoprint_service stop" "main_ui";; break;;
"restart octoprint") 3) clear && print_header
do_action "octoprint_service restart" "main_ui";; remove_menu
update) break;;
do_action "update_kiauh" "main_ui";; 4)clear && print_header
0) advanced_menu
do_action "upload_selection" "main_ui";; break;;
1) 5)clear && print_header
clear && install_menu && break;; backup_menu
2) main_ui;;
clear && update_menu && break;; 6)clear && print_header
3) settings_menu
clear && remove_menu && break;; break;;
4)
clear && advanced_menu && break;;
5)
clear && backup_menu && break;;
6)
clear && settings_menu && break;;
Q|q) Q|q)
echo -e "${green}###### Happy printing! ######${default}"; echo echo -e "${green}###### Happy printing! ######${white}"; echo
exit -1;; exit 0;;
*) *)
deny_action "main_ui";; deny_action "main_ui";;
esac esac
done done
clear; main_menu main_menu
} }

View File

@@ -1,31 +1,47 @@
remove_ui(){ #!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function remove_ui() {
top_border top_border
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} |"
hr hr
echo -e "| Directories which remain untouched: | " echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |"
echo -e "| --> Your printer configuration directory | "
echo -e "| --> ~/kiauh-backups | "
echo -e "| You need remove them manually if you wish so. | "
hr hr
echo -e "| Firmware: | Klipper Webinterface: | " echo -e "| Firmware & API: | Webcam Streamer: |"
echo -e "| 1) [Klipper] | 3) [Mainsail] | " echo -e "| 1) [Klipper] | 9) [Crowsnest] |"
echo -e "| | 4) [Fluidd] | " echo -e "| 2) [Moonraker] | 10) [MJPG-Streamer] |"
echo -e "| Klipper API: | | " echo -e "| | |"
echo -e "| 2) [Moonraker] | HDMI Screen: | " echo -e "| Klipper Webinterface: | Other: |"
echo -e "| | 5) [KlipperScreen] | " echo -e "| 3) [Mainsail] | 11) [PrettyGCode] |"
echo -e "| | | " echo -e "| 4) [Mainsail-Config] | 12) [Telegram Bot] |"
echo -e "| | Other: | " echo -e "| 5) [Fluidd] | 13) [Obico for Klipper] |"
echo -e "| | 6) [Duet Web Control] | " echo -e "| 6) [Fluidd-Config] | 14) [OctoEverywhere] |"
echo -e "| | 7) [OctoPrint] | " echo -e "| | 15) [Mobileraker] |"
echo -e "| | 8) [NGINX] | " echo -e "| Touchscreen GUI: | 16) [NGINX] |"
quit_footer echo -e "| 7) [KlipperScreen] | 17) [OctoApp] |"
echo -e "| | 18) [Spoolman] |"
echo -e "| 3rd Party Webinterface: | |"
echo -e "| 8) [OctoPrint] | |"
back_footer
} }
remove_menu(){ function remove_menu() {
do_action "" "remove_ui" do_action "" "remove_ui"
local action
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}####### Perform action:${white} " action
case "$action" in case "${action}" in
1) 1)
do_action "remove_klipper" "remove_ui";; do_action "remove_klipper" "remove_ui";;
2) 2)
@@ -33,16 +49,36 @@ remove_menu(){
3) 3)
do_action "remove_mainsail" "remove_ui";; do_action "remove_mainsail" "remove_ui";;
4) 4)
do_action "remove_fluidd" "remove_ui";; do_action "remove_mainsail_config" "remove_ui";;
5) 5)
do_action "remove_klipperscreen" "remove_ui";; do_action "remove_fluidd" "remove_ui";;
6) 6)
do_action "remove_dwc2" "remove_ui";; do_action "remove_fluidd_config" "remove_ui";;
7) 7)
do_action "remove_octoprint" "remove_ui";; do_action "remove_klipperscreen" "remove_ui";;
8) 8)
do_action "remove_octoprint" "remove_ui";;
9)
do_action "remove_crowsnest" "remove_ui";;
10)
do_action "remove_mjpg-streamer" "remove_ui";;
11)
do_action "remove_prettygcode" "remove_ui";;
12)
do_action "remove_telegram_bot" "remove_ui";;
13)
do_action "remove_moonraker_obico" "remove_ui";;
14)
do_action "remove_octoeverywhere" "remove_ui";;
15)
do_action "remove_mobileraker" "remove_ui";;
16)
do_action "remove_nginx" "remove_ui";; do_action "remove_nginx" "remove_ui";;
Q|q) 17)
do_action "remove_octoapp" "remove_ui";;
18)
do_action "remove_spoolman" "remove_ui";;
B|b)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
deny_action "remove_ui";; deny_action "remove_ui";;

View File

@@ -1,44 +1,166 @@
settings_ui(){ #!/usr/bin/env bash
source_kiauh_ini
top_border #=======================================================================#
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | " # Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
hr # #
echo -e "| ${red}Caution:${default} | " # This file is part of KIAUH - Klipper Installation And Update Helper #
echo -e "| When you change the config folder, be aware that ALL | " # https://github.com/dw-0/kiauh #
echo -e "| Klipper and Moonraker services will be STOPPED, | " # #
echo -e "| reconfigured and then restarted again. | " # This file may be distributed under the terms of the GNU GPLv3 license #
blank_line #=======================================================================#
echo -e "| ${red}DO NOT change the folder during printing!${default} | "
hr set -e
blank_line
echo -e "| ${cyan}● Current Klipper config folder:${default} | " function settings_ui() {
printf "|%-55s|\n" " $klipper_cfg_loc" read_kiauh_ini "${FUNCNAME[0]}"
blank_line
hr local custom_repo="${custom_klipper_repo}"
if [ -z $klipper_cfg_loc ]; then local custom_branch="${custom_klipper_repo_branch}"
echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${default} | " local ms_pre_rls="${mainsail_install_unstable}"
local fl_pre_rls="${fluidd_install_unstable}"
local bbu="${backup_before_update}"
### 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 else
echo -e "| 1) Change config folder | " custom_repo="${cyan}${custom_repo}${white}"
fi fi
quit_footer
### 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 "| ● 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) Set custom Klipper repository |"
blank_line
if [[ ${mainsail_install_unstable} == "false" ]]; then
echo -e "| 2) ${green}Allow${white} unstable Mainsail releases |"
else
echo -e "| 2) ${red}Disallow${white} unstable Mainsail releases |"
fi
if [[ ${fluidd_install_unstable} == "false" ]]; then
echo -e "| 3) ${green}Allow${white} unstable Fluidd releases |"
else
echo -e "| 3) ${red}Disallow${white} unstable Fluidd releases |"
fi
blank_line
if [[ ${backup_before_update} == "false" ]]; then
echo -e "| 4) ${green}Enable${white} automatic backups before updates |"
else
echo -e "| 4) ${red}Disable${white} automatic backups before updates |"
fi
back_help_footer
} }
settings_menu(){ function show_settings_help() {
do_action "" "settings_ui" local default_cfg="${cyan}${HOME}/klipper_config${white}"
top_border
echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |"
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 while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}###### Please select:${white} " choice
case "$action" in 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) 1)
if [ ! -z $klipper_cfg_loc ]; then clear && print_header
do_action "change_klipper_cfg_path" "settings_ui" change_klipper_repo_menu
else settings_ui;;
deny_action "settings_ui" 2)
fi;; switch_mainsail_releasetype
Q|q) settings_menu;;
clear; main_menu; break;; 3)
switch_fluidd_releasetype
settings_menu;;
4)
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";; deny_action "settings_ui";;
esac esac
done done
settings_ui
} }

View File

@@ -1,107 +1,172 @@
update_ui(){ #!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function update_ui() {
top_border top_border
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} |"
hr hr
echo -e "| Check the following website for important software | " echo -e "| a) [Update all] | | |"
echo -e "| changes to the config file before updating Klipper: | " echo -e "| | Installed: | Latest: |"
echo -e "| | " echo -e "| Klipper & API: |---------------|--------------|"
echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | " echo -e "| 1) [Klipper] |$(compare_klipper_versions)|"
bottom_border echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)|"
top_border echo -e "| | | |"
echo -e "| 0) $BB4U_STATUS| " echo -e "| Klipper Webinterface: |---------------|--------------|"
hr echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)|"
echo -e "| a) [Update all] | Local Vers: | Remote Vers: | " echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)|"
echo -e "| | | | " echo -e "| | | |"
echo -e "| Firmware: | | | " echo -e "| Touchscreen GUI: |---------------|--------------|"
echo -e "| 1) [Klipper] | $LOCAL_COMMIT | $REMOTE_COMMIT | " echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)|"
echo -e "| | | | " echo -e "| | | |"
echo -e "| Webinterface: |---------------|--------------| " echo -e "| Other: |---------------|--------------|"
echo -e "| 2) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | " echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)|"
echo -e "| 3) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | " echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)|"
echo -e "| |---------------|--------------| " echo -e "| 8) [Obico for Klipper]|$(compare_moonraker_obico_versions)|"
echo -e "| 4) [Moonraker] | $LOCAL_MOONRAKER_COMMIT | $REMOTE_MOONRAKER_COMMIT | " echo -e "| 9) [OctoEverywhere] |$(compare_octoeverywhere_versions)|"
echo -e "| 5) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | " echo -e "| 10) [Mobileraker] |$(compare_mobileraker_versions)|"
echo -e "| 6) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | " echo -e "| 11) [Crowsnest] |$(compare_crowsnest_versions)|"
echo -e "| | | | " echo -e "| 12) [OctoApp] |$(compare_octoapp_versions)|"
echo -e "| HDMI Screen: |---------------|--------------| " echo -e "| 13) [Spoolman] |$(compare_spoolman_versions)|"
echo -e "| 7) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | " echo -e "| |------------------------------|"
quit_footer echo -e "| 14) [System] | $(check_system_updates) |"
back_footer
} }
update_menu(){ function update_menu() {
print_header clear -x && sudo true && clear -x # (re)cache sudo credentials so password prompt doesn't bork ui
#compare versions do_action "" "update_ui"
ui_print_versions
print_msg && clear_msg local action
read_bb4u_stat
update_ui
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo read -p "${cyan}####### Perform action:${white} " action
case "$action" in case "${action}" in
0) 0)
clear do_action "toggle_backups" "update_ui";;
print_header
toggle_backups
print_msg && clear_msg
update_ui;;
1) 1)
clear do_action "update_klipper" "update_ui";;
print_header
update_klipper && ui_print_versions
print_msg && clear_msg
update_ui;;
2) 2)
clear do_action "update_moonraker" "update_ui";;
print_header
update_dwc2fk && ui_print_versions
print_msg && clear_msg
update_ui;;
3) 3)
clear do_action "update_mainsail" "update_ui";;
print_header
update_dwc2 && ui_print_versions
print_msg && clear_msg
update_ui;;
4) 4)
clear do_action "update_fluidd" "update_ui";;
print_header
update_moonraker && ui_print_versions
print_msg && clear_msg
update_ui;;
5) 5)
clear do_action "update_klipperscreen" "update_ui";;
print_header
update_mainsail && ui_print_versions
print_msg && clear_msg
update_ui;;
6) 6)
clear do_action "update_pgc_for_klipper" "update_ui";;
print_header
update_fluidd && ui_print_versions
print_msg && clear_msg
update_ui;;
7) 7)
clear do_action "update_telegram_bot" "update_ui";;
print_header 8)
update_klipperscreen && ui_print_versions do_action "update_moonraker_obico" "update_ui";;
print_msg && clear_msg 9)
update_ui;; do_action "update_octoeverywhere" "update_ui";;
10)
do_action "update_mobileraker" "update_ui";;
11)
do_action "update_crowsnest" "update_ui";;
12)
do_action "update_octoapp" "update_ui";;
13)
do_action "update_spoolman" "update_ui";;
14)
do_action "upgrade_system_packages" "update_ui";;
a) a)
clear do_action "update_all" "update_ui";;
print_header B|b)
update_all && ui_print_versions
print_msg && clear_msg
update_ui;;
Q|q)
clear; main_menu; break;; clear; main_menu; break;;
*) *)
clear deny_action "update_ui";;
print_header
print_unkown_cmd
print_msg && clear_msg
ui_print_versions
update_ui;;
esac esac
done done
update_menu update_menu
} }
function update_all() {
read_kiauh_ini "${FUNCNAME[0]}"
local update_arr
local app_update_state="${application_updates_available}"
IFS=', ' read -r -a update_arr <<< "${app_update_state}"
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: |"
[[ "${update_arr[*]}" =~ "klipper" ]] && \
echo -e "| ${cyan}● Klipper${white} |"
[[ "${update_arr[*]}" =~ "moonraker" ]] && \
echo -e "| ${cyan}● Moonraker${white} |"
[[ "${update_arr[*]}" =~ "mainsail" ]] && \
echo -e "| ${cyan}● Mainsail${white} |"
[[ "${update_arr[*]}" =~ "fluidd" ]] && \
echo -e "| ${cyan}● Fluidd${white} |"
[[ "${update_arr[*]}" =~ "klipperscreen" ]] && \
echo -e "| ${cyan}● KlipperScreen${white} |"
[[ "${update_arr[*]}" =~ "spoolman" ]] && \
echo -e "| ${cyan}● SpoolMan${white} |"
[[ "${update_arr[*]}" =~ "pgc_for_klipper" ]] && \
echo -e "| ${cyan}● PrettyGCode for Klipper${white} |"
[[ "${update_arr[*]}" =~ "telegram_bot" ]] && \
echo -e "| ${cyan}● MoonrakerTelegramBot${white} |"
[[ "${update_arr[*]}" =~ "octoeverywhere" ]] && \
echo -e "| ${cyan}● OctoEverywhere${white} |"
[[ "${update_arr[*]}" =~ "mobileraker" ]] && \
echo -e "| ${cyan}● Mobileraker${white} |"
[[ "${update_arr[*]}" =~ "octoapp" ]] && \
echo -e "| ${cyan}● OctoApp${white} |"
[[ "${update_arr[*]}" =~ "system" ]] && \
echo -e "| ${cyan}● System${white} |"
bottom_border
local yn
read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
local component
local update
for component in "${update_arr[@]}"; do
if [[ ${component} == "system" ]]; then
update="upgrade_system_packages"
else
update="update_${component}"
fi
#shellcheck disable=SC2250
$update
done
break;;
N|n|No|no)
break;;
*)
error_msg "Invalid command!";;
esac
done
}

View File

@@ -1,168 +0,0 @@
update_kiauh(){
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
status_msg "Updating KIAUH ..."
cd ${SRCDIR}/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(){
klipper_service "stop"
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
KLIPPER_OLDREQ_MD5SUM="$(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1)"
if [ "$DETACHED_HEAD" == "true" ]; then
git checkout $GET_BRANCH
unset DETACHED_HEAD
fi
### pull latest files from github
git pull && ok_msg "Update successfull!"
### check for possible new dependencies and install them
if [[ $(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1) != $KLIPPER_OLDREQ_MD5SUM ]]; then
PYTHONDIR="${HOME}/klippy-env"
status_msg "New dependecies detected..."
### always rebuild the pythondir from scratch if new dependencies were detected
rm -rf ${PYTHONDIR}
virtualenv -p python2 ${PYTHONDIR}
$PYTHONDIR/bin/pip install -r $KLIPPER_DIR/scripts/klippy-requirements.txt
ok_msg "Dependencies have been installed!"
fi
ok_msg "Update complete!"
fi
klipper_service "restart"
}
update_dwc2fk(){
dwc_service "stop"
bb4u "dwc2"
if [ ! -d $DWC2FK_DIR ]; then
cd ${HOME} && git clone $DWC2FK_REPO
else
cd $DWC2FK_DIR && git pull
fi
dwc_service "start"
}
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(){
moonraker_service "stop"
bb4u "moonraker"
status_msg "Updating Moonraker ..."
cd $MOONRAKER_DIR
MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
### pull latest files from github
git pull && ok_msg "Update successfull!"
### check for possible new dependencies and install them
if [[ $(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1) != $MOONRAKER_OLDREQ_MD5SUM ]]; then
PYTHONDIR="${HOME}/moonraker-env"
status_msg "New dependecies detected..."
### always rebuild the pythondir from scratch if new dependencies were detected
rm -rf ${PYTHONDIR}
virtualenv -p /usr/bin/python3 ${PYTHONDIR}
ln -s /usr/lib/python3/dist-packages/gpiod* ${PYTHONDIR}/lib/python*/site-packages
${PYTHONDIR}/bin/pip install -r $MOONRAKER_DIR/scripts/moonraker-requirements.txt
ok_msg "Dependencies have been installed!"
fi
ok_msg "Update complete!"
moonraker_service "restart"
}
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
}

View File

@@ -1,24 +1,39 @@
accept_upload_conditions(){ #!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function accept_upload_conditions() {
top_border
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |"
hr
echo -e "| The following function will help to quickly upload |"
echo -e "| logs for debugging purposes. With confirming this |"
echo -e "| dialog, you agree that during that process your logs |"
echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |"
hr
echo -e "| ${red}PLEASE NOTE:${white} |"
echo -e "| Be aware that logs can contain network information, |"
echo -e "| private data like usernames, filenames, or other |"
echo -e "| information you may not want to make public. |"
blank_line
echo -e "| Do ${red}NOT${white} use this function if you don't agree! |"
bottom_border
local yn
while true; do while true; do
top_border read -p "${cyan}Do you accept? (Y/n):${white} " yn
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${default} |" case "${yn}" in
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} |"
hr
echo -e "| ${red}PLEASE NOTE:${default} |"
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! |"
bottom_border
read -p "${cyan}Do you accept? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"") 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 clear && print_header && upload_selection
;; ;;
N|n|No|no) N|n|No|no)
@@ -27,75 +42,84 @@ accept_upload_conditions(){
break break
;; ;;
*) *)
clear error_msg "Invalid command!";;
print_header
print_unkown_cmd
print_msg && clear_msg
accept_upload_conditions;;
esac esac
done done
} }
upload_selection(){ function upload_selection() {
source_kiauh_ini read_kiauh_ini "${FUNCNAME[0]}"
[ "$logupload_accepted" = "false" ] && accept_upload_conditions
### find all suitable logfiles for klipper local upload_agreed="${logupload_accepted}"
logfiles=() [[ ${upload_agreed} == "false" ]] && accept_upload_conditions
if ls /tmp/klippy*.log 2>/dev/null 1>&2; then
for kl_log in $(find /tmp/klippy*.log); do local logfiles
logfiles+=($kl_log) 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 done
fi }
if ls /tmp/moonraker*.log 2>/dev/null 1>&2; then
for mr_log in $(find /tmp/moonraker*.log); do local logdir log_dirs
logfiles+=($mr_log) log_dirs=$(get_instance_folder_path "logs")
done for logdir in ${log_dirs}; do
fi find_logfile "klippy(-[0-9a-zA-Z]+)?\.log" "${logdir}"
if ls /tmp/dwc2*.log 2>/dev/null 1>&2; then find_logfile "moonraker(-[0-9a-zA-Z]+)?\.log" "${logdir}"
for dwc_log in $(find /tmp/dwc2*.log); do find_logfile "telegram(-[0-9a-zA-Z]+)?\.log" "${logdir}"
logfiles+=($dwc_log) done
done find_logfile "mainsail.*" "${webif_logs}"
fi find_logfile "fluidd.*" "${webif_logs}"
find_logfile "KlipperScreen.log" "/tmp"
find_logfile "webcamd\.log(\.[0-9]+)?$" "/var/log"
find_logfile "kiauh\.log" "/tmp"
### draw interface ### draw interface
i=0 local i=0
top_border top_border
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |" echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |"
hr hr
echo -e "| You can choose the following files for uploading: |" echo -e "| You can choose the following logfiles for uploading: |"
for log in ${logfiles[@]}; do blank_line
printf "| $i) %-50s|\n" "${logfiles[$i]}"
i=$((i + 1)) 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 done
quit_footer
blank_line
back_footer
local option re="^[0-9]+$"
while true; do while true; do
read -p "${cyan}Please select:${default} " choice read -p "${cyan}###### Please select:${white} " option
if [ $choice = "q" ] || [ $choice = "Q" ]; then
clear && main_menu && break if [[ ${option} =~ ${re} && ${option} -lt ${#logfiles[@]} ]]; then
elif [ $choice -le ${#logfiles[@]} ]; then upload_log "${logfiles[${option}]}"
upload_log "${logfiles[$choice]}"
upload_selection upload_selection
elif [[ ${option} == "B" || ${option} == "b" ]]; then
return
else else
clear && print_header error_msg "Invalid command!"
ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection
fi fi
done done
} }
upload_log(){ function upload_log() {
if [ -f "$1" ]; then local link
clear && print_header clear && print_header
status_msg "Uploading $1 ..." status_msg "Uploading ${1} ..."
LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') link=$(curl -s -H "x-random;" --upload-file "${1}" 'http://paste.c-net.org/')
[ ! -z "$LINK" ] && ok_msg "$1 upload successfull!"
echo -e "\n${cyan}###### Here is your link:${default}" if [[ -n ${link} ]]; then
echo -e ">>>>>> $LINK\n" ok_msg "${1} upload successfull!"
unset LINK echo -e "\n${cyan}###### Here is your link:${white}"
echo -e ">>>>>> ${link}\n"
else else
clear && print_header error_msg "Uploading failed!"
ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection
fi fi
} }

778
scripts/utilities.sh Normal file
View File

@@ -0,0 +1,778 @@
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/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 !!! |"
echo -e "| |"
echo -e "| It will ask for credentials as needed. |"
bottom_border
echo -e "${white}"
exit 1
fi
}
function check_if_ratos() {
if [[ -n $(which ratos) ]]; then
echo -e "${red}"
top_border
echo -e "| !!! RatOS 2.1 or greater detected !!! |"
echo -e "| |"
echo -e "| KIAUH does currently not support RatOS. |"
echo -e "| If you have any questions, please ask for help on the |"
echo -e "| RatRig Community Discord: https://discord.gg/ratrig |"
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/dw-0/kiauh #"
echo -e "# DO NOT edit this file! #"
echo -e "#=================================================#"
echo -e "# KIAUH v4.0.0"
echo -e "#"
} >> "${INI_FILE}"
fi
if ! grep -Eq "^application_updates_available=" "${INI_FILE}"; then
echo -e "\napplication_updates_available=\c" >> "${INI_FILE}"
else
sed -i "/application_updates_available=/s/=.*/=/" "${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_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
if ! grep -Eq "^multi_instance_names=" "${INI_FILE}"; then
echo -e "\nmulti_instance_names=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^version_to_launch=" "${INI_FILE}"; then
echo -e "\nversion_to_launch=\n\c" >> "${INI_FILE}"
fi
### strip all empty lines out of the file
sed -i "/^[[:blank:]]*$/ d" "${INI_FILE}"
}
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}"
}
function add_to_application_updates() {
read_kiauh_ini "${FUNCNAME[0]}"
local application="${1}"
local app_update_state="${application_updates_available}"
if ! grep -Eq "${application}" <<< "${app_update_state}"; then
app_update_state="${app_update_state}${application},"
sed -i "/application_updates_available=/s/=.*/=${app_update_state}/" "${INI_FILE}"
fi
}
#================================================#
#=============== 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 log_name="dependencies"
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
# update system package lists if stale
update_system_package_lists
# install required packages
install_system_packages "${log_name}" "packages[@]"
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 create_required_folders() {
local printer_data=${1} folders
folders=("backup" "certs" "config" "database" "gcodes" "comms" "logs" "systemd")
for folder in "${folders[@]}"; do
local dir="${printer_data}/${folder}"
### remove possible symlink created by moonraker
if [[ -L "${dir}" && -d "${dir}" ]]; then
rm "${dir}"
fi
if [[ ! -d "${dir}" ]]; then
status_msg "Creating folder '${dir}' ..."
mkdir -p "${dir}"
ok_msg "Folder '${dir}' created!"
fi
done
}
function update_system_package_lists() {
local cache_mtime update_age update_interval silent
if [[ $1 == '--silent' ]]; then silent="true"; fi
if [[ -e /var/lib/apt/periodic/update-success-stamp ]]; then
cache_mtime="$(stat -c %Y /var/lib/apt/periodic/update-success-stamp)"
elif [[ -e /var/lib/apt/lists ]]; then
cache_mtime="$(stat -c %Y /var/lib/apt/lists)"
else
log_warning "Failure determining package cache age, forcing update"
cache_mtime=0
fi
update_age="$(($(date +'%s') - cache_mtime))"
update_interval=$((48*60*60)) # 48hrs
# update if cache is greater than update_interval
if (( update_age > update_interval )); then
if [[ ! ${silent} == "true" ]]; then status_msg "Updating package lists..."; fi
if ! sudo apt-get update --allow-releaseinfo-change &>/dev/null; then
log_error "Failure while updating package lists!"
if [[ ! ${silent} == "true" ]]; then error_msg "Updating package lists failed!"; fi
return 1
else
log_info "Package lists updated successfully"
if [[ ! ${silent} == "true" ]]; then status_msg "Updated package lists."; fi
fi
else
log_info "Package lists updated recently, skipping update..."
fi
}
function check_system_updates() {
local updates_avail status
if ! update_system_package_lists --silent; then
status="${red}Update check failed! ${white}"
else
updates_avail="$(apt list --upgradeable 2>/dev/null | sed "1d")"
if [[ -n ${updates_avail} ]]; then
status="${yellow}System upgrade available!${white}"
# add system to application_updates_available in kiauh.ini
add_to_application_updates "system"
else
status="${green}System up to date! ${white}"
fi
fi
echo "${status}"
}
function upgrade_system_packages() {
status_msg "Upgrading System ..."
update_system_package_lists
if sudo apt-get upgrade -y; then
print_confirm "Upgrade complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been held back!${green}"
else
print_error "System upgrade failed! Please look for any errors printed above!"
fi
}
function install_system_packages() {
local log_name="$1"
local packages=("${!2}")
status_msg "Installing packages..."
if sudo apt-get install -y "${packages[@]}"; then
ok_msg "${log_name^} packages installed!"
else
log_error "Failure while installing ${log_name,,} packages"
error_msg "Installing ${log_name} packages failed!"
exit 1 # exit kiauh
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!"
}
#================================================#
#============ INSTANCE MANAGEMENT ===============#
#================================================#
###
# takes in a systemd service files full path and
# returns the sub-string with the instance name
#
# @param {string}: service file absolute path
# (e.g. '/etc/systemd/system/klipper-<name>.service')
#
# => return sub-string containing only the <name> part of the full string
#
function get_instance_name() {
local instance=${1}
local name
name=$(echo "${instance}" | rev | cut -d"/" -f1 | cut -d"." -f2 | cut -d"-" -f1 | rev)
echo "${name}"
}
###
# returns the instance name/identifier of the klipper service
# if the klipper service is part of a multi instance setup
# otherwise returns an emtpy string
#
# @param {string}: name - klipper service name (e.g. klipper-name.service)
#
function get_klipper_instance_name() {
local instance=${1}
local name
name=$(echo "${instance}" | rev | cut -d"/" -f1 | cut -d"." -f2 | rev)
local regex="^klipper-[0-9a-zA-Z]+$"
if [[ ${name} =~ ${regex} ]]; then
name=$(echo "${name}" | cut -d"-" -f2)
else
name=""
fi
echo "${name}"
}
###
# loops through all installed klipper services and saves
# each instances name in a comma separated format to the kiauh.ini
#
function set_multi_instance_names() {
read_kiauh_ini "${FUNCNAME[0]}"
local name
local names=""
local services
services=$(klipper_systemd)
###
# if value of 'multi_instance_names' is not an empty
# string, delete its value, so it can be re-written
if [[ -n ${multi_instance_names} ]]; then
sed -i "/multi_instance_names=/s/=.*/=/" "${INI_FILE}"
fi
for svc in ${services}; do
name=$(get_klipper_instance_name "${svc}")
if ! grep -Eq "${name}" <<<"${names}"; then
names="${names}${name},"
fi
done
# write up-to-date instance name string to kiauh.ini
sed -i "/multi_instance_names=/s/=.*/=${names}/" "${INI_FILE}"
}
###
# Helper function that returns all configured instance names
#
# => return an empty string if 0 or 1 klipper instance is installed
# => return space-separated string for names of the configured instances
# if 2 or more klipper instances are installed
#
function get_multi_instance_names() {
read_kiauh_ini "${FUNCNAME[0]}"
local instance_names=()
###
# convert the comma separates string from the .kiauh.ini into
# an array of instance names. a single instance installation
# results in an empty instance_names array
IFS=',' read -r -a instance_names <<< "${multi_instance_names}"
echo "${instance_names[@]}"
}
###
# helper function that returns all possibly available absolute
# klipper config directory paths based on their instance name.
#
# => return an empty string if klipper is not installed
# => return space-separated string of absolute config directory paths
#
function get_config_folders() {
local cfg_dirs=()
local instance_names
instance_names=$(get_multi_instance_names)
if [[ -n ${instance_names} ]]; then
for name in ${instance_names}; do
###
# by KIAUH convention, all instance names of only numbers
# need to be prefixed with 'printer_'
if [[ ${name} =~ ^[0-9]+$ ]]; then
cfg_dirs+=("${HOME}/printer_${name}_data/config")
else
cfg_dirs+=("${HOME}/${name}_data/config")
fi
done
elif [[ -z ${instance_names} && $(klipper_systemd | wc -w) -gt 0 ]]; then
cfg_dirs+=("${HOME}/printer_data/config")
else
cfg_dirs=()
fi
echo "${cfg_dirs[@]}"
}
###
# helper function that returns all available absolute directory paths
# based on their instance name and specified target folder
#
# @param {string}: folder name - target instance folder name (e.g. config)
#
# => return an empty string if klipper is not installed
# => return space-separated string of absolute directory paths
#
function get_instance_folder_path() {
local folder_name=${1}
local folder_paths=()
local instance_names
local path
instance_names=$(get_multi_instance_names)
if [[ -n ${instance_names} ]]; then
for name in ${instance_names}; do
###
# by KIAUH convention, all instance names of only numbers
# need to be prefixed with 'printer_'
if [[ ${name} =~ ^[0-9]+$ ]]; then
path="${HOME}/printer_${name}_data/${folder_name}"
if [[ -d ${path} ]]; then
folder_paths+=("${path}")
fi
else
path="${HOME}/${name}_data/${folder_name}"
if [[ -d ${path} ]]; then
folder_paths+=("${path}")
fi
fi
done
elif [[ -z ${instance_names} && $(klipper_systemd | wc -w) -gt 0 ]]; then
path="${HOME}/printer_data/${folder_name}"
if [[ -d ${path} ]]; then
folder_paths+=("${path}")
fi
fi
echo "${folder_paths[@]}"
}