mirror of
https://github.com/dw-0/kiauh.git
synced 2025-10-26 06:56:07 +01:00
feat: KIAUH v4.0.0 (#191)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1 @@
|
||||
.idea
|
||||
.shellcheckrc
|
||||
klipper_repos.txt
|
||||
15
.shellcheckrc
Normal file
15
.shellcheckrc
Normal file
@@ -0,0 +1,15 @@
|
||||
source=scripts
|
||||
|
||||
enable=avoid-nullary-conditions
|
||||
enable=deprecate-which
|
||||
enable=quote-safe-variables
|
||||
enable=require-variable-braces
|
||||
enable=require-double-brackets
|
||||
|
||||
# SC2162: `read` without `-r` will mangle backslashes.
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2162
|
||||
disable=SC2162
|
||||
|
||||
# SC2164: Use `cd ... || exit` in case `cd` fails
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2164
|
||||
disable=SC2164
|
||||
99
README.md
99
README.md
@@ -1,11 +1,24 @@
|
||||

|
||||
# Klipper Installation And Update Helper
|
||||
     
|
||||
<p align="center">
|
||||
<a>
|
||||
<img src="https://raw.githubusercontent.com/th33xitus/kiauh/master/resources/screenshots/kiauh.png" alt="KIAUH logo" height="181">
|
||||
<h1 align="center">Klipper Installation And Update Helper</h1>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
### **📋 Please see the [Changelog](docs/changelog.md) for possible important information !**
|
||||
|
||||
**📢 Disclaimer: Usage of this script happens at your own risk!**
|
||||
<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/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/stars/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/forks/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/languages/top/th33xitus/kiauh?logo=gnubash&logoColor=white"></a>
|
||||
<a><img src="https://img.shields.io/github/v/tag/th33xitus/kiauh"></a>
|
||||
<br />
|
||||
<a><img src="https://img.shields.io/github/last-commit/th33xitus/kiauh"></a>
|
||||
<a><img src="https://img.shields.io/github/contributors/th33xitus/kiauh"></a>
|
||||
</p>
|
||||
|
||||
## **🛠️ Instructions:**
|
||||
|
||||
@@ -20,31 +33,13 @@ git clone https://github.com/th33xitus/kiauh.git
|
||||
|
||||
./kiauh/kiauh.sh
|
||||
```
|
||||
**📢 Disclaimer: Usage of this script happens at your own risk!**
|
||||
|
||||
|
||||
## **🧰 Functions and Features:**
|
||||
|
||||
### **Core Functions:**
|
||||
|
||||
- **Installing** Klipper to your Raspberry Pi or other Debian based Linux Distribution.
|
||||
- **Installing** of the Moonraker API (needed for Mainsail, Fluidd and KlipperScreen)
|
||||
- **Installing** several 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:**
|
||||
|
||||
- Build the Klipper Firmware
|
||||
- Flash the MCU
|
||||
- Read ID of the currently connected MCU
|
||||
- and more ...
|
||||
|
||||
### **For a list of additional features please see: [Feature List](docs/features.md)**
|
||||
|
||||
## **❗ Notes:**
|
||||
|
||||
**📋 Please see the [Changelog](docs/changelog.md) for possible important changes!**
|
||||
|
||||
- Tested **only** on Raspberry Pi OS Lite (Debian 10 Buster)
|
||||
- Other Debian based distributions can work
|
||||
- Reported to work on Armbian too
|
||||
@@ -52,18 +47,44 @@ git clone https://github.com/th33xitus/kiauh.git
|
||||
|
||||
## **🌐 Sources & Further Information**
|
||||
|
||||
For more information or instructions to the various components KIAUH can install, please check out the corresponding repositories listed below:
|
||||
|
||||
* ⛵[Klipper](https://github.com/Klipper3d/klipper) by [KevinOConnor](https://github.com/KevinOConnor)
|
||||
* 🌙[Moonraker](https://github.com/Arksine/moonraker) by [Arksine](https://github.com/Arksine)
|
||||
* 💨[Mainsail](https://github.com/mainsail-crew/mainsail) by [mainsail-crew](https://github.com/mainsail-crew)
|
||||
* 🌊[Fluidd](https://github.com/fluidd-core/fluidd) by [fluidd-core](https://github.com/fluidd-core)
|
||||
* 🕸️[Duet Web Control](https://github.com/Duet3D/DuetWebControl) by [Duet3D](https://github.com/Duet3D)
|
||||
* 🕸️[DWC2-for-Klipper-Socket](https://github.com/Stephan3/dwc2-for-klipper-socket) by [Stephan3](https://github.com/Stephan3)
|
||||
* 🖥️[KlipperScreen](https://github.com/jordanruthe/KlipperScreen) by [jordanruthe](https://github.com/jordanruthe)
|
||||
* 🐙[OctoPrint](https://github.com/OctoPrint/OctoPrint) by [OctoPrint](https://github.com/OctoPrint)
|
||||
* 🔬[PrettyGCode](https://github.com/Kragrathea/pgcode) by [Kragrathea](https://github.com/Kragrathea)
|
||||
* 🤖[Moonraker-Telegram-Bot](https://github.com/nlef/moonraker-telegram-bot) by [nlef](https://github.com/nlef)
|
||||
<table>
|
||||
<tr>
|
||||
<th><h3><a href="https://github.com/Klipper3d/klipper">Klipper</a></h3></th>
|
||||
<th><h3><a href="https://github.com/Arksine/moonraker">Moonraker</a></h3></th>
|
||||
<th><h3><a href="https://github.com/mainsail-crew/mainsail">Mainsail</a></h3></th>
|
||||
<th><h3><a href="https://github.com/fluidd-core/fluidd">Fluidd</a></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><img src="https://raw.githubusercontent.com/Klipper3d/klipper/master/docs/img/klipper-logo.png" alt="Klipper Logo" height="64"></th>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/9563098?v=4" alt="Arksine avatar" height="64"></th>
|
||||
<th><img src="https://raw.githubusercontent.com/mainsail-crew/docs/master/assets/img/logo.png" alt="Mainsail Logo" height="64"></th>
|
||||
<th><img src="https://raw.githubusercontent.com/fluidd-core/fluidd/master/docs/assets/images/logo.svg" alt="Fluidd Logo" height="64"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>by <a href="https://github.com/KevinOConnor">KevinOConnor</a></th>
|
||||
<th>by <a href="https://github.com/Arksine">Arksine</a></th>
|
||||
<th>by <a href="https://github.com/mainsail-crew">mainsail-crew</a></th>
|
||||
<th>by <a href="https://github.com/fluidd-core">fluidd-core</a></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><h3><a href="https://github.com/jordanruthe/KlipperScreen">KlipperScreen</a></h3></th>
|
||||
<th><h3><a href="https://github.com/nlef/moonraker-telegram-bot">Moonraker-Telegram-Bot</a></h3></th>
|
||||
<th><h3><a href="https://github.com/Kragrathea/pgcode">PrettyGCode for Klipper</a></h3></th>
|
||||
<th><h3><a href="https://github.com/OctoPrint/OctoPrint">OctoPrint</a></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/31575189?v=4" alt="jordanruthe avatar" height="64"></th>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/52351624?v=4" alt="nlef avatar" height="64"></th>
|
||||
<th><img src="https://avatars.githubusercontent.com/u/5917231?v=4" alt="Kragrathea avatar" height="64"></th>
|
||||
<th><img src="https://camo.githubusercontent.com/627be7fc67195b626b298af9b9677d7c58e698c67305e54324cffbe06130d4a4/68747470733a2f2f6f63746f7072696e742e6f72672f6173736574732f696d672f6c6f676f2e706e67" alt="OctoPrint Logo" height="64"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>by <a href="https://github.com/jordanruthe">jordanruthe</a></th>
|
||||
<th>by <a href="https://github.com/nlef">nlef</a></th>
|
||||
<th>by <a href="https://github.com/Kragrathea">Kragrathea</a></th>
|
||||
<th>by <a href="https://github.com/OctoPrint">OctoPrint</a></th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## **Credits**
|
||||
|
||||
|
||||
@@ -2,6 +2,30 @@
|
||||
|
||||
This document covers possible important changes to KIAUH.
|
||||
|
||||
### 2022-04-XX
|
||||
KIAUH has now reached major version 4 !
|
||||
* feat: Klipper can be installed under Python3 (considered as experimental)
|
||||
* feat: Klipper can be installed from custom repositories / inofficial forks
|
||||
* feat: Custom instance name for multi instance installations of Klipper
|
||||
* Any other multi instance will share the same name given to the corresponding Klipper instance
|
||||
* E.g. klipper-voron2 -> moonraker-voron2 -> moonraker-telegram-bot-voron2
|
||||
* feat: Option to only allow the installation of stable Mainsail and Fluidd versions
|
||||
* feat: Multi-Instance OctoPrint installations now each have their own virtual python environment
|
||||
* allows independent installation of plugins for each instance
|
||||
* feat: Implementing the use of shellcheck during development
|
||||
* feat: Implementing a simple logging mechanic
|
||||
* feat: Log-upload function now also allows uploading other logfiles (kiauh.log, webcamd.log etc.)
|
||||
* fix: During Klipper installation, checks for group membership of `tty` and `dialout` are made
|
||||
* refactor: Support for DWC and DWC-for-Klipper has been removed
|
||||
* refactor: The backup before update settings were moved to the KIAUH settings menu
|
||||
* refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature)
|
||||
* refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen were removed from the moonraker.conf template
|
||||
* They will now be individually added during installation of the corresponding interface
|
||||
* refactor: The rollback function was reworked and now also allows rollbacks of Moonraker
|
||||
* It now takes numerical inputs and reverts the corresponding repository by the given amount instead
|
||||
* KIAUH does not save previous states to its config anymore like it did with the previous approach
|
||||
|
||||
|
||||
### 2022-01-29
|
||||
* Starting from the 28th of January, Moonraker can make use of PackageKit and PolicyKit.\
|
||||
More details on that can be found [here](
|
||||
@@ -114,9 +138,9 @@ Each service gets its corresponding instance added to the service filename.
|
||||
--> moonraker-2.service
|
||||
--> moonraker-n.service
|
||||
```
|
||||
* The same service file rules from above apply to DWC and OctoPrint even though only Klipper and Moonraker are shown in this example.
|
||||
* 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.
|
||||
|
||||
|
||||
@@ -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...
|
||||
162
kiauh.sh
162
kiauh.sh
@@ -1,105 +1,89 @@
|
||||
#!/bin/bash
|
||||
clear
|
||||
set -e
|
||||
#!/usr/bin/env bash
|
||||
|
||||
### set color variables
|
||||
green=$(echo -en "\e[92m")
|
||||
yellow=$(echo -en "\e[93m")
|
||||
red=$(echo -en "\e[91m")
|
||||
cyan=$(echo -en "\e[96m")
|
||||
default=$(echo -en "\e[39m")
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
clear
|
||||
|
||||
### sourcing all additional scripts
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done
|
||||
for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done
|
||||
KIAUH_SRCDIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
for script in "${KIAUH_SRCDIR}/scripts/"*.sh; do . "${script}"; done
|
||||
for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
|
||||
|
||||
### set important directories
|
||||
#klipper
|
||||
KLIPPER_DIR=${HOME}/klipper
|
||||
KLIPPY_ENV=${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
|
||||
OCTOPRINT_CFG_DIR=${HOME}/.octoprint
|
||||
#KlipperScreen
|
||||
KLIPPERSCREEN_DIR=${HOME}/KlipperScreen
|
||||
KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env
|
||||
#MoonrakerTelegramBot
|
||||
MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot
|
||||
MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env
|
||||
#misc
|
||||
INI_FILE=${HOME}/.kiauh.ini
|
||||
BACKUP_DIR=${HOME}/kiauh-backups
|
||||
#===================================================#
|
||||
#=================== UPDATE KIAUH ==================#
|
||||
#===================================================#
|
||||
|
||||
### set github repos
|
||||
KLIPPER_REPO=https://github.com/Klipper3d/klipper.git
|
||||
ARKSINE_REPO=https://github.com/Arksine/klipper.git
|
||||
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
|
||||
DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git
|
||||
NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git
|
||||
#branches
|
||||
BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing
|
||||
BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping
|
||||
function update_kiauh() {
|
||||
status_msg "Updating KIAUH ..."
|
||||
|
||||
### set some messages
|
||||
warn_msg(){
|
||||
echo -e "${red}<!!!!> $1${default}"
|
||||
}
|
||||
status_msg(){
|
||||
echo; echo -e "${yellow}###### $1${default}"
|
||||
}
|
||||
ok_msg(){
|
||||
echo -e "${green}>>>>>> $1${default}"
|
||||
}
|
||||
title_msg(){
|
||||
echo -e "${cyan}$1${default}"
|
||||
}
|
||||
get_date(){
|
||||
current_date=$(date +"%y%m%d-%H%M")
|
||||
}
|
||||
print_unkown_cmd(){
|
||||
ERROR_MSG="Invalid command!"
|
||||
cd "${KIAUH_SRCDIR}"
|
||||
git reset --hard && git pull
|
||||
|
||||
ok_msg "Update complete! Please restart KIAUH."
|
||||
exit 0
|
||||
}
|
||||
|
||||
print_msg(){
|
||||
if [[ "$ERROR_MSG" != "" ]]; then
|
||||
echo -e "${red}"
|
||||
echo -e "#########################################################"
|
||||
echo -e " $ERROR_MSG "
|
||||
echo -e "#########################################################"
|
||||
echo -e "${default}"
|
||||
fi
|
||||
if [ "$CONFIRM_MSG" != "" ]; then
|
||||
echo -e "${green}"
|
||||
echo -e "#########################################################"
|
||||
echo -e " $CONFIRM_MSG "
|
||||
echo -e "#########################################################"
|
||||
echo -e "${default}"
|
||||
#===================================================#
|
||||
#=================== KIAUH STATUS ==================#
|
||||
#===================================================#
|
||||
|
||||
function kiauh_update_avail() {
|
||||
[[ ! -d "${KIAUH_SRCDIR}/.git" ]] && return
|
||||
local origin head
|
||||
|
||||
cd "${KIAUH_SRCDIR}"
|
||||
|
||||
### abort if not on master branch
|
||||
! git branch -a | grep -q "\* master" && return
|
||||
|
||||
### compare commit hash
|
||||
git fetch -q
|
||||
origin=$(git rev-parse --short=8 origin/master)
|
||||
head=$(git rev-parse --short=8 HEAD)
|
||||
|
||||
if [[ ${origin} != "${head}" ]]; then
|
||||
echo "true"
|
||||
fi
|
||||
}
|
||||
|
||||
clear_msg(){
|
||||
unset CONFIRM_MSG
|
||||
unset ERROR_MSG
|
||||
function kiauh_update_dialog() {
|
||||
[[ ! $(kiauh_update_avail) == "true" ]] && return
|
||||
top_border
|
||||
echo -e "|${green} New KIAUH update available! ${white}|"
|
||||
hr
|
||||
echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}|"
|
||||
blank_line
|
||||
echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}|"
|
||||
echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|"
|
||||
echo -e "|${yellow} features. Please consider updating! ${white}|"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
read -p "${cyan}###### Do you want to update now? (Y/n):${white} " yn
|
||||
while true; do
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
do_action "update_kiauh"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
deny_action "kiauh_update_dialog";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
check_euid
|
||||
init_logfile
|
||||
set_globals
|
||||
init_ini
|
||||
kiauh_status
|
||||
kiauh_update_dialog
|
||||
main_menu
|
||||
|
||||
18
klipper_repos.txt.example
Normal file
18
klipper_repos.txt.example
Normal file
@@ -0,0 +1,18 @@
|
||||
# This file acts as an example file.
|
||||
#
|
||||
# 1) Make a copy of this file and rename it to 'klipper_repos.txt'
|
||||
# 2) Add your custom Klipper repository to the bottom of that copy
|
||||
# 3) Save the file
|
||||
#
|
||||
# Back in KIAUH you can now go into -> [Settings] and use action '2' to set a different Klipper repository
|
||||
#
|
||||
# Make sure to always separate the repository and the branch with a ','.
|
||||
# <repository>,<branch> -> https://github.com/Klipper3d/klipper,master
|
||||
# If you omit a branch, it will always default to 'master'
|
||||
#
|
||||
# You are allowed to omit the 'https://github.com/' part of the repository URL
|
||||
# Down below are now a few examples of what is considered as valid:
|
||||
https://github.com/Klipper3d/klipper,master
|
||||
https://github.com/Klipper3d/klipper
|
||||
Klipper3d/klipper,master
|
||||
Klipper3d/klipper
|
||||
@@ -1,10 +1,10 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#####################################################################
|
||||
### Please set the paths accordingly. In case you don't have all ###
|
||||
### the listed folders, just keep that line commented out. ###
|
||||
#####################################################################
|
||||
### Path to your config folder you want to backup
|
||||
### Path to your config folder you want to back up
|
||||
#config_folder=~/klipper_config
|
||||
|
||||
### Path to your Klipper folder, by default that is '~/klipper'
|
||||
@@ -26,35 +26,38 @@
|
||||
#####################################################################
|
||||
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
|
||||
#####################################################################
|
||||
grab_version(){
|
||||
if [ ! -z "$klipper_folder" ]; then
|
||||
cd "$klipper_folder"
|
||||
grab_version() {
|
||||
local klipper_commit moonraker_commit
|
||||
local mainsail_ver fluidd_ver
|
||||
|
||||
if [[ -n ${klipper_folder} ]]; then
|
||||
cd "${klipper_folder}"
|
||||
klipper_commit=$(git rev-parse --short=7 HEAD)
|
||||
m1="Klipper on commit: $klipper_commit"
|
||||
cd ..
|
||||
m1="Klipper on commit: ${klipper_commit}"
|
||||
fi
|
||||
if [ ! -z "$moonraker_folder" ]; then
|
||||
cd "$moonraker_folder"
|
||||
if [[ -n ${moonraker_folder} ]]; then
|
||||
cd "${moonraker_folder}"
|
||||
moonraker_commit=$(git rev-parse --short=7 HEAD)
|
||||
m2="Moonraker on commit: $moonraker_commit"
|
||||
cd ..
|
||||
m2="Moonraker on commit: ${moonraker_commit}"
|
||||
fi
|
||||
if [ ! -z "$mainsail_folder" ]; then
|
||||
mainsail_ver=$(head -n 1 $mainsail_folder/.version)
|
||||
m3="Mainsail version: $mainsail_ver"
|
||||
if [[ -n ${mainsail_folder} ]]; then
|
||||
mainsail_ver=$(head -n 1 "${mainsail_folder}/.version")
|
||||
m3="Mainsail version: ${mainsail_ver}"
|
||||
fi
|
||||
if [ ! -z "$fluidd_folder" ]; then
|
||||
fluidd_ver=$(head -n 1 $fluidd_folder/.version)
|
||||
m4="Fluidd version: $fluidd_ver"
|
||||
if [[ -n ${fluidd_folder} ]]; then
|
||||
fluidd_ver=$(head -n 1 "${fluidd_folder}/.version")
|
||||
m4="Fluidd version: ${fluidd_ver}"
|
||||
fi
|
||||
}
|
||||
|
||||
push_config(){
|
||||
cd $config_folder
|
||||
push_config() {
|
||||
local current_date
|
||||
|
||||
cd "${config_folder}" || exit 1
|
||||
git pull
|
||||
git add .
|
||||
current_date=$(date +"%Y-%m-%d %T")
|
||||
git commit -m "Autocommit from $current_date" -m "$m1" -m "$m2" -m "$m3" -m "$m4"
|
||||
git commit -m "Autocommit from ${current_date}" -m "${m1}" -m "${m2}" -m "${m3}" -m "${m4}"
|
||||
git push
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
upstream dwc2 {
|
||||
server 127.0.0.1:4750;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
#listen [::]:80;
|
||||
|
||||
location / {
|
||||
proxy_pass http://dwc2/;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
#proxy_set_header X-Script-Name /;
|
||||
proxy_http_version 1.1;
|
||||
client_max_body_size 0;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,22 @@
|
||||
#Systemd service file for klipper
|
||||
#Systemd Klipper Service
|
||||
|
||||
[Unit]
|
||||
Description=Starts klipper instance %INST% on startup
|
||||
Description=Systemd Klipper Service for instance klipper-%INST%
|
||||
Documentation=https://www.klipper3d.org/
|
||||
After=network.target
|
||||
Wants=udev.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=KLIPPER_CONFIG=%CFG%
|
||||
Environment=KLIPPER_LOG=%LOG%
|
||||
Environment=KLIPPER_SOCKET=%UDS%
|
||||
Environment=KLIPPER_PRINTER=%PRINTER%
|
||||
Type=simple
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
ExecStart=%KL_ENV%/bin/python %KL_DIR%/klippy/klippy.py %P_CFG% -I %P_TMP% -l %KL_LOG% -a %KL_UDS%
|
||||
ExecStart=%ENV%/bin/python %DIR%/klippy/klippy.py ${KLIPPER_CONFIG} -I ${KLIPPER_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPER_SOCKET}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
19
resources/moonraker-telegram-bot.service
Normal file
19
resources/moonraker-telegram-bot.service
Normal file
@@ -0,0 +1,19 @@
|
||||
#Systemd service file for Moonraker Telegram Bot
|
||||
|
||||
[Unit]
|
||||
Description=Starts Moonraker Telegram Bot instance %INST% on startup
|
||||
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=TELEGRAM_CONF=%CFG%
|
||||
Environment=TELEGRAM_LOG=%LOG%
|
||||
Type=simple
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
ExecStart=%ENV%/bin/python %DIR%/bot/main.py -c ${TELEGRAM_CONF} -l ${TELEGRAM_LOG}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
@@ -4,9 +4,6 @@ port: %PORT%
|
||||
enable_debug_logging: False
|
||||
klippy_uds_address: %UDS%
|
||||
|
||||
[database]
|
||||
database_path: %MR_DB%
|
||||
|
||||
[authorization]
|
||||
trusted_clients:
|
||||
%LAN%
|
||||
@@ -25,6 +22,9 @@ cors_domains:
|
||||
https://app.fluidd.xyz
|
||||
http://app.fluidd.xyz
|
||||
|
||||
[database]
|
||||
database_path: %DB%
|
||||
|
||||
[file_manager]
|
||||
config_path: %CFG%
|
||||
log_path: %LOG%
|
||||
@@ -36,21 +36,3 @@ log_path: %LOG%
|
||||
[update_manager]
|
||||
channel: dev
|
||||
refresh_interval: 168
|
||||
|
||||
[update_manager mainsail]
|
||||
type: web
|
||||
repo: mainsail-crew/mainsail
|
||||
path: ~/mainsail
|
||||
|
||||
[update_manager fluidd]
|
||||
type: web
|
||||
repo: fluidd-core/fluidd
|
||||
path: ~/fluidd
|
||||
|
||||
#[update_manager KlipperScreen]
|
||||
#type: git_repo
|
||||
#path: /home/%USER%/KlipperScreen
|
||||
#origin: https://github.com/jordanruthe/KlipperScreen.git
|
||||
#env: /home/%USER%/.KlipperScreen-env/bin/python
|
||||
#requirements: scripts/KlipperScreen-requirements.txt
|
||||
#install_script: scripts/KlipperScreen-install.sh
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#Systemd service file for moonraker
|
||||
#Systemd Moonraker Service
|
||||
|
||||
[Unit]
|
||||
Description=Starts Moonraker %INST% on startup
|
||||
Description=Systemd Moonraker Service for instance moonraker-%INST%
|
||||
Documentation=https://moonraker.readthedocs.io/
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=MOONRAKER_CONF=%CFG%
|
||||
Environment=MOONRAKER_LOG=%LOG%
|
||||
Type=simple
|
||||
SupplementaryGroups=moonraker-admin
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
ExecStart=%MR_ENV%/bin/python %MR_DIR%/moonraker/moonraker.py -l %MR_LOG% -c %MR_CONF%
|
||||
ExecStart=%ENV%/bin/python %DIR%/moonraker/moonraker.py -c ${MOONRAKER_CONF} -l ${MOONRAKER_LOG}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,6 @@
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/<your-mcu-id>
|
||||
|
||||
[pause_resume]
|
||||
|
||||
[display_status]
|
||||
|
||||
[virtual_sdcard]
|
||||
path: ~/gcode_files
|
||||
|
||||
[printer]
|
||||
kinematics: none
|
||||
max_velocity: 1000
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 18 KiB |
@@ -1,195 +1,188 @@
|
||||
check_for_backup_dir(){
|
||||
if [ ! -d $BACKUP_DIR ]; then
|
||||
status_msg "Create KIAUH backup directory ..."
|
||||
mkdir -p $BACKUP_DIR && ok_msg "Directory created!"
|
||||
fi
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function get_date() {
|
||||
local current_date
|
||||
current_date=$(date +"%y%m%d-%H%M")
|
||||
echo "${current_date}"
|
||||
}
|
||||
|
||||
toggle_backups(){
|
||||
source_kiauh_ini
|
||||
if [ "$backup_before_update" = "true" ]; then
|
||||
sed -i '/backup_before_update=/s/true/false/' $INI_FILE
|
||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
||||
CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !"
|
||||
fi
|
||||
if [ "$backup_before_update" = "false" ]; then
|
||||
sed -i '/backup_before_update=/s/false/true/' $INI_FILE
|
||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
||||
CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !"
|
||||
fi
|
||||
function check_for_backup_dir() {
|
||||
[[ -d ${BACKUP_DIR} ]] && return
|
||||
|
||||
status_msg "Create KIAUH backup directory ..."
|
||||
mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
|
||||
}
|
||||
|
||||
bb4u(){
|
||||
source_kiauh_ini
|
||||
if [ "$backup_before_update" = "true" ]; then
|
||||
backup_$1
|
||||
fi
|
||||
function backup_before_update() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${backup_before_update}"
|
||||
[[ ${state} = "false" ]] && return
|
||||
backup_"${1}"
|
||||
}
|
||||
|
||||
read_bb4u_stat(){
|
||||
source_kiauh_ini
|
||||
if [ ! "$backup_before_update" = "true" ]; then
|
||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
||||
else
|
||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
#******************************************************************************#
|
||||
################################################################################
|
||||
|
||||
backup_printer_cfg(){
|
||||
function backup_klipper_config_dir() {
|
||||
check_for_backup_dir
|
||||
if [ -f $PRINTER_CFG ]; then
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
status_msg "Create backup of printer.cfg ..."
|
||||
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!"
|
||||
else
|
||||
ok_msg "No printer.cfg found! Skipping backup ..."
|
||||
fi
|
||||
}
|
||||
local current_date config_folder_name
|
||||
|
||||
backup_klipper_config_dir(){
|
||||
source_kiauh_ini
|
||||
check_for_backup_dir
|
||||
if [ -d "$klipper_cfg_loc" ]; then
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
if [[ -d "${KLIPPER_CONFIG}" ]]; then
|
||||
current_date=$(get_date)
|
||||
config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)"
|
||||
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
status_msg "Create backup of the Klipper config directory ..."
|
||||
config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)"
|
||||
mkdir -p $BACKUP_DIR/$config_folder_name/$current_date
|
||||
cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!"
|
||||
echo
|
||||
|
||||
mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}"
|
||||
cp -r "${KLIPPER_CONFIG}" "${_}"
|
||||
|
||||
print_confirm "Configuration directory backup complete!"
|
||||
else
|
||||
ok_msg "No config directory found! Skipping backup ..."
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
backup_moonraker_database(){
|
||||
function backup_moonraker_database() {
|
||||
check_for_backup_dir
|
||||
if ls -d ${HOME}/.moonraker_database* 2>/dev/null 1>&2; then
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p "$BACKUP_DIR/mr_db_backup/$current_date"
|
||||
for database in $(ls -d ${HOME}/.moonraker_database*)
|
||||
do
|
||||
status_msg "Create backup of $database ..."
|
||||
cp -r $database "$BACKUP_DIR/mr_db_backup/$current_date"
|
||||
local current_date databases target_dir regex=".moonraker_database(_[0-9a-zA-Z]+)?"
|
||||
databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/${regex}" | sort)
|
||||
|
||||
if [[ -n ${databases} ]]; then
|
||||
current_date=$(get_date)
|
||||
target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}"
|
||||
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${target_dir}"
|
||||
|
||||
for database in ${databases}; do
|
||||
status_msg "Create backup of ${database} ..."
|
||||
cp -r "${database}" "${target_dir}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
ok_msg "Backup complete!\n"
|
||||
|
||||
print_confirm "Moonraker database backup complete!"
|
||||
else
|
||||
ok_msg "No Moonraker database found! Skipping backup ..."
|
||||
print_error "No Moonraker database found! Skipping backup ..."
|
||||
fi
|
||||
return
|
||||
}
|
||||
|
||||
backup_klipper(){
|
||||
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then
|
||||
function backup_klipper() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${KLIPPER_DIR} && -d ${KLIPPY_ENV} ]]; then
|
||||
status_msg "Creating Klipper backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date"
|
||||
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}"
|
||||
cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}"
|
||||
print_confirm "Klipper backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!"
|
||||
print_error "Can't back up 'klipper' and/or 'klipper-env' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_dwc2(){
|
||||
if [ -d $DWC2FK_DIR ] && [ -d $DWC_ENV_DIR ] && [ -d $DWC2_DIR ]; then
|
||||
status_msg "Creating DWC2 Web UI backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/dwc2-backups/"$current_date"
|
||||
cp -r $DWC2FK_DIR $_ && cp -r $DWC_ENV_DIR $_ && cp -r $DWC2_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
function backup_mainsail() {
|
||||
local current_date
|
||||
|
||||
backup_mainsail(){
|
||||
if [ -d $MAINSAIL_DIR ]; then
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
status_msg "Creating Mainsail backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date"
|
||||
cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}"
|
||||
cp -r "${MAINSAIL_DIR}" "${_}"
|
||||
print_confirm "Mainsail backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup mainsail directory! Not found!"
|
||||
print_error "Can't back up 'mainsail' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_fluidd(){
|
||||
if [ -d $FLUIDD_DIR ]; then
|
||||
function backup_fluidd() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||
status_msg "Creating Fluidd backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/fluidd-backups/"$current_date"
|
||||
cp -r $FLUIDD_DIR $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}"
|
||||
cp -r "${FLUIDD_DIR}" "${_}"
|
||||
print_confirm "Fluidd backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup fluidd directory! Not found!"
|
||||
print_error "Can't back up 'fluidd' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_moonraker(){
|
||||
if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV ]; then
|
||||
function backup_moonraker() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${MOONRAKER_DIR} && -d ${MOONRAKER_ENV} ]]; then
|
||||
status_msg "Creating Moonraker backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date"
|
||||
cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV $_ && ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}"
|
||||
cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}"
|
||||
print_confirm "Moonraker backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!"
|
||||
print_error "Can't back up moonraker and/or moonraker-env directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_octoprint(){
|
||||
if [ -d $OCTOPRINT_DIR ] && [ -d $OCTOPRINT_CFG_DIR ]; then
|
||||
function backup_octoprint() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${OCTOPRINT_DIR} && -d ${OCTOPRINT_CFG_DIR} ]]; then
|
||||
status_msg "Creating OctoPrint backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/octoprint-backups/"$current_date"
|
||||
cp -r $OCTOPRINT_DIR $_ && cp -r $OCTOPRINT_CFG_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}"
|
||||
cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
|
||||
print_confirm " OctoPrint backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup OctoPrint and/or .octoprint directory!\n Not found!"
|
||||
print_error "Can't back up OctoPrint and/or .octoprint directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_klipperscreen(){
|
||||
if [ -d $KLIPPERSCREEN_DIR ] ; then
|
||||
function backup_klipperscreen() {
|
||||
local current_date
|
||||
if [[ -d ${KLIPPERSCREEN_DIR} ]] ; then
|
||||
status_msg "Creating KlipperScreen backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/klipperscreen-backups/"$current_date"
|
||||
cp -r $KLIPPERSCREEN_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}"
|
||||
cp -r "${KLIPPERSCREEN_DIR}" "${_}"
|
||||
print_confirm "KlipperScreen backup complete!"
|
||||
else
|
||||
ERROR_MSG=" Can't backup KlipperScreen directory!\n Not found!"
|
||||
print_error "Can't back up KlipperScreen directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
backup_MoonrakerTelegramBot(){
|
||||
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] ; then
|
||||
function backup_telegram_bot() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${TELEGRAM_BOT_DIR} ]] ; then
|
||||
status_msg "Creating MoonrakerTelegramBot backup ..."
|
||||
check_for_backup_dir
|
||||
get_date
|
||||
status_msg "Timestamp: $current_date"
|
||||
mkdir -p $BACKUP_DIR/MoonrakerTelegramBot-backups/"$current_date"
|
||||
cp -r $MOONRAKER_TELEGRAM_BOT_DIR $_
|
||||
ok_msg "Backup complete!"
|
||||
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
|
||||
ERROR_MSG=" Can't backup MoonrakerTelegramBot directory!\n Not found!"
|
||||
print_error "Can't back up MoonrakerTelegramBot directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/sh
|
||||
# System startup script for dwc2-for-klipper-socket
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: dwc2-for-klipper-socket
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: dwc2-for-klipper-socket daemon
|
||||
# Description: Starts the dwc2-for-klipper-socket daemon.
|
||||
### END INIT INFO
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
DESC="dwc2-for-klipper-socket daemon"
|
||||
NAME="dwc2-for-klipper-socket"
|
||||
DEFAULTS_FILE=/etc/default/dwc
|
||||
PIDFILE=/var/run/dwc.pid
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
# Read defaults file
|
||||
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
|
||||
|
||||
case "$1" in
|
||||
start) log_daemon_msg "Starting dwc2-for-klipper-socket" $NAME
|
||||
start-stop-daemon --start --quiet --exec $DWC_EXEC \
|
||||
--background --pidfile $PIDFILE --make-pidfile \
|
||||
--chuid $DWC_USER --user $DWC_USER \
|
||||
-- $DWC_ARGS
|
||||
log_end_msg $?
|
||||
;;
|
||||
stop) log_daemon_msg "Stopping dwc2-for-klipper-socket" $NAME
|
||||
killproc -p $PIDFILE $DWC_EXEC
|
||||
RETVAL=$?
|
||||
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
|
||||
log_end_msg $RETVAL
|
||||
;;
|
||||
restart) log_daemon_msg "Restarting dwc2-for-klipper-socket" $NAME
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
reload|force-reload)
|
||||
log_daemon_msg "Reloading configuration not supported" $NAME
|
||||
log_end_msg 1
|
||||
;;
|
||||
status)
|
||||
status_of_proc -p $PIDFILE $DWC_EXEC $NAME && exit 0 || exit $?
|
||||
;;
|
||||
*) log_action_msg "Usage: /etc/init.d/dwc {start|stop|status|restart|reload|force-reload}"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -1,106 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running
|
||||
# Raspbian/Raspberry Pi OS based distributions.
|
||||
|
||||
# https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
|
||||
PYTHONDIR="${HOME}/dwc-env"
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
DWC_USER=${USER}
|
||||
|
||||
# Step 1: Verify Klipper has been installed
|
||||
check_klipper()
|
||||
{
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
echo "Klipper service found!"
|
||||
else
|
||||
echo "Klipper service not found, please install Klipper first"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Step 2: Install packages
|
||||
install_packages()
|
||||
{
|
||||
PKGLIST="python3-virtualenv python3-dev python3-tornado"
|
||||
|
||||
# Update system package info
|
||||
report_status "Running apt-get update..."
|
||||
sudo apt-get update --allow-releaseinfo-change
|
||||
|
||||
# Install desired packages
|
||||
report_status "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
# Step 3: Create python virtual environment
|
||||
create_virtualenv()
|
||||
{
|
||||
report_status "Updating python virtual environment..."
|
||||
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR}
|
||||
|
||||
# Install/update dependencies
|
||||
${PYTHONDIR}/bin/pip install tornado==6.0.4
|
||||
}
|
||||
|
||||
# Step 4: Install startup script
|
||||
install_script(){
|
||||
report_status "Installing system start script..."
|
||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/dwc.service" << EOF
|
||||
#Systemd service file for DWC
|
||||
[Unit]
|
||||
Description=dwc_webif
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$DWC_USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${PYTHONDIR}/bin/python3 ${SRCDIR}/web_dwc2.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
# Use systemctl to enable the klipper systemd service script
|
||||
sudo systemctl enable dwc.service
|
||||
}
|
||||
|
||||
# Step 5: Start DWC service
|
||||
start_software()
|
||||
{
|
||||
report_status "Launching dwc2-for-klipper-socket..."
|
||||
sudo systemctl start dwc
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
report_status()
|
||||
{
|
||||
echo -e "\n\n###### $1"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Force script to exit if an error occurs
|
||||
set -e
|
||||
|
||||
# Find SRCDIR from the pathname of this script
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
|
||||
# Run installation steps defined above
|
||||
verify_ready
|
||||
check_klipper
|
||||
install_packages
|
||||
create_virtualenv
|
||||
install_script
|
||||
start_software
|
||||
@@ -1,106 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running
|
||||
# Raspbian/Raspberry Pi OS based distributions.
|
||||
|
||||
# https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
|
||||
PYTHONDIR="${HOME}/dwc-env"
|
||||
|
||||
# Step 1: Verify Klipper has been installed
|
||||
check_klipper()
|
||||
{
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
echo "Klipper service found!"
|
||||
else
|
||||
echo "Klipper service not found, please install Klipper first"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Step 2: Install packages
|
||||
install_packages()
|
||||
{
|
||||
PKGLIST="python3-virtualenv python3-dev python3-tornado"
|
||||
|
||||
# Update system package info
|
||||
report_status "Running apt-get update..."
|
||||
sudo apt-get update --allow-releaseinfo-change
|
||||
|
||||
# Install desired packages
|
||||
report_status "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
# Step 3: Create python virtual environment
|
||||
create_virtualenv()
|
||||
{
|
||||
report_status "Updating python virtual environment..."
|
||||
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR}
|
||||
|
||||
# Install/update dependencies
|
||||
${PYTHONDIR}/bin/pip install tornado==6.0.4
|
||||
}
|
||||
|
||||
# Step 4: Install startup script
|
||||
install_script(){
|
||||
report_status "Installing system start script..."
|
||||
sudo cp "${SRCDIR}/scripts/dwc-start.sh" /etc/init.d/dwc
|
||||
sudo update-rc.d dwc defaults
|
||||
}
|
||||
|
||||
# Step 5: Install startup script config
|
||||
install_config(){
|
||||
DEFAULTS_FILE=/etc/default/dwc
|
||||
[ -f $DEFAULTS_FILE ] && return
|
||||
|
||||
report_status "Installing system start configuration..."
|
||||
sudo /bin/sh -c "cat > $DEFAULTS_FILE" <<EOF
|
||||
# Configuration for /etc/init.d/dwc
|
||||
DWC_USER=$USER
|
||||
|
||||
DWC_EXEC=${PYTHONDIR}/bin/python3
|
||||
|
||||
DWC_ARGS="${SRCDIR}/web_dwc2.py"
|
||||
EOF
|
||||
}
|
||||
|
||||
# Step 4: Start server
|
||||
start_software()
|
||||
{
|
||||
report_status "Launching dwc2-for-klipper-socket..."
|
||||
sudo /etc/init.d/klipper stop
|
||||
sudo /etc/init.d/dwc restart
|
||||
sudo /etc/init.d/klipper start
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
report_status()
|
||||
{
|
||||
echo -e "\n\n###### $1"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Force script to exit if an error occurs
|
||||
set -e
|
||||
|
||||
# Find SRCDIR from the pathname of this script
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
|
||||
# Run installation steps defined above
|
||||
verify_ready
|
||||
check_klipper
|
||||
install_packages
|
||||
create_virtualenv
|
||||
install_script
|
||||
install_config
|
||||
start_software
|
||||
@@ -1,41 +0,0 @@
|
||||
stop_service() {
|
||||
# Stop DWC Service
|
||||
echo "#### Stopping DWC Service.."
|
||||
sudo systemctl stop dwc
|
||||
sudo systemctl disable dwc
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove DWC from Services
|
||||
echo
|
||||
echo "#### Removing DWC Service.."
|
||||
sudo rm -f /etc/systemd/system/dwc.service
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
# Remove virtualenv
|
||||
if [ -d ~/dwc-env ]; then
|
||||
echo "Removing virtualenv..."
|
||||
rm -rf ~/dwc-env
|
||||
else
|
||||
echo "No DWC virtualenv found"
|
||||
fi
|
||||
|
||||
# Notify user of method to remove DWC source code
|
||||
echo
|
||||
echo "The DWC system files and virtualenv have been removed."
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
@@ -1,45 +0,0 @@
|
||||
stop_service() {
|
||||
# Stop DWC Service
|
||||
echo "#### Stopping DWC Service.."
|
||||
sudo service dwc stop
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove DWC from Startup
|
||||
echo
|
||||
echo "#### Removing DWC from Startup.."
|
||||
sudo update-rc.d -f dwc remove
|
||||
|
||||
# Remove DWC from Services
|
||||
echo
|
||||
echo "#### Removing DWC Service.."
|
||||
sudo rm -f /etc/init.d/dwc /etc/default/dwc
|
||||
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
# Remove virtualenv
|
||||
if [ -d ~/dwc-env ]; then
|
||||
echo "Removing virtualenv..."
|
||||
rm -rf ~/dwc-env
|
||||
else
|
||||
echo "No DWC virtualenv found"
|
||||
fi
|
||||
|
||||
# Notify user of method to remove DWC source code
|
||||
echo
|
||||
echo "The DWC system files and virtualenv have been removed."
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
409
scripts/flash_klipper.sh
Normal file
409
scripts/flash_klipper.sh
Normal file
@@ -0,0 +1,409 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function init_flash_process() {
|
||||
### step 1: check for required userhgroups (tty & dialout)
|
||||
check_usergroups
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| Please select the flashing method to flash your MCU. |"
|
||||
echo -e "| Make sure to only select a method your MCU supports. |"
|
||||
echo -e "| Not all MCUs support both methods! |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| 1) Regular flashing method |"
|
||||
echo -e "| 2) Updating via SD-Card Update |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice method
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
select_msg "Regular flashing method"
|
||||
method="regular"
|
||||
break;;
|
||||
2)
|
||||
select_msg "SD-Card Update"
|
||||
method="sdcard"
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_flash_method_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### step 2: select how the mcu is connected to the host
|
||||
select_mcu_connection
|
||||
|
||||
### step 3: select which detected mcu should be flashed
|
||||
select_mcu_id "${method}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 2 =====================#
|
||||
#================================================#
|
||||
function select_mcu_connection() {
|
||||
top_border
|
||||
echo -e "| ${yellow}Make sure that the controller board is connected now!${white} |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| How is the controller board connected to the host? |"
|
||||
echo -e "| 1) USB |"
|
||||
echo -e "| 2) UART |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Connection method:${white} " choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
status_msg "Identifying MCU connected via USB ...\n"
|
||||
get_usb_id || true # continue even after exit code 1
|
||||
break;;
|
||||
2)
|
||||
status_msg "Identifying MCU possibly connected via UART ...\n"
|
||||
get_uart_id || true # continue even after exit code 1
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_mcu_connection_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function print_detected_mcu_to_screen() {
|
||||
local i=1
|
||||
|
||||
if (( ${#mcu_list[@]} < 1 )); then
|
||||
print_error "No MCU found!\n MCU eihter not connected or not detected!"
|
||||
return
|
||||
fi
|
||||
|
||||
for mcu in "${mcu_list[@]}"; do
|
||||
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
|
||||
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 3 =====================#
|
||||
#================================================#
|
||||
function select_mcu_id() {
|
||||
local i=0 sel_index=0 method=${1}
|
||||
|
||||
if (( ${#mcu_list[@]} < 1 )); then
|
||||
print_error "No MCU found!\n MCU eihter not connected or not detected!"
|
||||
return
|
||||
fi
|
||||
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${white} |"
|
||||
hr
|
||||
echo -e "| Make sure, to select the correct MCU! |"
|
||||
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### List of available MCU:${white}"
|
||||
|
||||
### list all mcus
|
||||
for mcu in "${mcu_list[@]}"; do
|
||||
i=$(( i + 1 ))
|
||||
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
|
||||
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
|
||||
done
|
||||
|
||||
### verify user input
|
||||
local regex="^[1-9]+$"
|
||||
while [[ ! ${sel_index} =~ ${regex} ]] || [[ ${sel_index} -gt ${i} ]]; do
|
||||
echo
|
||||
read -p "${cyan}###### Select MCU to flash:${white} " sel_index
|
||||
|
||||
if [[ ! ${sel_index} =~ ${regex} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
elif [[ ${sel_index} -lt 1 ]] || [[ ${sel_index} -gt ${i} ]]; then
|
||||
error_msg "Please select a number between 1 and ${i}!"
|
||||
fi
|
||||
|
||||
local mcu_index=$(( sel_index - 1 ))
|
||||
local selected_mcu_id="${mcu_list[${mcu_index}]}"
|
||||
done
|
||||
|
||||
### confirm selection
|
||||
local yn
|
||||
while true; do
|
||||
echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n"
|
||||
read -p "${cyan}###### Continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
status_msg "Flashing ${selected_mcu_id} ..."
|
||||
if [[ ${method} == "regular" ]]; then
|
||||
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
|
||||
start_flash_mcu "${selected_mcu_id}"
|
||||
elif [[ ${method} == "sdcard" ]]; then
|
||||
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
|
||||
start_flash_sd "${selected_mcu_id}"
|
||||
else
|
||||
print_error "No flash method set! Aborting..."
|
||||
log_error "No flash method set!"
|
||||
return
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function start_flash_mcu() {
|
||||
local device=${1}
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
if make flash FLASH_DEVICE="${device}"; then
|
||||
ok_msg "Flashing successfull!"
|
||||
else
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
fi
|
||||
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function start_flash_sd() {
|
||||
local i=0 board_list=() device=${1}
|
||||
local flash_script="${KLIPPER_DIR}/scripts/flash-sdcard.sh"
|
||||
|
||||
### write each supported board to the array to make it selectable
|
||||
for board in $("${flash_script}" -l | tail -n +2); do
|
||||
board_list+=("${board}")
|
||||
done
|
||||
|
||||
top_border
|
||||
echo -e "| Please select the type of board that corresponds to |"
|
||||
echo -e "| the currently selected MCU ID you chose before. |"
|
||||
blank_line
|
||||
echo -e "| The following boards are currently supported: |"
|
||||
hr
|
||||
### display all supported boards to the user
|
||||
for board in "${board_list[@]}"; do
|
||||
if [[ ${i} -lt 10 ]]; then
|
||||
printf "| ${i}) %-50s|\n" "${board_list[${i}]}"
|
||||
else
|
||||
printf "| ${i}) %-49s|\n" "${board_list[${i}]}"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
quit_footer
|
||||
|
||||
### make the user select one of the boards
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select board type:${white} " choice
|
||||
if [[ ${choice} = "q" || ${choice} = "Q" ]]; then
|
||||
clear && advanced_menu && break
|
||||
elif [[ ${choice} -le ${#board_list[@]} ]]; then
|
||||
local selected_board="${board_list[${choice}]}"
|
||||
break
|
||||
else
|
||||
clear && print_header
|
||||
error_msg "Invalid choice!"
|
||||
flash_mcu_sd
|
||||
fi
|
||||
done
|
||||
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| If your board is flashed with firmware that connects |"
|
||||
echo -e "| at a custom baud rate, please change it now. |"
|
||||
blank_line
|
||||
echo -e "| If you are unsure, stick to the default 250000! |"
|
||||
bottom_border
|
||||
|
||||
local baud_rate regex="^[0-9]+$"
|
||||
echo -e "${cyan}###### Please set the baud rate:${white} "
|
||||
while [[ ! ${baud_rate} =~ ${regex} ]]; do
|
||||
read -e -i "250000" -e baud_rate
|
||||
local selected_baud_rate=${baud_rate}
|
||||
break
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
###flash process
|
||||
do_action_service "stop" "klipper"
|
||||
if "${flash_script}" -b "${selected_baud_rate}" "${device}" "${selected_board}"; then
|
||||
print_confirm "Flashing successfull!"
|
||||
log_info "Flash successfull!"
|
||||
else
|
||||
print_error "Flashing failed!\n Please read the console output above!"
|
||||
log_error "Flash failed!"
|
||||
fi
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function build_fw() {
|
||||
local python_version
|
||||
|
||||
if [[ ! -d ${KLIPPER_DIR} || ! -d ${KLIPPY_ENV} ]]; then
|
||||
print_error "Klipper not found!\n Cannot build firmware without Klipper!"
|
||||
return
|
||||
fi
|
||||
|
||||
python_version=$(get_klipper_python_ver)
|
||||
|
||||
cd "${KLIPPER_DIR}"
|
||||
status_msg "Initializing firmware build ..."
|
||||
local dep=(build-essential dpkg-dev make)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
make clean
|
||||
|
||||
status_msg "Building firmware ..."
|
||||
if (( python_version == 3 )); then
|
||||
make PYTHON=python3 menuconfig
|
||||
make PYTHON=python3
|
||||
elif (( python_version == 2 )); then
|
||||
make PYTHON=python2 menuconfig
|
||||
make PYTHON=python2
|
||||
else
|
||||
warn_msg "Error reading Python version!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
ok_msg "Firmware built!"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_usb_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(find /dev/serial/by-id/* 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function get_uart_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty(AMA0|S0)$" 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function show_flash_method_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}Regular flashing method:${white} |"
|
||||
echo -e "| The default method to flash controller boards which |"
|
||||
echo -e "| are connected and updated over USB and not by placing |"
|
||||
echo -e "| a compiled firmware file onto an internal SD-Card. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that get flashed that way are: |"
|
||||
echo -e "| - Arduino Mega 2560 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}Updating via SD-Card Update:${white} |"
|
||||
echo -e "| Many popular controller boards ship with a bootloader |"
|
||||
echo -e "| capable of updating the firmware via SD-Card. |"
|
||||
echo -e "| Choose this method if your controller board supports |"
|
||||
echo -e "| this way of updating. This method ONLY works for up- |"
|
||||
echo -e "| grading firmware. The initial flashing procedure must |"
|
||||
echo -e "| be done manually per the instructions that apply to |"
|
||||
echo -e "| your controller board. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that can be flashed that way are: |"
|
||||
echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |"
|
||||
echo -e "| - Fysetc Spider |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
init_flash_process
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function show_mcu_connection_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}USB:${white} |"
|
||||
echo -e "| Selecting USB as the connection method will scan the |"
|
||||
echo -e "| USB ports for connected controller boards. This will |"
|
||||
echo -e "| be similar to the 'ls /dev/serial/by-id/*' command |"
|
||||
echo -e "| suggested by the official Klipper documentation for |"
|
||||
echo -e "| determining successfull USB connections! |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}UART:${white} |"
|
||||
echo -e "| Selecting UART as the connection method will list all |"
|
||||
echo -e "| possible UART serial ports. Note: This method ALWAYS |"
|
||||
echo -e "| returns something as it seems impossible to determine |"
|
||||
echo -e "| if a valid Klipper controller board is connected or |"
|
||||
echo -e "| not. Because of that, you ${red}MUST${white} know which UART serial |"
|
||||
echo -e "| port your controller board is connected to when using |"
|
||||
echo -e "| this connection method. |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
select_mcu_connection
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
show_flash_method_help(){
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}Regular flashing method:${default} |"
|
||||
echo -e "| The default method to flash controller boards which |"
|
||||
echo -e "| are connected and updated over USB and not by placing |"
|
||||
echo -e "| a compiled firmware file onto an internal SD-Card. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that get flashed that way are: |"
|
||||
echo -e "| - Arduino Mega 2560 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}Updating via SD-Card Update:${default} |"
|
||||
echo -e "| Many popular controller boards ship with a bootloader |"
|
||||
echo -e "| capable of updating the firmware via SD-Card. |"
|
||||
echo -e "| Choose this method if your controller board supports |"
|
||||
echo -e "| this way of updating. This method ONLY works for up- |"
|
||||
echo -e "| grading firmware. The initial flashing procedure must |"
|
||||
echo -e "| be done manually per the instructions that apply to |"
|
||||
echo -e "| your controller board. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that can be flashed that way are: |"
|
||||
echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |"
|
||||
echo -e "| - Fysetc Spider |"
|
||||
blank_line
|
||||
back_footer
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${default} " choice
|
||||
case "$choice" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
select_flash_method
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
select_flash_method(){
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| Please select the flashing method to flash your MCU. |"
|
||||
echo -e "| Make sure to only select a method your MCU supports. |"
|
||||
echo -e "| Not all MCUs support both methods! |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| 1) Regular flashing method |"
|
||||
echo -e "| 2) Updating via SD-Card Update |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${default} " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
echo -e "###### > Regular flashing method"
|
||||
select_mcu_connection
|
||||
select_mcu_id
|
||||
[[ "$CONFIRM_FLASH" == true ]] && flash_mcu
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > SD-Card Update"
|
||||
select_mcu_connection
|
||||
select_mcu_id
|
||||
[[ "$CONFIRM_FLASH" == true ]] && flash_mcu_sd
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_flash_method_help
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
select_mcu_id(){
|
||||
if [ ${#mcu_list[@]} -ge 1 ]; then
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${default} |"
|
||||
hr
|
||||
echo -e "| Make sure, to select the correct MCU! |"
|
||||
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### List of available MCU:${default}"
|
||||
### list all mcus
|
||||
id=0
|
||||
for mcu in ${mcu_list[@]}; do
|
||||
let id++
|
||||
echo -e " $id) $mcu"
|
||||
done
|
||||
### verify user input
|
||||
sel_index=""
|
||||
while [[ ! ($sel_index =~ ^[1-9]+$) ]] || [ "$sel_index" -gt "$id" ]; do
|
||||
echo
|
||||
read -p "${cyan}###### Select MCU to flash:${default} " sel_index
|
||||
if [[ ! ($sel_index =~ ^[1-9]+$) ]]; then
|
||||
warn_msg "Invalid input!"
|
||||
elif [ "$sel_index" -lt 1 ] || [ "$sel_index" -gt "$id" ]; then
|
||||
warn_msg "Please select a number between 1 and $id!"
|
||||
fi
|
||||
mcu_index=$(echo $((sel_index - 1)))
|
||||
selected_mcu_id="${mcu_list[$mcu_index]}"
|
||||
done
|
||||
### confirm selection
|
||||
while true; do
|
||||
echo -e "\n###### You selected:\n ● MCU #$sel_index: $selected_mcu_id\n"
|
||||
read -p "${cyan}###### Continue? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Flashing $selected_mcu_id ..."
|
||||
CONFIRM_FLASH=true
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
CONFIRM_FLASH=false
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
flash_mcu(){
|
||||
do_action_service "stop" "klipper"
|
||||
make flash FLASH_DEVICE="${mcu_list[$mcu_index]}"
|
||||
### evaluate exit code of make flash
|
||||
if [ ! $? -eq 0 ]; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
flash_mcu_sd(){
|
||||
flash_script="${HOME}/klipper/scripts/flash-sdcard.sh"
|
||||
|
||||
### write each supported board to the array to make it selectable
|
||||
board_list=()
|
||||
for board in $("$flash_script" -l | tail -n +2); do
|
||||
board_list+=($board)
|
||||
done
|
||||
|
||||
i=0
|
||||
top_border
|
||||
echo -e "| Please select the type of board that corresponds to |"
|
||||
echo -e "| the currently selected MCU ID you chose before. |"
|
||||
blank_line
|
||||
echo -e "| The following boards are currently supported: |"
|
||||
hr
|
||||
### display all supported boards to the user
|
||||
for board in ${board_list[@]}; do
|
||||
if [ $i -lt 10 ]; then
|
||||
printf "| $i) %-50s|\n" "${board_list[$i]}"
|
||||
else
|
||||
printf "| $i) %-49s|\n" "${board_list[$i]}"
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
quit_footer
|
||||
|
||||
### make the user select one of the boards
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select board type:${default} " choice
|
||||
if [ "$choice" = "q" ] || [ "$choice" = "Q" ]; then
|
||||
clear && advanced_menu && break
|
||||
elif [ "$choice" -le ${#board_list[@]} ]; then
|
||||
selected_board="${board_list[$choice]}"
|
||||
break
|
||||
else
|
||||
clear && print_header
|
||||
ERROR_MSG="Invalid choice!" && print_msg && clear_msg
|
||||
flash_mcu_sd
|
||||
fi
|
||||
done
|
||||
|
||||
while true; do
|
||||
top_border
|
||||
echo -e "| If your board is flashed with firmware that connects |"
|
||||
echo -e "| at a custom baud rate, please change it now. |"
|
||||
blank_line
|
||||
echo -e "| If you are unsure, stick to the default 250000! |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### Please set the baud rate:${default} "
|
||||
unset baud_rate
|
||||
while [[ ! $baud_rate =~ ^[0-9]+$ ]]; do
|
||||
read -e -i "250000" -e baud_rate
|
||||
selected_baud_rate=$baud_rate
|
||||
break
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
###flash process
|
||||
do_action_service "stop" "klipper"
|
||||
"$flash_script" -b "$selected_baud_rate" "$selected_mcu_id" "$selected_board"
|
||||
### evaluate exit code of flash-sdcard.sh execution
|
||||
if [ ! $? -eq 0 ]; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
build_fw(){
|
||||
if [ -d "$KLIPPER_DIR" ]; then
|
||||
cd "$KLIPPER_DIR"
|
||||
status_msg "Initializing firmware build ..."
|
||||
dep=(build-essential dpkg-dev make)
|
||||
dependency_check
|
||||
make clean && make menuconfig
|
||||
status_msg "Building firmware ..."
|
||||
make && ok_msg "Firmware built!"
|
||||
else
|
||||
ERROR_MSG="Klipper was not found!\n Can not build firmware without Klipper!"
|
||||
print_msg && clear_msg && return 1
|
||||
fi
|
||||
}
|
||||
|
||||
select_mcu_connection(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${yellow}Make sure to have the controller board connected now!${default} |"
|
||||
blank_line
|
||||
echo -e "| How is the controller board connected to the host? |"
|
||||
echo -e "| 1) USB |"
|
||||
echo -e "| 2) UART |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Connection method:${default} " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
retrieve_id "USB"
|
||||
break;;
|
||||
2)
|
||||
retrieve_id "UART"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
unset mcu_count
|
||||
|
||||
if [[ "${#mcu_list[@]}" -lt 1 ]]; then
|
||||
warn_msg "No MCU found!"
|
||||
warn_msg "MCU not plugged in or not detectable!"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
retrieve_id(){
|
||||
status_msg "Identifying MCU ..."
|
||||
sleep 1
|
||||
mcu_list=()
|
||||
mcu_count=1
|
||||
[ "$1" = "USB" ] && path="/dev/serial/by-id/*"
|
||||
[ "$1" = "UART" ] && path="/dev/ttyAMA0"
|
||||
if [[ "$(ls $path)" != "" ]] ; then
|
||||
for mcu in $path; do
|
||||
declare "mcu_id_$mcu_count"="$mcu"
|
||||
mcu_id="mcu_id_$mcu_count"
|
||||
mcu_list+=("${!mcu_id}")
|
||||
echo -e " ● ($1) MCU #$mcu_count: ${cyan}$mcu${default}\n"
|
||||
let mcu_count++
|
||||
done
|
||||
fi 2>/dev/null
|
||||
}
|
||||
|
||||
check_usergroup_dialout(){
|
||||
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
|
||||
group_dialout=false
|
||||
else
|
||||
group_dialout=true
|
||||
fi
|
||||
if grep -q "tty" </etc/group && ! grep -q "tty" <(groups "${USER}"); then
|
||||
group_tty=false
|
||||
else
|
||||
group_tty=true
|
||||
fi
|
||||
if [ "$group_dialout" == "false" ] || [ "$group_tty" == "false" ] ; then
|
||||
top_border
|
||||
echo -e "| ${yellow}WARNING: Your current user is not in group:${default} |"
|
||||
[ "$group_tty" == "false" ] && echo -e "| ${yellow}● tty${default} |"
|
||||
[ "$group_dialout" == "false" ] && echo -e "| ${yellow}● dialout${default} |"
|
||||
blank_line
|
||||
echo -e "| It is possible that you won't be able to successfully |"
|
||||
echo -e "| flash without your user being a member of that group. |"
|
||||
echo -e "| If you want to add the current user to the group(s) |"
|
||||
echo -e "| listed above, answer with 'Y'. Else skip with 'n'. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}INFO:${default} |"
|
||||
echo -e "| ${yellow}Relog required for group assignments to take effect!${default} |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Adding user '${USER}' to group(s) ..."
|
||||
if [ "$group_tty" == "false" ]; then
|
||||
sudo usermod -a -G tty "${USER}" && ok_msg "Group 'tty' assigned!"
|
||||
fi
|
||||
if [ "$group_dialout" == "false" ]; then
|
||||
sudo usermod -a -G dialout "${USER}" && ok_msg "Group 'dialout' assigned!"
|
||||
fi
|
||||
ok_msg "You need to relog/restart for the group(s) to be applied!" && exit 0;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
421
scripts/fluidd.sh
Normal file
421
scripts/fluidd.sh
Normal file
@@ -0,0 +1,421 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================== INSTALL FLUIDD =================#
|
||||
#===================================================#
|
||||
|
||||
function install_fluidd() {
|
||||
### exit early if moonraker not found
|
||||
if [[ -z $(moonraker_systemd) ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### checking dependencies
|
||||
local dep=(wget nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
### detect conflicting Haproxy and Apache2 installations
|
||||
detect_conflicting_packages
|
||||
|
||||
status_msg "Initializing Fluidd installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
fluidd_port_check
|
||||
|
||||
### ask user to install mjpg-streamer
|
||||
local install_mjpg_streamer
|
||||
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Install MJGP-Streamer for webcam support? |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please select (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
install_mjpg_streamer="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
install_mjpg_streamer="false"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
### download fluidd
|
||||
download_fluidd
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
install_fluidd_macros
|
||||
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "fluidd"
|
||||
### nginx on ubuntu 21 and above needs special permissions to access the files
|
||||
set_nginx_permissions
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
|
||||
### add fluidd to the update manager in moonraker.conf
|
||||
patch_fluidd_update_manager
|
||||
|
||||
### install mjpg-streamer
|
||||
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
print_confirm "Fluidd has been set up!"
|
||||
}
|
||||
|
||||
function install_fluidd_macros() {
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to have some important macros in |"
|
||||
echo -e "| your printer configuration to have Fluidd fully |"
|
||||
echo -e "| functional and working. |"
|
||||
blank_line
|
||||
echo -e "| The recommended macros for Fluidd can be found here: |"
|
||||
echo -e "| https://docs.fluidd.xyz/configuration/initial_setup |"
|
||||
blank_line
|
||||
echo -e "| If you already have these macros in your config file, |"
|
||||
echo -e "| skip this step and answer with 'no'. |"
|
||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||
echo -e "| add the recommended example macros to your config. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
download_fluidd_macros
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
return
|
||||
}
|
||||
|
||||
function download_fluidd_macros() {
|
||||
local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg"
|
||||
local configs path
|
||||
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
|
||||
|
||||
if [[ -n ${configs} ]]; then
|
||||
for config in ${configs}; do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
if [[ ! -f "${path}/fluidd.cfg" ]]; then
|
||||
status_msg "Downloading fluidd.cfg to ${path} ..."
|
||||
log_info "downloading fluidd.cfg to: ${path}"
|
||||
wget "${fluidd_cfg}" -O "${path}/fluidd.cfg"
|
||||
|
||||
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
||||
log_info "modify fluidd.cfg"
|
||||
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg"
|
||||
|
||||
### write include to the very first line of the printer.cfg
|
||||
if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then
|
||||
log_info "modify printer.cfg"
|
||||
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log_error "execution stopped! reason: no printer.cfg found"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
function download_fluidd() {
|
||||
local url
|
||||
url=$(get_fluidd_download_url)
|
||||
|
||||
status_msg "Downloading Fluidd from ${url} ..."
|
||||
|
||||
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||
rm -rf "${FLUIDD_DIR}"
|
||||
fi
|
||||
|
||||
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
||||
|
||||
if wget "${url}"; then
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf ./*.zip && ok_msg "Done!"
|
||||
else
|
||||
print_error "Downloading Fluidd from\n ${url}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== REMOVE FLUIDD ==================#
|
||||
#===================================================#
|
||||
|
||||
function remove_fluidd_dir() {
|
||||
[[ ! -d ${FLUIDD_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Fluidd directory ..."
|
||||
rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_fluidd_config() {
|
||||
if [[ -e "/etc/nginx/sites-available/fluidd" ]]; then
|
||||
status_msg "Removing Fluidd configuration for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!"
|
||||
fi
|
||||
if [[ -L "/etc/nginx/sites-enabled/fluidd" ]]; then
|
||||
status_msg "Removing Fluidd Symlink for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd_logs() {
|
||||
local files
|
||||
files=$(find /var/log/nginx -name "fluidd*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
sudo rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd_log_symlinks() {
|
||||
local files
|
||||
files=$(find "${KLIPPER_LOGS}" -name "fluidd*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd() {
|
||||
remove_fluidd_dir
|
||||
remove_fluidd_config
|
||||
remove_fluidd_logs
|
||||
remove_fluidd_log_symlinks
|
||||
|
||||
### remove fluidd_port from ~/.kiauh.ini
|
||||
sed -i "/^fluidd_port=/d" "${INI_FILE}"
|
||||
|
||||
print_confirm "Fluidd successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== UPDATE FLUIDD ==================#
|
||||
#===================================================#
|
||||
|
||||
function update_fluidd() {
|
||||
backup_before_update "fluidd"
|
||||
status_msg "Updating Fluidd ..."
|
||||
download_fluidd
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
print_confirm "Fluidd successfully updated!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== FLUIDD STATUS ==================#
|
||||
#===================================================#
|
||||
|
||||
function get_fluidd_status() {
|
||||
local status
|
||||
local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd")
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_fluidd_version() {
|
||||
[[ ! -f "${FLUIDD_DIR}/.version" ]] && return
|
||||
|
||||
local version
|
||||
version=$(head -n 1 "${FLUIDD_DIR}/.version")
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function get_remote_fluidd_version() {
|
||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||
|
||||
local version
|
||||
version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev)
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function compare_fluidd_versions() {
|
||||
unset FLUIDD_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_fluidd_version)"
|
||||
remote_ver="$(get_remote_fluidd_version)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add fluidd to the update all array for the update all function in the updater
|
||||
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
FLUIDD_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_fluidd_download_url() {
|
||||
local tags latest_tag latest_url stable_tag stable_url url
|
||||
tags=$(curl -s "${FLUIDD_TAGS}" | grep "name" | cut -d'"' -f4)
|
||||
|
||||
### latest download url including pre-releases (alpha, beta, rc)
|
||||
latest_tag=$(echo "${tags}" | head -1)
|
||||
latest_url="https://github.com/fluidd-core/fluidd/releases/download/${latest_tag}/fluidd.zip"
|
||||
|
||||
### get stable fluidd download url
|
||||
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
|
||||
stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip"
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
if [[ ${fluidd_install_unstable} == "true" ]]; then
|
||||
url="${latest_url}"
|
||||
echo "${url}"
|
||||
else
|
||||
url="${stable_url}"
|
||||
echo "${url}"
|
||||
fi
|
||||
}
|
||||
|
||||
function fluidd_port_check() {
|
||||
if [[ ${FLUIDD_ENABLED} == "false" ]]; then
|
||||
|
||||
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
|
||||
[[ ${MAINSAIL_ENABLED} == "true" ]] && \
|
||||
echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}"
|
||||
|
||||
if [[ ${MAINSAIL_PORT} == "80" ]]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_fluidd_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
function select_fluidd_port() {
|
||||
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||
echo -e "| ${red}You need to choose a different port for Fluidd!${white} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||
blank_line
|
||||
[[ ${MAINSAIL_PORT} == "80" ]] && echo "| ● Mainsail |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which is already |"
|
||||
echo -e "| assigned to another webinterface! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
|
||||
local new_port re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||
if [[ ${new_port} =~ ${re} && ${new_port} != "${MAINSAIL_PORT}" ]]; then
|
||||
select_msg "Setting port ${new_port} for Fluidd!"
|
||||
SET_LISTEN_PORT=${new_port}
|
||||
break
|
||||
else
|
||||
if [[ ! ${new_port} =~ ${re} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
else
|
||||
error_msg "Port already taken! Select a different one!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function patch_fluidd_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager fluidd\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Fluidds update manager section to moonraker.conf
|
||||
status_msg "Adding Fluidd to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager fluidd]
|
||||
type: web
|
||||
channel: stable
|
||||
repo: fluidd-core/fluidd
|
||||
path: ~/fluidd
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -1,419 +0,0 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
set_klipper_cfg_path(){
|
||||
### stop services
|
||||
do_action_service "stop" "klipper"
|
||||
do_action_service "stop" "moonraker"
|
||||
|
||||
### copy config files to new klipper config folder
|
||||
if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then
|
||||
if [ ! -d "$new_klipper_cfg_loc" ]; then
|
||||
status_msg "Copy config files to '$new_klipper_cfg_loc' ..."
|
||||
mkdir -p "$new_klipper_cfg_loc"
|
||||
cd $old_klipper_cfg_loc
|
||||
cp -r -v ./* "$new_klipper_cfg_loc"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
fi
|
||||
|
||||
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])+[0-9]*.service")
|
||||
### handle single klipper instance service file
|
||||
if [ -f $SYSTEMDDIR/klipper.service ]; then
|
||||
status_msg "Configuring Klipper for new path ..."
|
||||
sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer.cfg|klippy.py $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service
|
||||
ok_msg "OK!"
|
||||
elif [ -n "$SERVICE_FILES" ]; then
|
||||
### handle multi klipper instance service file
|
||||
status_msg "Configuring Klipper for new path ..."
|
||||
for service in $SERVICE_FILES; do
|
||||
sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer_|klippy.py $new_klipper_cfg_loc/printer_|" "$service"
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])+[0-9]*.service")
|
||||
### handle single moonraker instance service and moonraker.conf file
|
||||
if [ -f $SYSTEMDDIR/moonraker.service ]; then
|
||||
status_msg "Configuring Moonraker for new path ..."
|
||||
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c $new_klipper_cfg_loc/moonraker.conf|" $SYSTEMDDIR/moonraker.service
|
||||
|
||||
### replace old file path with new one in moonraker.conf
|
||||
sed -i -r "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
|
||||
ok_msg "OK!"
|
||||
elif [ -n "$SERVICE_FILES" ]; then
|
||||
### handle multi moonraker instance service file
|
||||
status_msg "Configuring Moonraker for new path ..."
|
||||
for service in $SERVICE_FILES; do
|
||||
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" "$service"
|
||||
done
|
||||
MR_CONFS=$(find "$new_klipper_cfg_loc" -regextype posix-extended -regex "$new_klipper_cfg_loc/printer_[1-9]+/moonraker.conf")
|
||||
### replace old file path with new one in moonraker.conf
|
||||
for moonraker_conf in $MR_CONFS; do
|
||||
loc=$(echo "$moonraker_conf" | rev | cut -d"/" -f2- | rev)
|
||||
sed -i -r "/config_path:/ s|config_path:.*|config_path: $loc|" "$moonraker_conf"
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
### restart services
|
||||
do_action_service "restart" "klipper"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
source_kiauh_ini(){
|
||||
source $INI_FILE
|
||||
}
|
||||
|
||||
do_action_service(){
|
||||
shopt -s extglob # enable extended globbing
|
||||
SERVICES="$SYSTEMDDIR/$2?(-*([0-9])).service"
|
||||
### set a variable for the ok and status messages
|
||||
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
||||
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
||||
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
||||
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling"
|
||||
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling"
|
||||
|
||||
if ls $SERVICES 2>/dev/null 1>&2; then
|
||||
for service in $(ls $SERVICES | rev | cut -d"/" -f1 | rev); do
|
||||
status_msg "$ACTION2 $service ..."
|
||||
sudo systemctl $1 "$service"
|
||||
ok_msg "$service $ACTION1!"
|
||||
done
|
||||
fi
|
||||
shopt -u extglob # disable extended globbing
|
||||
}
|
||||
|
||||
toggle_octoprint_service(){
|
||||
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
|
||||
do_action_service "stop" "octoprint"
|
||||
do_action_service "disable" "octoprint"
|
||||
sleep 2
|
||||
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
|
||||
elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
|
||||
do_action_service "enable" "octoprint"
|
||||
do_action_service "start" "octoprint"
|
||||
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 [ ! -f "/etc/systemd/system/octoprint.service" ]; then
|
||||
return 0
|
||||
fi
|
||||
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!"
|
||||
}
|
||||
|
||||
start_MoonrakerTelegramBot(){
|
||||
status_msg "Starting MoonrakerTelegramBot Service ..."
|
||||
sudo systemctl start moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service started!"
|
||||
}
|
||||
|
||||
stop_MoonrakerTelegramBot(){
|
||||
status_msg "Stopping MoonrakerTelegramBot Service ..."
|
||||
sudo systemctl stop moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service stopped!"
|
||||
}
|
||||
|
||||
restart_MoonrakerTelegramBot(){
|
||||
status_msg "Restarting MoonrakerTelegramBot Service ..."
|
||||
sudo systemctl restart moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service restarted!"
|
||||
}
|
||||
|
||||
restart_nginx(){
|
||||
if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then
|
||||
status_msg "Restarting NGINX Service ..."
|
||||
sudo systemctl restart nginx && ok_msg "NGINX Service restarted!"
|
||||
fi
|
||||
}
|
||||
|
||||
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 update --allow-releaseinfo-change && 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 ..."
|
||||
if [ -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py ]; then
|
||||
warn_msg "There is already a file named 'gcode_shell_command.py'\nin 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(){
|
||||
do_action_service "stop" "klipper"
|
||||
status_msg "Copy 'gcode_shell_command.py' to '$KLIPPER_DIR/klippy/extras' ..."
|
||||
cp ${SRCDIR}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
|
||||
while true; do
|
||||
echo
|
||||
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!"
|
||||
do_action_service "restart" "klipper"
|
||||
}
|
||||
|
||||
create_minimal_cfg(){
|
||||
#create a minimal default config
|
||||
if [ "$SEL_DEF_CFG" = "true" ]; then
|
||||
cat <<- EOF >> $PRINTER_CFG
|
||||
[mcu]
|
||||
serial: </dev/serial/by-id/your-mcu>
|
||||
|
||||
[printer]
|
||||
kinematics: none
|
||||
max_velocity: 1
|
||||
max_accel: 1
|
||||
|
||||
[virtual_sdcard]
|
||||
path: ~/sdcard
|
||||
|
||||
[pause_resume]
|
||||
[display_status]
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
fetch_webui_ports
|
||||
}
|
||||
122
scripts/gcode_shell_command.sh
Normal file
122
scripts/gcode_shell_command.sh
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#======== INSTALL GCODE_SHELL_COMMAND.PY =========#
|
||||
#=================================================#
|
||||
|
||||
function setup_gcode_shell_command() {
|
||||
top_border
|
||||
echo -e "| You are about to install the 'G-Code Shell Command' |"
|
||||
echo -e "| extension. Please make sure to read the instructions |"
|
||||
echo -e "| before you continue and remember that potential risks |"
|
||||
echo -e "| can be involved after installing this extension! |"
|
||||
blank_line
|
||||
echo -e "| ${red}You accept that you are doing this on your own risk!${white} |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
|
||||
if [[ ! -d "${KLIPPER_DIR}/klippy/extras" ]]; then
|
||||
print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Installing gcode shell command extension ..."
|
||||
|
||||
if [[ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]]; then
|
||||
install_gcode_shell_command
|
||||
else
|
||||
echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!"
|
||||
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py"
|
||||
install_gcode_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
return;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function install_gcode_shell_command() {
|
||||
do_action_service "stop" "klipper"
|
||||
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
|
||||
|
||||
if cp "${KIAUH_SRCDIR}/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then
|
||||
ok_msg "Done!"
|
||||
else
|
||||
error_msg "Cannot copy file to target destination...Exiting!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
create_example_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
do_action_service "restart" "klipper"
|
||||
print_confirm "Shell command extension installed!"
|
||||
return
|
||||
}
|
||||
|
||||
function create_example_shell_command() {
|
||||
### create a backup of the config folder
|
||||
backup_klipper_config_dir
|
||||
|
||||
local printer_cfgs path
|
||||
printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg" | sort)
|
||||
|
||||
for cfg in ${printer_cfgs}; do
|
||||
path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev)
|
||||
|
||||
if [[ ! -f "${path}/shell_command.cfg" ]]; then
|
||||
status_msg "Copy shell_command.cfg to ${path} ..."
|
||||
cp "${KIAUH_SRCDIR}/resources/shell_command.cfg" "${path}"
|
||||
ok_msg "${path}/shell_command.cfg created!"
|
||||
### write include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include shell_command.cfg]" "${cfg}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
73
scripts/globals.sh
Normal file
73
scripts/globals.sh
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
set -e
|
||||
|
||||
function set_globals() {
|
||||
#=================== SYSTEM ===================#
|
||||
SYSTEMD="/etc/systemd/system"
|
||||
INITD="/etc/init.d"
|
||||
ETCDEF="/etc/default"
|
||||
|
||||
#=================== KIAUH ====================#
|
||||
green=$(echo -en "\e[92m")
|
||||
yellow=$(echo -en "\e[93m")
|
||||
magenta=$(echo -en "\e[35m")
|
||||
red=$(echo -en "\e[91m")
|
||||
cyan=$(echo -en "\e[96m")
|
||||
white=$(echo -en "\e[39m")
|
||||
INI_FILE="${HOME}/.kiauh.ini"
|
||||
LOGFILE="/tmp/kiauh.log"
|
||||
RESOURCES="${KIAUH_SRCDIR}/resources"
|
||||
BACKUP_DIR="${HOME}/kiauh-backups"
|
||||
|
||||
#================== KLIPPER ===================#
|
||||
KLIPPY_ENV="${HOME}/klippy-env"
|
||||
KLIPPER_DIR="${HOME}/klipper"
|
||||
KLIPPER_REPO="https://github.com/Klipper3d/klipper.git"
|
||||
KLIPPER_LOGS="${HOME}/klipper_logs"
|
||||
KLIPPER_CONFIG="$(get_klipper_cfg_dir)" # default: ${HOME}/klipper_config
|
||||
|
||||
#================= MOONRAKER ==================#
|
||||
MOONRAKER_ENV="${HOME}/moonraker-env"
|
||||
MOONRAKER_DIR="${HOME}/moonraker"
|
||||
MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
|
||||
|
||||
#================= MAINSAIL ===================#
|
||||
MAINSAIL_DIR="${HOME}/mainsail"
|
||||
MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases"
|
||||
MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags"
|
||||
|
||||
#================== FLUIDD ====================#
|
||||
FLUIDD_DIR="${HOME}/fluidd"
|
||||
FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases"
|
||||
FLUIDD_TAGS="https://api.github.com/repos/fluidd-core/fluidd/tags"
|
||||
|
||||
#=============== KLIPPERSCREEN ================#
|
||||
KLIPPERSCREEN_ENV="${HOME}/.KlipperScreen-env"
|
||||
KLIPPERSCREEN_DIR="${HOME}/KlipperScreen"
|
||||
KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git"
|
||||
|
||||
#========== MOONRAKER-TELEGRAM-BOT ============#
|
||||
TELEGRAM_BOT_ENV="${HOME}/moonraker-telegram-bot-env"
|
||||
TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot"
|
||||
TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git"
|
||||
|
||||
#=============== PRETTY-GCODE =================#
|
||||
PGC_DIR="${HOME}/pgcode"
|
||||
PGC_REPO="https://github.com/Kragrathea/pgcode"
|
||||
|
||||
#================== NGINX =====================#
|
||||
NGINX_SA="/etc/nginx/sites-available"
|
||||
NGINX_SE="/etc/nginx/sites-enabled"
|
||||
NGINX_CONFD="/etc/nginx/conf.d"
|
||||
}
|
||||
@@ -1,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_services_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 --allow-releaseinfo-change
|
||||
|
||||
# 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
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
KLIPPY_ENV="${HOME}/klippy-env"
|
||||
KLIPPER_DIR="${HOME}/klipper"
|
||||
KLIPPER_REPO="https://github.com/Klipper3d/klipper.git"
|
||||
|
||||
klipper_setup_dialog(){
|
||||
### check for existing klipper service installations
|
||||
SERVICE_FILES=""
|
||||
INITD_SERVICE_FILES=$(find "/etc/init.d" -regextype posix-extended -regex "/etc/init.d/klipper(-[^0])?[0-9]*")
|
||||
SYSTEMD_SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])?[0-9]*.service")
|
||||
[ -n "$INITD_SERVICE_FILES" ] && SERVICE_FILES+="${INITD_SERVICE_FILES}"
|
||||
[ -n "$SYSTEMD_SERVICE_FILES" ] && SERVICE_FILES+=" ${SYSTEMD_SERVICE_FILES}"
|
||||
if [ -n "$SERVICE_FILES" ]; then
|
||||
ERROR_MSG="At least one Klipper service is already installed:"
|
||||
for service in $SERVICE_FILES; do
|
||||
ERROR_MSG="${ERROR_MSG}\n ➔ $service"
|
||||
done && return
|
||||
fi
|
||||
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
|
||||
### initial printer.cfg path check
|
||||
check_klipper_cfg_path
|
||||
|
||||
### ask for amount of instances to create
|
||||
top_border
|
||||
echo -e "| Please select the number of Klipper instances to set |"
|
||||
echo -e "| up. The number of Klipper instances will determine |"
|
||||
echo -e "| the amount of printers you can run from this machine. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}WARNING: There is no limit on the number of instances${default} |"
|
||||
echo -e "| ${yellow}you can set up with this script.${default} |"
|
||||
bottom_border
|
||||
count=""
|
||||
while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do
|
||||
read -p "${cyan}###### Number of Klipper instances to set up:${default} " count
|
||||
if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then
|
||||
warn_msg "Invalid Input!" && echo
|
||||
else
|
||||
echo
|
||||
read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Installing $count Klipper instance(s) ..."
|
||||
klipper_setup "$count"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
warn_msg "Exiting Klipper setup ..."
|
||||
echo
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install_klipper_packages(){
|
||||
### read PKGLIST from official install script
|
||||
status_msg "Reading dependencies..."
|
||||
install_script="${HOME}/klipper/scripts/install-octopi.sh"
|
||||
#PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g')
|
||||
PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n')
|
||||
### add dbus requirement for DietPi distro
|
||||
[ -e "/boot/dietpi/.version" ] && PKGLIST+=" dbus"
|
||||
|
||||
for pkg in $PKGLIST; do
|
||||
echo "${cyan}$pkg${default}"
|
||||
done
|
||||
read -r -a PKGLIST <<< "$PKGLIST"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Running apt-get update..."
|
||||
sudo apt-get update --allow-releaseinfo-change
|
||||
|
||||
### 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
|
||||
}
|
||||
|
||||
klipper_setup(){
|
||||
INSTANCE_COUNT=$1
|
||||
### checking dependencies
|
||||
dep=(git)
|
||||
dependency_check
|
||||
|
||||
### step 1: clone klipper
|
||||
status_msg "Downloading Klipper ..."
|
||||
### force remove existing klipper dir and clone into fresh klipper dir
|
||||
[ -d "$KLIPPER_DIR" ] && rm -rf "$KLIPPER_DIR"
|
||||
cd "${HOME}" && git clone "$KLIPPER_REPO"
|
||||
status_msg "Download complete!"
|
||||
|
||||
### step 2: install klipper dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_klipper_packages
|
||||
create_klipper_virtualenv
|
||||
|
||||
### step 3: create shared gcode_files and logs folder
|
||||
[ ! -d "${HOME}"/gcode_files ] && mkdir -p "${HOME}"/gcode_files
|
||||
[ ! -d "${HOME}"/klipper_logs ] && mkdir -p "${HOME}"/klipper_logs
|
||||
|
||||
### step 4: create klipper instances
|
||||
create_klipper_service
|
||||
|
||||
### confirm message
|
||||
if [[ $INSTANCE_COUNT -eq 1 ]]; then
|
||||
CONFIRM_MSG="Klipper has been set up!"
|
||||
elif [[ $INSTANCE_COUNT -gt 1 ]]; then
|
||||
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
|
||||
fi && print_msg && clear_msg
|
||||
}
|
||||
|
||||
create_klipper_service(){
|
||||
### get config directory
|
||||
source_kiauh_ini
|
||||
|
||||
### set up default values
|
||||
SINGLE_INST=1
|
||||
CFG_PATH="$klipper_cfg_loc"
|
||||
KL_ENV=$KLIPPY_ENV
|
||||
KL_DIR=$KLIPPER_DIR
|
||||
KL_LOG="${HOME}/klipper_logs/klippy.log"
|
||||
KL_UDS="/tmp/klippy_uds"
|
||||
P_TMP="/tmp/printer"
|
||||
P_CFG="$CFG_PATH/printer.cfg"
|
||||
P_CFG_SRC="${SRCDIR}/kiauh/resources/printer.cfg"
|
||||
KL_SERV_SRC="${SRCDIR}/kiauh/resources/klipper.service"
|
||||
KL_SERV_TARGET="$SYSTEMDDIR/klipper.service"
|
||||
|
||||
write_kl_service(){
|
||||
[ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH"
|
||||
### create a minimal config if there is no printer.cfg
|
||||
[ ! -f "$P_CFG" ] && cp "$P_CFG_SRC" "$P_CFG"
|
||||
### replace placeholder
|
||||
if [ ! -f $KL_SERV_TARGET ]; then
|
||||
status_msg "Creating Klipper Service $i ..."
|
||||
sudo cp "$KL_SERV_SRC" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%INST%|$i|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%USER%|${USER}|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%KL_ENV%|$KL_ENV|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%KL_DIR%|$KL_DIR|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%KL_LOG%|$KL_LOG|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%P_CFG%|$P_CFG|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%P_TMP%|$P_TMP|" $KL_SERV_TARGET
|
||||
sudo sed -i "s|%KL_UDS%|$KL_UDS|" $KL_SERV_TARGET
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then
|
||||
### write single instance service
|
||||
write_kl_service
|
||||
### enable instance
|
||||
sudo systemctl enable klipper.service
|
||||
ok_msg "Single Klipper instance created!"
|
||||
### launching instance
|
||||
status_msg "Launching Klipper instance ..."
|
||||
sudo systemctl start klipper
|
||||
else
|
||||
i=1
|
||||
while [[ $i -le $INSTANCE_COUNT ]]; do
|
||||
### rewrite default variables for multi instance cases
|
||||
CFG_PATH="$klipper_cfg_loc/printer_$i"
|
||||
KL_SERV_TARGET="$SYSTEMDDIR/klipper-$i.service"
|
||||
P_TMP="/tmp/printer-$i"
|
||||
P_CFG="$CFG_PATH/printer.cfg"
|
||||
KL_LOG="${HOME}/klipper_logs/klippy-$i.log"
|
||||
KL_UDS="/tmp/klippy_uds-$i"
|
||||
### write multi instance service
|
||||
write_kl_service
|
||||
### enable instance
|
||||
sudo systemctl enable klipper-$i.service
|
||||
ok_msg "Klipper instance #$i created!"
|
||||
### launching instance
|
||||
status_msg "Launching Klipper instance #$i ..."
|
||||
sudo systemctl start klipper-$i
|
||||
|
||||
### raise values by 1
|
||||
i=$((i+1))
|
||||
done
|
||||
unset i
|
||||
fi
|
||||
}
|
||||
@@ -1,603 +0,0 @@
|
||||
MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases"
|
||||
FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases"
|
||||
|
||||
system_check_webui(){
|
||||
### check system for installed moonraker service
|
||||
if ls /etc/systemd/system/moonraker.service 2>/dev/null 1>&2 || ls /etc/systemd/system | grep -q -E "moonraker-[[:digit:]]+.service"; then
|
||||
moonraker_chk_ok="true"
|
||||
else
|
||||
moonraker_chk_ok="false"
|
||||
fi
|
||||
|
||||
### check system for an installed and enabled octoprint service
|
||||
if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
|
||||
OCTOPRINT_ENABLED="true"
|
||||
fi
|
||||
|
||||
### check system for an installed haproxy service
|
||||
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
|
||||
HAPROXY_FOUND="true"
|
||||
fi
|
||||
|
||||
### check system for an installed lighttpd service
|
||||
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
|
||||
LIGHTTPD_FOUND="true"
|
||||
fi
|
||||
|
||||
### check system for an installed apache2 service
|
||||
if [[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]]; then
|
||||
APACHE2_FOUND="true"
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selection_mjpg-streamer(){
|
||||
while true; do
|
||||
unset INSTALL_MJPG
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Install MJGP-Streamer for webcam support? |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
INSTALL_MJPG="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
INSTALL_MJPG="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
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(){
|
||||
source_kiauh_ini
|
||||
### checking dependencies
|
||||
dep=(nginx)
|
||||
dependency_check
|
||||
### check if moonraker is already installed
|
||||
system_check_webui
|
||||
### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found
|
||||
process_octoprint_dialog
|
||||
process_services_dialog
|
||||
### process possible disruptive services
|
||||
process_disruptive_services
|
||||
|
||||
[ "$1" == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail "
|
||||
[ "$1" == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd "
|
||||
|
||||
### 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
|
||||
fi
|
||||
|
||||
status_msg "Initializing $IF_NAME1 installation ..."
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
$1_port_check
|
||||
|
||||
### ask user to install mjpg-streamer
|
||||
if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then
|
||||
get_user_selection_mjpg-streamer
|
||||
fi
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
if ! ls "$klipper_cfg_loc"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "$klipper_cfg_loc"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then
|
||||
get_user_selection_kiauh_macros "$IF_NAME2"
|
||||
fi
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "$1"
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "$1"
|
||||
|
||||
### copy the kiauh_macros.cfg to the config location
|
||||
install_kiauh_macros
|
||||
|
||||
### install mainsail/fluidd
|
||||
$1_setup
|
||||
|
||||
### install mjpg-streamer
|
||||
[ "$INSTALL_MJPG" = "true" ] && install_mjpg-streamer
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
CONFIRM_MSG="$IF_NAME1 has been set up!"
|
||||
print_msg && clear_msg
|
||||
}
|
||||
|
||||
symlink_webui_nginx_log(){
|
||||
LPATH="${HOME}/klipper_logs"
|
||||
UI_ACCESS_LOG="/var/log/nginx/$1-access.log"
|
||||
UI_ERROR_LOG="/var/log/nginx/$1-error.log"
|
||||
[ ! -d "$LPATH" ] && mkdir -p "$LPATH"
|
||||
if [ -f "$UI_ACCESS_LOG" ] && [ ! -L "$LPATH/$1-access.log" ]; then
|
||||
status_msg "Creating symlink for $UI_ACCESS_LOG ..."
|
||||
ln -s "$UI_ACCESS_LOG" "$LPATH"
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -f "$UI_ERROR_LOG" ] && [ ! -L "$LPATH/$1-error.log" ]; then
|
||||
status_msg "Creating symlink for $UI_ERROR_LOG ..."
|
||||
ln -s "$UI_ERROR_LOG" "$LPATH"
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
}
|
||||
|
||||
install_kiauh_macros(){
|
||||
source_kiauh_ini
|
||||
### copy kiauh_macros.cfg
|
||||
if [ "$ADD_KIAUH_MACROS" = "true" ]; then
|
||||
### create a backup of the config folder
|
||||
backup_klipper_config_dir
|
||||
### handle multi printer.cfg
|
||||
if ls "$klipper_cfg_loc"/printer_* 2>/dev/null 1>&2; then
|
||||
for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do
|
||||
path=$(echo "$config" | rev | cut -d"/" -f2- | rev)
|
||||
if [ ! -f "$path/kiauh_macros.cfg" ]; then
|
||||
### copy kiauh_macros.cfg to config location
|
||||
status_msg "Creating macro config file ..."
|
||||
cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$path"
|
||||
### write the include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include kiauh_macros.cfg]" "$path/printer.cfg"
|
||||
ok_msg "$path/kiauh_macros.cfg created!"
|
||||
fi
|
||||
done
|
||||
### handle single printer.cfg
|
||||
elif [ -f "$klipper_cfg_loc/printer.cfg" ] && [ ! -f "$klipper_cfg_loc/kiauh_macros.cfg" ]; then
|
||||
### copy kiauh_macros.cfg to config location
|
||||
status_msg "Creating macro config file ..."
|
||||
cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$klipper_cfg_loc"
|
||||
### write the include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include kiauh_macros.cfg]" "$klipper_cfg_loc/printer.cfg"
|
||||
ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!"
|
||||
fi
|
||||
### restart klipper service to parse the modified printer.cfg
|
||||
do_action_service "restart" "klipper"
|
||||
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 $MAINSAIL_REPO_API | grep tag_name | cut -d'"' -f4 | head -1)
|
||||
}
|
||||
|
||||
get_fluidd_ver(){
|
||||
FLUIDD_VERSION=$(curl -s $FLUIDD_REPO_API | grep tag_name | cut -d'"' -f4 | head -1)
|
||||
}
|
||||
|
||||
mainsail_setup(){
|
||||
### get mainsail download url
|
||||
MAINSAIL_DL_URL=$(curl -s $MAINSAIL_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1)
|
||||
|
||||
### remove existing and create fresh mainsail folder, then download mainsail
|
||||
[ -d "$MAINSAIL_DIR" ] && rm -rf "$MAINSAIL_DIR"
|
||||
mkdir "$MAINSAIL_DIR" && cd $MAINSAIL_DIR
|
||||
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* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then
|
||||
enable_mainsail_remotemode
|
||||
fi
|
||||
}
|
||||
|
||||
enable_mainsail_remotemode(){
|
||||
rm -f "$MAINSAIL_DIR/config.json"
|
||||
echo -e "{\n \"remoteMode\":true\n}" >> "$MAINSAIL_DIR/config.json"
|
||||
}
|
||||
|
||||
fluidd_setup(){
|
||||
### get fluidd download url
|
||||
FLUIDD_DL_URL=$(curl -s $FLUIDD_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1)
|
||||
|
||||
### remove existing and create fresh fluidd folder, then download fluidd
|
||||
[ -d "$FLUIDD_DIR" ] && rm -rf "$FLUIDD_DIR"
|
||||
mkdir "$FLUIDD_DIR" && cd $FLUIDD_DIR
|
||||
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!"
|
||||
}
|
||||
|
||||
set_upstream_nginx_cfg(){
|
||||
get_date
|
||||
### backup existing nginx configs
|
||||
[ ! -d "$BACKUP_DIR/nginx_cfg" ] && mkdir -p "$BACKUP_DIR/nginx_cfg"
|
||||
[ -f "$NGINX_CONFD/upstreams.conf" ] && sudo mv "$NGINX_CONFD/upstreams.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_upstreams.conf"
|
||||
[ -f "$NGINX_CONFD/common_vars.conf" ] && sudo mv "$NGINX_CONFD/common_vars.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_common_vars.conf"
|
||||
### transfer ownership of backed up files from root to ${USER}
|
||||
for log in $(ls "$BACKUP_DIR/nginx_cfg"); do
|
||||
sudo chown "${USER}" "$BACKUP_DIR/nginx_cfg/$log"
|
||||
done
|
||||
### copy nginx configs to target destination
|
||||
if [ ! -f "$NGINX_CONFD/upstreams.conf" ]; then
|
||||
sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "$NGINX_CONFD"
|
||||
fi
|
||||
if [ ! -f "$NGINX_CONFD/common_vars.conf" ]; then
|
||||
sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "$NGINX_CONFD"
|
||||
fi
|
||||
}
|
||||
|
||||
fetch_webui_ports(){
|
||||
### read listen ports from possible installed interfaces
|
||||
### and write them to ~/.kiauh.ini
|
||||
WEBIFS=(mainsail fluidd octoprint dwc2)
|
||||
for interface in "${WEBIFS[@]}"; do
|
||||
if [ -f "/etc/nginx/sites-available/${interface}" ]; then
|
||||
port=$(grep -E "listen" "/etc/nginx/sites-available/$interface" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2)
|
||||
if [ ! -n "$(grep -E "${interface}_port" "$INI_FILE")" ]; then
|
||||
sed -i '$a'"${interface}_port=${port}" "$INI_FILE"
|
||||
else
|
||||
sed -i "/^${interface}_port/d" "$INI_FILE"
|
||||
sed -i '$a'"${interface}_port=${port}" "$INI_FILE"
|
||||
fi
|
||||
else
|
||||
sed -i "/^${interface}_port/d" "$INI_FILE"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
match_nginx_configs(){
|
||||
### reinstall nginx configs if the amount of upstreams don't match anymore
|
||||
source_kiauh_ini
|
||||
cfg_updated="false"
|
||||
mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail"
|
||||
fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd"
|
||||
upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l)
|
||||
status_msg "Checking validity of NGINX configurations ..."
|
||||
if [ -e "$mainsail_nginx_cfg" ]; then
|
||||
mainsail_webcams=$(grep -E "mjpgstreamer" "$mainsail_nginx_cfg" | wc -l)
|
||||
fi
|
||||
if [ -e "$fluidd_nginx_cfg" ]; then
|
||||
fluidd_webcams=$(grep -E "mjpgstreamer" "$fluidd_nginx_cfg" | wc -l)
|
||||
fi
|
||||
### check for outdated upstreams.conf
|
||||
if [[ "$upstreams_webcams" -lt "$mainsail_webcams" ]] || [[ "$upstreams_webcams" -lt "$fluidd_webcams" ]]; then
|
||||
status_msg "Outdated upstreams.conf found! Updating ..."
|
||||
sudo rm -f "$NGINX_CONFD/upstreams.conf"
|
||||
sudo rm -f "$NGINX_CONFD/common_vars.conf"
|
||||
set_upstream_nginx_cfg
|
||||
cfg_updated="true"
|
||||
fi
|
||||
### check for outdated mainsail config
|
||||
if [ -e "$mainsail_nginx_cfg" ]; then
|
||||
if [[ "$upstreams_webcams" -gt "$mainsail_webcams" ]]; then
|
||||
status_msg "Outdated Mainsail config found! Updating ..."
|
||||
sudo rm -f "$mainsail_nginx_cfg"
|
||||
sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "$mainsail_nginx_cfg"
|
||||
sudo sed -i "s/<<UI>>/mainsail/g" "$mainsail_nginx_cfg"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "$mainsail_nginx_cfg"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen $mainsail_port;/" "$mainsail_nginx_cfg"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$mainsail_port;/" "$mainsail_nginx_cfg"
|
||||
cfg_updated="true" && ok_msg "Done!"
|
||||
fi
|
||||
fi
|
||||
### check for outdated fluidd config
|
||||
if [ -e "$fluidd_nginx_cfg" ]; then
|
||||
if [[ "$upstreams_webcams" -gt "$fluidd_webcams" ]]; then
|
||||
status_msg "Outdated Fluidd config found! Updating ..."
|
||||
sudo rm -f "$fluidd_nginx_cfg"
|
||||
sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "$fluidd_nginx_cfg"
|
||||
sudo sed -i "s/<<UI>>/fluidd/g" "$fluidd_nginx_cfg"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "$fluidd_nginx_cfg"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen $fluidd_port;/" "$fluidd_nginx_cfg"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$fluidd_port;/" "$fluidd_nginx_cfg"
|
||||
cfg_updated="true" && ok_msg "Done!"
|
||||
fi
|
||||
fi
|
||||
### only restart nginx if configs were updated
|
||||
if [ "$cfg_updated" == "true" ]; then
|
||||
restart_nginx && unset cfg_updated
|
||||
fi
|
||||
}
|
||||
|
||||
process_octoprint_dialog(){
|
||||
#ask user to disable octoprint when its service was found
|
||||
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |"
|
||||
hr
|
||||
echo -e "| You might consider disabling the OctoPrint service, |"
|
||||
echo -e "| since an active OctoPrint service may lead to unex- |"
|
||||
echo -e "| pected behavior of the Klipper Webinterfaces. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Stopping OctoPrint ..."
|
||||
do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!"
|
||||
status_msg "Disabling OctoPrint ..."
|
||||
do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
process_disruptive_services(){
|
||||
#handle haproxy service
|
||||
if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then
|
||||
if systemctl is-active haproxy -q; then
|
||||
status_msg "Stopping haproxy service ..."
|
||||
sudo systemctl stop haproxy && ok_msg "Service stopped!"
|
||||
fi
|
||||
|
||||
### disable haproxy
|
||||
if [ "$DISABLE_HAPROXY" = "true" ]; then
|
||||
status_msg "Disabling haproxy ..."
|
||||
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
|
||||
|
||||
### remove haproxy
|
||||
if [ "$REMOVE_HAPROXY" = "true" ]; then
|
||||
status_msg "Removing haproxy ..."
|
||||
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
### handle lighttpd service
|
||||
if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then
|
||||
if systemctl is-active lighttpd -q; then
|
||||
status_msg "Stopping lighttpd service ..."
|
||||
sudo systemctl stop lighttpd && ok_msg "Service stopped!"
|
||||
fi
|
||||
|
||||
### disable lighttpd
|
||||
if [ "$DISABLE_LIGHTTPD" = "true" ]; then
|
||||
status_msg "Disabling lighttpd ..."
|
||||
sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!"
|
||||
|
||||
### remove lighttpd
|
||||
if [ "$REMOVE_LIGHTTPD" = "true" ]; then
|
||||
status_msg "Removing lighttpd ..."
|
||||
sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
### handle apache2 service
|
||||
if [ "$DISABLE_APACHE2" = "true" ] || [ "$REMOVE_APACHE2" = "true" ]; then
|
||||
if systemctl is-active apache2 -q; then
|
||||
status_msg "Stopping apache2 service ..."
|
||||
sudo systemctl stop apache2 && ok_msg "Service stopped!"
|
||||
fi
|
||||
|
||||
### disable lighttpd
|
||||
if [ "$DISABLE_APACHE2" = "true" ]; then
|
||||
status_msg "Disabling lighttpd ..."
|
||||
sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!"
|
||||
|
||||
### remove lighttpd
|
||||
if [ "$REMOVE_APACHE2" = "true" ]; then
|
||||
status_msg "Removing apache2 ..."
|
||||
sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
process_services_dialog(){
|
||||
#notify user about haproxy or lighttpd services found and possible issues
|
||||
if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ] || [ "$APACHE2_FOUND" = "true" ]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |"
|
||||
hr
|
||||
if [ "$HAPROXY_FOUND" = "true" ]; then
|
||||
echo -e "| ● haproxy |"
|
||||
fi
|
||||
if [ "$LIGHTTPD_FOUND" = "true" ]; then
|
||||
echo -e "| ● lighttpd |"
|
||||
fi
|
||||
if [ "$APACHE2_FOUND" = "true" ]; then
|
||||
echo -e "| ● apache2 |"
|
||||
fi
|
||||
hr
|
||||
echo -e "| Having those packages installed can lead to unwanted |"
|
||||
echo -e "| behaviour. It is recommend to remove those packages. |"
|
||||
echo -e "| |"
|
||||
echo -e "| 1) Remove packages (recommend) |"
|
||||
echo -e "| 2) Disable only (may cause issues) |"
|
||||
echo -e "| ${red}3) Skip this step (not recommended)${default} |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please choose:${default} " action
|
||||
case "$action" in
|
||||
1)
|
||||
echo -e "###### > Remove packages"
|
||||
REMOVE_HAPROXY="true"
|
||||
REMOVE_LIGHTTPD="true"
|
||||
REMOVE_APACHE2="true"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > Disable only"
|
||||
DISABLE_HAPROXY="true"
|
||||
DISABLE_LIGHTTPD="true"
|
||||
DISABLE_APACHE2="true"
|
||||
break;;
|
||||
3)
|
||||
echo -e "###### > Skip"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
install_klipperscreen(){
|
||||
python3_check
|
||||
if [ $py_chk_ok = "true" ]; then
|
||||
source_kiauh_ini
|
||||
#KlipperScreen main installation
|
||||
klipperscreen_setup
|
||||
#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
|
||||
}
|
||||
|
||||
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
|
||||
ok_msg "KlipperScreen successfully installed!"
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
WEBCAMD_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
|
||||
WEBCAM_TXT_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
|
||||
|
||||
install_mjpg-streamer(){
|
||||
check_klipper_cfg_path
|
||||
source_kiauh_ini
|
||||
|
||||
### set default values
|
||||
MJPG_SERV_SRC="${SRCDIR}/kiauh/resources/webcamd.service"
|
||||
MJPG_SERV_TARGET="$SYSTEMDDIR/webcamd.service"
|
||||
WEBCAM_TXT="$klipper_cfg_loc/webcam.txt"
|
||||
|
||||
### if there is a webcamd.service -> exit
|
||||
if [ -f $MJPG_SERV_TARGET ]; then
|
||||
ERROR_MSG="Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
|
||||
print_msg && clear_msg && return
|
||||
fi
|
||||
|
||||
### check and install dependencies if missing
|
||||
dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg)
|
||||
if apt-cache search libjpeg62-turbo-dev | grep -Eq "^libjpeg62-turbo-dev "; then
|
||||
dep+=(libjpeg62-turbo-dev)
|
||||
elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then
|
||||
dep+=(libjpeg8-dev)
|
||||
fi
|
||||
dependency_check
|
||||
|
||||
### step 1: clone moonraker
|
||||
status_msg "Downloading MJPG-Streamer ..."
|
||||
cd "${HOME}" && git clone https://github.com/jacksonliam/mjpg-streamer.git
|
||||
ok_msg "Download complete!"
|
||||
|
||||
### step 2: compiling mjpg-streamer
|
||||
status_msg "Compiling MJPG-Streamer ..."
|
||||
cd "${HOME}"/mjpg-streamer/mjpg-streamer-experimental && make
|
||||
ok_msg "Compiling complete!"
|
||||
|
||||
#step 3: install mjpg-streamer
|
||||
status_msg "Installing MJPG-Streamer ..."
|
||||
cd "${HOME}"/mjpg-streamer && mv mjpg-streamer-experimental/* .
|
||||
mkdir www-mjpgstreamer
|
||||
cat <<EOT >> ./www-mjpgstreamer/index.html
|
||||
<html>
|
||||
<head><title>mjpg_streamer test page</title></head>
|
||||
<body>
|
||||
<h1>Snapshot</h1>
|
||||
<p>Refresh the page to refresh the snapshot</p>
|
||||
<img src="./?action=snapshot" alt="Snapshot">
|
||||
<h1>Stream</h1>
|
||||
<img src="./?action=stream" alt="Stream">
|
||||
</body>
|
||||
</html>
|
||||
EOT
|
||||
sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd"
|
||||
sudo sed -i "/^config_dir=/ s|=.*|=$klipper_cfg_loc|" /usr/local/bin/webcamd
|
||||
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
|
||||
sudo chmod +x /usr/local/bin/webcamd
|
||||
|
||||
### step 4: create webcam.txt config file
|
||||
[ ! -d "$klipper_cfg_loc" ] && mkdir -p "$klipper_cfg_loc"
|
||||
if [ ! -f "$WEBCAM_TXT" ]; then
|
||||
status_msg "Creating webcam.txt config file ..."
|
||||
wget $WEBCAM_TXT_SRC -O "$WEBCAM_TXT"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 5: create systemd service
|
||||
status_msg "Creating MJPG-Streamer service ..."
|
||||
sudo cp "$MJPG_SERV_SRC" $MJPG_SERV_TARGET
|
||||
sudo sed -i "s|%USER%|${USER}|" $MJPG_SERV_TARGET
|
||||
ok_msg "MJPG-Streamer service created!"
|
||||
|
||||
### step 6: enabling and starting mjpg-streamer service
|
||||
status_msg "Starting MJPG-Streamer service ..."
|
||||
sudo systemctl enable webcamd.service
|
||||
sudo systemctl start webcamd.service
|
||||
ok_msg "MJPG-Streamer service started!"
|
||||
|
||||
### step 6.1: create webcamd.log symlink
|
||||
[ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs"
|
||||
if [ -f "/var/log/webcamd.log" ] && [ ! -L "${HOME}/klipper_logs/webcamd.log" ]; then
|
||||
ln -s "/var/log/webcamd.log" "${HOME}/klipper_logs/webcamd.log"
|
||||
fi
|
||||
|
||||
### step 6.2: add webcamd.log logrotate
|
||||
if [ ! -f "/etc/logrotate.d/webcamd" ]; then
|
||||
status_msg "Create logrotate rule ..."
|
||||
sudo /bin/sh -c "cat > /etc/logrotate.d/webcamd" << EOF
|
||||
/var/log/webcamd.log
|
||||
{
|
||||
rotate 2
|
||||
weekly
|
||||
maxsize 32M
|
||||
missingok
|
||||
notifempty
|
||||
compress
|
||||
delaycompress
|
||||
sharedscripts
|
||||
}
|
||||
EOF
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 7: check if user is in group "video"
|
||||
usergroup_changed=false
|
||||
USER_IN_VIDEO_GROUP=$(groups "${USER}" | grep "video")
|
||||
if [ -z "$USER_IN_VIDEO_GROUP" ]; then
|
||||
status_msg "Adding user ${USER} to group 'video' ..."
|
||||
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
|
||||
usergroup_changed=true
|
||||
else
|
||||
ok_msg "User ${USER} already in group 'video'!"
|
||||
fi
|
||||
|
||||
### confirm message
|
||||
CONFIRM_MSG="MJPG-Streamer has been set up!"
|
||||
if [ "$usergroup_changed" == true ]; then
|
||||
CONFIRM_MSG="${CONFIRM_MSG}\n ${yellow}INFO: Your User was added to a new group!${green}"
|
||||
CONFIRM_MSG="${CONFIRM_MSG}\n ${yellow}You need to relog/restart for the group to be applied!${green}"
|
||||
fi
|
||||
print_msg && clear_msg
|
||||
|
||||
### print webcam ip adress/url
|
||||
IP=$(hostname -I | cut -d" " -f1)
|
||||
WEBCAM_IP="http://$IP:8080/?action=stream"
|
||||
WEBCAM_URL="http://$IP/webcam/?action=stream"
|
||||
echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_IP"
|
||||
echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_URL"
|
||||
echo
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
install_MoonrakerTelegramBot(){
|
||||
source_kiauh_ini
|
||||
#MoonrakerTelegramBot main installation
|
||||
MoonrakerTelegramBot_setup
|
||||
#after install actions
|
||||
restart_MoonrakerTelegramBot
|
||||
}
|
||||
|
||||
MoonrakerTelegramBot_setup(){
|
||||
source_kiauh_ini
|
||||
export klipper_cfg_loc
|
||||
dep=(virtualenv)
|
||||
dependency_check
|
||||
status_msg "Downloading MoonrakerTelegramBot ..."
|
||||
#force remove existing MoonrakerTelegramBot dir
|
||||
[ -d $MOONRAKER_TELEGRAM_BOT_DIR ] && rm -rf $MOONRAKER_TELEGRAM_BOT_DIR
|
||||
#clone into fresh MoonrakerTelegramBot dir
|
||||
cd ${HOME} && git clone $NLEF_REPO
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Installing MoonrakerTelegramBot ..."
|
||||
$MOONRAKER_TELEGRAM_BOT_DIR/scripts/install.sh
|
||||
echo; ok_msg "MoonrakerTelegramBot successfully installed!"
|
||||
}
|
||||
@@ -1,321 +0,0 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
MOONRAKER_ENV="${HOME}/moonraker-env"
|
||||
MOONRAKER_DIR="${HOME}/moonraker"
|
||||
MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
|
||||
|
||||
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
|
||||
py_chk_ok="true"
|
||||
else
|
||||
py_chk_ok="false"
|
||||
fi
|
||||
}
|
||||
|
||||
moonraker_setup_dialog(){
|
||||
### check for existing moonraker service installations
|
||||
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service")
|
||||
if [ -n "$SERVICE_FILES" ]; then
|
||||
ERROR_MSG="At least one Moonraker service is already installed:"
|
||||
for service in $SERVICE_FILES; do
|
||||
ERROR_MSG="${ERROR_MSG}\n ➔ $service"
|
||||
done && return
|
||||
fi
|
||||
|
||||
status_msg "Initializing Moonraker installation ..."
|
||||
### checking system for python3.7+
|
||||
system_check_moonraker
|
||||
### exit moonraker setup if python versioncheck fails
|
||||
if [ $py_chk_ok = "false" ]; then
|
||||
ERROR_MSG="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
ERROR_MSG="${ERROR_MSG} Please upgrade Python."
|
||||
print_msg && clear_msg && return
|
||||
fi
|
||||
|
||||
### count amount of klipper services
|
||||
SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])+[0-9]*.service")
|
||||
if [ -f /etc/init.d/klipper ] || [ -f /etc/systemd/system/klipper.service ]; then
|
||||
KLIPPER_COUNT=1
|
||||
elif [ -n "$SERVICE_FILES" ]; then
|
||||
KLIPPER_COUNT=$(echo "$SERVICE_FILES" | wc -l)
|
||||
fi
|
||||
|
||||
### initial moonraker.conf path check
|
||||
check_klipper_cfg_path
|
||||
|
||||
top_border
|
||||
if [[ $KLIPPER_COUNT -eq 1 ]]; then
|
||||
printf "|${green}%-55s${default}|\n" " 1 Klipper instance was found!"
|
||||
elif [[ $KLIPPER_COUNT -gt 1 ]]; then
|
||||
printf "|${green}%-55s${default}|\n" " $KLIPPER_COUNT Klipper instances were found!"
|
||||
else
|
||||
echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |"
|
||||
fi
|
||||
echo -e "| Usually you need one Moonraker instance per Klipper |"
|
||||
echo -e "| instance. Though you can install as many as you wish. |"
|
||||
bottom_border
|
||||
echo
|
||||
count=""
|
||||
while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do
|
||||
read -p "${cyan}###### Number of Moonraker instances to set up:${default} " count
|
||||
if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then
|
||||
warn_msg "Invalid Input!\n"
|
||||
else
|
||||
echo
|
||||
read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Installing Moonraker ...\n"
|
||||
moonraker_setup "$count"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
warn_msg "Exiting Moonraker setup ...\n"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
moonraker_setup(){
|
||||
INSTANCE_COUNT=$1
|
||||
### checking dependencies
|
||||
dep=(wget curl unzip dfu-util virtualenv)
|
||||
### additional deps for kiauh compatibility for armbian
|
||||
dep+=(libjpeg-dev zlib1g-dev)
|
||||
dependency_check
|
||||
|
||||
### step 1: clone moonraker
|
||||
status_msg "Downloading Moonraker ..."
|
||||
### force remove existing moonraker dir and clone into fresh moonraker dir
|
||||
[ -d "$MOONRAKER_DIR" ] && rm -rf "$MOONRAKER_DIR"
|
||||
cd "${HOME}" && git clone $MOONRAKER_REPO
|
||||
ok_msg "Download complete!"
|
||||
|
||||
### step 2: install moonraker dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_moonraker_packages
|
||||
create_moonraker_virtualenv
|
||||
|
||||
### step 3: create moonraker.conf folder and moonraker.confs
|
||||
create_moonraker_conf
|
||||
|
||||
### step 4: create final moonraker instances
|
||||
create_moonraker_service
|
||||
|
||||
### step 5: create polkit rules for moonraker
|
||||
moonraker_polkit
|
||||
|
||||
### confirm message
|
||||
if [[ $INSTANCE_COUNT -eq 1 ]]; then
|
||||
CONFIRM_MSG="Moonraker has been set up!"
|
||||
elif [[ $INSTANCE_COUNT -gt 1 ]]; then
|
||||
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
|
||||
fi && print_msg && clear_msg
|
||||
|
||||
### display moonraker ips to the user
|
||||
print_mr_ip_list; echo
|
||||
}
|
||||
|
||||
install_moonraker_packages(){
|
||||
### read PKGLIST from official install script
|
||||
status_msg "Reading dependencies..."
|
||||
install_script="${HOME}/moonraker/scripts/install-moonraker.sh"
|
||||
PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n')
|
||||
for pkg in $PKGLIST; do
|
||||
echo "${cyan}$pkg${default}"
|
||||
done
|
||||
read -r -a PKGLIST <<< "$PKGLIST"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Running apt-get update..."
|
||||
sudo apt-get update --allow-releaseinfo-change
|
||||
|
||||
### 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
|
||||
|
||||
if [ ! -d "$MOONRAKER_ENV" ]; then
|
||||
virtualenv -p /usr/bin/python3 "$MOONRAKER_ENV"
|
||||
fi
|
||||
|
||||
### Install/update dependencies
|
||||
"$MOONRAKER_ENV"/bin/pip install -r "$MOONRAKER_DIR"/scripts/moonraker-requirements.txt
|
||||
}
|
||||
|
||||
create_moonraker_service(){
|
||||
### get config directory
|
||||
source_kiauh_ini
|
||||
|
||||
### set up default values
|
||||
SINGLE_INST=1
|
||||
CFG_PATH="$klipper_cfg_loc"
|
||||
MR_ENV=$MOONRAKER_ENV
|
||||
MR_DIR=$MOONRAKER_DIR
|
||||
MR_LOG="${HOME}/klipper_logs/moonraker.log"
|
||||
MR_CONF="$CFG_PATH/moonraker.conf"
|
||||
MR_SERV_SRC="${SRCDIR}/kiauh/resources/moonraker.service"
|
||||
MR_SERV_TARGET="$SYSTEMDDIR/moonraker.service"
|
||||
|
||||
write_mr_service(){
|
||||
if [ ! -f $MR_SERV_TARGET ]; then
|
||||
status_msg "Creating Moonraker Service $i ..."
|
||||
sudo cp "$MR_SERV_SRC" $MR_SERV_TARGET
|
||||
sudo sed -i "s|%INST%|$i|" $MR_SERV_TARGET
|
||||
sudo sed -i "s|%USER%|${USER}|" $MR_SERV_TARGET
|
||||
sudo sed -i "s|%MR_ENV%|$MR_ENV|" $MR_SERV_TARGET
|
||||
sudo sed -i "s|%MR_DIR%|$MR_DIR|" $MR_SERV_TARGET
|
||||
sudo sed -i "s|%MR_LOG%|$MR_LOG|" $MR_SERV_TARGET
|
||||
sudo sed -i "s|%MR_CONF%|$MR_CONF|" $MR_SERV_TARGET
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then
|
||||
### write single instance service
|
||||
write_mr_service
|
||||
### enable instance
|
||||
do_action_service "enable" "moonraker"
|
||||
ok_msg "Single Moonraker instance created!"
|
||||
### launching instance
|
||||
do_action_service "start" "moonraker"
|
||||
else
|
||||
i=1
|
||||
while [[ $i -le $INSTANCE_COUNT ]]; do
|
||||
### rewrite default variables for multi instance cases
|
||||
CFG_PATH="$klipper_cfg_loc/printer_$i"
|
||||
MR_SERV_TARGET="$SYSTEMDDIR/moonraker-$i.service"
|
||||
MR_CONF="$CFG_PATH/moonraker.conf"
|
||||
MR_LOG="${HOME}/klipper_logs/moonraker-$i.log"
|
||||
### write multi instance service
|
||||
write_mr_service
|
||||
### enable instance
|
||||
do_action_service "enable" "moonraker-$i"
|
||||
ok_msg "Moonraker instance #$i created!"
|
||||
### launching instance
|
||||
do_action_service "start" "moonraker-$i"
|
||||
### raise values by 1
|
||||
i=$((i+1))
|
||||
done
|
||||
unset i
|
||||
|
||||
### enable mainsails remoteMode if mainsail is found
|
||||
if [ -d "$MAINSAIL_DIR" ]; then
|
||||
status_msg "Mainsail installation found!"
|
||||
status_msg "Enabling Mainsail remoteMode ..."
|
||||
enable_mainsail_remotemode
|
||||
ok_msg "Mainsails remoteMode enabled!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
create_moonraker_conf(){
|
||||
### get config directory
|
||||
source_kiauh_ini
|
||||
|
||||
### set up default values
|
||||
SINGLE_INST=1
|
||||
PORT=7125
|
||||
CFG_PATH="$klipper_cfg_loc"
|
||||
LOG_PATH="${HOME}/klipper_logs"
|
||||
MR_CONF="$CFG_PATH/moonraker.conf"
|
||||
MR_DB="${HOME}/.moonraker_database"
|
||||
KLIPPY_UDS="/tmp/klippy_uds"
|
||||
MR_CONF_SRC="${SRCDIR}/kiauh/resources/moonraker.conf"
|
||||
mr_ip_list=()
|
||||
IP=$(hostname -I | cut -d" " -f1)
|
||||
LAN="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
|
||||
|
||||
write_mr_conf(){
|
||||
[ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH"
|
||||
if [ ! -f "$MR_CONF" ]; then
|
||||
status_msg "Creating moonraker.conf in $CFG_PATH ..."
|
||||
cp "$MR_CONF_SRC" "$MR_CONF"
|
||||
sed -i "s|%PORT%|$PORT|" "$MR_CONF"
|
||||
sed -i "s|%CFG%|$CFG_PATH|" "$MR_CONF"
|
||||
sed -i "s|%LOG%|$LOG_PATH|" "$MR_CONF"
|
||||
sed -i "s|%MR_DB%|$MR_DB|" "$MR_CONF"
|
||||
sed -i "s|%UDS%|$KLIPPY_UDS|" "$MR_CONF"
|
||||
# if host ip is not in the default ip ranges, replace placeholder
|
||||
# otherwise remove placeholder from config
|
||||
if ! grep -q "$LAN" "$MR_CONF"; then
|
||||
sed -i "s|%LAN%|$LAN|" "$MR_CONF"
|
||||
else
|
||||
sed -i "/%LAN%/d" "$MR_CONF"
|
||||
fi
|
||||
sed -i "s|%USER%|${USER}|g" "$MR_CONF"
|
||||
ok_msg "moonraker.conf created!"
|
||||
else
|
||||
warn_msg "There is already a file called 'moonraker.conf'!"
|
||||
warn_msg "Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then
|
||||
### write single instance config
|
||||
write_mr_conf
|
||||
mr_ip_list+=("$IP:$PORT")
|
||||
else
|
||||
i=1
|
||||
while [[ $i -le $INSTANCE_COUNT ]]; do
|
||||
### rewrite default variables for multi instance cases
|
||||
CFG_PATH="$klipper_cfg_loc/printer_$i"
|
||||
MR_CONF="$CFG_PATH/moonraker.conf"
|
||||
MR_DB="${HOME}/.moonraker_database_$i"
|
||||
KLIPPY_UDS="/tmp/klippy_uds-$i"
|
||||
|
||||
### write multi instance config
|
||||
write_mr_conf
|
||||
mr_ip_list+=("$IP:$PORT")
|
||||
|
||||
### raise values by 1
|
||||
PORT=$((PORT+1))
|
||||
i=$((i+1))
|
||||
done
|
||||
unset PORT && unset i
|
||||
fi
|
||||
}
|
||||
|
||||
print_mr_ip_list(){
|
||||
i=1
|
||||
for ip in "${mr_ip_list[@]}"; do
|
||||
echo -e " ${cyan}● Instance $i:${default} $ip"
|
||||
i=$((i + 1))
|
||||
done
|
||||
}
|
||||
|
||||
### introduced due to
|
||||
### https://github.com/Arksine/moonraker/issues/349
|
||||
### https://github.com/Arksine/moonraker/pull/346
|
||||
moonraker_polkit(){
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
MOONRAKER_SERVICES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service")
|
||||
for service in $MOONRAKER_SERVICES; do
|
||||
HAS_SUPP="$( grep -cm1 "SupplementaryGroups=moonraker-admin" "$service" || true )"
|
||||
if [ "$HAS_SUPP" -eq 0 ]; then
|
||||
status_msg "Adding moonraker-admin supplementary group to $service ..."
|
||||
sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "$service" \
|
||||
&& ok_msg "Adding moonraker-admin supplementary group successfull!"
|
||||
fi
|
||||
done
|
||||
### execute moonrakers policykit-rules script
|
||||
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
@@ -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 --python=python3 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
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
### base variables
|
||||
PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode"
|
||||
PGC_DIR="${HOME}/pgcode"
|
||||
|
||||
install_pgc_for_klipper(){
|
||||
pgconfsrc="$PGC_DIR/pgcode.local.conf"
|
||||
pgconf="/etc/nginx/sites-available/pgcode.local.conf"
|
||||
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
|
||||
pgc_default_port="7136"
|
||||
|
||||
status_msg "Installing PrettyGCode for Klipper ..."
|
||||
### let the user decide which port is used
|
||||
echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: $pgc_default_port)${default} "
|
||||
read -e -p "${cyan}###### Port:${default} " -i "$pgc_default_port" pgc_custom_port
|
||||
### check nginx dependency
|
||||
dep=(nginx)
|
||||
dependency_check
|
||||
### clone repo
|
||||
[ -d $PGC_DIR ] && rm -rf $PGC_DIR
|
||||
cd ${HOME} && git clone $PGC_FOR_KLIPPER_REPO
|
||||
### copy nginx config into destination directory
|
||||
sudo cp $pgconfsrc $pgconf
|
||||
### replace default pi user in case the user is called different
|
||||
sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" $pgconf
|
||||
### replace default port
|
||||
if [ $pgc_custom_port != $pgc_default_port ]; then
|
||||
sudo sed -i "s|listen $pgc_default_port;|listen $pgc_custom_port;|" $pgconf
|
||||
sudo sed -i "s|listen \[::\]:$pgc_default_port;|listen \[::\]:$pgc_custom_port;|" $pgconf
|
||||
fi
|
||||
### create symlink
|
||||
[ ! -L $pgconfsl ] && sudo ln -s $pgconf $pgconfsl
|
||||
sudo systemctl restart nginx
|
||||
### show URI
|
||||
pgc_uri="http://$(hostname -I | cut -d" " -f1):$pgc_custom_port"
|
||||
echo -e "${cyan}\n● Accessible via:${default} $pgc_uri"
|
||||
ok_msg "PrettyGCode for Klipper installed!\n"
|
||||
}
|
||||
599
scripts/klipper.sh
Normal file
599
scripts/klipper.sh
Normal file
@@ -0,0 +1,599 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#================ INSTALL KLIPPER ================#
|
||||
#=================================================#
|
||||
|
||||
### check for existing klipper service installations
|
||||
function klipper_initd() {
|
||||
local services
|
||||
services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function klipper_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function klipper_exists() {
|
||||
local services
|
||||
[[ -n $(klipper_initd) ]] && services+="$(klipper_initd) "
|
||||
[[ -n $(klipper_systemd) ]] && services+="$(klipper_systemd)"
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function klipper_setup_dialog() {
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
|
||||
local klipper_services
|
||||
local python_version="${1}" user_input=()
|
||||
klipper_services=$(klipper_exists)
|
||||
user_input+=("${python_version}")
|
||||
|
||||
### return early if klipper already exists
|
||||
if [[ -n ${klipper_services} ]]; then
|
||||
local error="At least one Klipper service is already installed:"
|
||||
|
||||
for s in ${klipper_services}; do
|
||||
log_info "Found Klipper service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### ask for amount of instances to create
|
||||
top_border
|
||||
echo -e "| Please select the number of Klipper instances to set |"
|
||||
echo -e "| up. The number of Klipper instances will determine |"
|
||||
echo -e "| the amount of printers you can run from this host. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}WARNING:${white} |"
|
||||
echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local klipper_count re="^[1-9][0-9]*$"
|
||||
while [[ ! ${klipper_count} =~ ${re} ]]; do
|
||||
read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e klipper_count
|
||||
### break if input is valid
|
||||
[[ ${klipper_count} =~ ${re} ]] && break
|
||||
### error messages on invalid input
|
||||
error_msg "Input not a number"
|
||||
done && select_msg "${klipper_count}"
|
||||
|
||||
user_input+=("${klipper_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Install ${klipper_count} instance(s)? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting Klipper setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### ask for custom names
|
||||
if (( klipper_count > 1 )); then
|
||||
local custom_names="false"
|
||||
top_border
|
||||
echo -e "| You can give each instance a custom name or skip. |"
|
||||
echo -e "| If skipped, KIAUH will automatically assign an index |"
|
||||
echo -e "| to each instance in ascending order, starting at '1'. |"
|
||||
blank_line
|
||||
echo -e "| Info: |"
|
||||
echo -e "| Only alphanumeric characters will be allowed. |"
|
||||
bottom_border
|
||||
while true; do
|
||||
read -p "${cyan}###### Use custom names? (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
custom_names="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### get user input for custom names
|
||||
if [[ ${custom_names} == "true" ]]; then
|
||||
local i=1 name re="^[0-9a-zA-Z]+$"
|
||||
while [[ ! ${name} =~ ${re} || ${i} -le ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Name for instance #${i}:${white} " name
|
||||
if [[ ${name} =~ ${re} ]]; then
|
||||
select_msg "Name: ${name}"
|
||||
user_input+=("${name}")
|
||||
i=$(( i + 1 ))
|
||||
else
|
||||
error_msg "Invalid Input!"
|
||||
fi
|
||||
done
|
||||
else
|
||||
### if no custom names are used, add the respective amount of indices to the user_input array
|
||||
for (( i=1; i <= klipper_count; i++ )); do
|
||||
user_input+=("${i}")
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
(( klipper_count > 1 )) && status_msg "Installing ${klipper_count} Klipper instances ..."
|
||||
(( klipper_count == 1 )) && status_msg "Installing single Klipper instance ..."
|
||||
|
||||
klipper_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_klipper_packages() {
|
||||
local packages python_version="${1}"
|
||||
local install_script="${KLIPPER_DIR}/scripts/install-debian.sh"
|
||||
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages=$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')
|
||||
### add dfu-util for octopi-images
|
||||
packages+=" dfu-util"
|
||||
### add dbus requirement for DietPi distro
|
||||
[[ -e "/boot/dietpi/.version" ]] && packages+=" dbus"
|
||||
|
||||
if [[ ${python_version} == "python3" ]]; then
|
||||
### replace python-dev with python3-dev if python3 was selected
|
||||
packages="${packages//python-dev/python3-dev}"
|
||||
else
|
||||
### package name 'python-dev' is deprecated (-> no installation candidate) on more modern linux distros
|
||||
packages="${packages//python-dev/python2-dev}"
|
||||
fi
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Updating package lists..."
|
||||
if ! sudo apt-get update --allow-releaseinfo-change; then
|
||||
log_error "failure while updating package lists"
|
||||
error_msg "Updating package lists failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Install required packages
|
||||
status_msg "Installing required packages..."
|
||||
if ! sudo apt-get install --yes "${packages[@]}"; then
|
||||
log_error "failure while installing required klipper packages"
|
||||
error_msg "Installing required packages failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_klipper_virtualenv() {
|
||||
local python_version="${1}"
|
||||
|
||||
[[ ${python_version} == "python2" ]] && \
|
||||
status_msg "Installing $(python2 -V) virtual environment..."
|
||||
|
||||
[[ ${python_version} == "python3" ]] && \
|
||||
status_msg "Installing $(python3 -V) virtual environment..."
|
||||
|
||||
### remove klippy-env if it already exists
|
||||
[[ -d ${KLIPPY_ENV} ]] && rm -rf "${KLIPPY_ENV}"
|
||||
|
||||
if [[ ${python_version} == "python2" ]]; then
|
||||
if virtualenv -p python2 "${KLIPPY_ENV}"; then
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||
else
|
||||
log_error "failure while creating python2 klippy-env"
|
||||
error_msg "Creation of Klipper virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${python_version} == "python3" ]]; then
|
||||
if virtualenv -p python3 "${KLIPPY_ENV}"; then
|
||||
"${KLIPPY_ENV}"/bin/pip install -U pip
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||
else
|
||||
log_error "failure while creating python3 klippy-env"
|
||||
error_msg "Creation of Klipper virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
function klipper_setup() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
### index 0: python version, index 1: instance count, index 2-n: instance names (optional)
|
||||
local user_input=("${@}")
|
||||
local python_version="${user_input[0]}" && unset "user_input[0]"
|
||||
local instance_arr=("${user_input[@]}") && unset "user_input[@]"
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
### checking dependencies
|
||||
local dep=(git)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone klipper
|
||||
clone_klipper "${custom_repo}" "${custom_branch}"
|
||||
|
||||
### step 2: install klipper dependencies and create python virtualenv
|
||||
install_klipper_packages "${python_version}"
|
||||
create_klipper_virtualenv "${python_version}"
|
||||
|
||||
### step 3: create gcode_files and logs folder
|
||||
[[ ! -d "${HOME}/gcode_files" ]] && mkdir -p "${HOME}/gcode_files"
|
||||
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
|
||||
|
||||
### step 4: create klipper instances
|
||||
create_klipper_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: enable and start all instances
|
||||
do_action_service "enable" "klipper"
|
||||
do_action_service "start" "klipper"
|
||||
|
||||
### step 6: check for dialout group membership
|
||||
check_usergroups
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Klipper has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Klipper instances have been set up!"
|
||||
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
function clone_klipper() {
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
[[ -z ${repo} ]] && repo="${KLIPPER_REPO}"
|
||||
repo=$(echo "${repo}" | sed -r "s/^(http|https):\/\/github\.com\///i; s/\.git$//")
|
||||
repo="https://github.com/${repo}"
|
||||
|
||||
[[ -z ${branch} ]] && branch="master"
|
||||
|
||||
### force remove existing klipper dir and clone into fresh klipper dir
|
||||
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
|
||||
|
||||
status_msg "Cloning Klipper from ${repo} ..."
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if git clone "${repo}" "${KLIPPER_DIR}"; then
|
||||
cd "${KLIPPER_DIR}" && git checkout "${branch}"
|
||||
else
|
||||
print_error "Cloning Klipper from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_klipper_service() {
|
||||
local i=${1} cfg=${2} log=${3} printer=${4} uds=${5} service=${6}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/klipper.service"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Klipper Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
[[ -z ${i} ]] && sudo sed -i "s| for instance klipper-%INST%||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${KLIPPY_ENV}|; s|%DIR%|${KLIPPER_DIR}|" "${service}"
|
||||
sudo sed -i "s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${printer}|; s|%UDS%|${uds}|" "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
function write_example_printer_cfg() {
|
||||
local cfg_dir=${1} cfg=${2}
|
||||
local cfg_template="${KIAUH_SRCDIR}/resources/printer.cfg"
|
||||
|
||||
### create a config directory if it doesn't exist
|
||||
if [[ ! -d ${cfg_dir} ]]; then
|
||||
status_msg "Creating '${cfg_dir}' ..."
|
||||
mkdir -p "${cfg_dir}"
|
||||
fi
|
||||
|
||||
### create a minimal config if there is no printer.cfg
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating minimal example printer.cfg ..."
|
||||
cp "${cfg_template}" "${cfg}"
|
||||
fi
|
||||
}
|
||||
|
||||
function create_klipper_service() {
|
||||
local input=("${@}")
|
||||
local klipper_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local cfg_dir cfg log printer uds service
|
||||
|
||||
if (( klipper_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/printer.cfg"
|
||||
log="${KLIPPER_LOGS}/klippy.log"
|
||||
printer="/tmp/printer"
|
||||
uds="/tmp/klippy_uds"
|
||||
service="${SYSTEMD}/klipper.service"
|
||||
### write single instance service
|
||||
write_klipper_service "" "${cfg}" "${log}" "${printer}" "${uds}" "${service}"
|
||||
write_example_printer_cfg "${cfg_dir}" "${cfg}"
|
||||
ok_msg "Klipper instance created!"
|
||||
|
||||
elif (( klipper_count >= 1 )) && [[ ${#names[@]} -gt 0 ]]; then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= klipper_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/printer.cfg"
|
||||
log="${KLIPPER_LOGS}/klippy-${names[${j}]}.log"
|
||||
printer="/tmp/printer-${names[${j}]}"
|
||||
uds="/tmp/klippy_uds-${names[${j}]}"
|
||||
service="${SYSTEMD}/klipper-${names[${j}]}.service"
|
||||
### write multi instance service
|
||||
write_klipper_service "${names[${j}]}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}"
|
||||
write_example_printer_cfg "${cfg_dir}" "${cfg}"
|
||||
ok_msg "Klipper instance 'klipper-${names[${j}]}' created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ REMOVE KLIPPER ================#
|
||||
#================================================#
|
||||
|
||||
function remove_klipper_sysvinit() {
|
||||
[[ ! -e "${INITD}/klipper" ]] && return
|
||||
|
||||
status_msg "Removing Klipper SysVinit service ..."
|
||||
sudo systemctl stop klipper
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo rm -f "${INITD}/klipper" "${ETCDEF}/klipper"
|
||||
ok_msg "Klipper SysVinit service removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_systemd() {
|
||||
[[ -z $(klipper_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Klipper Systemd Services ..."
|
||||
for service in $(klipper_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Klipper Service removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_logs() {
|
||||
local files regex="klippy(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper_uds() {
|
||||
local files
|
||||
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper_printer() {
|
||||
local files
|
||||
|
||||
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort)
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper_dir() {
|
||||
[[ ! -d ${KLIPPER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Klipper directory ..."
|
||||
rm -rf "${KLIPPER_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_env() {
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
status_msg "Removing klippy-env directory ..."
|
||||
rm -rf "${KLIPPY_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_klipper() {
|
||||
remove_klipper_sysvinit
|
||||
remove_klipper_systemd
|
||||
remove_klipper_logs
|
||||
remove_klipper_uds
|
||||
remove_klipper_printer
|
||||
remove_klipper_dir
|
||||
remove_klipper_env
|
||||
|
||||
local confirm="Klipper was successfully removed!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ UPDATE KLIPPER ================#
|
||||
#================================================#
|
||||
|
||||
function update_klipper() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
if [[ ! -d ${KLIPPER_DIR} ]]; then
|
||||
clone_klipper "${custom_repo}" "${custom_branch}"
|
||||
else
|
||||
backup_before_update "klipper"
|
||||
status_msg "Updating Klipper ..."
|
||||
cd "${KLIPPER_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_klipper_packages
|
||||
### install possible new python dependencies
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "klipper"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ KLIPPER STATUS ================#
|
||||
#================================================#
|
||||
|
||||
function get_klipper_status() {
|
||||
local sf_count status py_ver
|
||||
sf_count="$(klipper_systemd | wc -w)"
|
||||
|
||||
### detect an existing "legacy" klipper init.d installation
|
||||
if [[ $(klipper_systemd | wc -w) -eq 0 ]] \
|
||||
&& [[ $(klipper_initd | wc -w) -ge 1 ]]; then
|
||||
sf_count=1
|
||||
fi
|
||||
|
||||
py_ver=$(get_klipper_python_ver)
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a klipper service is installed
|
||||
local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
if (( py_ver == 3 )); then
|
||||
status="Installed: ${sf_count}(py${py_ver})"
|
||||
else
|
||||
status="Installed: ${sf_count}"
|
||||
fi
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_klipper_commit() {
|
||||
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_klipper_commit() {
|
||||
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_klipper_versions() {
|
||||
unset KLIPPER_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_klipper_commit)"
|
||||
remote_ver="$(get_remote_klipper_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add klipper to the update all array for the update all function in the updater
|
||||
KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
KLIPPER_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_klipper_cfg_dir() {
|
||||
local cfg_dir
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
if [[ -z ${custom_klipper_cfg_loc} ]]; then
|
||||
cfg_dir="${HOME}/klipper_config"
|
||||
else
|
||||
cfg_dir="${custom_klipper_cfg_loc}"
|
||||
fi
|
||||
|
||||
echo "${cfg_dir}"
|
||||
}
|
||||
|
||||
### returns the major python version the klippy-env was created with
|
||||
function get_klipper_python_ver() {
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
local version
|
||||
version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
|
||||
echo "${version}"
|
||||
}
|
||||
230
scripts/klipperscreen.sh
Normal file
230
scripts/klipperscreen.sh
Normal file
@@ -0,0 +1,230 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#============== INSTALL KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function klipperscreen_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/KlipperScreen.service")
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function install_klipperscreen() {
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
### install KlipperScreen
|
||||
klipperscreen_setup
|
||||
|
||||
### add klipperscreen to the update manager in moonraker.conf
|
||||
patch_klipperscreen_update_manager
|
||||
|
||||
do_action_service "restart" "KlipperScreen"
|
||||
}
|
||||
|
||||
function klipperscreen_setup() {
|
||||
local dep=(wget curl unzip dfu-util)
|
||||
dependency_check "${dep[@]}"
|
||||
status_msg "Cloning KlipperScreen from ${KLIPPERSCREEN_REPO} ..."
|
||||
|
||||
# force remove existing KlipperScreen dir
|
||||
[[ -d ${KLIPPERSCREEN_DIR} ]] && rm -rf "${KLIPPERSCREEN_DIR}"
|
||||
|
||||
# clone into fresh KlipperScreen dir
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${KLIPPERSCREEN_REPO}" "${KLIPPERSCREEN_DIR}"; then
|
||||
print_error "Cloning KlipperScreen from\n ${KLIPPERSCREEN_REPO}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
status_msg "Installing KlipperScreen ..."
|
||||
if "${KLIPPERSCREEN_DIR}"/scripts/KlipperScreen-install.sh; then
|
||||
ok_msg "KlipperScreen successfully installed!"
|
||||
else
|
||||
print_error "KlipperScreen installation failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== REMOVE KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function remove_klipperscreen() {
|
||||
### remove KlipperScreen dir
|
||||
if [[ -d ${KLIPPERSCREEN_DIR} ]]; then
|
||||
status_msg "Removing KlipperScreen directory ..."
|
||||
rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen VENV dir
|
||||
if [[ -d ${KLIPPERSCREEN_ENV} ]]; then
|
||||
status_msg "Removing KlipperScreen VENV directory ..."
|
||||
rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen service
|
||||
if [[ -e "${SYSTEMD}/KlipperScreen.service" ]]; then
|
||||
status_msg "Removing KlipperScreen service ..."
|
||||
do_action_service "stop" "KlipperScreen"
|
||||
do_action_service "disable" "KlipperScreen"
|
||||
sudo rm -f "${SYSTEMD}/KlipperScreen.service"
|
||||
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "KlipperScreen Service removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen log
|
||||
if [[ -e "/tmp/KlipperScreen.log" ]]; then
|
||||
status_msg "Removing KlipperScreen log file ..."
|
||||
rm -f "/tmp/KlipperScreen.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen log symlink in config dir
|
||||
if [[ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]]; then
|
||||
status_msg "Removing KlipperScreen log symlink ..."
|
||||
rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
print_confirm "KlipperScreen successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== UPDATE KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function update_klipperscreen() {
|
||||
local old_md5
|
||||
old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
|
||||
|
||||
do_action_service "stop" "KlipperScreen"
|
||||
cd "${KLIPPERSCREEN_DIR}"
|
||||
git pull origin master -q && ok_msg "Fetch successfull!"
|
||||
git checkout -f master && ok_msg "Checkout successfull"
|
||||
|
||||
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
||||
status_msg "New dependecies detected..."
|
||||
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
|
||||
ok_msg "Dependencies have been installed!"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "KlipperScreen"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== KLIPPERSCREEN STATUS ==============#
|
||||
#===================================================#
|
||||
|
||||
function get_klipperscreen_status() {
|
||||
local sf_count status
|
||||
sf_count="$(klipperscreen_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_klipperscreen_commit() {
|
||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPERSCREEN_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_klipperscreen_commit() {
|
||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_klipperscreen_versions() {
|
||||
unset KLIPPERSCREEN_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_klipperscreen_commit)"
|
||||
remote_ver="$(get_remote_klipperscreen_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add klipperscreen to the update all array for the update all function in the updater
|
||||
KLIPPERSCREEN_UPDATE_AVAIL="true" && update_arr+=(update_klipperscreen)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
KLIPPERSCREEN_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_klipperscreen_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager KlipperScreen\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add KlipperScreens update manager section to moonraker.conf
|
||||
status_msg "Adding KlipperScreen to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager KlipperScreen]
|
||||
type: git_repo
|
||||
path: ${HOME}/KlipperScreen
|
||||
origin: https://github.com/jordanruthe/KlipperScreen.git
|
||||
env: ${HOME}/.KlipperScreen-env/bin/python
|
||||
requirements: scripts/KlipperScreen-requirements.txt
|
||||
install_script: scripts/KlipperScreen-install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
577
scripts/mainsail.sh
Normal file
577
scripts/mainsail.sh
Normal file
@@ -0,0 +1,577 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================= INSTALL MAINSAIL ================#
|
||||
#===================================================#
|
||||
|
||||
function install_mainsail() {
|
||||
### exit early if moonraker not found
|
||||
if [[ -z $(moonraker_systemd) ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### checking dependencies
|
||||
local dep=(wget nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
### detect conflicting Haproxy and Apache2 installations
|
||||
detect_conflicting_packages
|
||||
|
||||
status_msg "Initializing Mainsail installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
mainsail_port_check
|
||||
|
||||
### ask user to install mjpg-streamer
|
||||
local install_mjpg_streamer
|
||||
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Install MJGP-Streamer for webcam support? |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please select (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
install_mjpg_streamer="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
install_mjpg_streamer="false"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
### download mainsail
|
||||
download_mainsail
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
install_mainsail_macros
|
||||
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "mainsail"
|
||||
### nginx on ubuntu 21 and above needs special permissions to access the files
|
||||
set_nginx_permissions
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
|
||||
### add mainsail to the update manager in moonraker.conf
|
||||
patch_mainsail_update_manager
|
||||
|
||||
### install mjpg-streamer
|
||||
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
print_confirm "Mainsail has been set up!"
|
||||
}
|
||||
|
||||
function install_mainsail_macros() {
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to have some important macros in |"
|
||||
echo -e "| your printer configuration to have Mainsail fully |"
|
||||
echo -e "| functional and working. |"
|
||||
blank_line
|
||||
echo -e "| The recommended macros for Mainsail can be seen here: |"
|
||||
echo -e "| https://docs.mainsail.xyz/configuration#macros |"
|
||||
blank_line
|
||||
echo -e "| If you already have these macros in your config file, |"
|
||||
echo -e "| skip this step and answer with 'no'. |"
|
||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||
echo -e "| add the recommended example macros to your config. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
download_mainsail_macros
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
return
|
||||
}
|
||||
|
||||
function download_mainsail_macros() {
|
||||
local ms_cfg="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mainsail/filesystem/home/pi/klipper_config/mainsail.cfg"
|
||||
local configs path
|
||||
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
|
||||
|
||||
if [[ -n ${configs} ]]; then
|
||||
for config in ${configs}; do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
if [[ ! -f "${path}/mainsail.cfg" ]]; then
|
||||
status_msg "Downloading mainsail.cfg to ${path} ..."
|
||||
log_info "downloading mainsail.cfg to: ${path}"
|
||||
wget "${ms_cfg}" -O "${path}/mainsail.cfg"
|
||||
|
||||
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
||||
log_info "modify mainsail.cfg"
|
||||
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg"
|
||||
|
||||
### write include to the very first line of the printer.cfg
|
||||
if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then
|
||||
log_info "modify printer.cfg"
|
||||
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log_error "execution stopped! reason: no printer.cfg found"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
function download_mainsail() {
|
||||
local url
|
||||
url=$(get_mainsail_download_url)
|
||||
|
||||
status_msg "Downloading Mainsail from ${url} ..."
|
||||
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
rm -rf "${MAINSAIL_DIR}"
|
||||
fi
|
||||
|
||||
mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}"
|
||||
|
||||
if wget "${url}"; then
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf ./*.zip && ok_msg "Done!"
|
||||
else
|
||||
print_error "Downloading Mainsail from\n ${url}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode
|
||||
if [[ $(moonraker_systemd | wc -w) -gt 1 ]]; then
|
||||
enable_mainsail_remotemode
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= REMOVE MAINSAIL =================#
|
||||
#===================================================#
|
||||
|
||||
function remove_mainsail_dir() {
|
||||
[[ ! -d ${MAINSAIL_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Mainsail directory ..."
|
||||
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_mainsail_config() {
|
||||
if [[ -e "/etc/nginx/sites-available/mainsail" ]]; then
|
||||
status_msg "Removing Mainsail configuration for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!"
|
||||
fi
|
||||
if [[ -L "/etc/nginx/sites-enabled/mainsail" ]]; then
|
||||
status_msg "Removing Mainsail Symlink for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail_logs() {
|
||||
local files
|
||||
files=$(find /var/log/nginx -name "mainsail*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
sudo rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail_log_symlinks() {
|
||||
local files
|
||||
files=$(find "${KLIPPER_LOGS}" -name "mainsail*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail() {
|
||||
remove_mainsail_dir
|
||||
remove_mainsail_config
|
||||
remove_mainsail_logs
|
||||
remove_mainsail_log_symlinks
|
||||
|
||||
### remove mainsail_port from ~/.kiauh.ini
|
||||
sed -i "/^mainsail_port=/d" "${INI_FILE}"
|
||||
|
||||
print_confirm "Mainsail successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= UPDATE MAINSAIL =================#
|
||||
#===================================================#
|
||||
|
||||
function update_mainsail() {
|
||||
backup_before_update "mainsail"
|
||||
status_msg "Updating Mainsail ..."
|
||||
download_mainsail
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
print_confirm "Mainsail successfully updated!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= MAINSAIL STATUS =================#
|
||||
#===================================================#
|
||||
|
||||
function get_mainsail_status() {
|
||||
local status
|
||||
local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail")
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_mainsail_version() {
|
||||
[[ ! -f "${MAINSAIL_DIR}/.version" ]] && return
|
||||
|
||||
local version
|
||||
version=$(head -n 1 "${MAINSAIL_DIR}/.version")
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function get_remote_mainsail_version() {
|
||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||
|
||||
local version
|
||||
version=$(get_mainsail_download_url | rev | cut -d"/" -f2 | rev)
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function compare_mainsail_versions() {
|
||||
unset MAINSAIL_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_mainsail_version)"
|
||||
remote_ver="$(get_remote_mainsail_version)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add mainsail to the update all array for the update all function in the updater
|
||||
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
MAINSAIL_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=========== MAINSAIL THEME INSTALLER ===========#
|
||||
#================================================#
|
||||
|
||||
function print_theme_list() {
|
||||
local i=0 theme_list=${1}
|
||||
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
if [[ ${col1} != "name" ]]; then
|
||||
printf "| ${i}) %-51s|\n" "[${col1}]"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done <<< "${theme_list}"
|
||||
}
|
||||
|
||||
function ms_theme_installer_menu() {
|
||||
local theme_list theme_author theme_repo theme_name theme_note theme_url
|
||||
local theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv"
|
||||
theme_list=$(curl -s -L "${theme_csv_url}")
|
||||
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| ${cyan}A preview of each Mainsail theme can be found here:${white} |"
|
||||
echo -e "| https://docs.mainsail.xyz/theming/themes |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}Important note:${white} |"
|
||||
echo -e "| Installing a theme from this menu will overwrite an |"
|
||||
echo -e "| already installed theme or modified custom.css file! |"
|
||||
hr
|
||||
print_theme_list "${theme_list}"
|
||||
echo -e "| |"
|
||||
echo -e "| R) [Remove Theme] |"
|
||||
back_footer
|
||||
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
theme_name+=("${col1}")
|
||||
theme_note+=("${col2}")
|
||||
theme_author+=("${col3}")
|
||||
theme_repo+=("${col4}")
|
||||
done <<< "${theme_list}"
|
||||
|
||||
local option
|
||||
while true; do
|
||||
read -p "${cyan}Install theme:${white} " option
|
||||
if (( option > 0 && option < ${#theme_name[@]} )); then
|
||||
theme_url="https://github.com/${theme_author[${option}]}/${theme_repo[${option}]}"
|
||||
ms_theme_install "${theme_url}" "${theme_name[${option}]}" "${theme_note[${option}]}"
|
||||
break
|
||||
elif [[ ${option} == "R" || ${option} == "r" ]]; then
|
||||
ms_theme_delete
|
||||
break
|
||||
elif [[ ${option} == "B" || ${option} == "b" ]]; then
|
||||
advanced_menu
|
||||
break
|
||||
else
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
ms_theme_installer_menu
|
||||
}
|
||||
|
||||
function ms_theme_install() {
|
||||
local theme_url=${1} theme_name theme_note
|
||||
theme_name=${2} theme_note=${3}
|
||||
|
||||
local config_folders target_folders=()
|
||||
config_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -maxdepth 1 -type d | sort)
|
||||
|
||||
### build target folder array
|
||||
for folder in ${config_folders}; do
|
||||
target_folders+=("${folder}")
|
||||
done
|
||||
|
||||
if (( ${#target_folders[@]} > 1 )); then
|
||||
top_border
|
||||
echo -e "| Please select the printer you want to apply the theme |"
|
||||
echo -e "| installation to: |"
|
||||
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f1 | rev)
|
||||
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||
done
|
||||
bottom_border
|
||||
|
||||
local target re="^[0-9]*$"
|
||||
while true; do
|
||||
read -p "${cyan}###### Select printer:${white} " target
|
||||
### break while loop if input is valid, else display error
|
||||
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||
error_msg "Invalid command!"
|
||||
done
|
||||
fi
|
||||
|
||||
[[ -d "${target_folders[${target}]}/.theme" ]] && rm -rf "${target_folders[${target}]}/.theme"
|
||||
|
||||
status_msg "Installing '${theme_name}' to ${target_folders[${target}]} ..."
|
||||
cd "${target_folders[${target}]}"
|
||||
|
||||
if git clone "${theme_url}" ".theme"; then
|
||||
ok_msg "Theme installation complete!"
|
||||
[[ -n ${theme_note} ]] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
|
||||
ok_msg "Please remember to delete your browser cache!\n"
|
||||
else
|
||||
error_msg "Theme installation failed!\n"
|
||||
fi
|
||||
}
|
||||
|
||||
function ms_theme_delete() {
|
||||
local theme_folders target_folders=()
|
||||
theme_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -type d -name ".theme" | sort)
|
||||
|
||||
### build target folder array
|
||||
for folder in ${theme_folders}; do
|
||||
target_folders+=("${folder}")
|
||||
done
|
||||
|
||||
if (( ${#target_folders[@]} > 0 )); then
|
||||
top_border
|
||||
echo -e "| Please select the printer you want to remove the |"
|
||||
echo -e "| theme installation from. |"
|
||||
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f2 | rev)
|
||||
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||
done
|
||||
bottom_border
|
||||
|
||||
local target re="^[0-9]*$"
|
||||
while true; do
|
||||
read -p "${cyan}###### Select printer:${white} " target
|
||||
### break while loop if input is valid, else display error
|
||||
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||
error_msg "Invalid command!"
|
||||
done
|
||||
else
|
||||
status_msg "No Themes installed!\n"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Removing ${target_folders[${target}]} ..."
|
||||
rm -rf "${target_folders[${target}]}" && ok_msg "Theme removed!\n"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_mainsail_download_url() {
|
||||
local tags latest_tag latest_url stable_tag stable_url url
|
||||
tags=$(curl -s "${MAINSAIL_TAGS}" | grep "name" | cut -d'"' -f4)
|
||||
|
||||
### latest download url including pre-releases (alpha, beta, rc)
|
||||
latest_tag=$(echo "${tags}" | head -1)
|
||||
latest_url="https://github.com/mainsail-crew/mainsail/releases/download/${latest_tag}/mainsail.zip"
|
||||
|
||||
### get stable mainsail download url
|
||||
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
|
||||
stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip"
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
if [[ ${mainsail_install_unstable} == "true" ]]; then
|
||||
url="${latest_url}"
|
||||
echo "${url}"
|
||||
else
|
||||
url="${stable_url}"
|
||||
echo "${url}"
|
||||
fi
|
||||
}
|
||||
|
||||
function mainsail_port_check() {
|
||||
if [[ ${MAINSAIL_ENABLED} == "false" ]]; then
|
||||
|
||||
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
|
||||
[[ ${FLUIDD_ENABLED} == "true" ]] && \
|
||||
echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${white}"
|
||||
|
||||
if [[ ${FLUIDD_PORT} == "80" ]]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_mainsail_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
function select_mainsail_port() {
|
||||
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||
echo -e "| ${red}You need to choose a different port for Mainsail!${white} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||
blank_line
|
||||
[[ ${FLUIDD_PORT} == "80" ]] && echo "| ● Fluidd |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to another webinterface! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
|
||||
local new_port re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||
if [[ ${new_port} =~ ${re} && ${new_port} != "${FLUIDD_PORT}" ]]; then
|
||||
select_msg "Setting port ${new_port} for Mainsail!"
|
||||
SET_LISTEN_PORT=${new_port}
|
||||
break
|
||||
else
|
||||
if [[ ! ${new_port} =~ ${re} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
else
|
||||
error_msg "Port already taken! Select a different one!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function enable_mainsail_remotemode() {
|
||||
[[ ! -f "${MAINSAIL_DIR}/config.json" ]] && return
|
||||
|
||||
rm -f "${MAINSAIL_DIR}/config.json"
|
||||
echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json"
|
||||
}
|
||||
|
||||
function patch_mainsail_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager mainsail\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Mainsails update manager section to moonraker.conf
|
||||
status_msg "Adding Mainsail to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager mainsail]
|
||||
type: web
|
||||
channel: stable
|
||||
repo: mainsail-crew/mainsail
|
||||
path: ~/mainsail
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
193
scripts/mjpg-streamer.sh
Normal file
193
scripts/mjpg-streamer.sh
Normal file
@@ -0,0 +1,193 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#============= INSTALL MJPG-STREAMER =============#
|
||||
#=================================================#
|
||||
|
||||
function install_mjpg-streamer() {
|
||||
local webcamd="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
|
||||
local webcam_txt="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt"
|
||||
local repo="https://github.com/jacksonliam/mjpg-streamer.git"
|
||||
local service="${KIAUH_SRCDIR}/resources/webcamd.service"
|
||||
|
||||
### return early if webcamd.service already exists
|
||||
if [[ -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
print_error "Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Initializing MJPG-Streamer installation ..."
|
||||
|
||||
### check and install dependencies if missing
|
||||
local dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg)
|
||||
if apt-cache search libjpeg62-turbo-dev | grep -Eq "^libjpeg62-turbo-dev "; then
|
||||
dep+=(libjpeg62-turbo-dev)
|
||||
elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then
|
||||
dep+=(libjpeg8-dev)
|
||||
fi
|
||||
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone mjpg-streamer
|
||||
status_msg "Cloning MJPG-Streamer from ${repo} ..."
|
||||
[[ -d "${HOME}/mjpg-streamer" ]] && rm -rf "${HOME}/mjpg-streamer"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${repo}" "${HOME}/mjpg-streamer"; then
|
||||
print_error "Cloning MJPG-Streamer from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
ok_msg "Cloning complete!"
|
||||
|
||||
### step 2: compiling mjpg-streamer
|
||||
status_msg "Compiling MJPG-Streamer ..."
|
||||
cd "${HOME}/mjpg-streamer/mjpg-streamer-experimental"
|
||||
if ! make; then
|
||||
print_error "Compiling MJPG-Streamer failed!"
|
||||
exit 1
|
||||
fi
|
||||
ok_msg "Compiling complete!"
|
||||
|
||||
#step 3: install mjpg-streamer
|
||||
status_msg "Installing MJPG-Streamer ..."
|
||||
cd "${HOME}/mjpg-streamer" && mv mjpg-streamer-experimental/* .
|
||||
mkdir www-mjpgstreamer
|
||||
|
||||
cat <<EOT >> ./www-mjpgstreamer/index.html
|
||||
<html>
|
||||
<head><title>mjpg_streamer test page</title></head>
|
||||
<body>
|
||||
<h1>Snapshot</h1>
|
||||
<p>Refresh the page to refresh the snapshot</p>
|
||||
<img src="./?action=snapshot" alt="Snapshot">
|
||||
<h1>Stream</h1>
|
||||
<img src="./?action=stream" alt="Stream">
|
||||
</body>
|
||||
</html>
|
||||
EOT
|
||||
|
||||
sudo wget "${webcamd}" -O "/usr/local/bin/webcamd"
|
||||
sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /usr/local/bin/webcamd
|
||||
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
|
||||
sudo chmod +x /usr/local/bin/webcamd
|
||||
|
||||
### step 4: create webcam.txt config file
|
||||
[[ ! -d ${KLIPPER_CONFIG} ]] && mkdir -p "${KLIPPER_CONFIG}"
|
||||
if [[ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]]; then
|
||||
status_msg "Creating webcam.txt config file ..."
|
||||
wget "${webcam_txt}" -O "${KLIPPER_CONFIG}/webcam.txt"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 5: create systemd service
|
||||
status_msg "Creating MJPG-Streamer service ..."
|
||||
sudo cp "${service}" "${SYSTEMD}/webcamd.service"
|
||||
sudo sed -i "s|%USER%|${USER}|" "${SYSTEMD}/webcamd.service"
|
||||
ok_msg "MJPG-Streamer service created!"
|
||||
|
||||
### step 6: enabling and starting mjpg-streamer service
|
||||
status_msg "Starting MJPG-Streamer service, please wait ..."
|
||||
sudo systemctl enable webcamd.service
|
||||
if sudo systemctl start webcamd.service; then
|
||||
ok_msg "MJPG-Streamer service started!"
|
||||
else
|
||||
status_msg "MJPG-Streamer service couldn't be started! No webcam connected?\n###### You need to manually restart the service once your webcam is set up correctly."
|
||||
fi
|
||||
|
||||
### step 6.1: create webcamd.log symlink
|
||||
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
|
||||
if [[ -f "/var/log/webcamd.log" && ! -L "${KLIPPER_LOGS}/webcamd.log" ]]; then
|
||||
ln -s "/var/log/webcamd.log" "${KLIPPER_LOGS}/webcamd.log"
|
||||
fi
|
||||
|
||||
### step 6.2: add webcamd.log logrotate
|
||||
if [[ ! -f "/etc/logrotate.d/webcamd" ]]; then
|
||||
status_msg "Create logrotate rule ..."
|
||||
sudo /bin/sh -c "cat > /etc/logrotate.d/webcamd" << EOF
|
||||
/var/log/webcamd.log
|
||||
{
|
||||
rotate 2
|
||||
weekly
|
||||
maxsize 32M
|
||||
missingok
|
||||
notifempty
|
||||
compress
|
||||
delaycompress
|
||||
sharedscripts
|
||||
}
|
||||
EOF
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 7: check if user is in group "video"
|
||||
local usergroup_changed="false"
|
||||
if ! groups "${USER}" | grep -q "video"; then
|
||||
status_msg "Adding user '${USER}' to group 'video' ..."
|
||||
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
|
||||
usergroup_changed="true"
|
||||
fi
|
||||
|
||||
### confirm message
|
||||
local confirm_msg="MJPG-Streamer has been set up!"
|
||||
if [[ ${usergroup_changed} == "true" ]]; then
|
||||
confirm_msg="${confirm_msg}\n ${yellow}INFO: Your User was added to a new group!${green}"
|
||||
confirm_msg="${confirm_msg}\n ${yellow}You need to relog/restart for the group to be applied!${green}"
|
||||
fi
|
||||
|
||||
print_confirm "${confirm_msg}"
|
||||
|
||||
### print webcam ip adress/url
|
||||
local ip
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
local cam_url="http://${ip}:8080/?action=stream"
|
||||
local cam_url_alt="http://${ip}/webcam/?action=stream"
|
||||
echo -e " ${cyan}● Webcam URL:${white} ${cam_url}"
|
||||
echo -e " ${cyan}● Webcam URL:${white} ${cam_url_alt}"
|
||||
echo
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#============== REMOVE MJPG-STREAMER =============#
|
||||
#=================================================#
|
||||
|
||||
function remove_mjpg-streamer() {
|
||||
### remove MJPG-Streamer service
|
||||
if [[ -e "${SYSTEMD}/webcamd.service" ]]; then
|
||||
status_msg "Removing MJPG-Streamer service ..."
|
||||
sudo systemctl stop webcamd && sudo systemctl disable webcamd
|
||||
sudo rm -f "${SYSTEMD}/webcamd.service"
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "MJPG-Streamer Service removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd from /usr/local/bin
|
||||
if [[ -e "/usr/local/bin/webcamd" ]]; then
|
||||
sudo rm -f "/usr/local/bin/webcamd"
|
||||
fi
|
||||
|
||||
### remove MJPG-Streamer directory
|
||||
if [[ -d "${HOME}/mjpg-streamer" ]]; then
|
||||
status_msg "Removing MJPG-Streamer directory ..."
|
||||
rm -rf "${HOME}/mjpg-streamer"
|
||||
ok_msg "MJPG-Streamer directory removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd log and symlink
|
||||
[[ -f "/var/log/webcamd.log" ]] && sudo rm -f "/var/log/webcamd.log"
|
||||
[[ -L "${KLIPPER_LOGS}/webcamd.log" ]] && rm -f "${KLIPPER_LOGS}/webcamd.log"
|
||||
|
||||
print_confirm "MJPG-Streamer successfully removed!"
|
||||
}
|
||||
486
scripts/moonraker-telegram-bot.sh
Normal file
486
scripts/moonraker-telegram-bot.sh
Normal file
@@ -0,0 +1,486 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#========== INSTALL MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function telegram_bot_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function telegram_bot_setup_dialog() {
|
||||
### return early if moonraker is not installed
|
||||
local moonraker_services
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
|
||||
if [[ -z ${moonraker_services} ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
status_msg "Initializing Telegram Bot installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_klipper_config_dir
|
||||
|
||||
local moonraker_count user_input=() moonraker_names=()
|
||||
moonraker_count=$(echo "${moonraker_services}" | wc -w )
|
||||
for service in ${moonraker_services}; do
|
||||
moonraker_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local telegram_bot_count
|
||||
if (( moonraker_count == 1 )); then
|
||||
ok_msg "Moonraker installation found!\n"
|
||||
telegram_bot_count=1
|
||||
elif (( moonraker_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${moonraker_count} Moonraker instances found!"
|
||||
for name in "${moonraker_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● ${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to Telegram Bot! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of Telegram Bot instances to |"
|
||||
echo -e "| install. Usually one Telegram Bot instance per |"
|
||||
echo -e "| Moonraker instance is required, but you may not |"
|
||||
echo -e "| install more Telegram Bot instances than available |"
|
||||
echo -e "| Moonraker instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${telegram_bot_count} =~ ${re} || ${telegram_bot_count} -gt ${moonraker_count} ]]; do
|
||||
read -p "${cyan}###### Number of Telegram Bot instances to set up:${white} " -i "${moonraker_count}" -e telegram_bot_count
|
||||
### break if input is valid
|
||||
[[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${telegram_bot_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( telegram_bot_count > moonraker_count )) && error_msg "Number of Telegram Bot instances larger than existing Moonraker instances"
|
||||
done && select_msg "${telegram_bot_count}"
|
||||
else
|
||||
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${telegram_bot_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( telegram_bot_count == 1 )) && local question="Install Telegram Bot?"
|
||||
(( telegram_bot_count > 1 )) && local question="Install ${telegram_bot_count} Telegram Bot instances?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting Telegram Bot setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for moonraker
|
||||
if (( moonraker_count > 1 )); then
|
||||
for name in "${moonraker_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( telegram_bot_count > 1 )) && status_msg "Installing ${telegram_bot_count} Telegram Bot instances ..."
|
||||
(( telegram_bot_count == 1 )) && status_msg "Installing Telegram Bot ..."
|
||||
telegram_bot_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_telegram_bot_dependencies() {
|
||||
local packages
|
||||
local install_script="${TELEGRAM_BOT_DIR}/scripts/install.sh"
|
||||
|
||||
### read PKGLIST from official install-script
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Updating package lists..."
|
||||
if ! sudo apt-get update --allow-releaseinfo-change; then
|
||||
log_error "failure while updating package lists"
|
||||
error_msg "Updating package lists failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Install required packages
|
||||
status_msg "Installing required packages..."
|
||||
if ! sudo apt-get install --yes "${packages[@]}"; then
|
||||
log_error "failure while installing required moonraker-telegram-bot packages"
|
||||
error_msg "Installing required packages failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_bot_virtualenv() {
|
||||
status_msg "Installing python virtual environment..."
|
||||
### always create a clean virtualenv
|
||||
[[ -d ${TELEGRAM_BOT_ENV} ]] && rm -rf "${TELEGRAM_BOT_ENV}"
|
||||
if virtualenv -p /usr/bin/python3 --system-site-packages "${TELEGRAM_BOT_ENV}"; then
|
||||
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
|
||||
else
|
||||
log_error "failure while creating python3 moonraker-telegram-bot-env"
|
||||
error_msg "Creation of Moonraker Telegram Bot virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function telegram_bot_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### checking dependencies
|
||||
local dep=(git virtualenv)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone telegram bot
|
||||
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
|
||||
|
||||
### step 2: install telegram bot dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_telegram_bot_dependencies
|
||||
create_telegram_bot_virtualenv
|
||||
|
||||
### step 3: create telegram.conf
|
||||
create_telegram_conf "${instance_arr[@]}"
|
||||
|
||||
### step 4: create telegram bot instances
|
||||
create_telegram_bot_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: add telegram-bot to the update manager in moonraker.conf
|
||||
patch_telegram_bot_update_manager
|
||||
|
||||
### step 6: enable and start all instances
|
||||
do_action_service "enable" "moonraker-telegram-bot"
|
||||
do_action_service "start" "moonraker-telegram-bot"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Telegram Bot has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Telegram Bot instances have been set up!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
function clone_telegram_bot() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning Moonraker-Telegram-Bot from ${repo} ..."
|
||||
### force remove existing Moonraker-Telegram-Bot dir
|
||||
[[ -d ${repo} ]] && rm -rf "${TELEGRAM_BOT_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${repo}" "${TELEGRAM_BOT_DIR}"; then
|
||||
print_error "Cloning Moonraker-Telegram-Bot from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_conf() {
|
||||
local input=("${@}")
|
||||
local telegram_bot_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local log="${KLIPPER_LOGS}"
|
||||
local cfg cfg_dir
|
||||
|
||||
if (( telegram_bot_count == 1 )); then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
### write single instance config
|
||||
write_telegram_conf "${cfg_dir}" "${cfg}" "${log}"
|
||||
|
||||
elif (( telegram_bot_count > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= telegram_bot_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
|
||||
### write multi instance config
|
||||
write_telegram_conf "${cfg_dir}" "${cfg}" "${log}"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_telegram_conf() {
|
||||
local cfg_dir=${1} cfg=${2} log=${3}
|
||||
local conf_template="${TELEGRAM_BOT_DIR}/scripts/base_install_template"
|
||||
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating telegram.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
sed -i "s|some_log_path|${log}|g" "${cfg}"
|
||||
ok_msg "telegram.conf created!"
|
||||
else
|
||||
status_msg "File '${cfg}' already exists!\nSkipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_bot_service() {
|
||||
local input=("${@}")
|
||||
local instances=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local cfg_dir cfg log service
|
||||
|
||||
if (( instances == 1 )); then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log="${KLIPPER_LOGS}/telegram.log"
|
||||
service="${SYSTEMD}/moonraker-telegram-bot.service"
|
||||
### write single instance service
|
||||
write_telegram_bot_service "" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Single Telegram Bot instance created!"
|
||||
|
||||
elif (( instances > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= instances; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log="${KLIPPER_LOGS}/telegram-${names[${j}]}.log"
|
||||
service="${SYSTEMD}/moonraker-telegram-bot-${names[${j}]}.service"
|
||||
### write multi instance service
|
||||
write_telegram_bot_service "${names[${j}]}" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Telegram Bot instance moonraker-telegram-bot-${names[${j}]} created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_telegram_bot_service() {
|
||||
local i=${1} cfg=${2} log=${3} service=${4}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.service"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Telegram Bot Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
[[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%DIR%|${TELEGRAM_BOT_DIR}|" "${service}"
|
||||
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#===================================================#
|
||||
#=========== REMOVE MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function remove_telegram_bot_systemd() {
|
||||
[[ -z $(telegram_bot_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Telegram Bot Systemd Services ..."
|
||||
for service in $(telegram_bot_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Telegram Bot Services removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_dir() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Moonraker-Telegram-Bot directory ..."
|
||||
rm -rf "${TELEGRAM_BOT_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_env() {
|
||||
[[ ! -d ${TELEGRAM_BOT_ENV} ]] && return
|
||||
|
||||
status_msg "Removing moonraker-telegram-bot-env directory ..."
|
||||
rm -rf "${TELEGRAM_BOT_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_logs() {
|
||||
local files regex="telegram(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_telegram_bot() {
|
||||
remove_telegram_bot_systemd
|
||||
remove_telegram_bot_dir
|
||||
remove_telegram_bot_env
|
||||
remove_telegram_bot_logs
|
||||
|
||||
local confirm="Moonraker-Telegram-Bot was successfully removed!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== UPDATE MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function update_telegram_bot() {
|
||||
do_action_service "stop" "moonraker-telegram-bot"
|
||||
|
||||
if [[ ! -d ${TELEGRAM_BOT_DIR} ]]; then
|
||||
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker-telegram-bot"
|
||||
status_msg "Updating Moonraker ..."
|
||||
cd "${TELEGRAM_BOT_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_telegram_bot_dependencies
|
||||
### install possible new python dependencies
|
||||
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "moonraker-telegram-bot"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== MOONRAKERTELEGRAMBOT STATUS ===========#
|
||||
#===================================================#
|
||||
|
||||
function get_telegram_bot_status() {
|
||||
local sf_count status
|
||||
sf_count="$(telegram_bot_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${TELEGRAM_BOT_DIR}" "${TELEGRAM_BOT_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed: ${sf_count}"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_telegram_bot_commit() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${TELEGRAM_BOT_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_telegram_bot_commit() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${TELEGRAM_BOT_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_telegram_bot_versions() {
|
||||
unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_telegram_bot_commit)"
|
||||
remote_ver="$(get_remote_telegram_bot_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker-telegram-bot to the update all array for the update all function in the updater
|
||||
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_telegram_bot)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_telegram_bot_update_manager() {
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager moonraker-telegram-bot\]$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Moonraker-Telegram-Bot update manager section to moonraker.conf
|
||||
status_msg "Adding Moonraker-Telegram-Bot to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager moonraker-telegram-bot]
|
||||
type: git_repo
|
||||
path: ~/moonraker-telegram-bot
|
||||
origin: https://github.com/nlef/moonraker-telegram-bot.git
|
||||
env: ~/moonraker-telegram-bot-env/bin/python
|
||||
requirements: scripts/requirements.txt
|
||||
install_script: scripts/install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
577
scripts/moonraker.sh
Normal file
577
scripts/moonraker.sh
Normal file
@@ -0,0 +1,577 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================ INSTALL MOONRAKER ================#
|
||||
#===================================================#
|
||||
|
||||
function moonraker_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function moonraker_setup_dialog() {
|
||||
status_msg "Initializing Moonraker installation ..."
|
||||
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### return early if moonraker already exists
|
||||
local moonraker_services
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
if [[ -n ${moonraker_services} ]]; then
|
||||
local error="At least one Moonraker service is already installed:"
|
||||
for s in ${moonraker_services}; do
|
||||
log_info "Found Moonraker service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### return early if klipper is not installed
|
||||
local klipper_services
|
||||
klipper_services=$(klipper_systemd)
|
||||
if [[ -z ${klipper_services} ]]; then
|
||||
local error="Klipper not installed! Please install Klipper first!"
|
||||
log_error "Moonraker setup started without Klipper being installed. Aborting setup."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
local klipper_count user_input=() klipper_names=()
|
||||
klipper_count=$(echo "${klipper_services}" | wc -w )
|
||||
for service in ${klipper_services}; do
|
||||
klipper_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local moonraker_count
|
||||
if (( klipper_count == 1 )); then
|
||||
ok_msg "Klipper installation found!\n"
|
||||
moonraker_count=1
|
||||
elif (( klipper_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
|
||||
for name in "${klipper_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● klipper-${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to Moonraker! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of Moonraker instances to |"
|
||||
echo -e "| install. Usually one Moonraker instance per Klipper |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| Moonraker instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${moonraker_count} =~ ${re} || ${moonraker_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count
|
||||
### break if input is valid
|
||||
[[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${moonraker_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( moonraker_count > klipper_count )) && error_msg "Number of Moonraker instances larger than installed Klipper instances"
|
||||
done && select_msg "${moonraker_count}"
|
||||
else
|
||||
log_error "Internal error. klipper_count of '${klipper_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${moonraker_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( moonraker_count == 1 )) && local question="Install Moonraker?"
|
||||
(( moonraker_count > 1 )) && local question="Install ${moonraker_count} Moonraker instances?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting Moonraker setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for moonraker
|
||||
if (( klipper_count > 1 )); then
|
||||
for name in "${klipper_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( moonraker_count > 1 )) && status_msg "Installing ${moonraker_count} Moonraker instances ..."
|
||||
(( moonraker_count == 1 )) && status_msg "Installing Moonraker ..."
|
||||
moonraker_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_moonraker_dependencies() {
|
||||
local packages
|
||||
local install_script="${MOONRAKER_DIR}/scripts/install-moonraker.sh"
|
||||
|
||||
### read PKGLIST from official install-script
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Updating package lists..."
|
||||
if ! sudo apt-get update --allow-releaseinfo-change; then
|
||||
log_error "failure while updating package lists"
|
||||
error_msg "Updating package lists failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Install required packages
|
||||
status_msg "Installing required packages..."
|
||||
if ! sudo apt-get install --yes "${packages[@]}"; then
|
||||
log_error "failure while installing required moonraker packages"
|
||||
error_msg "Installing required packages failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_virtualenv() {
|
||||
status_msg "Installing python virtual environment..."
|
||||
|
||||
### always create a clean virtualenv
|
||||
[[ -d ${MOONRAKER_ENV} ]] && rm -rf "${MOONRAKER_ENV}"
|
||||
|
||||
if virtualenv -p /usr/bin/python3 "${MOONRAKER_ENV}"; then
|
||||
"${MOONRAKER_ENV}"/bin/pip install -U pip
|
||||
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
|
||||
else
|
||||
log_error "failure while creating python3 moonraker-env"
|
||||
error_msg "Creation of Moonraker virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function moonraker_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### checking dependencies
|
||||
local dep=(git wget curl unzip dfu-util virtualenv)
|
||||
### additional required dependencies on armbian
|
||||
dep+=(libjpeg-dev zlib1g-dev)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone moonraker
|
||||
clone_moonraker "${MOONRAKER_REPO}"
|
||||
|
||||
### step 2: install moonraker dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_moonraker_dependencies
|
||||
create_moonraker_virtualenv
|
||||
|
||||
### step 3: create moonraker.conf
|
||||
create_moonraker_conf "${instance_arr[@]}"
|
||||
|
||||
### step 4: create moonraker instances
|
||||
create_moonraker_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: create polkit rules for moonraker
|
||||
moonraker_polkit || true
|
||||
|
||||
### step 6: enable and start all instances
|
||||
do_action_service "enable" "moonraker"
|
||||
do_action_service "start" "moonraker"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Moonraker has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Moonraker instances have been set up!"
|
||||
print_confirm "${confirm}" && print_mr_ip_list "${instance_arr[0]}" && return
|
||||
}
|
||||
|
||||
function clone_moonraker() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning Moonraker from ${repo} ..."
|
||||
|
||||
### force remove existing moonraker dir and clone into fresh moonraker dir
|
||||
[[ -d ${MOONRAKER_DIR} ]] && rm -rf "${MOONRAKER_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${MOONRAKER_REPO}" "${MOONRAKER_DIR}"; then
|
||||
print_error "Cloning Moonraker from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_conf() {
|
||||
local input=("${@}")
|
||||
local moonraker_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local log="${KLIPPER_LOGS}"
|
||||
local lan
|
||||
lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
|
||||
local port=7125 cfg_dir cfg db uds
|
||||
|
||||
if (( moonraker_count == 1 )); then
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
db="${HOME}/.moonraker_database"
|
||||
uds="/tmp/klippy_uds"
|
||||
### write single instance config
|
||||
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}"
|
||||
|
||||
elif (( moonraker_count > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= moonraker_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
uds="/tmp/klippy_uds-${names[${j}]}"
|
||||
db="${HOME}/.moonraker_database_${names[${j}]}"
|
||||
### write multi instance config
|
||||
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}"
|
||||
port=$(( port + 1 ))
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_moonraker_conf() {
|
||||
local cfg_dir=${1} cfg=${2} port=${3} log=${4} db=${5} uds=${6} lan=${7}
|
||||
local conf_template="${KIAUH_SRCDIR}/resources/moonraker.conf"
|
||||
|
||||
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating moonraker.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
sed -i "s|%USER%|${USER}|g" "${cfg}"
|
||||
sed -i "s|%CFG%|${cfg_dir}|; s|%PORT%|${port}|; s|%LOG%|${log}|; s|%DB%|${db}|; s|%UDS%|${uds}|" "${cfg}"
|
||||
# if host ip is not in the default ip ranges replace placeholder,
|
||||
# otherwise remove placeholder from config
|
||||
if ! grep -q "${lan}" "${cfg}"; then
|
||||
sed -i "s|%LAN%|${lan}|" "${cfg}"
|
||||
else
|
||||
sed -i "/%LAN%/d" "${cfg}"
|
||||
fi
|
||||
ok_msg "moonraker.conf created!"
|
||||
else
|
||||
status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_service() {
|
||||
local input=("${@}")
|
||||
local moonraker_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local cfg_dir cfg log service
|
||||
|
||||
if (( moonraker_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
|
||||
i=""
|
||||
cfg_dir="${KLIPPER_CONFIG}"
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
log="${KLIPPER_LOGS}/moonraker.log"
|
||||
service="${SYSTEMD}/moonraker.service"
|
||||
### write single instance service
|
||||
write_moonraker_service "" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Moonraker instance created!"
|
||||
|
||||
elif (( moonraker_count > 1 )) && [[ ${#names[@]} -gt 0 ]]; then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= moonraker_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}"
|
||||
else
|
||||
cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}"
|
||||
fi
|
||||
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
log="${KLIPPER_LOGS}/moonraker-${names[${j}]}.log"
|
||||
service="${SYSTEMD}/moonraker-${names[${j}]}.service"
|
||||
### write multi instance service
|
||||
write_moonraker_service "${names[${j}]}" "${cfg}" "${log}" "${service}"
|
||||
ok_msg "Moonraker instance 'moonraker-${names[${j}]}' created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset i
|
||||
|
||||
### enable mainsails remoteMode if mainsail is found
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
status_msg "Mainsail installation found! Enabling Mainsail remote mode ..."
|
||||
enable_mainsail_remotemode
|
||||
ok_msg "Mainsails remote mode enabled!"
|
||||
fi
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_moonraker_service() {
|
||||
local i=${1} cfg=${2} log=${3} service=${4}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker.service"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Moonraker Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
|
||||
[[ -z ${i} ]] && sudo sed -i "s| for instance moonraker-%INST%||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}"
|
||||
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
function print_mr_ip_list() {
|
||||
local ip count=${1} port=7125
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
for (( i=1; i <= count; i++ )); do
|
||||
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
|
||||
port=$(( port + 1 ))
|
||||
done && echo
|
||||
}
|
||||
|
||||
### introduced due to
|
||||
### https://github.com/Arksine/moonraker/issues/349
|
||||
### https://github.com/Arksine/moonraker/pull/346
|
||||
function moonraker_polkit() {
|
||||
local has_sup
|
||||
|
||||
### check for required SupplementaryGroups entry in service files
|
||||
### write it to the service if it doesn't exist
|
||||
for service in $(moonraker_systemd); do
|
||||
has_sup="$(grep "SupplementaryGroups=moonraker-admin" "${service}")"
|
||||
if [[ -z ${has_sup} ]]; then
|
||||
status_msg "Adding moonraker-admin supplementary group to ${service} ..."
|
||||
sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "${service}"
|
||||
ok_msg "Adding moonraker-admin supplementary group successfull!"
|
||||
fi
|
||||
done
|
||||
|
||||
[[ -z ${has_sup} ]] && echo "reloading services!!!" && sudo systemctl daemon-reload
|
||||
|
||||
### execute moonrakers policykit-rules script
|
||||
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ REMOVE MOONRAKER ================#
|
||||
#==================================================#
|
||||
|
||||
function remove_moonraker_sysvinit() {
|
||||
[[ ! -e "${INITD}/moonraker" ]] && return
|
||||
|
||||
status_msg "Removing Moonraker SysVinit service ..."
|
||||
sudo systemctl stop moonraker
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -f "${INITD}/moonraker" "${ETCDEF}/moonraker"
|
||||
ok_msg "Moonraker SysVinit service removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_systemd() {
|
||||
[[ -z $(moonraker_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Moonraker Systemd Services ..."
|
||||
|
||||
for service in $(moonraker_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Moonraker Services removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_logs() {
|
||||
local files regex="moonraker(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_moonraker_api_key() {
|
||||
### remove legacy api key
|
||||
if [[ -e "${HOME}/.klippy_api_key" ]]; then
|
||||
status_msg "Removing legacy API Key ..."
|
||||
rm "${HOME}/.klippy_api_key"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### remove api key
|
||||
if [[ -e "${HOME}/.moonraker_api_key" ]]; then
|
||||
status_msg "Removing API Key ..."
|
||||
rm "${HOME}/.moonraker_api_key"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_moonraker_dir() {
|
||||
[[ ! -d ${MOONRAKER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Moonraker directory ..."
|
||||
rm -rf "${MOONRAKER_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_env() {
|
||||
[[ ! -d ${MOONRAKER_ENV} ]] && return
|
||||
|
||||
status_msg "Removing moonraker-env directory ..."
|
||||
rm -rf "${MOONRAKER_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_polkit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing all Moonraker PolicyKit rules ..."
|
||||
"${MOONRAKER_DIR}"/scripts/set-policykit-rules.sh --clear
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function remove_moonraker() {
|
||||
remove_moonraker_sysvinit
|
||||
remove_moonraker_systemd
|
||||
remove_moonraker_logs
|
||||
remove_moonraker_api_key
|
||||
remove_moonraker_polkit
|
||||
remove_moonraker_dir
|
||||
remove_moonraker_env
|
||||
|
||||
print_confirm "Moonraker was successfully removed!"
|
||||
return
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ UPDATE MOONRAKER ================#
|
||||
#==================================================#
|
||||
|
||||
function update_moonraker() {
|
||||
do_action_service "stop" "moonraker"
|
||||
|
||||
if [[ ! -d ${MOONRAKER_DIR} ]]; then
|
||||
clone_moonraker "${MOONRAKER_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker"
|
||||
status_msg "Updating Moonraker ..."
|
||||
cd "${MOONRAKER_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_moonraker_dependencies
|
||||
### install possible new python dependencies
|
||||
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
|
||||
fi
|
||||
|
||||
### required due to https://github.com/Arksine/moonraker/issues/349
|
||||
moonraker_polkit
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ MOONRAKER STATUS ================#
|
||||
#==================================================#
|
||||
|
||||
function get_moonraker_status() {
|
||||
local sf_count status
|
||||
sf_count="$(moonraker_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${MOONRAKER_DIR}" "${MOONRAKER_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed: ${sf_count}"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_moonraker_commit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOONRAKER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_moonraker_commit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOONRAKER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_moonraker_versions() {
|
||||
unset MOONRAKER_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_moonraker_commit)"
|
||||
remote_ver="$(get_remote_moonraker_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to the update all array for the update all function in the updater
|
||||
MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
MOONRAKER_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
|
||||
get_theme_list(){
|
||||
theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv"
|
||||
theme_csv=$(curl -s -L $theme_csv_url)
|
||||
unset t_name
|
||||
unset t_note
|
||||
unset t_auth
|
||||
unset t_url
|
||||
i=0
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
t_name+=("$col1")
|
||||
t_note+=("$col2")
|
||||
t_auth+=("$col3")
|
||||
t_url+=("$col4")
|
||||
if [ ! "$col1" == "name" ]; then
|
||||
printf "| $i) %-50s|\n" "[$col1]"
|
||||
fi
|
||||
i=$((i+1))
|
||||
done <<< "$theme_csv"
|
||||
}
|
||||
|
||||
ms_theme_ui(){
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | "
|
||||
hr
|
||||
echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | "
|
||||
echo -e "| https://docs.mainsail.xyz/theming/themes | "
|
||||
blank_line
|
||||
echo -e "| ${yellow}Important note:${default} | "
|
||||
echo -e "| Installing a theme from this menu will overwrite an | "
|
||||
echo -e "| already installed theme or modified custom.css file! | "
|
||||
hr
|
||||
get_theme_list # dynamically generate the themelist from a csv file
|
||||
echo -e "| | "
|
||||
echo -e "| R) [Remove Theme] | "
|
||||
back_footer
|
||||
}
|
||||
|
||||
ms_theme_menu(){
|
||||
ms_theme_ui
|
||||
while true; do
|
||||
read -p "${cyan}Install theme:${default} " a; echo
|
||||
if [ "$a" = "b" ] || [ "$a" = "B" ]; then
|
||||
clear && advanced_menu && break
|
||||
elif [ "$a" = "r" ] || [ "$a" = "R" ]; then
|
||||
ms_theme_delete
|
||||
ms_theme_menu
|
||||
elif [ "$a" -le ${#t_url[@]} ]; then
|
||||
ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}"
|
||||
ms_theme_menu
|
||||
else
|
||||
clear && print_header
|
||||
ERROR_MSG="Invalid command!" && print_msg && clear_msg
|
||||
ms_theme_menu
|
||||
fi
|
||||
done
|
||||
ms_theme_menu
|
||||
}
|
||||
|
||||
check_select_printer(){
|
||||
unset printer_num
|
||||
|
||||
### get klipper cfg loc and set default .theme folder loc
|
||||
check_klipper_cfg_path
|
||||
THEME_PATH="$klipper_cfg_loc"
|
||||
|
||||
### check if there is more than one moonraker instance and if yes
|
||||
### ask the user to select the printer he wants to install/remove the theme
|
||||
MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l)
|
||||
if [[ $MR_SERVICE_COUNT -gt 1 ]]; then
|
||||
top_border
|
||||
echo -e "| More than one printer was found on this system! | "
|
||||
echo -e "| Please select the printer to which you want to | "
|
||||
echo -e "| apply the previously selected action. | "
|
||||
bottom_border
|
||||
read -p "${cyan}Select printer:${default} " printer_num
|
||||
|
||||
### rewrite the .theme path matching the selected printer
|
||||
THEME_PATH="$klipper_cfg_loc/printer_$printer_num"
|
||||
fi
|
||||
|
||||
### create the cfg folder if there is none yet
|
||||
[ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH"
|
||||
}
|
||||
|
||||
ms_theme_install(){
|
||||
THEME_URL="https://github.com/$1/$2"
|
||||
|
||||
### check and select printer if there is more than 1
|
||||
check_select_printer
|
||||
|
||||
### download all files
|
||||
status_msg "Installing $3 ..."
|
||||
status_msg "Please wait ..."
|
||||
|
||||
[ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme"
|
||||
cd "$THEME_PATH" && git clone "$THEME_URL" ".theme"
|
||||
|
||||
ok_msg "Theme installation complete!"
|
||||
[ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}"
|
||||
ok_msg "Please remember to delete your browser cache!\n"
|
||||
}
|
||||
|
||||
ms_theme_delete(){
|
||||
check_select_printer
|
||||
if [ -d "$THEME_PATH/.theme" ]; then
|
||||
status_msg "Removing Theme ..."
|
||||
rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n"
|
||||
else
|
||||
status_msg "No Theme installed!\n"
|
||||
fi
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
347
scripts/nginx.sh
Normal file
347
scripts/nginx.sh
Normal file
@@ -0,0 +1,347 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#=================== REMOVE NGINX ==================#
|
||||
#===================================================#
|
||||
|
||||
function remove_nginx() {
|
||||
if [[ $(dpkg -s nginx 2>/dev/null | grep "Status") = *\ installed ]]; then
|
||||
status_msg "Stopping NGINX service ..."
|
||||
if systemctl is-active nginx -q; then
|
||||
sudo systemctl stop nginx && ok_msg "Service stopped!"
|
||||
else
|
||||
warn_msg "NGINX service not active!"
|
||||
fi
|
||||
|
||||
status_msg "Removing NGINX from system ..."
|
||||
if sudo apt-get remove nginx -y && sudo update-rc.d -f nginx remove; then
|
||||
ok_msg "NGINX removed!"
|
||||
else
|
||||
error_msg "Removing NGINX from system failed!"
|
||||
fi
|
||||
else
|
||||
print_error "Looks like Nginx was already removed!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#===================== HELPERS =====================#
|
||||
#===================================================#
|
||||
|
||||
function set_upstream_nginx_cfg() {
|
||||
local current_date
|
||||
local upstreams="${NGINX_CONFD}/upstreams.conf"
|
||||
local common_vars="${NGINX_CONFD}/common_vars.conf"
|
||||
|
||||
current_date=$(get_date)
|
||||
|
||||
### backup existing nginx configs
|
||||
[[ ! -d "${BACKUP_DIR}/nginx_cfg" ]] && mkdir -p "${BACKUP_DIR}/nginx_cfg"
|
||||
|
||||
if [[ -f ${upstreams} ]]; then
|
||||
sudo mv "${upstreams}" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf"
|
||||
fi
|
||||
|
||||
if [[ -f ${common_vars} ]]; then
|
||||
sudo mv "${common_vars}" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf"
|
||||
fi
|
||||
|
||||
### transfer ownership of backed up files from root to ${USER}
|
||||
local files
|
||||
files=$(find "${BACKUP_DIR}/nginx_cfg")
|
||||
|
||||
for file in ${files}; do
|
||||
if [[ $(stat -c "%U" "${file}") != "${USER}" ]]; then
|
||||
log_info "chown for user: ${USER} on file: ${file}"
|
||||
sudo chown "${USER}" "${file}"
|
||||
fi
|
||||
done
|
||||
|
||||
### copy nginx configs to target destination
|
||||
[[ ! -f ${upstreams} ]] && sudo cp "${RESOURCES}/upstreams.conf" "${upstreams}"
|
||||
[[ ! -f ${common_vars} ]] && sudo cp "${RESOURCES}/common_vars.conf" "${common_vars}"
|
||||
}
|
||||
|
||||
function symlink_webui_nginx_log() {
|
||||
local interface=${1} path="${KLIPPER_LOGS}"
|
||||
local access_log="/var/log/nginx/${interface}-access.log"
|
||||
local error_log="/var/log/nginx/${interface}-error.log"
|
||||
|
||||
[[ ! -d ${path} ]] && mkdir -p "${path}"
|
||||
|
||||
if [[ -f ${access_log} && ! -L "${path}/${interface}-access.log" ]]; then
|
||||
status_msg "Creating symlink for ${access_log} ..."
|
||||
ln -s "${access_log}" "${path}"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
if [[ -f ${error_log} && ! -L "${path}/${interface}-error.log" ]]; then
|
||||
status_msg "Creating symlink for ${error_log} ..."
|
||||
ln -s "${error_log}" "${path}"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
function match_nginx_configs() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local require_service_restart="false"
|
||||
local upstreams="${NGINX_CONFD}/upstreams.conf"
|
||||
local common_vars="${NGINX_CONFD}/common_vars.conf"
|
||||
local mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail"
|
||||
local fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd"
|
||||
local upstreams_webcams mainsail_webcams fluidd_webcams
|
||||
|
||||
### reinstall nginx configs if the amount of upstreams don't match anymore
|
||||
upstreams_webcams=$(grep -Ec "mjpgstreamer" "/etc/nginx/conf.d/upstreams.conf")
|
||||
mainsail_webcams=$(grep -Ec "mjpgstreamer" "${mainsail_nginx_cfg}" 2>/dev/null || echo "0")
|
||||
fluidd_webcams=$(grep -Ec "mjpgstreamer" "${fluidd_nginx_cfg}" 2>/dev/null || echo "0")
|
||||
|
||||
status_msg "Checking validity of NGINX configurations ..."
|
||||
|
||||
### check for outdated upstreams.conf
|
||||
if (( upstreams_webcams < mainsail_webcams || upstreams_webcams < fluidd_webcams )); then
|
||||
status_msg "Outdated upstreams.conf found! Updating ..."
|
||||
|
||||
sudo rm -f "${upstreams}" "${common_vars}"
|
||||
set_upstream_nginx_cfg
|
||||
|
||||
require_service_restart="true"
|
||||
fi
|
||||
|
||||
### check for outdated mainsail config
|
||||
if [[ -e ${mainsail_nginx_cfg} ]] && (( upstreams_webcams > mainsail_webcams )); then
|
||||
status_msg "Outdated Mainsail config found! Updating ..."
|
||||
|
||||
sudo rm -f "${mainsail_nginx_cfg}"
|
||||
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "s/<<UI>>/mainsail/g" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}"
|
||||
|
||||
require_service_restart="true"
|
||||
fi
|
||||
|
||||
### check for outdated fluidd config
|
||||
if [[ -e ${fluidd_nginx_cfg} ]] && (( upstreams_webcams > fluidd_webcams )); then
|
||||
status_msg "Outdated Fluidd config found! Updating ..."
|
||||
|
||||
sudo rm -f "${fluidd_nginx_cfg}"
|
||||
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "s/<<UI>>/fluidd/g" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}"
|
||||
|
||||
require_service_restart="true"
|
||||
fi
|
||||
|
||||
### only restart nginx if configs were updated
|
||||
if [[ ${require_service_restart} == "true" ]]; then
|
||||
sudo systemctl restart nginx.service
|
||||
fi
|
||||
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function remove_conflicting_packages() {
|
||||
local apache=${1} haproxy=${2}
|
||||
|
||||
### disable services before removing them
|
||||
disable_conflicting_packages "${apache}" "${haproxy}"
|
||||
|
||||
if [[ ${apache} == "true" ]]; then
|
||||
status_msg "Removing Apache2 from system ..."
|
||||
if sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove; then
|
||||
ok_msg "Apache2 removed!"
|
||||
else
|
||||
error_msg "Removing Apache2 from system failed!"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${haproxy} == "true" ]]; then
|
||||
status_msg "Removing haproxy from system ..."
|
||||
if sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove; then
|
||||
ok_msg "Haproxy removed!"
|
||||
else
|
||||
error_msg "Removing Haproxy from system failed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function disable_conflicting_packages() {
|
||||
local apache=${1} haproxy=${2}
|
||||
|
||||
if [[ ${apache} == "true" ]]; then
|
||||
status_msg "Stopping Apache2 service ..."
|
||||
if systemctl is-active apache2 -q; then
|
||||
sudo systemctl stop apache2 && ok_msg "Service stopped!"
|
||||
else
|
||||
warn_msg "Apache2 service not active!"
|
||||
fi
|
||||
|
||||
status_msg "Disabling Apache2 service ..."
|
||||
if sudo systemctl disable apache2; then
|
||||
ok_msg "Apache2 service disabled!"
|
||||
else
|
||||
error_msg "Disabling Apache2 service failed!"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${haproxy} == "true" ]]; then
|
||||
status_msg "Stopping Haproxy service ..."
|
||||
if systemctl is-active haproxy -q; then
|
||||
sudo systemctl stop haproxy && ok_msg "Service stopped!"
|
||||
else
|
||||
warn_msg "Haproxy service not active!"
|
||||
fi
|
||||
|
||||
status_msg "Disabling Haproxy service ..."
|
||||
if sudo systemctl disable haproxy; then
|
||||
ok_msg "Haproxy service disabled!"
|
||||
else
|
||||
error_msg "Disabling Haproxy service failed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function detect_conflicting_packages() {
|
||||
local apache="false" haproxy="false"
|
||||
|
||||
### check system for an installed apache2 service
|
||||
[[ $(dpkg -s apache2 2>/dev/null | grep "Status") = *\ installed ]] && apache="true"
|
||||
### check system for an installed haproxy service
|
||||
[[ $(dpkg -s haproxy 2>/dev/null | grep "Status") = *\ installed ]] && haproxy="true"
|
||||
|
||||
#notify user about haproxy or apache2 services found and possible issues
|
||||
if [[ ${haproxy} == "false" && ${apache} == "false" ]]; then
|
||||
return
|
||||
else
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}Conflicting package installations found:${white} |"
|
||||
[[ ${apache} == "true" ]] && \
|
||||
echo -e "| ${red}● apache2${white} |"
|
||||
[[ ${haproxy} == "true" ]] && \
|
||||
echo -e "| ${red}● haproxy${white} |"
|
||||
blank_line
|
||||
echo -e "| Having those packages installed can lead to unwanted |"
|
||||
echo -e "| behaviour. It's recommended to remove those packages. |"
|
||||
echo -e "| |"
|
||||
echo -e "| ${green}1) Remove packages (recommend)${white} |"
|
||||
echo -e "| 2) Disable only (may still cause issues) |"
|
||||
echo -e "| ${red}3) Skip this step (not recommended)${white} |"
|
||||
bottom_border
|
||||
|
||||
local action
|
||||
read -p "${cyan}###### Please choose:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
echo -e "###### > Remove packages"
|
||||
remove_conflicting_packages "${apache}" "${haproxy}"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > Disable only"
|
||||
disable_conflicting_packages "${apache}" "${haproxy}"
|
||||
break;;
|
||||
3)
|
||||
echo -e "###### > Skip"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function set_nginx_cfg() {
|
||||
local interface=${1}
|
||||
if [[ ${SET_NGINX_CFG} == "true" ]]; then
|
||||
local cfg="${RESOURCES}/${interface}"
|
||||
#check for dependencies
|
||||
local dep=(nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
status_msg "Creating Nginx configuration for ${interface^} ..."
|
||||
cat "${RESOURCES}/klipper_webui_nginx.cfg" > "${cfg}"
|
||||
sed -i "s/<<UI>>/${interface}/g" "${cfg}"
|
||||
|
||||
if [[ ${SET_LISTEN_PORT} != "${DEFAULT_PORT}" ]]; then
|
||||
status_msg "Configuring port for ${interface^} ..."
|
||||
sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}"
|
||||
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}"
|
||||
fi
|
||||
|
||||
#set correct user
|
||||
if [[ ${interface} == "mainsail" || ${interface} == "fluidd" ]]; then
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${cfg}"
|
||||
fi
|
||||
|
||||
#moving the config file into correct directory
|
||||
sudo mv "${cfg}" "/etc/nginx/sites-available/${interface}"
|
||||
ok_msg "Nginx configuration for ${interface^} was set!"
|
||||
if [[ -n ${SET_LISTEN_PORT} ]]; then
|
||||
ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!"
|
||||
else
|
||||
ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!"
|
||||
fi
|
||||
|
||||
#remove nginx default config
|
||||
if [[ -e "/etc/nginx/sites-enabled/default" ]]; then
|
||||
sudo rm "/etc/nginx/sites-enabled/default"
|
||||
fi
|
||||
|
||||
#create symlink for own sites
|
||||
if [[ ! -e "/etc/nginx/sites-enabled/${interface}" ]]; then
|
||||
sudo ln -s "/etc/nginx/sites-available/${interface}" "/etc/nginx/sites-enabled/"
|
||||
fi
|
||||
sudo systemctl restart nginx.service
|
||||
fi
|
||||
}
|
||||
|
||||
function set_nginx_permissions() {
|
||||
local distro_name version_id
|
||||
|
||||
distro_name=$(grep -E "^NAME=" /etc/os-release | cut -d'"' -f2)
|
||||
version_id=$(grep -E "^VERSION_ID=" /etc/os-release | cut -d'"' -f2)
|
||||
|
||||
if [[ ${distro_name} == "Ubuntu" && ( ${version_id} == "21.10" || ${version_id} == "22.04") ]]; then
|
||||
status_msg "Granting NGINX the required permissions ..."
|
||||
chmod og+x "${HOME}" && ok_msg "Done!"
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
function read_listen_port() {
|
||||
local port interface=${1}
|
||||
port=$(grep listen "/etc/nginx/sites-enabled/${interface}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
echo "${port}"
|
||||
}
|
||||
|
||||
function detect_enabled_sites() {
|
||||
MAINSAIL_ENABLED="false" FLUIDD_ENABLED="false"
|
||||
#check if there is another UI config already installed and reads the port they are listening on
|
||||
if [[ -e "/etc/nginx/sites-enabled/mainsail" ]]; then
|
||||
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
|
||||
MAINSAIL_PORT=$(read_listen_port "mainsail")
|
||||
fi
|
||||
if [[ -e "/etc/nginx/sites-enabled/fluidd" ]]; then
|
||||
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
|
||||
FLUIDD_PORT=$(read_listen_port "fluidd")
|
||||
|
||||
fi
|
||||
}
|
||||
401
scripts/octoprint.sh
Normal file
401
scripts/octoprint.sh
Normal file
@@ -0,0 +1,401 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#=============== INSTALL OCTOPRINT ===============#
|
||||
#=================================================#
|
||||
|
||||
function octoprint_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function octoprint_setup_dialog() {
|
||||
status_msg "Initializing OctoPrint installation ..."
|
||||
|
||||
local klipper_services klipper_count user_input=() klipper_names=()
|
||||
klipper_services=$(klipper_systemd)
|
||||
klipper_count=$(echo "${klipper_services}" | wc -w )
|
||||
|
||||
for service in ${klipper_services}; do
|
||||
klipper_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local octoprint_count
|
||||
if (( klipper_count == 1 )); then
|
||||
ok_msg "Klipper installation found!\n"
|
||||
octoprint_count=1
|
||||
|
||||
elif (( klipper_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
|
||||
for name in "${klipper_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● ${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to OctoPrint! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of OctoPrint instances to |"
|
||||
echo -e "| install. Usually one OctoPrint instance per Klipper |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| OctoPrint instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${octoprint_count} =~ ${re} || ${octoprint_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " -i "${klipper_count}" -e octoprint_count
|
||||
### break if input is valid
|
||||
[[ ${octoprint_count} =~ ${re} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${octoprint_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( octoprint_count > klipper_count )) && error_msg "Number of OctoPrint instances larger than existing Klipper instances"
|
||||
done && select_msg "${octoprint_count}"
|
||||
|
||||
else
|
||||
log_error "Internal error. octoprint_count of '${octoprint_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${octoprint_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( octoprint_count == 1 )) && local question="Install OctoPrint?"
|
||||
(( octoprint_count > 1 )) && local question="Install ${octoprint_count} OctoPrint instances?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting OctoPrint setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for octoprint
|
||||
if (( klipper_count > 1 )); then
|
||||
for name in "${klipper_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( octoprint_count > 1 )) && status_msg "Installing ${octoprint_count} OctoPrint instances ..."
|
||||
(( octoprint_count == 1 )) && status_msg "Installing OctoPrint ..."
|
||||
octoprint_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function octoprint_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### check and install all dependencies
|
||||
local dep=(
|
||||
git
|
||||
wget
|
||||
python3-pip
|
||||
python3-dev
|
||||
libyaml-dev
|
||||
build-essential
|
||||
python3-setuptools
|
||||
python3-virtualenv
|
||||
)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: check for tty and dialout usergroups and add reboot permissions
|
||||
check_usergroups
|
||||
add_reboot_permission
|
||||
|
||||
### step 2: install octoprint
|
||||
install_octoprint "${instance_arr[@]}"
|
||||
|
||||
### step 3: set up service
|
||||
create_octoprint_service "${instance_arr[@]}"
|
||||
|
||||
### step 4: enable and start all instances
|
||||
do_action_service "enable" "octoprint"
|
||||
do_action_service "start" "octoprint"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="OctoPrint has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} OctoPrint instances have been set up!"
|
||||
print_confirm "${confirm}" && print_op_ip_list "${instance_arr[0]}" && return
|
||||
}
|
||||
|
||||
function install_octoprint() {
|
||||
|
||||
function install_octoprint_python_env() {
|
||||
local tmp="${1}"
|
||||
### create and activate the virtualenv
|
||||
status_msg "Installing python virtual environment..."
|
||||
|
||||
if [[ ! -d ${tmp} ]]; then
|
||||
mkdir -p "${tmp}"
|
||||
else
|
||||
error_msg "Cannot create temporary directory in ${HOME}!"
|
||||
error_msg "Folder 'TMP_OCTO_ENV' exists and may not be empty!"
|
||||
error_msg "Please remove/rename that folder and start again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd "${tmp}"
|
||||
|
||||
if virtualenv --python=python3 venv; then
|
||||
### activate virtualenv
|
||||
source venv/bin/activate
|
||||
pip install pip --upgrade
|
||||
pip install --no-cache-dir octoprint
|
||||
### leave virtualenv
|
||||
deactivate
|
||||
else
|
||||
log_error "failure while creating python3 OctoPrint env"
|
||||
error_msg "Creation of OctoPrint virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${HOME}"
|
||||
}
|
||||
|
||||
local input=("${@}")
|
||||
local octoprint_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local j=0 octo_env
|
||||
local tmp="${HOME}/TMP_OCTO_ENV"
|
||||
|
||||
### handle single instance installs
|
||||
if (( octoprint_count == 1 )); then
|
||||
if install_octoprint_python_env "${tmp}"; then
|
||||
status_msg "Installing OctoPrint ..."
|
||||
octo_env="${HOME}/OctoPrint"
|
||||
|
||||
### rename the temporary directory to the correct name
|
||||
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
|
||||
mv "${tmp}" "${octo_env}"
|
||||
|
||||
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
|
||||
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
|
||||
else
|
||||
error_msg "OctoPrint installation failed!"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
### handle multi instance installs
|
||||
if (( octoprint_count > 1 )); then
|
||||
if install_octoprint_python_env "${tmp}"; then
|
||||
for (( i=1; i <= octoprint_count; i++ )); do
|
||||
status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..."
|
||||
octo_env="${HOME}/OctoPrint_${names[${j}]}"
|
||||
|
||||
### rename the temporary directory to the correct name
|
||||
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
|
||||
cp -r "${tmp}" "${octo_env}"
|
||||
|
||||
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
|
||||
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
|
||||
j=$(( j + 1 ))
|
||||
done && rm -rf "${tmp}"
|
||||
else
|
||||
error_msg "OctoPrint installation failed!"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function create_octoprint_service() {
|
||||
local input=("${@}")
|
||||
local octoprint_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local j=0 port=5000
|
||||
local octo_env service basedir tmp_printer config_yaml restart_cmd
|
||||
|
||||
for (( i=1; i <= octoprint_count; i++ )); do
|
||||
if (( octoprint_count == 1 )); then
|
||||
octo_env="${HOME}/OctoPrint"
|
||||
service="${SYSTEMD}/octoprint.service"
|
||||
basedir="${HOME}/.octoprint"
|
||||
tmp_printer="/tmp/printer"
|
||||
config_yaml="${basedir}/config.yaml"
|
||||
restart_cmd="sudo service octoprint restart"
|
||||
elif (( octoprint_count > 1 )); then
|
||||
octo_env="${HOME}/OctoPrint_${names[${j}]}"
|
||||
service="${SYSTEMD}/octoprint-${names[${j}]}.service"
|
||||
basedir="${HOME}/.octoprint_${names[${j}]}"
|
||||
tmp_printer="/tmp/printer-${names[${j}]}"
|
||||
config_yaml="${basedir}/config.yaml"
|
||||
restart_cmd="sudo service octoprint-${names[${j}]} restart"
|
||||
fi
|
||||
|
||||
(( octoprint_count == 1 )) && status_msg "Creating OctoPrint Service ..."
|
||||
(( octoprint_count > 1 )) && status_msg "Creating OctoPrint Service ${i}(${names[${j}]}) ..."
|
||||
|
||||
sudo /bin/sh -c "cat > ${service}" << OCTOPRINT
|
||||
[Unit]
|
||||
Description=Starts OctoPrint on startup
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Environment="LC_ALL=C.UTF-8"
|
||||
Environment="LANG=C.UTF-8"
|
||||
Type=simple
|
||||
User=${USER}
|
||||
ExecStart=${octo_env}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
OCTOPRINT
|
||||
|
||||
port=$(( port + 1 ))
|
||||
j=$(( j + 1 ))
|
||||
ok_msg "Ok!"
|
||||
|
||||
### create config.yaml
|
||||
if [[ ! -f ${basedir}/config.yaml ]]; then
|
||||
[[ ! -d ${basedir} ]] && mkdir "${basedir}"
|
||||
|
||||
(( octoprint_count == 1 )) && status_msg "Creating config.yaml ..."
|
||||
(( octoprint_count > 1 )) && status_msg "Creating config.yaml for instance ${i}(${names[${j}]}) ..."
|
||||
|
||||
/bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML
|
||||
serial:
|
||||
additionalPorts:
|
||||
- ${tmp_printer}
|
||||
disconnectOnErrors: false
|
||||
port: ${tmp_printer}
|
||||
server:
|
||||
commands:
|
||||
serverRestartCommand: ${restart_cmd}
|
||||
systemRestartCommand: sudo shutdown -r now
|
||||
systemShutdownCommand: sudo shutdown -h now
|
||||
CONFIGYAML
|
||||
ok_msg "Ok!"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function add_reboot_permission() {
|
||||
#create a backup if file already exists
|
||||
if [[ -f /etc/sudoers.d/octoprint-shutdown ]]; then
|
||||
sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old
|
||||
fi
|
||||
|
||||
#create new permission file
|
||||
status_msg "Add reboot permission to user '${USER}' ..."
|
||||
cd "${HOME}" && echo "${USER} ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
|
||||
sudo chown 0 octoprint-shutdown
|
||||
sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown
|
||||
ok_msg "Permission set!"
|
||||
}
|
||||
|
||||
function print_op_ip_list() {
|
||||
local ip octoprint_count="${1}" port=5000
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
for (( i=1; i <= octoprint_count; i++ )); do
|
||||
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
|
||||
port=$(( port + 1 ))
|
||||
done && echo
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=============== REMOVE OCTOPRINT ================#
|
||||
#=================================================#
|
||||
|
||||
function remove_octoprint_service() {
|
||||
[[ -z $(octoprint_systemd) ]] && return
|
||||
|
||||
###remove all octoprint services
|
||||
status_msg "Removing OctoPrint Systemd Services ..."
|
||||
|
||||
for service in $(octoprint_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
}
|
||||
|
||||
function remove_octoprint_sudoers() {
|
||||
[[ ! -f /etc/sudoers.d/octoprint-shutdown ]] && return
|
||||
|
||||
### remove sudoers file
|
||||
sudo rm -f /etc/sudoers.d/octoprint-shutdown
|
||||
}
|
||||
|
||||
function remove_octoprint_env() {
|
||||
local files
|
||||
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -rf "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoprint_dir() {
|
||||
local files
|
||||
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -rf "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoprint() {
|
||||
remove_octoprint_service
|
||||
remove_octoprint_sudoers
|
||||
remove_octoprint_env
|
||||
remove_octoprint_dir
|
||||
|
||||
local confirm="OctoPrint was successfully removed!"
|
||||
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=============== OCTOPRINT STATUS ================#
|
||||
#=================================================#
|
||||
|
||||
function get_octoprint_status() {
|
||||
local sf_count env_count dir_count status
|
||||
sf_count="$(octoprint_systemd | wc -w)"
|
||||
env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | wc -w)
|
||||
dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | wc -w)
|
||||
|
||||
if (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then
|
||||
status="Not installed!"
|
||||
elif (( sf_count == env_count )) && (( sf_count == dir_count )); then
|
||||
status="Installed: ${sf_count}"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
129
scripts/pretty_gcode.sh
Normal file
129
scripts/pretty_gcode.sh
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#================== INSTALL PGC ==================#
|
||||
#=================================================#
|
||||
|
||||
function install_pgc_for_klipper() {
|
||||
local pgconfsrc="${PGC_DIR}/pgcode.local.conf"
|
||||
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
|
||||
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
|
||||
local pgc_uri pgc_custom_port pgc_default_port="7136"
|
||||
|
||||
status_msg "Installing PrettyGCode for Klipper ..."
|
||||
echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: ${pgc_default_port})${white} "
|
||||
read -e -p "${cyan}###### Port:${white} " -i "${pgc_default_port}" pgc_custom_port
|
||||
|
||||
### check nginx dependency
|
||||
local dep=(nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
[[ -d ${PGC_DIR} ]] && rm -rf "${PGC_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${PGC_REPO}" "${PGC_DIR}"; then
|
||||
print_error "Cloning PrettyGCode for Klipper from\n ${PGC_REPO}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo cp "${pgconfsrc}" "${pgconf}"
|
||||
sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" "${pgconf}"
|
||||
|
||||
### replace default port
|
||||
if (( pgc_custom_port != pgc_default_port )); then
|
||||
sudo sed -i "s|listen ${pgc_default_port};|listen ${pgc_custom_port};|" "${pgconf}"
|
||||
sudo sed -i "s|listen \[::\]:${pgc_default_port};|listen \[::\]:${pgc_custom_port};|" "${pgconf}"
|
||||
fi
|
||||
|
||||
[[ ! -L ${pgconfsl} ]] && sudo ln -s "${pgconf}" "${pgconfsl}"
|
||||
sudo systemctl restart nginx
|
||||
|
||||
pgc_uri="http://$(hostname -I | cut -d" " -f1):${pgc_custom_port}"
|
||||
echo -e "${cyan}\n● Accessible via:${white} ${pgc_uri}"
|
||||
ok_msg "PrettyGCode for Klipper installed!\n"
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=================== REMOVE PGC ==================#
|
||||
#=================================================#
|
||||
|
||||
function remove_prettygcode() {
|
||||
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
|
||||
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
|
||||
|
||||
if [[ -d ${PGC_DIR} || -f ${pgconf} || -L ${pgconfsl} ]]; then
|
||||
status_msg "Removing PrettyGCode for Klipper ..."
|
||||
rm -rf "${PGC_DIR}"
|
||||
sudo rm -f "${pgconf}"
|
||||
sudo rm -f "${pgconfsl}"
|
||||
sudo systemctl restart nginx
|
||||
print_confirm "PrettyGCode for Klipper successfully removed!"
|
||||
else
|
||||
print_error "PrettyGCode for Klipper not found!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=================== UPDATE PGC ==================#
|
||||
#=================================================#
|
||||
|
||||
function update_pgc_for_klipper() {
|
||||
[[ ! -d ${PGC_DIR} ]] && return
|
||||
|
||||
status_msg "Updating PrettyGCode for Klipper ..."
|
||||
cd "${PGC_DIR}" && git pull
|
||||
ok_msg "Update complete!"
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#=================== PGC STATUS ==================#
|
||||
#=================================================#
|
||||
|
||||
function get_local_prettygcode_commit() {
|
||||
local commit
|
||||
|
||||
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
|
||||
cd "${PGC_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_prettygcode_commit() {
|
||||
local commit
|
||||
|
||||
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
|
||||
cd "${PGC_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_prettygcode_versions() {
|
||||
unset PGC_UPDATE_AVAIL
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_prettygcode_commit)"
|
||||
remote_ver="$(get_remote_prettygcode_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add prettygcode to the update all array for the update all function in the updater
|
||||
PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper)
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
PGC_UPDATE_AVAIL="false"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
@@ -1,510 +0,0 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
|
||||
remove_klipper(){
|
||||
shopt -s extglob # enable extended globbing
|
||||
### ask the user if he wants to uninstall moonraker too.
|
||||
###? currently usefull if the user wants to switch from single-instance to multi-instance
|
||||
FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service"
|
||||
if ls $FILE 2>/dev/null 1>&2; 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 ]; then
|
||||
status_msg "Removing Klipper Service ..."
|
||||
sudo systemctl stop klipper
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo rm -f /etc/init.d/klipper
|
||||
sudo rm -f /etc/default/klipper
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
|
||||
### remove all klipper services
|
||||
FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service"
|
||||
if ls $FILE 2>/dev/null 1>&2; then
|
||||
status_msg "Removing Klipper Services ..."
|
||||
for service in $(ls $FILE | cut -d"/" -f5)
|
||||
do
|
||||
status_msg "Removing $service ..."
|
||||
sudo systemctl stop $service
|
||||
sudo systemctl disable $service
|
||||
sudo rm -f $SYSTEMDDIR/$service
|
||||
ok_msg "Done!"
|
||||
done
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
|
||||
### remove all logfiles
|
||||
FILE="${HOME}/klipper_logs/klippy?(-*([0-9])).log"
|
||||
if ls $FILE 2>/dev/null 1>&2; then
|
||||
for log in $(ls $FILE); do
|
||||
status_msg "Removing $log ..."
|
||||
rm -f $log
|
||||
ok_msg "$log removed!"
|
||||
done
|
||||
fi
|
||||
|
||||
### remove all UDS
|
||||
FILE="/tmp/klippy_uds?(-*([0-9]))"
|
||||
if ls $FILE 2>/dev/null 1>&2; then
|
||||
for uds in $(ls $FILE); do
|
||||
status_msg "Removing $uds ..."
|
||||
rm -f $uds
|
||||
ok_msg "$uds removed!"
|
||||
done
|
||||
fi
|
||||
|
||||
### remove all tmp-printer
|
||||
FILE="/tmp/printer?(-*([0-9]))"
|
||||
if ls $FILE 2>/dev/null 1>&2; then
|
||||
for tmp_printer in $(ls $FILE); do
|
||||
status_msg "Removing $tmp_printer ..."
|
||||
rm -f $tmp_printer
|
||||
ok_msg "$tmp_printer removed!"
|
||||
done
|
||||
fi
|
||||
|
||||
### removing klipper and klippy-env folders
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
status_msg "Removing Klipper directory ..."
|
||||
rm -rf $KLIPPER_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
if [ -d $KLIPPY_ENV ]; then
|
||||
status_msg "Removing klippy-env directory ..."
|
||||
rm -rf $KLIPPY_ENV && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg
|
||||
shopt -u extglob # enable extended globbing
|
||||
|
||||
if [ "$REM_MR" == "true" ]; then
|
||||
remove_moonraker && unset REM_MR
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_moonraker(){
|
||||
shopt -s extglob # enable extended globbing
|
||||
### remove "legacy" moonraker init.d service
|
||||
if [ -f /etc/init.d/moonraker ]; then
|
||||
status_msg "Removing Moonraker Service ..."
|
||||
sudo systemctl stop moonraker
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -f /etc/init.d/moonraker
|
||||
sudo rm -f /etc/default/moonraker
|
||||
ok_msg "Moonraker Service removed!"
|
||||
fi
|
||||
|
||||
### remove all moonraker services
|
||||
FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service"
|
||||
if ls $FILE 2>/dev/null 1>&2; then
|
||||
status_msg "Removing Moonraker Services ..."
|
||||
for service in $(ls $FILE | cut -d"/" -f5)
|
||||
do
|
||||
status_msg "Removing $service ..."
|
||||
sudo systemctl stop $service
|
||||
sudo systemctl disable $service
|
||||
sudo rm -f $SYSTEMDDIR/$service
|
||||
ok_msg "Done!"
|
||||
done
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Moonraker Service removed!"
|
||||
fi
|
||||
|
||||
### remove all logfiles
|
||||
FILE="${HOME}/klipper_logs/moonraker?(-*([0-9])).log"
|
||||
if ls $FILE 2>/dev/null 1>&2; then
|
||||
for log in $(ls $FILE); do
|
||||
status_msg "Removing $log ..."
|
||||
rm -f $log
|
||||
ok_msg "$log removed!"
|
||||
done
|
||||
fi
|
||||
|
||||
### remove 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!"
|
||||
shopt -u extglob # disable extended globbing
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_dwc2(){
|
||||
### remove "legacy" init.d service
|
||||
if [ -e /etc/init.d/dwc ]; then
|
||||
status_msg "Removing DWC2-for-Klipper-Socket Service ..."
|
||||
sudo systemctl stop dwc
|
||||
sudo update-rc.d -f dwc remove
|
||||
sudo rm -f /etc/init.d/dwc
|
||||
sudo rm -f /etc/default/dwc
|
||||
ok_msg "DWC2-for-Klipper-Socket Service removed!"
|
||||
fi
|
||||
|
||||
### remove all dwc services
|
||||
if ls /etc/systemd/system/dwc*.service 2>/dev/null 1>&2; then
|
||||
status_msg "Removing DWC2-for-Klipper-Socket Services ..."
|
||||
for service in $(ls /etc/systemd/system/dwc*.service | cut -d"/" -f5)
|
||||
do
|
||||
status_msg "Removing $service ..."
|
||||
sudo systemctl stop $service
|
||||
sudo systemctl disable $service
|
||||
sudo rm -f $SYSTEMDDIR/$service
|
||||
ok_msg "Done!"
|
||||
done
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "DWC2-for-Klipper-Socket Service removed!"
|
||||
fi
|
||||
|
||||
### remove all logfiles
|
||||
if ls /tmp/dwc*.log 2>/dev/null 1>&2; then
|
||||
for logfile in $(ls /tmp/dwc*.log)
|
||||
do
|
||||
status_msg "Removing $logfile ..."
|
||||
rm -f $logfile
|
||||
ok_msg "File '$logfile' removed!"
|
||||
done
|
||||
fi
|
||||
|
||||
### removing the rest of the folders
|
||||
if [ -d $DWC2FK_DIR ]; then
|
||||
status_msg "Removing DWC2-for-Klipper-Socket directory ..."
|
||||
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
if [ -d $DWC_ENV_DIR ]; then
|
||||
status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..."
|
||||
rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
if [ -d $DWC2_DIR ]; then
|
||||
status_msg "Removing DWC2 directory ..."
|
||||
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove dwc2_port from ~/.kiauh.ini
|
||||
sed -i "/^dwc2_port=/d" $INI_FILE
|
||||
|
||||
CONFIRM_MSG=" DWC2-for-Klipper-Socket 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
|
||||
|
||||
### remove mainsail nginx logs and log symlinks
|
||||
for log in $(find /var/log/nginx -name "mainsail*"); do
|
||||
sudo rm -f $log
|
||||
done
|
||||
for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do
|
||||
rm -f $log
|
||||
done
|
||||
|
||||
### remove mainsail_port from ~/.kiauh.ini
|
||||
sed -i "/^mainsail_port=/d" $INI_FILE
|
||||
|
||||
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
|
||||
|
||||
### remove mainsail nginx logs and log symlinks
|
||||
for log in $(find /var/log/nginx -name "fluidd*"); do
|
||||
sudo rm -f $log
|
||||
done
|
||||
for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do
|
||||
rm -f $log
|
||||
done
|
||||
|
||||
### remove fluidd_port from ~/.kiauh.ini
|
||||
sed -i "/^fluidd_port=/d" $INI_FILE
|
||||
|
||||
CONFIRM_MSG="Fluidd successfully removed!"
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_octoprint(){
|
||||
###remove all octoprint services
|
||||
if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then
|
||||
status_msg "Removing OctoPrint Services ..."
|
||||
for service in $(ls /etc/systemd/system/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
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
fi
|
||||
|
||||
### 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 ls -d ${HOME}/.octoprint* 2>/dev/null 1>&2; then
|
||||
for folder in $(ls -d ${HOME}/.octoprint*)
|
||||
do
|
||||
status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
|
||||
### remove octoprint_port from ~/.kiauh.ini
|
||||
sed -i "/^octoprint_port=/d" $INI_FILE
|
||||
|
||||
CONFIRM_MSG=" OctoPrint successfully removed!"
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
remove_nginx(){
|
||||
if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then
|
||||
status_msg "Stopping Nginx service ..."
|
||||
sudo systemctl stop nginx && sudo systemctl disable nginx
|
||||
ok_msg "Service stopped and disabled!"
|
||||
status_msg "Purging Nginx from system ..."
|
||||
sudo apt-get purge nginx nginx-common -y
|
||||
sudo update-rc.d -f nginx remove
|
||||
CONFIRM_MSG=" Nginx successfully removed!"
|
||||
else
|
||||
ERROR_MSG=" Looks like Nginx was already removed!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
remove_klipperscreen(){
|
||||
source_kiauh_ini
|
||||
|
||||
### 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 service
|
||||
if [ -e /etc/systemd/system/KlipperScreen.service ]; then
|
||||
status_msg "Removing KlipperScreen service ..."
|
||||
sudo systemctl stop KlipperScreen
|
||||
sudo systemctl disable KlipperScreen
|
||||
sudo rm -f $SYSTEMDDIR/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_cfg_loc/KlipperScreen.log ]; then
|
||||
status_msg "Removing KlipperScreen log symlink ..."
|
||||
rm -f $klipper_cfg_loc/KlipperScreen.log && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
CONFIRM_MSG="KlipperScreen successfully removed!"
|
||||
}
|
||||
|
||||
remove_MoonrakerTelegramBot(){
|
||||
source_kiauh_ini
|
||||
|
||||
### remove MoonrakerTelegramBot dir
|
||||
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ]; then
|
||||
status_msg "Removing MoonrakerTelegramBot directory ..."
|
||||
rm -rf $MOONRAKER_TELEGRAM_BOT_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove MoonrakerTelegramBot VENV dir
|
||||
if [ -d $MOONRAKER_TELEGRAM_BOT_ENV_DIR ]; then
|
||||
status_msg "Removing MoonrakerTelegramBot VENV directory ..."
|
||||
rm -rf $MOONRAKER_TELEGRAM_BOT_ENV_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove MoonrakerTelegramBot service
|
||||
if [ -e /etc/systemd/system/moonraker-telegram-bot.service ]; then
|
||||
status_msg "Removing MoonrakerTelegramBot service ..."
|
||||
sudo systemctl stop moonraker-telegram-bot
|
||||
sudo systemctl disable moonraker-telegram-bot
|
||||
sudo rm -f $SYSTEMDDIR/moonraker-telegram-bot.service
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "MoonrakerTelegramBot Service removed!"
|
||||
fi
|
||||
|
||||
### remove MoonrakerTelegramBot log
|
||||
if [ -e /tmp/telegram.log ] || [ -e ${HOME}/klipper_logs/telegram.log ]; then
|
||||
status_msg "Removing MoonrakerTelegramBot log file ..."
|
||||
rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
### remove MoonrakerTelegramBot log symlink in config dir
|
||||
|
||||
if [ -e $klipper_cfg_loc/telegram.log ]; then
|
||||
status_msg "Removing MoonrakerTelegramBot log symlink ..."
|
||||
rm -f $klipper_cfg_loc/telegram.log && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
CONFIRM_MSG="MoonrakerTelegramBot successfully removed!"
|
||||
}
|
||||
|
||||
remove_mjpg-streamer(){
|
||||
### remove MJPG-Streamer service
|
||||
if [ -e $SYSTEMDDIR/webcamd.service ]; then
|
||||
status_msg "Removing MJPG-Streamer service ..."
|
||||
sudo systemctl stop webcamd && sudo systemctl disable webcamd
|
||||
sudo rm -f $SYSTEMDDIR/webcamd.service
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "MJPG-Streamer Service removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd from /usr/local/bin
|
||||
if [ -e "/usr/local/bin/webcamd" ]; then
|
||||
sudo rm -f "/usr/local/bin/webcamd"
|
||||
fi
|
||||
|
||||
### remove MJPG-Streamer directory
|
||||
if [ -d ${HOME}/mjpg-streamer ]; then
|
||||
status_msg "Removing MJPG-Streamer directory ..."
|
||||
rm -rf ${HOME}/mjpg-streamer
|
||||
ok_msg "MJPG-Streamer directory removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd log and symlink
|
||||
[ -f "/var/log/webcamd.log" ] && sudo rm -f "/var/log/webcamd.log"
|
||||
[ -L "${HOME}/klipper_logs/webcamd.log" ] && rm -f "${HOME}/klipper_logs/webcamd.log"
|
||||
|
||||
CONFIRM_MSG="MJPG-Streamer successfully removed!"
|
||||
}
|
||||
|
||||
remove_prettygcode(){
|
||||
pgconf="/etc/nginx/sites-available/pgcode.local.conf"
|
||||
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
|
||||
if [ -d ${HOME}/pgcode ] || [ -f $pgconf ] || [ -L $pgconfsl ]; then
|
||||
status_msg "Removing PrettyGCode for Klipper ..."
|
||||
rm -rf ${HOME}/pgcode
|
||||
sudo rm -f $pgconf
|
||||
sudo rm -f $pgconfsl
|
||||
sudo systemctl restart nginx
|
||||
CONFIRM_MSG="PrettyGCode for Klipper successfully removed!"
|
||||
else
|
||||
ERROR_MSG="PrettyGCode for Klipper not found!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
@@ -1,111 +1,85 @@
|
||||
save_klipper_state(){
|
||||
source_kiauh_ini
|
||||
#read current klipper state
|
||||
cd $KLIPPER_DIR
|
||||
COMMIT_STATE=$(git rev-parse --short HEAD)
|
||||
if [ "$GET_BRANCH" = "master" ]; then
|
||||
ORI_OLD=$previous_origin_state
|
||||
ORI_NEW=$COMMIT_STATE
|
||||
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE
|
||||
elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
|
||||
SHA_OLD=$previous_shaping_state
|
||||
SHA_NEW=$COMMIT_STATE
|
||||
sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE
|
||||
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
|
||||
SMO_OLD=$previous_smoothing_state
|
||||
SMO_NEW=$COMMIT_STATE
|
||||
sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE
|
||||
fi
|
||||
}
|
||||
#!/usr/bin/env bash
|
||||
|
||||
load_klipper_state(){
|
||||
source_kiauh_ini
|
||||
print_branch
|
||||
cd $KLIPPER_DIR
|
||||
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD)
|
||||
if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then
|
||||
PREVIOUS_COMMIT=$previous_origin_state
|
||||
elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
|
||||
PREVIOUS_COMMIT=$previous_shaping_state
|
||||
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
|
||||
PREVIOUS_COMMIT=$previous_smoothing_state
|
||||
fi
|
||||
CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT)
|
||||
if [ "$PREVIOUS_COMMIT" != "0" ]; then
|
||||
PREVIOUS_COMMIT_DATE=$(git show -s --format=%cd --date=short $PREVIOUS_COMMIT)
|
||||
fi
|
||||
if [ "$PREVIOUS_COMMIT" = "0" ]; then
|
||||
CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}")
|
||||
PREV_UI=$(echo -e "${red}None${default} ")
|
||||
else
|
||||
if [ "$CURRENT_COMMIT" = "$PREVIOUS_COMMIT" ]; then
|
||||
CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}")
|
||||
PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}")
|
||||
else
|
||||
CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}")
|
||||
PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}")
|
||||
fi
|
||||
fi
|
||||
rollback_ui
|
||||
rollback_klipper
|
||||
}
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
rollback_ui(){
|
||||
set -e
|
||||
|
||||
function rollback_menu() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | "
|
||||
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} | "
|
||||
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 "| Currently on commit: | "
|
||||
echo -e "| $CURR_UI | "
|
||||
hr
|
||||
echo -e "| Commit last updated from: | "
|
||||
echo -e "| $PREV_UI | "
|
||||
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
|
||||
}
|
||||
|
||||
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;;
|
||||
B|b) 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
|
||||
B|b)
|
||||
clear; advanced_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
rollback_ui;;
|
||||
esac
|
||||
done
|
||||
function rollback_component() {
|
||||
local component=${1}
|
||||
|
||||
if [[ ! -d "${HOME}/${component}" ]]; then
|
||||
print_error "Rollback not possible! Missing installation?"
|
||||
return
|
||||
fi
|
||||
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Please select how many commits you want to revert. |"
|
||||
echo -e "| Consider using the information provided by the GitHub |"
|
||||
echo -e "| commit history to decide how many commits to revert. |"
|
||||
blank_line
|
||||
echo -e "| ${red}Warning:${white} |"
|
||||
echo -e "| ${red}Do not proceed if you are currently in the progress${white} |"
|
||||
echo -e "| ${red}of printing! Proceeding WILL terminate that print!${white} |"
|
||||
back_footer
|
||||
|
||||
local count
|
||||
while true; do
|
||||
read -p "${cyan}###### Revert this amount of commits:${white} " count
|
||||
if [[ -n ${count} ]] && (( count > 0 )); then
|
||||
status_msg "Revert ${component^} by ${count} commits ..."
|
||||
cd "${HOME}/${component}"
|
||||
if git reset --hard HEAD~"${count}"; then
|
||||
do_action_service "restart" "${component}"
|
||||
print_confirm "${component^} was successfully reset!"
|
||||
else
|
||||
print_error "Reverting ${component^} failed! Please see the console output above."
|
||||
fi
|
||||
break
|
||||
elif [[ ${count} == "B" || ${count} == "b" ]]; then
|
||||
clear && print_header && break
|
||||
else
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
rollback_menu
|
||||
}
|
||||
|
||||
@@ -1,628 +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
|
||||
}
|
||||
|
||||
check_system_updates(){
|
||||
SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d")
|
||||
if [ ! -z "$SYS_UPDATE" ]; then
|
||||
# add system updates to the update all array for the update all function in the updater
|
||||
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
|
||||
DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${default}"
|
||||
else
|
||||
SYS_UPDATE_AVAIL="false"
|
||||
DISPLAY_SYS_UPDATE="${green}System up to date! ${default}"
|
||||
fi
|
||||
}
|
||||
|
||||
klipper_status(){
|
||||
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(\-[[:digit:]]+)?\.service$" | wc -l)
|
||||
|
||||
### a fix to detect an existing "legacy" klipper init.d installation
|
||||
if [ -f /etc/init.d/klipper ] && [ -f /etc/init.d/klipper ]; then
|
||||
SERVICE_FILE_COUNT=1
|
||||
fi
|
||||
|
||||
### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
|
||||
[ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0]
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
for kd in "${klipper_data[@]}"
|
||||
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(\-[[:digit:]]+)?\.service$" | wc -l)
|
||||
|
||||
### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed
|
||||
[ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0]
|
||||
|
||||
#count+1 for each found data-item from array
|
||||
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(\-[[:digit:]]+)?\.service$" | wc -l)
|
||||
|
||||
### remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
|
||||
[ $SERVICE_FILE_COUNT -gt 0 ] && unset moonraker_data[0]
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
for mrd in "${moonraker_data[@]}"
|
||||
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(\-[[:digit:]]+)?\.service$" | wc -l)
|
||||
|
||||
### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed
|
||||
[ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0]
|
||||
|
||||
#count+1 for each found data-item from array
|
||||
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
|
||||
}
|
||||
|
||||
MoonrakerTelegramBot_status(){
|
||||
mtbcount=0
|
||||
MoonrakerTelegramBot_data=(
|
||||
SERVICE
|
||||
$MOONRAKER_TELEGRAM_BOT_DIR
|
||||
$MOONRAKER_TELEGRAM_BOT_ENV_DIR
|
||||
)
|
||||
|
||||
### count amount of MoonrakerTelegramBot_data service files in /etc/systemd/system
|
||||
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker-telegram-bot" | wc -l)
|
||||
|
||||
### remove the "SERVICE" entry from the MoonrakerTelegramBot_data array if a MoonrakerTelegramBot service is installed
|
||||
[ $SERVICE_FILE_COUNT -gt 0 ] && unset MoonrakerTelegramBot_data[0]
|
||||
|
||||
#count+1 for each found data-item from array
|
||||
for mtbd in "${MoonrakerTelegramBot_data[@]}"
|
||||
do
|
||||
if [ -e $mtbd ]; then
|
||||
mtbcount=$(expr $mtbcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$mtbcount" == "${#MoonrakerTelegramBot_data[*]}" ]; then
|
||||
MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${default} "
|
||||
elif [ "$mtbcount" == 0 ]; then
|
||||
MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
### 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}"
|
||||
# add klipper to the update all array for the update all function in the updater
|
||||
KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper)
|
||||
else
|
||||
LOCAL_COMMIT="${green}$(printf "%-12s" "$LOCAL_COMMIT")${default}"
|
||||
REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}"
|
||||
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}"
|
||||
# add dwc2fk to the update all array for the update all function in the updater
|
||||
DWC2FK_UPDATE_AVAIL="true" && update_arr+=(update_dwc2fk)
|
||||
else
|
||||
LOCAL_DWC2FK_COMMIT="${green}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}"
|
||||
REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}"
|
||||
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 "%-12s" "$DWC2_LOCAL_VER")${default}"
|
||||
DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}"
|
||||
elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then
|
||||
DWC2_LOCAL_VER="${yellow}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}"
|
||||
DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}"
|
||||
# add dwc to the update all array for the update all function in the updater
|
||||
DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2)
|
||||
else
|
||||
DWC2_LOCAL_VER=$NONE
|
||||
DWC2_REMOTE_VER="${green}$(printf "%-12s" "$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}"
|
||||
# add moonraker to the update all array for the update all function in the updater
|
||||
MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker)
|
||||
else
|
||||
LOCAL_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_COMMIT")${default}"
|
||||
REMOTE_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_COMMIT")${default}"
|
||||
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}"
|
||||
# add mainsail to the update all array for the update all function in the updater
|
||||
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
|
||||
else
|
||||
MAINSAIL_LOCAL_VER=$NONE
|
||||
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}"
|
||||
# add fluidd to the update all array for the update all function in the updater
|
||||
FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd)
|
||||
else
|
||||
FLUIDD_LOCAL_VER=$NONE
|
||||
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
|
||||
}
|
||||
|
||||
read_MoonrakerTelegramBot_versions(){
|
||||
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] && [ -d $MOONRAKER_TELEGRAM_BOT_DIR/.git ]; then
|
||||
cd $MOONRAKER_TELEGRAM_BOT_DIR
|
||||
git fetch origin master -q
|
||||
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
else
|
||||
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$NONE
|
||||
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
compare_MoonrakerTelegramBot_versions(){
|
||||
unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL
|
||||
read_MoonrakerTelegramBot_versions
|
||||
if [ "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT" != "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT" ]; then
|
||||
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
|
||||
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
|
||||
# add moonraker telegram bot to the update all array for the update all function in the updater
|
||||
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_MoonrakerTelegramBot)
|
||||
else
|
||||
LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
|
||||
REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}"
|
||||
MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
read_pgc_versions(){
|
||||
PGC_DIR="${HOME}/pgcode"
|
||||
if [ -d $PGC_DIR ] && [ -d $PGC_DIR/.git ]; then
|
||||
cd $PGC_DIR
|
||||
git fetch origin main -q
|
||||
LOCAL_PGC_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
REMOTE_PGC_COMMIT=$(git describe origin/main --always --tags | cut -d "-" -f 1,2)
|
||||
else
|
||||
LOCAL_PGC_COMMIT=$NONE
|
||||
REMOTE_PGC_COMMIT=$NONE
|
||||
fi
|
||||
}
|
||||
|
||||
compare_pgc_versions(){
|
||||
unset PGC_UPDATE_AVAIL
|
||||
read_pgc_versions
|
||||
if [ "$LOCAL_PGC_COMMIT" != "$REMOTE_PGC_COMMIT" ]; then
|
||||
LOCAL_PGC_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_PGC_COMMIT")${default}"
|
||||
REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "$REMOTE_PGC_COMMIT")${default}"
|
||||
# add PGC to the update all array for the update all function in the updater
|
||||
PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper)
|
||||
else
|
||||
LOCAL_PGC_COMMIT="${green}$(printf "%-12s" "$LOCAL_PGC_COMMIT")${default}"
|
||||
REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "$REMOTE_PGC_COMMIT")${default}"
|
||||
PGC_UPDATE_AVAIL="false"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
#display this as placeholder if no version/commit could be fetched
|
||||
NONE="${red}$(printf "%-12s" "--------")${default}"
|
||||
|
||||
ui_print_versions(){
|
||||
unset update_arr
|
||||
check_system_updates
|
||||
compare_klipper_versions
|
||||
compare_dwc2fk_versions
|
||||
compare_dwc2_versions
|
||||
compare_moonraker_versions
|
||||
compare_mainsail_versions
|
||||
compare_fluidd_versions
|
||||
compare_klipperscreen_versions
|
||||
compare_MoonrakerTelegramBot_versions
|
||||
compare_pgc_versions
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
switch_to_master(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
git fetch origin -q && git checkout master; echo
|
||||
}
|
||||
|
||||
switch_to_scurve_shaping(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep dmbutyugin -q; then
|
||||
git remote add dmbutyugin $DMBUTYUGIN_REPO
|
||||
fi
|
||||
git fetch dmbutyugin -q && git checkout scurve-shaping; echo
|
||||
}
|
||||
|
||||
switch_to_scurve_smoothing(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep dmbutyugin -q; then
|
||||
git remote add dmbutyugin $DMBUTYUGIN_REPO
|
||||
fi
|
||||
git fetch dmbutyugin -q && git checkout scurve-smoothing; echo
|
||||
}
|
||||
138
scripts/switch_klipper_repo.sh
Normal file
138
scripts/switch_klipper_repo.sh
Normal file
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function change_klipper_repo_menu() {
|
||||
local repo_file="${KIAUH_SRCDIR}/klipper_repos.txt"
|
||||
local repo branch repos=() branches=()
|
||||
|
||||
if [[ ! -f ${repo_file} ]]; then
|
||||
print_error "File not found:\n '${KIAUH_SRCDIR}/klipper_repos.txt'"
|
||||
return
|
||||
fi
|
||||
|
||||
### generate the repolist from the klipper_repos.txt textfile
|
||||
while IFS="," read -r repo branch; do
|
||||
repo=$(echo "${repo}" | sed -r "s/^http(s)?:\/\/github.com\///" | sed "s/\.git$//" )
|
||||
repos+=("${repo}")
|
||||
### if branch is not given, default to 'master'
|
||||
[[ -z ${branch} ]] && branch="master"
|
||||
branches+=("${branch}")
|
||||
done < <(grep -E "^[^#]" "${repo_file}")
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | "
|
||||
hr
|
||||
blank_line
|
||||
### print repolist
|
||||
local i=0
|
||||
for _ in "${repos[@]}"; do
|
||||
printf "| %s) %-63s|\n" "${i}" "${yellow}${repos[${i}]}${white} → ${branches[${i}]}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local option
|
||||
while true; do
|
||||
read -p "${cyan}###### Perform action:${white} " option
|
||||
case "${option}" in
|
||||
0 | "$(( option < ${#repos[@]} ))")
|
||||
select_msg "Repo: ${repos[option]} Branch: ${branches[option]}"
|
||||
if [[ -d ${KLIPPER_DIR} ]]; then
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${white} |"
|
||||
echo -e "| Existing Klipper folder found! Proceeding will remove | "
|
||||
echo -e "| the existing Klipper folder and replace it with a | "
|
||||
echo -e "| clean copy of the previously selected source repo! | "
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Proceed? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
switch_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
|
||||
set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
status_msg "Set custom Klipper repository to:\n ● Repository: ${repos[${option}]}\n ● Branch: ${branches[${option}]}"
|
||||
set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}"
|
||||
ok_msg "This repo will now be used for new Klipper installations!\n"
|
||||
fi
|
||||
break;;
|
||||
B|b)
|
||||
clear && print_header
|
||||
settings_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_custom_klipper_repo_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
change_klipper_repo_menu
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function switch_klipper_repo() {
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
status_msg "Switching Klipper repository..."
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
|
||||
clone_klipper "${repo}" "${branch}"
|
||||
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function show_custom_klipper_repo_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |"
|
||||
hr
|
||||
echo -e "| With this setting, it is possible to install Klipper |"
|
||||
echo -e "| from a custom repository. It will also switch an |"
|
||||
echo -e "| existing Klipper installation to the newly selected |"
|
||||
echo -e "| source repository. |"
|
||||
echo -e "| A list of repositories is automatically generated by |"
|
||||
echo -e "| a 'klipper_repos.txt' textfile in KIAUHs root folder. |"
|
||||
echo -e "| An example file is provided at the same location. |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
change_klipper_repo_menu
|
||||
break;;
|
||||
*)
|
||||
deny_action "show_settings_help";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -1,70 +1,64 @@
|
||||
advanced_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function advanced_ui() {
|
||||
top_border
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
if [ ! "$OPRINT_SERVICE_STATUS" == "" ]; then
|
||||
echo -e "| 0) $OPRINT_SERVICE_STATUS| "
|
||||
hr
|
||||
echo -e "| | | "
|
||||
fi
|
||||
echo -e "| Klipper: | Mainsail: | "
|
||||
echo -e "| 1) [Switch Branch] | 7) [Theme installer] | "
|
||||
echo -e "| 2) [Rollback] | | "
|
||||
echo -e "| | System: | "
|
||||
echo -e "| Firmware: | 8) [Change hostname] | "
|
||||
echo -e "| 3) [Build only] | | "
|
||||
echo -e "| 4) [Flash only] | Extensions: | "
|
||||
echo -e "| 5) [Build + Flash] | 9) [Shell Command] | "
|
||||
echo -e "| 6) [Get MCU ID] | | "
|
||||
echo -e "| | CustomPiOS: | "
|
||||
echo -e "| | 10) [Migration Helper] | "
|
||||
back_footer
|
||||
echo -e "| Klipper & API: | Mainsail: |"
|
||||
echo -e "| 1) [Rollback] | 6) [Theme installer] |"
|
||||
echo -e "| | |"
|
||||
echo -e "| Firmware: | System: |"
|
||||
echo -e "| 2) [Build only] | 7) [Change hostname] |"
|
||||
echo -e "| 3) [Flash only] | |"
|
||||
echo -e "| 4) [Build + Flash] | Extras: |"
|
||||
echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
advanced_menu(){
|
||||
read_octoprint_service_status
|
||||
function advanced_menu() {
|
||||
do_action "" "advanced_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
0)
|
||||
clear
|
||||
print_header
|
||||
toggle_octoprint_service
|
||||
read_octoprint_service_status
|
||||
print_msg && clear_msg
|
||||
advanced_ui;;
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
do_action "switch_menu";;
|
||||
do_action "rollback_menu" "advanced_menu";;
|
||||
2)
|
||||
do_action "load_klipper_state" "advanced_ui";;
|
||||
3)
|
||||
do_action "build_fw" "advanced_ui";;
|
||||
3)
|
||||
clear && print_header
|
||||
do_action "init_flash_process" "advanced_ui";;
|
||||
4)
|
||||
clear && print_header
|
||||
check_usergroup_dialout
|
||||
do_action "select_flash_method" "advanced_ui";;
|
||||
status_msg "Please wait..."
|
||||
build_fw && init_flash_process
|
||||
advanced_ui;;
|
||||
5)
|
||||
clear && print_header
|
||||
check_usergroup_dialout
|
||||
status_msg "Please wait..."
|
||||
build_fw && select_flash_method
|
||||
print_msg && clear_msg
|
||||
select_mcu_connection
|
||||
print_detected_mcu_to_screen
|
||||
advanced_ui;;
|
||||
6)
|
||||
do_action "select_mcu_connection" "advanced_ui";;
|
||||
do_action "ms_theme_installer_menu";;
|
||||
7)
|
||||
do_action "ms_theme_menu";;
|
||||
8)
|
||||
clear
|
||||
print_header
|
||||
create_custom_hostname && set_hostname
|
||||
print_msg && clear_msg
|
||||
set_custom_hostname
|
||||
advanced_ui;;
|
||||
9)
|
||||
8)
|
||||
do_action "setup_gcode_shell_command" "advanced_ui";;
|
||||
10)
|
||||
do_action "migration_menu";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
@@ -72,108 +66,4 @@ advanced_menu(){
|
||||
esac
|
||||
done
|
||||
advanced_menu
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
switch_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |"
|
||||
bottom_border
|
||||
echo
|
||||
echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}"
|
||||
echo
|
||||
top_border
|
||||
echo -e "| | "
|
||||
echo -e "| KevinOConnor: | "
|
||||
echo -e "| 1) [--> master] | "
|
||||
echo -e "| | "
|
||||
echo -e "| dmbutyugin: | "
|
||||
echo -e "| 2) [--> scurve-shaping] | "
|
||||
echo -e "| 3) [--> scurve-smoothing] | "
|
||||
back_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;;
|
||||
B|b)
|
||||
clear; advanced_menu; break;;
|
||||
*)
|
||||
deny_action "switch_ui";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
ERROR_MSG="No Klipper directory found! Download Klipper first!"
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
migration_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~ [ CustomPiOS Migration ] ~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| This function will help you to migrate a vanilla | "
|
||||
echo -e "| MainsailOS or FluiddPi image to a newer state. | "
|
||||
blank_line
|
||||
echo -e "| Only use this function if you use MainsailOS 0.4.0 | "
|
||||
echo -e "| or lower, or FluiddPi v1.13.0 or lower. | "
|
||||
blank_line
|
||||
echo -e "| Please have a look at the KIAUH changelog for more | "
|
||||
echo -e "| details on what this function will do. | "
|
||||
hr
|
||||
echo -e "| | "
|
||||
echo -e "| 1) [Migrate MainsailOS] | "
|
||||
echo -e "| 2) [Migrate FluiddPi] | "
|
||||
echo -e "| | "
|
||||
back_footer
|
||||
}
|
||||
|
||||
migration_menu(){
|
||||
print_msg && clear_msg
|
||||
migration_ui
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
1) migrate_custompios "mainsail"; migration_menu;;
|
||||
2) migrate_custompios "fluiddpi"; migration_menu;;
|
||||
B|b) clear; advanced_menu; break;;
|
||||
*) print_unkown_cmd; migration_menu;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,59 @@
|
||||
backup_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function backup_ui() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | "
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | "
|
||||
echo -e "| ${yellow}INFO: Backups are located in '~/kiauh-backups'${white} |"
|
||||
hr
|
||||
echo -e "| Configuration folder: | Klipper Webinterface: | "
|
||||
echo -e "| 0) [Klipper configs] | 4) [Mainsail] | "
|
||||
echo -e "| | 5) [Fluidd] | "
|
||||
echo -e "| Firmware: | | "
|
||||
echo -e "| 1) [Klipper] | HDMI Screen: | "
|
||||
echo -e "| | 6) [KlipperScreen] | "
|
||||
echo -e "| Klipper API: | | "
|
||||
echo -e "| 2) [Moonraker] | Other: | "
|
||||
echo -e "| 3) [Moonraker DB] | 7) [Duet Web Control] | "
|
||||
echo -e "| | 8) [OctoPrint] | "
|
||||
echo -e "| | 9) [MoonrakerTelegramBot] | "
|
||||
echo -e "| Klipper & API: | Touchscreen GUI: |"
|
||||
echo -e "| 1) [Klipper] | 7) [KlipperScreen] |"
|
||||
echo -e "| 2) [Moonraker] | |"
|
||||
echo -e "| 3) [Configuration Folder] | 3rd Party Webinterface: |"
|
||||
echo -e "| 4) [Moonraker Database] | 8) [OctoPrint] |"
|
||||
echo -e "| | |"
|
||||
echo -e "| Klipper Webinterface: | Other: |"
|
||||
echo -e "| 5) [Mainsail] | 9) [Telegram Bot] |"
|
||||
echo -e "| 6) [Fluidd] | |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
backup_menu(){
|
||||
function backup_menu() {
|
||||
do_action "" "backup_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
0)
|
||||
do_action "backup_klipper_config_dir" "backup_ui";;
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
do_action "backup_klipper" "backup_ui";;
|
||||
2)
|
||||
do_action "backup_moonraker" "backup_ui";;
|
||||
3)
|
||||
do_action "backup_moonraker_database" "backup_ui";;
|
||||
do_action "backup_klipper_config_dir" "backup_ui";;
|
||||
4)
|
||||
do_action "backup_mainsail" "backup_ui";;
|
||||
do_action "backup_moonraker_database" "backup_ui";;
|
||||
5)
|
||||
do_action "backup_fluidd" "backup_ui";;
|
||||
do_action "backup_mainsail" "backup_ui";;
|
||||
6)
|
||||
do_action "backup_klipperscreen" "backup_ui";;
|
||||
do_action "backup_fluidd" "backup_ui";;
|
||||
7)
|
||||
do_action "backup_dwc2" "backup_ui";;
|
||||
do_action "backup_klipperscreen" "backup_ui";;
|
||||
8)
|
||||
do_action "backup_octoprint" "backup_ui";;
|
||||
9)
|
||||
do_action "backup_MoonrakerTelegramBot" "backup_ui";;
|
||||
do_action "backup_telegram_bot" "backup_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
|
||||
@@ -1,39 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#ui total width = 57 chars
|
||||
top_border(){
|
||||
function top_border() {
|
||||
echo -e "/=======================================================\\"
|
||||
}
|
||||
|
||||
bottom_border(){
|
||||
function bottom_border() {
|
||||
echo -e "\=======================================================/"
|
||||
}
|
||||
|
||||
blank_line(){
|
||||
function blank_line() {
|
||||
echo -e "| |"
|
||||
}
|
||||
|
||||
hr(){
|
||||
function hr() {
|
||||
echo -e "|-------------------------------------------------------|"
|
||||
}
|
||||
|
||||
quit_footer(){
|
||||
function quit_footer() {
|
||||
hr
|
||||
echo -e "| ${red}Q) Quit${default} |"
|
||||
echo -e "| ${red}Q) Quit${white} |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
back_footer(){
|
||||
function back_footer() {
|
||||
hr
|
||||
echo -e "| ${green}B) « Back${default} |"
|
||||
echo -e "| ${green}B) « Back${white} |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
back_help_footer(){
|
||||
function back_help_footer() {
|
||||
hr
|
||||
echo -e "| ${green}B) « Back${default} | ${yellow}H) Help [?]${default} |"
|
||||
echo -e "| ${green}B) « Back${white} | ${yellow}H) Help [?]${white} |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
print_header(){
|
||||
function print_header() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |"
|
||||
echo -e "| $(title_msg " Klipper Installation And Update Helper ") |"
|
||||
@@ -41,35 +54,17 @@ print_header(){
|
||||
bottom_border
|
||||
}
|
||||
|
||||
kiauh_update_msg(){
|
||||
top_border
|
||||
echo -e "|${green} New KIAUH update available! ${default}| "
|
||||
hr
|
||||
echo -e "|${green} View Changelog: https://git.io/JnmlX ${default}| "
|
||||
blank_line
|
||||
echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${default}| "
|
||||
echo -e "|${yellow} usually contain bugfixes, important changes or new ${default}| "
|
||||
echo -e "|${yellow} features. Please consider updating! ${default}| "
|
||||
bottom_border
|
||||
}
|
||||
|
||||
################################################################################
|
||||
#******************************************************************************#
|
||||
################################################################################
|
||||
### TODO: rework other menus to make use of the following functions too and make them more readable
|
||||
|
||||
do_action(){
|
||||
function do_action() {
|
||||
clear && print_header
|
||||
### $1 is the action the user wants to fire
|
||||
$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
|
||||
}
|
||||
|
||||
deny_action(){
|
||||
function deny_action() {
|
||||
clear && print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
print_error "Invalid command!"
|
||||
$1
|
||||
}
|
||||
|
||||
@@ -1,49 +1,62 @@
|
||||
install_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function install_ui() {
|
||||
top_border
|
||||
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| You need this menu usually only for installing | "
|
||||
echo -e "| all necessary dependencies for the various | "
|
||||
echo -e "| functions on a completely fresh system. | "
|
||||
echo -e "| You need this menu usually only for installing |"
|
||||
echo -e "| all necessary dependencies for the various |"
|
||||
echo -e "| functions on a completely fresh system. |"
|
||||
hr
|
||||
echo -e "| Firmware: | Touchscreen GUI: | "
|
||||
echo -e "| 1) [Klipper] | 5) [KlipperScreen] | "
|
||||
echo -e "| | | "
|
||||
echo -e "| Klipper API: | Other: | "
|
||||
echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
|
||||
echo -e "| | 7) [OctoPrint] | "
|
||||
echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | "
|
||||
echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | "
|
||||
echo -e "| 4) [Fluidd] | | "
|
||||
echo -e "| | Webcam: | "
|
||||
echo -e "| | 10) [MJPG-Streamer] | "
|
||||
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
|
||||
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
|
||||
echo -e "| 2) [Moonraker] | |"
|
||||
echo -e "| | Other: |"
|
||||
echo -e "| Klipper Webinterface: | 7) [PrettyGCode] |"
|
||||
echo -e "| 3) [Mainsail] | 8) [Telegram Bot] |"
|
||||
echo -e "| 4) [Fluidd] | |"
|
||||
echo -e "| | Webcam Streamer: |"
|
||||
echo -e "| Touchscreen GUI: | 9) [MJPG-Streamer] |"
|
||||
echo -e "| 5) [KlipperScreen] | |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
install_menu(){
|
||||
do_action "" "install_ui"
|
||||
function install_menu() {
|
||||
clear && print_header
|
||||
install_ui
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
do_action "klipper_setup_dialog" "install_ui";;
|
||||
do_action "select_klipper_python_version" "install_ui";;
|
||||
2)
|
||||
do_action "moonraker_setup_dialog" "install_ui";;
|
||||
3)
|
||||
do_action "install_webui mainsail" "install_ui";;
|
||||
do_action "install_mainsail" "install_ui";;
|
||||
4)
|
||||
do_action "install_webui fluidd" "install_ui";;
|
||||
do_action "install_fluidd" "install_ui";;
|
||||
5)
|
||||
do_action "install_klipperscreen" "install_ui";;
|
||||
6)
|
||||
do_action "dwc_setup_dialog" "install_ui";;
|
||||
7)
|
||||
do_action "octoprint_setup_dialog" "install_ui";;
|
||||
8)
|
||||
7)
|
||||
do_action "install_pgc_for_klipper" "install_ui";;
|
||||
8)
|
||||
do_action "telegram_bot_setup_dialog" "install_ui";;
|
||||
9)
|
||||
do_action "install_MoonrakerTelegramBot" "install_ui";;
|
||||
10)
|
||||
do_action "install_mjpg-streamer" "install_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
@@ -53,3 +66,33 @@ install_menu(){
|
||||
done
|
||||
install_menu
|
||||
}
|
||||
|
||||
function select_klipper_python_version() {
|
||||
top_border
|
||||
echo -e "| Please select the preferred Python version. | "
|
||||
echo -e "| The recommended version is Python 2.7. | "
|
||||
blank_line
|
||||
echo -e "| Installing Klipper with Python 3 is officially not | "
|
||||
echo -e "| recommended and should be considered as experimental. | "
|
||||
hr
|
||||
echo -e "| 1) [Python 2.7] (recommended) | "
|
||||
echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | "
|
||||
back_footer
|
||||
while true; do
|
||||
read -p "${cyan}###### Select Python version:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
select_msg "Python 2.7"
|
||||
klipper_setup_dialog "python2"
|
||||
break;;
|
||||
2)
|
||||
select_msg "Python 3.x"
|
||||
klipper_setup_dialog "python3"
|
||||
break;;
|
||||
B|b)
|
||||
clear; install_menu; break;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
@@ -1,89 +1,124 @@
|
||||
main_ui(){
|
||||
#[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function main_ui() {
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|"
|
||||
echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|"
|
||||
echo -e "| 1) [Install] | |"
|
||||
echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|"
|
||||
echo -e "| 3) [Remove] | |"
|
||||
echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|"
|
||||
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
|
||||
echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|"
|
||||
echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|"
|
||||
echo -e "| | |"
|
||||
echo -e "| | DWC2: $DWC2_STATUS|"
|
||||
echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|"
|
||||
echo -e "| 0) [Log-Upload] | Klipper: $(print_status "klipper")|"
|
||||
echo -e "| | Repo: $(print_klipper_repo)|"
|
||||
echo -e "| 1) [Install] | |"
|
||||
echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|"
|
||||
echo -e "| 3) [Remove] | |"
|
||||
echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|"
|
||||
echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|"
|
||||
echo -e "| | KlipperScreen: $(print_status "klipperscreen")|"
|
||||
echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|"
|
||||
echo -e "| | |"
|
||||
echo -e "| $(print_kiauh_version)| Octoprint: $(print_status "octoprint")|"
|
||||
quit_footer
|
||||
}
|
||||
|
||||
print_kiauh_version(){
|
||||
cd ${SRCDIR}/kiauh
|
||||
KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
|
||||
KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")"
|
||||
function get_kiauh_version() {
|
||||
local version
|
||||
cd "${KIAUH_SRCDIR}"
|
||||
version="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
kiauh_update_dialog(){
|
||||
kiauh_update_msg
|
||||
read -p "${cyan}Do you want to update now? (Y/n):${default} " yn
|
||||
while true; do
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
do_action "update_kiauh"
|
||||
break;;
|
||||
N|n|No|no) break;;
|
||||
*)
|
||||
deny_action "kiauh_update_dialog";;
|
||||
esac
|
||||
done
|
||||
function print_kiauh_version() {
|
||||
local version
|
||||
version="$(printf "%-18s" "$(get_kiauh_version)")"
|
||||
echo "${cyan}${version}${white}"
|
||||
}
|
||||
|
||||
main_menu(){
|
||||
print_header
|
||||
#print KIAUH update msg if update available
|
||||
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
|
||||
kiauh_update_dialog
|
||||
fi
|
||||
#check install status
|
||||
print_kiauh_version
|
||||
klipper_status
|
||||
moonraker_status
|
||||
dwc2_status
|
||||
fluidd_status
|
||||
mainsail_status
|
||||
octoprint_status
|
||||
klipperscreen_status
|
||||
MoonrakerTelegramBot_status
|
||||
print_branch
|
||||
print_msg && clear_msg
|
||||
main_ui
|
||||
function print_status() {
|
||||
local status component="${1}"
|
||||
status=$(get_"${component}"_status)
|
||||
|
||||
if [[ ${status} == "Not installed!" ]]; then
|
||||
status="${red}${status}${white}"
|
||||
elif [[ ${status} == "Incomplete!" ]]; then
|
||||
status="${yellow}${status}${white}"
|
||||
else
|
||||
status="${green}${status}${white}"
|
||||
fi
|
||||
|
||||
printf "%-28s" "${status}"
|
||||
}
|
||||
|
||||
function print_klipper_repo() {
|
||||
read_kiauh_ini
|
||||
|
||||
local repo klipper_status
|
||||
klipper_status=$(get_klipper_status)
|
||||
repo=$(echo "${custom_klipper_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//")
|
||||
repo="${repo^^}"
|
||||
|
||||
if [[ ${klipper_status} == "Not installed!" ]]; then
|
||||
repo="${red}-${white}"
|
||||
elif [[ -n ${repo} && ${repo} != "KLIPPER3D/KLIPPER" ]]; then
|
||||
repo="${cyan}custom${white}"
|
||||
else
|
||||
repo="${cyan}Klipper3d/klipper${white}"
|
||||
fi
|
||||
|
||||
printf "%-28s" "${repo}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function main_menu() {
|
||||
print_header && main_ui
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
"start klipper") do_action_service "start" "klipper"; main_ui;;
|
||||
"stop klipper") do_action_service "stop" "klipper"; main_ui;;
|
||||
"restart klipper") do_action_service "restart" "klipper"; main_ui;;
|
||||
"start moonraker") do_action_service "start" "moonraker"; main_ui;;
|
||||
"stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
|
||||
"restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
|
||||
"start dwc") do_action_service "start" "dwc"; main_ui;;
|
||||
"stop dwc") do_action_service "stop" "dwc"; main_ui;;
|
||||
"restart dwc") do_action_service "restart" "dwc"; main_ui;;
|
||||
"start octoprint") do_action_service "start" "octoprint"; main_ui;;
|
||||
"stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
|
||||
"restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
|
||||
update) do_action "update_kiauh" "main_ui";;
|
||||
0) do_action "upload_selection" "main_ui";;
|
||||
1) clear && install_menu && break;;
|
||||
2) clear && update_menu && break;;
|
||||
3) clear && remove_menu && break;;
|
||||
4) clear && advanced_menu && break;;
|
||||
5) clear && backup_menu && break;;
|
||||
6) clear && settings_menu && break;;
|
||||
0)clear && print_header
|
||||
upload_selection
|
||||
break;;
|
||||
1)clear && print_header
|
||||
install_menu
|
||||
break;;
|
||||
2) clear && print_header
|
||||
update_menu
|
||||
break;;
|
||||
3) clear && print_header
|
||||
remove_menu
|
||||
break;;
|
||||
4)clear && print_header
|
||||
advanced_menu
|
||||
break;;
|
||||
5)clear && print_header
|
||||
backup_menu
|
||||
break;;
|
||||
6)clear && print_header
|
||||
settings_menu
|
||||
break;;
|
||||
Q|q)
|
||||
echo -e "${green}###### Happy printing! ######${default}"; echo
|
||||
exit -1;;
|
||||
echo -e "${green}###### Happy printing! ######${white}"; echo
|
||||
exit 0;;
|
||||
*)
|
||||
deny_action "main_ui";;
|
||||
esac
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
remove_ui(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function remove_ui() {
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| Directories which remain untouched: | "
|
||||
echo -e "| --> Your printer configuration directory | "
|
||||
echo -e "| --> ~/kiauh-backups | "
|
||||
echo -e "| You need remove them manually if you wish so. | "
|
||||
echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |"
|
||||
hr
|
||||
echo -e "| Firmware: | Touchscreen GUI: | "
|
||||
echo -e "| 1) [Klipper] | 5) [KlipperScreen] | "
|
||||
echo -e "| | | "
|
||||
echo -e "| Klipper API: | Other: | "
|
||||
echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
|
||||
echo -e "| | 7) [OctoPrint] | "
|
||||
echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | "
|
||||
echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | "
|
||||
echo -e "| 4) [Fluidd] | | "
|
||||
echo -e "| | 10) [MJPG-Streamer] | "
|
||||
echo -e "| | 11) [NGINX] | "
|
||||
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
|
||||
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
|
||||
echo -e "| 2) [Moonraker] | |"
|
||||
echo -e "| | Webcam Streamer: |"
|
||||
echo -e "| Klipper Webinterface: | 7) [MJPG-Streamer] |"
|
||||
echo -e "| 3) [Mainsail] | |"
|
||||
echo -e "| 4) [Fluidd] | Other: |"
|
||||
echo -e "| | 8) [PrettyGCode] |"
|
||||
echo -e "| Touchscreen GUI: | 9) [Telegram Bot] |"
|
||||
echo -e "| 5) [KlipperScreen] | 10) [NGINX] |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
remove_menu(){
|
||||
function remove_menu() {
|
||||
do_action "" "remove_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
do_action "remove_klipper" "remove_ui";;
|
||||
2)
|
||||
@@ -37,16 +48,14 @@ remove_menu(){
|
||||
5)
|
||||
do_action "remove_klipperscreen" "remove_ui";;
|
||||
6)
|
||||
do_action "remove_dwc2" "remove_ui";;
|
||||
7)
|
||||
do_action "remove_octoprint" "remove_ui";;
|
||||
7)
|
||||
do_action "remove_mjpg-streamer" "remove_ui";;
|
||||
8)
|
||||
do_action "remove_prettygcode" "remove_ui";;
|
||||
9)
|
||||
do_action "remove_MoonrakerTelegramBot" "remove_ui";;
|
||||
do_action "remove_telegram_bot" "remove_ui";;
|
||||
10)
|
||||
do_action "remove_mjpg-streamer" "remove_ui";;
|
||||
11)
|
||||
do_action "remove_nginx" "remove_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
|
||||
@@ -1,44 +1,191 @@
|
||||
settings_ui(){
|
||||
source_kiauh_ini
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| ${red}Caution:${default} | "
|
||||
echo -e "| When you change the config folder, be aware that ALL | "
|
||||
echo -e "| Klipper and Moonraker services will be STOPPED, | "
|
||||
echo -e "| reconfigured and then restarted again. | "
|
||||
blank_line
|
||||
echo -e "| ${red}DO NOT change the folder during printing!${default} | "
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| ${cyan}● Current Klipper config folder:${default} | "
|
||||
printf "|%-55s|\n" " $klipper_cfg_loc"
|
||||
blank_line
|
||||
hr
|
||||
if [ -z $klipper_cfg_loc ]; then
|
||||
echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${default} | "
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function settings_ui() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
local custom_cfg_loc="${custom_klipper_cfg_loc}"
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
local ms_pre_rls="${mainsail_install_unstable}"
|
||||
local fl_pre_rls="${fluidd_install_unstable}"
|
||||
local bbu="${backup_before_update}"
|
||||
|
||||
### config location
|
||||
if [[ -z ${custom_cfg_loc} ]]; then
|
||||
custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}"
|
||||
else
|
||||
echo -e "| 1) Change config folder | "
|
||||
custom_cfg_loc="${cyan}${custom_cfg_loc}${white}"
|
||||
fi
|
||||
back_footer
|
||||
|
||||
### custom repository
|
||||
custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" )
|
||||
if [[ -z ${custom_repo} ]]; then
|
||||
custom_repo="${cyan}Klipper3D/klipper${white}"
|
||||
else
|
||||
custom_repo="${cyan}${custom_repo}${white}"
|
||||
fi
|
||||
|
||||
### custom repository branch
|
||||
if [[ -z ${custom_branch} ]]; then
|
||||
custom_branch="${cyan}master${white}"
|
||||
else
|
||||
custom_branch="${cyan}${custom_branch}${white}"
|
||||
fi
|
||||
|
||||
### webinterface stable toggle
|
||||
if [[ ${ms_pre_rls} == "false" ]]; then
|
||||
ms_pre_rls="${red}● ${ms_pre_rls}${white}"
|
||||
else
|
||||
ms_pre_rls="${green}● ${ms_pre_rls}${white}"
|
||||
fi
|
||||
|
||||
if [[ ${fl_pre_rls} == "false" ]]; then
|
||||
fl_pre_rls="${red}● ${fl_pre_rls}${white}"
|
||||
else
|
||||
fl_pre_rls="${green}● ${fl_pre_rls}${white}"
|
||||
fi
|
||||
|
||||
### backup before update toggle
|
||||
if [[ "${bbu}" == "false" ]]; then
|
||||
bbu="${red}● ${bbu}${white}"
|
||||
else
|
||||
bbu="${green}● ${bbu}${white}"
|
||||
fi
|
||||
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| Klipper: |"
|
||||
echo -e "| ● Config folder: |"
|
||||
printf "| %-60s|\n" "${custom_cfg_loc}"
|
||||
echo -e "| ● Repository: |"
|
||||
printf "| %-70s|\n" "${custom_repo} (${custom_branch})"
|
||||
hr
|
||||
echo -e "| Install unstable releases: |"
|
||||
printf "| Mainsail: %-29sFluidd: %-27s|\n" "${ms_pre_rls}" "${fl_pre_rls}"
|
||||
hr
|
||||
printf "| Backup before updating: %-42s|\n" "${bbu}"
|
||||
hr
|
||||
echo -e "| 1) Change Klipper config folder location |"
|
||||
echo -e "| 2) Set custom Klipper repository |"
|
||||
blank_line
|
||||
if [[ ${mainsail_install_unstable} == "false" ]]; then
|
||||
echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |"
|
||||
else
|
||||
echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |"
|
||||
fi
|
||||
if [[ ${fluidd_install_unstable} == "false" ]]; then
|
||||
echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |"
|
||||
else
|
||||
echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |"
|
||||
fi
|
||||
blank_line
|
||||
if [[ ${backup_before_update} == "false" ]]; then
|
||||
echo -e "| 5) ${green}Enable${white} automatic backups before updates |"
|
||||
else
|
||||
echo -e "| 5) ${red}Disable${white} automatic backups before updates |"
|
||||
fi
|
||||
back_help_footer
|
||||
}
|
||||
|
||||
settings_menu(){
|
||||
do_action "" "settings_ui"
|
||||
function show_settings_help() {
|
||||
local default_cfg="${cyan}${HOME}/klipper_config${white}"
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}Klipper config folder:${white} |"
|
||||
echo -e "| The location of your printer.cfg and all other config |"
|
||||
echo -e "| files that gets used during installation of Klipper |"
|
||||
echo -e "| and all other components which need that location. |"
|
||||
echo -e "| It is not recommended to change this location. |"
|
||||
echo -e "| Be advised, that negative side effects could occur. |"
|
||||
blank_line
|
||||
printf "| Default: %-55s|\n" "${default_cfg}"
|
||||
blank_line
|
||||
hr
|
||||
echo -e "| ${cyan}Install unstable releases:${white} |"
|
||||
echo -e "| If set to ${green}true${white}, KIAUH installs/updates the software |"
|
||||
echo -e "| with the latest, currently available release. |"
|
||||
echo -e "| ${yellow}This will include alpha, beta and rc releases!${white} |"
|
||||
blank_line
|
||||
echo -e "| If set to ${red}false${white}, KIAUH installs/updates the software |"
|
||||
echo -e "| with the most recent stable release. |"
|
||||
blank_line
|
||||
echo -e "| Default: ${red}false${white} |"
|
||||
blank_line
|
||||
hr
|
||||
echo -e "| ${cyan}Backup before updating:${white} |"
|
||||
echo -e "| If set to true, KIAUH will automatically create a |"
|
||||
echo -e "| backup from the corresponding component you are about |"
|
||||
echo -e "| to update before actually updating it, preserving the |"
|
||||
echo -e "| current state of the component in a safe location. |"
|
||||
echo -e "| All backups are stored in '~/kiauh_backups'. |"
|
||||
blank_line
|
||||
echo -e "| Default: ${red}false${white} |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
1)
|
||||
if [ ! -z $klipper_cfg_loc ]; then
|
||||
do_action "change_klipper_cfg_path" "settings_ui"
|
||||
else
|
||||
deny_action "settings_ui"
|
||||
fi;;
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
clear && print_header
|
||||
settings_menu
|
||||
break;;
|
||||
*)
|
||||
deny_action "show_settings_help";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function settings_menu() {
|
||||
clear && print_header
|
||||
settings_ui
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
1)
|
||||
clear && print_header
|
||||
change_klipper_cfg_folder
|
||||
settings_ui;;
|
||||
2)
|
||||
clear && print_header
|
||||
change_klipper_repo_menu
|
||||
settings_ui;;
|
||||
3)
|
||||
switch_mainsail_releasetype
|
||||
settings_menu;;
|
||||
4)
|
||||
switch_fluidd_releasetype
|
||||
settings_menu;;
|
||||
5)
|
||||
toggle_backup_before_update
|
||||
settings_menu;;
|
||||
B|b)
|
||||
clear
|
||||
main_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_settings_help
|
||||
break;;
|
||||
*)
|
||||
deny_action "settings_ui";;
|
||||
esac
|
||||
done
|
||||
settings_ui
|
||||
}
|
||||
|
||||
@@ -1,39 +1,49 @@
|
||||
update_ui(){
|
||||
ui_print_versions
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function update_ui() {
|
||||
top_border
|
||||
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | "
|
||||
echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| 0) $BB4U_STATUS| "
|
||||
hr
|
||||
echo -e "| a) [Update all] | | | "
|
||||
echo -e "| | Local Vers: | Remote Vers: | "
|
||||
echo -e "| Klipper/Klipper API: |---------------|--------------| "
|
||||
echo -e "| 1) [Klipper] | $LOCAL_COMMIT | $REMOTE_COMMIT | "
|
||||
echo -e "| 2) [Moonraker] | $LOCAL_MOONRAKER_COMMIT | $REMOTE_MOONRAKER_COMMIT | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| Klipper Webinterface: |---------------|--------------| "
|
||||
echo -e "| 3) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | "
|
||||
echo -e "| 4) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| Touchscreen GUI: |---------------|--------------| "
|
||||
echo -e "| 5) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| Other: |---------------|--------------| "
|
||||
echo -e "| 6) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | "
|
||||
echo -e "| 7) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | "
|
||||
echo -e "| 8) [PrettyGCode] | $LOCAL_PGC_COMMIT | $REMOTE_PGC_COMMIT | "
|
||||
echo -e "| 9) [Telegram Bot] | $LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT | $REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT | "
|
||||
echo -e "| |------------------------------| "
|
||||
echo -e "| 10) [System] | $DISPLAY_SYS_UPDATE | "
|
||||
echo -e "| a) [Update all] | | |"
|
||||
echo -e "| | Installed: | Latest: |"
|
||||
echo -e "| Klipper & API: |---------------|--------------|"
|
||||
echo -e "| 1) [Klipper] |$(compare_klipper_versions)|"
|
||||
echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)|"
|
||||
echo -e "| | | |"
|
||||
echo -e "| Klipper Webinterface: |---------------|--------------|"
|
||||
echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)|"
|
||||
echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)|"
|
||||
echo -e "| | | |"
|
||||
echo -e "| Touchscreen GUI: |---------------|--------------|"
|
||||
echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)|"
|
||||
echo -e "| | | |"
|
||||
echo -e "| Other: |---------------|--------------|"
|
||||
echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)|"
|
||||
echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)|"
|
||||
echo -e "| |------------------------------|"
|
||||
echo -e "| 8) [System] | $(check_system_updates) |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
update_menu(){
|
||||
read_bb4u_stat
|
||||
function update_menu() {
|
||||
unset update_arr
|
||||
do_action "" "update_ui"
|
||||
|
||||
local action
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
read -p "${cyan}####### Perform action:${white} " action
|
||||
case "${action}" in
|
||||
0)
|
||||
do_action "toggle_backups" "update_ui";;
|
||||
1)
|
||||
@@ -47,14 +57,10 @@ update_menu(){
|
||||
5)
|
||||
do_action "update_klipperscreen" "update_ui";;
|
||||
6)
|
||||
do_action "update_dwc2fk" "update_ui";;
|
||||
7)
|
||||
do_action "update_dwc2" "update_ui";;
|
||||
8)
|
||||
do_action "update_pgc_for_klipper" "update_ui";;
|
||||
9)
|
||||
do_action "update_MoonrakerTelegramBot" "update_ui";;
|
||||
10)
|
||||
7)
|
||||
do_action "update_telegram_bot" "update_ui";;
|
||||
8)
|
||||
do_action "update_system" "update_ui";;
|
||||
a)
|
||||
do_action "update_all" "update_ui";;
|
||||
@@ -66,3 +72,60 @@ update_menu(){
|
||||
done
|
||||
update_menu
|
||||
}
|
||||
|
||||
function update_all() {
|
||||
while true; do
|
||||
if (( ${#update_arr[@]} == 0 )); then
|
||||
print_confirm "Everything is already up-to-date!"
|
||||
echo; break
|
||||
fi
|
||||
|
||||
echo
|
||||
top_border
|
||||
echo -e "| The following installations will be updated: |"
|
||||
if [[ "${KLIPPER_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Klipper${white} |"
|
||||
fi
|
||||
if [[ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Moonraker${white} |"
|
||||
fi
|
||||
if [[ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Mainsail${white} |"
|
||||
fi
|
||||
if [[ "${FLUIDD_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● Fluidd${white} |"
|
||||
fi
|
||||
if [[ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● KlipperScreen${white} |"
|
||||
fi
|
||||
if [[ "${PGC_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● PrettyGCode for Klipper${white} |"
|
||||
fi
|
||||
if [[ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● MoonrakerTelegramBot${white} |"
|
||||
fi
|
||||
if [[ "${SYS_UPDATE_AVAIL}" = "true" ]]; then
|
||||
echo -e "| ${cyan}● System${white} |"
|
||||
fi
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
if (( ${#update_arr[@]} != 0 )); then
|
||||
read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
for update in "${update_arr[@]}"
|
||||
do
|
||||
#shellcheck disable=SC2250
|
||||
$update
|
||||
done
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -1,341 +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
|
||||
if [ "$PGC_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● PrettyGCode for Klipper${default} |"
|
||||
fi
|
||||
if [ "$MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● MoonrakerTelegramBot${default} |"
|
||||
fi
|
||||
if [ "$SYS_UPDATE_AVAIL" = "true" ]; then
|
||||
echo -e "| ${cyan}● System${default} |"
|
||||
fi
|
||||
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_log_paths(){
|
||||
### update services to make use of moonrakers new log_path option
|
||||
### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a
|
||||
shopt -s extglob # enable extended globbing
|
||||
source_kiauh_ini
|
||||
LPATH="${HOME}/klipper_logs"
|
||||
[ ! -d "$LPATH" ] && mkdir -p "$LPATH"
|
||||
FILE="$SYSTEMDDIR/$1?(-*([0-9])).service"
|
||||
for file in $(ls $FILE); do
|
||||
[ "$1" == "klipper" ] && LOG="klippy"
|
||||
[ "$1" == "moonraker" ] && LOG="moonraker"
|
||||
if [ ! "$(grep "\-l" $file)" ]; then
|
||||
status_msg "Updating $file ..."
|
||||
sudo sed -i -r "/ExecStart=/ s|$| -l $LPATH/$LOG.log|" $file
|
||||
ok_msg "$file updated!"
|
||||
elif [ "$(grep "\-l \/tmp\/$LOG" $file)" ]; then
|
||||
status_msg "Updating $file ..."
|
||||
sudo sed -i -r "/ExecStart=/ s|-l \/tmp\/$LOG|-l $LPATH/$LOG|" $file
|
||||
ok_msg "$file updated!"
|
||||
fi
|
||||
done
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# patch log_path entry if not found
|
||||
dir1="$klipper_cfg_loc"
|
||||
dir2="$klipper_cfg_loc/printer_*"
|
||||
for conf in $(find $dir1 $dir2 -name "moonraker.conf" 2> /dev/null); do
|
||||
if ! grep -q "log_path" $conf; then
|
||||
status_msg "Patching $conf"
|
||||
sed -i "/^config_path/a log_path: $LPATH" $conf
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
done
|
||||
|
||||
# create symlink for mainsail and fluidd nginx logs
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
|
||||
# create symlink for webcamd log
|
||||
if [ -f "/var/log/webcamd.log" ] && [ ! -L "$LPATH/webcamd.log" ]; then
|
||||
status_msg "Creating symlink for '/var/log/webcamd.log' ..."
|
||||
ln -s "/var/log/webcamd.log" "$LPATH"
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
shopt -u extglob # disable extended globbing
|
||||
}
|
||||
|
||||
migrate_custompios(){
|
||||
### migrate vanilla mainsailOS 0.4.0 / fluiddPI v1.13.0
|
||||
### and older to be in sync with newer releases
|
||||
WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd"
|
||||
MJPG_SERV_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/etc/systemd/system/webcamd.service"
|
||||
KL_SERV_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/klipper/filesystem/root/etc/systemd/system/klipper.service"
|
||||
NGINX_CFG1="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mainsail/filesystem/root/etc/nginx/conf.d/upstreams.conf"
|
||||
NGINX_CFG2="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mainsail/filesystem/root/etc/nginx/sites-available/mainsail"
|
||||
LOG_ROTATE_KLIPPER="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/klipper/filesystem/root/etc/logrotate.d/klipper"
|
||||
LOG_ROTATE_MOONRAKER="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/moonraker/filesystem/root/etc/logrotate.d/moonraker"
|
||||
LOG_ROTATE_WEBCAMD="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/etc/logrotate.d/webcamd"
|
||||
|
||||
if [ "$1" == "mainsail" ]; then
|
||||
OS_VER="MainsailOS"
|
||||
MACRO_CFG="mainsail.cfg"
|
||||
fi
|
||||
if [ "$1" == "fluiddpi" ]; then
|
||||
OS_VER="FluiddPi"
|
||||
MACRO_CFG="client_macros.cfg"
|
||||
fi
|
||||
if [ ! -f "/boot/$1.txt" ] || [ ! -f "/etc/init.d/klipper" ]; then
|
||||
# abort function if there is no sign of an old CustomPiOS anymore
|
||||
ERROR_MSG="No vanilla $OS_VER found. Aborting..." && return 0
|
||||
fi
|
||||
status_msg "Starting migration of $OS_VER... Please wait..."
|
||||
if [ -d "${HOME}/klipper_logs" ]; then
|
||||
# delete an existing klipper_logs directory
|
||||
# shouldn't be there in the first place if its a true vanilla CustomPiOS
|
||||
status_msg "Recreate '~/klipper_logs' directory..."
|
||||
rm -rf "${HOME}/klipper_logs" && mkdir "${HOME}/klipper_logs"
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -f "/boot/$1.txt" ]; then
|
||||
# replace old webcamd.service and webcamd
|
||||
status_msg "Migrating MJPG-Streamer..."
|
||||
sudo systemctl stop webcamd
|
||||
sudo rm -f "/etc/systemd/system/webcamd.service"
|
||||
sudo rm -f "/root/bin/webcamd"
|
||||
sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd"
|
||||
sudo wget $MJPG_SERV_SRC -O "/etc/systemd/system/webcamd.service"
|
||||
sudo sed -i "s/MainsailOS/$OS_VER/" "/etc/systemd/system/webcamd.service"
|
||||
sudo chmod +x "/usr/local/bin/webcamd"
|
||||
# move mainsail.txt/fluiddpi.txt from boot to klipper_config and rename it
|
||||
sudo mv "/boot/$1.txt" "${HOME}/klipper_config/webcam.txt"
|
||||
sudo chown pi:pi "${HOME}/klipper_config/webcam.txt"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart webcamd
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -f "/etc/init.d/klipper" ] && [ ! -f "/etc/systemd/system/klipper.service" ]; then
|
||||
# replace klipper SysVinit service with systemd service
|
||||
status_msg "Migrating Klipper Service..."
|
||||
sudo systemctl stop klipper
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo rm -f "/etc/init.d/klipper"
|
||||
sudo rm -f "/etc/default/klipper"
|
||||
sudo wget $KL_SERV_SRC -O "/etc/systemd/system/klipper.service"
|
||||
sudo systemctl enable klipper.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart klipper
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -f "/etc/systemd/system/moonraker.service" ]; then
|
||||
# update new log path in existing moonraker service
|
||||
status_msg "Updating Moonraker Service..."
|
||||
sudo systemctl stop moonraker
|
||||
update_log_paths "moonraker"
|
||||
sudo systemctl restart moonraker
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -f "/etc/nginx/conf.d/upstreams.conf" ]; then
|
||||
[ "$1" == "mainsail" ] && cfg="mainsail"
|
||||
[ "$1" == "fluiddpi" ] && cfg="fluidd"
|
||||
# update nginx upstreams.conf and mainsail/fluidd config file
|
||||
status_msg "Updating NGINX configurations..."
|
||||
sudo systemctl stop nginx
|
||||
sudo rm -f "/etc/nginx/conf.d/upstreams.conf"
|
||||
sudo rm -f "/etc/nginx/sites-available/$cfg"
|
||||
sudo wget $NGINX_CFG1 -O "/etc/nginx/conf.d/upstreams.conf"
|
||||
sudo wget $NGINX_CFG2 -O "/etc/nginx/sites-available/$cfg"
|
||||
sudo sed -i "s/mainsail/$cfg/g" "/etc/nginx/sites-available/$cfg"
|
||||
sudo systemctl restart nginx
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -f "${HOME}/klipper_config/$MACRO_CFG" ]; then
|
||||
# update macro files
|
||||
status_msg "Updating $MACRO_CFG ..."
|
||||
MACRO_CFG_PATH="${HOME}/klipper_config/$MACRO_CFG"
|
||||
sed -i "/SAVE_GCODE_STATE NAME=PAUSE_state/d" $MACRO_CFG_PATH
|
||||
sed -i "/RESTORE_GCODE_STATE NAME=PAUSE_state/d" $MACRO_CFG_PATH
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
if [ -d "/etc/logrotate.d" ]; then
|
||||
# download logrotate configs
|
||||
status_msg "Setting up logrotations..."
|
||||
sudo wget $LOG_ROTATE_KLIPPER -O "/etc/logrotate.d/klipper"
|
||||
sudo wget $LOG_ROTATE_MOONRAKER -O "/etc/logrotate.d/moonraker"
|
||||
sudo wget $LOG_ROTATE_WEBCAMD -O "/etc/logrotate.d/webcamd"
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
ok_msg "Migration done!"
|
||||
}
|
||||
|
||||
update_klipper(){
|
||||
do_action_service "stop" "klipper"
|
||||
if [ ! -d $KLIPPER_DIR ]; then
|
||||
cd ${HOME} && git clone $KLIPPER_REPO
|
||||
else
|
||||
bb4u "klipper"
|
||||
read_branch
|
||||
save_klipper_state
|
||||
status_msg "Updating $GET_BRANCH"
|
||||
cd $KLIPPER_DIR
|
||||
if [ "$DETACHED_HEAD" == "true" ]; then
|
||||
git checkout $GET_BRANCH
|
||||
unset DETACHED_HEAD
|
||||
fi
|
||||
### pull latest files from github
|
||||
git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_klipper_packages
|
||||
### install possible new python dependencies
|
||||
KLIPPER_REQ_TXT="$KLIPPER_DIR/scripts/klippy-requirements.txt"
|
||||
$KLIPPY_ENV/bin/pip install -r $KLIPPER_REQ_TXT
|
||||
fi
|
||||
update_log_paths "klipper"
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "klipper"
|
||||
}
|
||||
|
||||
update_dwc2fk(){
|
||||
do_action_service "stop" "dwc"
|
||||
bb4u "dwc2"
|
||||
if [ ! -d $DWC2FK_DIR ]; then
|
||||
cd ${HOME} && git clone $DWC2FK_REPO
|
||||
else
|
||||
cd $DWC2FK_DIR && git pull
|
||||
fi
|
||||
do_action_service "start" "dwc"
|
||||
}
|
||||
|
||||
update_dwc2(){
|
||||
bb4u "dwc2"
|
||||
download_dwc_webui
|
||||
}
|
||||
|
||||
update_mainsail(){
|
||||
bb4u "mainsail"
|
||||
status_msg "Updating Mainsail ..."
|
||||
mainsail_setup
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
}
|
||||
|
||||
update_fluidd(){
|
||||
bb4u "fluidd"
|
||||
status_msg "Updating Fluidd ..."
|
||||
fluidd_setup
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
}
|
||||
|
||||
update_moonraker(){
|
||||
do_action_service "stop" "moonraker"
|
||||
bb4u "moonraker"
|
||||
status_msg "Updating Moonraker ..."
|
||||
### pull latest files from github
|
||||
cd "$MOONRAKER_DIR" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_moonraker_packages
|
||||
### install possible new python dependencies
|
||||
MR_REQ_TXT="$MOONRAKER_DIR/scripts/moonraker-requirements.txt"
|
||||
"$MOONRAKER_ENV"/bin/pip install -r "$MR_REQ_TXT"
|
||||
update_log_paths "moonraker"
|
||||
|
||||
### required due to https://github.com/Arksine/moonraker/issues/349
|
||||
moonraker_polkit
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
update_klipperscreen(){
|
||||
stop_klipperscreen
|
||||
cd $KLIPPERSCREEN_DIR
|
||||
KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1)
|
||||
git pull origin master -q && ok_msg "Fetch successfull!"
|
||||
git checkout -f 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
|
||||
}
|
||||
|
||||
update_pgc_for_klipper(){
|
||||
PGC_DIR="${HOME}/pgcode"
|
||||
status_msg "Updating PrettyGCode for Klipper ..."
|
||||
cd $PGC_DIR && git pull
|
||||
ok_msg "Update complete!"
|
||||
}
|
||||
|
||||
update_MoonrakerTelegramBot(){
|
||||
source_kiauh_ini
|
||||
export klipper_cfg_loc
|
||||
stop_MoonrakerTelegramBot
|
||||
cd $MOONRAKER_TELEGRAM_BOT_DIR
|
||||
git pull
|
||||
./scripts/install.sh
|
||||
ok_msg "Update complete!"
|
||||
start_MoonrakerTelegramBot
|
||||
}
|
||||
|
||||
update_system(){
|
||||
status_msg "Updating System ..."
|
||||
sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y
|
||||
CONFIRM_MSG="Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}"
|
||||
print_msg && clear_msg
|
||||
}
|
||||
@@ -1,24 +1,39 @@
|
||||
accept_upload_conditions(){
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function accept_upload_conditions() {
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| The following function will help to quickly upload |"
|
||||
echo -e "| logs for debugging purposes. With confirming this |"
|
||||
echo -e "| dialog, you agree that during that process your logs |"
|
||||
echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |"
|
||||
hr
|
||||
echo -e "| ${red}PLEASE NOTE:${white} |"
|
||||
echo -e "| Be aware that logs can contain network information, |"
|
||||
echo -e "| private data like usernames, filenames, or other |"
|
||||
echo -e "| information you may not want to make public. |"
|
||||
blank_line
|
||||
echo -e "| Do ${red}NOT${white} use this function if you don't agree! |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${default} |"
|
||||
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
|
||||
read -p "${cyan}Do you accept? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
sed -i "/logupload_accepted=/s/false/true/" $INI_FILE
|
||||
sed -i "/logupload_accepted=/s/false/true/" "${INI_FILE}"
|
||||
clear && print_header && upload_selection
|
||||
;;
|
||||
N|n|No|no)
|
||||
@@ -27,78 +42,81 @@ accept_upload_conditions(){
|
||||
break
|
||||
;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
accept_upload_conditions;;
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
upload_selection(){
|
||||
source_kiauh_ini
|
||||
[ "$logupload_accepted" = "false" ] && accept_upload_conditions
|
||||
function upload_selection() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
### find all suitable logfiles for klipper
|
||||
logfiles=()
|
||||
klipper_logs="${HOME}/klipper_logs/klippy*.log"
|
||||
moonraker_logs="${HOME}/klipper_logs/moonraker*.log"
|
||||
local upload_agreed="${logupload_accepted}"
|
||||
[[ ${upload_agreed} == "false" ]] && accept_upload_conditions
|
||||
|
||||
if ls $klipper_logs 2>/dev/null 1>&2; then
|
||||
for kl_log in $(find $klipper_logs); do
|
||||
logfiles+=($kl_log)
|
||||
local logfiles
|
||||
local logs_dir="${KLIPPER_LOGS}"
|
||||
local webif_logs="/var/log/nginx"
|
||||
|
||||
function find_logfile() {
|
||||
local name=${1} location=${2}
|
||||
for log in $(find "${location}" -maxdepth 1 -regextype posix-extended -regex "${location}/${name}" | sort -g); do
|
||||
logfiles+=("${log}")
|
||||
done
|
||||
fi
|
||||
if ls $moonraker_logs 2>/dev/null 1>&2; then
|
||||
for mr_log in $(find $moonraker_logs); do
|
||||
logfiles+=($mr_log)
|
||||
done
|
||||
fi
|
||||
if ls /tmp/dwc2*.log 2>/dev/null 1>&2; then
|
||||
for dwc_log in $(find /tmp/dwc2*.log); do
|
||||
logfiles+=($dwc_log)
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
find_logfile "kiauh\.log" "/tmp"
|
||||
find_logfile "klippy(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
|
||||
find_logfile "moonraker(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
|
||||
find_logfile "telegram(-[0-9a-zA-Z]+)?\.log" "${logs_dir}"
|
||||
find_logfile "mainsail.*" "${webif_logs}"
|
||||
find_logfile "fluidd.*" "${webif_logs}"
|
||||
find_logfile "KlipperScreen.log" "/tmp"
|
||||
find_logfile "webcamd\.log(\.[0-9]+)?$" "/var/log"
|
||||
|
||||
### draw interface
|
||||
i=0
|
||||
local i=0
|
||||
top_border
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |"
|
||||
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| You can choose the following files for uploading: |"
|
||||
for log in ${logfiles[@]}; do
|
||||
printf "| $i) %-50s|\n" "${logfiles[$i]}"
|
||||
i=$((i + 1))
|
||||
echo -e "| You can choose the following logfiles for uploading: |"
|
||||
blank_line
|
||||
|
||||
for log in "${logfiles[@]}"; do
|
||||
log=${log//${HOME}/"~"}
|
||||
(( i < 10 )) && printf "| ${i}) %-50s|\n" "${log}"
|
||||
(( i >= 10 )) && printf "| ${i}) %-50s|\n" "${log}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local option re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please select:${default} " choice
|
||||
if [ $choice = "b" ] || [ $choice = "B" ]; then
|
||||
clear && main_menu && break
|
||||
elif [ $choice -le ${#logfiles[@]} ]; then
|
||||
upload_log "${logfiles[$choice]}"
|
||||
read -p "${cyan}###### Please select:${white} " option
|
||||
|
||||
if [[ ${option} =~ ${re} && ${option} -lt ${#logfiles[@]} ]]; then
|
||||
upload_log "${logfiles[${option}]}"
|
||||
upload_selection
|
||||
elif [[ ${option} == "B" || ${option} == "b" ]]; then
|
||||
return
|
||||
else
|
||||
clear && print_header
|
||||
ERROR_MSG="File not found!" && print_msg && clear_msg
|
||||
upload_selection
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
upload_log(){
|
||||
if [ -f "$1" ]; then
|
||||
clear && print_header
|
||||
status_msg "Uploading $1 ..."
|
||||
LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/')
|
||||
[ ! -z "$LINK" ] && ok_msg "$1 upload successfull!"
|
||||
echo -e "\n${cyan}###### Here is your link:${default}"
|
||||
echo -e ">>>>>> $LINK\n"
|
||||
unset LINK
|
||||
function upload_log() {
|
||||
local link
|
||||
clear && print_header
|
||||
status_msg "Uploading ${1} ..."
|
||||
link=$(curl -s -H "x-random;" --upload-file "${1}" 'http://paste.c-net.org/')
|
||||
|
||||
if [[ -n ${link} ]]; then
|
||||
ok_msg "${1} upload successfull!"
|
||||
echo -e "\n${cyan}###### Here is your link:${white}"
|
||||
echo -e ">>>>>> ${link}\n"
|
||||
else
|
||||
clear && print_header
|
||||
ERROR_MSG="File not found!" && print_msg && clear_msg
|
||||
upload_selection
|
||||
error_msg "Uploading failed!"
|
||||
fi
|
||||
}
|
||||
|
||||
654
scripts/utilities.sh
Normal file
654
scripts/utilities.sh
Normal file
@@ -0,0 +1,654 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/th33xitus/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#================================================#
|
||||
#=================== STARTUP ====================#
|
||||
#================================================#
|
||||
|
||||
function check_euid() {
|
||||
if [[ ${EUID} -eq 0 ]]; then
|
||||
echo -e "${red}"
|
||||
top_border
|
||||
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
|
||||
bottom_border
|
||||
echo -e "${white}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#============= MESSAGE FORMATTING ===============#
|
||||
#================================================#
|
||||
|
||||
function select_msg() {
|
||||
echo -e "${white} [➔] ${1}"
|
||||
}
|
||||
function status_msg() {
|
||||
echo -e "\n${magenta}###### ${1}${white}"
|
||||
}
|
||||
function ok_msg() {
|
||||
echo -e "${green}[✓ OK] ${1}${white}"
|
||||
}
|
||||
function warn_msg() {
|
||||
echo -e "${yellow}>>>>>> ${1}${white}"
|
||||
}
|
||||
function error_msg() {
|
||||
echo -e "${red}>>>>>> ${1}${white}"
|
||||
}
|
||||
function abort_msg() {
|
||||
echo -e "${red}<<<<<< ${1}${white}"
|
||||
}
|
||||
function title_msg() {
|
||||
echo -e "${cyan}${1}${white}"
|
||||
}
|
||||
|
||||
function print_error() {
|
||||
[[ -z ${1} ]] && return
|
||||
|
||||
echo -e "${red}"
|
||||
echo -e "#=======================================================#"
|
||||
echo -e " ${1} "
|
||||
echo -e "#=======================================================#"
|
||||
echo -e "${white}"
|
||||
}
|
||||
|
||||
function print_confirm() {
|
||||
[[ -z ${1} ]] && return
|
||||
|
||||
echo -e "${green}"
|
||||
echo -e "#=======================================================#"
|
||||
echo -e " ${1} "
|
||||
echo -e "#=======================================================#"
|
||||
echo -e "${white}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== LOGGING ====================#
|
||||
#================================================#
|
||||
|
||||
function timestamp() {
|
||||
date +"[%F %T]"
|
||||
}
|
||||
|
||||
function init_logfile() {
|
||||
local log="/tmp/kiauh.log"
|
||||
{
|
||||
echo -e "#================================================================#"
|
||||
echo -e "# New KIAUH session started on: $(date) #"
|
||||
echo -e "#================================================================#"
|
||||
echo -e "KIAUH $(get_kiauh_version)"
|
||||
echo -e "#================================================================#"
|
||||
} >> "${log}"
|
||||
}
|
||||
|
||||
function log_info() {
|
||||
local message="${1}" log="${LOGFILE}"
|
||||
echo -e "$(timestamp) [INFO]: ${message}" | tr -s " " >> "${log}"
|
||||
}
|
||||
|
||||
function log_warning() {
|
||||
local message="${1}" log="${LOGFILE}"
|
||||
echo -e "$(timestamp) [WARN]: ${message}" | tr -s " " >> "${log}"
|
||||
}
|
||||
|
||||
function log_error() {
|
||||
local message="${1}" log="${LOGFILE}"
|
||||
echo -e "$(timestamp) [ERR]: ${message}" | tr -s " " >> "${log}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=============== KIAUH SETTINGS =================#
|
||||
#================================================#
|
||||
|
||||
function read_kiauh_ini() {
|
||||
local func=${1}
|
||||
|
||||
if [[ ! -f ${INI_FILE} ]]; then
|
||||
log_warning "Reading from .kiauh.ini failed! File not found! Creating default ini file."
|
||||
init_ini
|
||||
fi
|
||||
|
||||
log_info "Reading from .kiauh.ini ... (${func})"
|
||||
source "${INI_FILE}"
|
||||
}
|
||||
|
||||
function init_ini() {
|
||||
### remove pre-version 4 ini files
|
||||
if [[ -f ${INI_FILE} ]] && ! grep -Eq "^# KIAUH v4\.0\.0$" "${INI_FILE}"; then
|
||||
rm "${INI_FILE}"
|
||||
fi
|
||||
|
||||
### initialize v4.0.0 ini file
|
||||
if [[ ! -f ${INI_FILE} ]]; then
|
||||
{
|
||||
echo -e "# File creation date: $(date)"
|
||||
echo -e "#=================================================#"
|
||||
echo -e "# KIAUH - Klipper Installation And Update Helper #"
|
||||
echo -e "# https://github.com/th33xitus/kiauh #"
|
||||
echo -e "# DO NOT edit this file! #"
|
||||
echo -e "#=================================================#"
|
||||
echo -e "# KIAUH v4.0.0"
|
||||
} >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then
|
||||
echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^logupload_accepted=." "${INI_FILE}"; then
|
||||
echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then
|
||||
echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then
|
||||
echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^custom_klipper_repo_branch=" "${INI_FILE}"; then
|
||||
echo -e "\ncustom_klipper_repo_branch=\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then
|
||||
echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^fluidd_install_unstable=" "${INI_FILE}"; then
|
||||
echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}"
|
||||
fi
|
||||
|
||||
fetch_webui_ports
|
||||
}
|
||||
|
||||
function change_klipper_cfg_folder() {
|
||||
local current_cfg_loc example_loc recommended_loc new_cfg_loc
|
||||
current_cfg_loc="$(get_klipper_cfg_dir)"
|
||||
example_loc=$(printf "%s/<your_config_folder>" "${HOME}")
|
||||
recommended_loc=$(printf "%s/klipper_config" "${HOME}")
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
top_border
|
||||
echo -e "| ${yellow}IMPORTANT:${white} |"
|
||||
echo -e "| Please enter the new path in the following format: |"
|
||||
printf "| ${cyan}%-51s${white} |\n" "${example_loc}"
|
||||
blank_line
|
||||
echo -e "| ${red}WARNING: ${white} |"
|
||||
echo -e "| ${red}There will be no validation checks! Make sure to set${white} |"
|
||||
echo -e "| ${red}a valid directory to prevent possible problems!${white} |"
|
||||
blank_line
|
||||
printf "| Recommended: ${cyan}%-38s${white} |\n" "${recommended_loc}"
|
||||
bottom_border
|
||||
echo
|
||||
echo -e "${cyan}###### Please set the new Klipper config directory:${white} "
|
||||
read -e -i "${current_cfg_loc}" -e new_cfg_loc
|
||||
echo
|
||||
read -p "${cyan}###### Set config directory to '${yellow}${new_cfg_loc}${cyan}' ? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
set_klipper_cfg_path "${current_cfg_loc}" "${new_cfg_loc}"
|
||||
print_confirm "New config directory set!"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function set_klipper_cfg_path() {
|
||||
local current_cfg_loc="${1}" new_cfg_loc="${2}"
|
||||
local instance klipper_services moonraker_services moonraker_configs
|
||||
|
||||
log_info "Function set_klipper_cfg_path invoked\nCurrent location: ${1}\nNew location: ${2}"
|
||||
### backup the old config dir
|
||||
backup_klipper_config_dir
|
||||
### write new location to .kiauh.ini
|
||||
sed -i "/^custom_klipper_cfg_loc=/d" "${INI_FILE}"
|
||||
sed -i '$a'"custom_klipper_cfg_loc=${new_cfg_loc}" "${INI_FILE}"
|
||||
status_msg "New directory was set to '${new_cfg_loc}'!"
|
||||
|
||||
### stop services
|
||||
do_action_service "stop" "klipper"
|
||||
do_action_service "stop" "moonraker"
|
||||
|
||||
### copy config files to new klipper config folder
|
||||
if [[ -n ${current_cfg_loc} && -d ${current_cfg_loc} ]]; then
|
||||
status_msg "Copy config files to '${new_cfg_loc}' ..."
|
||||
|
||||
if [[ ! -d ${new_cfg_loc} ]]; then
|
||||
log_info "Copy process started"
|
||||
mkdir -p "${new_cfg_loc}"
|
||||
cd "${current_cfg_loc}"
|
||||
cp -r -v ./* "${new_cfg_loc}"
|
||||
ok_msg "Done!"
|
||||
else
|
||||
log_warning "Copy process skipped, new config directory already exists and may not be empty!"
|
||||
warn_msg "New config directory already exists! Copy process skipped!"
|
||||
fi
|
||||
fi
|
||||
|
||||
klipper_services=$(klipper_systemd)
|
||||
|
||||
if [[ -n ${klipper_services} ]]; then
|
||||
status_msg "Re-writing Klipper services to use new config file location ..."
|
||||
|
||||
for service in ${klipper_services}; do
|
||||
if [[ ${service} = "/etc/systemd/system/klipper.service" ]]; then
|
||||
|
||||
if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then
|
||||
### single instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer\.cfg|CONFIG=${new_cfg_loc}/printer\.cfg|" "${service}"
|
||||
else
|
||||
### single instance klipper service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer\.cfg|" "${service}"
|
||||
fi
|
||||
|
||||
else
|
||||
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
|
||||
|
||||
if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then
|
||||
### multi instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer_${instance}\/printer\.cfg|CONFIG=${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
|
||||
else
|
||||
### multi instance klipper service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer_${instance}\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
|
||||
if [[ -n ${moonraker_services} ]]; then
|
||||
### handle multi moonraker instance service file
|
||||
status_msg "Re-writing Moonraker services to use new config file location ..."
|
||||
|
||||
for service in ${moonraker_services}; do
|
||||
if [[ ${service} = "/etc/systemd/system/moonraker.service" ]]; then
|
||||
|
||||
if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then
|
||||
### single instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/moonraker\.conf|_CONF=${new_cfg_loc}\/moonraker\.conf|" "${service}"
|
||||
else
|
||||
### single instance moonraker service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/moonraker\.conf| -c ${new_cfg_loc}\/moonraker\.conf|" "${service}"
|
||||
fi
|
||||
|
||||
else
|
||||
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
|
||||
|
||||
if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then
|
||||
### multi instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
|
||||
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/printer_${instance}\/moonraker\.conf|_CONF=${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
|
||||
else
|
||||
### multi instance moonraker service installed by kiauh v3
|
||||
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/printer_${instance}\/moonraker\.conf| -c ${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
### replace old file path with new one in moonraker.conf
|
||||
local loc
|
||||
for conf in ${moonraker_configs}; do
|
||||
loc=$(echo "${conf}" | rev | cut -d"/" -f2- | rev)
|
||||
sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${conf}"
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
### restart services
|
||||
do_action_service "restart" "klipper"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
function switch_mainsail_releasetype() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${mainsail_install_unstable}"
|
||||
|
||||
if [[ ${state} == "false" ]]; then
|
||||
sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}"
|
||||
log_info "mainsail_install_unstable changed (false -> true) "
|
||||
else
|
||||
sed -i '/mainsail_install_unstable=/s/true/false/' "${INI_FILE}"
|
||||
log_info "mainsail_install_unstable changed (true -> false) "
|
||||
fi
|
||||
}
|
||||
|
||||
function switch_fluidd_releasetype() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${fluidd_install_unstable}"
|
||||
|
||||
if [[ ${state} == "false" ]]; then
|
||||
sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}"
|
||||
log_info "fluidd_install_unstable changed (false -> true) "
|
||||
else
|
||||
sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}"
|
||||
log_info "fluidd_install_unstable changed (true -> false) "
|
||||
fi
|
||||
}
|
||||
|
||||
function toggle_backup_before_update() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${backup_before_update}"
|
||||
|
||||
if [[ ${state} = "false" ]]; then
|
||||
sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}"
|
||||
else
|
||||
sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}"
|
||||
fi
|
||||
}
|
||||
|
||||
function set_custom_klipper_repo() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
sed -i "/^custom_klipper_repo=/d" "${INI_FILE}"
|
||||
sed -i '$a'"custom_klipper_repo=${repo}" "${INI_FILE}"
|
||||
sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}"
|
||||
sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=============== HANDLE SERVICES ================#
|
||||
#================================================#
|
||||
|
||||
function do_action_service() {
|
||||
local services action=${1} service=${2}
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
|
||||
if [[ -n ${services} ]]; then
|
||||
for service in ${services}; do
|
||||
service=$(echo "${service}" | rev | cut -d"/" -f1 | rev)
|
||||
status_msg "${action^} ${service} ..."
|
||||
|
||||
if sudo systemctl "${action}" "${service}"; then
|
||||
log_info "${service}: ${action} > success"
|
||||
ok_msg "${action^} ${service} successfull!"
|
||||
else
|
||||
log_warning "${service}: ${action} > failed"
|
||||
warn_msg "${action^} ${service} failed!"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ DEPENDENCIES ==================#
|
||||
#================================================#
|
||||
|
||||
### returns 'true' if python version >= 3.7
|
||||
function python3_check() {
|
||||
local major minor passed
|
||||
|
||||
major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1)
|
||||
minor=$(python3 --version | cut -d"." -f2)
|
||||
|
||||
if (( major >= 3 && minor >= 7 )); then
|
||||
passed="true"
|
||||
else
|
||||
passed="false"
|
||||
fi
|
||||
|
||||
echo "${passed}"
|
||||
}
|
||||
|
||||
function dependency_check() {
|
||||
local dep=( "${@}" )
|
||||
local packages
|
||||
status_msg "Checking for the following dependencies:"
|
||||
|
||||
#check if package is installed, if not write its name into array
|
||||
for pkg in "${dep[@]}"; do
|
||||
echo -e "${cyan}● ${pkg} ${white}"
|
||||
[[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]] && \
|
||||
packages+=("${pkg}")
|
||||
done
|
||||
|
||||
#if array is not empty, install packages from array
|
||||
if (( ${#packages[@]} > 0 )); then
|
||||
status_msg "Installing the following dependencies:"
|
||||
for package in "${packages[@]}"; do
|
||||
echo -e "${cyan}● ${package} ${white}"
|
||||
done
|
||||
echo
|
||||
|
||||
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then
|
||||
ok_msg "Dependencies installed!"
|
||||
else
|
||||
error_msg "Installing dependencies failed!"
|
||||
return 1 # exit kiauh
|
||||
fi
|
||||
else
|
||||
ok_msg "Dependencies already met!"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
function fetch_webui_ports() {
|
||||
local port interfaces=("mainsail" "fluidd" "octoprint")
|
||||
|
||||
### read ports from possible installed interfaces and write them to ~/.kiauh.ini
|
||||
for interface in "${interfaces[@]}"; do
|
||||
if [[ -f "/etc/nginx/sites-available/${interface}" ]]; then
|
||||
port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2)
|
||||
if ! grep -Eq "${interface}_port" "${INI_FILE}"; then
|
||||
sed -i '$a'"${interface}_port=${port}" "${INI_FILE}"
|
||||
else
|
||||
sed -i "/^${interface}_port/d" "${INI_FILE}"
|
||||
sed -i '$a'"${interface}_port=${port}" "${INI_FILE}"
|
||||
fi
|
||||
else
|
||||
sed -i "/^${interface}_port/d" "${INI_FILE}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== SYSTEM =====================#
|
||||
#================================================#
|
||||
|
||||
function check_system_updates() {
|
||||
local updates_avail info_msg
|
||||
updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d")
|
||||
|
||||
if [[ -n ${updates_avail} ]]; then
|
||||
# add system updates to the update all array for the update all function in the updater
|
||||
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
|
||||
info_msg="${yellow}System upgrade available!${white}"
|
||||
else
|
||||
SYS_UPDATE_AVAIL="false"
|
||||
info_msg="${green}System up to date! ${white}"
|
||||
fi
|
||||
|
||||
echo "${info_msg}"
|
||||
}
|
||||
|
||||
function update_system() {
|
||||
status_msg "Updating System ..."
|
||||
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y; then
|
||||
print_confirm "Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}"
|
||||
else
|
||||
print_error "System update failed! Please watch for any errors printed above!"
|
||||
fi
|
||||
}
|
||||
|
||||
function check_usergroups() {
|
||||
local group_dialout group_tty
|
||||
|
||||
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
|
||||
group_dialout="false"
|
||||
fi
|
||||
|
||||
if grep -q "tty" </etc/group && ! grep -q "tty" <(groups "${USER}"); then
|
||||
group_tty="false"
|
||||
fi
|
||||
|
||||
if [[ ${group_dialout} == "false" || ${group_tty} == "false" ]] ; then
|
||||
top_border
|
||||
echo -e "| ${yellow}WARNING: Your current user is not in group:${white} |"
|
||||
[[ ${group_tty} == "false" ]] && \
|
||||
echo -e "| ${yellow}● tty${white} |"
|
||||
[[ ${group_dialout} == "false" ]] && \
|
||||
echo -e "| ${yellow}● dialout${white} |"
|
||||
blank_line
|
||||
echo -e "| It is possible that you won't be able to successfully |"
|
||||
echo -e "| connect and/or flash the controller board without |"
|
||||
echo -e "| your user being a member of that group. |"
|
||||
echo -e "| If you want to add the current user to the group(s) |"
|
||||
echo -e "| listed above, answer with 'Y'. Else skip with 'n'. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}INFO:${white} |"
|
||||
echo -e "| ${yellow}Relog required for group assignments to take effect!${white} |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
status_msg "Adding user '${USER}' to group(s) ..."
|
||||
if [[ ${group_tty} == "false" ]]; then
|
||||
sudo usermod -a -G tty "${USER}" && ok_msg "Group 'tty' assigned!"
|
||||
fi
|
||||
if [[ ${group_dialout} == "false" ]]; then
|
||||
sudo usermod -a -G dialout "${USER}" && ok_msg "Group 'dialout' assigned!"
|
||||
fi
|
||||
ok_msg "Remember to relog/restart this machine for the group(s) to be applied!"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function set_custom_hostname() {
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Changing the hostname of this machine allows you to |"
|
||||
echo -e "| access a webinterface that is configured for port 80 |"
|
||||
echo -e "| by simply typing '<hostname>.local' in the browser. |"
|
||||
echo -e "| |"
|
||||
echo -e "| E.g.: If you set the hostname to 'my-printer' you |"
|
||||
echo -e "| can open Mainsail / Fluidd / Octoprint by |"
|
||||
echo -e "| browsing to: http://my-printer.local |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
change_hostname
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function change_hostname() {
|
||||
local new_hostname regex="^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$"
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |"
|
||||
echo -e "| ${red}No special characters allowed!${white} |"
|
||||
echo -e "| ${red}No leading or trailing '-' allowed!${white} |"
|
||||
bottom_border
|
||||
|
||||
while true; do
|
||||
read -p "${cyan}###### Please set the new hostname:${white} " new_hostname
|
||||
|
||||
if [[ ${new_hostname} =~ ${regex} ]]; then
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want '${new_hostname}' to be the new hostname? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
set_hostname "${new_hostname}"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Skip hostname change ..."
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
warn_msg "'${new_hostname}' is not a valid hostname!"
|
||||
fi
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
function set_hostname() {
|
||||
local new_hostname=${1} current_date
|
||||
#check for dependencies
|
||||
local dep=(avahi-daemon)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
#create host file if missing or create backup of existing one with current date&time
|
||||
if [[ -f /etc/hosts ]]; then
|
||||
current_date=$(get_date)
|
||||
status_msg "Creating backup of hosts file ..."
|
||||
sudo cp "/etc/hosts" "/etc/hosts.${current_date}.bak"
|
||||
ok_msg "Backup done!"
|
||||
ok_msg "File:'/etc/hosts.${current_date}.bak'"
|
||||
else
|
||||
sudo touch /etc/hosts
|
||||
fi
|
||||
|
||||
#set new hostname in /etc/hostname
|
||||
status_msg "Setting hostname to '${new_hostname}' ..."
|
||||
status_msg "Please wait ..."
|
||||
sudo hostnamectl set-hostname "${new_hostname}"
|
||||
|
||||
#write new hostname to /etc/hosts
|
||||
status_msg "Writing new hostname to /etc/hosts ..."
|
||||
echo "127.0.0.1 ${new_hostname}" | sudo tee -a /etc/hosts &>/dev/null
|
||||
ok_msg "New hostname successfully configured!"
|
||||
ok_msg "Remember to reboot for the changes to take effect!"
|
||||
}
|
||||
|
||||
### this function takes in the full path of a systemd service file and returns
|
||||
### either the instance index or the custom name
|
||||
### input: /etc/systemd/system/klipper-name.service
|
||||
### returns: name
|
||||
function get_instance_name() {
|
||||
local instance=${1} name
|
||||
name=$(echo "${instance}" | rev | cut -d"/" -f1 | rev | cut -d"-" -f2 | cut -d"." -f1)
|
||||
echo "${name}"
|
||||
}
|
||||
Reference in New Issue
Block a user