From f59c7cea77737a2ff5e8c14ab42dc8d6a55d693f Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 28 Dec 2009 16:51:33 +0100 Subject: runmirrors, getopts add new option parsing using getopts. keep the old way of just telling it the archive name working Signed-off-by: Joerg Jaspert --- bin/runmirrors | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index a79e33d..3a9d943 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -28,11 +28,69 @@ BASEDIR=${BASEDIR:-"${HOME}"} NAME="`basename $0`" -# In case we are called with an argument we look for a different configuration. -CONF=${1:-""} -if [ -n "${CONF}" ]; then - NAME="${NAME}-${CONF}" +HELP="$0, (C) 2008, 2009 by Joerg Jaspert \n +Usage:\n\n + +1.) a single parameter with NO leading -.\n +\t This will will then be used as the addition for our configfile. Ie. \`$0 security\` will\n +\t have us look for ${NAME}-security.{conf,mirror} files.\n\n + +2.) using getopt style parameters:\n +\t -a [NAME] - Same as 1.) above, used for the config files. Default empty.\n +\t -k [TYPE] - Type of push. all, mhop. Default all.\n +\t -s [STAGE] - Stage of push. stage1, stage2, all. Default all.\n +\t -f - Run from within the mirrorscript ftpsync. Don't use from commandline!\n +\t -h - Print this help and exit +" +# 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 + # Yes, does not start with a -, so use it for the config name. + CONF=${1:-""} + 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} + NAME=${NAME}-${CONF} + ;; + k) PUSHKIND=${OPTARG} + ;; + f) FROMFTPSYNC="true" + ;; + h) echo -e $HELP + exit 0 + ;; + + \?) echo "Unknown option \"-$OPTARG\"." + echo -e $HELP + exit 1 + ;; + :) echo "Option \"-$OPTARG\" needs an argument." + echo -e $HELP + exit 1 + ;; + esac + done + fi fi +# Make sure the values are always defined, even if there was no commandline option +# for them +# Default config is empty +CONF=${CONF:-""} + +# Set the default to all, if we didnt get told about it. Currently +# valid: all - normal push. mhop - multi-hop multi-stage push. Default is all. +# If mhop we will run a normal stage1 push *and then exit*. +PUSHKIND=${PUSHKIND:-"all"} + +# If we are pushed from within ftpsync. Default false. +FROMFTPSYNC=${FROMFTPSYNC:-"false"} # Read our config file . "${BASEDIR}/etc/${NAME}.conf" -- cgit v1.2.3 From 2d67be7b5cefd83acd188f640d7b3a582f8b45ea Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 28 Dec 2009 16:51:57 +0100 Subject: runmirrors add two seperators between initial setup, config values and code. Signed-off-by: Joerg Jaspert --- bin/runmirrors | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 3a9d943..413738f 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -92,6 +92,7 @@ PUSHKIND=${PUSHKIND:-"all"} # If we are pushed from within ftpsync. Default false. FROMFTPSYNC=${FROMFTPSYNC:-"false"} +######################################################################## # Read our config file . "${BASEDIR}/etc/${NAME}.conf" @@ -138,6 +139,8 @@ HOOK1=${HOOK1:-""} HOOK2=${HOOK2:-""} HOOK3=${HOOK3:-""} +######################################################################## + # Some sane defaults cd ${BASEDIR} umask 022 -- cgit v1.2.3 From 2863757b0fb80c151daf8d6e4788ba14495f8b4c Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 28 Dec 2009 22:32:01 +0100 Subject: runmirrors drop the -s Signed-off-by: Joerg Jaspert --- bin/runmirrors | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 413738f..791ee16 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -37,8 +37,7 @@ Usage:\n\n 2.) using getopt style parameters:\n \t -a [NAME] - Same as 1.) above, used for the config files. Default empty.\n -\t -k [TYPE] - Type of push. all, mhop. Default all.\n -\t -s [STAGE] - Stage of push. stage1, stage2, all. Default all.\n +\t -k [TYPE] - Type of push. all, stage2, mhop. Default all.\n \t -f - Run from within the mirrorscript ftpsync. Don't use from commandline!\n \t -h - Print this help and exit " -- cgit v1.2.3 From 05c7958f9f9dd12d5f802d679d69c651699f23b3 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 28 Dec 2009 22:32:48 +0100 Subject: runmirrors only look at mhop/&taged entries if doing mhop push Signed-off-by: Joerg Jaspert --- bin/runmirrors | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 791ee16..23c2e32 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -84,8 +84,8 @@ fi CONF=${CONF:-""} # Set the default to all, if we didnt get told about it. Currently -# valid: all - normal push. mhop - multi-hop multi-stage push. Default is all. -# If mhop we will run a normal stage1 push *and then exit*. +# valid: all - normal push. mhop - multi-hop multi-stage push, this is stage1, +# stage2 - staged push, second phase. Default is all. PUSHKIND=${PUSHKIND:-"all"} # If we are pushed from within ftpsync. Default false. @@ -183,6 +183,14 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do continue fi + # If we are told we have a mhop sync to do, we will only look at staged/mhop + # entries and ignore the rest. + if [ "x${PUSHKIND}x" = "xmhopx" ]; then + if [ "x${MTYPE}x" != "xstagedx" ] || [ "x${MTYPE}x" != "xmhopx" ]; then + continue + fi + fi + # Now, MSSHOPT may start with a -. In that case the whole rest of the line is taken # as a set of options to give to ssh, we pass it without doing anything with it. # If it starts with a 1 or 2 then it will tell us about the ssh protocol version to use, -- cgit v1.2.3 From 49607174263e88a82d16d131bf4ea3cac71d5c91 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 28 Dec 2009 22:33:42 +0100 Subject: runmirrors two new options in the array Signed-off-by: Joerg Jaspert --- bin/runmirrors | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 23c2e32..60471d6 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -231,15 +231,17 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do # Built our array SIGNAL_OPTS=( - MIRROR="${MLNAME}" - HOSTNAME="${MHOSTNAME}" - USERNAME="${MUSER}" - SSHPROTO="${MPROTO}" - SSHKEY="${MKEYFILE}" - SSHOPTS="${SSHOPT/ /#}" - PUSHLOCKOWN="${LOCKDIR}/${MLNAME}.stage1" - PUSHTYPE="${MTYPE}" - PUSHARCHIVE=${PUSHARCHIVE} + MIRROR="${MLNAME}" + HOSTNAME="${MHOSTNAME}" + USERNAME="${MUSER}" + SSHPROTO="${MPROTO}" + SSHKEY="${MKEYFILE}" + SSHOPTS="${SSHOPT/ /#}" + PUSHLOCKOWN="${LOCKDIR}/${MLNAME}.stage1" + PUSHTYPE="${MTYPE}" + PUSHARCHIVE=${PUSHARCHIVE} + PUSHKIND=${PUSHKIND} + FROMFTPSYNC=${FROMFTPSYNC} ) # And finally, push the mirror -- cgit v1.2.3 From 422a8bf4de1a4662268413ee32b8e21e17b77c50 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 28 Dec 2009 22:51:37 +0100 Subject: runmirrors getopts merge \?) and :) into *) Signed-off-by: Joerg Jaspert --- bin/runmirrors | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 60471d6..4a3ef51 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -66,12 +66,8 @@ if [ $# -gt 0 ]; then exit 0 ;; - \?) echo "Unknown option \"-$OPTARG\"." - echo -e $HELP - exit 1 - ;; - :) echo "Option \"-$OPTARG\" needs an argument." - echo -e $HELP + *) echo "Invalid usage" + echo -e $HELP exit 1 ;; esac -- cgit v1.2.3 From a6550370967800a9c365d0ad9b65b3e9553a7e7b Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Tue, 29 Dec 2009 10:36:10 +0100 Subject: set delay to 600 to be what we tell users in our config file would be default Signed-off-by: Joerg Jaspert --- bin/runmirrors | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 4a3ef51..6952228 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -172,7 +172,7 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do if [ "x${MTYPE}x" = "xDELAYx" ]; then # We should wait a bit. if [ -z ${MLNAME} ]; then - MLNAME=60 + MLNAME=600 fi log "Delay of ${MLNAME} requested, sleeping" >> "${LOG}" sleep ${MLNAME} -- cgit v1.2.3 From ffd522df0efa4e480456fddfb3d26d7076c7cfd1 Mon Sep 17 00:00:00 2001 From: Uli Martens Date: Tue, 29 Dec 2009 18:23:14 +0100 Subject: quote some more arguments Signed-off-by: Joerg Jaspert --- bin/runmirrors | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 6952228..92dda78 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -55,10 +55,10 @@ if [ $# -gt 0 ]; then # Yeah well, new style, starting with - for getopts while getopts ':a:k:fh' OPTION ; do case $OPTION in - a) CONF=${OPTARG} - NAME=${NAME}-${CONF} + a) CONF="${OPTARG}" + NAME="${NAME}-${CONF}" ;; - k) PUSHKIND=${OPTARG} + k) PUSHKIND="${OPTARG}" ;; f) FROMFTPSYNC="true" ;; -- cgit v1.2.3 From fa36383caf8b29facb367d291062c15951763c7b Mon Sep 17 00:00:00 2001 From: Uli Martens Date: Tue, 29 Dec 2009 18:25:56 +0100 Subject: fix whitespace indenting to minimize diff Signed-off-by: Joerg Jaspert --- bin/runmirrors | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 92dda78..6fe3d0c 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -227,17 +227,17 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do # Built our array SIGNAL_OPTS=( - MIRROR="${MLNAME}" - HOSTNAME="${MHOSTNAME}" - USERNAME="${MUSER}" - SSHPROTO="${MPROTO}" - SSHKEY="${MKEYFILE}" - SSHOPTS="${SSHOPT/ /#}" - PUSHLOCKOWN="${LOCKDIR}/${MLNAME}.stage1" - PUSHTYPE="${MTYPE}" - PUSHARCHIVE=${PUSHARCHIVE} - PUSHKIND=${PUSHKIND} - FROMFTPSYNC=${FROMFTPSYNC} + MIRROR="${MLNAME}" + HOSTNAME="${MHOSTNAME}" + USERNAME="${MUSER}" + SSHPROTO="${MPROTO}" + SSHKEY="${MKEYFILE}" + SSHOPTS="${SSHOPT/ /#}" + PUSHLOCKOWN="${LOCKDIR}/${MLNAME}.stage1" + PUSHTYPE="${MTYPE}" + PUSHARCHIVE=${PUSHARCHIVE} + PUSHKIND=${PUSHKIND} + FROMFTPSYNC=${FROMFTPSYNC} ) # And finally, push the mirror -- cgit v1.2.3 From 7b011505f809740d5dad18f056723d2d9166bdc9 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Wed, 30 Dec 2009 21:24:43 +0100 Subject: runmirrors update copyright Signed-off-by: Joerg Jaspert --- bin/runmirrors | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 6fe3d0c..a1623fd 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -7,7 +7,7 @@ set -u # Based losely on existing scripts, written by an unknown number of # different people over the years. # -# Copyright (C) 2008 Joerg Jaspert +# Copyright (C) 2008, 2009 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 -- cgit v1.2.3 From bce457d4e1f83d2ce0a80a889cb6462199387c1a Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Thu, 31 Dec 2009 15:11:25 +0100 Subject: runmirrors only add -conf to the name when it has value Signed-off-by: Joerg Jaspert --- bin/runmirrors | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index a1623fd..6d4faed 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -56,7 +56,9 @@ if [ $# -gt 0 ]; then while getopts ':a:k:fh' OPTION ; do case $OPTION in a) CONF="${OPTARG}" - NAME="${NAME}-${CONF}" + if [ -n "${CONF}" ]; then + NAME="${NAME}-${CONF}" + fi ;; k) PUSHKIND="${OPTARG}" ;; -- cgit v1.2.3 From 464b2942c49d25cf9cbc8f76becfa155981bd86b Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Thu, 31 Dec 2009 15:44:23 +0100 Subject: runmirrors default is mhop and use && when checking for things not enabled Signed-off-by: Joerg Jaspert --- bin/runmirrors | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 6d4faed..275f82e 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -37,7 +37,7 @@ Usage:\n\n 2.) using getopt style parameters:\n \t -a [NAME] - Same as 1.) above, used for the config files. Default empty.\n -\t -k [TYPE] - Type of push. all, stage2, mhop. Default all.\n +\t -k [TYPE] - Type of push. all, stage2, mhop. Default mhop.\n \t -f - Run from within the mirrorscript ftpsync. Don't use from commandline!\n \t -h - Print this help and exit " @@ -83,8 +83,8 @@ CONF=${CONF:-""} # Set the default to all, if we didnt get told about it. Currently # valid: all - normal push. mhop - multi-hop multi-stage push, this is stage1, -# stage2 - staged push, second phase. Default is all. -PUSHKIND=${PUSHKIND:-"all"} +# stage2 - staged push, second phase. Default is mhop. +PUSHKIND=${PUSHKIND:-"mhop"} # If we are pushed from within ftpsync. Default false. FROMFTPSYNC=${FROMFTPSYNC:-"false"} @@ -184,7 +184,7 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do # If we are told we have a mhop sync to do, we will only look at staged/mhop # entries and ignore the rest. if [ "x${PUSHKIND}x" = "xmhopx" ]; then - if [ "x${MTYPE}x" != "xstagedx" ] || [ "x${MTYPE}x" != "xmhopx" ]; then + if [ "x${MTYPE}x" != "xstagedx" ] && [ "x${MTYPE}x" != "xmhopx" ]; then continue fi fi -- cgit v1.2.3 From c7ecee0e9700f796ab63388a60095c478952eb82 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Thu, 31 Dec 2009 16:26:36 +0100 Subject: ftpsync, runmirrors fixup calling of runmirrors log more what we are supposed to do Signed-off-by: Joerg Jaspert --- bin/runmirrors | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index 275f82e..e320722 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -148,7 +148,7 @@ mkdir -p "${LOCKDIR}" trap 'log "Mirrorpush done" >> ${LOG}; savelog "${LOG}" > /dev/null' EXIT -log "Pushing leaf mirrors" >> ${LOG} +log "Pushing leaf mirrors. Inside ftpsync: ${FROMFTPSYNC}. Pushkind: ${PUSHKIND}" >> ${LOG} HOOK=( HOOKNR=1 -- cgit v1.2.3 From f190bba422623faf981d793830867e16c6c6fe97 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Thu, 31 Dec 2009 16:36:51 +0100 Subject: runmirrors only skip non-mhop/staged entries if we are called from within ftpsync. When we are called outside, ie. starting the mirror run, we do have to push everything and can not skip. Signed-off-by: Joerg Jaspert --- bin/runmirrors | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin/runmirrors') diff --git a/bin/runmirrors b/bin/runmirrors index e320722..752e351 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -181,9 +181,9 @@ while read MTYPE MLNAME MHOSTNAME MUSER MSSHOPT; do continue fi - # If we are told we have a mhop sync to do, we will only look at staged/mhop - # entries and ignore the rest. - if [ "x${PUSHKIND}x" = "xmhopx" ]; then + # 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 continue fi -- cgit v1.2.3