commit bd078d1b5d295a6c6192a8ad750e5d68c594b346
parent b1cf17342a8fe7b8512f890f381c64416c1731b8
Author: Fred Großkopf <fred@kuandu.systems>
Date: Thu, 14 May 2026 22:34:34 +0200
Updates install.sh
Requires new arugments:
install.sh <git-user> <git-src> <web-root>
Diffstat:
| M | install.sh | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
1 file changed, 60 insertions(+), 14 deletions(-)
diff --git a/install.sh b/install.sh
@@ -24,7 +24,7 @@ error() {
}
usage() {
- printf 'usage: %s <git-user>\n' "$(basename "$0")"
+ printf 'usage: %s <git-user> <git-src> <web-root>\n' "$(basename "$0")"
exit 1
}
@@ -46,8 +46,6 @@ setup_group() {
}
setup_user() {
- setup_group
-
if ! id "$USER_NAME" > /dev/null 2>&1; then
useradd -s /sbin/nologin \
-d "$VAR_DIR" \
@@ -75,16 +73,31 @@ install_scripts() {
}
setup_config() {
- if [ ! -f "$ETC_DIR/gitpages.conf" ]; then
- cat << EOF > "$ETC_DIR/gitpages.conf"
-GIT_SRC=/var/git/repos
-WEB_ROOT=/var/www/htdocs
-GIT_RAW=git-raw
-GIT_HTML=git
-ASSETS_DIR=/var/gitpages/assets
-EOF
- log "Created default config in $ETC_DIR/gitpages.conf"
+ config="$ETC_DIR/gitpages.conf"
+ backup="$config.bak"
+
+ if [ -f "$config" ]; then
+ n=1
+ while [ -f "$backup.$n" ]; do
+ n=$((n + 1))
+ done
+ cp -p "$config" "$backup.$n"
+ log "Backed up $config to $backup.$n"
fi
+
+ tmp="$(mktemp "$ETC_DIR/gitpages.conf.XXXXXX")"
+ trap 'rm -f "$tmp"' EXIT INT TERM
+ cat > "$tmp" << EOF
+GIT_SRC=$GIT_SRC
+WEB_ROOT=$WEB_ROOT
+GIT_RAW=$GIT_RAW
+GIT_HTML=$GIT_HTML
+ASSETS_DIR=$ASSETS_DIR
+EOF
+
+ mv "$tmp" "$config"
+ trap - EXIT INT TERM
+ log "Wrote config to $config"
}
setup_logrotation() {
@@ -111,36 +124,69 @@ setup_cron() {
fi
}
+setup_webroot() {
+ install -d -m 755 -o "root" -g "wheel" "$WEB_ROOT"
+ install -d -m 755 -o "$USER_NAME" -g "$GROUP_NAME" "$WEB_ROOT/git"
+ install -d -m 755 -o "$USER_NAME" -g "$GROUP_NAME" "$WEB_ROOT/git-raw"
+ log "Created web root and subdirectories under $WEB_ROOT"
+}
+
main() {
- [ $# -ne 1 ] && usage
+ [ $# -ne 3 ] && usage
GIT_USER="$1"
+ GIT_SRC="$2"
+ WEB_ROOT="$3"
+
USER_NAME="_gitpages"
GROUP_NAME="gitpages"
+ GIT_RAW=git-raw
+ GIT_HTML=git
+ ASSETS_DIR=/var/gitpages/assets
+
BIN_DIR="/usr/local/sbin"
ETC_DIR="/etc"
VAR_DIR="/var/gitpages"
LOG_DIR="/var/log/gitpages"
SPOOL_DIR="/var/spool"
QUEUE_DIR="$SPOOL_DIR/gitpages/queue"
- STAGING_DIR="$VAR_DIR/staging"
+ # Validation
if ! id "$GIT_USER" > /dev/null 2>&1; then
error "User '$GIT_USER' does not exist."
fi
+ case "$GIT_SRC" in
+ /*) : ;;
+ *) error "GIT_SRC must be an absolute path" ;;
+ esac
+
+ [ -d "$GIT_SRC" ] || error "GIT_SRC directory '$GIT_SRC' not found"
+
+ if ! su - "$GIT_USER" -c "test -r '$GIT_SRC'"; then
+ error "GIT_USER '$GIT_USER' cannot read GIT_SRC '$GIT_SRC'"
+ fi
+
+ case "$WEB_ROOT" in
+ /*) : ;;
+ *) error "WEB_ROOT must be an absolute path" ;;
+ esac
+
log "Installing gitpages environment for git-user: $GIT_USER"
+ log "Using WEB_ROOT: $WEB_ROOT"
# Determine and switch to where this script resides
# so ./gitpages-*.sh work no matter where script is invoked from
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
cd "$SCRIPT_DIR" || error "cannot cd to $SCRIPT_DIR"
+ setup_group
setup_user
setup_dirs
setup_spool
install_scripts
setup_config
+ setup_webroot
setup_logrotation
setup_cron