summaryrefslogtreecommitdiffstats
path: root/pkgdb
blob: d2cf510d48697a25ca2088691c2e5132cea5dee1 (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
#!/bin/bash
# $Id: pkgdb,v 1.14 2004/05/06 02:27:40 judd Exp $

tl=`pwd`

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

dbuser='archweb'
dbname='archweb'
dbpass='YWkrOjqm'

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
	mysql -u $dbuser -p$dbpass $dbname <<_EOF
DELETE FROM todolist_pkgs WHERE pkgid='$id';
_EOF
}

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

insertpkg()
{
	echo "Inserting $pkgname"
	mysql -u $dbuser -p$dbpass $dbname <<_EOF
INSERT INTO packages (id,repoid,categoryid,pkgname,pkgver,pkgrel,
pkgdesc,url,sources,depends,lastupdate) VALUES (NULL,$repoid,
'$categoryid','$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|$tl/||" | sed 's|/.*$||'`
			mysql --skip-column-names -u $dbuser -p$dbpass $dbname >$TMPFILE2 <<_EOF
SELECT id FROM categories WHERE category='$category';
_EOF
			categoryid=`cat $TMPFILE2 | awk '{print $1}'`
			if [ "$categoryid" = "" ]; then
				echo "WARNING: no categoryid found for '$category'" >&2
			fi
			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

echo " -> Scanning for Updated/Deleted packages..."
cat $TMPFILE | ( \
	ln='a'
	while [ "$ln" != "" ]; do
		read ln
		process "$ln"
	done
)

echo " -> Scanning for New packages..."
cd $tl
for category in `find . -type d -maxdepth 1 | grep -v CVS | grep -v "^extra" | grep -v "^unstable"`; do
	category=`echo $category | sed 's|./||'`
	if [ "$category" = "." ]; then
		continue
	fi
	mysql --skip-column-names -u $dbuser -p$dbpass $dbname >$TMPFILE <<_EOF
SELECT id FROM categories WHERE category='$category';
_EOF
	categoryid=`cat $TMPFILE | awk '{print $1}'`
	if [ "$categoryid" = "" ]; then
		echo "WARNING: no categoryid found for '$category'" >&2
	fi
	for pkg in `ls $category | sort`; do
		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