summaryrefslogtreecommitdiff
path: root/web-server/update-scripts/create-gnu-sv-www-repo.sh
diff options
context:
space:
mode:
Diffstat (limited to 'web-server/update-scripts/create-gnu-sv-www-repo.sh')
-rwxr-xr-xweb-server/update-scripts/create-gnu-sv-www-repo.sh138
1 files changed, 138 insertions, 0 deletions
diff --git a/web-server/update-scripts/create-gnu-sv-www-repo.sh b/web-server/update-scripts/create-gnu-sv-www-repo.sh
new file mode 100755
index 0000000..8c2ea2c
--- /dev/null
+++ b/web-server/update-scripts/create-gnu-sv-www-repo.sh
@@ -0,0 +1,138 @@
+#!/bin/sh
+
+# Copyright (C) 2014 Assaf Gordon (assafgordon@gmail.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+##
+## Git-Clones new projects from the 'wwwgit' server,
+## and setups the correct symlinks under /var/www/savannah-checkouts/
+##
+## If a project/repository is already cloned, this script silently ignores it,
+## so it's safe to run it again and again (i.e. even to clone just one more
+## new project).
+##
+
+die()
+{
+ BASE=$(basename "$0")
+ echo "$BASE: error: $@" >&2
+ exit 1
+}
+
+log()
+{
+ DATE=$(date +%F-%H%M%S)
+ echo "$DATE: $@" >&2
+}
+
+# Git Repositories Server
+GITURL=git://gnueval.housegordon.org
+# Directory containing detached ".git" content (but not a bare repository).
+GITDIR=/var/lib/savannah-checkouts/
+WWWDIR=/var/www/savannah-checkouts/
+
+PROJ_LIST=gnu-sv-projects-list.txt
+test -e "$PROJ_LIST" \
+ || die "Project-List file ($PROJ_LIST) not found"
+
+##
+## Clone the WWW project, with special settings
+##
+test -d "$GITDIR/www" \
+ || git clone "$GITURL/www" "$GITDIR/www" \
+ || die "git-clone failed, src='$GITURL/www' " \
+ " dst='$GITDIR/www'"
+test -d "$GITDIR/www/www" \
+ || die "invalid Web repository for project (www) "\
+ "- does not contain sub-directory named 'www' " \
+ "(gitdir='$GITDIR/www')"
+## Special Hack:
+## The 'www/www' directory must be in '/var/www' .
+## But this should not be done as the non-root user?
+test -h "/var/www" \
+ || ln -s "$GITDIR/www/www" /var/www \
+ || die "failed to create symlink '/var/www' to '$GITDIR/www/www'"
+
+
+##
+## Clone all other projects
+##
+
+## Ensure sub-directories exist in the 'www' project
+for TYPE in gnu nongnu translation ;
+do
+ mkdir -p "$WWWDIR/$TYPE" \
+ || die "failed to create directory '$WWWDIR/$TYPE'"
+done
+
+cat "$PROJ_LIST" \
+ | while read PROJ TYPE ;
+do
+ ## The 'www' project is special, and was handled above
+ test "x$PROJ" = "xwww" && continue
+
+ expr "$PROJ" : '^[A-Za-z0-9_\-][A-Za-z0-9_\-]*$' >/dev/null \
+ || die "invalid repository/project name ($PROJ) found in '$PROJ_LIST'"
+
+ case "$TYPE" in
+ gnu) LINKDIR="$WWWDIR/gnu" ;;
+ nongnu) LINKDIR="$WWWDIR/non-gnu" ;;
+ translation) LINKDIR="$WWWDIR/translation" ;;
+ *) die "invalid type ($TYPE) for project '$PROJ' found " \
+ "in '$PROJ_LIST" ;;
+ esac
+
+ ## Sanity checks:
+ ## A valid (already-cloned) project need three things:
+ ## 1. a 'git' repository
+ ## 2. a sub-directory named the same as the project
+ ## (e.g. 'datamash/datamash') in which the HTML files are stored.
+ ## This is a hack from the CVS checkout method days.
+ ## 3. a symlink for the directory in the ./savannah-checkouts/{gnu,nongnu}'
+ ## directory - the Apache rules will look there for each project's files.
+
+ ## Clone the repository
+ if ! test -d "$GITDIR/$PROJ" ; then
+ log "cloning new repository '$PROJ'"
+ git clone --quiet "$GITURL/$PROJ" "$GITDIR/$PROJ" \
+ || die "git-clone failed, src='$GITURL/$PROJ' " \
+ " dst='$GITDIR/$PROJ'"
+ fi
+
+ ## Empty repository?
+ ## don't link directory
+ if ! git --git-dir "$GITDIR/$PROJ/.git" rev-parse HEAD 1>/dev/null 2>&1 ;
+ then
+ log "skipping empty web repository for project ($PROJ) "
+ continue
+ fi
+
+ ## Verify it has a properly named sub-directory
+ ## NOTE: instead of die() with failure, ignore this repository -
+ ## could be just an empty repository.
+ test -d "$GITDIR/$PROJ/$PROJ" \
+ || log "skipping invalid web repository for project ($PROJ) "\
+ "- does not contain sub-directory named '$PROJ' " \
+ "(gitdir='$GITDIR/$PROJ')"
+
+ ## Create a symlink to this directory
+ test -h "$LINKDIR/$PROJ" \
+ || ln -s "$GITDIR/$PROJ/$PROJ" "$LINKDIR/$PROJ" \
+ || die "failed to create symlink in '$LINKDIR/$PROJ'"
+done
+
+## vim: set shiftwidth=4:
+## vim: set tabstop=4:
+## vim: set expandtab: