-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_index.sh
executable file
·81 lines (66 loc) · 1.67 KB
/
gen_index.sh
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
#!/bin/bash
set -eu
[ -f pkg/index.db ] && rm pkg/index.db
[ -f pkg/index.csv ] && rm pkg/index.csv
sqlite3 pkg/index.db <<EOF
create table packages (
name varchar(100) primary key,
version varchar(20) not null,
build_revision varchar(40) not null,
description text,
home_url varchar(400),
archive_file_name varchar(100),
acrhive_sha256 varchar(64)
);
create table depends (
package_name varchar(100) not null,
depends_on varchar(100) not null,
unique (package_name, depends_on),
foreign key (package_name) references packages (name)
foreign key (depends_on) references packages (name)
);
EOF
get_field() {
grep -e "$2\b" $1 | cut -d= -f2- | awk '{$1=$1;print}'
}
sql_quote() {
val=$(echo "$*" | sed "s/'/''/")
echo "'$val'"
}
for f in pkg/*.pkginfo.txt; do
base=$(basename $f .pkginfo.txt)
pkgfile=${base}.pkg.tar.gz
parts=(${barepkgname//-/ })
pkgname=$(get_field $f pkgname)
pkgver=$(get_field $f pkgver)
buildrev=$(get_field $f buildrev)
echo -n "Adding $pkgname $pkgver"
pkgdesc=$(get_field $f pkgdesc)
pkgurl=$(get_field $f url)
sha256=$(sha256sum pkg/$pkgfile | cut -d" " -f1)
echo -n "."
sqlite3 pkg/index.db <<-EOF
insert into packages values(
$(sql_quote $pkgname),
$(sql_quote $pkgver),
$(sql_quote $buildrev),
$(sql_quote $pkgdesc),
$(sql_quote $pkgurl),
$(sql_quote $pkgfile),
$(sql_quote $sha256)
)
EOF
echo -n "."
for dep in $(get_field $f depend); do
sqlite3 pkg/index.db <<-EOF
insert into depends values (
$(sql_quote $pkgname),
$(sql_quote $dep)
)
EOF
done
echo -n "."
echo "$pkgname,$pkgver,$pkgfile,$sha256,$buildrev" >> pkg/index.csv
echo ".done"
done
echo "Done"