Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arch/pacman in update checker #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion install-update-tracker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -248,12 +252,59 @@ 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 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
;;
Expand Down
20 changes: 20 additions & 0 deletions rp-update-tracker/pacman/pacman-metrics.sh
Original file line number Diff line number Diff line change
@@ -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 pacman package pending updates by origin."
echo "# TYPE os_upgrades_pending gauge"
echo "os_upgrades_pending ${UPDATES}"

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}"

echo "# HELP os_reboot_required Node reboot is required for software updates."
echo "# TYPE os_reboot_required gauge"
echo "os_reboot_required ${REBOOT}"
4 changes: 4 additions & 0 deletions rp-update-tracker/pacman/rp-pacman-check.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions rp-update-tracker/pacman/rp-update-tracker.service
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions rp-update-tracker/pacman/rp-update-tracker.timer
Original file line number Diff line number Diff line change
@@ -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