commit d0525d2eafcf126a6e05ac6d39a93a103a73466a parent 6e9b0998404a87809bcafab68c008fd57d464d95 Author: Fred Großkopf <fred@kuandu.systems> Date: Fri, 29 May 2026 11:59:27 +0200 Updates uninstall script Diffstat:
| M | uninstall.sh | | | 135 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ |
1 file changed, 105 insertions(+), 30 deletions(-)
diff --git a/uninstall.sh b/uninstall.sh @@ -17,69 +17,144 @@ set -e log() { printf 'info: %s\n' "$1"; } +warn() { printf 'warning: %s\n' "$1" >&2; } # Constants (Must match install.sh) BIN_DIR="/usr/local/sbin" ETC_DIR="/etc" VAR_DIR="/var/gitpages" LOG_DIR="/var/log/gitpages" +SPOOL_DIR="/var/spool/gitpages" USER_NAME="_gitpages" GROUP_NAME="gitpages" - -remove_cron() { - if id "$USER_NAME" > /dev/null 2>&1; then - crontab -u "$USER_NAME" -r 2> /dev/null || true - log "Removed crontab for ${USER_NAME} user." - fi -} +WEB_ROOT="" +ASSETS_DIR="${VAR_DIR}/assets" remove_files() { - rm -f "$ETC_DIR/gitpages.conf" - rm -f "$BIN_DIR/gitpages.sh" "$BIN_DIR/gitpages-init.sh" \ - "$BIN_DIR/gitpages-mirror-git.sh" "$BIN_DIR/gitpages-update.sh" - log "Removed configuration and binaries." + rm -f "$BIN_DIR/gitpages.sh" \ + "$BIN_DIR/gitpages-init.sh" \ + "$BIN_DIR/gitpages-mirror-git.sh" \ + "$BIN_DIR/gitpages-update.sh" + + log "Removed binaries." + warn "Configuration files were not removed:" + warn " $ETC_DIR/gitpages.conf" + warn " $ETC_DIR/gitpages.conf.bak*" + warn "Remove them manually if no longer needed:" + warn " rm -f $ETC_DIR/gitpages.conf $ETC_DIR/gitpages.conf.bak*" } remove_logrotation() { if [ -f "$ETC_DIR/newsyslog.conf" ]; then - # Use a different delimiter for sed since the path contains slashes - sed -i "\%$LOG_DIR/updates.log%d" "$ETC_DIR/newsyslog.conf" - log "Removed log rotation entry." + if grep -qF "$LOG_DIR/updates.log" "$ETC_DIR/newsyslog.conf"; then + sed -i '' "\\%$LOG_DIR/updates.log%d" "$ETC_DIR/newsyslog.conf" + log "Removed log rotation entry." + else + log "No log rotation entry found." + fi fi } -remove_user_and_data() { - if id "$USER_NAME" > /dev/null 2>&1; then - userdel "$USER_NAME" - log "Removed ${USER_NAME} user." - fi - +remove_dirs() { if [ -d "$VAR_DIR" ]; then rm -rf "$VAR_DIR" log "Removed service directory $VAR_DIR." fi + + if [ -d "$LOG_DIR" ]; then + rm -rf "$LOG_DIR" + log "Removed log directory $LOG_DIR." + fi + + if [ -d "$SPOOL_DIR" ]; then + rm -rf "$SPOOL_DIR" + log "Removed spool directory $SPOOL_DIR." + fi } -remove_group() { - if groupinfo "$GROUP_NAME" > /dev/null 2>&1; then - if command -v groupdel > /dev/null 2>&1; then - groupdel "$GROUP_NAME" - log "Removed group $GROUP_NAME" +remove_user_and_group() { + # Remove user + if id "$USER_NAME" > /dev/null 2>&1; then + if userdel -r "$USER_NAME" 2> /dev/null; then + log "Removed user ${USER_NAME} and home directory." + else + warn "Could not remove user ${USER_NAME} (userdel -r failed)." + warn "Remove it manually if not needed:" + warn " userdel -r ${USER_NAME}" + fi + else + log "User ${USER_NAME} does not exist; skipping user removal." + fi + + # Remove group + if getent group "$GROUP_NAME" > /dev/null 2>&1; then + if groupdel "$GROUP_NAME" 2> /dev/null; then + log "Removed group ${GROUP_NAME}." else - # On some systems groupdel may not exist; fall back to manual /etc/group edit - log "WARNING: groupdel not found; please remove group $GROUP_NAME manually from /etc/group." + warn "Could not remove group ${GROUP_NAME} (groupdel failed)." + warn "Remove it manually if not needed:" + warn " groupdel ${GROUP_NAME}" fi + else + log "Group ${GROUP_NAME} does not exist; skipping group removal." + fi +} + +warn_about_webroot() { + if [ -z "$WEB_ROOT" ]; then + warn "WEB_ROOT not specified; web root was NOT removed." + warn "If you know the web root path and want to remove it manually:" + warn " rm -rf /path/to/webroot" + elif [ -d "$WEB_ROOT" ]; then + warn "Web root $WEB_ROOT still exists; NOT removed." + warn "Remove it manually if no longer needed:" + warn " rm -rf $WEB_ROOT" + fi +} + +confirm_removal() { + prompt="$1" + printf '%s [y/N] ' "$prompt" >&2 + read -r answer + case "$answer" in + [yY] | [yY][eE][sS]) return 0 ;; + *) return 1 ;; + esac +} + +confirm_assets_removal() { + if [ ! -d "$ASSETS_DIR" ]; then + return 0 + fi + + printf '\n' >&2 + warn "The default assets directory will be removed:" + warn " $ASSETS_DIR" + warn "This includes all files deployed to the web root from this directory." + warn "If you customized ASSETS_DIR in /etc/gitpages.conf, you are responsible for that directory." + printf '\n' >&2 + + if ! confirm_removal "Do you really want to continue and remove everything under ${VAR_DIR} (including assets)?"; then + log "Uninstall aborted by user." + exit 0 fi } main() { + if [ $# -ge 1 ]; then + WEB_ROOT="$1" + fi + log "Starting uninstallation of gitpages..." - remove_cron + confirm_assets_removal + remove_files remove_logrotation - remove_user_and_data - remove_group + remove_dirs + remove_user_and_group + + warn_about_webroot log "Uninstallation complete." }