#!/bin/bash # init variables tmpDir="$(mktemp -d /tmp/archive.XXXXXX)" pkgDir="/srv/arch-mirror/arch/arch/archlinuxewe/os" pkgSrcDir="$(dirname $(readlink -f -n "$0"))" [ "$(hostname)" == "rechenknecht" ] && \ [ "${pkgSrcDir}" == "${HOME}" ] && \ aufRechenknecht=true || \ aufRechenknecht=false force=false upload=true updateMe=true abortOnMakepkgError=true # print help screen usage() { >&2 echo '' >&2 echo 'Skript zum Updaten der selbsterstellten Archlinux-Pakete' >&2 echo '' >&2 echo 'Verwendung:' >&2 echo ' '"$0"' [ -f|--force ] [ --no-upload ] [ --no-selfUpdate ] [ --no-abortOnMakepkgError ]' >&2 echo ' -f|--force: rebuild packages even if they look up to date' >&2 echo ' --no-upload: do not upload built packages from rechenknecht to jeti100' >&2 echo ' --no-selfUpdate: do not update this script from git' >&2 echo ' --no-abortOnMakepkgError: do not abort when makepkg returns non-zero' >&2 echo '' rm -rf "${tmpDir}" exit 1 } echo 'parse arguments ...' eval set -- "$(getopt -o f --long force,no-upload,no-selfUpdate,no-abortOnMakepkgError -n "$(basename "$0")" -- "$@" || echo "usage")" args=("$@") while true do case $1 in -f|--force) echo '"force" erkannt' force=true shift ;; --no-upload) echo '"no-upload" erkannt' upload=false shift ;; --no-selfUpdate) echo '"no-selfUpdate" erkannt' updateMe=false shift ;; --no-abortOnMakepkgError) echo '"no-abortOnMakepkgError" erkannt' abortOnMakepkgError=false shift ;; --) shift break ;; *) >&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende." rm -rf "${tmpDir}" exit 1 esac done if [ ! $# -eq 0 ] then >&2 echo 'FEHLER: Zu viele Argumente! Ich beende.' usage fi echo '... done' $aufRechenknecht && pkgSrcDir="${pkgSrcDir}/archPackages" cd "${pkgSrcDir}" # extract git HEAD git archive --format tar HEAD | \ tar -x -C "${tmpDir}" -f - cd "${tmpDir}" # update $0 if ${updateMe} && ${aufRechenknecht} && [ -e "$(basename $0)" ] && ! diff -q "$(basename $0)" "$0" &> /dev/null then cp "$(basename $0)" "$0" $0 "${args}" err=$? rm -rf "${tmpDir}" exit ${err} fi unset pakete unset archs unset verss # collect packages for paket in $( \ echo */PKGBUILD | \ sed "s|/PKGBUILD||g" \ ) do [ -d "${paket}" ] || continue . ${paket}/PKGBUILD for singleArch in "${arch[@]}" do [ "${singleArch}" == "x86_64" ] || \ [ "${singleArch}" == "i686" ] || \ [ "${singleArch}" == "any" ] || \ continue pkgFile="${paket}-${pkgver}-${pkgrel}-${singleArch}.pkg.tar.xz" allExist=true [ "${singleArch}" == "any" ] && \ for dir in ${pkgDir}/* do [ "${dir}" == "any" ] && continue [ ! -d "${dir}" ] && continue [ ! -e "${dir}/${pkgFile}" ] && allExist=false done if ${force} || \ ! ${aufRechenknecht} || \ [ ! -e "${pkgDir}/${singleArch}/${pkgFile}" ] || \ ! ${allExist} then pakete[${#pakete[@]}]="${paket}" archs[${#archs[@]}]="${singleArch}" verss[${#verss[@]}]="${pkgver}-${pkgrel}" fi done done if ${aufRechenknecht} then sudo pacman -Syy maxErr=0 # build packages for ((i=0; i<${#pakete[@]}; i++)) do paket="${pakete[${i}]}" arch="${archs[${i}]}" vers="${verss[${i}]}" cd "${tmpDir}/${paket}" rm -f ${paket}-*-${arch}.pkg.tar.xz if [ "${arch}" == "i686" ] then # 32-bit is built in chroot echo '\ sudo pacman -Sy && \ cd "'"${tmpDir}/${paket}"'" && \ _targetHost='\''--host=i686-pc-linux-gnu'\'' makepkg -fcsr --noconfirm && \ exit\ ' | \ chrootUnpriv err[${i}]=$? else # everything else is built directly makepkg -fcsr --noconfirm err[${i}]=$? fi if ${abortOnMakepkgError} && [ ${err[${i}]} -ne 0 ] then rm -rf "${tmpDir}" exit ${err[${i}]} fi [ ${err[${i}]} -gt ${maxErr} ] && maxErr=${err[${i}]} # upload packages if ${upload} && [ ${err[${i}]} -eq 0 ] then scp ${tmpDir}/${paket}/${paket}-${vers}-${arch}.pkg.tar.xz paule@127.0.0.1:${pkgDir}/${arch}/ [ "${arch}" == "any" ] && ssh paule@127.0.0.1 '\ cd '${pkgDir}' for dir in * do [ "${dir}" == "any" ] && continue [ ! -d "${dir}" ] && continue [ -e "'"${pkgDir}"'/${dir}/'"${paket}-${vers}-${arch}.pkg.tar.xz"'" ] && rm "'"${pkgDir}"'/${dir}/'"${paket}-${vers}-${arch}.pkg.tar.xz"'" ln -s "'"${pkgDir}/${arch}/${paket}-${vers}-${arch}.pkg.tar.xz"'" "'"${pkgDir}"'/${dir}/" done \ ' fi done # update packagedb if ${upload} then for ((i=0; i<${#pakete[@]}; i++)) do [ ${err[${i}]} == 0 ] || continue echo "${pakete[${i}]}" echo "${verss[${i}]}" echo "${archs[${i}]}" done | \ ssh paule@127.0.0.1 ' \ cd "'"${pkgDir}"'" while read paket do read vers || break read oarch || break # delete old versions of packages for arch in * do [ ! -d "${arch}" ] && continue [ ! "${arch}" == "any" ] && [ ! "${arch}" == "${oarch}" ] && continue for zuLoeschen in $( \ ls ${arch}/${paket}-*-${oarch}.pkg.tar.xz 2> /dev/null | \ grep -v "${arch}/${paket}-${vers}-${oarch}.pkg.tar.xz" \ ) do repo-remove \ "${arch}/archlinuxewe.db.tar.gz" \ "${zuLoeschen}" rm "${zuLoeschen}" done done # update db for arch in * do [ ! -d "${arch}" ] && continue [ "${arch}" == "any" ] && continue [ ! "${oarch}" == "any" ] && [ ! "${arch}" == "${oarch}" ] && continue repo-add \ '${pkgDir}'/${arch}/archlinuxewe.db.tar.gz \ '${pkgDir}'/${arch}/${paket}-${vers}-${oarch}.pkg.tar.xz done done # check db err=0 for arch in * do [ ! -d "${arch}" ] && continue [ "${arch}" == "any" ] && continue for warnungen in $( \ ( tar -Oxzf '${pkgDir}'/${arch}/archlinuxewe.db.tar.gz | \ grep -A1 "^%FILENAME%\$" | \ grep -v "^%FILENAME%\$" | \ grep -v -- "^--\$" ls '${pkgDir}'/${arch} | \ grep "^.*\.pkg\.tar\.xz\$" ) | \ sort | \ uniq -u ) do err=1 >&2 echo "FEHLER: Paket '${pkgDir}'/${arch}/${warnungen} ist entweder nur in der Datenbank oder nur im Verzeichnisbaum vorhanden." done done exit ${err} ' fi if [ ${maxErr} -ne 0 ] then rm -rf "${tmpDir}" exit ${maxErr} fi else # check packages err=false for ((i=0; i<${#pakete[@]}; i++)) do paket="${pakete[${i}]}" . ${paket}/PKGBUILD if echo "${source}" | grep -q "://opensources\.eckner\.net/" then # one of Erich's packages remSum="$(curl -o - "${source#*::}&post=sha256sum" 2> /dev/null)" if [ ! "${remSum}" == "${sha256sums}" ] then >&2 echo "sha256sum von ${pkgname} stimmt nicht: ${remSum} vs. ${sha256sums}." err=true fi elif echo "${source}" | grep -q "://arch\.eckner\.net/" then # a modified official package offVer="$( \ ssh paule@jeti100 'ls '"${pkgDir}"'/*/'"${paket}"'-*.pkg.tar.xz' | \ xargs -n1 basename | \ sort -V | \ tail -n1 \ )" if [ ! "${offVer}" == "${pkgname}-${pkgver}-${pkgrel}-${arch}.pkg.tar.xz" ] then >&2 echo "${pkgname} ist in den offiziellen Quellen aktueller: ${offVer}." err=true fi fi done if ${err} then rm -rf "${tmpDir}" exit 1 fi cd "${pkgSrcDir}" git push err=$? if [ ${err} -ne 0 ] then rm -rf "${tmpDir}" exit ${err} fi ssh -p 22222 141.35.51.219 "~/archPackagesUpdate" "${args}" err=$? if [ ${err} -ne 0 ] then rm -rf "${tmpDir}" exit ${err} fi fi # clean up rm -rf "${tmpDir}"