uninstall.sh (2459B)
1 #!/bin/sh 2 # 3 # Copyright (c) 2026 Fred Großkopf 4 # 5 # Permission to use, copy, modify, and/or distribute this software for any 6 # purpose with or without fee is hereby granted, provided that the above 7 # copyright notice and this permission notice appear in all copies. 8 # 9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 17 set -e 18 19 log() { printf 'info: %s\n' "$1"; } 20 21 # Constants (Must match install.sh) 22 BIN_DIR="/usr/local/sbin" 23 ETC_DIR="/etc" 24 VAR_DIR="/var/gitpages" 25 LOG_DIR="/var/log/gitpages" 26 USER_NAME="_gitpages" 27 GROUP_NAME="gitpages" 28 29 remove_cron() { 30 if id "$USER_NAME" > /dev/null 2>&1; then 31 crontab -u "$USER_NAME" -r 2> /dev/null || true 32 log "Removed crontab for ${USER_NAME} user." 33 fi 34 } 35 36 remove_files() { 37 rm -f "$ETC_DIR/gitpages.conf" 38 rm -f "$BIN_DIR/gitpages.sh" "$BIN_DIR/gitpages-init.sh" \ 39 "$BIN_DIR/gitpages-mirror-git.sh" "$BIN_DIR/gitpages-update.sh" 40 log "Removed configuration and binaries." 41 } 42 43 remove_logrotation() { 44 if [ -f "$ETC_DIR/newsyslog.conf" ]; then 45 # Use a different delimiter for sed since the path contains slashes 46 sed -i "\%$LOG_DIR/updates.log%d" "$ETC_DIR/newsyslog.conf" 47 log "Removed log rotation entry." 48 fi 49 } 50 51 remove_user_and_data() { 52 if id "$USER_NAME" > /dev/null 2>&1; then 53 userdel "$USER_NAME" 54 log "Removed ${USER_NAME} user." 55 fi 56 57 if [ -d "$VAR_DIR" ]; then 58 rm -rf "$VAR_DIR" 59 log "Removed service directory $VAR_DIR." 60 fi 61 } 62 63 remove_group() { 64 if groupinfo "$GROUP_NAME" > /dev/null 2>&1; then 65 if command -v groupdel > /dev/null 2>&1; then 66 groupdel "$GROUP_NAME" 67 log "Removed group $GROUP_NAME" 68 else 69 # On some systems groupdel may not exist; fall back to manual /etc/group edit 70 log "WARNING: groupdel not found; please remove group $GROUP_NAME manually from /etc/group." 71 fi 72 fi 73 } 74 75 main() { 76 log "Starting uninstallation of gitpages..." 77 78 remove_cron 79 remove_files 80 remove_logrotation 81 remove_user_and_data 82 remove_group 83 84 log "Uninstallation complete." 85 } 86 87 main "$@"