aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorNathan <nathan@vertile.com>2019-01-05 20:03:59 -0800
committerKevinOConnor <kevin@koconnor.net>2019-01-10 09:38:15 -0500
commitc9c8ae049965eba91fe6a4d548643e9010331740 (patch)
tree394e8ec9296bb71999248a3030d653d824f8abe6 /scripts
parent2ea7c97bbd3680949a2d89c3c9ab3a2552a25b4b (diff)
downloadkutter-c9c8ae049965eba91fe6a4d548643e9010331740.tar.gz
kutter-c9c8ae049965eba91fe6a4d548643e9010331740.tar.xz
kutter-c9c8ae049965eba91fe6a4d548643e9010331740.zip
Ubuntu 18.04 install script
Signed-off-by: Nathan Tsoi <nathan@vertile.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install-ubuntu-18.04.sh104
1 files changed, 104 insertions, 0 deletions
diff --git a/scripts/install-ubuntu-18.04.sh b/scripts/install-ubuntu-18.04.sh
new file mode 100755
index 00000000..0c211dab
--- /dev/null
+++ b/scripts/install-ubuntu-18.04.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+# This script installs Klipper on an Ubuntu 18.04 machine with Octoprint
+# Assumes the user running this is named "octoprint"
+
+PYTHONDIR="${HOME}/klippy-env"
+SYSTEMDDIR="/etc/systemd/system"
+KLIPPER_USER="octoprint"
+KLIPPER_GROUP=$KLIPPER_USER
+
+# Step 1: Install system packages
+install_packages()
+{
+ # Packages for python cffi
+ PKGLIST="python-virtualenv virtualenv python-dev libffi-dev build-essential"
+ # 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} stm32flash libnewlib-arm-none-eabi"
+ PKGLIST="${PKGLIST} gcc-arm-none-eabi binutils-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()
+{
+# Create systemd service file
+ KLIPPER_LOG=/var/log/klippy.log
+ report_status "Installing system start script..."
+ sudo touch $KLIPPER_LOG && sudo chown $KLIPPER_USER:$KLIPPER_GROUP $KLIPPER_LOG
+ sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << EOF
+#Systemd service file for klipper
+[Unit]
+Description=Starts klipper on startup
+After=network.target
+
+[Install]
+WantedBy=multi-user.target
+
+[Service]
+Type=simple
+User=$KLIPPER_USER
+RemainAfterExit=yes
+ExecStart=${PYTHONDIR}/bin/python ${SRCDIR}/klippy/klippy.py ${HOME}/printer.cfg -l ${KLIPPER_LOG}
+EOF
+# Use systemctl to enable the klipper systemd service script
+ sudo systemctl enable klipper.service
+}
+
+# Step 4: Start host software
+start_software()
+{
+ report_status "Launching Klipper host software..."
+ sudo systemctl start klipper
+}
+
+# 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
+start_software