diff options
-rwxr-xr-x | apk-content2sqlite.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/apk-content2sqlite.sh b/apk-content2sqlite.sh new file mode 100755 index 0000000..d09f7fd --- /dev/null +++ b/apk-content2sqlite.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +base="/var/www/localhost/htdocs/alpine" +#release=$(readlink $base/latest-stable) +release="edge" +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%-*-*}" + oIFS=$IFS + 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 + IFS=$oIFS +} + + +rm -f $output $database + +printf "CREATE TABLE filelist(file varchar(255), path text, pkgname varchar(255), repo varchar(8), arch varchar(8));" | 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 + done +done + +printf ".mode csv\n.import $output filelist" | sqlite3 $database |