From 613818497b9056ca9cfa973045ac98e3b8b2a263 Mon Sep 17 00:00:00 2001 From: JordanHoeft Date: Thu, 5 Oct 2023 17:20:31 -0500 Subject: [PATCH 1/3] feat: support arch/pacman in update checker --- install-update-tracker.sh | 54 ++++++++++++++++++- rp-update-tracker/pacman/pacman-metrics.sh | 20 +++++++ rp-update-tracker/pacman/rp-pacman-check.sh | 4 ++ .../pacman/rp-update-tracker.service | 10 ++++ .../pacman/rp-update-tracker.timer | 10 ++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 rp-update-tracker/pacman/pacman-metrics.sh create mode 100644 rp-update-tracker/pacman/rp-pacman-check.sh create mode 100644 rp-update-tracker/pacman/rp-update-tracker.service create mode 100644 rp-update-tracker/pacman/rp-update-tracker.timer diff --git a/install-update-tracker.sh b/install-update-tracker.sh index f864b087..cdcec777 100755 --- a/install-update-tracker.sh +++ b/install-update-tracker.sh @@ -34,6 +34,8 @@ if [ "$PLATFORM" = "Linux" ]; then INSTALLER="apt" elif [ $(echo $OS_ID | grep -c -E "fedora|rhel|centos") -gt "0" ]; then INSTALLER="dnf" + elif [ $(echo $OS_ID | grep -c -E "arch") -gt "0" ]; then + INSTALLER="pacman" fi # Fall back to `lsb_release` @@ -50,6 +52,8 @@ if [ "$PLATFORM" = "Linux" ]; then INSTALLER="dnf" elif [ -f "/etc/fedora-release" ]; then INSTALLER="dnf" + elif [ -f "/etc/arch-release" ]; then + INSTALLER="pacman" fi fi @@ -248,12 +252,60 @@ case "$INSTALLER" in ;; + # Arch Linux + pacman) + + # The total number of steps in the installation process + TOTAL_STEPS="4" + + # Install dependencies + progress 1 "Installing dependencies..." + { sudo pacman -Sy; } >&2 + # arch-audit checks for security updates + { sudo pacman -S --noconfirm arch-audit || true; } >&2 + { sudo pacman -S --noconfirm moreutils || fail "Could not install OS dependencies."; } >&2 + + # Download and extract package files + progress 2 "Downloading Rocket Pool update tracker package files..." + { curl -L "$PACKAGE_URL" | tar -xJ -C "$TEMPDIR" || fail "Could not download and extract the Rocket Pool update tracker package files."; } >&2 + { test -d "$PACKAGE_FILES_PATH" || fail "Could not extract the Rocket Pool update tracker package files."; } >&2 + + # Install the update tracker files + progress 3 "Installing update tracker..." + { sudo mkdir -p "$TEXTFILE_COLLECTOR_PATH" || fail "Could not create textfile collector path."; } >&2 + { sudo mv "$PACKAGE_FILES_PATH/pacman/pacman-metrics.sh" "$UPDATE_SCRIPT_PATH" || fail "Could not move pacman update collector."; } >&2 + { sudo mv "$PACKAGE_FILES_PATH/rp-version-check.sh" "$UPDATE_SCRIPT_PATH" || fail "Could not move Rocket Pool update collector."; } >&2 + { sudo mv "$PACKAGE_FILES_PATH/pacman/rp-pacman-check.sh" "$UPDATE_SCRIPT_PATH" || fail "Could not move update tracker script."; } >&2 + { sudo mv "$PACKAGE_FILES_PATH/pacman/rp-update-tracker.service" "/etc/systemd/system" || fail "Could not move update tracker service."; } >&2 + { sudo mv "$PACKAGE_FILES_PATH/pacman/rp-update-tracker.timer" "/etc/systemd/system" || fail "Could not move update tracker timer."; } >&2 + { sudo chmod +x "$UPDATE_SCRIPT_PATH/pacman-metrics.sh" || fail "Could not set permissions on pacman update collector."; } >&2 + { sudo chmod +x "$UPDATE_SCRIPT_PATH/rp-version-check.sh" || fail "Could not set permissions on Rocket Pool update collector."; } >&2 + { sudo chmod +x "$UPDATE_SCRIPT_PATH/rp-pacman-check.sh" || fail "Could not set permissions on Rocket Pool update tracker script."; } >&2 + + # Install the update checking service + progress 4 "Installing update tracker service..." + if [ "$SELINUX" = true ]; then + echo -e "${COLOR_YELLOW}Your system has SELinux enabled, so Rocket Pool can't automatically start the update tracker service." + echo "Please run the following commands manually:" + echo "" + echo -e '\tsudo restorecon /usr/share/rp-pacman-check.sh /usr/share/rp-version-check.sh /etc/systemd/system/rp-update-tracker.service /etc/systemd/system/rp-update-tracker.timer' + echo -e '\tsudo systemctl enable rp-update-tracker' + echo -e '\tsudo systemctl start rp-update-tracker' + echo -e "${COLOR_RESET}" + else + { sudo systemctl daemon-reload || fail "Couldn't update systemctl daemons."; } >&2 + { sudo systemctl enable rp-update-tracker || fail "Couldn't enable update tracker service."; } >&2 + { sudo systemctl start rp-update-tracker || fail "Couldn't start update tracker service."; } >&2 + fi + + ;; + # Unsupported package manager *) RED='\033[0;31m' echo "" echo -e "${RED}**ERROR**" - echo "Update tracker installation is only supported for system that use the 'apt' or 'dnf' package managers." + echo "Update tracker installation is only supported for system that use the 'apt', 'dnf', or 'pacman' package managers." echo "If your operating system uses one of these and you received this message in error, please notify the Rocket Pool team." exit 1 ;; diff --git a/rp-update-tracker/pacman/pacman-metrics.sh b/rp-update-tracker/pacman/pacman-metrics.sh new file mode 100644 index 00000000..b4134070 --- /dev/null +++ b/rp-update-tracker/pacman/pacman-metrics.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +UPDATES=$(pacman -Qu | wc -l) +SECURITY=$(arch-audit --upgradable --quiet | wc -l) + +# If the currently running kernel is less than the latest available, then a reboot is required. +# not perfect but better than nothing +REBOOT=$([[ $(pacman -Q linux | cut -d " " -f 2) > $(uname -r) ]] && echo 0 || echo 1) + +echo "# HELP os_upgrades_pending Apt package pending updates by origin." +echo "# TYPE os_upgrades_pending gauge" +echo "os_upgrades_pending ${UPDATES}" + +echo "# HELP os_security_upgrades_pending Apt package pending security updates by origin." +echo "# TYPE os_security_upgrades_pending gauge" +echo "os_security_upgrades_pending ${SECURITY}" + +echo "# HELP os_reboot_required Node reboot is required for software updates." +echo "# TYPE os_reboot_required gauge" +echo "os_reboot_required ${REBOOT}" diff --git a/rp-update-tracker/pacman/rp-pacman-check.sh b/rp-update-tracker/pacman/rp-pacman-check.sh new file mode 100644 index 00000000..c7b873b6 --- /dev/null +++ b/rp-update-tracker/pacman/rp-pacman-check.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +/usr/share/pacman-metrics.sh | sponge /var/lib/node_exporter/textfile_collector/pacman.prom || true +/usr/share/rp-version-check.sh | sponge /var/lib/node_exporter/textfile_collector/rp.prom || true \ No newline at end of file diff --git a/rp-update-tracker/pacman/rp-update-tracker.service b/rp-update-tracker/pacman/rp-update-tracker.service new file mode 100644 index 00000000..7db752a7 --- /dev/null +++ b/rp-update-tracker/pacman/rp-update-tracker.service @@ -0,0 +1,10 @@ +[Unit] +Description=Checks for system and Rocket Pool updates periodically +Wants=rp-update-tracker.timer + +[Service] +Type=oneshot +ExecStart=/usr/share/rp-pacman-check.sh + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/rp-update-tracker/pacman/rp-update-tracker.timer b/rp-update-tracker/pacman/rp-update-tracker.timer new file mode 100644 index 00000000..170bd6ef --- /dev/null +++ b/rp-update-tracker/pacman/rp-update-tracker.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Timer for the Rocket Pool updates tracker +Requires=rp-update-tracker.service + +[Timer] +Unit=rp-update-tracker.service +OnCalendar=*-*-* *:00:00 + +[Install] +WantedBy=timers.target \ No newline at end of file From 8ecb23d3583c45c0deb3a1644aabe3f48ad8451c Mon Sep 17 00:00:00 2001 From: JordanHoeft Date: Thu, 5 Oct 2023 17:22:45 -0500 Subject: [PATCH 2/3] feat: support arch/pacman in update checker --- install-update-tracker.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install-update-tracker.sh b/install-update-tracker.sh index cdcec777..88e34a2b 100755 --- a/install-update-tracker.sh +++ b/install-update-tracker.sh @@ -262,8 +262,7 @@ case "$INSTALLER" in progress 1 "Installing dependencies..." { sudo pacman -Sy; } >&2 # arch-audit checks for security updates - { sudo pacman -S --noconfirm arch-audit || true; } >&2 - { sudo pacman -S --noconfirm moreutils || fail "Could not install OS dependencies."; } >&2 + { sudo pacman -S --noconfirm arch-audit moreutils || fail "Could not install OS dependencies."; } >&2 # Download and extract package files progress 2 "Downloading Rocket Pool update tracker package files..." From e89a32ae9c8809327a8961fd2b234c0b9140c605 Mon Sep 17 00:00:00 2001 From: JordanHoeft Date: Thu, 5 Oct 2023 17:27:20 -0500 Subject: [PATCH 3/3] feat: support arch/pacman in update checker --- rp-update-tracker/pacman/pacman-metrics.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rp-update-tracker/pacman/pacman-metrics.sh b/rp-update-tracker/pacman/pacman-metrics.sh index b4134070..77f494df 100644 --- a/rp-update-tracker/pacman/pacman-metrics.sh +++ b/rp-update-tracker/pacman/pacman-metrics.sh @@ -7,11 +7,11 @@ SECURITY=$(arch-audit --upgradable --quiet | wc -l) # not perfect but better than nothing REBOOT=$([[ $(pacman -Q linux | cut -d " " -f 2) > $(uname -r) ]] && echo 0 || echo 1) -echo "# HELP os_upgrades_pending Apt package pending updates by origin." +echo "# HELP os_upgrades_pending pacman package pending updates by origin." echo "# TYPE os_upgrades_pending gauge" echo "os_upgrades_pending ${UPDATES}" -echo "# HELP os_security_upgrades_pending Apt package pending security updates by origin." +echo "# HELP os_security_upgrades_pending pacman package pending security updates by origin." echo "# TYPE os_security_upgrades_pending gauge" echo "os_security_upgrades_pending ${SECURITY}"