-
Notifications
You must be signed in to change notification settings - Fork 1
/
createlinks.sh
executable file
·63 lines (51 loc) · 1.7 KB
/
createlinks.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
#!/bin/bash
# modified https://github.com/archlinux/infrastructure/master/roles/sogrep/files/createlinks
target="$1"
repos=("$2")
arches=('x86_64' 'i686' 'arm' 'armv6h' 'armv7h' 'aarch64')
lock='/tmp/links.lck'
tmp="$(mktemp -d)"
[ -f "${lock}" ] && exit 1
touch "${lock}"
renice +10 -p $$ > /dev/null
getpkgname() {
local tmp
tmp=${1##*/}
echo ${tmp%-*.pkg.tar.*}
}
for repo in ${repos[@]}; do
for arch in ${arches[@]}; do
repodir=${arch}
[ ! -f ${target}/$repodir/$repo.db ] && continue
mkdir -p ${tmp}/tmp/${repodir}
# extract old file archive
if [ -f ${target}/${repodir}/${repo}.links.tar.gz ]; then
mkdir -p ${tmp}/cache/${repodir}
bsdtar -xf ${target}/${repodir}/${repo}.links.tar.gz -C ${tmp}/cache/${repodir}
fi
# create file lists
for pkg in $(find $target/$repodir -xtype f -name "*-${arch}.pkg.tar.*" ! -name "*.sig"); do
pkgname=$(getpkgname $pkg)
tmppkgdir=${tmp}/tmp/${repodir}/${pkgname}
mkdir -p $tmppkgdir
if [ -f "${tmp}/cache/${repodir}/${pkgname}/links" ]; then
# reuse the cached file
mv ${tmp}/cache/${repodir}/${pkgname}/links ${tmppkgdir}/links
else
echo "$repo/$arch: $pkgname"
mkdir -p ${tmppkgdir}/pkg
zstd -d --stdout $pkg | bsdtar -xof - -C ${tmppkgdir}/pkg --include={opt,{,usr/}{lib{,32},{s,}bin}}'/*' 2>/dev/null
for f in $(find ${tmppkgdir}/pkg -type f); do
readelf -d "$f" 2> /dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p'
done | sort -u > ${tmppkgdir}/links
rm -rf ${tmppkgdir}/pkg
fi
done
# create new file archive
pkgdir=${target}/${repodir}
mkdir -p $pkgdir
bsdtar --exclude=*.tar.* -czf ${pkgdir}/${repo}.links.tar.gz -C ${tmp}/tmp/${repodir} .
done
done
rm -rf ${tmp}
rm -f "${lock}"