2024-04-08 04:50:36 +00:00
|
|
|
#!/bin/bash
|
2024-04-09 01:35:02 +00:00
|
|
|
|
|
|
|
# TODO: CHANGE KLIPPER PORTS
|
|
|
|
|
2024-07-30 01:18:31 +00:00
|
|
|
SOURCE=${BASH_SOURCE[0]}
|
|
|
|
while [ -L "$SOURCE" ]; do
|
|
|
|
TARGET=$(readlink "$SOURCE")
|
|
|
|
if [[ $TARGET == /* ]]; then
|
|
|
|
SOURCE=$TARGET
|
|
|
|
else
|
|
|
|
DIR=$( dirname "$SOURCE" )
|
|
|
|
SOURCE=$DIR/$TARGET
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
RDIR=$( dirname "$SOURCE" )
|
|
|
|
ROOT_DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
|
2024-04-08 04:50:36 +00:00
|
|
|
cd $ROOT_DIR
|
|
|
|
|
2024-08-06 00:47:48 +00:00
|
|
|
source ./ColorEchoForShell/dist/ColorEcho.bash
|
|
|
|
|
2024-04-08 04:50:36 +00:00
|
|
|
# Pull Klipper
|
|
|
|
git submodule update --init --recursive
|
|
|
|
|
2024-08-06 00:31:28 +00:00
|
|
|
|
|
|
|
# Name Printer
|
|
|
|
# Todo: avoid duplications
|
|
|
|
NAME_NOT_VALID=true
|
|
|
|
while $NAME_NOT_VALID ; do
|
|
|
|
PRINTER_NAME=$(dialog --backtitle 'drwho@hackers.town' --inputbox 'Name This Printer' 8 40 "${PRINTER_NAME}" 3>&1 1>&2 2>&3)
|
|
|
|
if [[ $PRINTER_NAME =~ ^[a-zA-Z0-9_-]+$ ]]; then
|
|
|
|
NAME_NOT_VALID=false
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
cp -r $ROOT_DIR/dirs $ROOT_DIR/$PRINTER_NAME
|
|
|
|
|
2024-04-08 04:50:36 +00:00
|
|
|
# Select Klipper Config
|
2024-08-06 00:31:28 +00:00
|
|
|
cd $ROOT_DIR/$PRINTER_NAME/klipper
|
2024-04-08 04:50:36 +00:00
|
|
|
make menuconfig
|
|
|
|
CONFIG_FILES=(`ls config`)
|
2024-04-30 00:37:05 +00:00
|
|
|
CONFIG_FILES+=("Enter_Manually")
|
2024-04-08 04:50:36 +00:00
|
|
|
let i=0
|
|
|
|
C=()
|
|
|
|
for f in ${CONFIG_FILES[@]}; do
|
|
|
|
C+=($i $f)
|
|
|
|
let i+=1
|
|
|
|
done
|
2024-04-30 00:37:05 +00:00
|
|
|
CONFIG_INDEX=$(dialog --backtitle "drwho@hackers.town" --title "Printer Selection" --menu "Select Printer Config" --output-fd 1 40 0 1 ${C[@]})
|
2024-04-08 04:50:36 +00:00
|
|
|
CONFIG_FILE=${CONFIG_FILES[$CONFIG_INDEX]}
|
2024-04-30 00:37:05 +00:00
|
|
|
if [[ $CONFIG_FILE == "Enter_Manually" ]]; then
|
|
|
|
MANUAL_FILE=""
|
|
|
|
while [ ! -f "${MANUAL_FILE}" ]; do
|
|
|
|
MANUAL_FILE=$(dialog --backtitle "drwho@hackers.town" --title "Manual Config Selection" --inputbox "Enter Full Config File Path" 8 40 "${MANUAL_FILE}" 3>&1 1>&2 2>&3)
|
|
|
|
done
|
|
|
|
CONFIG_FILE=$MANUAL_FILE
|
|
|
|
else
|
|
|
|
CONFIG_FILE="./config/$CONFIG_FILE"
|
|
|
|
fi
|
2024-04-08 04:50:36 +00:00
|
|
|
|
|
|
|
# Select Serial Device
|
|
|
|
DEVICES=(`ls /dev/serial/by-id/`)
|
2024-04-30 00:37:05 +00:00
|
|
|
DEVICES+=("Enter_Manually")
|
2024-04-08 04:50:36 +00:00
|
|
|
let i=0
|
|
|
|
C=()
|
|
|
|
for f in ${DEVICES[@]}; do
|
|
|
|
C+=($i $f)
|
|
|
|
let i+=1
|
|
|
|
done
|
2024-04-30 00:37:05 +00:00
|
|
|
DEVICE_INDEX=$(dialog --backtitle "drwho@hackers.town" --title "USB Device Selection" --menu "Select USB Device" --output-fd 1 40 0 1 ${C[@]})
|
2024-04-08 04:50:36 +00:00
|
|
|
DEVICE=${DEVICES[$DEVICE_INDEX]}
|
|
|
|
|
2024-04-30 00:37:05 +00:00
|
|
|
if [[ $DEVICE == "Enter_Manually" ]]; then
|
|
|
|
MANUAL_FILE=""
|
|
|
|
while [ ! -f "${MANUAL_FILE}" ]; do
|
|
|
|
MANUAL_FILE=$(dialog --backtitle "drwho@hackers.town" --title "Manual Device Selection" --inputbox "Enter Full Device File Path" 8 40 "${MANUAL_FILE}" 3>&1 1>&2 2>&3)
|
|
|
|
done
|
|
|
|
DEVICE=$MANUAL_FILE
|
|
|
|
fi
|
|
|
|
|
2024-04-08 04:50:36 +00:00
|
|
|
# Build Klipper
|
2024-08-06 00:31:28 +00:00
|
|
|
cp $CONFIG_FILE $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg
|
|
|
|
sed -i -e "s/^serial: .\+$/serial: \/dev\/serial\/by-id\/${DEVICE}/g" "${ROOT_DIR}/$PRINTER_NAME/klipper/printer.cfg"
|
2024-04-08 04:50:36 +00:00
|
|
|
make -j$(nproc)
|
|
|
|
|
|
|
|
# Flash Firmware
|
|
|
|
make flash FLASH_DEVICE=/dev/serial/by-id/$DEVICE
|
|
|
|
|
|
|
|
# Copy over printer config file
|
2024-08-06 00:47:48 +00:00
|
|
|
echo.Cyan "Setup printer.cfg"
|
2024-08-06 00:31:28 +00:00
|
|
|
cd $ROOT_DIR/$PRINTER_NAME
|
2024-04-09 01:22:35 +00:00
|
|
|
cat $ROOT_DIR/config/macros.gcode >> printer.cfg.tmp
|
|
|
|
cat klipper/printer.cfg >> printer.cfg.tmp
|
|
|
|
mv printer.cfg.tmp printer_data/config/printer.cfg
|
2024-04-08 04:50:36 +00:00
|
|
|
|
|
|
|
# Apply Edits to Configs
|
2024-08-06 00:56:06 +00:00
|
|
|
echo.Cyan "Setup Moonraker"
|
2024-08-06 00:31:28 +00:00
|
|
|
cd $ROOT_DIR/$PRINTER_NAME/printer_data/config
|
2024-07-30 01:18:31 +00:00
|
|
|
sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "moonraker.conf"
|
2024-08-06 00:31:28 +00:00
|
|
|
sed -i -e "s/pi/$USER/g" "moonraker.conf"
|
2024-08-06 01:07:52 +00:00
|
|
|
|
2024-08-06 00:47:48 +00:00
|
|
|
echo.Cyan "Setup Mainsail Config"
|
2024-08-06 00:31:28 +00:00
|
|
|
cd $ROOT_DIR/$PRINTER_NAME/mainsail-config
|
2024-08-06 01:24:18 +00:00
|
|
|
# USABLE_HOME=`echo "$HOME" | sed -e 's/\//\\\\\\\\\//g'`
|
|
|
|
# echo "s/~\/printer_data/$USABLE_HOME\/$PRINTER_NAME\/printer_data/g"
|
|
|
|
# sed -i -e "s/~\/printer_data/$USABLE_HOME\/$PRINTER_NAME\/printer_data/g" "client.cfg"
|
|
|
|
cat "client.cfg" | replace "~/printer_data" "$HOME/$PRINTER_NAME/printer_data" > tmp.client.cfg
|
|
|
|
rm client.cfg
|
|
|
|
mv tmp.client.cfg client.cfg
|
2024-08-06 00:31:28 +00:00
|
|
|
sed -i -e "s/pi/$USER/g" "client.cfg"
|
2024-04-09 01:22:35 +00:00
|
|
|
|
2024-04-09 00:31:37 +00:00
|
|
|
# Download Mainsail
|
|
|
|
cd $ROOT_DIR
|
2024-08-06 00:47:48 +00:00
|
|
|
echo.Cyan "Downloading Mainsail"
|
2024-04-09 00:31:37 +00:00
|
|
|
wget -q -O mainsail.zip https://github.com/mainsail-crew/mainsail/releases/latest/download/mainsail.zip
|
2024-08-06 00:31:28 +00:00
|
|
|
unzip -o mainsail.zip -d $PRINTER_NAME/mainsail
|
|
|
|
rm mainsail.zip
|
2024-04-09 00:47:55 +00:00
|
|
|
|
2024-04-09 01:22:35 +00:00
|
|
|
# Copy To Final Location
|
2024-08-06 00:47:48 +00:00
|
|
|
echo.Cyan "Run Copy"
|
2024-08-06 00:31:28 +00:00
|
|
|
mkdir -p $HOME/$PRINTER_NAME
|
|
|
|
cp -r $PRINTER_NAME/* $HOME/$PRINTER_NAME
|
2024-04-09 01:22:35 +00:00
|
|
|
|
2024-08-06 00:56:06 +00:00
|
|
|
# Create Empty dirs
|
|
|
|
dirs=(logs gcodes certs backup mainsail-config)
|
|
|
|
for d in ${dirs[@]}; do
|
2024-08-06 00:31:28 +00:00
|
|
|
mkdir -p "$HOME/$PRINTER_NAME/$d"
|
2024-04-09 01:22:35 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Configure System Services
|
2024-08-06 00:56:06 +00:00
|
|
|
|
|
|
|
# cd $ROOT_DIR/config/services
|
|
|
|
# TODO: Add Crowsnest Support
|
|
|
|
# FILES=(moonraker klipper)
|
|
|
|
# for f in ${FILES[@]}; do
|
|
|
|
# echo.ICyan "Configuring ${f}"
|
|
|
|
# sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${f}.service"
|
|
|
|
# sed -i -e "s/pi/$USER/g" "${f}.service"
|
|
|
|
# done
|
|
|
|
|
2024-04-09 01:22:35 +00:00
|
|
|
cd $ROOT_DIR/config/services
|
|
|
|
SERVICES=()
|
|
|
|
for f in *.service; do
|
2024-08-06 00:47:48 +00:00
|
|
|
echo.Cyan "Setup ${f}"
|
2024-04-09 01:22:35 +00:00
|
|
|
SERVICES+=($f)
|
2024-08-06 00:31:28 +00:00
|
|
|
cp "${f}" "${ROOT_DIR}/${PRINTER_NAME}/${PRINTER_NAME}-${f}"
|
|
|
|
sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${ROOT_DIR}/${PRINTER_NAME}/${PRINTER_NAME}-${f}"
|
2024-08-06 00:56:06 +00:00
|
|
|
sed -i -e "s/pi/$USER/g" "${ROOT_DIR}/${PRINTER_NAME}/${PRINTER_NAME}-${f}"
|
2024-04-09 01:22:35 +00:00
|
|
|
done
|
|
|
|
|
2024-04-09 00:47:55 +00:00
|
|
|
# Install System Services
|
2024-08-06 00:47:48 +00:00
|
|
|
echo.Cyan "Install Services"
|
2024-08-06 00:31:28 +00:00
|
|
|
sudo cp $ROOT_DIR/$PRINTER_NAME/*.service /etc/systemd/system/
|
2024-04-09 01:22:35 +00:00
|
|
|
sudo systemctl daemon-reload
|
|
|
|
for svc in ${SERVICES[@]}; do
|
|
|
|
sudo systemctl enable $PRINTER_NAME-$svc
|
|
|
|
sudo systemctl start $PRINTER_NAME-$svc
|
|
|
|
done
|
2024-07-30 01:18:31 +00:00
|
|
|
|
|
|
|
# Cleanup
|