gitpages

A collection of scripts to securely webhost and publish git repositories.
git clone https://scm.kuandu.systems/git-raw/gitpages.git
Log | Files | Refs | README | LICENSE

uninstall.sh (3533B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 log() { printf 'info: %s\n' "$1"; }
      6 warn() { printf 'warning: %s\n' "$1" >&2; }
      7 
      8 # Constants (Must match install.sh)
      9 BIN_DIR="/usr/local/sbin"
     10 ETC_DIR="/etc"
     11 VAR_DIR="/var/gitpages"
     12 LOG_DIR="/var/log/gitpages"
     13 SPOOL_DIR="/var/spool/gitpages"
     14 USER_NAME="_gitpages"
     15 GROUP_NAME="gitpages"
     16 WEB_ROOT=""
     17 ASSETS_DIR="${VAR_DIR}/assets"
     18 
     19 remove_files() {
     20   rm -f "$BIN_DIR/gitpages"
     21   rm -f "$BIN_DIR/gitpages.post-receive.hook"
     22 
     23   log "Removed binaries."
     24   warn "Configuration files were not removed:"
     25   warn "  $ETC_DIR/gitpages.conf"
     26   warn "Remove them manually if no longer needed:"
     27   warn "  rm -f $ETC_DIR/gitpages.conf"
     28 }
     29 
     30 remove_logrotation() {
     31   if [ -f "$ETC_DIR/newsyslog.conf" ]; then
     32     if grep -qF "$LOG_DIR/updates.log" "$ETC_DIR/newsyslog.conf"; then
     33       sed -i '' "\\%$LOG_DIR/updates.log%d" "$ETC_DIR/newsyslog.conf"
     34       log "Removed log rotation entry."
     35     else
     36       log "No log rotation entry found."
     37     fi
     38   fi
     39 }
     40 
     41 remove_dirs() {
     42   if [ -d "$VAR_DIR" ]; then
     43     rm -rf "$VAR_DIR"
     44     log "Removed service directory $VAR_DIR."
     45   fi
     46 
     47   if [ -d "$LOG_DIR" ]; then
     48     rm -rf "$LOG_DIR"
     49     log "Removed log directory $LOG_DIR."
     50   fi
     51 
     52   if [ -d "$SPOOL_DIR" ]; then
     53     rm -rf "$SPOOL_DIR"
     54     log "Removed spool directory $SPOOL_DIR."
     55   fi
     56 }
     57 
     58 remove_user_and_group() {
     59   # Remove user
     60   if id "$USER_NAME" > /dev/null 2>&1; then
     61     if userdel -r "$USER_NAME" 2> /dev/null; then
     62       log "Removed user ${USER_NAME} and home directory."
     63     else
     64       warn "Could not remove user ${USER_NAME} (userdel -r failed)."
     65       warn "Remove it manually if not needed:"
     66       warn "  userdel -r ${USER_NAME}"
     67     fi
     68   else
     69     log "User ${USER_NAME} does not exist; skipping user removal."
     70   fi
     71 
     72   # Remove group
     73   if getent group "$GROUP_NAME" > /dev/null 2>&1; then
     74     if groupdel "$GROUP_NAME" 2> /dev/null; then
     75       log "Removed group ${GROUP_NAME}."
     76     else
     77       warn "Could not remove group ${GROUP_NAME} (groupdel failed)."
     78       warn "Remove it manually if not needed:"
     79       warn "  groupdel ${GROUP_NAME}"
     80     fi
     81   else
     82     log "Group ${GROUP_NAME} does not exist; skipping group removal."
     83   fi
     84 }
     85 
     86 warn_about_webroot() {
     87   if [ -z "$WEB_ROOT" ]; then
     88     warn "WEB_ROOT not specified; web root was NOT removed."
     89     warn "If you know the web root path and want to remove it manually:"
     90     warn "  rm -rf /path/to/webroot"
     91   elif [ -d "$WEB_ROOT" ]; then
     92     warn "Web root $WEB_ROOT still exists; NOT removed."
     93     warn "Remove it manually if no longer needed:"
     94     warn "  rm -rf $WEB_ROOT"
     95   fi
     96 }
     97 
     98 confirm_removal() {
     99   prompt="$1"
    100   printf '%s [y/N] ' "$prompt" >&2
    101   read -r answer
    102   case "$answer" in
    103     [yY] | [yY][eE][sS]) return 0 ;;
    104     *) return 1 ;;
    105   esac
    106 }
    107 
    108 confirm_assets_removal() {
    109   if [ ! -d "$ASSETS_DIR" ]; then
    110     return 0
    111   fi
    112 
    113   printf '\n' >&2
    114   warn "The default assets directory will be removed:"
    115   warn "  $ASSETS_DIR"
    116   warn "Any custom files stored in this directory will be deleted."
    117   warn "If you customized ASSETS_DIR in /etc/gitpages.conf, you are responsible for that directory."
    118   printf '\n' >&2
    119 
    120   if ! confirm_removal "Do you really want to continue and remove everything under ${VAR_DIR} (including assets)?"; then
    121     log "Uninstall aborted by user."
    122     exit 0
    123   fi
    124 }
    125 
    126 main() {
    127   if [ $# -ge 1 ]; then
    128     WEB_ROOT="$1"
    129   fi
    130 
    131   log "Starting uninstallation of gitpages..."
    132 
    133   confirm_assets_removal
    134 
    135   remove_files
    136   remove_logrotation
    137   remove_dirs
    138   remove_user_and_group
    139 
    140   warn_about_webroot
    141 
    142   log "Uninstallation complete."
    143 }
    144 
    145 main "$@"