mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 02:54:28 +05:00
add: support to install klipper as systemd service
This commit is contained in:
1
kiauh.sh
1
kiauh.sh
@@ -20,6 +20,7 @@ KLIPPER_DIR=${HOME}/klipper
|
|||||||
KLIPPY_ENV_DIR=${HOME}/klippy-env
|
KLIPPY_ENV_DIR=${HOME}/klippy-env
|
||||||
KLIPPER_SERVICE1=/etc/init.d/klipper
|
KLIPPER_SERVICE1=/etc/init.d/klipper
|
||||||
KLIPPER_SERVICE2=/etc/default/klipper
|
KLIPPER_SERVICE2=/etc/default/klipper
|
||||||
|
KLIPPER_SERVICE3=/etc/systemd/system/klipper.service
|
||||||
#nginx
|
#nginx
|
||||||
NGINX_SA=/etc/nginx/sites-available
|
NGINX_SA=/etc/nginx/sites-available
|
||||||
NGINX_SE=/etc/nginx/sites-enabled
|
NGINX_SE=/etc/nginx/sites-enabled
|
||||||
|
|||||||
@@ -13,17 +13,24 @@ check_euid(){
|
|||||||
|
|
||||||
locate_printer_cfg(){
|
locate_printer_cfg(){
|
||||||
unset PRINTER_CFG
|
unset PRINTER_CFG
|
||||||
status_msg "Locating printer.cfg via /etc/default/klipper ..."
|
if [ -e $KLIPPER_SERVICE2 ]; then
|
||||||
if [ -f $KLIPPER_SERVICE2 ]; then
|
status_msg "Locating printer.cfg via $KLIPPER_SERVICE2 ..."
|
||||||
#reads /etc/default/klipper and gets the default printer.cfg location
|
#reads /etc/default/klipper and gets the default printer.cfg location
|
||||||
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)"
|
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)"
|
||||||
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
|
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
|
||||||
i=1
|
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")
|
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'"
|
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
|
else
|
||||||
PRINTER_CFG=""
|
PRINTER_CFG=""
|
||||||
warn_msg "Can't read /etc/default/klipper - File not found!"
|
warn_msg "Can't read printer.cfg location!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
install_klipper(){
|
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!"
|
ERROR_MSG="Looks like Klipper is already installed!"
|
||||||
else
|
else
|
||||||
get_user_selections_klipper
|
get_user_selections_klipper
|
||||||
@@ -12,6 +12,37 @@ install_klipper(){
|
|||||||
|
|
||||||
get_user_selections_klipper(){
|
get_user_selections_klipper(){
|
||||||
status_msg "Initializing Klipper installation ..."
|
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
|
#ask user for building firmware
|
||||||
while true; do
|
while true; do
|
||||||
echo
|
echo
|
||||||
@@ -61,14 +92,12 @@ klipper_setup(){
|
|||||||
git clone $KLIPPER_REPO
|
git clone $KLIPPER_REPO
|
||||||
ok_msg "Klipper successfully cloned!"
|
ok_msg "Klipper successfully cloned!"
|
||||||
status_msg "Installing Klipper Service ..."
|
status_msg "Installing Klipper Service ..."
|
||||||
$KLIPPER_DIR/scripts/install-octopi.sh
|
if [ "$INST_KLIPPER_INITD" = "true" ]; then
|
||||||
ok_msg "Klipper installation complete!"
|
$KLIPPER_DIR/scripts/install-octopi.sh
|
||||||
#create a klippy.log symlink in home-dir just for convenience
|
elif [ "$INST_KLIPPER_SYSTEMD" = "true" ]; then
|
||||||
if [ ! -e ${HOME}/klippy.log ]; then
|
$KLIPPER_DIR/scripts/install-debian.sh
|
||||||
status_msg "Creating klippy.log Symlink ..."
|
|
||||||
ln -s /tmp/klippy.log ${HOME}/klippy.log
|
|
||||||
ok_msg "Symlink created!"
|
|
||||||
fi
|
fi
|
||||||
|
ok_msg "Klipper installation complete!"
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_routine(){
|
flash_routine(){
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ remove_klipper(){
|
|||||||
data_arr=(
|
data_arr=(
|
||||||
/etc/init.d/klipper
|
/etc/init.d/klipper
|
||||||
/etc/default/klipper
|
/etc/default/klipper
|
||||||
|
/etc/systemd/system/klipper.service
|
||||||
$KLIPPER_DIR
|
$KLIPPER_DIR
|
||||||
$KLIPPY_ENV_DIR
|
$KLIPPY_ENV_DIR
|
||||||
${HOME}/klippy.log
|
${HOME}/klippy.log
|
||||||
@@ -15,6 +16,13 @@ remove_klipper(){
|
|||||||
sudo update-rc.d -f klipper remove
|
sudo update-rc.d -f klipper remove
|
||||||
ok_msg "Klipper Service removed!"
|
ok_msg "Klipper Service removed!"
|
||||||
fi
|
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
|
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; 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_DIR && ok_msg "Directories removed!"
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ klipper_status(){
|
|||||||
klipper_data=(
|
klipper_data=(
|
||||||
$KLIPPER_DIR
|
$KLIPPER_DIR
|
||||||
$KLIPPY_ENV_DIR
|
$KLIPPY_ENV_DIR
|
||||||
$KLIPPER_SERVICE1
|
SERVICE
|
||||||
$KLIPPER_SERVICE2
|
|
||||||
)
|
)
|
||||||
|
#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
|
#count+1 for each found data-item from array
|
||||||
for kd in "${klipper_data[@]}"
|
for kd in "${klipper_data[@]}"
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user