blob: 1134b2d9be3851d812333bddd519bc497109ccc6 (
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
186
187
188
189
190
191
192
193
194
195
|
#!/bin/bash
if [ $# -ne 2 ]; then
echo "usage: $(basename $0) <arch> <reponame>"
exit 1
fi
if [ -f "/etc/makepkg.conf" ]; then
#Get some config info
. /etc/makepkg.conf
else
echo "/etc/makepkg.conf does not exist!"
exit 1
fi
reponame="$1"
arch="$2"
export CARCH="$arch"
##### Arch specific stuff. TODO make this configurable #####
ftppath="/home/ftp/$reponame/os/$arch/"
svnpath="file:///home/svn-packages"
svnrepo="$reponame-$arch"
stagedir="$HOME/staging/$reponame"
############################################################
[ "$UID" = "" ] && UID=$(uid)
WORKDIR="/tmp/db-update.$svnrepo.$UID"
LOCKFILE="/tmp/.repolck.$arch.$reponame"
ADDPKGS=""
REMPKGS=""
if [ ! `type -p fakeroot` ]; then
echo "error: fakeroot is missing" >&2
exit 1
fi
if [ ! -d $stagedir ]; then
echo "error: staging directory missing: $stagedir" >&2
exit 1
fi
# Get the package name from the filename
# hackish, but should work for now
getpkgname() {
local tmp
tmp=${1##*/}
tmp=${tmp%$PKGEXT}
tmp=${tmp%-$CARCH}
echo ${tmp%-*-*}
}
cleanup() {
# unlock
rm -f "$LOCKFILE"
#rm -rf "$WORKDIR"
[ "$1" ] && exit $1
}
ctrl_c() {
echo "Interrupted" >&2
cleanup 0
}
die() {
echo "$*" >&2
cleanup 1
}
# check for locks
if [ -f "$LOCKFILE" ]; then
owner="$(/usr/bin/stat -c %U $LOCKFILE)"
echo "error: db generation is already in progress (started by $owner)"
exit 1
fi
trap ctrl_c 2
trap cleanup 0
/bin/touch "$LOCKFILE"
/bin/mkdir -p "$WORKDIR"
echo "Updating DB for $reponame $arch"
if [ -d "${stagedir}64" ]; then
echo "It looks like you have an old staging dir"
echo "Packages are now differentiated by the arch in the filename."
echo "Please delete '${stagedir}64'"
/bin/cp -r "${stagedir}64/" "$stagedir"
fi
to_add=""
if [ -d "$stagedir/add" ]; then
ADDPKGS="$(/bin/ls $stagedir/add/*-${arch}$PKGEXT 2>/dev/null)"
fi
if [ -n "$ADDPKGS" ]; then
echo "==> Processing new/updated packages for repository '$reponame'..." >&2
/bin/cd "$WORKDIR"
/usr/bin/svn checkout -N $svnpath checkout
/bin/cd checkout
for pkg in $ADDPKGS; do
_pkgfile=$(basename $pkg)
_pkgname="$(getpkgname $pkg)"
echo " Checking SVN for $_pkgname"
/usr/bin/svn up -q $_pkgname
if [ -d "$_pkgname/repos/$svnrepo" ]; then
. "$_pkgname/repos/$svnrepo/$BUILDSCRIPT"
if [ "$_pkgfile" = "$pkgname-$pkgver-$pkgrel-$CARCH$PKGEXT" ]; then
to_add="$to_add $pkg"
else
echo " WARNING: $_pkgfile does not match $BUILDSCRIPT in $svnrepo"
fi
else
echo " WARNING: Package $_pkgname not found in $svnrepo"
fi
done
cd "$WORKDIR"
[ -d build/ ] || mkdir build
# copy the db file into our working area
[ -f "$ftppath/$reponame.db.tar.gz" ] && cp "$ftppath/$reponame.db.tar.gz" build/
/bin/cp $to_add build/
cd build/
/usr/bin/repo-add "$reponame.db.tar.$DB_COMPRESSION" $to_add
else
echo "No packages to add"
fi
to_rem=""
if [ -d "$stagedir/del" ]; then
REMPKGS="$(/bin/ls $stagedir/del/*-${arch}$PKGEXT 2>/dev/null)"
fi
if [ -n "$REMPKGS" ]; then
echo "==> Processing deleted packages for repository '$reponame'..." >&2
if [ ! -d "$WORKDIR/checkout" ]; then
/bin/cd "$WORKDIR"
/usr/bin/svn checkout -N $svnpath checkout
fi
/bin/cd "$WORKDIR/checkout"
#TODO removal shouldn't require a package file
for pkg in $REMPKGS; do
_pkgfile=$(basename $pkg)
_pkgname="$(getpkgname $pkg)"
echo " Checking SVN for $_pkgname"
svn up -q $_pkgname
if [ -d "$_pkgname/repos/$svnrepo" ]; then
echo " WARNING: $_pkgname still exists in $svnrepo"
else
to_rem="$to_rem $pkg"
fi
done
cd "$WORKDIR"
[ -d build/ ] || mkdir build
# copy the db file into our working area
[ -f "$ftppath/$reponame.db.tar.gz" ] && cp "$ftppath/$reponame.db.tar.gz" build/
for rem in $to_rem; do
if [ -f "build/$rem" ]; then
/bin/rm "build/$rem"
fi
done
cd build/
/usr/bin/repo-remove "$reponame.db.tar.$DB_COMPRESSION" $to_rem
else
echo "No packages to delete"
fi
# if non empty, move all build dirs
if [ $(/bin/ls "$WORKDIR/build/" 2>/dev/null | wc -l) != 0 ]; then
/bin/cp -r "$WORKDIR/build/"* "$ftppath"
fi
if [ "$updatelists" ]; then
echo "==> Generating Text Package List..." >&2
cd "$WORKDIR/checkout"
$ARCHDIR/genpkglist $ftppath $svnrepo
if [ -f packages.txt ]; then
mv packages.txt $ftppath/packages.txt
fi
fi
# vim: set ts=4 sw=4 noet ft=sh:
|