initial commit of a bigger kiauh rework to make multi instance installations possible

This commit is contained in:
th33xitus
2021-01-07 15:26:19 +01:00
parent 61dfab5683
commit 08ae57d349
12 changed files with 873 additions and 310 deletions

View File

@@ -11,47 +11,162 @@ check_euid(){
fi fi
} }
locate_printer_cfg(){ check_klipper_cfg_path(){
unset PRINTER_CFG source_kiauh_ini
if [ -e $KLIPPER_SERVICE2 ]; then if [ -z $klipper_cfg_loc ]; then
status_msg "Locating printer.cfg via $KLIPPER_SERVICE2 ..." echo
#reads /etc/default/klipper and gets the default printer.cfg location top_border
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)" echo -e "| ${red}!!! WARNING !!!${default} |"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)" echo -e "| ${red}No Klipper configuration directory set!${default} |"
i=1 hr
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") echo -e "| Before we can continue, you need to specify a folder |"
ok_msg "printer.cfg location: '$PRINTER_CFG'" echo -e "| where your Klipper configuration(s) will be stored! |"
elif [ -e $KLIPPER_SERVICE3 ]; then bottom_border
status_msg "Locating printer.cfg via $KLIPPER_SERVICE3 ..." change_klipper_cfg_path
#reads /etc/systemd/system/klipper.service and gets the default printer.cfg location
KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
i=1
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/systemd/system/klipper.service | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg")
ok_msg "printer.cfg location: '$PRINTER_CFG'"
else
PRINTER_CFG=""
warn_msg "Can't read printer.cfg location!"
fi fi
} }
source_ini(){ change_klipper_cfg_path(){
source_kiauh_ini
old_klipper_cfg_loc="$klipper_cfg_loc"
while true; do
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"
### 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'!"
### backup the old config dir
backup_klipper_config_dir
### write new location to klipper and moonraker service
set_klipper_cfg_path
echo; ok_msg "Config directory changed!"
break;;
N|n|No|no)
echo -e "###### > No"
change_klipper_cfg_path
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
###? if path was changed in 'change_klipper_cfg_path', we need to edit the service files
###? and set the new path. after that, copy configs to new location and reload service units.
set_klipper_cfg_path(){
### stop services
klipper_service "stop" && moonraker_service "stop"
### copy config files to new location if old location exists
[ ! -d "$new_klipper_cfg_loc" ] && mkdir -p "$new_klipper_cfg_loc"
if [ ! -z "$old_klipper_cfg_loc" ]; then
status_msg "Copy files to '$new_klipper_cfg_loc'!"; echo
cd $old_klipper_cfg_loc
cp -avr * "$new_klipper_cfg_loc/" && ok_msg "Done!"
fi
### handle single klipper instance service file
if [ -f /etc/systemd/system/klipper.service ]; then
status_msg "Configuring Klipper for new path ..."
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer.cfg|$new_klipper_cfg_loc/printer.cfg|" /etc/systemd/system/klipper.service
ok_msg "OK!"
fi
### handle multi klipper instance service file
if [ "$(ls /etc/systemd/system/klipper-*.service)" > /dev/null 2>&1 ]; then
status_msg "Configuring Klipper for new path ..."
for service in $(find /etc/systemd/system/klipper-*.service); do
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer-|$new_klipper_cfg_loc/printer-|" $service
done
ok_msg "OK!"
fi
### handle single moonraker instance service and moonraker.conf file
if [ -f /etc/systemd/system/moonraker.service ]; then
status_msg "Configuring Moonraker for new path ..."
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/moonraker.conf|$new_klipper_cfg_loc/moonraker.conf|" /etc/systemd/system/moonraker.service
### replace old file path with new one in moonraker.conf
sed -i "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
ok_msg "OK!"
fi
### handle multi moonraker instance service file
if [ "$(ls /etc/systemd/system/moonraker-*.service)" > /dev/null 2>&1 ]; then
status_msg "Configuring Moonraker for new path ..."
for service in $(find /etc/systemd/system/moonraker-*.service); do
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/moonraker-|$new_klipper_cfg_loc/moonraker-|" $service
done
### replace old file path with new one in moonraker-*.conf
for moonraker_conf in $(find $new_klipper_cfg_loc/moonraker-*.conf); do
sed -i "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $moonraker_conf
done
ok_msg "OK!"
fi
### reloading units
sudo systemctl daemon-reload
### restart services
klipper_service "stop" && moonraker_service "stop"
}
source_kiauh_ini(){
source ${SRCDIR}/kiauh/kiauh.ini source ${SRCDIR}/kiauh/kiauh.ini
} }
start_klipper(){ klipper_service(){
status_msg "Starting Klipper Service ..." ### set a variable for the ok and status messages
sudo systemctl start klipper && ok_msg "Klipper Service started!" [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
if [ "$(ls /etc/systemd/system/klipper-*.service)" > /dev/null 2>&1 ]; then
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Klipper Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 klipper-$INSTANCE && ok_msg "Klipper Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper.service")" ]; then
status_msg "$ACTION2 Klipper Service ..."
sudo systemctl $1 klipper && ok_msg "Klipper Service $ACTION1!"
fi
} }
stop_klipper(){ moonraker_service(){
status_msg "Stopping Klipper Service ..." ### set a variable for the ok and status messages
sudo systemctl stop klipper && ok_msg "Klipper Service stopped!" [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
} [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
restart_klipper(){ if [ "$(ls /etc/systemd/system/moonraker-*.service)" > /dev/null 2>&1 ]; then
status_msg "Restarting Klipper Service ..." INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l)
sudo systemctl restart klipper && ok_msg "Klipper Service restarted!" INSTANCE=1
status_msg "$ACTION2 $INSTANCE_COUNT Moonraker Services ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
sudo systemctl $1 moonraker-$INSTANCE && ok_msg "Moonraker Service #$INSTANCE $ACTION1!"
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker.service")" ]; then
status_msg "$ACTION2 Moonraker Service ..."
sudo systemctl $1 moonraker && ok_msg "Moonraker Service $ACTION1!"
fi
} }
start_dwc(){ start_dwc(){
@@ -64,21 +179,6 @@ stop_dwc(){
sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!" sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!"
} }
start_moonraker(){
status_msg "Starting Moonraker Service ..."
sudo systemctl start moonraker && ok_msg "Moonraker Service started!"
}
stop_moonraker(){
status_msg "Stopping Moonraker Service ..."
sudo systemctl stop moonraker && ok_msg "Moonraker Service stopped!"
}
restart_moonraker(){
status_msg "Restarting Moonraker Service ..."
sudo systemctl restart moonraker && ok_msg "Moonraker Service restarted!"
}
start_octoprint(){ start_octoprint(){
status_msg "Starting OctoPrint Service ..." status_msg "Starting OctoPrint Service ..."
sudo systemctl start octoprint && ok_msg "OctoPrint Service started!" sudo systemctl start octoprint && ok_msg "OctoPrint Service started!"
@@ -252,8 +352,8 @@ setup_gcode_shell_command(){
} }
install_gcode_shell_command(){ install_gcode_shell_command(){
stop_klipper klipper_service "stop"
status_msg "Copy 'gcode_shell_command.py' to $KLIPPER_DIR/klippy/extras" status_msg "Copy 'gcode_shell_command.py' to $KLIKLIPPER_DIRPPER/klippy/extras"
cp ${HOME}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras cp ${HOME}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
echo echo
while true; do while true; do
@@ -272,7 +372,7 @@ install_gcode_shell_command(){
esac esac
done done
ok_msg "Shell command extension installed!" ok_msg "Shell command extension installed!"
restart_klipper klipper_service "restart"
} }
create_minimal_cfg(){ create_minimal_cfg(){
@@ -374,4 +474,8 @@ init_ini(){
if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then
echo -e "\nlogupload_accepted=false\c" >> $INI_FILE echo -e "\nlogupload_accepted=false\c" >> $INI_FILE
fi fi
###add empty klipper config path if missing
if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then
echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE
fi
} }

View File

@@ -7,7 +7,7 @@ install_dwc2(){
#ask user for customization #ask user for customization
get_user_selections_dwc2 get_user_selections_dwc2
#dwc2 main installation #dwc2 main installation
stop_klipper klipper_service "stop"
dwc2_setup dwc2_setup
#setup config #setup config
setup_printer_config_dwc2 setup_printer_config_dwc2
@@ -16,7 +16,7 @@ install_dwc2(){
set_nginx_cfg "dwc2" set_nginx_cfg "dwc2"
set_hostname set_hostname
#after install actions #after install actions
restart_klipper klipper_service "restart"
else else
ERROR_MSG=" Please install Klipper first!\n Skipping..." ERROR_MSG=" Please install Klipper first!\n Skipping..."
fi fi

View File

@@ -1,103 +1,207 @@
install_klipper(){ #install_klipper(){
if [ -e $KLIPPER_SERVICE1 ] && [ -e $KLIPPER_SERVICE2 ] || [ -e $KLIPPER_SERVICE3 ]; then # get_user_selections_klipper
ERROR_MSG="Looks like Klipper is already installed!" # klipper_setup
else # build_fw
get_user_selections_klipper # flash_mcu
klipper_setup # write_printer_usb
build_fw #}
flash_mcu
write_printer_usb ### base variables
SYSTEMDDIR="/etc/systemd/system"
KLIPPY_ENV="${HOME}/klippy-env"
KLIPPER_DIR="${HOME}/klipper"
klipper_setup_dialog(){
status_msg "Initializing Klipper installation ..."
### check for existing klipper service installations
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
ERROR_MSG="At least one Klipper service is already installed!" && return 0
fi fi
### initial printer.cfg path check
check_klipper_cfg_path
### ask for amount of instances to create
while true; do
echo
read -p "${cyan}###### How many Klipper instances do you want to set up?:${default} " INSTANCE_COUNT
echo
if [ $INSTANCE_COUNT == 1 ]; then
read -p "${cyan}###### Create $INSTANCE_COUNT single instance? (Y/n):${default} " yn
else
read -p "${cyan}###### Create $INSTANCE_COUNT instances? (Y/n):${default} " yn
fi
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT Klipper instances ..."
klipper_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting Klipper setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
} }
get_user_selections_klipper(){ install_klipper_packages(){
status_msg "Initializing Klipper installation ..." ### Packages for python cffi
#let user choose to install systemd or init.d service PKGLIST="python-virtualenv virtualenv python-dev libffi-dev build-essential"
while true; do ### kconfig requirements
echo PKGLIST="${PKGLIST} libncurses-dev"
top_border ### hub-ctrl
echo -e "| Do you want to install Klipper as: |" PKGLIST="${PKGLIST} libusb-dev"
echo -e "| 1) Init.d Service (default) |" ### AVR chip installation and building
echo -e "| 2) Systemd Service |" PKGLIST="${PKGLIST} avrdude gcc-avr binutils-avr avr-libc"
hr ### ARM chip installation and building
echo -e "| Please use the appropriate option for your chosen |" PKGLIST="${PKGLIST} stm32flash libnewlib-arm-none-eabi"
echo -e "| Linux distribution. If you are unsure what to select, |" PKGLIST="${PKGLIST} gcc-arm-none-eabi binutils-arm-none-eabi libusb-1.0"
echo -e "| please do some research before. |" ### dbus requirement for DietPi
hr PKGLIST="${PKGLIST} dbus"
echo -e "| If you run Raspberry Pi OS, both options will work. |"
bottom_border ### Update system package info
read -p "${cyan}###### Please choose:${default} " action status_msg "Running apt-get update..."
case "$action" in sudo apt-get update
1|"")
echo -e "###### > 1) Init.d" ### Install desired packages
INST_KLIPPER_INITD="true" status_msg "Installing packages..."
INST_KLIPPER_SYSTEMD="false" sudo apt-get install --yes ${PKGLIST}
break;; }
2)
echo -e "###### > 2) Systemd" create_klipper_virtualenv(){
INST_KLIPPER_INITD="false" status_msg "Installing python virtual environment..."
INST_KLIPPER_SYSTEMD="true" # Create virtualenv if it doesn't already exist
break;; [ ! -d ${KLIPPY_ENV} ] && virtualenv -p python2 ${KLIPPY_ENV}
*) # Install/update dependencies
print_unkown_cmd ${KLIPPY_ENV}/bin/pip install -r ${KLIPPER_DIR}/scripts/klippy-requirements.txt
print_msg && clear_msg;; }
esac
done create_single_klipper_startscript(){
#ask user for building firmware ### create systemd service file
while true; do sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << EOF
echo #Systemd service file for klipper
read -p "${cyan}###### Do you want to build the Firmware? (y/N):${default} " yn [Unit]
case "$yn" in Description=Starts klipper on startup
Y|y|Yes|yes) After=network.target
echo -e "###### > Yes" [Install]
BUILD_FIRMWARE="true" WantedBy=multi-user.target
break;; [Service]
N|n|No|no|"") Type=simple
echo -e "###### > No" User=$USER
BUILD_FIRMWARE="false" RemainAfterExit=yes
break;; ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
*) Restart=always
print_unkown_cmd RestartSec=10
print_msg && clear_msg;; EOF
esac }
done
#ask user for flashing mcu create_multi_klipper_startscript(){
while true; do ### create multi instance systemd service file
echo sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << EOF
read -p "${cyan}###### Do you want to flash your MCU? (y/N):${default} " yn #Systemd service file for klipper
case "$yn" in [Unit]
Y|y|Yes|yes) Description=Starts klipper instance $INSTANCE on startup
echo -e "###### > Yes" After=network.target
FLASH_FIRMWARE="true" [Install]
flash_routine WantedBy=multi-user.target
break;; [Service]
N|n|No|no|"") Type=simple
echo -e "###### > No" User=$USER
FLASH_FIRMWARE="false" RemainAfterExit=yes
break;; ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -I ${TMP_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
*) Restart=always
print_unkown_cmd RestartSec=10
print_msg && clear_msg;; EOF
esac
done
} }
klipper_setup(){ klipper_setup(){
#check for dependencies ### get printer config directory
dep=(git dbus) source_kiauh_ini
dependency_check PRINTER_CFG_LOC="$klipper_cfg_loc"
#execute operation
### clone klipper
cd ${HOME} cd ${HOME}
status_msg "Cloning Klipper repository ..." status_msg "Downloading Klipper ..."
[ -d $KLIPPER_DIR ] && rm -rf $KLIPPER_DIR
git clone $KLIPPER_REPO git clone $KLIPPER_REPO
ok_msg "Klipper successfully cloned!" status_msg "Download complete!"
status_msg "Installing Klipper Service ..."
if [ "$INST_KLIPPER_INITD" = "true" ]; then ### install klipper dependencies and create python virtualenv
$KLIPPER_DIR/scripts/install-octopi.sh status_msg "Installing dependencies ..."
elif [ "$INST_KLIPPER_SYSTEMD" = "true" ]; then install_klipper_packages
$KLIPPER_DIR/scripts/install-debian.sh create_klipper_virtualenv
### create sdcard folder
[ ! -d ${HOME}/sdcard ] && mkdir -p ${HOME}/sdcard
### create config folder
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
### create klipper instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_klipper_instance
else
create_multi_klipper_instance
fi fi
ok_msg "Klipper installation complete!" }
create_single_klipper_instance(){
status_msg "Setting up 1 Klipper instance ..."
### single instance variables
KLIPPER_LOG=/tmp/klippy.log
KLIPPY_UDS=/tmp/klippy_uds
PRINTER_CFG="$PRINTER_CFG_LOC/printer.cfg"
### create instance
status_msg "Creating single Klipper instance ..."
status_msg "Installing system start script ..."
create_single_klipper_startscript
### enable instance
sudo systemctl enable klipper.service
ok_msg "Single Klipper instance created!"
### launching instance
status_msg "Launching Klipper instance ..."
sudo systemctl start klipper
### confirm message
ok_msg "Single Klipper instance has been set up!\n"
}
create_multi_klipper_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of Klipper ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
KLIPPER_LOG=/tmp/klippy-$INSTANCE.log
KLIPPY_UDS=/tmp/klippy_uds-$INSTANCE
TMP_PRINTER=/tmp/printer-$INSTANCE
PRINTER_CFG="$PRINTER_CFG_LOC/printer-$INSTANCE.cfg"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_klipper_startscript
### enable instance
sudo systemctl enable klipper-$INSTANCE.service
ok_msg "Klipper instance $INSTANCE created!"
### launching instance
status_msg "Launching Klipper instance $INSTANCE ..."
sudo systemctl start klipper-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
ok_msg "$INSTANCE_COUNT Klipper instances have been set up!\n"
} }
flash_routine(){ flash_routine(){
@@ -138,14 +242,14 @@ flash_routine(){
flash_mcu(){ flash_mcu(){
if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then
stop_klipper klipper_service "stop"
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
warn_msg "Flashing failed!" warn_msg "Flashing failed!"
warn_msg "Please read the console output above!" warn_msg "Please read the console output above!"
else else
ok_msg "Flashing successfull!" ok_msg "Flashing successfull!"
fi fi
start_klipper klipper_service "start"
fi fi
} }

View File

@@ -1,3 +1,317 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
MOONRAKER_ENV="${HOME}/moonraker-env"
MOONRAKER_DIR="${HOME}/moonraker"
moonraker_setup_dialog(){
status_msg "Initializing Moonraker installation ..."
### check for existing moonraker service installations
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
ERROR_MSG="At least one Moonraker service is already installed!" && return 0
fi
### check for existing klipper service installations
if [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
fi
### count amount of klipper services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
INSTANCE_COUNT=1
else
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
fi
### initial moonraker.conf path check
check_klipper_cfg_path
### ask for amount of instances to create
while true; do
echo
top_border
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
echo -e "| You need one Moonraker instance per Klipper instance. | "
bottom_border
echo
read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
status_msg "Creating $INSTANCE_COUNT Moonraker instances ..."
moonraker_setup
break;;
N|n|No|no)
echo -e "###### > No"
warn_msg "Exiting Moonraker setup ..."
echo
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
install_moonraker_packages(){
PKGLIST="python3-virtualenv python3-dev nginx libopenjp2-7 python3-libgpiod"
### Update system package info
status_msg "Running apt-get update..."
sudo apt-get update
### Install desired packages
status_msg "Installing packages..."
sudo apt-get install --yes ${PKGLIST}
}
create_moonraker_virtualenv(){
status_msg "Installing python virtual environment..."
### If venv exists and user prompts a rebuild, then do so
if [ -d ${MOONRAKER_ENV} ] && [ $REBUILD_ENV = "y" ]; then
status_msg "Removing old virtualenv"
rm -rf ${MOONRAKER_ENV}
fi
[ ! -d ${MOONRAKER_ENV} ] && virtualenv -p /usr/bin/python3 --system-site-packages ${MOONRAKER_ENV}
### Install/update dependencies
${MOONRAKER_ENV}/bin/pip install -r ${MOONRAKER_DIR}/scripts/moonraker-requirements.txt
}
create_single_moonraker_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/moonraker.service" << EOF
#Systemd service file for moonraker
[Unit]
Description=Starts Moonraker on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=$USER
RemainAfterExit=yes
ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF}
Restart=always
RestartSec=10
EOF
}
create_multi_moonraker_startscript(){
### create multi instance systemd service file
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/moonraker-$INSTANCE.service" << EOF
#Systemd service file for moonraker
[Unit]
Description=Starts Moonraker instance $INSTANCE on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=$USER
RemainAfterExit=yes
ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF}
Restart=always
RestartSec=10
EOF
}
moonraker_setup(){
### get printer config directory
source_kiauh_ini
MOONRAKER_CONF_LOC="$klipper_cfg_loc"
### clone moonraker
status_msg "Downloading Moonraker ..."
### force remove existing moonraker dir
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
### clone into fresh moonraker dir
cd ${HOME} && git clone $MOONRAKER_REPO
status_msg "Download complete!"
### install klipper dependencies and create python virtualenv
status_msg "Installing dependencies ..."
install_moonraker_packages
create_moonraker_virtualenv
### create moonraker.conf folder
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
### create moonraker.confs
moonraker_conf_creation
### create moonraker instances
INSTANCE=1
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
create_single_moonraker_instance
else
create_multi_moonraker_instance
fi
}
create_single_moonraker_instance(){
status_msg "Setting up 1 Moonraker instance ..."
### single instance variables
MOONRAKER_LOG=/tmp/moonraker.log
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker.conf"
### create instance
status_msg "Creating single Moonraker instance ..."
status_msg "Installing system start script ..."
create_single_moonraker_startscript
### enable instance
sudo systemctl enable moonraker.service
ok_msg "Single Moonraker instance created!"
### launching instance
status_msg "Launching Moonraker instance ..."
sudo systemctl start moonraker
### confirm message
ok_msg "Single Moonraker instance has been set up!\n"
}
create_multi_moonraker_instance(){
status_msg "Setting up $INSTANCE_COUNT instances of Moonraker ..."
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf"
### create instance
status_msg "Creating instance #$INSTANCE ..."
create_multi_moonraker_startscript
### enable instance
sudo systemctl enable moonraker-$INSTANCE.service
ok_msg "Moonraker instance $INSTANCE created!"
### launching instance
status_msg "Launching Moonraker instance $INSTANCE ..."
sudo systemctl start moonraker-$INSTANCE
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!\n"
}
moonraker_conf_creation(){
### default moonraker port
PORT=7125
### get printer and moonraker config directory
source_kiauh_ini
PRINTER_CFG_LOC="$klipper_cfg_loc"
MOONRAKER_CONF_LOC="$klipper_cfg_loc"
### reset instances back to 1 again
INSTANCE=1
### create moonraker.conf
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
status_msg "Creating moonraker.conf in $MOONRAKER_CONF_LOC"
if [ ! -f $MOONRAKER_CONF_LOC/moonraker.conf ]; then
create_single_moonraker_conf && ok_msg "moonraker.conf created!"
else
warn_msg "There is already a file called 'moonraker.conf'!"
warn_msg "Skipping..."
fi
else
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
status_msg "Creating moonraker-$INSTANCE.conf in $MOONRAKER_CONF_LOC"
if [ ! -f $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf ]; then
PORT=$(expr $PORT + $INSTANCE - 1)
create_multi_moonraker_conf && ok_msg "moonraker-$INSTANCE.conf created!"
else
warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!"
warn_msg "Skipping..."
fi
INSTANCE=$(expr $INSTANCE + 1)
done
fi
}
create_single_moonraker_conf(){
HOSTNAME=$(hostname -I | cut -d" " -f1)
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF
[server]
host: 0.0.0.0
port: $PORT
klippy_uds_address: /tmp/klippy_uds
enable_debug_logging: True
config_path: $PRINTER_CFG_LOC
[authorization]
enabled: True
api_key_file: ~/.moonraker_api_key
trusted_clients:
127.0.0.1
cors_domains:
http://*.local
http://app.fluidd.xyz
https://app.fluidd.xyz
http://$HOSTNAME:*
[update_manager]
#client_repo:
#client_path:
MOONRAKERCONF
}
create_multi_moonraker_conf(){
HOSTNAME=$(hostname -I | cut -d" " -f1)
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" << MOONRAKERCONF
[server]
host: 0.0.0.0
port: $PORT
klippy_uds_address: /tmp/klippy_uds-$INSTANCE
enable_debug_logging: True
config_path: $PRINTER_CFG_LOC
[authorization]
enabled: True
api_key_file: ~/.moonraker_api_key
trusted_clients:
127.0.0.1
$HOSTNAME
cors_domains:
http://*.local
http://app.fluidd.xyz
https://app.fluidd.xyz
http://$HOSTNAME:*
[update_manager]
#client_repo:
#client_path:
MOONRAKERCONF
}
install_moonraker(){ install_moonraker(){
python3_check python3_check
if [ $py_chk_ok = "true" ]; then if [ $py_chk_ok = "true" ]; then
@@ -18,7 +332,7 @@ install_moonraker(){
disable_octoprint disable_octoprint
#after install actions #after install actions
restart_moonraker restart_moonraker
restart_klipper klipper_service "restart"
else else
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
print_msg && clear_msg print_msg && clear_msg
@@ -254,48 +568,28 @@ get_user_selections_moonraker(){
############################################################# #############################################################
############################################################# #############################################################
moonraker_setup(){ #moonraker_setup(){
dep=(wget curl unzip dfu-util) # dep=(wget curl unzip dfu-util)
dependency_check # dependency_check
status_msg "Downloading Moonraker ..." # status_msg "Downloading Moonraker ..."
#force remove existing moonraker dir # #force remove existing moonraker dir
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR # [ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
#clone into fresh moonraker dir # #clone into fresh moonraker dir
cd ${HOME} && git clone $MOONRAKER_REPO # cd ${HOME} && git clone $MOONRAKER_REPO
ok_msg "Download complete!" # ok_msg "Download complete!"
status_msg "Installing Moonraker ..." # status_msg "Installing Moonraker ..."
$MOONRAKER_DIR/scripts/install-moonraker.sh # $MOONRAKER_DIR/scripts/install-moonraker.sh
#copy moonraker configuration for nginx to /etc/nginx/conf.d # #copy moonraker configuration for nginx to /etc/nginx/conf.d
setup_moonraker_nginx_cfg # setup_moonraker_nginx_cfg
#backup a possible existing printer.cfg at the old location and before patching in the new location # #backup a possible existing printer.cfg at the old location and before patching in the new location
backup_printer_cfg # backup_printer_cfg
patch_klipper_sysfile "moonraker" # patch_klipper_sysfile "moonraker"
#re-run printer.cfg location function to read the new path for the printer.cfg # #re-run printer.cfg location function to read the new path for the printer.cfg
locate_printer_cfg # locate_printer_cfg
echo; ok_msg "Moonraker successfully installed!" # echo; ok_msg "Moonraker successfully installed!"
} #}
patch_klipper_sysfile(){ patch_klipper_sysfile(){
if [ -e $KLIPPER_SERVICE2 ]; then
status_msg "Checking /etc/default/klipper for necessary entries ..."
#patching new printer.cfg location to /etc/default/klipper
if [ "$1" = "moonraker" ]; then
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
sudo sed -i "/KLIPPY_ARGS=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE2
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
fi
fi
#patching new UDS argument to /etc/default/klipper
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then
status_msg "Patching unix domain socket to /etc/default/klipper ..."
#append the new argument to /tmp/klippy.log argument
sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2
ok_msg "Patching done!"
fi
fi
fi
if [ -e $KLIPPER_SERVICE3 ]; then if [ -e $KLIPPER_SERVICE3 ]; then
status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..." status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..."
#patching new printer.cfg location to /etc/systemd/system/klipper.service #patching new printer.cfg location to /etc/systemd/system/klipper.service

View File

@@ -1,38 +1,66 @@
remove_klipper(){ remove_klipper(){
data_arr=( ###remove single instance
/etc/init.d/klipper if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
/etc/default/klipper
/etc/systemd/system/klipper.service
$KLIPPER_DIR
$KLIPPY_ENV_DIR
${HOME}/klippy.log
)
print_error "Klipper" && data_count=()
if [ "$ERROR_MSG" = "" ]; then
stop_klipper
if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then
status_msg "Removing Klipper Service ..." status_msg "Removing Klipper Service ..."
sudo rm -rf /etc/init.d/klipper /etc/default/klipper sudo systemctl stop klipper
sudo update-rc.d -f klipper remove sudo systemctl disable klipper
sudo rm -f $SYSTEMDDIR/klipper.service
ok_msg "Klipper Service removed!" ok_msg "Klipper Service removed!"
fi fi
if [ -e /etc/systemd/system/klipper.service ]; then if [ -f /tmp/klippy.log ]; then
status_msg "Removing Klipper Service ..." status_msg "Removing /tmp/klippy.log ..." && rm -f /tmp/klippy.log && ok_msg "Done!"
sudo rm -rf /etc/systemd/system/klipper.service fi
sudo update-rc.d -f klipper remove if [ -e /tmp/klippy_uds ]; then
status_msg "Removing /tmp/klippy_uds ..." && rm -f /tmp/klippy_uds && ok_msg "Done!"
fi
if [ -h /tmp/printer ]; then
status_msg "Removing /tmp/printer ..." && rm -f /tmp/printer && ok_msg "Done!"
fi
###remove multi instance services
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
status_msg "Removing Klipper Services ..."
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "klipper-*.service" | cut -d"/" -f5)
do
status_msg "Removing $service ..."
sudo systemctl stop $service
sudo systemctl disable $service
sudo rm -f $SYSTEMDDIR/$service
ok_msg "Done!"
done
fi
###remove multi instance logfiles
if [ "$(find /tmp -maxdepth 1 -name "klippy-*.log")" ]; then
for logfile in $(find /tmp -maxdepth 1 -name "klippy-*.log")
do
status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
done
fi
###remove multi instance UDS
if [ "$(find /tmp -maxdepth 1 -name "klippy_uds-*")" ]; then
for uds in $(find /tmp -maxdepth 1 -name "klippy_uds-*")
do
status_msg "Removing $uds ..." && rm -f $uds && ok_msg "Done!"
done
fi
###remove multi instance tmp-printer
if [ "$(find /tmp -maxdepth 1 -name "printer-*")" ]; then
for tmp_printer in $(find /tmp -maxdepth 1 -name "printer-*")
do
status_msg "Removing $tmp_printer ..." && rm -f $tmp_printer && ok_msg "Done!"
done
fi
###reloading units
sudo systemctl daemon-reload sudo systemctl daemon-reload
ok_msg "Klipper Service removed!"
fi ###removing klipper and klippy-env folders
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then if [ -d $KLIPPER_DIR ] || [ -d $KLIPPY_ENV ]; then
status_msg "Removing Klipper and klippy-env directory ..." status_msg "Removing Klipper and klippy-env directory ..."
rm -rf $KLIPPER_DIR $KLIPPY_ENV_DIR && ok_msg "Directories removed!" rm -rf $KLIPPER_DIR $KLIPPY_ENV && ok_msg "Directories removed!"
fi
if [[ -L ${HOME}/klippy.log || -e /tmp/klippy.log ]]; then
status_msg "Removing klippy.log Symlink ..."
rm -rf ${HOME}/klippy.log /tmp/klippy.log && ok_msg "Symlink removed!"
fi
CONFIRM_MSG=" Klipper successfully removed!"
fi fi
CONFIRM_MSG=" Klipper was successfully removed!"
} }
############################################################# #############################################################
@@ -101,83 +129,63 @@ remove_dwc2(){
############################################################# #############################################################
remove_moonraker(){ remove_moonraker(){
data_arr=( ###remove single instance
$MOONRAKER_SERVICE1 if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then
$MOONRAKER_SERVICE2 status_msg "Removing Moonraker Service ..."
$MOONRAKER_DIR sudo systemctl stop moonraker
$MOONRAKER_ENV_DIR sudo systemctl disable moonraker
$NGINX_CONFD/upstreams.conf sudo rm -f $SYSTEMDDIR/moonraker.service
$NGINX_CONFD/common_vars.conf ok_msg "Moonraker Service removed!"
${HOME}/moonraker.conf fi
${HOME}/moonraker.log if [ -f /tmp/moonraker.log ]; then
${HOME}/klipper_config/moonraker.log status_msg "Removing /tmp/moonraker.log ..." && rm -f /tmp/moonraker.log && ok_msg "Done!"
${HOME}/klipper_config/klippy.log fi
${HOME}/.klippy_api_key
${HOME}/.moonraker_api_key ###remove multi instance services
) if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
print_error "Moonraker" && data_count=() status_msg "Removing Moonraker Services ..."
if [ "$ERROR_MSG" = "" ]; then for service in $(find $SYSTEMDDIR -maxdepth 1 -name "moonraker-*.service" | cut -d"/" -f5)
if [ -e ${HOME}/moonraker.conf ]; then do
unset REMOVE_MOONRAKER_CONF status_msg "Removing $service ..."
while true; do sudo systemctl stop $service
echo sudo systemctl disable $service
read -p "${cyan}###### Delete moonraker.conf? (y/N):${default} " yn sudo rm -f $SYSTEMDDIR/$service
case "$yn" in ok_msg "Done!"
Y|y|Yes|yes)
echo -e "###### > Yes"
REMOVE_MOONRAKER_CONF="true"
break;;
N|n|No|no|"")
echo -e "###### > No"
REMOVE_MOONRAKER_CONF="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done done
fi fi
status_msg "Processing ..." ###remove multi instance logfiles
stop_moonraker if [ "$(find /tmp -maxdepth 1 -name "moonraker-*.log")" ]; then
#remove moonraker services for logfile in $(find /tmp -maxdepth 1 -name "moonraker-*.log")
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then do
status_msg "Removing Moonraker Service ..." status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
sudo update-rc.d -f moonraker remove done
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker Service removed!"
fi fi
#remove moonraker and moonraker-env dir
if [[ -d $MOONRAKER_DIR || -d $MOONRAKER_ENV_DIR ]]; then ###reloading units
sudo systemctl daemon-reload
###removing moonraker and moonraker-env folders
if [ -d $MOONRAKER_DIR ] || [ -d $MOONRAKER_ENV ]; then
status_msg "Removing Moonraker and moonraker-env directory ..." status_msg "Removing Moonraker and moonraker-env directory ..."
rm -rf $MOONRAKER_DIR $MOONRAKER_ENV_DIR && ok_msg "Directories removed!" rm -rf $MOONRAKER_DIR $MOONRAKER_ENV && ok_msg "Directories removed!"
fi
#remove moonraker.conf
if [ "$REMOVE_MOONRAKER_CONF" = "true" ]; then
status_msg "Removing moonraker.conf ..."
rm -rf ${HOME}/moonraker.conf && ok_msg "File removed!"
fi
#remove moonraker.log and symlink
if [[ -L ${HOME}/moonraker.log || -L ${HOME}/klipper_config/moonraker.log || -L ${HOME}/klipper_config/klippy.log || -e /tmp/moonraker.log ]]; then
status_msg "Removing Logs and Symlinks ..."
rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log ${HOME}/klipper_config/klippy.log /tmp/moonraker.log
ok_msg "Files removed!"
fi fi
#remove moonraker nginx config #remove moonraker nginx config
if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then
status_msg "Removing Moonraker NGINX configuration ..." status_msg "Removing Moonraker NGINX configuration ..."
sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!" sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!"
fi fi
#remove legacy api key #remove legacy api key
if [ -e ${HOME}/.klippy_api_key ]; then if [ -e ${HOME}/.klippy_api_key ]; then
status_msg "Removing legacy API Key ..." status_msg "Removing legacy API Key ..." && rm ${HOME}/.klippy_api_key && ok_msg "Done!"
rm ${HOME}/.klippy_api_key && ok_msg "Done!"
fi fi
#remove api key #remove api key
if [ -e ${HOME}/.moonraker_api_key ]; then if [ -e ${HOME}/.moonraker_api_key ]; then
status_msg "Removing API Key ..." status_msg "Removing API Key ..." && rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
fi
CONFIRM_MSG="Moonraker successfully removed!"
fi fi
CONFIRM_MSG=" Moonraker was successfully removed!"
} }
############################################################# #############################################################

View File

@@ -1,5 +1,5 @@
save_klipper_state(){ save_klipper_state(){
source_ini source_kiauh_ini
#read current klipper state #read current klipper state
cd $KLIPPER_DIR cd $KLIPPER_DIR
COMMIT_STATE=$(git rev-parse --short HEAD) COMMIT_STATE=$(git rev-parse --short HEAD)
@@ -19,7 +19,7 @@ save_klipper_state(){
} }
load_klipper_state(){ load_klipper_state(){
source_ini source_kiauh_ini
print_branch print_branch
cd $KLIPPER_DIR cd $KLIPPER_DIR
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) CURRENT_COMMIT=$(git rev-parse --short=8 HEAD)

View File

@@ -18,7 +18,9 @@ klipper_status(){
$KLIPPY_ENV_DIR $KLIPPY_ENV_DIR
) )
#remove the "SERVICE" entry from the klipper_data array if a klipper service is installed #remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && unset klipper_data[0] 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
unset klipper_data[0]
fi
#count+1 for each found data-item from array #count+1 for each found data-item from array
for kd in "${klipper_data[@]}" for kd in "${klipper_data[@]}"
do do
@@ -64,11 +66,11 @@ moonraker_status(){
SERVICE SERVICE
$MOONRAKER_DIR $MOONRAKER_DIR
$MOONRAKER_ENV_DIR $MOONRAKER_ENV_DIR
$NGINX_CONFD/upstreams.conf
$NGINX_CONFD/common_vars.conf
) )
#remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed #remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] && unset moonraker_data[0] if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
unset moonraker_data[0]
fi
#count+1 for each found data-item from array #count+1 for each found data-item from array
for mrd in "${moonraker_data[@]}" for mrd in "${moonraker_data[@]}"
do do

View File

@@ -26,13 +26,13 @@ install_menu(){
1) 1)
clear clear
print_header print_header
install_klipper klipper_setup_dialog
print_msg && clear_msg print_msg && clear_msg
install_ui;; install_ui;;
2) 2)
clear clear
print_header print_header
install_moonraker moonraker_setup_dialog
print_msg && clear_msg print_msg && clear_msg
install_ui;; install_ui;;
3) 3)

View File

@@ -7,10 +7,10 @@ main_ui(){
echo -e "| 1) [Install] | |" echo -e "| 1) [Install] | |"
echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|"
echo -e "| 3) [Remove] | |" echo -e "| 3) [Remove] | |"
echo -e "| | DWC2: $DWC2_STATUS|" echo -e "| 4) [Advanced] | DWC2: $DWC2_STATUS|"
echo -e "| 4) [Advanced] | Fluidd: $FLUIDD_STATUS|" echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
echo -e "| 5) [Backup] | Mainsail: $MAINSAIL_STATUS|" echo -e "| | Mainsail: $MAINSAIL_STATUS|"
echo -e "| | Octoprint: $OCTOPRINT_STATUS|" echo -e "| 6) [Settings] | Octoprint: $OCTOPRINT_STATUS|"
echo -e "| | |" echo -e "| | |"
echo -e "| ${cyan}$KIAUH_VER${default}| KlipperScreen: $KLIPPERSCREEN_STATUS|" echo -e "| ${cyan}$KIAUH_VER${default}| KlipperScreen: $KLIPPERSCREEN_STATUS|"
quit_footer quit_footer
@@ -75,6 +75,10 @@ main_menu(){
clear clear
backup_menu backup_menu
break;; break;;
6)
clear
settings_menu
break;;
Q|q) Q|q)
echo -e "${green}###### Happy printing! ######${default}"; echo echo -e "${green}###### Happy printing! ######${default}"; echo
exit -1;; exit -1;;

47
scripts/ui/settings_menu.sh Executable file
View File

@@ -0,0 +1,47 @@
settings_ui(){
source_kiauh_ini
[ -z $klipper_cfg_loc ] && klipper_cfg_loc="----------"
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | "
hr
echo -e "| ${red}Caution:${default} | "
echo -e "| Changing the path below will COPY the config files | "
echo -e "| to the new location. During that process ALL Klipper | "
echo -e "| and Moonraker services get stopped and reconfigured. | "
blank_line
echo -e "| ${red}DO NOT change the folder location during printing!${default} | "
hr
blank_line
echo -e "| ${yellow}● Current Klipper configuration folder:${default} | "
printf "|%-55s|\n" " $klipper_cfg_loc"
blank_line
hr
echo -e "| 1) Change configuration folder | "
quit_footer
}
settings_menu(){
print_header
print_msg && clear_msg
settings_ui
while true; do
read -p "${cyan}Perform action:${default} " action; echo
case "$action" in
1)
clear
print_header
change_klipper_cfg_path
print_msg && clear_msg
settings_ui;;
Q|q)
clear; main_menu; break;;
*)
clear
print_header
print_unkown_cmd
print_msg && clear_msg
settings_ui;;
esac
done
settings_ui
}

View File

@@ -58,7 +58,7 @@ update_all(){
} }
update_klipper(){ update_klipper(){
stop_klipper klipper_service "stop"
if [ ! -d $KLIPPER_DIR ]; then if [ ! -d $KLIPPER_DIR ]; then
cd ${HOME} && git clone $KLIPPER_REPO cd ${HOME} && git clone $KLIPPER_REPO
else else
@@ -82,7 +82,7 @@ update_klipper(){
ok_msg "Dependencies already met or have been installed!" ok_msg "Dependencies already met or have been installed!"
ok_msg "Update complete!" ok_msg "Update complete!"
fi fi
start_klipper klipper_service "start"
} }
update_dwc2fk(){ update_dwc2fk(){

View File

@@ -37,7 +37,7 @@ accept_upload_conditions(){
} }
upload_selection(){ upload_selection(){
source_ini source_kiauh_ini
[ "$logupload_accepted" = "false" ] && accept_upload_conditions [ "$logupload_accepted" = "false" ] && accept_upload_conditions
KLIPPY_LOG=/tmp/klippy.log KLIPPY_LOG=/tmp/klippy.log
MOONRAKER_LOG=/tmp/moonraker.log MOONRAKER_LOG=/tmp/moonraker.log