[arch-projects] [ABS][PATCH] Bashify and quoting
Thanks to Lukas Fleischer for review Signed-off-by: Sébastien Luttringer <seblu@seblu.net> --- abs | 80 +++++++++++++++++++++++----------------------- makeworld | 50 ++++++++++++++--------------- scripts/svn2abs | 84 ++++++++++++++++++++++++------------------------- scripts/update-abs.sh | 22 ++++++------- 4 files changed, 118 insertions(+), 118 deletions(-) diff --git a/abs b/abs index 39d5798..25a3e1d 100755 --- a/abs +++ b/abs @@ -22,8 +22,8 @@ ## # Constants ## -ABS_VERSION="%%ABS_VERSION%%" -CONFDIR="%%CONF_DIR%%" +ABS_VERSION='%%ABS_VERSION%%' +CONFDIR='%%CONF_DIR%%' SYNCCMD='rsync' SYNCARGS='-mrtv --no-motd --delete-after --no-p --no-o --no-g' BUG_REPORT_EMAIL=pacman-dev@archlinux.org @@ -57,7 +57,7 @@ error() { ## # Source configuration ## -if [ -f "$CONFDIR/abs.conf" ]; then +if [[ -f $CONFDIR/abs.conf ]]; then source "$CONFDIR/abs.conf" else error "Could not find configuration file $CONFDIR/abs.conf" @@ -67,23 +67,23 @@ fi ## # User based overrides ## -[ -f ~/.abs.conf ] && source ~/.abs.conf +[[ -f ~/.abs.conf ]] && source ~/.abs.conf ## # Helper functions ## usage() { echo "Arch Build System $ABS_VERSION -- synchronization utility" - echo "" - echo "Usage:" + echo + echo 'Usage:' echo "$0 [options] [repository1[/package1] [repository2[/package2] ...]]" echo - echo "Options:" - echo " -h, --help Display this help message then exit." - echo " -V, --version Display version information then exit." - echo " -t, --tarball Sync ABS tree using tarballs from your pacman mirror." + echo 'Options:' + echo ' -h, --help Display this help message then exit.' + echo ' -V, --version Display version information then exit.' + echo ' -t, --tarball Sync ABS tree using tarballs from your pacman mirror.' echo - echo "abs will synchronize PKGBUILD scripts from the Arch Linux repositories" + echo 'abs will synchronize PKGBUILD scripts from the Arch Linux repositories' echo "into $ABSROOT via rsync. If no argument is given, abs will synchronize" echo "the repositories specified in ${CONFDIR}abs.conf." echo @@ -93,11 +93,11 @@ usage() { version() { echo "abs $ABS_VERSION" echo - echo "Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>" - echo "Copyright (C) 2007-2010 Aaron Griffin <aaron@archlinux.org>" + echo 'Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>' + echo 'Copyright (C) 2007-2010 Aaron Griffin <aaron@archlinux.org>' echo - echo "This is free software; see the source for copying conditions." - echo "There is NO WARRANTY, to the extent permitted by law." + echo 'This is free software; see the source for copying conditions.' + echo 'There is NO WARRANTY, to the extent permitted by law.' } update_rsync() { @@ -105,15 +105,15 @@ update_rsync() { cd "$ABSROOT" - if [ ! "$(type -p rsync)" ]; then - error "missing rsync synchronization utility. Install rsync." + if [[ -z $(type -p rsync) ]]; then + error 'missing rsync synchronization utility. Install rsync.' exit $_E_MISSING_PROGRAM fi - if [ "$CLPARAM" = "" ]; then + if [[ -z $CLPARAM ]]; then # using repos specified in abs.conf for repo in "${REPOS[@]}"; do - if [ "$repo" != "${repo#!}" ]; then + if [[ "$repo" != "${repo#!}" ]]; then EXCLUDE="${EXCLUDE} --filter=-_/${repo#!}/" fi done @@ -124,7 +124,7 @@ update_rsync() { # using repos/packages specified on the command line for param in "${REPOS[@]}"; do INCLUDE="${INCLUDE} --include=/${param}" - if [ "$param" != "${param/\/}" ]; then + if [[ "$param" != "${param/\/}" ]]; then repo=${param%/*} INCLUDE="${INCLUDE} --include=/${repo}" EXCLUDE="${EXCLUDE} --exclude=/${repo}/*" @@ -132,55 +132,55 @@ update_rsync() { done # remove duplicate values - INCLUDE=$(echo $INCLUDE | tr " " "\n" | sort -u | tr "\n" " ") + INCLUDE=$(echo $INCLUDE | tr ' ' '\n' | sort -u | tr '\n' ' ') EXCLUDE="${EXCLUDE} --exclude=/*" fi - msg "Starting ABS sync..." + msg 'Starting ABS sync...' $SYNCCMD $SYNCARGS $INCLUDE $EXCLUDE ${SYNCSERVER}::abs/{${ARCH},any}/ $ABSROOT } update_tarball() { cd "$ABSROOT" - if [ ! "$(type -p wget)" ]; then - error "missing wget download utility. Install wget." + if [[ -z $(type -p wget) ]]; then + error 'missing wget download utility. Install wget.' exit $_E_MISSING_PROGRAM fi - if [ -f "$MIRRORLIST" ]; then - mirrorlist=$(grep "^Server" $MIRRORLIST | cut -f3 -d" ") + if [[ -f $MIRRORLIST ]]; then + mirrorlist=$(grep "^Server" $MIRRORLIST | cut -f3 -d' ') else error "Could not find pacman mirrorlist file $MIRRORLIST" exit $_E_CONFIG_ERROR fi - msg "Downloading tarballs..." + msg 'Downloading tarballs...' for repo in "${REPOS[@]}"; do - if [ "$repo" == "${repo#!}" ]; then + if [[ "$repo" == "${repo#!}" ]]; then echo " ==> ${repo}..." local ret - for mirror in ${mirrorlist[@]}; do + for mirror in "${mirrorlist[@]}"; do ret=0 tarball=$(echo $mirror | sed "s#\$repo#$repo#;s#\$arch#$ARCH#") tarball="${tarball}/${repo}.abs.tar.gz" protocol=$(echo $tarball | cut -f1 -d":") - if [ "$protocol" == "file" ]; then + if [[ "$protocol" == "file" ]]; then tarball=$(echo $tarball | sed "s#file://##") ln -s $tarball . 2>/dev/null || ret=$? - if [ $ret -ne 0 ]; then + if (( $ret != 0 )); then ret=0 fi else wget -q $tarball || ret=$? fi - if [ $ret -eq 0 ]; then + if (( $ret == 0 )); then break fi done - if [ $ret -ne 0 ]; then + if (( $ret != 0 )); then error "Download failed" continue fi @@ -202,8 +202,8 @@ trap 'error "An unknown error has occured. Exiting..."; exit 1' ERR ## # Parse Options ## -OPT_SHORT="hVt" -OPT_LONG="help,version,tarball" +OPT_SHORT='hVt' +OPT_LONG='help,version,tarball' OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')" if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then # This is a small hack to stop the script bailing with 'set -e' @@ -224,7 +224,7 @@ while true; do shift done -if [ "$#" -gt "0" ]; then +if (( $# > 0 )); then CLPARAM=1 REPOS=("$@") fi @@ -232,12 +232,12 @@ fi ## # Verify Config ## -if [ ! -d "$ABSROOT" ]; then +if [[ ! -d $ABSROOT ]]; then error "$ABSROOT does not exist (or is not a directory)" exit $_E_CONFIG_ERROR fi -if [ ! -w "$ABSROOT" ]; then +if [[ ! -w $ABSROOT ]]; then error "no write permissions in $ABSROOT" exit $_E_CONFIG_ERROR fi @@ -247,9 +247,9 @@ fi ## # Use tarball method on first run -[ "$(ls -A $ABSROOT | sed -e 's#local##' -e 's#README##')" -o "$CLPARAM" ] || TARBALL=1 +[[ -n $(ls -A $ABSROOT | sed -e 's#local##' -e 's#README##') || -n $CLPARAM ]] || TARBALL=1 -if [ "$TARBALL" ]; then +if [[ -n $TARBALL ]]; then update_tarball else update_rsync diff --git a/makeworld b/makeworld index e5d9f0f..dd6e00b 100755 --- a/makeworld +++ b/makeworld @@ -19,7 +19,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -ABS_VERSION="%%ABS_VERSION%%" +ABS_VERSION='%%ABS_VERSION%%' BUG_REPORT_EMAIL='pacman-dev@archlinux.org' toplevel=$(pwd) @@ -31,38 +31,38 @@ trap 'error "Aborted by user! Exiting..."; exit 1' INT trap 'error "An unknown error has occured. Exiting..."; exit 1' ERR usage() { - printf "makeworld %s - a makepkg wrapper to build multiple packages\n" "$myver" + printf 'makeworld %s - a makepkg wrapper to build multiple packages\n' "$myver" echo - printf "Usage: %s [options] <destdir> <repo> [repo] ...\n" "$0" + printf 'Usage: %s [options] <destdir> <repo> [repo] ...\n' "$0" echo - echo "Where <repo> is one or more directory names under the ABS root" - echo " eg: makeworld -c /packages core extra" + echo 'Where <repo> is one or more directory names under the ABS root' + echo ' eg: makeworld -c /packages core extra' echo - echo "This should be run from the toplevel directory of ABS (usually /var/abs)" + echo 'This should be run from the toplevel directory of ABS (usually /var/abs)' echo - echo "See makepkg --help for supported options (passed directly to makepkg)" + echo 'See makepkg --help for supported options (passed directly to makepkg)' } version() { - printf "makeworld %s\n" "$myver" - printf "\ + printf 'makeworld %s\n' "$myver" + printf '\ Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>\n\n\ Copyright (C) 2007-2010 Aaron Griffin <aaron@archlinux.org>\n\n\ This is free software; see the source for copying conditions.\n\ -There is NO WARRANTY, to the extent permitted by law.\n" +There is NO WARRANTY, to the extent permitted by law.\n' } # Source makepkg.conf; fail if it is not found (need this for $CARCH, $PKGEXT) -if [ -r "/etc/makepkg.conf" ]; then - source "/etc/makepkg.conf" +if [[ -r /etc/makepkg.conf ]]; then + source /etc/makepkg.conf else - printf "%s not found" "/etc/makepkg.conf" - echo "Aborting..." + printf '%s not found' '/etc/makepkg.conf' + echo 'Aborting...' exit 1 fi # Source user-specific makepkg.conf overrides -if [ -r ~/.makepkg.conf ]; then +if [[ -r ~/.makepkg.conf ]]; then source ~/.makepkg.conf fi @@ -79,7 +79,7 @@ for arg in $*; do # and let it error out later if it was invalid MAKEPKG_OPTS="$MAKEPKG_OPTS $arg" ;; -*) - while getopts "AcCdefFghiLmorRsV-" opt; do + while getopts 'AcCdefFghiLmorRsV-' opt; do case $opt in h) usage; exit 0 ;; @@ -96,23 +96,23 @@ for arg in $*; do dest=$arg; shift; break ;; esac shift - if [ "$dest" != "" ]; then + if [[ -n $dest ]]; then break fi done -if [ "$dest" = "" ]; then +if [[ -z $dest ]]; then usage exit 1 fi -if [ $# -lt 1 ]; then +if (( $# < 1 )); then usage exit 1 fi # convert a (possibly) relative path to absolute -if [ ! -d "$dest" ]; then +if [[ ! -d $dest ]]; then echo "$dest does not exist, creating directory" mkdir "$dest" fi @@ -125,13 +125,13 @@ sd=$(date +"[%b %d %H:%M]") for repo in $*; do for pkg in $(find "$toplevel/$repo" -maxdepth 1 -mindepth 1 -type d | sort); do cd $pkg - if [ -f PKGBUILD ]; then - . PKGBUILD + if [[ -f PKGBUILD ]]; then + source PKGBUILD buildstatus=0 - if [ ! -f "$dest/$pkgname-$pkgver-$pkgrel-$CARCH$PKGEXT" -a ! -f "$dest/$pkgname-$pkgver-$pkgrel-any$PKGEXT" ]; then + if [[ ! -f "$dest/$pkgname-$pkgver-$pkgrel-$CARCH$PKGEXT" && ! -f "$dest/$pkgname-$pkgver-$pkgrel-any$PKGEXT" ]]; then PKGDEST="$dest" makepkg $MAKEPKG_OPTS -m 2>&1 1>&2 | tee -a $toplevel/makepkg.log - if [ ${PIPESTATUS[0]} -ne 0 ]; then + if (( ${PIPESTATUS[0]} != 0 )); then buildstatus=2 else buildstatus=1 @@ -151,7 +151,7 @@ for repo in $*; do done ed=$(date +"[%b %d %H:%M]") -echo "makeworld complete." >>$toplevel/build.log +echo 'makeworld complete.' >>$toplevel/build.log echo " started: $sd" >>$toplevel/build.log echo " finished: $ed" >>$toplevel/build.log diff --git a/scripts/svn2abs b/scripts/svn2abs index 0d4c74d..102c731 100755 --- a/scripts/svn2abs +++ b/scripts/svn2abs @@ -21,7 +21,7 @@ ## # Constants ## -ABS_VERSION="%%ABS_VERSION%%" +ABS_VERSION='%%ABS_VERSION%%' TREE_DIR=/tmp/__abs-tree__ # Directory to store the extracted ABS tree ## @@ -41,29 +41,29 @@ function usage() echo " $0 (-v | --version)" echo " $0 (-h | --help)" echo - echo "Takes svn repo structure of form \$pkgname/repos/\$repo-\$arch" - echo "and converts it to the ABS structure of \$arch/\$repo/\$pkgname" + echo 'Takes svn repo structure of form $pkgname/repos/$repo-$arch' + echo 'and converts it to the ABS structure of $arch/$repo/$pkgname' echo "then syncs ABS tree in $ABS_DIR with extracted structure." echo - echo "Options:" - echo " -h | --help - show this message" - echo " -v | --version - show version information" + echo 'Options:' + echo ' -h | --help - show this message' + echo ' -v | --version - show version information' echo - echo "Parameters:" - echo " [svn checkout dir] - dir to store svn checkout. Defaults to" + echo 'Parameters:' + echo ' [svn checkout dir] - dir to store svn checkout. Defaults to' echo " $CHECKOUT_DIR" - echo " [abs dir] - dir containing abs tree to update. Defaults to" + echo ' [abs dir] - dir containing abs tree to update. Defaults to' echo " $ABS_DIR" - echo " [svn repo location] - URL to subversion repo containing PKGBUILDs" + echo ' [svn repo location] - URL to subversion repo containing PKGBUILDs' } version() { echo "svn2abs $ABS_VERSION" echo - echo "Copyright (C) 2008-2010 Aaron Griffin <aaron@archlinux.org>." + echo 'Copyright (C) 2008-2010 Aaron Griffin <aaron@archlinux.org>.' echo - echo "This is free software; see the source for copying conditions." - echo "There is NO WARRANTY, to the extent permitted by law." + echo 'This is free software; see the source for copying conditions.' + echo 'There is NO WARRANTY, to the extent permitted by law.' } @@ -75,12 +75,12 @@ function checkout_svn() local targetdir=$1 local origdir=$(pwd) - if [ -f "$targetdir" ]; then + if [[ -f $targetdir ]]; then echo "Could not create checkout target $targetdir. File exists." return 1 fi - if [ ! -d "$targetdir" ]; then + if [[ ! -d $targetdir ]]; then mkdir "$targetdir" fi @@ -89,23 +89,23 @@ function checkout_svn() # Simple check - if $targetdir/.svn exists, then we can assume # the repo has been checked out (ie. we can just run an update # instead of a full checkout) - if [ -d "./.svn" ]; then + if [[ -d './.svn' ]]; then # Checkout already exists - just update it - echo "Updating SVN repo..." + echo 'Updating SVN repo...' svn update else # Checkout the tree into $targetdir - echo "Checking out SVN repo..." + echo 'Checking out SVN repo...' svn co "$SVN_REPO_LOCATION" ./ fi - if [ "$?" != "0" ]; then + if (( $? != 0 )); then cd "$origdir" - echo "Error with SVN checkout/update." + echo 'Error with SVN checkout/update.' return 1 fi - echo "SVN checkout/update complete." + echo 'SVN checkout/update complete.' cd "$origdir" return 0 @@ -124,17 +124,17 @@ function extract_abs_tree() local checkoutdir="$1" local origdir=$(pwd) - if [ ! -d "$checkoutdir" ]; then + if [[ ! -d "$checkoutdir" ]]; then echo "SVN checkout dir $checkoutdir does not exist" return 1 fi - if [ -f "$targetdir" ]; then + if [[ -f "$targetdir" ]]; then echo "Could not create abs tree target $targetdir. File exists." return 1 fi - if [ ! -d "$targetdir" ]; then + if [[ ! -d "$targetdir" ]]; then mkdir "$targetdir" else # Clear out target dir @@ -142,14 +142,14 @@ function extract_abs_tree() fi cd "$targetdir" - local targetdir="$(pwd)" + local targetdir=$(pwd) cd - cd "$checkoutdir" for pkg in *; do # It seems that some repos directories have no tags in them... - if [ -d "$pkg" -a -d "$pkg/repos" ]; then + if [[ -d "$pkg" && -d "$pkg/repos" ]]; then echo "Creating ABS tree for package $pkg" cd $pkg/repos @>/dev/null @@ -157,8 +157,8 @@ function extract_abs_tree() for repo in $(ls); do arch=$(echo $repo | sed "s/.*-\(.*\)/\1/") dest_repo=$(echo $repo | sed "s/\(.*\)-.*/\1/") - mkdir -p $targetdir/$arch/$dest_repo/$pkg - cp -r $repo/* $targetdir/$arch/$dest_repo/$pkg + mkdir -p "$targetdir/$arch/$dest_repo/$pkg" + cp -r "$repo"/* "$targetdir/$arch/$dest_repo/$pkg" done cd ../../ @@ -176,36 +176,36 @@ function extract_abs_tree() ## # Simple params ## -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 CHECKOUT_DIR=$1 fi -if [ "$2" != "" ]; then +if [[ -n $2 ]]; then ABS_DIR=$2 fi -if [ "$3" != "" ]; then +if [[ -n $3 ]]; then SVN_REPO_LOCATION=$3 fi ## # Check config ## -if [ "$ABS_DIR" = "" ]; then - echo "No ABS_DIR specified!" +if [[ -z $ABS_DIR ]]; then + echo 'No ABS_DIR specified!' exit 1 -elif [ ! -d "$ABS_DIR" ]; then - echo "ABS_DIR not a directory." +elif [[ ! -d $ABS_DIR ]]; then + echo 'ABS_DIR not a directory.' exit 1 fi @@ -215,8 +215,8 @@ fi checkout_svn "$CHECKOUT_DIR" || exit 1 extract_abs_tree "$CHECKOUT_DIR" "$TREE_DIR" -if [ "$?" -ne "0" ]; then - echo "Error occurred extracting the abs tree." +if (( $? != 0 )); then + echo 'Error occurred extracting the abs tree.' exit 1 fi @@ -231,9 +231,9 @@ for abs_arch in $(ls); do done cd - -echo "Cleaning up..." -rm -r $TREE_DIR +echo 'Cleaning up...' +rm -r "$TREE_DIR" -echo "Done!" +echo 'Done!' # vim: set ts=2 sw=2 noet: diff --git a/scripts/update-abs.sh b/scripts/update-abs.sh index ff3510e..4e313ff 100644 --- a/scripts/update-abs.sh +++ b/scripts/update-abs.sh @@ -7,8 +7,8 @@ ARCHES=('i686' 'x86_64' 'any') mkdir -p /srv/abs/{checkout,rsync,tree} # clear any "broken" entries from previous ABS tree generation -for server in ${SERVERS[@]}; do - [ -d /srv/abs/tree/$server ] && rm -rf /srv/abs/tree/$server/* +for server in "${SERVERS[@]}"; do + [[ -d "/srv/abs/tree/$server" ]] && rm -rf "/srv/abs/tree/$server"/* done # create ABS trees @@ -16,27 +16,27 @@ done /srv/abs/svn2abs /srv/abs/checkout/sigurd /srv/abs/tree/sigurd file:///srv/svn-community # clean and regenerate ABS rsync folder -for arch in ${ARCHES[@]}; do - if [ ! -d /srv/abs/rsync/$arch ]; then - mkdir /srv/abs/rsync/$arch +for arch in "${ARCHES[@]}"; do + if [[ ! -d "/srv/abs/rsync/$arch" ]]; then + mkdir "/srv/abs/rsync/$arch" else - rm -rf /srv/abs/rsync/$arch/* + rm -rf "/srv/abs/rsync/$arch"/* fi - for server in ${SERVERS[@]}; do - if [ -d /srv/abs/tree/$server/$arch ]; then - mv /srv/abs/tree/$server/$arch/* /srv/abs/rsync/$arch/ + for server in "${SERVERS[@]}"; do + if [[ -d "/srv/abs/tree/$server/$arch" ]]; then + mv "/srv/abs/tree/$server/$arch"/* "/srv/abs/rsync/$arch/" fi done done # generate tarballs for package mirrors for repo in testing core extra community community-testing; do - for arch in ${ARCHES[@]/any/}; do + for arch in "${ARCHES[@]/any/}"; do tarcmd="tar -czf /srv/ftp/${repo}/os/${arch}/${repo}.abs.tar.gz \ -C /srv/abs/rsync/${arch} ${repo}" - if [ -d "/srv/abs/rsync/any/${repo}" ]; then + if [[ -d "/srv/abs/rsync/any/${repo}" ]]; then tarcmd="$tarcmd -C /srv/abs/rsync/any ${repo}" fi -- Sebastien "Seblu" Luttringer
participants (1)
-
Sébastien Luttringer