Skip to content

Commit ec805ae

Browse files
committedApr 21, 2017
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>
1 parent 167b18b commit ec805ae

File tree

3 files changed

+172
-36
lines changed

3 files changed

+172
-36
lines changed
 

‎docs/Installation.md

+16-36
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,29 @@ Raspberry Pi computer. Use OctoPi v0.13.0 or later - see the
1616
[octopi releases](https://github.com/guysoft/OctoPi/releases) for
1717
release information. One should verify that OctoPi boots and that the
1818
OctoPrint web server works. After connecting to the OctoPrint web
19-
page, follow the prompt to upgrade OctoPrint to v1.3.0 or later.
19+
page, follow the prompt to upgrade OctoPrint to v1.3.2 or later.
2020

2121
After installing OctoPi and upgrading OctoPrint, ssh into the target
2222
machine (ssh pi@octopi -- password is "raspberry") and run the
2323
following commands:
2424

2525
```
26-
sudo apt-get update
27-
sudo apt-get install libncurses-dev libusb-dev
28-
sudo apt-get install avrdude gcc-avr binutils-avr avr-libc # AVR toolchain
29-
sudo apt-get install bossa-cli libnewlib-arm-none-eabi # ARM toolchain
30-
```
31-
32-
The host software (Klippy) requires a one-time setup - run as the
33-
regular "pi" user:
34-
35-
```
36-
virtualenv ~/klippy-env
37-
~/klippy-env/bin/pip install cffi==1.6.0 pyserial==3.2.1 greenlet==0.4.10
26+
git clone https://github.com/KevinOConnor/klipper
27+
./klipper/scripts/install-octopi.sh
3828
```
3929

40-
Building Klipper
41-
================
42-
43-
To obtain Klipper, run the following command on the target machine:
30+
The above will download Klipper, install some system dependencies,
31+
setup Klipper to run at system startup, and start the Klipper host
32+
software. It will require an internet connection and it may take a few
33+
minutes to complete.
4434

45-
```
46-
git clone https://github.com/KevinOConnor/klipper
47-
cd klipper/
48-
```
35+
Building the micro-controller code
36+
==================================
4937

5038
To compile the micro-controller code, start by configuring it:
5139

5240
```
41+
cd ~/klipper/
5342
make menuconfig
5443
```
5544

@@ -118,21 +107,10 @@ Enter the Settings tab again and under "Serial Connection" change the
118107
"Serial Port" setting to "/tmp/printer". Change the Baudrate field to
119108
250000 (this buad rate field is not related to the firmware baudrate
120109
and may be safely left at 250000). Unselect the "Not only cancel
121-
ongoing prints but also disconnect..." checkbox.
122-
123-
Running the host software
124-
=========================
125-
126-
The host software is executed by running the following as the regular
127-
"pi" user:
128-
129-
```
130-
~/klippy-env/bin/python ~/klipper/klippy/klippy.py ~/printer.cfg -l /tmp/klippy.log < /dev/null > /dev/null 2>&1 &
131-
```
110+
ongoing prints but also disconnect..." checkbox. Click "Save".
132111

133-
Once Klippy is running, use a web-browser and navigate to the
134-
OctoPrint web site. Under the "Connection" tab (on the left of the
135-
main page) make sure the "Serial Port" is set to "/tmp/printer" and
112+
From the main page, under the "Connection" window (at the top left of
113+
the page) make sure the "Serial Port" is set to "/tmp/printer" and
136114
click "Connect". (If "/tmp/printer" is not an available selection then
137115
try reloading the page.)
138116

@@ -142,7 +120,9 @@ the Klippy config file was successfully read, and the micro-controller
142120
was successfully found and configured, then this command will report
143121
that the printer is ready. Klippy reports error messages via this
144122
terminal tab. The "status" command can be used to re-report error
145-
messages.
123+
messages. The default Klipper startup script also places a log in
124+
**/tmp/klippy.log** which may provide more detailed information should
125+
an error occur.
146126

147127
In addition to common g-code commands, Klippy supports a few extended
148128
commands - "status" is an example of one of these commands. Use the

‎scripts/install-octopi.sh

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
# This script installs Klipper on a Raspberry Pi machine running the
3+
# OctoPi distribution.
4+
5+
PYTHONDIR="${HOME}/klippy-env"
6+
7+
# Step 1: Install system packages
8+
install_packages()
9+
{
10+
# Packages for python cffi
11+
PKGLIST="libffi-dev"
12+
# kconfig requirements
13+
PKGLIST="${PKGLIST} libncurses-dev"
14+
# hub-ctrl
15+
PKGLIST="${PKGLIST} libusb-dev"
16+
# AVR chip installation and building
17+
PKGLIST="${PKGLIST} avrdude gcc-avr binutils-avr avr-libc"
18+
# ARM chip installation and building
19+
PKGLIST="${PKGLIST} bossa-cli libnewlib-arm-none-eabi"
20+
21+
# Update system package info
22+
report_status "Running apt-get update..."
23+
sudo apt-get update
24+
25+
# Install desired packages
26+
report_status "Installing packages..."
27+
sudo apt-get install --yes ${PKGLIST}
28+
}
29+
30+
# Step 2: Create python virtual environment
31+
create_virtualenv()
32+
{
33+
report_status "Updating python virtual environment..."
34+
35+
# Create virtualenv if it doesn't already exist
36+
[ ! -d ${PYTHONDIR} ] && virtualenv ${PYTHONDIR}
37+
38+
# Install/update dependencies
39+
${PYTHONDIR}/bin/pip install cffi==1.6.0 pyserial==3.2.1 greenlet==0.4.10
40+
}
41+
42+
# Step 3: Install startup script
43+
install_script()
44+
{
45+
report_status "Installing system start script..."
46+
sudo cp "${SRCDIR}/scripts/klipper-start.sh" /etc/init.d/klipper
47+
sudo update-rc.d klipper defaults
48+
}
49+
50+
# Step 4: Install startup script config
51+
install_config()
52+
{
53+
DEFAULTS_FILE=/etc/default/klipper
54+
[ -f $DEFAULTS_FILE ] && return
55+
56+
report_status "Installing system start configuration..."
57+
sudo /bin/sh -c "cat > $DEFAULTS_FILE" <<EOF
58+
# Configuration for /etc/init.d/klipper
59+
60+
KLIPPY_USER=$USER
61+
62+
KLIPPY_EXEC=${PYTHONDIR}/bin/python
63+
64+
KLIPPY_ARGS="${SRCDIR}/klippy/klippy.py ${HOME}/printer.cfg -l /tmp/klippy.log"
65+
66+
EOF
67+
}
68+
69+
# Step 5: Start host software
70+
start_software()
71+
{
72+
report_status "Launching Klipper host software..."
73+
sudo /etc/init.d/klipper restart
74+
}
75+
76+
# Helper functions
77+
report_status()
78+
{
79+
echo -e "\n\n###### $1"
80+
}
81+
82+
verify_ready()
83+
{
84+
if [ "$EUID" -eq 0 ]; then
85+
echo "This script must not run as root"
86+
exit -1
87+
fi
88+
}
89+
90+
# Force script to exit if an error occurs
91+
set -e
92+
93+
# Find SRCDIR from the pathname of this script
94+
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
95+
96+
# Run installation steps defined above
97+
verify_ready
98+
install_packages
99+
create_virtualenv
100+
install_script
101+
install_config
102+
start_software

‎scripts/klipper-start.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
# System startup script for Klipper 3d-printer host code
3+
4+
### BEGIN INIT INFO
5+
# Provides: klipper
6+
# Required-Start: $local_fs
7+
# Required-Stop:
8+
# Default-Start: 2 3 4 5
9+
# Default-Stop: 0 1 6
10+
# Short-Description: Klipper daemon
11+
# Description: Starts the Klipper daemon.
12+
### END INIT INFO
13+
14+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
15+
DESC="klipper daemon"
16+
NAME="klipper"
17+
DEFAULTS_FILE=/etc/default/klipper
18+
PIDFILE=/var/run/klipper.pid
19+
20+
. /lib/lsb/init-functions
21+
22+
# Read defaults file
23+
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
24+
25+
case "$1" in
26+
start) log_daemon_msg "Starting klipper" $NAME
27+
start-stop-daemon --start --quiet --exec $KLIPPY_EXEC \
28+
--background --pidfile $PIDFILE --make-pidfile \
29+
--chuid $KLIPPY_USER --user $KLIPPY_USER \
30+
-- $KLIPPY_ARGS
31+
log_end_msg $?
32+
;;
33+
stop) log_daemon_msg "Stopping klipper" $NAME
34+
killproc -p $PIDFILE $KLIPPY_EXEC
35+
RETVAL=$?
36+
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
37+
log_end_msg $RETVAL
38+
;;
39+
restart) log_daemon_msg "Restarting klipper" $NAME
40+
$0 stop
41+
$0 start
42+
;;
43+
reload|force-reload)
44+
log_daemon_msg "Reloading configuration not supported" $NAME
45+
log_end_msg 1
46+
;;
47+
status)
48+
status_of_proc -p $PIDFILE $KLIPPY_EXEC $NAME && exit 0 || exit $?
49+
;;
50+
*) log_action_msg "Usage: /etc/init.d/klipper {start|stop|status|restart|reload|force-reload}"
51+
exit 2
52+
;;
53+
esac
54+
exit 0

0 commit comments

Comments
 (0)