summaryrefslogtreecommitdiffstats
path: root/pkgdb
blob: ae14660662b5210577260a604a9daa312ac72277 (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
#!/bin/bash
# $Id: pkgdb,v 1.6 2003/05/26 17:10:12 judd Exp $

tl=`pwd`

# we use this instead of mktemp cuz the RH server's mktemp is broken :(
uid=`id -u`
TMPFILE="/tmp/.mysqltmp.$uid"

repoid=$1
dbuser='archweb'
dbname='archweb'
dbpass='14xuk0Gi'

if [ "$repoid" = "" ]; then
	me=`basename $0`
	echo "usage: $me <repoid>"
	exit 1
fi

deletepkg()
{
	echo "Deleting $pkgname"
	mysql -u $dbuser -p$dbpass $dbname <<_EOF
DELETE FROM packages WHERE id='$id';
_EOF
}

updatepkg()
{
	echo "Updating $pkgname"
	mysql -u $dbuser -p$dbpass $dbname <<_EOF
UPDATE packages SET category='$category',pkgname='$pkgname',pkgver='$pkgver',
pkgrel='$pkgrel',pkgdesc='$pkgdesc',url='$url',sources='$sources',
depends='$deplist',lastupdate=NOW() WHERE id='$id';
_EOF
}

insertpkg()
{
	echo "Inserting $pkgname"
	mysql -u $dbuser -p$dbpass $dbname <<_EOF
INSERT INTO packages (id,repoid,category,pkgname,pkgver,pkgrel,
pkgdesc,url,sources,depends,lastupdate) VALUES (NULL,$repoid,
'$category','$pkgname','$pkgver','$pkgrel','$pkgdesc','$url',
'$sources','$deplist',NOW());
_EOF
}

process() {
	pkg=$1

	id=`echo $pkg | awk '{print $1}'`
	pkgname=`echo $pkg | awk '{print $2}'`
	oldver=`echo $pkg | awk '{print $3}'`
	oldrel=`echo $pkg | awk '{print $4}'`
	[ "$pkgname" = "" ] && return;
	cd $tl
	pkgdir=`find . -type d -name "$pkgname" -maxdepth 2 -mindepth 1 | head -1`
	if [ "$pkgdir" = "" ]; then
		deletepkg
	else
		cd $pkgdir
		if [ ! -f PKGBUILD ]; then
			echo "WARNING: missing PKGBUILD in `pwd`" >&2
		else
			unset depends source deplist sources
			unset pkgname pkgver pkgrel pkgdesc url
			. PKGBUILD
			# tag it
			touch .tag
			category=`pwd | sed 's|^.*/||g'`			
			cd - &>/dev/null
			deplist=${depends[@]}
			deplist=`php -r "echo addslashes(\"$deplist\");"`
			sources=${source[@]}
			sources=`php -r "echo addslashes(\"$sources\");"`
			pkgname=`php -r "echo addslashes(\"$pkgname\");"`
			pkgver=`php -r "echo addslashes(\"$pkgver\");"`
			pkgrel=`php -r "echo addslashes(\"$pkgrel\");"`
			pkgdesc=`php -r "echo addslashes(\"$pkgdesc\");"`
			url=`php -r "echo addslashes(\"$url\");"`

			if [ "$oldver" != "$pkgver" -o "$oldrel" != "$pkgrel" ]; then
				updatepkg
			fi							
		fi
	fi
}

echo "==> Updating Package Entries in Database..."
mysql --skip-column-names -u $dbuser -p$dbpass $dbname >$TMPFILE <<_EOF
SELECT id,pkgname,pkgver,pkgrel FROM packages WHERE repoid=$repoid
_EOF

cat $TMPFILE | ( \
	ln='a'
	while [ "$ln" != "" ]; do
		read ln
		process "$ln"
	done
)

cd $tl
for category in `find . -type d -maxdepth 1 | grep -v CVS | grep -v "^unofficial" | grep -v "^unstable"`; do
	for pkg in `ls $category | sort`; do
		category=`echo $category | sed 's|.*/||'`
		cd $tl/$category/$pkg
		if [ -f .tag ]; then
			# already processed
			rm -f .tag
		else
			if [ -f PKGBUILD ]; then
				. PKGBUILD
				deplist=${depends[@]}
				deplist=`php -r "echo addslashes(\"$deplist\");"`
				sources=${source[@]}
				sources=`php -r "echo addslashes(\"$sources\");"`
				pkgname=`php -r "echo addslashes(\"$pkgname\");"`
				pkgver=`php -r "echo addslashes(\"$pkgver\");"`
				pkgrel=`php -r "echo addslashes(\"$pkgrel\");"`
				pkgdesc=`php -r "echo addslashes(\"$pkgdesc\");"`
				url=`php -r "echo addslashes(\"$url\");"`
				insertpkg
			fi
		fi
		cd $tl
	done
done

rm -f $TMPFILE
exit 0