mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 02:54:28 +05:00
add: dwc2-for-klipper-socket installer scripts
This commit is contained in:
54
scripts/dwc2-for-klipper-socket-installer/dwc-start.sh
Executable file
54
scripts/dwc2-for-klipper-socket-installer/dwc-start.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
# System startup script for dwc2-for-klipper-socket
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: dwc2-for-klipper-socket
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: dwc2-for-klipper-socket daemon
|
||||
# Description: Starts the dwc2-for-klipper-socket daemon.
|
||||
### END INIT INFO
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
DESC="dwc2-for-klipper-socket daemon"
|
||||
NAME="dwc2-for-klipper-socket"
|
||||
DEFAULTS_FILE=/etc/default/dwc
|
||||
PIDFILE=/var/run/dwc.pid
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
# Read defaults file
|
||||
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
|
||||
|
||||
case "$1" in
|
||||
start) log_daemon_msg "Starting dwc2-for-klipper-socket" $NAME
|
||||
start-stop-daemon --start --quiet --exec $DWC_EXEC \
|
||||
--background --pidfile $PIDFILE --make-pidfile \
|
||||
--chuid $DWC_USER --user $DWC_USER \
|
||||
-- $DWC_ARGS
|
||||
log_end_msg $?
|
||||
;;
|
||||
stop) log_daemon_msg "Stopping dwc2-for-klipper-socket" $NAME
|
||||
killproc -p $PIDFILE $DWC_EXEC
|
||||
RETVAL=$?
|
||||
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
|
||||
log_end_msg $RETVAL
|
||||
;;
|
||||
restart) log_daemon_msg "Restarting dwc2-for-klipper-socket" $NAME
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
reload|force-reload)
|
||||
log_daemon_msg "Reloading configuration not supported" $NAME
|
||||
log_end_msg 1
|
||||
;;
|
||||
status)
|
||||
status_of_proc -p $PIDFILE $DWC_EXEC $NAME && exit 0 || exit $?
|
||||
;;
|
||||
*) log_action_msg "Usage: /etc/init.d/dwc {start|stop|status|restart|reload|force-reload}"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
106
scripts/dwc2-for-klipper-socket-installer/install-debian.sh
Executable file
106
scripts/dwc2-for-klipper-socket-installer/install-debian.sh
Executable file
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running
|
||||
# Raspbian/Raspberry Pi OS based distributions.
|
||||
|
||||
# https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
|
||||
PYTHONDIR="${HOME}/dwc-env"
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
DWC_USER=${USER}
|
||||
|
||||
# Step 1: Verify Klipper has been installed
|
||||
check_klipper()
|
||||
{
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
echo "Klipper service found!"
|
||||
else
|
||||
echo "Klipper service not found, please install Klipper first"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Step 2: Install packages
|
||||
install_packages()
|
||||
{
|
||||
PKGLIST="python3-virtualenv python3-dev python3-tornado"
|
||||
|
||||
# Update system package info
|
||||
report_status "Running apt-get update..."
|
||||
sudo apt-get update
|
||||
|
||||
# Install desired packages
|
||||
report_status "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
# Step 3: Create python virtual environment
|
||||
create_virtualenv()
|
||||
{
|
||||
report_status "Updating python virtual environment..."
|
||||
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR}
|
||||
|
||||
# Install/update dependencies
|
||||
${PYTHONDIR}/bin/pip install tornado==6.0.4
|
||||
}
|
||||
|
||||
# Step 4: Install startup script
|
||||
install_script(){
|
||||
report_status "Installing system start script..."
|
||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/dwc.service" << EOF
|
||||
#Systemd service file for DWC
|
||||
[Unit]
|
||||
Description=dwc_webif
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$DWC_USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${PYTHONDIR}/bin/python3 ${SRCDIR}/dwc2-for-klipper-socket/web_dwc2.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
# Use systemctl to enable the klipper systemd service script
|
||||
sudo systemctl enable dwc.service
|
||||
}
|
||||
|
||||
# Step 5: Start DWC service
|
||||
start_software()
|
||||
{
|
||||
report_status "Launching dwc2-for-klipper-socket..."
|
||||
sudo systemctl start dwc
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
report_status()
|
||||
{
|
||||
echo -e "\n\n###### $1"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Force script to exit if an error occurs
|
||||
set -e
|
||||
|
||||
# Find SRCDIR from the pathname of this script
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
|
||||
# Run installation steps defined above
|
||||
verify_ready
|
||||
check_klipper
|
||||
install_packages
|
||||
create_virtualenv
|
||||
install_script
|
||||
start_software
|
||||
106
scripts/dwc2-for-klipper-socket-installer/install-octopi.sh
Executable file
106
scripts/dwc2-for-klipper-socket-installer/install-octopi.sh
Executable file
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running
|
||||
# Raspbian/Raspberry Pi OS based distributions.
|
||||
|
||||
# https://github.com/Stephan3/dwc2-for-klipper-socket.git
|
||||
|
||||
PYTHONDIR="${HOME}/dwc-env"
|
||||
|
||||
# Step 1: Verify Klipper has been installed
|
||||
check_klipper()
|
||||
{
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
echo "Klipper service found!"
|
||||
else
|
||||
echo "Klipper service not found, please install Klipper first"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Step 2: Install packages
|
||||
install_packages()
|
||||
{
|
||||
PKGLIST="python3-virtualenv python3-dev python3-tornado"
|
||||
|
||||
# Update system package info
|
||||
report_status "Running apt-get update..."
|
||||
sudo apt-get update
|
||||
|
||||
# Install desired packages
|
||||
report_status "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
# Step 3: Create python virtual environment
|
||||
create_virtualenv()
|
||||
{
|
||||
report_status "Updating python virtual environment..."
|
||||
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR}
|
||||
|
||||
# Install/update dependencies
|
||||
${PYTHONDIR}/bin/pip install tornado==6.0.4
|
||||
}
|
||||
|
||||
# Step 4: Install startup script
|
||||
install_script(){
|
||||
report_status "Installing system start script..."
|
||||
sudo cp "${SRCDIR}/scripts/dwc-start.sh" /etc/init.d/dwc
|
||||
sudo update-rc.d dwc defaults
|
||||
}
|
||||
|
||||
# Step 5: Install startup script config
|
||||
install_config(){
|
||||
DEFAULTS_FILE=/etc/default/dwc
|
||||
[ -f $DEFAULTS_FILE ] && return
|
||||
|
||||
report_status "Installing system start configuration..."
|
||||
sudo /bin/sh -c "cat > $DEFAULTS_FILE" <<EOF
|
||||
# Configuration for /etc/init.d/dwc
|
||||
DWC_USER=$USER
|
||||
|
||||
DWC_EXEC=${PYTHONDIR}/bin/python3
|
||||
|
||||
DWC_ARGS="${SRCDIR}/web_dwc2.py"
|
||||
EOF
|
||||
}
|
||||
|
||||
# Step 4: Start server
|
||||
start_software()
|
||||
{
|
||||
report_status "Launching dwc2-for-klipper-socket..."
|
||||
sudo /etc/init.d/klipper stop
|
||||
sudo /etc/init.d/dwc restart
|
||||
sudo /etc/init.d/klipper start
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
report_status()
|
||||
{
|
||||
echo -e "\n\n###### $1"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Force script to exit if an error occurs
|
||||
set -e
|
||||
|
||||
# Find SRCDIR from the pathname of this script
|
||||
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
|
||||
|
||||
# Run installation steps defined above
|
||||
verify_ready
|
||||
check_klipper
|
||||
install_packages
|
||||
create_virtualenv
|
||||
install_script
|
||||
install_config
|
||||
start_software
|
||||
41
scripts/dwc2-for-klipper-socket-installer/uninstall-debian.sh
Executable file
41
scripts/dwc2-for-klipper-socket-installer/uninstall-debian.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
stop_service() {
|
||||
# Stop DWC Service
|
||||
echo "#### Stopping DWC Service.."
|
||||
sudo systemctl stop dwc
|
||||
sudo systemctl disable dwc
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove DWC from Services
|
||||
echo
|
||||
echo "#### Removing DWC Service.."
|
||||
sudo rm -f /etc/systemd/system/dwc.service
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
# Remove virtualenv
|
||||
if [ -d ~/dwc-env ]; then
|
||||
echo "Removing virtualenv..."
|
||||
rm -rf ~/dwc-env
|
||||
else
|
||||
echo "No DWC virtualenv found"
|
||||
fi
|
||||
|
||||
# Notify user of method to remove DWC source code
|
||||
echo
|
||||
echo "The DWC system files and virtualenv have been removed."
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
45
scripts/dwc2-for-klipper-socket-installer/uninstall-octopi.sh
Executable file
45
scripts/dwc2-for-klipper-socket-installer/uninstall-octopi.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
stop_service() {
|
||||
# Stop DWC Service
|
||||
echo "#### Stopping DWC Service.."
|
||||
sudo service dwc stop
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove DWC from Startup
|
||||
echo
|
||||
echo "#### Removing DWC from Startup.."
|
||||
sudo update-rc.d -f dwc remove
|
||||
|
||||
# Remove DWC from Services
|
||||
echo
|
||||
echo "#### Removing DWC Service.."
|
||||
sudo rm -f /etc/init.d/dwc /etc/default/dwc
|
||||
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
# Remove virtualenv
|
||||
if [ -d ~/dwc-env ]; then
|
||||
echo "Removing virtualenv..."
|
||||
rm -rf ~/dwc-env
|
||||
else
|
||||
echo "No DWC virtualenv found"
|
||||
fi
|
||||
|
||||
# Notify user of method to remove DWC source code
|
||||
echo
|
||||
echo "The DWC system files and virtualenv have been removed."
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
{
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script must not run as root"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
Reference in New Issue
Block a user