Skip to content

Commit

Permalink
initial rework for env variables
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Baker <[email protected]>
  • Loading branch information
Travis Baker authored and funtimeerror committed Nov 20, 2024
1 parent 5088242 commit 69e2e9b
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 62 deletions.
8 changes: 6 additions & 2 deletions scripts/flash-path.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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
7 changes: 5 additions & 2 deletions scripts/generate-belt-tension-graph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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…
Expand All @@ -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"
8 changes: 6 additions & 2 deletions scripts/generate-shaper-graph-x.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions scripts/generate-shaper-graph-y.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions scripts/idex-generate-belt-tension-graph.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# shellcheck source=./scripts/ratos-common.sh
source "$SCRIPT_DIR"/ratos-common.sh

DISABLE_Y=0
DISABLE_X=0

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
31 changes: 17 additions & 14 deletions scripts/idex-generate-shaper-graph.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# shellcheck source=./scripts/ratos-common.sh
source "$SCRIPT_DIR"/ratos-common.sh

DISABLE_Y=0
DISABLE_X=0

Expand All @@ -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
Expand Down Expand Up @@ -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 ]
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ]
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
9 changes: 6 additions & 3 deletions scripts/moonraker-ensure-policykit-rules.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -20,17 +23,17 @@ 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
echo -e "\n\n###### Moonraker policy not found, running moonraker policykit script..."
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
Expand Down
Loading

0 comments on commit 69e2e9b

Please sign in to comment.