Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup-klipper.sh script for Octoprint 2.x #502

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions scripts/setup-klipper.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
#!/bin/bash
set -e
COL='\033[1;32m'
NC='\033[0m' # No Color
echo -e "${COL}Setting up klipper"

read -p "Do you have \"Plugin extras\" installed? (y/n): " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo -e "${COL}\nPlease go to settings and install plugin extras${NC}"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi

echo -e "${COL}\nInstalling dependencies...\n${NC}"
# install required dependencies
apk add py3-cffi py3-greenlet linux-headers can-utils
pip3 install python-can

echo -e "${COL}Downloading klipper\n${NC}"
curl -o klipper.zip -L https://github.com/Klipper3d/klipper/archive/refs/heads/master.zip

echo -e "${COL}Extracting klipper\n${NC}"
unzip klipper.zip
rm -rf klipper.zip
mv klipper-master /klipper
echo "# replace with your config" >> /root/printer.cfg

mkdir -p /root/extensions/klipper
cat << EOF > /root/extensions/klipper/manifest.json
echo -e "${COL}Setting up klipper for Octo4a v2.x"

# Prepare venv for klipper
python3 -m venv ~/klipper-venv

echo -e "${COL}\nDownloading klipper...\n${NC}"
cd ~/
git clone https://github.com/KevinOConnor/klipper

~/klipper-venv/bin/pip install -r ./klipper/scripts/klippy-requirements.txt

# Prepare necessary directories
mkdir ~/printer_data/
mkdir ~/printer_data/logs
mkdir ~/printer_data/gcodes
mkdir ~/printer_data/systemd
mkdir ~/printer_data/comms
touch ~/printer.cfg

echo -e "${COL}\nInserting configurations...\n${NC}"

mkdir -p /mnt/external/extensions/klipper
cat << EOF > /mnt/external/extensions/klipper/manifest.json
{
"title": "Klipper plugin",
"description": "Requires OctoKlipper plugin"
"description": "Runs Klipper"
}
EOF

cat << EOF > /root/extensions/klipper/start.sh
cat << EOF > /mnt/external/extensions/klipper/start.sh
#!/bin/sh
python3 /klipper/klippy/klippy.py /root/printer.cfg -l /tmp/klippy.log -a /tmp/klippy_uds
KLIPPER_ARGS="/root/klipper/klippy/klippy.py /root/printer.cfg -l /root/printer_data/logs/klippy.log -I /root/printer_data/comms/klippy.serial -a /root/printer_data/comms/klippy.sock"
LD_PRELOAD=/home/octoprint/ioctl-hook.so /root/klipper-venv/bin/python \$KLIPPER_ARGS &
EOF

cat << EOF > /root/extensions/klipper/kill.sh
cat << EOF > /mnt/external/extensions/klipper/kill.sh
#!/bin/sh
pkill -f 'klippy\.py'
EOF
chmod +x /root/extensions/klipper/start.sh
chmod +x /root/extensions/klipper/kill.sh
chmod 777 /root/extensions/klipper/start.sh
chmod 777 /root/extensions/klipper/kill.sh

chmod +x /mnt/external/extensions/klipper/start.sh
chmod +x /mnt/external/extensions/klipper/kill.sh
chmod 777 /mnt/external/extensions/klipper/start.sh
chmod 777 /mnt/external/extensions/klipper/kill.sh

cat << EOF
${COL}
Klipper installed!
Please place your own klipper config file at /root/printer.cfg
Please kill the app and restart it again to see it in extension settings${NC}

Set your OctoKlipper plugin settings:
Serial Port: /root/printer_data/comms/klippy.serial
Klipper Log File: /root/printer_data/logs/klippy.log
EOF