summaryrefslogtreecommitdiff
path: root/web-server/update-scripts/create-gnu-sv-www-repo.sh
blob: 8c2ea2c2353f6a191491b8b83fc505545ca775c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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: