diff options
Diffstat (limited to 'apkcontent2sqlite.sh')
-rwxr-xr-x | apkcontent2sqlite.sh | 139 |
1 files changed, 95 insertions, 44 deletions
diff --git a/apkcontent2sqlite.sh b/apkcontent2sqlite.sh index f7a381c..21d4284 100755 --- a/apkcontent2sqlite.sh +++ b/apkcontent2sqlite.sh @@ -1,48 +1,99 @@ #!/bin/sh -base="/var/www/localhost/htdocs/alpine" -#release=$(readlink $base/latest-stable) -release="edge" +packages="repository" +filelist="filelist" repos="main testing" archs="x86 x86_64 armhf" -output="output.csv" -database="filelist.db" - -create_filelist() { - local apk="$1" repo="$2" arch="$3" - local filelist=$(tar --exclude ".*" -ztf "$apk") - local filename="${apk##*/}" - local pkgname="${filename%-*-*}" - IFS=$'\n' - for item in $filelist; do - file="${item##*/}" - path="${item%/*}" - case "$file" in - *,*) file="\"$file\"" ;; - esac - case "$path" in - *,*) path="\"$path\"" ;; - esac - [ ! -z "$file" ] && \ - echo "$file,$path,$pkgname,$repo,$arch" >> $output - done - unset IFS -} - - -rm -f $output $database - -printf "CREATE TABLE filelist(file text, path text, pkgname text, repo text, arch text);" | sqlite3 $database - -for repo in $repos; do - for arch in $archs; do - printf "Starting: $repo/$arch" - for apk in $base/$release/$repo/$arch/*.apk; do - printf . - create_filelist "$apk" "$repo" "$arch" - done - printf "\n" - done -done - -printf ".mode csv\n.import $output filelist" | sqlite3 $database +db="db/filelist.db" +csv="csv/filelist.csv" +turbo_db="/var/www/aports-turbo/db/apkindex.db" + +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" + 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 +} + +# 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 + |