diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.am | 4 | ||||
-rw-r--r-- | scripts/makepkg.sh.in | 847 | ||||
-rw-r--r-- | scripts/pacman-optimize.sh.in | 22 | ||||
-rw-r--r-- | scripts/pkgdelta.sh.in | 22 | ||||
-rw-r--r-- | scripts/rankmirrors.py.in | 189 | ||||
-rw-r--r-- | scripts/rankmirrors.sh.in | 202 | ||||
-rw-r--r-- | scripts/repo-add.sh.in | 95 |
7 files changed, 733 insertions, 648 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 5d656534..330acb98 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -16,7 +16,7 @@ EXTRA_DIST = \ makepkg.sh.in \ pacman-optimize.sh.in \ pkgdelta.sh.in \ - rankmirrors.py.in \ + rankmirrors.sh.in \ repo-add.sh.in # Files that should be removed, but which Automake does not know. @@ -62,7 +62,7 @@ $(OURSCRIPTS): Makefile makepkg: $(srcdir)/makepkg.sh.in pacman-optimize: $(srcdir)/pacman-optimize.sh.in pkgdelta: $(srcdir)/pkgdelta.sh.in -rankmirrors: $(srcdir)/rankmirrors.py.in +rankmirrors: $(srcdir)/rankmirrors.sh.in repo-add: $(srcdir)/repo-add.sh.in repo-remove: $(srcdir)/repo-add.sh.in rm -f repo-remove diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index f58e2742..5bd294c1 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -27,8 +27,8 @@ # makepkg uses quite a few external programs during its execution. You # need to have at least the following installed for makepkg to function: -# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils), -# getopt (util-linux), gettext, grep, gzip, openssl, sed +# bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils), +# getopt (util-linux), gettext, grep, gzip, openssl, sed, tput (ncurses) # gettext initialization export TEXTDOMAIN='pacman' @@ -46,8 +46,9 @@ pkgdir="$startdir/pkg" packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') other_options=('ccache' 'distcc' 'makeflags' 'force') -splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \ - 'conflicts' 'replaces' 'backup' 'options' 'install') +splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \ + 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \ + 'backup' 'options' 'install' 'changelog') readonly -a packaging_options other_options splitpkg_overrides # Options @@ -69,9 +70,10 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +BUILDFUNC=0 PKGFUNC=0 SPLITPKG=0 -COLORMSG=0 +PKGLIST="" # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call # when dealing with svn/cvs/etc PKGBUILDs. @@ -83,47 +85,27 @@ PACMAN_OPTS= plain() { local mesg=$1; shift - if [ $COLORMSG -eq 1 ]; then - printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 - else - printf " ${mesg}\n" "$@" >&2 - fi + printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg() { local mesg=$1; shift - if [ $COLORMSG -eq 1 ]; then - printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 - else - printf "==> ${mesg}\n" "$@" >&2 - fi + printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg2() { local mesg=$1; shift - if [ $COLORMSG -eq 1 ]; then - printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 - else - printf " -> ${mesg}\n" "$@" >&2 - fi + printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } warning() { local mesg=$1; shift - if [ $COLORMSG -eq 1 ]; then - printf "\033[1;33m==> $(gettext "WARNING:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 - else - printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 - fi + printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { local mesg=$1; shift - if [ $COLORMSG -eq 1 ]; then - printf "\033[1;31m==> $(gettext "ERROR:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 - else - printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 - fi + printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } @@ -132,10 +114,11 @@ error() { # the fakeroot call, the error message will be printed by the main call. ## trap_exit() { - if [ "$INFAKEROOT" -eq 0 ]; then + if (( ! INFAKEROOT )); then echo error "$@" fi + [[ -n $srclinks ]] && rm -rf "$srclinks" exit 1 } @@ -146,25 +129,36 @@ trap_exit() { clean_up() { local EXIT_CODE=$? - if [ "$INFAKEROOT" -eq 1 ]; then + if (( INFAKEROOT )); then # Don't clean up when leaving fakeroot, we're not done yet. return fi - if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then + if (( ! EXIT_CODE && CLEANUP )); then # If it's a clean exit and -c/--clean has been passed... msg "$(gettext "Cleaning up...")" rm -rf "$pkgdir" "$srcdir" - if [ -n "$pkgbase" ]; then + if [[ -n $pkgbase ]]; then # Can't do this unless the BUILDSCRIPT has been sourced. - rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"* - if [ "$PKGFUNC" -eq 1 ]; then + if (( BUILDFUNC )); then + rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"* + fi + if (( PKGFUNC )); then rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"* - elif [ "$SPLITPKG" -eq 1 ]; then + elif (( SPLITPKG )); then for pkg in ${pkgname[@]}; do - rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"* + rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package_${pkg}.log"* done fi + + # clean up dangling symlinks to packages + for pkg in ${pkgname[@]}; do + for file in ${pkg}-*-*-${CARCH}${PKGEXT}; do + if [[ -h $file && ! -e $file ]]; then + rm -f $file + fi + done + done fi fi @@ -175,6 +169,7 @@ clean_up() { ## # Signal Traps ## +set -E trap 'clean_up' 0 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT @@ -187,15 +182,15 @@ trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR # extract the filename from a source entry get_filename() { # if a filename is specified, use it - local filename=$(echo $1 | sed 's|::.*||') + local filename="${1%%::*}" # if it is just an URL, we only keep the last component - echo "$filename" | sed 's|^.*://.*/||g' + echo "${filename##*/}" } # extract the URL from a source entry get_url() { # strip an eventual filename - echo $1 | sed 's|.*::||' + echo "${1#*::}" } ## @@ -209,14 +204,14 @@ get_url() { ## check_option() { local ret=$(in_opt_array "$1" ${options[@]}) - if [ "$ret" != '?' ]; then + if [[ $ret != '?' ]]; then echo $ret return fi # fall back to makepkg.conf options ret=$(in_opt_array "$1" ${OPTIONS[@]}) - if [ "$ret" != '?' ]; then + if [[ $ret != '?' ]]; then echo $ret return fi @@ -245,15 +240,15 @@ check_buildenv() { # ? - not found ## in_opt_array() { - local needle=$(echo $1 | tr '[:upper:]' '[:lower:]'); shift + local needle="${1,,}"; shift local opt for opt in "$@"; do - opt=$(echo $opt | tr '[:upper:]' '[:lower:]') - if [ "$opt" = "$needle" ]; then + opt="${opt,,}" + if [[ $opt = $needle ]]; then echo 'y' # Enabled return - elif [ "$opt" = "!$needle" ]; then + elif [[ $opt = "!$needle" ]]; then echo 'n' # Disabled return fi @@ -270,10 +265,10 @@ in_opt_array() { ## in_array() { local needle=$1; shift - [ -z "$1" ] && return 1 # Not Found + [[ -z $1 ]] && return 1 # Not Found local item for item in "$@"; do - [ "$item" = "$needle" ] && return 0 # Found + [[ $item = $needle ]] && return 0 # Found done return 1 # Not Found } @@ -281,28 +276,28 @@ in_array() { get_downloadclient() { # $1 = URL with valid protocol prefix local url=$1 - local proto=$(echo "$url" | sed 's|://.*||') + local proto="${url%%://*}" # loop through DOWNLOAD_AGENTS variable looking for protocol local i for i in "${DLAGENTS[@]}"; do - local handler=$(echo $i | sed 's|::.*||') - if [ "$proto" = "$handler" ]; then - agent=$(echo $i | sed 's|^.*::||') + local handler="${i%%::*}" + if [[ $proto = $handler ]]; then + agent="${i##*::}" break fi done # if we didn't find an agent, return an error - if [ -z "$agent" ]; then + if [[ -z $agent ]]; then error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF" plain "$(gettext "Aborting...")" exit 1 # $E_CONFIG_ERROR fi # ensure specified program is installed - local program="$(echo $agent | awk '{print $1 }')" - if [ ! -x "$program" ]; then + local program="${agent%% *}" + if [[ ! -x $program ]]; then local baseprog=$(basename $program) error "$(gettext "The download program %s is not installed.")" "$baseprog" plain "$(gettext "Aborting...")" @@ -320,7 +315,7 @@ download_file() { # destination file local file=$3 # temporary download file, default to last component of the URL - local dlfile=$(echo "$url" | sed 's|^.*://.*/||g') + local dlfile="${url##*/}" # replace %o by the temporary dlfile if it exists if echo "$dlcmd" | grep -q "%o" ; then @@ -334,52 +329,61 @@ download_file() { dlcmd="$dlcmd \"$url\"" fi - eval $dlcmd || return $? + local ret=0 + eval "$dlcmd || ret=\$?" + if (( ret )); then + [[ ! -s $dlfile ]] && rm -f -- "$dlfile" + return $ret + fi # rename the temporary download file to the final destination - if [ "$dlfile" != "$file" ]; then + if [[ $dlfile != $file ]]; then mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file" fi } +run_pacman() { + local ret=0 + if (( ! ASROOT )) && [[ $1 != "-T" ]] && sudo -l $PACMAN &>/dev/null; then + sudo $PACMAN $PACMAN_OPTS "$@" || ret=$? + else + $PACMAN $PACMAN_OPTS "$@" || ret=$? + fi + return $ret +} + check_deps() { - [ $# -gt 0 ] || return + (( $# > 0 )) || return - pmout=$(pacman $PACMAN_OPTS -T "$@") + local ret=0 + pmout=$(run_pacman -T "$@") ret=$? - if [ $ret -eq 127 ]; then #unresolved deps + if (( ret == 127 )); then #unresolved deps echo "$pmout" - elif [ $ret -ne 0 ]; then - error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout" + elif (( ret )); then + error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout" exit 1 fi } -handledeps() { +handle_deps() { local R_DEPS_SATISFIED=0 local R_DEPS_MISSING=1 - [ $# -eq 0 ] && return $R_DEPS_SATISFIED + (( $# == 0 )) && return $R_DEPS_SATISFIED local deplist="$*" - if [ "$DEP_BIN" -eq 0 ]; then + if (( ! DEP_BIN )); then return $R_DEPS_MISSING fi - if [ "$DEP_BIN" -eq 1 ]; then + if (( DEP_BIN )); then # install missing deps from binary packages (using pacman -S) msg "$(gettext "Installing missing dependencies...")" - local ret=0 - if [ "$ASROOT" -eq 0 ]; then - sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? - else - pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? - fi - - if [ $ret -ne 0 ]; then - error "$(gettext "Pacman failed to install missing dependencies.")" + if ! run_pacman -S --asdeps $deplist; then + error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN" exit 1 # TODO: error code fi fi @@ -400,16 +404,16 @@ resolve_deps() { local R_DEPS_MISSING=1 local deplist="$(check_deps $*)" - if [ -z "$deplist" ]; then + if [[ -z $deplist ]]; then return $R_DEPS_SATISFIED fi - if handledeps $deplist; then + if handle_deps $deplist; then pkgdeps="$pkgdeps $deplist" # check deps again to make sure they were resolved deplist="$(check_deps $*)" - [ -z "$deplist" ] && return $R_DEPS_SATISFIED - elif [ "$DEP_BIN" -eq 1 ]; then + [[ -z $deplist ]] && return $R_DEPS_SATISFIED + elif (( DEP_BIN )); then error "$(gettext "Failed to install all missing dependencies.")" fi @@ -425,26 +429,20 @@ resolve_deps() { # fix flyspray bug #5923 remove_deps() { # $pkgdeps is a GLOBAL variable, set by resolve_deps() - [ "$RMDEPS" -eq 0 ] && return - [ -z "$pkgdeps" ] && return + (( ! RMDEPS )) && return + [[ -z $pkgdeps ]] && return local dep depstrip deplist deplist="" for dep in $pkgdeps; do - depstrip=$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||') + depstrip="${dep%%[<=>]*}" deplist="$deplist $depstrip" done msg "Removing installed dependencies..." - local ret=0 - if [ "$ASROOT" -eq 0 ]; then - sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$? - else - pacman $PACMAN_OPTS -Rns $deplist || ret=$? - fi - # Fixes FS#10039 - exit cleanly as package has built successfully - if [ $ret -ne 0 ]; then + # exit cleanly on failure to remove deps as package has been built successfully + if ! run_pacman -Rns $deplist; then warning "$(gettext "Failed to remove installed dependencies.")" return 0 fi @@ -453,7 +451,7 @@ remove_deps() { download_sources() { msg "$(gettext "Retrieving Sources...")" - if [ ! -w "$SRCDEST" ] ; then + if [[ ! -w $SRCDEST ]] ; then error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST" plain "$(gettext "Aborting...")" exit 1 @@ -465,12 +463,12 @@ download_sources() { for netfile in "${source[@]}"; do local file=$(get_filename "$netfile") local url=$(get_url "$netfile") - if [ -f "$startdir/$file" ]; then + if [[ -f $startdir/$file ]]; then msg2 "$(gettext "Found %s in build dir")" "$file" rm -f "$srcdir/$file" ln -s "$startdir/$file" "$srcdir/" continue - elif [ -f "$SRCDEST/$file" ]; then + elif [[ -f $SRCDEST/$file ]]; then msg2 "$(gettext "Using cached copy of %s")" "$file" rm -f "$srcdir/$file" ln -s "$SRCDEST/$file" "$srcdir/" @@ -478,7 +476,7 @@ download_sources() { fi # if we get here, check to make sure it was a URL, else fail - if [ "$file" = "$url" ]; then + if [[ $file = $url ]]; then error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file" exit 1 # $E_MISSING_FILE fi @@ -490,7 +488,7 @@ download_sources() { # fix flyspray bug #3289 local ret=0 download_file "$dlclient" "$url" "$file" || ret=$? - if [ $ret -gt 0 ]; then + if (( ret )); then error "$(gettext "Failure while downloading %s")" "$file" plain "$(gettext "Aborting...")" exit 1 @@ -513,7 +511,7 @@ generate_checksums() { local integ for integ in ${INTEGRITY_CHECK[@]}; do - integ="$(echo $integ | tr '[:upper:]' '[:lower:]')" + integ="${integ,,}" case "$integ" in md5|sha1|sha256|sha384|sha512) : ;; *) @@ -525,19 +523,18 @@ generate_checksums() { local numsrc=${#source[@]} echo -n "${integ}sums=(" - local i=0; + local i local indent='' - while [ $i -lt $((${#integ}+6)) ]; do + for (( i = 0; i < ${#integ} + 6; i++ )); do indent="$indent " - i=$(($i+1)) done local netfile for netfile in "${source[@]}"; do local file="$(get_filename "$netfile")" - if [ ! -f "$file" ] ; then - if [ ! -f "$SRCDEST/$file" ] ; then + if [[ ! -f $file ]] ; then + if [[ ! -f $SRCDEST/$file ]] ; then error "$(gettext "Unable to find source file %s to generate checksum.")" "$file" plain "$(gettext "Aborting...")" exit 1 @@ -546,11 +543,12 @@ generate_checksums() { fi fi - local sum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')" - [ $ct -gt 0 ] && echo -n "$indent" + local sum="$(openssl dgst -${integ} "$file")" + sum=${sum##* } + (( ct )) && echo -n "$indent" echo -n "'$sum'" ct=$(($ct+1)) - [ $ct -lt $numsrc ] && echo + (( $ct < $numsrc )) && echo done echo ")" @@ -558,7 +556,7 @@ generate_checksums() { } check_checksums() { - [ ${#source[@]} -eq 0 ] && return 0 + (( ! ${#source[@]} )) && return 0 if [ ! $(type -p openssl) ]; then error "$(gettext "Cannot find openssl.")" @@ -569,7 +567,7 @@ check_checksums() { local integ required for integ in md5 sha1 sha256 sha384 sha512; do local integrity_sums=($(eval echo "\${${integ}sums[@]}")) - if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then + if (( ${#integrity_sums[@]} == ${#source[@]} )); then msg "$(gettext "Validating source files with %s...")" "${integ}sums" correlation=1 local errors=0 @@ -580,8 +578,8 @@ check_checksums() { file="$(get_filename "$file")" echo -n " $file ... " >&2 - if [ ! -f "$file" ] ; then - if [ ! -f "$SRCDEST/$file" ] ; then + if [[ ! -f $file ]] ; then + if [[ ! -f $SRCDEST/$file ]] ; then echo "$(gettext "NOT FOUND")" >&2 errors=1 found=0 @@ -590,10 +588,11 @@ check_checksums() { fi fi - if [ $found -gt 0 ] ; then - local expectedsum="$(echo ${integrity_sums[$idx]} | tr '[A-F]' '[a-f]')" - local realsum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')" - if [ "$expectedsum" = "$realsum" ]; then + if (( $found )) ; then + local expectedsum="${integrity_sums[$idx],,}" + local realsum="$(openssl dgst -${integ} "$file")" + realsum="${realsum##* }" + if [[ $expectedsum = $realsum ]]; then echo "$(gettext "Passed")" >&2 else echo "$(gettext "FAILED")" >&2 @@ -604,18 +603,18 @@ check_checksums() { idx=$((idx + 1)) done - if [ $errors -gt 0 ]; then + if (( errors )); then error "$(gettext "One or more files did not pass the validity check!")" exit 1 # TODO: error code fi - elif [ ${#integrity_sums[@]} -gt 0 ]; then + elif (( ${#integrity_sums[@]} )); then error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" exit 1 # TODO: error code fi done - if [ $correlation -eq 0 ]; then - if [ $SKIPINTEG -eq 1 ]; then + if (( ! correlation )); then + if (( SKIPINTEG )); then warning "$(gettext "Integrity checks are missing.")" else error "$(gettext "Integrity checks are missing.")" @@ -635,8 +634,8 @@ extract_sources() { continue fi - if [ ! -f "$file" ] ; then - if [ ! -f "$SRCDEST/$file" ] ; then + if [[ ! -f $file ]] ; then + if [[ ! -f $SRCDEST/$file ]] ; then error "$(gettext "Unable to find source file %s for extraction.")" "$file" plain "$(gettext "Aborting...")" exit 1 @@ -675,94 +674,45 @@ extract_sources() { local ret=0 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd" - if [ "$cmd" = "bsdtar" ]; then + if [[ $cmd = bsdtar ]]; then $cmd -xf "$file" || ret=? else rm -f "${file%.*}" $cmd -dcf "$file" > "${file%.*}" || ret=? fi - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Failed to extract %s")" "$file" plain "$(gettext "Aborting...")" exit 1 fi done - if [ $EUID -eq 0 ]; then + if (( EUID == 0 )); then # change perms of all source files to root user & root group chown -R 0:0 "$srcdir" fi } -run_build() { - # use distcc if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then - [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH" - export DISTCC_HOSTS - elif [ "$(check_option distcc)" = "n" ]; then - # if it is not wanted, clear the makeflags too - MAKEFLAGS="" - fi - - # use ccache if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then - [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH" - fi - - # clear user-specified makeflags if requested - if [ "$(check_option makeflags)" = "n" ]; then - MAKEFLAGS="" - fi - - msg "$(gettext "Starting build()...")" - cd "$srcdir" - - # ensure all necessary build variables are exported - export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST - # save our shell options so build() can't override what we need - local shellopts=$(shopt -p) - - local ret=0 - if [ "$LOGGING" -eq 1 ]; then - BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log" - if [ -f "$BUILDLOG" ]; then - local i=1 - while true; do - if [ -f "$BUILDLOG.$i" ]; then - i=$(($i +1)) - else - break - fi - done - mv "$BUILDLOG" "$BUILDLOG.$i" - fi - - build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} - else - build 2>&1 || ret=$? +error_function() { + if [[ -p $logpipe ]]; then + rm "$logpipe" fi - # reset our shell options - eval "$shellopts" - - if [ $ret -gt 0 ]; then - error "$(gettext "Build Failed.")" + # first exit all subshells, then print the error + if (( ! BASH_SUBSHELL )); then plain "$(gettext "Aborting...")" remove_deps - exit 2 # $E_BUILD_FAILED fi + exit 2 # $E_BUILD_FAILED } -run_package() { - if [ -z "$1" ]; then - pkgfunc="package" - nameofpkg="$pkgname" - else - pkgfunc="package_$1" - nameofpkg="$1" +run_function() { + if [[ -z $1 ]]; then + return 1 fi + pkgfunc="$1" # clear user-specified makeflags if requested - if [ "$(check_option makeflags)" = "n" ]; then + if [[ $(check_option makeflags) = "n" ]]; then MAKEFLAGS="" fi @@ -771,14 +721,16 @@ run_package() { # ensure all necessary build variables are exported export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST + # save our shell options so pkgfunc() can't override what we need + local shellopts=$(shopt -p) local ret=0 - if [ "$LOGGING" -eq 1 ]; then - BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log" - if [ -f "$BUILDLOG" ]; then + if (( LOGGING )); then + BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log" + if [[ -f $BUILDLOG ]]; then local i=1 while true; do - if [ -f "$BUILDLOG.$i" ]; then + if [[ -f $BUILDLOG.$i ]]; then i=$(($i +1)) else break @@ -793,36 +745,65 @@ run_package() { exec 3>&1 tee "$BUILDLOG" < "$logpipe" & exec 1>"$logpipe" 2>"$logpipe" - $pkgfunc 2>&1 || ret=$? + restoretrap=$(trap -p ERR) + trap 'error_function' ERR + $pkgfunc 2>&1 + eval $restoretrap sync exec 1>&3 2>&3 3>&- rm "$logpipe" else - $pkgfunc 2>&1 || ret=$? + restoretrap=$(trap -p ERR) + trap 'error_function' ERR + $pkgfunc 2>&1 + eval $restoretrap fi + # reset our shell options + eval "$shellopts" +} - if [ $ret -gt 0 ]; then - error "$(gettext "Packaging Failed.")" - plain "$(gettext "Aborting...")" - remove_deps - exit 2 # $E_BUILD_FAILED +run_build() { + # use distcc if it is requested (check buildenv and PKGBUILD opts) + if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then + [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" + export DISTCC_HOSTS + elif [[ $(check_option distcc) = "n" ]]; then + # if it is not wanted, clear the makeflags too + MAKEFLAGS="" + fi + + # use ccache if it is requested (check buildenv and PKGBUILD opts) + if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then + [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" + fi + + run_function "build" +} + +run_package() { + if [[ -z $1 ]]; then + pkgfunc="package" + else + pkgfunc="package_$1" fi + + run_function "$pkgfunc" } tidy_install() { cd "$pkgdir" msg "$(gettext "Tidying install...")" - if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then + if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then msg2 "$(gettext "Removing doc files...")" rm -rf ${DOC_DIRS[@]} fi - if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then + if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then msg2 "$(gettext "Purging other files...")" local pt for pt in "${PURGE_TARGETS[@]}"; do - if [ "${pt}" = "${pt//\/}" ]; then + if [[ ${pt} = ${pt//\/} ]]; then find . -type f -name "${pt}" -exec rm -f -- '{}' \; else rm -f ${pt} @@ -830,16 +811,16 @@ tidy_install() { done fi - if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then + if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then msg2 "$(gettext "Compressing man and info pages...")" local manpage ext file link hardlinks hl find ${MAN_DIRS[@]} -type f 2>/dev/null | while read manpage ; do # check file still exists (potentially compressed with hard link) - if [ -f ${manpage} ]; then + if [[ -f ${manpage} ]]; then ext="${manpage##*.}" file="${manpage##*/}" - if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then + if [[ $ext != gz && $ext != bz2 ]]; then # update symlinks to this manpage find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null | while read link ; do @@ -865,7 +846,7 @@ tidy_install() { done fi - if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then + if [[ $(check_option strip) = y && -n ${STRIP_DIRS[*]} ]]; then msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" local binary find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do @@ -882,12 +863,12 @@ tidy_install() { done fi - if [ "$(check_option libtool)" = "n" ]; then + if [[ $(check_option libtool) = "n" ]]; then msg2 "$(gettext "Removing libtool .la files...")" find . ! -type d -name "*.la" -exec rm -f -- '{}' \; fi - if [ "$(check_option emptydirs)" = "n" ]; then + if [[ $(check_option emptydirs) = "n" ]]; then msg2 "$(gettext "Removing empty directories...")" find . -depth -type d -empty -delete fi @@ -895,31 +876,30 @@ tidy_install() { write_pkginfo() { local builddate=$(date -u "+%s") - if [ -n "$PACKAGER" ]; then + if [[ -n $PACKAGER ]]; then local packager="$PACKAGER" else local packager="Unknown Packager" fi - local size=$(du -sk | awk '{print $1 * 1024}') + local size="$(du -sk)" + size="$(( ${size%%[^0-9]*} * 1024 ))" msg2 "$(gettext "Generating .PKGINFO file...")" echo "# Generated by makepkg $myver" >.PKGINFO - if [ "$INFAKEROOT" -eq 1 ]; then + if (( INFAKEROOT )); then echo "# using $(fakeroot -v)" >>.PKGINFO fi echo "# $(LC_ALL=C date -u)" >>.PKGINFO echo "pkgname = $1" >>.PKGINFO - [ "$SPLITPKG" -eq 1 ] && echo "pkgbase = $pkgbase" >>.PKGINFO + (( SPLITPKG )) && echo pkgbase = $pkgbase >>.PKGINFO echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO echo "pkgdesc = $pkgdesc" >>.PKGINFO echo "url = $url" >>.PKGINFO echo "builddate = $builddate" >>.PKGINFO echo "packager = $packager" >>.PKGINFO echo "size = $size" >>.PKGINFO - if [ -n "$CARCH" ]; then - echo "arch = $CARCH" >>.PKGINFO - fi - if [ "$(check_option force)" = "y" ]; then + echo "arch = $PKGARCH" >>.PKGINFO + if [[ $(check_option force) = "y" ]]; then echo "force = true" >> .PKGINFO fi @@ -950,8 +930,8 @@ write_pkginfo() { done for it in "${packaging_options[@]}"; do local ret="$(check_option $it)" - if [ "$ret" != "?" ]; then - if [ "$ret" = "y" ]; then + if [[ $ret != "?" ]]; then + if [[ $ret = y ]]; then echo "makepkgopt = $it" >>.PKGINFO else echo "makepkgopt = !$it" >>.PKGINFO @@ -961,43 +941,68 @@ write_pkginfo() { # TODO maybe remove this at some point # warn if license array is not present or empty - if [ -z "$license" ]; then + if [[ -z $license ]]; then warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" plain "$(gettext "Example for GPL\'ed software: license=('GPL').")" fi } +check_package() { + cd "$pkgdir" + + # check existence of backup files + local file + for file in "${backup[@]}"; do + if [[ ! -f $file ]]; then + warning "$(gettext "Invalid backup entry : %s")" "$file" + fi + done + + # check for references to the build directory + if grep -R "${srcdir}" "${pkgdir}" &>/dev/null; then + warning "$(gettext "Package contains reference to %s")" "\$srcdir" + fi +} + create_package() { - if [ ! -d "$pkgdir" ]; then + if [[ ! -d $pkgdir ]]; then error "$(gettext "Missing pkg/ directory.")" plain "$(gettext "Aborting...")" exit 1 # $E_MISSING_PKGDIR fi + check_package + cd "$pkgdir" msg "$(gettext "Creating package...")" - if [ -z "$1" ]; then + if [[ -z $1 ]]; then nameofpkg="$pkgname" else nameofpkg="$1" fi + if [[ $arch = "any" ]]; then + PKGARCH="any" + else + PKGARCH=$CARCH + fi + write_pkginfo $nameofpkg local comp_files=".PKGINFO" # check for an install script - if [ -n "$install" ]; then + if [[ -n $install ]]; then msg2 "$(gettext "Adding install script...")" cp "$startdir/$install" .INSTALL comp_files="$comp_files .INSTALL" fi # do we have a changelog? - if [ -f "$startdir/ChangeLog" ]; then + if [[ -n $changelog ]]; then msg2 "$(gettext "Adding package changelog...")" - cp "$startdir/ChangeLog" .CHANGELOG + cp "$startdir/$changelog" .CHANGELOG comp_files="$comp_files .CHANGELOG" fi @@ -1011,29 +1016,39 @@ create_package() { *) warning "$(gettext "'%s' is not a valid archive extension.")" \ "$PKGEXT" ; EXT=$PKGEXT ;; esac - local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${EXT}" + local tar_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${PKGARCH}${EXT}" + local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${PKGARCH}${PKGEXT}" local ret=0 # when fileglobbing, we want * in an empty directory to expand to # the null string rather than itself shopt -s nullglob - bsdtar -cf - $comp_files * > "$pkg_file" || ret=$? + bsdtar -cf - $comp_files * > "$tar_file" || ret=$? shopt -u nullglob - if [ $ret -eq 0 ]; then + if (( ! ret )); then case "$PKGEXT" in - *tar.gz) gzip -f -n "$pkg_file" ;; - *tar.bz2) bzip2 -f "$pkg_file" ;; - *tar.xz) xz -z -f "$pkg_file" ;; + *tar.gz) gzip -f -n "$tar_file" ;; + *tar.bz2) bzip2 -f "$tar_file" ;; + *tar.xz) xz -z -f "$tar_file" ;; esac ret=$? fi - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Failed to create package file.")" exit 1 # TODO: error code fi + + if (( ! ret )) && [[ "$PKGDEST" != "${startdir}" ]]; then + ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}" + ret=$? + fi + + if (( ret )); then + warning "$(gettext "Failed to create symlink to package file.")" + fi } create_srcpackage() { @@ -1054,27 +1069,31 @@ create_srcpackage() { msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}" - if [ -n "$install" ]; then - if [ -f $install ]; then + if [[ -n $install ]]; then + if [[ -f $install ]]; then msg2 "$(gettext "Adding install script...")" ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/" else - error "$(gettext "Install script %s not found.")" "$install" + error "$(gettext "Install scriptlet (%s) does not exist.")" "$install" fi fi - if [ -f ChangeLog ]; then - msg2 "$(gettext "Adding %s...")" "ChangeLog" - ln -s "${startdir}/ChangeLog" "${srclinks}/${pkgbase}" + if [[ -n $changelog ]]; then + if [[ -f $changelog ]]; then + msg2 "$(gettext "Adding package changelog...")" + ln -s "${startdir}/$changelog" "${srclinks}/${pkgbase}/" + else + error "$(gettext "Changelog file (%s) does not exist.")" "$changelog" + fi fi local netfile for netfile in "${source[@]}"; do local file=$(get_filename "$netfile") - if [ -f "$netfile" ]; then + if [[ -f $netfile ]]; then msg2 "$(gettext "Adding %s...")" "$netfile" ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}" - elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then + elif (( SOURCEONLY == 2 )) && [[ -f $SRCDEST/$file ]]; then msg2 "$(gettext "Adding %s...")" "$file" ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/" fi @@ -1089,7 +1108,7 @@ create_srcpackage() { "$SRCEXT" ;; esac - local pkg_file="$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" + local pkg_file="$SRCPKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" # tar it up msg2 "$(gettext "Compressing source package...")" @@ -1103,27 +1122,24 @@ create_srcpackage() { } install_package() { - [ "$INSTALL" -eq 0 ] && return + (( ! INSTALL )) && return - if [ "$SPLITPKG" -eq 0 ]; then - msg "$(gettext "Installing package ${pkgname} with pacman -U...")" + if (( ! SPLITPKG )); then + msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN" else - msg "$(gettext "Installing ${pkgbase} package group with pacman -U...")" + msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN" fi local pkglist for pkg in ${pkgname[@]}; do - pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]]; then + pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + else + pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT}" + fi done - local ret=0 - if [ "$ASROOT" -eq 0 ]; then - sudo pacman $PACMAN_OPTS -U ${pkglist} || ret=$? - else - pacman $PACMAN_OPTS -U ${pkglist} || ret=$? - fi - - if [ $ret -ne 0 ]; then + if ! run_pacman -U $pkglist; then warning "$(gettext "Failed to install built package(s).")" return 0 fi @@ -1131,76 +1147,105 @@ install_package() { check_sanity() { # check for no-no's in the build script - if [ -z "$pkgname" ]; then + if [[ -z $pkgname ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgname" return 1 fi - if [ -z "$pkgver" ]; then + if [[ -z $pkgver ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgver" return 1 fi - if [ -z "$pkgrel" ]; then + if [[ -z $pkgrel ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgrel" return 1 fi - if [ "${pkgname:0:1}" == "-" ]; then - error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" + + local name + for name in "${pkgname[@]}"; do + if [[ ${name:0:1} = "-" ]]; then + error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" + return 1 + fi + done + + if [[ ${pkgbase:0:1} = "-" ]]; then + error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase" return 1 fi - if [ "$pkgver" != "${pkgver//-/}" ]; then + if [[ $pkgver != ${pkgver//-/} ]]; then error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver" return 1 fi - if [ "$pkgrel" != "${pkgrel//-/}" ]; then + if [[ $pkgrel != ${pkgrel//-/} ]]; then error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel" return 1 fi - if [ "$arch" = 'any' ]; then - CARCH='any' - fi - if ! in_array $CARCH ${arch[@]}; then - if [ "$IGNOREARCH" -eq 0 ]; then - error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH" - plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" - plain "$(gettext "such as arch=('%s').")" "$CARCH" - return 1 + if [[ $arch != 'any' ]]; then + if ! in_array $CARCH ${arch[@]}; then + if (( ! IGNOREARCH )); then + error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH" + plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" + plain "$(gettext "such as arch=('%s').")" "$CARCH" + return 1 + fi fi fi local provide for provide in ${provides[@]}; do - if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then + if [[ $provide != ${provide//</} || $provide != ${provide//>/} ]]; then error "$(gettext "Provides array cannot contain comparison (< or >) operators.")" return 1 fi done - if [ "$install" -a ! -f "$install" ]; then + local file + for file in "${backup[@]}"; do + if [[ ${file:0:1} = "/" ]]; then + error "$(gettext "Invalid backup entry : %s")" "$file" + return 1 + fi + done + + local optdepend + for optdepend in "${optdepends[@]}"; do + pkg=${optdepend%%:*} + if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then + error "$(gettext "Invalid syntax for optdepend : '%s'")" "$optdepend" + fi + done + + if [[ $install && ! -f $install ]]; then error "$(gettext "Install scriptlet (%s) does not exist.")" "$install" return 1 fi + if [[ -n $changelog && ! -f $changelog ]]; then + error "$(gettext "Changelog file (%s) does not exist.")" "$changelog" + return 1 + fi + local valid_options=1 local opt known kopt for opt in ${options[@]}; do known=0 # check if option matches a known option or its inverse for kopt in ${packaging_options[@]} ${other_options[@]}; do - if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then + if [[ ${opt} = ${kopt} || ${opt} = "!${kopt}" ]]; then known=1 fi done - if [ $known -eq 0 ]; then + if (( ! known )); then error "$(gettext "options array contains unknown option '%s'")" "$opt" valid_options=0 fi done - if [ $valid_options -eq 0 ]; then + if (( ! valid_options )); then return 1 fi - if [ "${#pkgname[@]}" -gt "1" ]; then + if (( ${#pkgname[@]} > 1 )); then for pkg in ${pkgname[@]}; do if [ "$(type -t package_${pkg})" != "function" ]; then error "$(gettext "missing package function for split package '%s'")" "$pkg" @@ -1209,50 +1254,59 @@ check_sanity() { done fi + if [[ -n "${PKGLIST[@]}" ]]; then + for pkg in ${PKGLIST[@]}; do + if ! in_array $pkg ${pkgname[@]}; then + error "$(gettext "requested package %s is not provided in %s")" "$pkg" "$BUILDSCRIPT" + return 1 + fi + done + fi + return 0 } devel_check() { newpkgver="" - # Do not update pkgver if --holdver is set, when building a source package, - # when reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w) - if [ "$HOLDVER" -eq 1 -o "$SOURCEONLY" -ne 0 -o ! -f "$BUILDFILE" \ - -o ! -w "$BUILDFILE" ]; then + # Do not update pkgver if --holdver is set, when building a source package, repackaging, + # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w) + if (( HOLDVER || SOURCEONLY || REPKG )) \ + || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then return fi - if [ -z "$FORCE_VER" ]; then + if [[ -z $FORCE_VER ]]; then # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so. # This will only be used on the first call to makepkg; subsequent # calls to makepkg via fakeroot will explicitly pass the version # number to avoid having to determine the version number twice. # Also do a brief check to make sure we have the VCS tool available. oldpkgver=$pkgver - if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then + if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then [ $(type -p darcs) ] || return 0 msg "$(gettext "Determining latest darcs revision...")" newpkgver=$(date +%Y%m%d) - elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then + elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then [ $(type -p cvs) ] || return 0 msg "$(gettext "Determining latest cvs revision...")" newpkgver=$(date +%Y%m%d) - elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then + elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then [ $(type -p git) ] || return 0 msg "$(gettext "Determining latest git revision...")" newpkgver=$(date +%Y%m%d) - elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then + elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then [ $(type -p svn) ] || return 0 msg "$(gettext "Determining latest svn revision...")" newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p') - elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then + elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then [ $(type -p bzr) ] || return 0 msg "$(gettext "Determining latest bzr revision...")" newpkgver=$(bzr revno ${_bzrtrunk}) - elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then + elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then [ $(type -p hg) ] || return 0 msg "$(gettext "Determining latest hg revision...")" - if [ -d ./src/$_hgrepo ] ; then + if [[ -d ./src/$_hgrepo ]] ; then cd ./src/$_hgrepo hg pull hg update @@ -1265,7 +1319,7 @@ devel_check() { cd ../../ fi - if [ -n "$newpkgver" ]; then + if [[ -n $newpkgver ]]; then msg2 "$(gettext "Version found: %s")" "$newpkgver" fi @@ -1285,9 +1339,9 @@ devel_update() { # ... # _foo=pkgver # - if [ -n "$newpkgver" ]; then - if [ "$newpkgver" != "$pkgver" ]; then - if [ -f "$BUILDFILE" -a -w "$BUILDFILE" ]; then + if [[ -n $newpkgver ]]; then + if [[ $newpkgver != $pkgver ]]; then + if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE" @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE" source "$BUILDFILE" @@ -1306,7 +1360,7 @@ backup_package_variables() { restore_package_variables() { for var in ${splitpkg_overrides[@]}; do indirect="${var}_backup" - if [ -n "${!indirect}" ]; then + if [[ -n ${!indirect} ]]; then eval "${var}=(\"\${$indirect[@]}\")" else unset ${var} @@ -1321,21 +1375,21 @@ parse_options() { local ret=0; local unused_options="" - while [ -n "$1" ]; do - if [ ${1:0:2} = '--' ]; then - if [ -n "${1:2}" ]; then + while [[ -n $1 ]]; do + if [[ ${1:0:2} = '--' ]]; then + if [[ -n ${1:2} ]]; then local match="" for i in ${long_options//,/ }; do - if [ ${1:2} = ${i//:} ]; then + if [[ ${1:2} = ${i//:} ]]; then match=$i break fi done - if [ -n "$match" ]; then - if [ ${1:2} = $match ]; then + if [[ -n $match ]]; then + if [[ ${1:2} = $match ]]; then printf ' %s' "$1" else - if [ -n "$2" ]; then + if [[ -n $2 ]]; then printf ' %s' "$1" shift printf " '%s'" "$1" @@ -1352,15 +1406,15 @@ parse_options() { shift break fi - elif [ ${1:0:1} = '-' ]; then + elif [[ ${1:0:1} = '-' ]]; then for ((i=1; i<${#1}; i++)); do - if [[ "$short_options" =~ "${1:i:1}" ]]; then - if [[ "$short_options" =~ "${1:i:1}:" ]]; then - if [ -n "${1:$i+1}" ]; then + if [[ $short_options =~ ${1:i:1} ]]; then + if [[ $short_options =~ "${1:i:1}:" ]]; then + if [[ -n ${1:$i+1} ]]; then printf ' -%s' "${1:i:1}" printf " '%s'" "${1:$i+1}" else - if [ -n "$2" ]; then + if [[ -n $2 ]]; then printf ' -%s' "${1:i:1}" shift printf " '%s'" "${1}" @@ -1385,13 +1439,13 @@ parse_options() { done printf " --" - if [ -n "$unused_options" ]; then + if [[ -n $unused_options ]]; then for i in ${unused_options[@]}; do printf ' %s' "$i" done fi - if [ -n "$1" ]; then - while [ -n "$1" ]; do + if [[ -n $1 ]]; then + while [[ -n $1 ]]; do printf " '%s'" "${1}" shift done @@ -1410,31 +1464,31 @@ usage() { printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" echo "$(gettext " -c, --clean Clean up work files after build")" echo "$(gettext " -C, --cleancache Clean up source files from the cache")" - printf "$(gettext " --config <config> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" echo "$(gettext " -d, --nodeps Skip all dependency checks")" echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" echo "$(gettext " -f, --force Overwrite existing package")" echo "$(gettext " -g, --geninteg Generate integrity checks for source files")" - echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")" echo "$(gettext " -h, --help This help")" echo "$(gettext " -i, --install Install package after successful build")" echo "$(gettext " -L, --log Log package build process")" echo "$(gettext " -m, --nocolor Disable colorized output messages")" echo "$(gettext " -o, --nobuild Download and extract files only")" - printf "$(gettext " -p <buildscript> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" + printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" - # fix flyspray feature request #2978 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")" echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" - echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")" - echo "$(gettext " --asroot Allow makepkg to run as root user")" - echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")" - echo "$(gettext " --source Generate a source-only tarball without downloaded sources")" + echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")" + echo "$(gettext " --asroot Allow makepkg to run as root user")" + printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" + echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")" + echo "$(gettext " --pkg <list> Only build listed packages from a split package")" + echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")" + echo "$(gettext " --source Generate a source-only tarball without downloaded sources")" echo echo "$(gettext "These options can be passed to pacman:")" echo - echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" - echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" + echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" + echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" echo printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT" echo @@ -1464,7 +1518,7 @@ ARGLIST=("$@") OPT_SHORT="AcCdefFghiLmop:rRsV" OPT_LONG="allsource,asroot,ignorearch,clean,cleancache,nodeps" OPT_LONG="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver" -OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,skipinteg" +OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,pkg:,rmdeps,repackage,skipinteg" OPT_LONG="$OPT_LONG,source,syncdeps,version,config:" # Pacman Options OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" @@ -1502,6 +1556,7 @@ while true; do -m|--nocolor) USE_COLOR='n' ;; -o|--nobuild) NOBUILD=1 ;; -p) shift; BUILDFILE=$1 ;; + --pkg) shift; PKGLIST=$1 ;; -r|--rmdeps) RMDEPS=1 ;; -R|--repackage) REPKG=1 ;; --skipinteg) SKIPINTEG=1 ;; @@ -1520,12 +1575,13 @@ done #preserve environment variables _PKGDEST=${PKGDEST} _SRCDEST=${SRCDEST} +_SRCPKGDEST=${SRCPKGDEST} # default config is makepkg.conf MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf} # Source the config file; fail if it is not found -if [ -r "$MAKEPKG_CONF" ]; then +if [[ -r $MAKEPKG_CONF ]]; then source "$MAKEPKG_CONF" else error "$(gettext "%s not found.")" "$MAKEPKG_CONF" @@ -1534,39 +1590,51 @@ else fi # Source user-specific makepkg.conf overrides -if [ -r ~/.makepkg.conf ]; then +if [[ -r ~/.makepkg.conf ]]; then source ~/.makepkg.conf fi +# set pacman command if not already defined +PACMAN=${PACMAN:-pacman} + # check if messages are to be printed using color -if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - COLORMSG=1 +unset ALL_OFF BOLD BLUE GREEN RED YELLOW +if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then + ALL_OFF="$(tput sgr0)" + BOLD="$(tput bold)" + BLUE="${BOLD}$(tput setaf 4)" + GREEN="${BOLD}$(tput setaf 2)" + RED="${BOLD}$(tput setaf 1)" + YELLOW="${BOLD}$(tput setaf 3)" fi +readonly ALL_OFF BOLD BLUE GREEN RED YELLOW # override settings with an environment variable for batch processing PKGDEST=${_PKGDEST:-$PKGDEST} PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined SRCDEST=${_SRCDEST:-$SRCDEST} SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined +SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST} +SRCPKGDEST=${SRCPKGDEST:-$PKGDEST} #default to $PKGDEST if undefined -if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then +if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then # The '\\0' is here to prevent gettext from thinking --holdver is an option error "$(gettext "\\0--holdver and --forcever cannot both be specified" )" exit 1 fi -if [ "$CLEANCACHE" -eq 1 ]; then +if (( CLEANCACHE )); then #fix flyspray feature request #5223 - if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then + if [[ -n $SRCDEST && $SRCDEST != $startdir ]]; then msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST" echo -n "$(gettext " Are you sure you wish to do this? ")" echo -n "$(gettext "[y/N]")" read answer - answer=$(echo $answer | tr '[:lower:]' '[:upper:]') - if [ "$answer" = "$(gettext "YES")" -o "$answer" = "$(gettext "Y")" ]; then + answer="${answer^^}" + if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then rm "$SRCDEST"/* - if [ $? -ne 0 ]; then + if (( $? )); then error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST" exit 1 else @@ -1587,40 +1655,39 @@ if [ "$CLEANCACHE" -eq 1 ]; then fi fi -if [ "$INFAKEROOT" -eq 0 ]; then - if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then +if (( ! INFAKEROOT )); then + if (( EUID == 0 && ! ASROOT )); then # Warn those who like to live dangerously. error "$(gettext "Running makepkg as root is a BAD idea and can cause")" plain "$(gettext "permanent, catastrophic damage to your system. If you")" plain "$(gettext "wish to run as root, please use the --asroot option.")" exit 1 # $E_USER_ABORT - elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then + elif (( EUID > 0 && ASROOT )); then # Warn those who try to use the --asroot option when they are not root error "$(gettext "The --asroot option is meant for the root user only.")" plain "$(gettext "Please rerun makepkg without the --asroot flag.")" exit 1 # $E_USER_ABORT - elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then + elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then if [ ! $(type -p fakeroot) ]; then error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")" plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF" exit 1 fi - elif [ $EUID -gt 0 ]; then + elif (( EUID > 0 )); then warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")" plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")" plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF" sleep 1 fi else - if [ -z "$FAKEROOTKEY" ]; then + if [[ -z $FAKEROOTKEY ]]; then error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" exit 1 # TODO: error code fi fi # check for sudo if we will need it during makepkg execution -if [ "$ASROOT" -eq 0 \ - -a \( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \) ]; then +if (( ! ASROOT && ( DEP_BIN || RMDEPS || INSTALL ) )); then if [ ! "$(type -p sudo)" ]; then error "$(gettext "Cannot find the sudo binary! Is sudo installed?")" plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")" @@ -1630,12 +1697,12 @@ if [ "$ASROOT" -eq 0 \ fi unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides -unset md5sums replaces depends conflicts backup source install build +unset md5sums replaces depends conflicts backup source install changelog build unset makedepends optdepends options noextract BUILDFILE=${BUILDFILE:-$BUILDSCRIPT} -if [ ! -f "$BUILDFILE" ]; then - if [ -t 0 ]; then +if [[ ! -f $BUILDFILE ]]; then + if [[ -t 0 ]]; then error "$(gettext "%s does not exist.")" "$BUILDFILE" exit 1 else @@ -1645,18 +1712,18 @@ if [ ! -f "$BUILDFILE" ]; then fi else crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true) - if [ -n "$crlftest" ]; then + if [[ -n $crlftest ]]; then error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE" exit 1 fi - if [ "${BUILDFILE:0:1}" != "/" ]; then + if [[ ${BUILDFILE:0:1} != "/" ]]; then BUILDFILE="$startdir/$BUILDFILE" fi source "$BUILDFILE" fi -if [ "$GENINTEG" -eq 1 ]; then +if (( GENINTEG )); then mkdir -p "$srcdir" cd "$srcdir" download_sources @@ -1664,10 +1731,6 @@ if [ "$GENINTEG" -eq 1 ]; then exit 0 # $E_OK fi -if [ "$(type -t package)" = "function" ]; then - PKGFUNC=1 -fi - # check the PKGBUILD for some basic requirements check_sanity || exit 1 @@ -1678,16 +1741,34 @@ check_sanity || exit 1 devel_check devel_update -if [ "${#pkgname[@]}" -gt "1" ]; then +if (( ${#pkgname[@]} > 1 )); then + SPLITPKG=1 +fi + +# test for available PKGBUILD functions +# The exclamation mark is required here to avoid triggering the ERR trap when +# a tested function does not exist. +if [[ $(! type -t build) = "function" ]]; then + BUILDFUNC=1 +fi +if [ "$(type -t package)" = "function" ]; then + PKGFUNC=1 +elif [ $SPLITPKG -eq 0 -a "$(type -t package_${pkgname})" = "function" ]; then SPLITPKG=1 fi pkgbase=${pkgbase:-${pkgname[0]}} -if [ "$SPLITPKG" -eq 0 ]; then - if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ - -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then - if [ "$INSTALL" -eq 1 ]; then +if [[ -n "${PKGLIST[@]}" ]]; then + unset pkgname + pkgname="${PKGLIST[@]}" +fi + +if (( ! SPLITPKG )); then + if [[ -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \ + || -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-any${PKGEXT} ]] \ + && ! (( FORCE || SOURCEONLY || NOBUILD )); then + if (( INSTALL )); then warning "$(gettext "A package has already been built, installing existing package...")" install_package exit $? @@ -1700,15 +1781,16 @@ else allpkgbuilt=1 somepkgbuilt=0 for pkg in ${pkgname[@]}; do - if [ -f "$PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" ]; then + if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \ + || -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT} ]]; then somepkgbuilt=1 else allpkgbuilt=0 fi done - if [ "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then - if [ "$allpkgbuilt" -eq 1 ]; then - if [ "$INSTALL" -eq 1 ]; then + if ! (( FORCE || SOURCEONLY || NOBUILD )); then + if (( allpkgbuilt )); then + if (( INSTALL )); then warning "$(gettext "The package group has already been built, installing existing packages...")" install_package exit $? @@ -1717,7 +1799,7 @@ else exit 1 fi fi - if [ "$somepkgbuilt" -eq 1 ]; then + if (( somepkgbuilt )); then error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")" exit 1 fi @@ -1726,10 +1808,10 @@ else fi # Run the bare minimum in fakeroot -if [ "$INFAKEROOT" -eq 1 ]; then - if [ "$SPLITPKG" -eq 0 ]; then - if [ "$PKGFUNC" -eq 0 ]; then - if [ "$REPKG" -eq 0 ]; then +if (( INFAKEROOT )); then + if (( ! SPLITPKG )); then + if (( ! PKGFUNC )); then + if (( BUILDFUNC && ! REPKG )); then run_build tidy_install fi @@ -1755,13 +1837,13 @@ if [ "$INFAKEROOT" -eq 1 ]; then exit 0 # $E_OK fi -msg "$(gettext "Making package: %s")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))" +msg "$(gettext "Making package: %s")" "$pkgbase $pkgver-$pkgrel ($(date))" # if we are creating a source-only package, go no further -if [ "$SOURCEONLY" -ne 0 ]; then - if [ -f "$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" \ - -a "$FORCE" -eq 0 ]; then - error "$(gettext "A package has already been built. (use -f to overwrite)")" +if (( SOURCEONLY )); then + if [[ -f $SRCPKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT} ]] \ + && (( ! FORCE )); then + error "$(gettext "A source package has already been built. (use -f to overwrite)")" exit 1 fi create_srcpackage @@ -1770,12 +1852,12 @@ if [ "$SOURCEONLY" -ne 0 ]; then fi # fix flyspray bug #5973 -if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then +if (( NODEPS || NOBUILD || REPKG )); then # no warning message needed for nobuild, repkg - if [ "$NODEPS" -eq 1 ]; then + if (( NODEPS )); then warning "$(gettext "Skipping dependency checks.")" fi -elif [ $(type -p pacman) ]; then +elif [ $(type -p "${PACMAN%% *}") ]; then unset pkgdeps # Set by resolve_deps() and used by remove_deps() deperr=0 @@ -1785,12 +1867,12 @@ elif [ $(type -p pacman) ]; then msg "$(gettext "Checking Buildtime Dependencies...")" resolve_deps ${makedepends[@]} || deperr=1 - if [ $deperr -eq 1 ]; then + if (( deperr )); then error "$(gettext "Could not resolve all dependencies.")" exit 1 fi else - warning "$(gettext "pacman was not found in PATH; skipping dependency checks.")" + warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}" fi # ensure we have a sane umask set @@ -1800,19 +1882,19 @@ umask 0022 mkdir -p "$srcdir" cd "$srcdir" -if [ "$NOEXTRACT" -eq 1 ]; then +if (( NOEXTRACT )); then warning "$(gettext "Skipping source retrieval -- using existing src/ tree")" warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")" warning "$(gettext "Skipping source extraction -- using existing src/ tree")" - if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then + if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then error "$(gettext "The source directory is empty, there is nothing to build!")" plain "$(gettext "Aborting...")" exit 1 fi -elif [ "$REPKG" -eq 1 ]; then - if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \ - -a \( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \) ]; then +elif (( REPKG )); then + if (( ! PKGFUNC && ! SPLITPKG )) \ + && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then error "$(gettext "The package directory is empty, there is nothing to repackage!")" plain "$(gettext "Aborting...")" exit 1 @@ -1823,13 +1905,12 @@ else extract_sources fi -if [ "$NOBUILD" -eq 1 ]; then +if (( NOBUILD )); then msg "$(gettext "Sources are ready.")" exit 0 #E_OK else # check for existing pkg directory; don't remove if we are repackaging - if [ -d "$pkgdir" \ - -a \( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then + if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$pkgdir" fi @@ -1837,16 +1918,16 @@ else cd "$startdir" # if we are root or if fakeroot is not enabled, then we don't use it - if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then - if [ "$REPKG" -eq 0 ]; then + if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then + if (( ! REPKG )); then devel_update - run_build + (( BUILDFUNC )) && run_build fi - if [ "$SPLITPKG" -eq 0 ]; then - if [ "$PKGFUNC" -eq 1 ]; then + if (( ! SPLITPKG )); then + if (( PKGFUNC )); then run_package tidy_install - elif [ "$REPKG" -eq 0 ]; then + elif (( ! REPKG )); then tidy_install fi create_package @@ -1863,15 +1944,15 @@ else done fi else - if [ "$REPKG" -eq 0 -a \( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then + if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then devel_update - run_build + (( BUILDFUNC )) && run_build cd "$startdir" fi msg "$(gettext "Entering fakeroot environment...")" - if [ -n "$newpkgver" ]; then + if [[ -n $newpkgver ]]; then fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $? else fakeroot -- $0 -F "${ARGLIST[@]}" || exit $? @@ -1879,7 +1960,7 @@ else fi fi -msg "$(gettext "Finished making: %s")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))" +msg "$(gettext "Finished making: %s")" "$pkgbase $pkgver-$pkgrel ($(date))" install_package diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in index e43e946d..d9f1ca2e 100644 --- a/scripts/pacman-optimize.sh.in +++ b/scripts/pacman-optimize.sh.in @@ -74,23 +74,23 @@ die_r() { # PROGRAM START # determine whether we have gettext; make it a no-op if we do not -if [ ! $(type -t gettext) ]; then +if ! type gettext &>/dev/null; then gettext() { echo "$@" } fi -if [ "$1" = "-h" -o "$1" = "--help" ]; then +if [[ $1 = "-h" || $1 = "--help" ]]; then usage exit 0 fi -if [ "$1" = "-V" -o "$1" = "--version" ]; then +if [[ $1 = "-V" || $1 = "--version" ]]; then version exit 0 fi -if [ "$1" != "" ]; then +if [[ -n $1 ]]; then dbroot="$1" fi @@ -99,11 +99,11 @@ if ! type diff >/dev/null 2>&1; then die "$(gettext "diff tool was not found, please install diffutils.")" fi -if [ ! -d "$dbroot" ]; then +if [[ ! -d $dbroot ]]; then die "$(gettext "%s does not exist or is not a directory.")" "$dbroot" fi -if [ ! -w "$dbroot" ]; then +if [[ ! -w $dbroot ]]; then die "$(gettext "You must have correct permissions to optimize the database.")" fi @@ -113,7 +113,7 @@ dbroot="${dbroot%/}" lockfile="${dbroot}/db.lck" # make sure pacman isn't running -if [ -f "$lockfile" ]; then +if [[ -f $lockfile ]]; then die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")" fi # do not let pacman run while we do this @@ -130,7 +130,7 @@ find "$dbroot" -type f | sort | xargs md5sum > "$workdir/pacsums.old" msg "$(gettext "Tar'ing up %s...")" "$dbroot" cd "$dbroot" bsdtar -czf "$workdir/pacman-db.tar.gz" ./ -if [ $? -ne 0 ]; then +if (( $? )); then rm -rf "$workdir" die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot" fi @@ -139,7 +139,7 @@ fi msg "$(gettext "Making and MD5sum'ing the new database...")" mkdir "$dbroot.new" bsdtar -xpf "$workdir/pacman-db.tar.gz" -C "$dbroot.new" -if [ $? -ne 0 ]; then +if (( $? )); then rm -rf "$workdir" die_r "$(gettext "Untar'ing %s failed.")" "$dbroot" fi @@ -152,7 +152,7 @@ find "$dbroot.new" -type f | sort | \ # step 4: compare the sums msg "$(gettext "Checking integrity...")" diff "$workdir/pacsums.old" "$workdir/pacsums.new" >/dev/null 2>&1 -if [ $? -ne 0 ]; then +if (( $? )); then # failed # leave our pacman-optimize tmpdir for checking to see what doesn't match up rm -rf "$dbroot.new" @@ -167,7 +167,7 @@ mv "$dbroot" "$dbroot.old" || fail=1 mv "$dbroot.new" "$dbroot" || fail=1 chmod --reference="$dbroot.old" "$dbroot" || fail=1 chown --reference="$dbroot.old" "$dbroot" || fail=1 -if [ $fail -ne 0 ]; then +if (( fail )); then # failure with our directory shuffle die_r "$(gettext "New database substitution failed. Check for $dbroot,\n$dbroot.old, and $dbroot.new directories.")" fi diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in index 588dc49d..1550fa10 100644 --- a/scripts/pkgdelta.sh.in +++ b/scripts/pkgdelta.sh.in @@ -35,7 +35,7 @@ QUIET=0 umask 0022 msg() { - [ $QUIET -ne 0 ] && return + (( QUIET )) && return local mesg=$1; shift printf "==> ${mesg}\n" "$@" >&1 } @@ -79,7 +79,7 @@ read_pkginfo() for line in $(bsdtar -xOf "$1" .PKGINFO 2>/dev/null | grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do eval "$line" - if [ -n "$pkgname" -a -n "$pkgver" -a -n "$arch" ]; then + if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then IFS=$OLDIFS return 0 fi @@ -108,17 +108,17 @@ create_xdelta() newver="$pkgver" newarch="$arch" - if [ "$oldname" != "$newname" ]; then + if [[ $oldname != $newname ]]; then error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname" return 1 fi - if [ "$oldarch" != "$newarch" ]; then + if [[ $oldarch != $newarch ]]; then error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch" return 1 fi - if [ "$oldver" == "$newver" ]; then + if [[ $oldver == $newver ]]; then error "$(gettext "Both packages have the same version : '%s'")" "$newver" return 1 fi @@ -128,12 +128,12 @@ create_xdelta() local ret=0 xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$? - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Delta could not be created.")" return 1 else msg "$(gettext "Generated delta : '%s'")" "$deltafile" - [ $QUIET -eq 1 ] && echo "$deltafile" + (( QUIET )) && echo "$deltafile" fi return 0 } @@ -142,22 +142,22 @@ case "$1" in -q|--quiet) QUIET=1; shift ;; esac -if [ $# -ne 2 ]; then +if (( $# != 2 )); then usage exit 0 fi -if [ ! -f "$1" ]; then +if [[ ! -f $1 ]]; then error "$(gettext "File '%s' does not exist")" "$1" exit 0 fi -if [ ! -f "$2" ]; then +if [[ ! -f $2 ]]; then error "$(gettext "File '%s' does not exist")" "$2" exit 0 fi -if [ ! "$(type -p xdelta3)" ]; then +if ! type xdelta3 &>/dev/null; then error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")" exit 1 fi diff --git a/scripts/rankmirrors.py.in b/scripts/rankmirrors.py.in deleted file mode 100644 index 4b253b67..00000000 --- a/scripts/rankmirrors.py.in +++ /dev/null @@ -1,189 +0,0 @@ -#! /usr/bin/python -# -# rankmirrors - read a list of mirrors from a file and rank them by speed -# @configure_input@ -# -# Copyright (c) 2006-2009 Pacman Development Team <pacman-dev@archlinux.org> -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -import os, sys, datetime, time, socket, urllib2 -from optparse import OptionParser -from string import Template - -def createOptParser(): - usage = "usage: %prog [options] MIRRORFILE | URL" - version = "%prog (pacman) @PACKAGE_VERSION@\n" \ - "Copyright (c) 2006-2009 Pacman Development Team <pacman-dev@archlinux.org>.\n" \ - "Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n" \ - "This is free software; see the source for copying conditions.\n" \ - "There is NO WARRANTY, to the extent permitted by law." - description = "Ranks pacman mirrors by their connection and opening " \ - "speed. Pacman mirror files are located in /etc/pacman.d/. It " \ - "can also rank one mirror if the URL is provided." - parser = OptionParser(usage = usage, version = version, - description = description) - parser.add_option("-n", type = "int", dest = "num", default = 0, - help = "number of servers to output, 0 for all") - parser.add_option("-t", "--times", action = "store_true", - dest = "times", default = False, - help = "only output mirrors and their response times") - parser.add_option("-u", "--url", action = "store_true", dest = "url", - default = False, help = "test a specific url") - parser.add_option("-v", "--verbose", action = "store_true", - dest = "verbose", default = False, - help = "be verbose in ouptut") - # The following two options should be automatic - #parser.add_option("-h", "--help", action = "help") - #parser.add_option("-V", "--version", action = "version") - return parser - -def timeCmd(cmd): - before = time.time() - try: - cmd() - except KeyboardInterrupt, ki: - raise ki - except socket.timeout, ioe: - return 'timeout' - except Exception, e: - return 'unreachable' - return time.time() - before - -def talkToServer(serverUrl): - opener = urllib2.build_opener() - # retrieve first 50,000 bytes only - tmp = opener.open(serverUrl).read(50000) - -def getFuncToTime(serverUrl): - return lambda : talkToServer(serverUrl) - -def cmpPairBySecond(p1, p2): - if p1[1] == p2[1]: - return 0 - if p1[1] < p2[1]: - return -1 - return 1 - -def printResults(servers, time, verbose, num): - items = servers.items() - items.sort(cmpPairBySecond) - itemsLen = len(items) - numToShow = num - if numToShow > itemsLen or numToShow == 0: - numToShow = itemsLen - if itemsLen > 0: - if time: - print - print ' Servers sorted by time (seconds):' - for i in items[0:numToShow]: - if i[1] == 'timeout' or i[1] == 'unreachable': - print i[0], ':', i[1] - else: - print i[0], ':', "%.2f" % i[1] - else: - for i in items[0:numToShow]: - print 'Server =', i[0] - -if __name__ == "__main__": - parser = createOptParser() - (options, args) = parser.parse_args() - - if len(args) != 1: - parser.print_help(sys.stderr) - sys.exit(0) - - # allows connections to time out if they take too long - socket.setdefaulttimeout(10) - - if options.url: - if options.verbose: - print 'Testing', args[0] + '...' - try: - serverToTime = timeCmd(getFuncToTime(args[0])) - except KeyboardInterrupt, ki: - sys.exit(1) - if serverToTime == 'timeout' or serverToTime == 'unreachable': - print args[0], ':', serverToTime - else: - print args[0], ':', "%.2f" % serverToTime - sys.exit(0) - - if not os.path.isfile(args[0]) and args[0] != "-": - print >>sys.stderr, 'rankmirrors: file', args[0], 'does not exist.' - sys.exit(1) - - if args[0] == "-": - fl = sys.stdin - else: - fl = open(args[0], 'r') - - serverToTime = {} - if options.times: - print 'Querying servers, this may take some time...' - else: - print "# Server list generated by rankmirrors on", - print datetime.date.today() - for ln in fl.readlines(): - splitted = ln.split('=') - if splitted[0].strip() != 'Server': - if not options.times: - print ln, - continue - - serverUrl = splitted[1].strip() - if serverUrl[-1] == '\n': - serverUrl = serverUrl[0:-1] - if options.verbose and options.times: - print serverUrl, '...', - elif options.verbose: - print '#', serverUrl, '...', - elif options.times: - print ' * ', - sys.stdout.flush() - - # if the $repo var is used in the url, replace it by core - tempUrl = Template(serverUrl).safe_substitute(repo='core') - - # add @DBEXT@ to server name. the repo name is parsed - # from the mirror url; it is the third (or fourth) dir - # from the end, where the url is http://foo/bar/REPO/os/arch - try: - splitted2 = tempUrl.split('/') - if tempUrl[-1] != '/': - repoName = splitted2[-3] - dbFileName = '/' + repoName + '@DBEXT@' - else: - repoName = splitted2[-4] - dbFileName = repoName + '@DBEXT@' - except: - dbFileName = '' - - try: - serverToTime[serverUrl] = timeCmd(getFuncToTime(tempUrl + dbFileName)) - if options.verbose: - try: - print "%.2f" % serverToTime[serverUrl] - except: - print serverToTime[serverUrl] - except: - print - printResults(serverToTime, options.times, options.verbose, - options.num) - sys.exit(0) - - printResults(serverToTime, options.times, options.verbose, options.num) - -# vim: set ts=4 sw=4 et: diff --git a/scripts/rankmirrors.sh.in b/scripts/rankmirrors.sh.in new file mode 100644 index 00000000..d5cbaddd --- /dev/null +++ b/scripts/rankmirrors.sh.in @@ -0,0 +1,202 @@ +#!/bin/bash +# +# rankmirrors - read a list of mirrors from a file and rank them by speed +# @configure_input@ +# +# Copyright (c) 2009 Matthew Bruenig <matthewbruenig@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# traps interrupt key to spit out pre-interrupt info +trap finaloutput INT + +usage() { + echo "Usage: rankmirrors [options] MIRRORFILE | URL" + echo + echo "Ranks pacman mirrors by their connection and opening speed. Pacman mirror" + echo "files are located in /etc/pacman.d/. It can also rank one mirror if the URL is" + echo "provided." + echo + echo "Options:" + echo " --version show program's version number and exit" + echo " -h, --help show this help message and exit" + echo " -n NUM number of servers to output, 0 for all" + echo " -t, --times only output mirrors and their response times" + echo " -u, --url test a specific url" + echo " -v, --verbose be verbose in ouptut" + exit 0 +} + +version() { + echo "rankmirrors (pacman) @PACKAGE_VERSION@" + echo "Copyright (c) 2009 Matthew Bruenig <matthewbruenig@gmail.com>." + echo + echo "This is free software; see the source for copying conditions." + echo "There is NO WARRANTY, to the extent permitted by law." + exit 0 +} + +err() { + echo "$1" + exit 1 +} + +# gettime fetchurl (e.g gettime http://foo.com/core/os/i686/core.db.tar.gz) +# returns the fetching time, or timeout, or unreachable +gettime() { + IFS=' ' output=( $(curl -s -m 10 -w "%{time_total} %{http_code}" "$1" -o/dev/null) ) + (( $? == 28 )) && echo timeout && return + (( ${output[1]} >= 400 || ! ${output[1]} )) && echo unreachable && return + echo "${output[0]}" +} + +# getfetchurl serverurl (e.g. getturl http://foo.com/core/os/i686) +# if $repo is in the line, then assumes core +# if $arch is in the line, then assumes $(uname -m) +# returns a fetchurl (e.g. http://foo.com/core/os/i686/core.db.tar.gz) +ARCH="$(uname -m)" +getfetchurl() { + local strippedurl="${1%/}" + + local replacedurl="${strippedurl//'$repo'/core}" + replacedurl="${replacedurl//'$arch'/$ARCH}" + + local tmp="${replacedurl%/*}" + tmp="${tmp%/*}" + + local reponame="${tmp##*/}" + if [[ -z $reponame || $reponame = $replacedurl ]]; then + echo "fail" + else + local fetchurl="${replacedurl}/$reponame@DBEXT@" + echo "$fetchurl" + fi +} + +# This exists to remove the need for a separate interrupt function +finaloutput() { + IFS=$'\n' sortedarray=( $(LC_COLLATE=C printf "%s\n" "${timesarray[@]}" | sort) ) + + # Final output for mirrorfile + numiterator="0" + if [[ $TIMESONLY ]]; then + echo + echo " Servers sorted by time (seconds):" + for line in "${sortedarray[@]}"; do + echo "${line#* } : ${line% *}" + ((numiterator++)) + (( NUM && numiterator >= NUM )) && break + done + else + for line in "${sortedarray[@]}"; do + echo "Server = ${line#* }" + ((numiterator++)) + (( NUM && numiterator >= NUM )) && break + done + fi + exit 0 +} + + +# Argument parsing +[[ $1 ]] || usage +while [[ $1 ]]; do + if [[ ${1:0:2} = -- ]]; then + case "${1:2}" in + help) usage ;; + version) version ;; + times) TIMESONLY=1 ; shift ;; + verbose) VERBOSE=1 ; shift ;; + url) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; shift 2;; + *) err "\`$1' is an invalid argument." + esac + elif [[ ${1:0:1} = - ]]; then + + if [[ ! ${1:1:1} ]]; then + [[ -t 0 ]] && err "Stdin is empty." + IFS=$'\n' linearray=( $(</dev/stdin) ) + STDIN=1 + shift + else + snum=1 + for ((i=1 ; i<${#1}; i++)); do + case ${1:$i:1} in + h) usage ;; + t) TIMESONLY=1 ;; + v) VERBOSE=1 ;; + u) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; snum=2;; + n) [[ $2 ]] || err "Must specify number." ; NUM="$2" ; snum=2;; + *) err "\`-$1' is an invald argument." ;; + esac + done + shift $snum + fi + elif [[ -f $1 ]]; then + FILE="1" + IFS=$'\n' linearray=( $(<$1) ) + [[ $linearray ]] || err "File is empty." + shift + else + err "\`$1' does not exist." + fi +done + +# Some sanity checks +[[ $NUM ]] || NUM=0 +[[ $FILE && $CHECKURL ]] && err "Cannot specify a url and mirrorfile." +[[ $FILE || $CHECKURL || $STDIN ]] || err "Must specify url, mirrorfile, or stdin." + +# Single url handling +if [[ $CHECKURL ]]; then + url="$(getfetchurl "$URL")" + [[ $url = fail ]] && err "url \`$URL' is malformed." + [[ $VERBOSE ]] && echo "Testing $url..." + time=$(gettime "$url") + echo "$URL : $time" + exit 0 +fi + +# Get url results from mirrorfile, fill up the array, and so on +if [[ $TIMESONLY ]]; then + echo "Querying servers, this may take some time..." +elif [[ $FILE ]]; then + echo "# Server list generated by rankmirrors on $(date +%Y-%m-%d)" +fi + +timesarray=() +for line in "${linearray[@]}"; do + if [[ $line =~ ^# ]]; then + [[ $TIMESONLY ]] || echo $line + elif [[ $line =~ ^Server ]]; then + + # Getting values and times and such + server="${line#*= }" + url="$(getfetchurl "$server")" + [[ $url = fail ]] && err "url \`$URL' is malformed." + time=$(gettime "$url") + timesarray+=("$time $server") + + # Output + if [[ $VERBOSE && $TIMESONLY ]]; then + echo "$server ... $time" + elif [[ $VERBOSE ]]; then + echo "# $server ... $time" + elif [[ $TIMESONLY ]]; then + echo -n " *" + fi + fi +done +finaloutput + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index c8380c4e..0e46c371 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -42,7 +42,7 @@ msg() { } msg2() { - [ $QUIET -ne 0 ] && return + (( QUIET )) && return local mesg=$1; shift printf " -> ${mesg}\n" "$@" >&1 } @@ -90,7 +90,7 @@ There is NO WARRANTY, to the extent permitted by law.\n")" # arg2 - List # arg3 - File to write to write_list_entry() { - if [ -n "$2" ]; then + if [[ -n $2 ]]; then echo "%$1%" >>$3 echo -e $2 >>$3 fi @@ -102,7 +102,7 @@ find_pkgentry() local pkgentry for pkgentry in $tmpdir/$pkgname*; do name=${pkgentry##*/} - if [ "${name%-*-*}" = "$pkgname" ]; then + if [[ ${name%-*-*} = $pkgname ]]; then echo $pkgentry return 0 fi @@ -126,17 +126,18 @@ db_write_delta() pkgname="$(get_delta_pkgname $deltafile)" pkgentry=$(find_pkgentry $pkgname) - if [ -z "$pkgentry" ]; then + if [[ -z $pkgentry ]]; then return 1 fi deltas="$pkgentry/deltas" # create deltas file if it does not already exist - if [ ! -f "$deltas" ]; then + if [[ ! -f $deltas ]]; then msg2 "$(gettext "Creating 'deltas' db entry...")" echo -e "%DELTAS%" >>$deltas fi # get md5sum and compressed size of package - md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')" + md5sum="$(openssl dgst -md5 "$deltafile")" + md5sum="${md5sum##* }" csize=$(@SIZECMD@ "$deltafile") oldfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (source)" | sed 's/.*: *//') @@ -161,11 +162,11 @@ db_remove_delta() pkgname="$(get_delta_pkgname $deltafile)" pkgentry=$(find_pkgentry $pkgname) - if [ -z "$pkgentry" ]; then + if [[ -z $pkgentry ]]; then return 1 fi deltas="$pkgentry/deltas" - if [ ! -f "$deltas" ]; then + if [[ ! -f $deltas ]]; then return 1 fi if grep -q "$filename" $deltas; then @@ -213,18 +214,19 @@ db_write_entry() IFS=$OLDIFS # get md5sum and compressed size of package - md5sum="$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')" + md5sum="$(openssl dgst -md5 "$pkgfile")" + md5sum="${md5sum##* }" csize=$(@SIZECMD@ "$pkgfile") # ensure $pkgname and $pkgver variables were found - if [ -z "$pkgname" -o -z "$pkgver" ]; then + if [[ -z $pkgname || -z $pkgver ]]; then error "$(gettext "Invalid package file '%s'.")" "$pkgfile" return 1 fi cd "$tmpdir" - if [ -d "$pkgname-$pkgver" ]; then + if [[ -d $pkgname-$pkgver ]]; then warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver" fi @@ -236,30 +238,30 @@ db_write_entry() cd "$pkgname-$pkgver" # restore an eventual deltas file - [ -f "../$pkgname.deltas" ] && mv "../$pkgname.deltas" deltas + [[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas # create desc entry msg2 "$(gettext "Creating 'desc' db entry...")" echo -e "%FILENAME%\n$(basename "$1")\n" >>desc echo -e "%NAME%\n$pkgname\n" >>desc - [ -n "$pkgbase" ] && echo -e "%BASE%\n$pkgbase\n" >>desc + [[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc echo -e "%VERSION%\n$pkgver\n" >>desc - [ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc + [[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc write_list_entry "GROUPS" "$_groups" "desc" - [ -n "$csize" ] && echo -e "%CSIZE%\n$csize\n" >>desc - [ -n "$size" ] && echo -e "%ISIZE%\n$size\n" >>desc + [[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc + [[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc # compute checksums msg2 "$(gettext "Computing md5 checksums...")" echo -e "%MD5SUM%\n$md5sum\n" >>desc - [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc + [[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc write_list_entry "LICENSE" "$_licenses" "desc" - [ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc - [ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc - [ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc + [[ -n $arch ]] && echo -e "%ARCH%\n$arch\n" >>desc + [[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc + [[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc write_list_entry "REPLACES" "$_replaces" "desc" - [ -n "$force" ] && echo -e "%FORCE%\n" >>desc + [[ -n $force ]] && echo -e "%FORCE%\n" >>desc # create depends entry msg2 "$(gettext "Creating 'depends' db entry...")" @@ -281,9 +283,9 @@ db_remove_entry() { local pkgname=$1 local notfound=1 local pkgentry=$(find_pkgentry $pkgname) - while [ -n "$pkgentry" ]; do + while [[ -n $pkgentry ]]; do notfound=0 - if [ -f "$pkgentry/deltas" ]; then + if [[ -f $pkgentry/deltas ]]; then mv "$pkgentry/deltas" "$tmpdir/$pkgname.deltas" fi msg2 "$(gettext "Removing existing entry '%s'...")" \ @@ -301,16 +303,16 @@ check_repo_db() CLEAN_LOCK=1 else error "$(gettext "Failed to acquire lockfile: %s.")" "$LOCKFILE" - [ -f "$LOCKFILE" ] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)" + [[ -f $LOCKFILE ]] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)" exit 1 fi - if [ -f "$REPO_DB_FILE" ]; then + if [[ -f $REPO_DB_FILE ]]; then # there are two situations we can have here- a DB with some entries, # or a DB with no contents at all. if ! bsdtar -tqf "$REPO_DB_FILE" '*/desc' >/dev/null 2>&1; then # check empty case - if [ -n "$(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null)" ]; then + if [[ -n $(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null) ]]; then error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE" exit 1 fi @@ -337,15 +339,15 @@ check_repo_db() add() { - if [ ! -f "$1" ]; then + if [[ ! -f $1 ]]; then error "$(gettext "File '%s' not found.")" "$1" return 1 fi - if [ "${1##*.}" == "delta" ]; then + if [[ ${1##*.} == "delta" ]]; then deltafile=$1 msg "$(gettext "Adding delta '%s'")" "$deltafile" - if [ ! "$(type -p xdelta3)" ]; then + if ! type xdelta3 &>/dev/null; then error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")" exit 1 fi @@ -357,7 +359,7 @@ add() fi pkgfile=$1 - if ! bsdtar -tqf "$pkgfile" .PKGINFO 2>&1 >/dev/null; then + if ! bsdtar -tqf "$pkgfile" .PKGINFO >/dev/null 2>&1; then error "$(gettext "'%s' is not a package file, skipping")" "$pkgfile" return 1 fi @@ -369,7 +371,7 @@ add() remove() { - if [ "${1##*.}" == "delta" ]; then + if [[ ${1##*.} == "delta" ]]; then deltafile=$1 msg "$(gettext "Searching for delta '%s'...")" "$deltafile" if db_remove_delta "$deltafile"; then @@ -403,8 +405,8 @@ clean_up() { local exit_code=$? cd "$startdir" - [ -d "$tmpdir" ] && rm -rf "$tmpdir" - [ $CLEAN_LOCK -eq 1 -a -f "$LOCKFILE" ] && rm -f "$LOCKFILE" + [[ -d $tmpdir ]] && rm -rf "$tmpdir" + (( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE" exit $exit_code } @@ -412,7 +414,7 @@ clean_up() { # PROGRAM START # determine whether we have gettext; make it a no-op if we do not -if [ ! $(type -t gettext) ]; then +if ! type gettext &>/dev/null; then gettext() { echo "$@" } @@ -423,15 +425,9 @@ case "$1" in -V|--version) version; exit 0;; esac -# check for correct number of args -if [ $# -lt 2 ]; then - usage - exit 1 -fi - # figure out what program we are cmd="$(basename $0)" -if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then +if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then error "$(gettext "Invalid command name '%s' specified.")" "$cmd" exit 1 fi @@ -450,14 +446,8 @@ success=0 for arg in "$@"; do case "$arg" in -q|--quiet) QUIET=1;; - - -f|--force) - warning "$(gettext "the -f and --force options are no longer recognized")" - msg2 "$(gettext "use options=(force) in the PKGBUILD instead")" - ;; - *) - if [ -z "$REPO_DB_FILE" ]; then + if [[ -z $REPO_DB_FILE ]]; then REPO_DB_FILE="$arg" LOCKFILE="$REPO_DB_FILE.lck" check_repo_db @@ -472,7 +462,7 @@ for arg in "$@"; do done # if at least one operation was a success, re-zip database -if [ $success -eq 1 ]; then +if (( success )); then msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE" case "$REPO_DB_FILE" in @@ -486,7 +476,7 @@ if [ $success -eq 1 ]; then filename=$(basename "$REPO_DB_FILE") cd "$tmpdir" - if [ -n "$(ls)" ]; then + if [[ -n $(ls) ]]; then bsdtar -c${TAR_OPT}f "$filename" * else # we have no packages remaining? zip up some emptyness @@ -495,10 +485,11 @@ if [ $success -eq 1 ]; then fi cd "$startdir" - [ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old" - [ -f "$tmpdir/$filename" ] && mv "$tmpdir/$filename" "$REPO_DB_FILE" + [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old" + [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE" else msg "$(gettext "No packages modified, nothing to do.")" + exit 1 fi exit 0 |