diff --git a/kiauh.sh b/kiauh.sh index e505991..3e210a5 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -20,6 +20,7 @@ KLIPPER_DIR=${HOME}/klipper KLIPPY_ENV_DIR=${HOME}/klippy-env KLIPPER_SERVICE1=/etc/init.d/klipper KLIPPER_SERVICE2=/etc/default/klipper +KLIPPER_SERVICE3=/etc/systemd/system/klipper.service #nginx NGINX_SA=/etc/nginx/sites-available NGINX_SE=/etc/nginx/sites-enabled diff --git a/scripts/functions.sh b/scripts/functions.sh index b9213fe..03b051f 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -13,17 +13,24 @@ check_euid(){ locate_printer_cfg(){ unset PRINTER_CFG - status_msg "Locating printer.cfg via /etc/default/klipper ..." - if [ -f $KLIPPER_SERVICE2 ]; then + if [ -e $KLIPPER_SERVICE2 ]; then + status_msg "Locating printer.cfg via $KLIPPER_SERVICE2 ..." #reads /etc/default/klipper and gets the default printer.cfg location KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)" KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)" i=1 PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/default/klipper | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg") ok_msg "printer.cfg location: '$PRINTER_CFG'" + elif [ -e $KLIPPER_SERVICE3 ]; then + #reads /etc/systemd/system/klipper.service and gets the default printer.cfg location + KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)" + KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)" + i=1 + PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/systemd/system/klipper.service | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg") + ok_msg "printer.cfg location: '$PRINTER_CFG'" else PRINTER_CFG="" - warn_msg "Can't read /etc/default/klipper - File not found!" + warn_msg "Can't read printer.cfg location!" fi } diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 38d06d0..4747ffb 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -1,5 +1,5 @@ install_klipper(){ - if [ -e /etc/init.d/klipper ] && [ -e /etc/default/klipper ]; then + if [ -e $KLIPPER_SERVICE1 ] && [ -e $KLIPPER_SERVICE2 ] || [ -e $KLIPPER_SERVICE3 ]; then ERROR_MSG="Looks like Klipper is already installed!" else get_user_selections_klipper @@ -12,6 +12,37 @@ install_klipper(){ get_user_selections_klipper(){ status_msg "Initializing Klipper installation ..." + #let user choose to install systemd or init.d service + unset INST_SYSTEMD + unset INST_INITD + while true; do + echo + top_border + echo -e "| Do you want to install Klipper as: |" + echo -e "| 1) Init.d Service (default) |" + echo -e "| 2) Systemd Service |" + hr + echo -e "| Please use the appropriate option for your chosen |" + echo -e "| Linux distribution. If you are unsure what to select, |" + echo -e "| please do some research before. |" + hr + echo -e "| If you run Raspberry Pi OS, both options will work. |" + bottom_border + read -p "${cyan}###### Please choose:${default} " action + case "$action" in + 1|"") + INST_KLIPPER_INITD="true" + INST_KLIPPER_SYSTEMD="false" + break;; + 2) + INST_KLIPPER_INITD="false" + INST_KLIPPER_SYSTEMD="true" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done #ask user for building firmware while true; do echo @@ -61,14 +92,12 @@ klipper_setup(){ git clone $KLIPPER_REPO ok_msg "Klipper successfully cloned!" status_msg "Installing Klipper Service ..." - $KLIPPER_DIR/scripts/install-octopi.sh - ok_msg "Klipper installation complete!" - #create a klippy.log symlink in home-dir just for convenience - if [ ! -e ${HOME}/klippy.log ]; then - status_msg "Creating klippy.log Symlink ..." - ln -s /tmp/klippy.log ${HOME}/klippy.log - ok_msg "Symlink created!" + if [ "$INST_KLIPPER_INITD" = "true" ]; then + $KLIPPER_DIR/scripts/install-octopi.sh + elif [ "$INST_KLIPPER_SYSTEMD" = "true" ]; then + $KLIPPER_DIR/scripts/install-debian.sh fi + ok_msg "Klipper installation complete!" } flash_routine(){ diff --git a/scripts/remove.sh b/scripts/remove.sh index 95b4e85..550b753 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -2,6 +2,7 @@ remove_klipper(){ data_arr=( /etc/init.d/klipper /etc/default/klipper + /etc/systemd/system/klipper.service $KLIPPER_DIR $KLIPPY_ENV_DIR ${HOME}/klippy.log @@ -15,6 +16,13 @@ remove_klipper(){ sudo update-rc.d -f klipper remove ok_msg "Klipper Service removed!" fi + if [ -e /etc/systemd/system/klipper.service ]; then + status_msg "Removing Klipper Service ..." + sudo rm -rf /etc/systemd/system/klipper.service + sudo update-rc.d -f klipper remove + sudo systemctl daemon-reload + ok_msg "Klipper Service removed!" + fi if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then status_msg "Removing Klipper and klippy-env directory ..." rm -rf $KLIPPER_DIR $KLIPPY_ENV_DIR && ok_msg "Directories removed!" diff --git a/scripts/status.sh b/scripts/status.sh index f9e3d60..b4cd852 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -15,9 +15,10 @@ klipper_status(){ klipper_data=( $KLIPPER_DIR $KLIPPY_ENV_DIR - $KLIPPER_SERVICE1 - $KLIPPER_SERVICE2 + SERVICE ) + #remove the "SERVICE" entry from the klipper_data array if a klipper service is installed + [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && unset klipper_data[2] #count+1 for each found data-item from array for kd in "${klipper_data[@]}" do