From a2efef9af95aadc610400958cb16420091e584a6 Mon Sep 17 00:00:00 2001 From: Mikkel Schmidt Date: Sat, 30 Nov 2024 01:50:40 +0100 Subject: [PATCH] Scripts: more fixes for reporting, better githook checks --- configuration/scripts/ratos-common.sh | 37 +++++++++++++++------------ configuration/scripts/ratos-update.sh | 5 +++- src/scripts/common.sh | 3 ++- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/configuration/scripts/ratos-common.sh b/configuration/scripts/ratos-common.sh index 5248053c6..f10a7bdb5 100755 --- a/configuration/scripts/ratos-common.sh +++ b/configuration/scripts/ratos-common.sh @@ -142,23 +142,21 @@ register_z_offset_probe() } register_ratos_kinematics() { - echo "Registering ratos-kinematics extension..." if ratos extensions list | grep "ratos-kinematics" &>/dev/null; then - echo "Unregistering old ratos-kinematics extension..." + report_status "Unregistering old ratos-kinematics extension..." ratos extensions unregister klipper -k ratos_hybrid_corexy fi if [ -e "${RATOS_PRINTER_DATA_DIR}/config/RatOS/klippy/kinematics/ratos-kinematics" ]; then - echo "Removing old ratos-kinematics directory..." + report_status "Removing old ratos-kinematics directory..." rm -rf "${RATOS_PRINTER_DATA_DIR}/config/RatOS/klippy/kinematics/ratos-kinematics" fi EXT_NAME="ratos_hybrid_corexy" EXT_PATH=$(realpath "${SCRIPT_DIR}/../klippy/kinematics/ratos_hybrid_corexy.py") - ratos extensions register klipper -k $EXT_NAME "$EXT_PATH" + _register_klippy_extension $EXT_NAME "$EXT_PATH" "ratos_hybrid_corexy.py" } register_ratos() { - echo "Registering ratos extension..." EXT_NAME="ratos_extension" EXT_PATH=$(realpath "$SCRIPT_DIR"/../klippy) EXT_FILE="ratos.py" @@ -177,25 +175,32 @@ remove_old_postprocessor() install_hooks() { - report_status "Installing git hooks" - if [[ ! -L ${KLIPPER_DIR}/.git/hooks/post-merge ]] + report_status "Verifying git hooks are installed..." + if [[ ! -L "${KLIPPER_DIR}"/.git/hooks/post-merge ]] || [[ ! "$(readlink "${KLIPPER_DIR}"/.git/hooks/post-merge)" = "$SCRIPT_DIR/klipper-post-merge.sh" ]] then - ln -s "$SCRIPT_DIR"/klipper-post-merge.sh "${KLIPPER_DIR}/.git/hooks/post-merge" + rm -f "${KLIPPER_DIR}/.git/hooks/post-merge" + ln -s "$SCRIPT_DIR"/klipper-post-merge.sh "${KLIPPER_DIR}/.git/hooks/post-merge" + echo "Klipper git hook installed!" fi - if [[ ! -L ${MOONRAKER_DIR}/.git/hooks/post-merge ]] + if [[ ! -L "${MOONRAKER_DIR}"/.git/hooks/post-merge ]] || [[ ! "$(readlink "${MOONRAKER_DIR}"/.git/hooks/post-merge)" = "$SCRIPT_DIR/moonraker-post-merge.sh" ]] then - ln -s "$SCRIPT_DIR"/moonraker-post-merge.sh "${MOONRAKER_DIR}/.git/hooks/post-merge" + rm -f "${MOONRAKER_DIR}/.git/hooks/post-merge" + ln -s "$SCRIPT_DIR"/moonraker-post-merge.sh "${MOONRAKER_DIR}/.git/hooks/post-merge" + echo "Moonraker git hook installed!" fi - if [[ ! -L ${BEACON_DIR}/.git/hooks/post-merge ]] + if [[ ! -L "${BEACON_DIR}"/.git/hooks/post-merge ]] || [[ ! "$(readlink "${BEACON_DIR}"/.git/hooks/post-merge)" = "$SCRIPT_DIR/beacon-post-merge.sh" ]] then - ln -s "$SCRIPT_DIR"/beacon-post-merge.sh "${BEACON_DIR}/.git/hooks/post-merge" + rm -f "${BEACON_DIR}/.git/hooks/post-merge" + ln -s "$SCRIPT_DIR"/beacon-post-merge.sh "${BEACON_DIR}/.git/hooks/post-merge" + echo "Beacon git hook installed!" fi + echo "Git hooks are correctly installed!" } ensure_service_permission() { - if ! grep "klipper_mcu" "${RATOS_PRINTER_DATA_DIR}/moonraker.asvc" &>/dev/null || ! grep "ratos-configurator" "${RATOS_PRINTER_DATA_DIR}/moonraker.asvc" &>/dev/null; then - report_status "Updating service permissions" + if [ ! -e "${RATOS_PRINTER_DATA_DIR}/moonraker.asvc" ]; then + report_status "Fixing moonraker service permissions..." cat << EOF > "${RATOS_PRINTER_DATA_DIR}/moonraker.asvc" klipper_mcu webcamd @@ -209,7 +214,7 @@ octoeverywhere ratos-configurator EOF - report_status "Configurator added to moonraker service permissions" + echo "Moonraker service permissions restored!" fi } @@ -221,7 +226,7 @@ patch_klipperscreen_service_restarts() sudo sed -i 's/\RestartSec=1/\RestartSec=5/g' /etc/systemd/system/KlipperScreen.service sudo sed -i 's/\StartLimitIntervalSec=0/\StartLimitIntervalSec=100\nStartLimitBurst=4/g' /etc/systemd/system/KlipperScreen.service sudo systemctl daemon-reload - report_status "KlipperScreen service patched!" + echo "KlipperScreen service patched!" fi } diff --git a/configuration/scripts/ratos-update.sh b/configuration/scripts/ratos-update.sh index 5aff74dc0..064530243 100755 --- a/configuration/scripts/ratos-update.sh +++ b/configuration/scripts/ratos-update.sh @@ -37,8 +37,11 @@ ensure_node_18() fix_klippy_env_ownership() { report_status "Ensuring klipper environment ownership" - if [ -n "$(find "${KLIPPER_ENV}"/lib/python3.9/site-packages/matplotlib -user "root" -print -prune -o -prune)" ]; then + if [ -n "$(find "${KLIPPER_ENV}" \! -user "${RATOS_USERNAME}" -o \! -group "${RATOS_USERGROUP}" -quit)" ]; then chown -R "${RATOS_USERNAME}:${RATOS_USERGROUP}" "${KLIPPER_ENV}" + echo "Klipper environment ownership has been set to ${RATOS_USERNAME}:${RATOS_USERGROUP}." + else + echo "Klipper environment ownership already set correctly." fi } diff --git a/src/scripts/common.sh b/src/scripts/common.sh index f55627dec..a86dd4fdc 100755 --- a/src/scripts/common.sh +++ b/src/scripts/common.sh @@ -87,8 +87,8 @@ ensure_pnpm_installation() { ensure_service_permission() { - report_status "Updating service permissions" if ! grep -q "ratos-configurator" "${RATOS_PRINTER_DATA_DIR}/moonraker.asvc"; then + report_status "Updatin moonraker service permissions" printf '\nratos-configurator' >> "${RATOS_PRINTER_DATA_DIR}/moonraker.asvc" echo "Configurator added to moonraker service permissions!" fi @@ -101,6 +101,7 @@ install_hooks() rm "$GIT_DIR/hooks/post-merge" fi ln -s "$SCRIPT_DIR/post-merge.sh" "$GIT_DIR/hooks/post-merge" + echo "Post-merge git-hook installed!" } install_logrotation() {