mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-15 03:24:29 +05:00
fix: introduce new/better folder structure for multi instance setups
This commit is contained in:
@@ -76,7 +76,7 @@ create_klipper_virtualenv(){
|
|||||||
|
|
||||||
create_single_klipper_startscript(){
|
create_single_klipper_startscript(){
|
||||||
### create systemd service file
|
### create systemd service file
|
||||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << EOF
|
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << SINGLE_STARTSCRIPT
|
||||||
#Systemd service file for klipper
|
#Systemd service file for klipper
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Starts klipper on startup
|
Description=Starts klipper on startup
|
||||||
@@ -90,12 +90,12 @@ RemainAfterExit=yes
|
|||||||
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
|
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
EOF
|
SINGLE_STARTSCRIPT
|
||||||
}
|
}
|
||||||
|
|
||||||
create_multi_klipper_startscript(){
|
create_multi_klipper_startscript(){
|
||||||
### create multi instance systemd service file
|
### create multi instance systemd service file
|
||||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << EOF
|
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << MULTI_STARTSCRIPT
|
||||||
#Systemd service file for klipper
|
#Systemd service file for klipper
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Starts klipper instance $INSTANCE on startup
|
Description=Starts klipper instance $INSTANCE on startup
|
||||||
@@ -109,7 +109,26 @@ RemainAfterExit=yes
|
|||||||
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -I ${TMP_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
|
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -I ${TMP_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
EOF
|
MULTI_STARTSCRIPT
|
||||||
|
}
|
||||||
|
|
||||||
|
create_minimal_printer_cfg(){
|
||||||
|
/bin/sh -c "cat > $1" << MINIMAL_CFG
|
||||||
|
[mcu]
|
||||||
|
serial: /dev/serial/by-id/
|
||||||
|
pin_map: arduino
|
||||||
|
|
||||||
|
[pause_resume]
|
||||||
|
[display_status]
|
||||||
|
|
||||||
|
[virtual_sdcard]
|
||||||
|
path: ~/gcode_files
|
||||||
|
|
||||||
|
[printer]
|
||||||
|
kinematics: none
|
||||||
|
max_velocity: 1
|
||||||
|
max_accel: 1
|
||||||
|
MINIMAL_CFG
|
||||||
}
|
}
|
||||||
|
|
||||||
klipper_setup(){
|
klipper_setup(){
|
||||||
@@ -129,9 +148,9 @@ klipper_setup(){
|
|||||||
install_klipper_packages
|
install_klipper_packages
|
||||||
create_klipper_virtualenv
|
create_klipper_virtualenv
|
||||||
|
|
||||||
### create sdcard folder
|
### create shared gcode_files folder
|
||||||
[ ! -d ${HOME}/sdcard ] && mkdir -p ${HOME}/sdcard
|
[ ! -d ${HOME}/gcode_files ] && mkdir -p ${HOME}/gcode_files
|
||||||
### create config folder
|
### create shared config folder
|
||||||
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
|
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
|
||||||
|
|
||||||
### create klipper instances
|
### create klipper instances
|
||||||
@@ -155,6 +174,7 @@ create_single_klipper_instance(){
|
|||||||
status_msg "Creating single Klipper instance ..."
|
status_msg "Creating single Klipper instance ..."
|
||||||
status_msg "Installing system start script ..."
|
status_msg "Installing system start script ..."
|
||||||
create_single_klipper_startscript
|
create_single_klipper_startscript
|
||||||
|
[ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG"
|
||||||
|
|
||||||
### enable instance
|
### enable instance
|
||||||
sudo systemctl enable klipper.service
|
sudo systemctl enable klipper.service
|
||||||
@@ -165,7 +185,8 @@ create_single_klipper_instance(){
|
|||||||
sudo systemctl start klipper
|
sudo systemctl start klipper
|
||||||
|
|
||||||
### confirm message
|
### confirm message
|
||||||
ok_msg "Single Klipper instance has been set up!\n"
|
CONFIRM_MSG="Single Klipper instance has been set up!"
|
||||||
|
print_msg && clear_msg
|
||||||
}
|
}
|
||||||
|
|
||||||
create_multi_klipper_instance(){
|
create_multi_klipper_instance(){
|
||||||
@@ -175,7 +196,11 @@ create_multi_klipper_instance(){
|
|||||||
KLIPPER_LOG=/tmp/klippy-$INSTANCE.log
|
KLIPPER_LOG=/tmp/klippy-$INSTANCE.log
|
||||||
KLIPPY_UDS=/tmp/klippy_uds-$INSTANCE
|
KLIPPY_UDS=/tmp/klippy_uds-$INSTANCE
|
||||||
TMP_PRINTER=/tmp/printer-$INSTANCE
|
TMP_PRINTER=/tmp/printer-$INSTANCE
|
||||||
PRINTER_CFG="$PRINTER_CFG_LOC/printer-$INSTANCE.cfg"
|
PRINTER_CFG="$PRINTER_CFG_LOC/printer_$INSTANCE/printer.cfg"
|
||||||
|
|
||||||
|
### create printer config folder and write a minimal printer.cfg to it
|
||||||
|
[ ! -d $PRINTER_CFG_LOC/printer_$INSTANCE ] && mkdir -p $PRINTER_CFG_LOC/printer_$INSTANCE
|
||||||
|
[ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG"
|
||||||
|
|
||||||
### create instance
|
### create instance
|
||||||
status_msg "Creating instance #$INSTANCE ..."
|
status_msg "Creating instance #$INSTANCE ..."
|
||||||
@@ -192,10 +217,18 @@ create_multi_klipper_instance(){
|
|||||||
### instance counter +1
|
### instance counter +1
|
||||||
INSTANCE=$(expr $INSTANCE + 1)
|
INSTANCE=$(expr $INSTANCE + 1)
|
||||||
done
|
done
|
||||||
|
|
||||||
### confirm message
|
### confirm message
|
||||||
ok_msg "$INSTANCE_COUNT Klipper instances have been set up!\n"
|
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
|
||||||
|
print_msg && clear_msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##############################################################################################
|
||||||
|
#********************************************************************************************#
|
||||||
|
##############################################################################################
|
||||||
|
|
||||||
|
|
||||||
flash_routine(){
|
flash_routine(){
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ moonraker_setup_dialog(){
|
|||||||
### check system for python3 before initializing the moonraker installation
|
### check system for python3 before initializing the moonraker installation
|
||||||
python3_check
|
python3_check
|
||||||
if [ $py_chk_ok = "false" ]; then
|
if [ $py_chk_ok = "false" ]; then
|
||||||
return 0
|
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
|
||||||
|
print_msg && clear_msg && return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
status_msg "Initializing Moonraker installation ..."
|
status_msg "Initializing Moonraker installation ..."
|
||||||
@@ -157,6 +158,7 @@ moonraker_setup(){
|
|||||||
create_moonraker_virtualenv
|
create_moonraker_virtualenv
|
||||||
|
|
||||||
### create moonraker.conf folder
|
### create moonraker.conf folder
|
||||||
|
### athough it should already exist because its the same as the klipper config folder
|
||||||
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
|
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
|
||||||
|
|
||||||
### create moonraker.confs
|
### create moonraker.confs
|
||||||
@@ -200,7 +202,8 @@ create_single_moonraker_instance(){
|
|||||||
sudo systemctl start moonraker
|
sudo systemctl start moonraker
|
||||||
|
|
||||||
### confirm message
|
### confirm message
|
||||||
ok_msg "Single Moonraker instance has been set up!"
|
CONFIRM_MSG="Single Moonraker instance has been set up!"
|
||||||
|
print_msg && clear_msg
|
||||||
|
|
||||||
### display moonraker ip to the user
|
### display moonraker ip to the user
|
||||||
print_ip_list; echo
|
print_ip_list; echo
|
||||||
@@ -211,7 +214,7 @@ create_multi_moonraker_instance(){
|
|||||||
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||||
### multi instance variables
|
### multi instance variables
|
||||||
MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log
|
MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log
|
||||||
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf"
|
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf"
|
||||||
|
|
||||||
### create instance
|
### create instance
|
||||||
status_msg "Creating instance #$INSTANCE ..."
|
status_msg "Creating instance #$INSTANCE ..."
|
||||||
@@ -228,9 +231,10 @@ create_multi_moonraker_instance(){
|
|||||||
### instance counter +1
|
### instance counter +1
|
||||||
INSTANCE=$(expr $INSTANCE + 1)
|
INSTANCE=$(expr $INSTANCE + 1)
|
||||||
done
|
done
|
||||||
|
|
||||||
### confirm message
|
### confirm message
|
||||||
echo; echo;
|
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
|
||||||
ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!"
|
print_msg && clear_msg
|
||||||
|
|
||||||
### display all moonraker ips to the user
|
### display all moonraker ips to the user
|
||||||
print_ip_list; echo
|
print_ip_list; echo
|
||||||
@@ -278,9 +282,9 @@ moonraker_conf_creation(){
|
|||||||
ip_list+=("$HOSTNAME:$PORT")
|
ip_list+=("$HOSTNAME:$PORT")
|
||||||
|
|
||||||
### start the creation of each instance
|
### start the creation of each instance
|
||||||
status_msg "Creating moonraker-$INSTANCE.conf in $MOONRAKER_CONF_LOC"
|
status_msg "Creating moonraker.conf for instance #$INSTANCE"
|
||||||
if [ ! -f $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf ]; then
|
if [ ! -f $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf ]; then
|
||||||
create_multi_moonraker_conf && ok_msg "moonraker-$INSTANCE.conf created!"
|
create_multi_moonraker_conf && ok_msg "moonraker.conf created!"
|
||||||
else
|
else
|
||||||
warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!"
|
warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!"
|
||||||
warn_msg "Skipping..."
|
warn_msg "Skipping..."
|
||||||
@@ -312,6 +316,8 @@ trusted_clients:
|
|||||||
$LOCAL_NETWORK
|
$LOCAL_NETWORK
|
||||||
cors_domains:
|
cors_domains:
|
||||||
http://*.local
|
http://*.local
|
||||||
|
http://my.mainsail.app
|
||||||
|
https://my.mainsail.app
|
||||||
http://app.fluidd.xyz
|
http://app.fluidd.xyz
|
||||||
https://app.fluidd.xyz
|
https://app.fluidd.xyz
|
||||||
http://$HOSTNAME
|
http://$HOSTNAME
|
||||||
@@ -324,15 +330,15 @@ MOONRAKERCONF
|
|||||||
|
|
||||||
create_multi_moonraker_conf(){
|
create_multi_moonraker_conf(){
|
||||||
HOSTNAME=$(hostname -I | cut -d" " -f1)
|
HOSTNAME=$(hostname -I | cut -d" " -f1)
|
||||||
NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24"
|
LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24"
|
||||||
|
|
||||||
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" << MOONRAKERCONF
|
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF
|
||||||
[server]
|
[server]
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: $PORT
|
port: $PORT
|
||||||
klippy_uds_address: /tmp/klippy_uds-$INSTANCE
|
klippy_uds_address: /tmp/klippy_uds-$INSTANCE
|
||||||
enable_debug_logging: True
|
enable_debug_logging: True
|
||||||
config_path: $PRINTER_CFG_LOC
|
config_path: $PRINTER_CFG_LOC/printer_$INSTANCE
|
||||||
|
|
||||||
[authorization]
|
[authorization]
|
||||||
enabled: True
|
enabled: True
|
||||||
@@ -342,6 +348,8 @@ trusted_clients:
|
|||||||
$LOCAL_NETWORK
|
$LOCAL_NETWORK
|
||||||
cors_domains:
|
cors_domains:
|
||||||
http://*.local
|
http://*.local
|
||||||
|
http://my.mainsail.app
|
||||||
|
https://my.mainsail.app
|
||||||
http://app.fluidd.xyz
|
http://app.fluidd.xyz
|
||||||
https://app.fluidd.xyz
|
https://app.fluidd.xyz
|
||||||
http://$HOSTNAME
|
http://$HOSTNAME
|
||||||
@@ -353,20 +361,9 @@ MOONRAKERCONF
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##############################################################################################
|
||||||
|
#********************************************************************************************#
|
||||||
|
##############################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install_moonraker(){
|
install_moonraker(){
|
||||||
|
|||||||
Reference in New Issue
Block a user