summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rwxr-xr-xcreatelinks69
-rwxr-xr-xgetpkgbase43
-rwxr-xr-xsogrep35
-rwxr-xr-xsyncrepo29
5 files changed, 179 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0653bab
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+repo/
+files
+*~
diff --git a/createlinks b/createlinks
new file mode 100755
index 0000000..bfcefae
--- /dev/null
+++ b/createlinks
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+home="$(dirname "${0}")"
+target="${home}/repo"
+repos=('core' 'extra' 'community')
+arches=('i686' 'x86_64')
+lock='/tmp/mirrorsync.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=${repo}/os/${arch}
+ cached=false
+
+ # 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}
+ cached=true
+ fi
+
+ # create file lists
+ for pkg in $(find $target/$repodir -type f -name '*.pkg.tar.*'); 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
+ bsdtar -xof $pkg -C ${tmppkgdir}/pkg --include={opt,{,usr/}{lib,{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
+ cached=false
+ fi
+ done
+
+ # create new file archive
+ if ! $cached; then
+ # at least one package has changed, so let's rebuild the archive
+ pkgdir=${target}/${repodir}
+ mkdir -p $pkgdir
+ bsdtar --exclude=*.tar.* -czf ${pkgdir}/${repo}.links.tar.gz -C ${tmp}/tmp/${repodir} .
+ fi
+ # )&
+ done
+#wait
+done
+
+rm -rf ${tmp}
+rm -f "${lock}"
diff --git a/getpkgbase b/getpkgbase
new file mode 100755
index 0000000..2206a08
--- /dev/null
+++ b/getpkgbase
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# usage: _grep_pkginfo pkgfile pattern
+_grep_pkginfo() {
+ local _ret
+
+ _ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 -E "$2" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')"
+ echo "$_ret"
+}
+
+# Get the package name
+getpkgname() {
+ local _name
+
+ _name="$(_grep_pkginfo "$1" "^pkgname")"
+ if [ -z "$_name" ]; then
+ echo "ERROR: Package '$1' has no pkgname in the PKGINFO. Fail!" >&2
+ exit 1
+ fi
+
+ echo "$_name"
+}
+
+# Get the package base or name as fallback
+getpkgbase() {
+ local _base
+
+ _base="$(_grep_pkginfo "$1" "^pkgbase")"
+ if [ -z "$_base" ]; then
+ getpkgname "$1"
+ return 0
+ fi
+
+ echo "$_base"
+}
+
+
+if [ $# -ne 1 ]; then
+ echo "usage: $(basename $0) <pkgfile>"
+ exit 1
+fi
+
+getpkgbase "${1}"
diff --git a/sogrep b/sogrep
new file mode 100755
index 0000000..b80d66f
--- /dev/null
+++ b/sogrep
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+home="$(dirname "${0}")"
+target="${home}/repo"
+tmp=$(mktemp -d)
+arches=('i686' 'x86_64')
+lock='/tmp/mirrorsync.lck'
+
+[ -f "${lock}" ] && exit 1
+
+if [ $# -ne 2 ]; then
+ echo "usage: $(basename $0) <repo> <soname>"
+ exit 1
+fi
+
+repo="${1}"
+lib="${2}"
+
+for arch in ${arches[@]}; do
+ db=${target}/${repo}/os/${arch}/${repo}.links.tar.gz
+ if [ -f ${db} ]; then
+ mkdir -p ${tmp}/${repo}/${arch}
+ bsdtar -xf ${db} -C ${tmp}/${repo}/${arch}
+ else
+ echo "${db} not found!"
+ exit 1
+ fi
+done
+
+for i in $(grep -rl "${lib}" ${tmp}); do
+ pkg=$(basename $(dirname $i))
+ echo ${pkg%-*-*}
+done | sort -u
+
+rm -rf ${tmp}
diff --git a/syncrepo b/syncrepo
new file mode 100755
index 0000000..1803b8c
--- /dev/null
+++ b/syncrepo
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+home="$(dirname "${0}")"
+target="${home}/repo"
+lock='/tmp/mirrorsync.lck'
+source='-e ssh gerolde.archlinux.org:/srv/ftp'
+repos='core,extra,testing,community,community-testing'
+
+[ ! -d "${target}" ] && exit 1
+[ -f "${lock}" ] && exit 1
+touch "${lock}"
+
+rsync -rptlv --safe-links --delete --progress -h \
+ --include='*/' \
+ --include='*.db.tar.gz' \
+ --exclude='*' \
+ ${source}/{${repos}} \
+ "${target}"
+
+rsync -rptlv --safe-links --delete --progress -h \
+ --exclude='*.db.tar.gz*' \
+ --exclude='*.abs.tar.gz*' \
+ --exclude='*.files.tar.gz*' \
+ --exclude='*.links.tar.gz*' \
+ --exclude='lastsync' \
+ ${source}/{${repos}} \
+ "${target}"
+
+rm -f "${lock}"