User Tools

Site Tools


shutdown_linux

This is an old revision of the document!


Sovol SV06+ (mostly)

Klipper Shutdown

Linux version

Requirements

  • HS110 wifi power plug
  • For simple setup using clear text passwords:
    • plink from putty-tools
    • install with sudo apt install putty-tools
  • For recommended setup using ssh with a key file:
    • ssh with a private key generated by ssh-keygen and its public key pasted to the device's ~./ssh/authorized_keys file
    • see man ssh and man ssh-keygen for further help
  • softScheck “tplink_smartplug.py” from https://github.com/softScheck/tplink-smartplug/tree/master

Copy the files hs110_off, hs110_on, mks_poweroff , shutdown_sv06 and tplink_smartplug.py into a single directory and make them executable by using chmod +x *.

Now you should be able to shutdown and power off the device using clear text passwords by executing shutdown_sv06.
To power it back on, execute hs110_on.


To use passwordless login (recommended), you need to generate a key file.
You can either use putty's plink or standard ssh for that, but the keys need to be generated differently.

First create the “.ssh” directory (if not already existing)

  • mkdir -p ~/.ssh ; chmod 700 ~/.ssh

For plink:

  • Use puttygen to generate the key
    Example: puttygen -t ed25519 -f ~/.ssh/printerkey
  • Use puttygen again to generate and display the accompanying standard ssh public key
    Example: puttygen ~/.ssh/printerkey -L
  • See man puttgen for further details

For standard ssh:

  • Use ssh-keygen to generate the key
    Example: ssh-keygen -t ed25519 -f ~/.ssh/printerkey
  • Use cat ~/.ssh/printerkey.pub to display the ssh public key
  • See man ssh-keygen for further details.
  • Set the PLINKCMD variable in mks_poweroff to ssh

Then

  • Make the keyfile unreadable to other users: chmod 600 ~/.ssh/printerkey
  • Adjust the PLINKKEY variable in mks_poweroff so it points to your private key file (~/.ssh/printerkey in these examples)
  • Empty the PASSWORD variable in mks_poweroff
  • Log into the device using ssh and add the public key to ~/.ssh/authorized_keys:
    • cat » ~/.ssh/authorized_keys
    • Paste the public key line and press CTRL+D to quit

Now you should be able to shutdown and power off the device without clear text passwords.


The files:

hs110_off

#!/bin/sh
python tplink_smartplug.py -t 192.168.1.60 -c off

hs110_on

#!/bin/sh
python tplink_smartplug.py -t 192.168.1.60 -c on

mks_poweroff

#!/bin/bash

# Install plink (allows passwords given on commandline)
#   apt install putty-tools
# To use a ssh key:
#   Adjust PLINKKEY so it points to your private key
#   (generated with "puttygen" when using putty, or with "ssh-keygen" for default ssh)
# Using ssh instead of plink is possible when using a ssh key instead of a clear text password:
#   Set PLINKCMD=ssh

# === best practice is using a PLINKKEY instead of a cleartext PASSWORD ===

PRINTER=mkspi
USERNAME=mks
PASSWORD=makerbase
PLINKCMD=plink
PLINKKEY=
# options for plink with putty key (created with puttygen)
#PASSWORD=
#PLINKKEY=~/.ssh/printerkey
# options for standard ssh (key created with ssh-keygen)
#PASSWORD=
#PLINKKEY=~/.ssh/printerkey
#PLINKCMD=ssh

# === nothing should be changed below here ===

# MKSPI: allow user "mks" to shutdown/reboot/halt (without "sudo" asking for a password):
#        add following to /etc/sudoers.conf (run "visudo"):
#        mks ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff

POWERCMD="sudo poweroff"

if [ "$PLINKCMD" == "plink" ]; then
  OPTBATCH=-batch
fi

if [ ! -z $PLINKKEY ]; then
  OPTKEY="-i $PLINKKEY"
fi

if [ ! -z $PASSWORD ]; then
  OPTPW="-pw $PASSWORD"
  POWERCMD="echo $PASSWORD|sudo -S poweroff"
fi

$PLINKCMD $OPTPW $OPTKEY $OPTBATCH $USERNAME@$PRINTER $POWERCMD

shutdown_sv06

#!/bin/bash

PRINTER=mkspi

# try to ping MKSPI, shut it down, if it responds
if ping -c 1 -W 1 $PRINTER >/dev/null; then
  echo Shutting down MKSPI
  bash mks_poweroff
  echo -n Waiting for MKS to shutdown.
  # ping MKSPI, until it stops responding
  while ping -c 1 -W 1 $PRINTER >/dev/null; do
    echo -n .
    sleep 1
  done
  # not responding any longer
  echo MKSPI has shut down.
  echo Waiting additional 7 seconds...
  sleep 7
fi
echo Power off HS110 smartplug...
bash hs110_off

Back to shutdown


Back to start

shutdown_linux.1732710912.txt.gz · Last modified: 2024/11/27 13:35 by torte