From 3adcb19f8d9ddee67c2e2404de198fdeb39e2581 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Thu, 7 Jan 2016 23:27:30 +0100 Subject: One more style cleanup --- bin/runmirrors | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/bin/runmirrors b/bin/runmirrors index a84c27b..6f670c4 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -1,13 +1,10 @@ #! /bin/bash -set -e -set -u - # runmirrors script for Debian # Based losely on existing scripts, written by an unknown number of # different people over the years. # -# Copyright (C) 2008, 2009 Joerg Jaspert +# Copyright (C) 2008-2016 Joerg Jaspert # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -22,13 +19,16 @@ set -u # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +set -e +set -u + # In case the admin somehow wants to have this script located someplace else, # he can set BASEDIR, and we will take that. If it is unset we take ${HOME} BASEDIR=${BASEDIR:-"${HOME}"} NAME="$(basename $0)" -HELP="$0, (C) 2008, 2009 by Joerg Jaspert \n +HELP="$0\n Usage:\n\n 1.) a single parameter with NO leading -.\n @@ -44,27 +44,27 @@ Usage:\n\n # If we got options, lets see if we use newstyle options, or oldstyle. If oldstyle # it will not start with a -. If we find oldstyle we assume its only one, the config # name we run on. -if [ $# -gt 0 ]; then - if [ "x${1:0:1}x" != "x-x" ]; then +if [[ $# -gt 0 ]]; then + if [[ ${1:0:1} != - ]]; then # Yes, does not start with a -, so use it for the config name. CONF=${1:-""} - if [ -n "${CONF}" ]; then + if [[ -n ${CONF} ]]; then NAME="${NAME}-${CONF}" fi else # Yeah well, new style, starting with - for getopts while getopts ':a:k:fh' OPTION ; do case $OPTION in - a) CONF="${OPTARG}" - if [ -n "${CONF}" ]; then + a) CONF="${OPTARG}" + if [[ -n ${CONF} ]]; then NAME="${NAME}-${CONF}" fi ;; - k) PUSHKIND="${OPTARG}" + k) PUSHKIND="${OPTARG}" ;; - f) FROMFTPSYNC="true" + f) FROMFTPSYNC="true" ;; - h) echo -e $HELP + h) echo -e $HELP exit 0 ;; @@ -122,7 +122,7 @@ KEYFILE=${KEYFILE:-".ssh/pushmirror"} savelog "${LOG}" > /dev/null # where to send mails to -if [ "x$(hostname -d)x" != "xdebian.orgx" ]; then +if [[ $(hostname -d) != debian.org ]]; then # We are not on a debian.org host MAILTO=${MAILTO:-"root"} else @@ -130,7 +130,7 @@ else MAILTO=${MAILTO:-"mirrorlogs@debian.org"} fi -if ! [ -f "${BASEDIR}/${KEYFILE}" ]; then +if ! [[ -f ${BASEDIR}/${KEYFILE} ]]; then error "SSH Key ${BASEDIR}/${KEYFILE} does not exist" >> "${LOG}" exit 5 fi @@ -175,7 +175,7 @@ rm -f "${LOCKDIR}/all_stage1" # We use grep to easily sort out all lines having a # in front of them or are empty. egrep -v '^[[:space:]]*(#|$)' "${MIRRORS}" | while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do - if [ "x${MTYPE}x" = "xDELAYx" ]; then + if [[ ${MTYPE} = DELAY ]]; then # We should wait a bit. if [ -z ${MLNAME} ]; then MLNAME=600 @@ -187,8 +187,8 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do # If we are told we have a mhop sync to do and are called from within ftpsync, # we will only look at staged/mhop entries and ignore the rest. - if [ "x${PUSHKIND}x" = "xmhopx" ] && [ "x${FROMFTPSYNC}x" = "xtruex" ]; then - if [ "x${MTYPE}x" != "xstagedx" ] && [ "x${MTYPE}x" != "xmhopx" ]; then + if [[ ${PUSHKIND} = mhop ]] && [[ ${FROMFTPSYNC} = true ]]; then + if [[ ${MTYPE} != staged ]] && [[ ${MTYPE} != mhop ]]; then continue fi fi @@ -208,15 +208,15 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do # # The only sane way to go around this, i think, is by dropping backward compability. # Which I don't really like. - if [ -n "${MSSHOPT}" ]; then + if [[ -n ${MSSHOPT} ]]; then # So its not empty, lets check if it starts with a - and as such is a "new-style" # ssh options set. - if [ "x${MSSHOPT:0:1}x" = "x-x" ]; then + if [[ ${MSSHOPT:0:1} = - ]]; then # Yes we start with a - SSHOPT="${MSSHOPT}" MPROTO="99" MKEYFILE="${BASEDIR}/${KEYFILE}" - elif [ ${MSSHOPT:0:1} -eq 1 ] || [ ${MSSHOPT:0:1} -eq 2 ]; then + elif [[ ${MSSHOPT:0:1} -eq 1 ]] || [[ ${MSSHOPT:0:1} -eq 2 ]]; then # We do seem to have oldstyle options here. MPROTO=${MSSHOPT:0:1} MKEYFILE=${MSSHOPT:2} @@ -265,18 +265,18 @@ done # As the signal routine touches $LOCKDIR/all_stage1 when all are done, its # easy enough just to wait for that to appear. Of course we do the same game # with PUSHDELAY to not wait forever. -if [ "xtruex" = "x${FROMFTPSYNC}x" ] && [ "xmhopx" = "x${PUSHKIND}x" ]; then +if [[ true = ${FROMFTPSYNC} ]] && [[ mhop = ${PUSHKIND} ]]; then tries=0 # We do not wait forever - while [ ${tries} -lt ${PUSHDELAY} ]; do - if [ -f "${LOCKDIR}/all_stage1" ]; then + while [[ ${tries} -lt ${PUSHDELAY} ]]; do + if [[ -f ${LOCKDIR}/all_stage1 ]]; then break fi - tries=$((tries + 5)) + tries=$(( tries + 5 )) sleep 5 done - if [ ${tries} -ge ${PUSHDELAY} ]; then + if [[ ${tries} -ge ${PUSHDELAY} ]]; then error "Failed to wait for our mirrors when sending mhop push down." >> "${LOG}" fi fi -- cgit v1.2.3