From fc61e12ef95be2f4f5e224904b0634867e1ea1d1 Mon Sep 17 00:00:00 2001 From: Damian D'Souza Date: Sun, 12 Oct 2025 23:54:29 +0200 Subject: [PATCH] Battery: add uninstall script template, create uninstall script in installation script --- .../install-battery-manager.sh | 31 +++++++++++++++++++ .../templates/uninstall-template | 30 ++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Bin/battery-manager/templates/uninstall-template diff --git a/Bin/battery-manager/install-battery-manager.sh b/Bin/battery-manager/install-battery-manager.sh index e65c9acd..1ed28413 100755 --- a/Bin/battery-manager/install-battery-manager.sh +++ b/Bin/battery-manager/install-battery-manager.sh @@ -138,6 +138,36 @@ else print_info "Could not restart polkit automatically, you may need to reboot" fi +print_info "Creating uninstall script..." +UNINSTALL_SCRIPT="$SCRIPT_DIR/uninstall-battery-manager-$ACTUAL_USER.sh" + + +if [ -f "$SCRIPT_DIR/templates/uninstall-template" ]; then + SHEBANG=$(head -n 1 "$SCRIPT_DIR/templates/uninstall-template") +else + SHEBANG="#!/usr/bin/env bash" +fi +echo "$SHEBANG" > "$UNINSTALL_SCRIPT" +echo "" >> "$UNINSTALL_SCRIPT" + +cat >> "$UNINSTALL_SCRIPT" << EOF +SCRIPT_PATH="$BATTERY_MANAGER_SCRIPT" +POLICY_PATH="$POLICY_FILE" +RULES_PATH="$RULES_FILE" +LOG_PATH="/var/log/battery-manager.log" + +EOF + +if [ -f "$SCRIPT_DIR/templates/uninstall-template" ]; then + tail -n +2 "$SCRIPT_DIR/templates/uninstall-template" >> "$UNINSTALL_SCRIPT" +fi + +chmod 744 "$UNINSTALL_SCRIPT" +chown root:root "$UNINSTALL_SCRIPT" + +print_info "Uninstall script created at $UNINSTALL_SCRIPT" + + echo print_info "Installation complete!" echo @@ -145,3 +175,4 @@ print_info "Log file: /var/log/battery-manager.log" print_info "User-specific script: $BATTERY_MANAGER_SCRIPT" print_info "User-specific policy: $POLICY_FILE" print_info "User-specific rules: $RULES_FILE" +print_info "User-specific uninstall script: $UNINSTALL_SCRIPT" diff --git a/Bin/battery-manager/templates/uninstall-template b/Bin/battery-manager/templates/uninstall-template new file mode 100644 index 00000000..f2cf83eb --- /dev/null +++ b/Bin/battery-manager/templates/uninstall-template @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +if [ "$(id -u)" -ne 0 ]; then + echo "This script must be run as root" + exit 1 +fi + +echo "Uninstalling battery manager..." + +if [ -f "$SCRIPT_PATH" ]; then + rm -f "$SCRIPT_PATH" + echo "Removed script from $SCRIPT_PATH" +fi + +if [ -f "$POLICY_PATH" ]; then + rm -f "$POLICY_PATH" + echo "Removed policy file from $POLICY_PATH" +fi + +if [ -f "$RULE_PATH" ]; then + rm -f "$RULE_PATH" + echo "Removed udev rule from $RULE_PATH" +fi + +if [ -f "$LOG_PATH" ]; then + rm -f "$LOG_PATH" + echo "Removed log file from $LOG_PATH" +fi + +echo "Uninstallation completed successfully"