summaryrefslogtreecommitdiffstats
path: root/pkgdb
blob: b394e3aab69033926f274d076ee82c003addae9c (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
#!/bin/bash
# $Id: pkgdb,v 1.2 2003/05/23 05:08:57 judd Exp $

tl=`pwd`
TMPFILE=/tmp/.mysqltmp
repoid=$1
dbuser='archweb'
dbname='archweb'
dbpass='14xuk0Gi'

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

echo "==> Updating Package Entries in Database..."

for category in `find * -type d -maxdepth 0 | grep -v CVS | grep -v "^unofficial" | grep -v "^unstable"`; do
  for pkg in `ls $category | sort`; do
    cd $tl/$category/$pkg
    if [ -f PKGBUILD ]; then
			unset depends source deplist sources
			unset pkgname pkgver pkgrel pkgdesc url
      . 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\");"`
			mysql -u $dbuser -p$dbpass $dbname >$TMPFILE <<_EOF
SELECT id,pkgver,pkgrel FROM packages WHERE repoid=$repoid AND pkgname='$pkgname';
_EOF
			id=`tail -1 $TMPFILE | awk '{print $1}'`
			if [ "$id" != "" ]; then
				oldver=`tail -1 $TMPFILE | awk '{print $2}'`
				oldrel=`tail -1 $TMPFILE | awk '{print $3}'`
				if [ "$oldver" != "$pkgver" -o "$oldrel" != "$pkgrel" ]; then
					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
				fi							
			else
			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
			fi
		fi
  done
  cd $tl
done

rm -f $TMPFILE