Use temp dir

This commit is contained in:
Elizabeth Cray 2024-08-05 20:31:28 -04:00
parent 14812d2432
commit 9e74bf51cd

View File

@ -19,8 +19,21 @@ cd $ROOT_DIR
# Pull Klipper # Pull Klipper
git submodule update --init --recursive git submodule update --init --recursive
# 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
# Select Klipper Config # Select Klipper Config
cd $ROOT_DIR/dirs/klipper cd $ROOT_DIR/$PRINTER_NAME/klipper
make menuconfig make menuconfig
CONFIG_FILES=(`ls config`) CONFIG_FILES=(`ls config`)
CONFIG_FILES+=("Enter_Manually") CONFIG_FILES+=("Enter_Manually")
@ -62,57 +75,51 @@ if [[ $DEVICE == "Enter_Manually" ]]; then
DEVICE=$MANUAL_FILE DEVICE=$MANUAL_FILE
fi fi
# 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
# Build Klipper # Build Klipper
cp $CONFIG_FILE $ROOT_DIR/dirs/klipper/printer.cfg cp $CONFIG_FILE $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg
sed -i -e "s/^serial: .\+$/serial: \/dev\/serial\/by-id\/${DEVICE}/g" "${ROOT_DIR}/dirs/klipper/printer.cfg" sed -i -e "s/^serial: .\+$/serial: \/dev\/serial\/by-id\/${DEVICE}/g" "${ROOT_DIR}/$PRINTER_NAME/klipper/printer.cfg"
make -j$(nproc) make -j$(nproc)
# Flash Firmware # Flash Firmware
make flash FLASH_DEVICE=/dev/serial/by-id/$DEVICE make flash FLASH_DEVICE=/dev/serial/by-id/$DEVICE
# Copy over printer config file # Copy over printer config file
cd $ROOT_DIR/dirs cd $ROOT_DIR/$PRINTER_NAME
cat $ROOT_DIR/config/macros.gcode >> printer.cfg.tmp cat $ROOT_DIR/config/macros.gcode >> printer.cfg.tmp
cat klipper/printer.cfg >> printer.cfg.tmp cat klipper/printer.cfg >> printer.cfg.tmp
mv printer.cfg.tmp printer_data/config/printer.cfg mv printer.cfg.tmp printer_data/config/printer.cfg
# Apply Edits to Configs # Apply Edits to Configs
cd $ROOT_DIR/dirs/printer_data/config cd $ROOT_DIR/$PRINTER_NAME/printer_data/config
sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "moonraker.conf" sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "moonraker.conf"
sed -i -e "s/pi/$USER/g" "moonraker.conf"
cd $ROOT_DIR/dirs/mainsail-config cd $ROOT_DIR/$PRINTER_NAME/mainsail-config
sed -i -e "s/~\/printer_data/~\/$PRINTER_NAME\/printer_data/g" "client.cfg" sed -i -e "s/$HOME\/printer_data/$HOME\/$PRINTER_NAME\/printer_data/g" "client.cfg"
sed -i -e "s/pi/$USER/g" "client.cfg"
cd $ROOT_DIR/config/services cd $ROOT_DIR/config/services
# TODO: Add Crowsnest Support # TODO: Add Crowsnest Support
FILES=(moonraker klipper) FILES=(moonraker klipper)
for f in ${FILES[@]}; do for f in ${FILES[@]}; do
sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${f}.service" sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${f}.service"
sed -i -e "s/pi/$USER/g" "${f}.service"
done done
# Download Mainsail # Download Mainsail
cd $ROOT_DIR cd $ROOT_DIR
wget -q -O mainsail.zip https://github.com/mainsail-crew/mainsail/releases/latest/download/mainsail.zip wget -q -O mainsail.zip https://github.com/mainsail-crew/mainsail/releases/latest/download/mainsail.zip
unzip -o mainsail.zip -d dirs/mainsail unzip -o mainsail.zip -d $PRINTER_NAME/mainsail
rm mainsail.zip
# Copy To Final Location # Copy To Final Location
mkdir -p ~/$PRINTER_NAME mkdir -p $HOME/$PRINTER_NAME
cp -r dirs/* ~/$PRINTER_NAME cp -r $PRINTER_NAME/* $HOME/$PRINTER_NAME
# Create Empty Dirs # Create Empty $PRINTER_NAME
DIRS=(logs gcodes certs backup mainsail-config) $PRINTER_NAME=(logs gcodes certs backup mainsail-config)
for d in ${DIRS[@]}; do for d in ${$PRINTER_NAME[@]}; do
mkdir -p "~/$PRINTER_NAME/$d" mkdir -p "$HOME/$PRINTER_NAME/$d"
done done
# Configure System Services # Configure System Services
@ -120,12 +127,12 @@ cd $ROOT_DIR/config/services
SERVICES=() SERVICES=()
for f in *.service; do for f in *.service; do
SERVICES+=($f) SERVICES+=($f)
cp "${f}" "${PRINTER_NAME}-${f}" cp "${f}" "${ROOT_DIR}/${PRINTER_NAME}/${PRINTER_NAME}-${f}"
sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${PRINTER_NAME}-${f}" sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${ROOT_DIR}/${PRINTER_NAME}/${PRINTER_NAME}-${f}"
done done
# Install System Services # Install System Services
sudo cp $ROOT_DIR/config/services/* /etc/systemd/system/ sudo cp $ROOT_DIR/$PRINTER_NAME/*.service /etc/systemd/system/
sudo systemctl daemon-reload sudo systemctl daemon-reload
for svc in ${SERVICES[@]}; do for svc in ${SERVICES[@]}; do
sudo systemctl enable $PRINTER_NAME-$svc sudo systemctl enable $PRINTER_NAME-$svc
@ -133,4 +140,3 @@ for svc in ${SERVICES[@]}; do
done done
# Cleanup # Cleanup
rm -rf "${ROOT_DIR}/mainsail.zip"