From 03acea832ad39fa371781f045c39677a02d1156a Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 17 Apr 2012 21:34:30 -0400 Subject: validate bash scripts with 'bash -n' during build. Use the no-exec mode of $(BASH_SHELL) to check for syntax errors in shell scripts. Since we use the extglob feature in various places, this requires that we pass -O extglob to the shell as well, to ensure that the parser is armed to handle this syntax. Signed-off-by: Dave Reisner --- scripts/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/Makefile.am b/scripts/Makefile.am index b8a19900..06e9095e 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -64,6 +64,7 @@ $(OURSCRIPTS): Makefile $(AM_V_at)$(RM) $@ $(AM_V_GEN)test -f $(srcdir)/$@.sh.in && m4 -P -I $(srcdir) $(srcdir)/$@.sh.in | $(edit) >$@ $(AM_V_at)chmod +x,a-w $@ + @$(BASH_SHELL) -O extglob -n $@ makepkg: \ $(srcdir)/makepkg.sh.in \ -- cgit v1.2.3 From 953415c86a17c1db8bebbbaca89e6fd5783386b6 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 22 Apr 2012 17:38:48 -0400 Subject: rankmirrors: move to contrib/ This script is of questionable value, as it ranks mirrors by an uninteresting attribute: ping. While the script itself is interesting, people should be encouraged to rank mirrors by more useful measures, such as actual speed, locality, or up to date-ness. Signed-off-by: Dave Reisner --- scripts/.gitignore | 1 - scripts/Makefile.am | 4 - scripts/rankmirrors.sh.in | 212 ---------------------------------------------- 3 files changed, 217 deletions(-) delete mode 100644 scripts/rankmirrors.sh.in (limited to 'scripts') diff --git a/scripts/.gitignore b/scripts/.gitignore index 21b671c0..9e403bfb 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -3,7 +3,6 @@ pacman-db-upgrade pacman-key pacman-optimize pkgdelta -rankmirrors repo-add repo-elephant repo-remove diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 06e9095e..a1a4f366 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -12,7 +12,6 @@ OURSCRIPTS = \ pacman-key \ pacman-optimize \ pkgdelta \ - rankmirrors \ repo-add EXTRA_DIST = \ @@ -21,7 +20,6 @@ EXTRA_DIST = \ pacman-key.sh.in \ pacman-optimize.sh.in \ pkgdelta.sh.in \ - rankmirrors.sh.in \ repo-add.sh.in \ $(LIBRARY) @@ -87,8 +85,6 @@ pkgdelta: \ $(srcdir)/pkgdelta.sh.in \ $(srcdir)/library/output_format.sh -rankmirrors: $(srcdir)/rankmirrors.sh.in - repo-add: \ $(srcdir)/repo-add.sh.in \ $(srcdir)/library/output_format.sh diff --git a/scripts/rankmirrors.sh.in b/scripts/rankmirrors.sh.in deleted file mode 100644 index 875a1439..00000000 --- a/scripts/rankmirrors.sh.in +++ /dev/null @@ -1,212 +0,0 @@ -#!/bin/bash -# -# rankmirrors - read a list of mirrors from a file and rank them by speed -# @configure_input@ -# -# Copyright (c) 2009 Matthew Bruenig -# -# 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 . - -# 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 @sysconfdir@/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" - echo " -r, --repo specify a specific repo name instead of guessing" - exit 0 -} - -version() { - echo "rankmirrors (pacman) @PACKAGE_VERSION@" - echo "Copyright (c) 2009 Matthew Bruenig ." - 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" >&2 - 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//'$arch'/$ARCH}" - if [[ ! $TARGETREPO ]]; then - replacedurl="${replacedurl//'$repo'/core}" - local tmp="${replacedurl%/*}" - tmp="${tmp%/*}" - - local reponame="${tmp##*/}" - else - replacedurl="${replacedurl//'$repo'/$TARGETREPO}" - local reponame="$TARGETREPO" - fi - - if [[ -z $reponame || $reponame = $replacedurl ]]; then - echo "fail" - else - local fetchurl="${replacedurl}/$reponame.db" - echo "$fetchurl" - fi -} - -# This exists to remove the need for a separate interrupt function -finaloutput() { - IFS=$'\n' read -r -d '' -a sortedarray < \ - <(printf '%s\n' "${timesarray[@]}" | LC_COLLATE=C 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;; - repo) [[ $2 ]] || err "Must specify repo name."; TARGETREPO="$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=( $(