From 3e35be5681e1b0161b0ea7a612d8412c8a2a56c4 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sun, 13 Sep 2020 11:25:46 +0200 Subject: [PATCH] add: user choice for dwc service (init.d or systemd) --- scripts/install_dwc2.sh | 38 +++++++++++++++++++++++++++++++++++++- scripts/remove.sh | 12 +++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index 6aedec5..6e89936 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -37,6 +37,38 @@ system_check_dwc2(){ } get_user_selections_dwc2(){ + #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 wan't to install dwc2-for-klipper-socket as |" + echo -e "| 1) Init.d Service |" + 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 pick, |" + echo -e "| please do a research before. |" + hr + echo -e "| In case you are using Raspberry Pi OS, either option |" + echo -e "| 1 or 2 will work. |" + bottom_border + read -p "${cyan}###### Please choose:${default} " action + case "$action" in + 1) + INST_INITD="true" + INST_SYSTEMD="false" + break;; + 2) + INST_INITD="false" + INST_SYSTEMD="true" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done #user selection for printer.cfg if [ "$PRINTER_CFG_FOUND" = "false" ]; then unset SEL_DEF_CFG @@ -127,7 +159,11 @@ dwc2_setup(){ cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts ok_msg "Done!" status_msg "Starting service-installer ..." - $DWC2FK_DIR/scripts/install-octopi.sh + if [ "$INST_INITD" = "true" ] && [ "$INST_SYSTEMD" = "false" ]; then + $DWC2FK_DIR/scripts/install-octopi.sh + elif [ "$INST_INITD" = "false" ] && [ "$INST_SYSTEMD" = "true" ]; then + $DWC2FK_DIR/scripts/install-debian.sh + fi ok_msg "Service installed!" #patch /etc/default/klipper to append the uds argument patch_klipper_sysfile_dwc2 diff --git a/scripts/remove.sh b/scripts/remove.sh index 1f58320..489be4f 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -34,6 +34,7 @@ remove_dwc2(){ data_arr=( /etc/init.d/dwc /etc/default/dwc + /etc/systemd/system/dwc.service $DWC2FK_DIR $DWC_ENV_DIR $DWC2_DIR @@ -42,15 +43,24 @@ remove_dwc2(){ if [ "$ERROR_MSG" = "" ]; then if systemctl is-active dwc -q; then status_msg "Stopping DWC2-for-Klipper-Socket Service ..." - sudo /etc/init.d/dwc stop && sudo systemctl disable dwc + sudo systemctl stop dwc && sudo systemctl disable dwc ok_msg "Service stopped!" fi + #remove if init.d service if [[ -e /etc/init.d/dwc || -e /etc/default/dwc ]]; then + status_msg "Init.d Service found ..." status_msg "Removing DWC2-for-Klipper-Socket Service ..." sudo rm -rf /etc/init.d/dwc /etc/default/dwc sudo update-rc.d -f dwc remove ok_msg "DWC2-for-Klipper-Socket Service removed!" fi + #remove if systemd service + if [ -e /etc/systemd/system/dwc.service ]; then + status_msg "Systemd Service found ..." + status_msg "Removing DWC2-for-Klipper-Socket Service ..." + sudo rm -rf /etc/systemd/system/dwc.service + ok_msg "DWC2-for-Klipper-Socket Service removed!" + fi if [ -d $DWC2FK_DIR ]; then status_msg "Removing DWC2-for-Klipper-Socket directory ..." rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"