mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-15 03:24:29 +05:00
fix: prepare for possible multi instance capabilities of dwc2-for-klipper-socket
This commit is contained in:
5
kiauh.sh
5
kiauh.sh
@@ -32,7 +32,8 @@ FLUIDD_DIR=${HOME}/fluidd
|
|||||||
#dwc2
|
#dwc2
|
||||||
DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket
|
DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket
|
||||||
DWC_ENV_DIR=${HOME}/dwc-env
|
DWC_ENV_DIR=${HOME}/dwc-env
|
||||||
DWC2_DIR=${HOME}/sdcard/web
|
#DWC2_DIR=${HOME}/sdcard/web
|
||||||
|
DWC2_DIR=${HOME}/duetwebcontrol
|
||||||
#octoprint
|
#octoprint
|
||||||
OCTOPRINT_DIR=${HOME}/OctoPrint
|
OCTOPRINT_DIR=${HOME}/OctoPrint
|
||||||
#KlipperScreen
|
#KlipperScreen
|
||||||
@@ -46,7 +47,7 @@ BACKUP_DIR=${HOME}/kiauh-backups
|
|||||||
KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git
|
KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git
|
||||||
ARKSINE_REPO=https://github.com/Arksine/klipper.git
|
ARKSINE_REPO=https://github.com/Arksine/klipper.git
|
||||||
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
|
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
|
||||||
DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
DWC2FK_REPO=https://github.com/th33xitus/dwc2-for-klipper-socket.git
|
||||||
MOONRAKER_REPO=https://github.com/Arksine/moonraker.git
|
MOONRAKER_REPO=https://github.com/Arksine/moonraker.git
|
||||||
KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git
|
KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git
|
||||||
#branches
|
#branches
|
||||||
|
|||||||
@@ -112,6 +112,10 @@ get_dwc_ver(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
dwc_setup(){
|
dwc_setup(){
|
||||||
|
### get printer config directory
|
||||||
|
source_kiauh_ini
|
||||||
|
DWC_CONF_LOC="$klipper_cfg_loc"
|
||||||
|
|
||||||
### check dependencies
|
### check dependencies
|
||||||
dep=(git wget gzip tar curl)
|
dep=(git wget gzip tar curl)
|
||||||
dependency_check
|
dependency_check
|
||||||
@@ -126,16 +130,20 @@ dwc_setup(){
|
|||||||
install_dwc_packages
|
install_dwc_packages
|
||||||
create_dwc_virtualenv
|
create_dwc_virtualenv
|
||||||
|
|
||||||
### step 3: download Duet Web Control
|
### 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
|
download_dwc_webui
|
||||||
|
|
||||||
### step 4: create dwc instances
|
### step 5: create dwc instances
|
||||||
INSTANCE=1
|
INSTANCE=1
|
||||||
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
|
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
|
||||||
create_single_dwc_instance
|
create_single_dwc_instance
|
||||||
else
|
else
|
||||||
#create_multi_dwc_instance
|
#create_multi_dwc_instance
|
||||||
warn_msg "Sorry, at the moment only single instance installations are supported!"
|
create_multi_dwc_instance
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,11 +199,10 @@ create_dwc_virtualenv()
|
|||||||
}
|
}
|
||||||
|
|
||||||
create_single_dwc_startscript(){
|
create_single_dwc_startscript(){
|
||||||
### create systemd service file
|
### create systemd service file
|
||||||
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC
|
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC
|
||||||
#Systemd service file for DWC
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=dwc_webif
|
Description=DuetWebControl
|
||||||
After=network.target
|
After=network.target
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
@@ -203,17 +210,62 @@ WantedBy=multi-user.target
|
|||||||
Type=simple
|
Type=simple
|
||||||
User=${USER}
|
User=${USER}
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py
|
ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG}
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
DWC
|
DWC
|
||||||
}
|
}
|
||||||
|
|
||||||
create_multi_dwc_startscript(){
|
create_multi_dwc_startscript(){
|
||||||
###! atm not possible due to hardcoded log and config files used by dwc2-for-klipper-socket!
|
### create systemd service file
|
||||||
###! either needs a PR to read start-arguments passed over by the service file or
|
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc-$INSTANCE.service" << DWC
|
||||||
###! every instance needs its own copy of dwc2-for-klipper-socket with a modifief web_dwc2.py
|
[Unit]
|
||||||
###! on line 223, 228 and probably 217 as well
|
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: ~/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: ~/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
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################################################
|
##############################################################################################
|
||||||
@@ -232,20 +284,13 @@ create_single_dwc_instance(){
|
|||||||
status_msg "Setting up 1 Duet Web Control instance ..."
|
status_msg "Setting up 1 Duet Web Control instance ..."
|
||||||
|
|
||||||
### single instance variables
|
### single instance variables
|
||||||
PORT=4750
|
|
||||||
DWC_LOG=/tmp/dwc.log
|
DWC_LOG=/tmp/dwc.log
|
||||||
|
DWC_CFG="$DWC_CONF_LOC/dwc2.cfg"
|
||||||
### 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 instance
|
### create instance
|
||||||
status_msg "Creating single DWC instance ..."
|
status_msg "Creating single DWC instance ..."
|
||||||
create_single_dwc_startscript
|
create_single_dwc_startscript
|
||||||
|
|
||||||
### write the ip and port to the ip list for displaying it later to the user
|
|
||||||
dwc_ip_list+=("$HOSTNAME:$PORT")
|
|
||||||
|
|
||||||
### enable instance
|
### enable instance
|
||||||
sudo systemctl enable dwc.service
|
sudo systemctl enable dwc.service
|
||||||
ok_msg "Single DWC instance created!"
|
ok_msg "Single DWC instance created!"
|
||||||
@@ -263,8 +308,89 @@ create_single_dwc_instance(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
create_multi_dwc_instance(){
|
create_multi_dwc_instance(){
|
||||||
###! atm not possible due to hardcoded log and config files used by dwc2-for-klipper-socket!
|
status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..."
|
||||||
###! either needs a PR to read start-arguments passed over by the service file or
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||||
###! every instance needs its own copy of dwc2-for-klipper-socket with a modifief web_dwc2.py
|
### multi instance variables
|
||||||
###! on line 223, 228 and probably 217 as well
|
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
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user