scripts: Add octopi installation scripts
Add a system startup script so that Klipper can automatically start at boot time. Create an installation script that will install the system dependencies and the startup script. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
167b18b58f
commit
ec805aee2e
|
@ -16,40 +16,29 @@ Raspberry Pi computer. Use OctoPi v0.13.0 or later - see the
|
||||||
[octopi releases](https://github.com/guysoft/OctoPi/releases) for
|
[octopi releases](https://github.com/guysoft/OctoPi/releases) for
|
||||||
release information. One should verify that OctoPi boots and that the
|
release information. One should verify that OctoPi boots and that the
|
||||||
OctoPrint web server works. After connecting to the OctoPrint web
|
OctoPrint web server works. After connecting to the OctoPrint web
|
||||||
page, follow the prompt to upgrade OctoPrint to v1.3.0 or later.
|
page, follow the prompt to upgrade OctoPrint to v1.3.2 or later.
|
||||||
|
|
||||||
After installing OctoPi and upgrading OctoPrint, ssh into the target
|
After installing OctoPi and upgrading OctoPrint, ssh into the target
|
||||||
machine (ssh pi@octopi -- password is "raspberry") and run the
|
machine (ssh pi@octopi -- password is "raspberry") and run the
|
||||||
following commands:
|
following commands:
|
||||||
|
|
||||||
```
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install libncurses-dev libusb-dev
|
|
||||||
sudo apt-get install avrdude gcc-avr binutils-avr avr-libc # AVR toolchain
|
|
||||||
sudo apt-get install bossa-cli libnewlib-arm-none-eabi # ARM toolchain
|
|
||||||
```
|
|
||||||
|
|
||||||
The host software (Klippy) requires a one-time setup - run as the
|
|
||||||
regular "pi" user:
|
|
||||||
|
|
||||||
```
|
|
||||||
virtualenv ~/klippy-env
|
|
||||||
~/klippy-env/bin/pip install cffi==1.6.0 pyserial==3.2.1 greenlet==0.4.10
|
|
||||||
```
|
|
||||||
|
|
||||||
Building Klipper
|
|
||||||
================
|
|
||||||
|
|
||||||
To obtain Klipper, run the following command on the target machine:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/KevinOConnor/klipper
|
git clone https://github.com/KevinOConnor/klipper
|
||||||
cd klipper/
|
./klipper/scripts/install-octopi.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The above will download Klipper, install some system dependencies,
|
||||||
|
setup Klipper to run at system startup, and start the Klipper host
|
||||||
|
software. It will require an internet connection and it may take a few
|
||||||
|
minutes to complete.
|
||||||
|
|
||||||
|
Building the micro-controller code
|
||||||
|
==================================
|
||||||
|
|
||||||
To compile the micro-controller code, start by configuring it:
|
To compile the micro-controller code, start by configuring it:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
cd ~/klipper/
|
||||||
make menuconfig
|
make menuconfig
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -118,21 +107,10 @@ Enter the Settings tab again and under "Serial Connection" change the
|
||||||
"Serial Port" setting to "/tmp/printer". Change the Baudrate field to
|
"Serial Port" setting to "/tmp/printer". Change the Baudrate field to
|
||||||
250000 (this buad rate field is not related to the firmware baudrate
|
250000 (this buad rate field is not related to the firmware baudrate
|
||||||
and may be safely left at 250000). Unselect the "Not only cancel
|
and may be safely left at 250000). Unselect the "Not only cancel
|
||||||
ongoing prints but also disconnect..." checkbox.
|
ongoing prints but also disconnect..." checkbox. Click "Save".
|
||||||
|
|
||||||
Running the host software
|
From the main page, under the "Connection" window (at the top left of
|
||||||
=========================
|
the page) make sure the "Serial Port" is set to "/tmp/printer" and
|
||||||
|
|
||||||
The host software is executed by running the following as the regular
|
|
||||||
"pi" user:
|
|
||||||
|
|
||||||
```
|
|
||||||
~/klippy-env/bin/python ~/klipper/klippy/klippy.py ~/printer.cfg -l /tmp/klippy.log < /dev/null > /dev/null 2>&1 &
|
|
||||||
```
|
|
||||||
|
|
||||||
Once Klippy is running, use a web-browser and navigate to the
|
|
||||||
OctoPrint web site. Under the "Connection" tab (on the left of the
|
|
||||||
main page) make sure the "Serial Port" is set to "/tmp/printer" and
|
|
||||||
click "Connect". (If "/tmp/printer" is not an available selection then
|
click "Connect". (If "/tmp/printer" is not an available selection then
|
||||||
try reloading the page.)
|
try reloading the page.)
|
||||||
|
|
||||||
|
@ -142,7 +120,9 @@ the Klippy config file was successfully read, and the micro-controller
|
||||||
was successfully found and configured, then this command will report
|
was successfully found and configured, then this command will report
|
||||||
that the printer is ready. Klippy reports error messages via this
|
that the printer is ready. Klippy reports error messages via this
|
||||||
terminal tab. The "status" command can be used to re-report error
|
terminal tab. The "status" command can be used to re-report error
|
||||||
messages.
|
messages. The default Klipper startup script also places a log in
|
||||||
|
**/tmp/klippy.log** which may provide more detailed information should
|
||||||
|
an error occur.
|
||||||
|
|
||||||
In addition to common g-code commands, Klippy supports a few extended
|
In addition to common g-code commands, Klippy supports a few extended
|
||||||
commands - "status" is an example of one of these commands. Use the
|
commands - "status" is an example of one of these commands. Use the
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# This script installs Klipper on a Raspberry Pi machine running the
|
||||||
|
# OctoPi distribution.
|
||||||
|
|
||||||
|
PYTHONDIR="${HOME}/klippy-env"
|
||||||
|
|
||||||
|
# Step 1: Install system packages
|
||||||
|
install_packages()
|
||||||
|
{
|
||||||
|
# Packages for python cffi
|
||||||
|
PKGLIST="libffi-dev"
|
||||||
|
# kconfig requirements
|
||||||
|
PKGLIST="${PKGLIST} libncurses-dev"
|
||||||
|
# hub-ctrl
|
||||||
|
PKGLIST="${PKGLIST} libusb-dev"
|
||||||
|
# AVR chip installation and building
|
||||||
|
PKGLIST="${PKGLIST} avrdude gcc-avr binutils-avr avr-libc"
|
||||||
|
# ARM chip installation and building
|
||||||
|
PKGLIST="${PKGLIST} bossa-cli libnewlib-arm-none-eabi"
|
||||||
|
|
||||||
|
# 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 2: Create python virtual environment
|
||||||
|
create_virtualenv()
|
||||||
|
{
|
||||||
|
report_status "Updating python virtual environment..."
|
||||||
|
|
||||||
|
# Create virtualenv if it doesn't already exist
|
||||||
|
[ ! -d ${PYTHONDIR} ] && virtualenv ${PYTHONDIR}
|
||||||
|
|
||||||
|
# Install/update dependencies
|
||||||
|
${PYTHONDIR}/bin/pip install cffi==1.6.0 pyserial==3.2.1 greenlet==0.4.10
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 3: Install startup script
|
||||||
|
install_script()
|
||||||
|
{
|
||||||
|
report_status "Installing system start script..."
|
||||||
|
sudo cp "${SRCDIR}/scripts/klipper-start.sh" /etc/init.d/klipper
|
||||||
|
sudo update-rc.d klipper defaults
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 4: Install startup script config
|
||||||
|
install_config()
|
||||||
|
{
|
||||||
|
DEFAULTS_FILE=/etc/default/klipper
|
||||||
|
[ -f $DEFAULTS_FILE ] && return
|
||||||
|
|
||||||
|
report_status "Installing system start configuration..."
|
||||||
|
sudo /bin/sh -c "cat > $DEFAULTS_FILE" <<EOF
|
||||||
|
# Configuration for /etc/init.d/klipper
|
||||||
|
|
||||||
|
KLIPPY_USER=$USER
|
||||||
|
|
||||||
|
KLIPPY_EXEC=${PYTHONDIR}/bin/python
|
||||||
|
|
||||||
|
KLIPPY_ARGS="${SRCDIR}/klippy/klippy.py ${HOME}/printer.cfg -l /tmp/klippy.log"
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 5: Start host software
|
||||||
|
start_software()
|
||||||
|
{
|
||||||
|
report_status "Launching Klipper host software..."
|
||||||
|
sudo /etc/init.d/klipper restart
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
install_packages
|
||||||
|
create_virtualenv
|
||||||
|
install_script
|
||||||
|
install_config
|
||||||
|
start_software
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# System startup script for Klipper 3d-printer host code
|
||||||
|
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: klipper
|
||||||
|
# Required-Start: $local_fs
|
||||||
|
# Required-Stop:
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Klipper daemon
|
||||||
|
# Description: Starts the Klipper daemon.
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
DESC="klipper daemon"
|
||||||
|
NAME="klipper"
|
||||||
|
DEFAULTS_FILE=/etc/default/klipper
|
||||||
|
PIDFILE=/var/run/klipper.pid
|
||||||
|
|
||||||
|
. /lib/lsb/init-functions
|
||||||
|
|
||||||
|
# Read defaults file
|
||||||
|
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start) log_daemon_msg "Starting klipper" $NAME
|
||||||
|
start-stop-daemon --start --quiet --exec $KLIPPY_EXEC \
|
||||||
|
--background --pidfile $PIDFILE --make-pidfile \
|
||||||
|
--chuid $KLIPPY_USER --user $KLIPPY_USER \
|
||||||
|
-- $KLIPPY_ARGS
|
||||||
|
log_end_msg $?
|
||||||
|
;;
|
||||||
|
stop) log_daemon_msg "Stopping klipper" $NAME
|
||||||
|
killproc -p $PIDFILE $KLIPPY_EXEC
|
||||||
|
RETVAL=$?
|
||||||
|
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
|
||||||
|
log_end_msg $RETVAL
|
||||||
|
;;
|
||||||
|
restart) log_daemon_msg "Restarting klipper" $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 $KLIPPY_EXEC $NAME && exit 0 || exit $?
|
||||||
|
;;
|
||||||
|
*) log_action_msg "Usage: /etc/init.d/klipper {start|stop|status|restart|reload|force-reload}"
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
Loading…
Reference in New Issue