From 69e2e9bc56967be4bc9757c7ebb7eb62b5876e56 Mon Sep 17 00:00:00 2001 From: Travis Baker Date: Tue, 17 Sep 2024 23:03:36 -0500 Subject: [PATCH] initial rework for env variables Signed-off-by: Travis Baker --- scripts/flash-path.sh | 8 ++- scripts/generate-belt-tension-graph.sh | 7 ++- scripts/generate-shaper-graph-x.sh | 8 ++- scripts/generate-shaper-graph-y.sh | 8 ++- scripts/idex-generate-belt-tension-graph.sh | 11 ++-- scripts/idex-generate-shaper-graph.sh | 31 ++++----- scripts/moonraker-ensure-policykit-rules.sh | 9 ++- scripts/ratos-common.sh | 70 +++++++++++++-------- scripts/ratos-install.sh | 6 +- scripts/ratos-update.sh | 6 +- 10 files changed, 102 insertions(+), 62 deletions(-) diff --git a/scripts/flash-path.sh b/scripts/flash-path.sh index 575793809..986f6f1f3 100755 --- a/scripts/flash-path.sh +++ b/scripts/flash-path.sh @@ -1,4 +1,8 @@ #!/bin/bash + +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + MCU=$1 if [ "$EUID" -ne 0 ] then echo "ERROR: Please run as root" @@ -8,7 +12,7 @@ if [ "$MCU" == "" ]; then echo "ERROR: Please specify a device to flash" exit 1 fi -pushd /home/pi/klipper || exit +pushd ${KLIPPER_DIR} || exit service klipper stop dfuDevicesPreFlash=$(lsusb | grep -c "0483:df11") if [ -h "$MCU" ]; then @@ -35,7 +39,7 @@ if [ $retVal -eq 0 ]; then else echo "Flashing failed." fi -chown pi:pi -R /home/pi/klipper +chown ${RATOS_USERNAME}:${RATOS_USERGROUP} -R ${KLIPPER_DIR} service klipper start popd || exit exit $retVal diff --git a/scripts/generate-belt-tension-graph.sh b/scripts/generate-belt-tension-graph.sh index d2fc502d7..930773035 100755 --- a/scripts/generate-belt-tension-graph.sh +++ b/scripts/generate-belt-tension-graph.sh @@ -2,6 +2,9 @@ set -e -u SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + ## the TEST_RESONANCES command seems to return before all data is completely ## written. it'd be better to poll for the files to be completely written, ## but this has been reliable for me so far… @@ -10,12 +13,12 @@ sleep 10 outdir="${SCRIPT_DIR}"/../../input_shaper if [ ! -d "${outdir}" ]; then mkdir "${outdir}" - chown pi:pi "$SCRIPT_DIR"/../../input_shaper + chown ${RATOS_USERNAME}:${RATOS_USERGROUP} "$SCRIPT_DIR"/../../input_shaper fi NEWUPPER=$(find /tmp -name "raw_data_axis*_belt-tension-upper.csv" -printf '%T@ %p\n' 2> /dev/null | sort -n | tail -1 | cut -f2- -d" ") NEWLOWER=$(find /tmp -name "raw_data_axis*_belt-tension-lower.csv" -printf '%T@ %p\n' 2> /dev/null | sort -n | tail -1 | cut -f2- -d" ") -~/klipper/scripts/graph_accelerometer.py \ +${KLIPPER_DIR}/scripts/graph_accelerometer.py \ -c "$NEWLOWER" "$NEWUPPER" \ -o "${outdir}/belt-tension-resonances-$( date +'%Y-%m-%d-%H%M%S' ).png" diff --git a/scripts/generate-shaper-graph-x.sh b/scripts/generate-shaper-graph-x.sh index 8096227cb..a20f0368b 100755 --- a/scripts/generate-shaper-graph-x.sh +++ b/scripts/generate-shaper-graph-x.sh @@ -1,12 +1,16 @@ #!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + NEWX=$(find /tmp -name "resonances_x_*.csv" -printf '%T@ %p\n' 2> /dev/null | sort -n | tail -1 | cut -f2- -d" ") DATE=$(date +'%Y-%m-%d-%H%M%S') if [ ! -d "$SCRIPT_DIR/../../input_shaper" ] then mkdir "$SCRIPT_DIR"/../../input_shaper - chown pi:pi "$SCRIPT_DIR"/../../input_shaper + chown ${RATOS_USERNAME}:${RATOS_USERGROUP} "$SCRIPT_DIR"/../../input_shaper fi -~/klipper/scripts/calibrate_shaper.py "$NEWX" -o "$SCRIPT_DIR"/../../input_shaper/resonances_x_"$DATE".png +${KLIPPER_DIR}/scripts/calibrate_shaper.py "$NEWX" -o "$SCRIPT_DIR"/../../input_shaper/resonances_x_"$DATE".png diff --git a/scripts/generate-shaper-graph-y.sh b/scripts/generate-shaper-graph-y.sh index 86002d328..00a45cb04 100755 --- a/scripts/generate-shaper-graph-y.sh +++ b/scripts/generate-shaper-graph-y.sh @@ -1,12 +1,16 @@ #!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + NEWY=$(find /tmp -name "resonances_y_*.csv" -printf '%T@ %p\n' 2> /dev/null | sort -n | tail -1 | cut -f2- -d" ") DATE=$(date +'%Y-%m-%d-%H%M%S') if [ ! -d "$SCRIPT_DIR/../../input_shaper" ] then mkdir "$SCRIPT_DIR"/../../input_shaper - chown pi:pi "$SCRIPT_DIR"/../../input_shaper + chown ${RATOS_USERNAME}:${RATOS_USERGROUP} "$SCRIPT_DIR"/../../input_shaper fi -~/klipper/scripts/calibrate_shaper.py "$NEWY" -o "$SCRIPT_DIR"/../../input_shaper/resonances_y_"$DATE".png +${KLIPPER_DIR}/scripts/calibrate_shaper.py "$NEWY" -o "$SCRIPT_DIR"/../../input_shaper/resonances_y_"$DATE".png diff --git a/scripts/idex-generate-belt-tension-graph.sh b/scripts/idex-generate-belt-tension-graph.sh index 4417772e7..a076b7a9e 100755 --- a/scripts/idex-generate-belt-tension-graph.sh +++ b/scripts/idex-generate-belt-tension-graph.sh @@ -1,5 +1,8 @@ #!/bin/bash +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + DISABLE_Y=0 DISABLE_X=0 @@ -12,9 +15,9 @@ then DISABLE_X=1 fi -if [ ! -d "/home/pi/printer_data/config/input_shaper" ] +if [ ! -d "${RATOS_PRINTER_DATA_DIR}/config/input_shaper" ] then - mkdir /home/pi/printer_data/config/input_shaper + mkdir ${RATOS_PRINTER_DATA_DIR}/config/input_shaper fi T0=1 @@ -80,7 +83,7 @@ then fi fi - /home/pi/klipper/scripts/graph_accelerometer.py -c /tmp/*_y_belt_tension.csv -o /home/pi/printer_data/config/input_shaper/y_tension_comparison_"$DATE".png + ${KLIPPER_DIR}/scripts/graph_accelerometer.py -c /tmp/*_y_belt_tension.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/y_tension_comparison_"$DATE".png fi if [ $DISABLE_X -eq 0 ] then @@ -107,5 +110,5 @@ then mv /tmp/raw_data_x_toolboard_t1_t1.csv /tmp/right_x_belt_tension.csv fi - /home/pi/klipper/scripts/graph_accelerometer.py -c /tmp/*_x_belt_tension.csv -o /home/pi/printer_data/config/input_shaper/x_tension_comparison_"$DATE".png + ${KLIPPER_DIR}/scripts/graph_accelerometer.py -c /tmp/*_x_belt_tension.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/x_tension_comparison_"$DATE".png fi \ No newline at end of file diff --git a/scripts/idex-generate-shaper-graph.sh b/scripts/idex-generate-shaper-graph.sh index 72ea0c53f..b95959872 100755 --- a/scripts/idex-generate-shaper-graph.sh +++ b/scripts/idex-generate-shaper-graph.sh @@ -1,5 +1,8 @@ #!/bin/bash +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + DISABLE_Y=0 DISABLE_X=0 @@ -12,9 +15,9 @@ then DISABLE_X=1 fi -if [ ! -d "/home/pi/printer_data/config/input_shaper" ] +if [ ! -d "${RATOS_PRINTER_DATA_DIR}/config/input_shaper" ] then - mkdir /home/pi/printer_data/config/input_shaper + mkdir ${RATOS_PRINTER_DATA_DIR}/config/input_shaper fi T0=1 @@ -59,7 +62,7 @@ then fi mv "/tmp/resonances_y_$4_$5_$6_t0.csv" /tmp/t0_y.csv echo "please wait..." - /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_y.csv -o /home/pi/printer_data/config/input_shaper/t0_resonances_y_"$DATE".png + ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t0_y.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t0_resonances_y_"$DATE".png fi if [ $T1 -eq 1 ] @@ -71,7 +74,7 @@ then fi mv "/tmp/resonances_y_$4_$5_$6_t1.csv" /tmp/t1_y.csv echo "please wait..." - /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_y.csv -o /home/pi/printer_data/config/input_shaper/t1_resonances_y_"$DATE".png + ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t1_y.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t1_resonances_y_"$DATE".png fi fi @@ -86,7 +89,7 @@ then fi echo "please wait..." mv "/tmp/resonances_y_$4_$5_$6_t0_copy.csv" /tmp/t0_copy_y.csv - [ -e "/tmp/t0_copy_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_copy_y.csv -o /home/pi/printer_data/config/input_shaper/t0_copy_resonances_y_"$DATE".png + [ -e "/tmp/t0_copy_y.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t0_copy_y.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t0_copy_resonances_y_"$DATE".png fi if [ $T1 -eq 1 ] then @@ -97,7 +100,7 @@ then fi echo "please wait..." mv "/tmp/resonances_y_$4_$5_$6_t1_copy.csv" /tmp/t1_copy_y.csv - [ -e "/tmp/t1_copy_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_copy_y.csv -o /home/pi/printer_data/config/input_shaper/t1_copy_resonances_y_"$DATE".png + [ -e "/tmp/t1_copy_y.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t1_copy_y.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t1_copy_resonances_y_"$DATE".png fi fi @@ -112,7 +115,7 @@ then fi echo "please wait..." mv "/tmp/resonances_y_$4_$5_$6_t0_mirror.csv" /tmp/t0_mirror_y.csv - [ -e "/tmp/t0_mirror_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_mirror_y.csv -o /home/pi/printer_data/config/input_shaper/t0_mirror_resonances_y_"$DATE".png + [ -e "/tmp/t0_mirror_y.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t0_mirror_y.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t0_mirror_resonances_y_"$DATE".png fi if [ $T1 -eq 1 ] then @@ -123,7 +126,7 @@ then fi echo "please wait..." mv "/tmp/resonances_y_$4_$5_$6_t1_mirror.csv" /tmp/t1_mirror_y.csv - [ -e "/tmp/t1_mirror_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_mirror_y.csv -o /home/pi/printer_data/config/input_shaper/t1_mirror_resonances_y_"$DATE".png + [ -e "/tmp/t1_mirror_y.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t1_mirror_y.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t1_mirror_resonances_y_"$DATE".png fi fi fi @@ -149,7 +152,7 @@ then fi mv "/tmp/resonances_x_$4_$5_$6_t0.csv" /tmp/t0_x.csv echo "please wait..." - /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_x.csv -o /home/pi/printer_data/config/input_shaper/t0_resonances_x_"$DATE".png + ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t0_x.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t0_resonances_x_"$DATE".png fi if [ $T1 -eq 1 ] @@ -161,7 +164,7 @@ then fi mv "/tmp/resonances_x_$4_$5_$6_t1.csv" /tmp/t1_x.csv echo "please wait..." - /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_x.csv -o /home/pi/printer_data/config/input_shaper/t1_resonances_x_"$DATE".png + ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t1_x.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t1_resonances_x_"$DATE".png fi fi @@ -176,7 +179,7 @@ then fi echo "please wait..." mv "/tmp/resonances_x_$4_$5_$6_t0_copy.csv" /tmp/t0_copy_x.csv - [ -e "/tmp/t0_copy_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_copy_x.csv -o /home/pi/printer_data/config/input_shaper/t0_copy_resonances_x_"$DATE".png + [ -e "/tmp/t0_copy_x.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t0_copy_x.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t0_copy_resonances_x_"$DATE".png fi if [ $T1 -eq 1 ] then @@ -187,7 +190,7 @@ then fi echo "please wait..." mv "/tmp/resonances_x_$4_$5_$6_t1_copy.csv" /tmp/t1_copy_x.csv - [ -e "/tmp/t1_copy_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_copy_x.csv -o /home/pi/printer_data/config/input_shaper/t1_copy_resonances_x_"$DATE".png + [ -e "/tmp/t1_copy_x.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t1_copy_x.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t1_copy_resonances_x_"$DATE".png fi fi @@ -202,7 +205,7 @@ then fi echo "please wait..." mv "/tmp/resonances_x_$4_$5_$6_t0_mirror.csv" /tmp/t0_mirror_x.csv - [ -e "/tmp/t0_mirror_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_mirror_x.csv -o /home/pi/printer_data/config/input_shaper/t0_mirror_resonances_x_"$DATE".png + [ -e "/tmp/t0_mirror_x.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t0_mirror_x.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t0_mirror_resonances_x_"$DATE".png fi if [ $T1 -eq 1 ] then @@ -213,7 +216,7 @@ then fi echo "please wait..." mv "/tmp/resonances_x_$4_$5_$6_t1_mirror.csv" /tmp/t1_mirror_x.csv - [ -e "/tmp/t1_mirror_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_mirror_x.csv -o /home/pi/printer_data/config/input_shaper/t1_mirror_resonances_x_"$DATE".png + [ -e "/tmp/t1_mirror_x.csv" ] && ${KLIPPER_DIR}/scripts/calibrate_shaper.py /tmp/t1_mirror_x.csv -o ${RATOS_PRINTER_DATA_DIR}/config/input_shaper/t1_mirror_resonances_x_"$DATE".png fi fi fi \ No newline at end of file diff --git a/scripts/moonraker-ensure-policykit-rules.sh b/scripts/moonraker-ensure-policykit-rules.sh index 4113c7e0e..3e6c8e4d9 100755 --- a/scripts/moonraker-ensure-policykit-rules.sh +++ b/scripts/moonraker-ensure-policykit-rules.sh @@ -1,5 +1,8 @@ #!/bin/bash +# shellcheck source=./scripts/ratos-common.sh +source "$SCRIPT_DIR"/ratos-common.sh + POLKIT_LEGACY_DIR="/etc/polkit-1/localauthority/50-local.d" POLKIT_DIR="/etc/polkit-1/rules.d" POLKIT_USR_DIR="/usr/share/polkit-1/rules.d" @@ -20,9 +23,9 @@ ensure_moonraker_policiykit_rules() { echo -e "\n\n###### Moonraker legacy policy exists, skipping policykit script." return fi - if [[ -e /home/pi/moonraker/scripts/set-policykit-rules.sh ]] + if [[ -e ${MOONRAKER_DIR}/scripts/set-policykit-rules.sh ]] then - cp /home/pi/moonraker/scripts/set-policykit-rules.sh /tmp/set-policykit-rules.sh + cp ${MOONRAKER_DIR}/scripts/set-policykit-rules.sh /tmp/set-policykit-rules.sh # if moonraker restarts the update process will be terminated, leaving a broken moonraker install. sed -i 's/sudo systemctl restart moonraker/#sudo systemctl restart moonraker/g' /tmp/set-policykit-rules.sh #sed -i ':a;N;$!ba;s/verify_ready\n/#verify_ready\n/g' /tmp/set-policykit-rules.sh @@ -30,7 +33,7 @@ ensure_moonraker_policiykit_rules() { if [ "$EUID" -eq 0 ]; then # This feels wrong, but... OLDUSER=$USER - USER=pi + USER=${RATOS_USERNAME} /tmp/set-policykit-rules.sh --root USER=$OLDUSER else diff --git a/scripts/ratos-common.sh b/scripts/ratos-common.sh index e065732e8..898758942 100755 --- a/scripts/ratos-common.sh +++ b/scripts/ratos-common.sh @@ -5,6 +5,30 @@ report_status() echo -e "\n\n###### $1" } + +#create ~/.ratos.env if file does not exist using sane defaults on a ratos pi image. +#performed outside of a function so that other scripts sourcing this in run this by default +if [ ! -f ~/.ratos.env ] && [ -f /etc/ratos-release ]; then +cat < ~/.ratos.env +RATOS_USERNAME="pi" +RATOS_USERGROUP="pi" +RATOS_PRINTER_DATA_DIR="/home/${RATOS_USERNAME}/printer_data" +MOONRAKER_DIR="/home/${RATOS_USERNAME}/moonraker" +KLIPPER_DIR="/home/${RATOS_USERNAME}/klipper" +${RATOS_PRINTER_DATA_DIR}="/home/${RATOS_USERNAME}/klippy-env" +BEACON_DIR="/home/${RATOS_USERNAME}/beacon" +EOF +fi + +if [ -f ~/.ratos.env ] ; then + report_status "Loading RatOS environment data" + set -a && source ~/.ratos.env && set +a +else + report_status "Unable to load RatOS environment data, exiting..." + exit 1 +fi + + disable_modem_manager() { report_status "Checking if ModemManager is enabled..." @@ -22,9 +46,6 @@ disable_modem_manager() update_beacon_fw() { report_status "Updating beacon firmware..." - KLIPPER_DIR="/home/pi/klipper" - KLIPPER_ENV="/home/pi/klippy-env" - BEACON_DIR="/home/pi/beacon" if [ ! -d "$BEACON_DIR" ] || [ ! -e "$KLIPPER_DIR/klippy/extras/beacon.py" ]; then echo "beacon: beacon isn't installed, skipping..." return @@ -44,9 +65,6 @@ update_beacon_fw() install_beacon() { - KLIPPER_DIR="/home/pi/klipper" - KLIPPER_ENV="/home/pi/klippy-env" - BEACON_DIR="/home/pi/beacon" report_status "Installing beacon module..." if [ -d "$BEACON_DIR" ] || [ -e "$KLIPPER_DIR/klippy/extras/beacon.py" ]; then @@ -59,10 +77,8 @@ install_beacon() return fi - pushd "/home/pi" || return - git clone https://github.com/beacon3d/beacon_klipper.git beacon - chown -R pi:pi beacon - popd || return + git clone https://github.com/beacon3d/beacon_klipper.git ${BEACON_DIR} + chown -R ${RATOS_USERNAME}:${RATOS_USERGROUP} ${BEACON_DIR} # install beacon requirements to env echo "beacon: installing python requirements to env." @@ -149,9 +165,9 @@ register_ratos_kinematics() { if ratos extensions list | grep "ratos-kinematics" &>/dev/null; then ratos extensions unregister klipper -k ratos_hybrid_corexy fi - if [ -e /home/pi/ratos-kinematics ]; then + if [ -e /home/${RATOS_USERNAME}/ratos-kinematics ]; then report_status "Removing old ratos-kinematics directory..." - rm -rf /home/pi/ratos-kinematics + rm -rf /home/${RATOS_USERNAME}/ratos-kinematics fi EXT_NAME="ratos_hybrid_corexy" EXT_PATH=$(realpath "${SCRIPT_DIR}/../klippy/kinematics/ratos_hybrid_corexy.py") @@ -169,38 +185,38 @@ register_ratos() remove_old_postprocessor() { - if [ -L /home/pi/klipper/klippy/extras/ratos_post_processor.py ]; then + if [ -L ${KLIPPER_DIR}/klippy/extras/ratos_post_processor.py ]; then report_status "Removing old postprocessor.py..." - rm /home/pi/klipper/klippy/extras/ratos_post_processor.py + rm ${KLIPPER_DIR}/klippy/extras/ratos_post_processor.py fi } install_hooks() { report_status "Installing git hooks" - if [[ ! -L /home/pi/printer_data/config/RatOS/.git/hooks/post-merge ]] + if [[ ! -L ${RATOS_PRINTER_DATA_DIR}/config/RatOS/.git/hooks/post-merge ]] then ln -s "$SCRIPT_DIR"/ratos-post-merge.sh "$SCRIPT_DIR"/../.git/hooks/post-merge fi - if [[ ! -L /home/pi/klipper/.git/hooks/post-merge ]] + if [[ ! -L ${KLIPPER_DIR}/.git/hooks/post-merge ]] then - ln -s "$SCRIPT_DIR"/klipper-post-merge.sh /home/pi/klipper/.git/hooks/post-merge + ln -s "$SCRIPT_DIR"/klipper-post-merge.sh ${KLIPPER_DIR}/.git/hooks/post-merge fi - if [[ ! -L /home/pi/moonraker/.git/hooks/post-merge ]] + if [[ ! -L ${MOONRAKER_DIR}/.git/hooks/post-merge ]] then - ln -s "$SCRIPT_DIR"/moonraker-post-merge.sh /home/pi/moonraker/.git/hooks/post-merge + ln -s "$SCRIPT_DIR"/moonraker-post-merge.sh ${MOONRAKER_DIR}/.git/hooks/post-merge fi - if [[ ! -L /home/pi/beacon/.git/hooks/post-merge ]] + if [[ ! -L ${BEACON_DIR}/.git/hooks/post-merge ]] then - ln -s "$SCRIPT_DIR"/beacon-post-merge.sh /home/pi/beacon/.git/hooks/post-merge + ln -s "$SCRIPT_DIR"/beacon-post-merge.sh ${BEACON_DIR}/.git/hooks/post-merge fi } ensure_service_permission() { report_status "Updating service permissions" - if ! grep "klipper_mcu" /home/pi/printer_data/moonraker.asvc &>/dev/null || ! grep "ratos-configurator" /home/pi/printer_data/moonraker.asvc &>/dev/null; then - cat << '#EOF' > /home/pi/printer_data/moonraker.asvc + if ! grep "klipper_mcu" ${RATOS_PRINTER_DATA_DIR}/moonraker.asvc &>/dev/null || ! grep "ratos-configurator" ${RATOS_PRINTER_DATA_DIR}/moonraker.asvc &>/dev/null; then + cat << '#EOF' > ${RATOS_PRINTER_DATA_DIR}/moonraker.asvc klipper_mcu webcamd MoonCord @@ -244,10 +260,10 @@ ensure_sudo_command_whitelisting() fi touch /tmp/030-ratos-githooks cat << '#EOF' > /tmp/030-ratos-githooks -pi ALL=(ALL) NOPASSWD: /home/pi/printer_data/config/RatOS/scripts/ratos-update.sh -pi ALL=(ALL) NOPASSWD: /home/pi/printer_data/config/RatOS/scripts/klipper-mcu-update.sh -pi ALL=(ALL) NOPASSWD: /home/pi/printer_data/config/RatOS/scripts/beacon-update.sh -pi ALL=(ALL) NOPASSWD: /home/pi/printer_data/config/RatOS/scripts/moonraker-update.sh +${RATOS_USERNAME} ALL=(ALL) NOPASSWD: ${RATOS_PRINTER_DATA_DIR}/config/RatOS/scripts/ratos-update.sh +${RATOS_USERNAME} ALL=(ALL) NOPASSWD: ${RATOS_PRINTER_DATA_DIR}/config/RatOS/scripts/klipper-mcu-update.sh +${RATOS_USERNAME} ALL=(ALL) NOPASSWD: ${RATOS_PRINTER_DATA_DIR}/config/RatOS/scripts/beacon-update.sh +${RATOS_USERNAME} ALL=(ALL) NOPASSWD: ${RATOS_PRINTER_DATA_DIR}/config/RatOS/scripts/moonraker-update.sh #EOF $sudo chown root:root /tmp/030-ratos-githooks diff --git a/scripts/ratos-install.sh b/scripts/ratos-install.sh index 1d7445f86..d1f9ae286 100755 --- a/scripts/ratos-install.sh +++ b/scripts/ratos-install.sh @@ -18,14 +18,14 @@ install_dependencies() install_printer_config() { report_status "Copying printer configuration" - PRINTER_CFG="/home/pi/printer_data/config/printer.cfg" - tail -n +2 /home/pi/printer_data/config/RatOS/templates/initial-printer.template.cfg > $PRINTER_CFG + PRINTER_CFG="${RATOS_PRINTER_DATA_DIR}/config/printer.cfg" + tail -n +2 ${RATOS_PRINTER_DATA_DIR}/config/RatOS/templates/initial-printer.template.cfg > $PRINTER_CFG } install_udev_rules() { report_status "Installing udev rules" - sudo ln -s /home/pi/printer_data/config/RatOS/boards/*/*.rules /etc/udev/rules.d/ + sudo ln -s ${RATOS_PRINTER_DATA_DIR}/config/RatOS/boards/*/*.rules /etc/udev/rules.d/ } verify_ready() diff --git a/scripts/ratos-update.sh b/scripts/ratos-update.sh index 94bff9034..002cd82d3 100755 --- a/scripts/ratos-update.sh +++ b/scripts/ratos-update.sh @@ -14,7 +14,7 @@ update_symlinks() { echo "Updating RatOS device symlinks.." rm /etc/udev/rules.d/98-*.rules - ln -s /home/pi/printer_data/config/RatOS/boards/*/*.rules /etc/udev/rules.d/ + ln -s ${RATOS_PRINTER_DATA_DIR}/config/RatOS/boards/*/*.rules /etc/udev/rules.d/ } ensure_node_18() @@ -34,8 +34,8 @@ ensure_node_18() fix_klippy_env_ownership() { - if [ -n "$(find /home/pi/klippy-env/lib/python3.9/site-packages/matplotlib -user "root" -print -prune -o -prune)" ]; then - chown -R pi:pi /home/pi/klippy-env + if [ -n "$(find ${KLIPPER_ENV}/lib/python3.9/site-packages/matplotlib -user "root" -print -prune -o -prune)" ]; then + chown -R ${RATOS_USERNAME}:${RATOS_USERGROUP} ${KLIPPER_ENV} fi }