--- srcpac0 2011-08-17 22:09:23.304042065 +0200 +++ srcpac 2011-08-17 21:46:24.841693343 +0200 @@ -26,6 +26,7 @@ [ -f /etc/abs.conf ] && source /etc/abs.conf [ -f /etc/makepkg.conf ] && source /etc/makepkg.conf [ -f ~/.makepkg.conf ] && source ~/.makepkg.conf +[ -f /etc/srcpac.conf ] && source /etc/srcpac.conf usage() { @@ -42,7 +43,8 @@ echo " -b, --build builds the targets from source" echo " -m, --makedeps remove the makedepends after the build" echo " -o, --onlyconf applies the changes and displays the PKGBUILD without building" - + echo " -z, --git uses the ArchLinux Git repository instead of the ABS tree" + exit 0 } @@ -84,7 +86,7 @@ { local found=0 - for pkgbuild in ${ABSROOT}*/*/PKGBUILD; do + for pkgbuild in ${ALL_PKGBUILDS}; do unset pkgbase unset pkgname source $pkgbuild &> /dev/null @@ -93,7 +95,7 @@ break else for _package in "${pkgname[@]}"; do - if [ "${1}" = "${_package}" ]; then + if [ "${1}" = "${_package}" ]; then found=1 break fi @@ -107,7 +109,7 @@ if [ ${found} -eq 1 ]; then local already=0 - local tmp=${pkgbuild#${ABSROOT}} + local tmp=${pkgbuild#${PKGROOT}} for c in ${candidates}; do if [ "${tmp/\/PKGBUILD}" = "$c" ]; then already=1 @@ -118,7 +120,7 @@ candidates="${candidates} ${tmp/\/PKGBUILD}" fi else - echo "Error: Could not find \"${1}\" under ${ABSROOT}" + echo "Error: Could not find \"${1}\" under ${PKGROOT}" fi } @@ -127,9 +129,28 @@ ## refresh() { - echo -n "Starting ABS sync..." - abs &> /dev/null - echo "done" + if [ ${USEGIT} -eq 0 ]; then + echo -n "Starting ABS sync..." + abs &> /dev/null + echo "done" + else + if [ -d "${PKGROOT}" ]; then + ( cd "${PKGROOT}" && git checkout --force && git pull; ) + else + local gitrootbase="`basename "${PKGROOT}"`" + local gitrootparent="${PKGROOT%/${gitrootbase}}" + if [ -d "${gitrootparent}" ]; then + ( cd "${gitrootparent}" && git clone "${GITREPO}" "${gitrootbase}"; ) + else + echo 'Error: The GITROOT environment variable has an invalid value: '"${PKGROOT}" + exit 1 + fi + fi + if [ $? -ne 0 ]; then + echo 'Error: Git repository update failed' + exit 1 + fi + fi pacman -Sy if [ ${#args[@]} -eq 0 -a $SYSUPGRADE -eq 0 ]; then exit 0 @@ -141,16 +162,17 @@ ## build_packages() { - action="build" + local action="build" if [ "$1" = "install" ]; then action="install" fi shift - pkg=${1#*/} - pkgdir="${ABSROOT}/${1}" - builddir=/var/srcpac/${pkg} + local pkg=${1#*/} + local pkg=${pkg%/*} + local pkgdir="${PKGROOT}/${1}" + local builddir=/var/srcpac/${pkg} MAKEPKGOPTS="-c -s" [ $NODEPS -eq 1 ] && MAKEPKGOPTS="${MAKEPKGOPTS} -d" @@ -167,7 +189,7 @@ if [ -z "${SUDO_USER}" ]; then chown -R nobody ${builddir} - makepkg ${MAKEPKGOPTS} --asroot + sudo -u nobody makepkg ${MAKEPKGOPTS} else chown -R ${SUDO_USER} ${builddir} sudo -u ${SUDO_USER} makepkg ${MAKEPKGOPTS} @@ -206,6 +228,8 @@ pkglist="${pkglist} ${builddir}/${builtpkgs[$i]}-${pkgver}-*.pkg.tar.?z" done pacman $PACARGS ${pkglist} + else + pacman $PACARGS ${builddir}/*.pkg.tar.?z fi else pacman $PACARGS ${builddir}/*.pkg.tar.?z @@ -243,9 +267,9 @@ BUILD=0 ONLYCONF=0 MAKEDEPS=1 + USEGIT=0 ARGLIST=$@ - ARGSANS="" while [ "$#" -ne "0" ]; do case $1 in @@ -253,85 +277,69 @@ --version) version ;; --query) MAJOR="query" - ARGSANS="$ARGSANS $1" ;; --remove) MAJOR="remove" - ARGSANS="$ARGSANS $1" ;; --sync) MAJOR="sync" - ARGSANS="$ARGSANS $1" ;; --asdeps) ASDEPS=1 - ARGSANS="$ARGSANS $1" ;; --asexplicit) ASEXPLICIT=1 - ARGSANS="$ARGSANS $1" ;; --nodeps) NODEPS=1 - ARGSANS="$ARGSANS $1" ;; --force) FORCE=1 - ARGSANS="$ARGSANS $1" ;; --info) INFO=1 - ARGSANS="$ARGSANS $1" ;; --sysupgrade) SYSUPGRADE=1 - ARGSANS="$ARGSANS $1" ;; --downloadonly) DOWNLOAD=1 - ARGSANS="$ARGSANS $1" ;; --refresh) REFRESH=1 - ARGSANS="$ARGSANS $1" ;; --ignore) IGNORE=1 IGNOREPKG="$IGNOREPKG $2" - ARGSANS="$ARGSANS $1 $2" ;; --noconfirm) NOCONFIRM=1 - ARGSANS="$ARGSANS $1" ;; --root) ROOT=1 NEWROOT="$2" - ARGSANS="$ARGSANS $1 $2" shift ;; --build) BUILD=1 - ARGSANS="$ARGSANS $1" ;; --onlyconf) ONLYCONF=1 - ARGSANS="$ARGSANS $1" ;; --makedeps) MAKEDEPS=0 - ARGSANS="$ARGSANS $1" + ;; + --git) + USEGIT=1 ;; --*) - ARGSANS="$ARGSANS $1" ;; -*) - ARGSANS="$ARGSANS $1" if [ $(echo $1 | grep r) ]; then OPTIONAL=$2 fi OPTIND=1 - while getopts ":VQRSbdfimuyr:ow" opt $1 $OPTIONAL; do + while getopts ":VQRSbdfimuyr:owz" opt $1 $OPTIONAL; do case $opt in V) version ;; Q) MAJOR="query" ;; @@ -349,6 +357,7 @@ u) SYSUPGRADE=1 ;; w) DOWNLOAD=1 ;; y) REFRESH=1 ;; + z) USEGIT=1 ;; esac done ;; @@ -393,15 +402,29 @@ usage exit 1 fi - + if [ ${UID} -ne 0 -a -z "${SUDO_USER}" -a ${MAJOR} != "query" ]; then - echo "Error: You need to use sudo or to be root" + echo "Error: You need to be root" exit 1 fi - if [ -z "${ABSROOT}" ]; then - echo "Error: The ABSROOT environment variable is not defined" - exit 1 + if [ ${MAJOR} != "query" -a ${MAJOR} != "remove" ]; then + if [ ${USEGIT} -eq 0 ]; then + if [ -z "${ABSROOT}" ]; then + echo "Error: The ABSROOT environment variable is not defined" + exit 1 + fi + else + if [ -z "${GITROOT}" ]; then + echo "Error: The GITROOT environment variable is not defined" + exit 1 + fi + + if [ -z "${GITREPO}" ]; then + echo "Error: The GITREPO environment variable is not defined" + exit 1 + fi + fi fi if [ ! -d /var/lib/srcpac ]; then @@ -410,7 +433,7 @@ if [ "${MAJOR}" = "remove" ]; then pacman $ARGLIST - + for pkg in ${args[@]}; do remove $pkg done @@ -427,7 +450,7 @@ if [ $? -eq 0 ]; then is_built $pkg if [ $INFO -eq 1 ]; then - echo -n "Source : " + echo -n "Source : " if [ $built -eq 1 ]; then echo "Yes" else @@ -445,6 +468,14 @@ done fi + if [ ${USEGIT} -eq 0 ]; then + ALL_PKGBUILDS="${ABSROOT%/}/*/*/PKGBUILD" + PKGROOT="${ABSROOT}" + else + ALL_PKGBUILDS="${GITROOT%/}/*/trunk/PKGBUILD" + PKGROOT="${GITROOT}" + fi + if [ "${MAJOR}" = "sync" ]; then if [ $BUILD -eq 0 -a $ONLYCONF -ne 1 ]; then if [ $SYSUPGRADE -eq 1 ]; then @@ -515,7 +546,7 @@ done for pkg in ${candidates}; do - apply_config "${pkg#*/}" "${ABSROOT}/$pkg" noreplace + apply_config "${pkg#*/}" "${PKGROOT}/$pkg" noreplace done exit 0 fi @@ -528,8 +559,9 @@ if [ -n "${candidates}" ]; then echo echo -n "Source Targets: " - for pkg in ${candidates}; do - echo -n "${pkg#*/} " + for candidate in ${candidates}; do + candidate="${candidate#*/}" + echo -n "${candidate%/*} " done echo if [ ${NOCONFIRM} -eq 0 ]; then