blob: 4efdb80f12bb05646f3c9d52fe5460dff4cbe31d (
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
|
#!/bin/sh
path=$(readlink -f $0)
path=$(dirname $path)
packages="$path/repository"
filelist="$path/filelist"
repos="main testing"
archs="x86 x86_64 armhf"
db="$path/db/filelist.db"
csv="$path/csv/filelist.csv"
turbo_db="/var/www/aports-turbo/db/filelist.db"
rsync="rsync://nl.alpinelinux.org/alpine/edge"
rm_stale_filelist() {
for repo in $repos; do
for arch in $archs; do
for list in $filelist/$repo/$arch/*.csv; do
local file="${list##*/}"
local apk="${file%.*}"
if [ ! -e "$packages/$repo/$arch/$apk" ]; then
rm -f "$list"
result=1
fi
done
done
done
}
update_filelist() {
for repo in $repos; do
for arch in $archs; do
mkdir -p "$filelist/$repo/$arch"
for apk in $packages/$repo/$arch/*.apk; do
local file="${apk##*/}"
if [ ! -e "$filelist/$repo/$arch/${file}.csv" ]; then
create_apk_csv "$apk" "$repo" "$arch" >> \
"$filelist/$repo/$arch/${file}.csv.tmp"
mv "$filelist/$repo/$arch/${file}.csv.tmp" \
"$filelist/$repo/$arch/${file}.csv"
result=1
fi
done
done
done
}
apk_sync() {
for repo in $repos; do
rsync -a --delete-before $rsync/$repo $packages || return 1
done
}
create_apk_csv() {
local apk="$1" repo="$2" arch="$3"
local list=$(tar --exclude ".*" -ztf "$apk")
local filename="${apk##*/}"
local pkgname="${filename%-*-*}"
IFS=$'\n'
for line in $list; do
local file="${line##*/}"
local path="${line%/*}"
case "$file" in
*,*) file="\"$file\"" ;;
esac
case "$path" in
*,*) path="\"$path\"" ;;
esac
[ ! -z "$file" ] && \
echo "$file,$path,$pkgname,$repo,$arch"
done
unset IFS
}
cat_csv() {
rm -f $csv
for repo in $repos; do
for arch in $archs; do
cat $filelist/$repo/$arch/*.csv >> $csv
done
done
}
prepare() {
rm -f $db $csv
mkdir -p ${csv%/*} ${db%/*}
}
create_db() {
printf "CREATE TABLE filelist(file text, path text, pkgname text, repo text, arch text);" | sqlite3 $db
printf ".mode csv\n.import $csv filelist" | sqlite3 $db
printf "CREATE INDEX file on filelist (file);" | sqlite3 $db
printf "CREATE INDEX arch on filelist (arch);" | sqlite3 $db
printf "CREATE INDEX pkgname on filelist (pkgname);" | sqlite3 $db
}
mv_db() {
mv $db $turbo_db
}
update_apkindex() {
$path/apkindex2sqlite.sh
}
# just do it
prepare && apk_sync && update_filelist && rm_stale_filelist
# only update db when we have changes
[ ! -z "$result" ] && cat_csv && create_db && mv_db && update_apkindex
|