summaryrefslogtreecommitdiffstats
path: root/mgasoft
blob: 91052580952885ad063f4a1b63795228330a3b43 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/sh

# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide.
# This software is distributed without any warranty.

# You should have received a copy of the CC0 Public Domain Dedication
# along with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

. /etc/mgasoft.conf

function check_softname()
{
    local softname="$1"
    test -n "$softname" || return 1
    echo "$softname" | fgrep -q .. && return 1
    echo "$softname" | fgrep -q / && return 1
    return 0
}

function check_softrel()
{
    check_softname $@
}

function usage()
{
    local cmd="$1"
    local exitval=$2
    case "$cmd" in
	tagrelease)
	    cat <<EOF
Usage: mgasoft tag [name] [version]

This command tag a version from trunk.
EOF
            ;;
	gettar)
	    cat <<EOF
Usage: mgasoft tar [name] [version]

This command will create a tarball.
EOF
            ;;
	publish)
	    cat <<EOF
Usage: mgasoft publish [name] [version]

This command will publish a version on mageia mirrors.
EOF
            ;;
	*)
	    cat <<EOF
Usage: mgasoft [command] [args]

Available commands :
   tag
   publish
   tar

For more infos about a command, use :
   mgasoft [command] --help
EOF
        ;;
esac
    exit $exitval
}

function tagrelease()
{
    [ "$1" == "--help" ] && usage tagrelease 0
    [ $# -ne 2 ] && usage tagrelease 1
    local softname="$1"
    local softrel="$2"
    check_softname "$softname" || exit 1
    check_softrel "$softrel" || exit 1

    local softdir="$svn_soft/$softname"
    
    if ! svn ls "$softdir/trunk" > /dev/null 2>&1
    then
	echo "error: $softname does not exists" >&2
	exit 2
    fi

    if svn ls "$softdir/tags/$softrel" > /dev/null 2>&1
    then
	echo "error: $softname version $softrel already exists" >&2
	exit 2
    fi

    if ! svn ls "$softdir/tags" > /dev/null 2>&1
    then
	svn mkdir -q -m "create tags directory for $softname" "$softdir/tags"
    fi
    svn cp -q -m "$softname version $softrel" "$softdir/trunk" "$softdir/tags/$softrel"
}

function gettar()
{
    [ "$1" == "--help" ] && usage gettar 0
    [ $# -ne 2 ] && usage gettar 1
    local softname="$1"
    local softrel="$2"
    check_softname "$softname" || exit 1
    check_softrel "$softrel" || exit 1

    local oldpwd=$PWD
    local tmpdir=$(mktemp -d)
    cd $tmpdir
    if [ "$softrel" == "trunk" ]
    then
	local svnpath="$anonsvn_soft/$softname/trunk"
    else
	local svnpath="$anonsvn_soft/$softname/tags/$softrel"
    fi
    if ! svn export -q "$svnpath" "$softname-$softrel"
    then
	echo "Error exporting $softname-$softrel" >&2
	rm -Rf "$tmpdir"
	exit 2
    fi
    tar cvJf "$oldpwd/$softname-$softrel.tar.xz" "$softname-$softrel"
    cd "$oldpwd"
    rm -Rf "$tmpdir"
    echo "Created $softname-$softrel.tar.xz"
}

function publishrelease()
{
    [ "$1" == "--help" ] && usage publish 0
    [ $# -ne 2 ] && usage publish 1
    local softname="$1"
    local softrel="$2"
    check_softname "$softname" || exit 1
    check_softrel "$softrel" || exit 1

    local svnpath="$svn_soft/$softname/tags/$softrel"
    if ! svn ls "$svnpath" > /dev/null 2>&1
    then
	echo "error: $softname version $softrel does not exist" >&2
	exit 2
    fi

    local pubdir="$svn_soft_publish/$softname"
    if svn ls "$pubdir/$softrel" > /dev/null 2>&1
    then
	echo "$softname version $softrel already published" >&2
	exit 2
    fi
    if ! svn ls "$pubdir" > /dev/null 2>&1
    then
	svn mkdir -q -m "create directory for $softname" "$pubdir"
    fi
    local tmpdir=$(mktemp -d)
    pushd "$tmpdir" > /dev/null
    svn co -q "$pubdir"
    cd "$softname"
    touch "$softrel"
    svn add -q "$softrel"
    svn ci -q -m "publish $softname version $softrel"
    popd > /dev/null
    rm -Rf "$tmpdir"
}

case "$1" in
    tag)
	shift
	tagrelease $@
	;;
    tar)
	shift
	gettar $@
	;;
    publish)
	shift
	publishrelease $@
	;;
    *)
	usage '' 1
	;;
esac