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 (4436B)


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