From 3cc60964994fd618998e92acc039aedd19d0b680 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Wed, 6 Jan 2016 23:35:47 +0100 Subject: Style ([ -> [[) --- etc/common | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/etc/common b/etc/common index 21be610..fd4cebb 100644 --- a/etc/common +++ b/etc/common @@ -51,26 +51,27 @@ signal () { SSH_OPTIONS="-o user=${USERNAME} -o BatchMode=yes -o ServerAliveInterval=45 -o ConnectTimeout=45 -o PasswordAuthentication=no" # If there are userdefined ssh options, add them. - if [ -n "${SSH_OPTS}" ]; then + if [[ -n ${SSH_OPTS} ]]; then SSH_OPTIONS="${SSH_OPTIONS} ${SSH_OPTS}" fi # Does this machine need a special key? - if [ -n "${SSHKEY}" ]; then + if [[ -n ${SSHKEY} ]]; then SSH_OPTIONS="${SSH_OPTIONS} -i ${SSHKEY}" fi # Does this machine have an extra own set of ssh options? - if [ -n "${SSHOPTS}" ]; then + if [[ -n ${SSHOPTS} ]]; then SSH_OPTIONS="${SSH_OPTIONS} ${SSHOPTS}" fi # Set the protocol version - if [ ${SSHPROTO} -ne 1 ] && [ ${SSHPROTO} -ne 2 ] && [ ${SSHPROTO} -ne 99 ]; then + if [[ ${SSHPROTO} -ne 1 ]] && [[ ${SSHPROTO} -ne 2 ]] && [[ ${SSHPROTO} -ne 99 ]]; then # Idiots, we only want 1 or 2. Cant decide? Lets force 2. SSHPROTO=2 fi - if [ -n "${SSHPROTO}" ] && [ ${SSHPROTO} -ne 99 ]; then + + if [[ -n ${SSHPROTO} ]] && [[ ${SSHPROTO} -ne 99 ]]; then SSH_OPTIONS="${SSH_OPTIONS} -${SSHPROTO}" fi @@ -83,34 +84,34 @@ signal () { PUSHARGS="${PUSHARGS} sync:archive:${PUSHARCHIVE}" # We have a callback wish, tell downstreams - if [ -n "${PUSHCB}" ]; then + if [[ -n ${PUSHCB} ]]; then PUSHARGS="${PUSHARGS} sync:callback" fi # If we are running an mhop push AND our downstream is one to receive it, tell it. - if [ "xmhopx" = "x${PUSHKIND}x" ] && [ "xmhopx" = "x${PUSHTYPE}x" ]; then + if [[ mhop = ${PUSHKIND} ]] && [[ mhop = ${PUSHTYPE} ]]; then PUSHARGS="${PUSHARGS} sync:mhop" fi - if [ "xallx" = "x${PUSHTYPE}x" ]; then + if [[ all = ${PUSHTYPE} ]]; then # Default normal "fire and forget" push. We background that, we do not care about the mirrors doings log "Sending normal push" >> "${LOGDIR}/${MIRROR}.log" PUSHARGS1="sync:all" ssh -n $SSH_OPTIONS "${HOSTNAME}" "${PUSHARGS} ${PUSHARGS1}" >>"${LOGDIR}/${MIRROR}.log" 2>&1 - if [ $? -eq 255 ]; then + if [[ $? -eq 255 ]]; then error "Trigger to ${HOSTNAME} failed" >> "${LOG}" else log "Trigger to ${HOSTNAME} succeed" >> "${LOG}" fi - elif [ "xstagedx" = "x${PUSHTYPE}x" ] || [ "xmhopx" = "x${PUSHTYPE}x" ]; then + elif [[ staged = ${PUSHTYPE} ]] || [[ mhop = ${PUSHTYPE} ]]; then # Want a staged push. Fine, lets do that. Not backgrounded. We care about the mirrors doings. log "Sending staged push" >> "${LOGDIR}/${MIRROR}.log" # Only send stage1 if we havent already send it. When called with stage2, we already did. - if [ "xstage2x" != "x${PUSHKIND}x" ]; then + if [[ stage2 != ${PUSHKIND} ]]; then # Step1: Do a push to only sync stage1, do not background PUSHARGS1="sync:stage1" ssh $SSH_OPTIONS "${HOSTNAME}" "${PUSHARGS} ${PUSHARGS1}" >>"${LOGDIR}/${MIRROR}.log" 2>&1 - if [ $? -eq 255 ]; then + if [[ $? -eq 255 ]]; then error "Trigger to ${HOSTNAME} failed" >> "${LOG}" else log "Trigger to ${HOSTNAME} succeed" >> "${LOG}" @@ -120,29 +121,29 @@ signal () { # Step2: Wait for all the other "lock"files to appear. tries=0 # We do not wait forever - while [ ${tries} -lt ${PUSHDELAY} ]; do + while [[ ${tries} -lt ${PUSHDELAY} ]]; do total=0 found=0 for file in ${PUSHLOCKS}; do - total=$((total + 1)) - if [ -f ${file} ]; then - found=$((found + 1)) + total=$(( total + 1 )) + if [[ -f ${file} ]]; then + found=$(( found + 1 )) fi done - if [ ${total} -eq ${found} ] || [ -f "${LOCKDIR}/all_stage1" ]; then + if [[ ${total} -eq ${found} ]] || [[ -f ${LOCKDIR}/all_stage1 ]]; then touch "${LOCKDIR}/all_stage1" break fi - tries=$((tries + 5)) + tries=$(( tries + 5 )) sleep 5 done # In case we did not have all PUSHLOCKS and still continued, note it # This is a little racy, especially if the other parts decide to do this # at the same time, but it wont hurt more than a mail too much, so I don't care much - if [ ${tries} -ge ${PUSHDELAY} ]; then + if [[ ${tries} -ge ${PUSHDELAY} ]]; then log "Failed to wait for all other mirrors. Failed ones are:" >> "${LOGDIR}/${MIRROR}.log" for file in ${PUSHLOCKS}; do - if [ ! -f ${file} ]; then + if [[ ! -f ${file} ]]; then log "${file}" >> "${LOGDIR}/${MIRROR}.log" error "Missing Pushlockfile ${file} after waiting ${tries} second, continuing" fi @@ -157,13 +158,13 @@ signal () { # stage1. It can then finish its own, and if all our upstreams downlinks are done, # it will send us stage2. # If we are not doing mhop or are not called from ftpsync, we start stage2 - if [ "xtruex" = "x${FROMFTPSYNC}x" ] && [ "xmhopx" = "x${PUSHKIND}x" ]; then + if [[ true = ${FROMFTPSYNC} ]] && [[ mhop = ${PUSHKIND} ]]; then return else PUSHARGS2="sync:stage2" log "Now doing the second stage push" >> "${LOGDIR}/${MIRROR}.log" ssh $SSH_OPTIONS "${HOSTNAME}" "${PUSHARGS} ${PUSHARGS2}" >>"${LOGDIR}/${MIRROR}.log" 2>&1 - if [ $? -eq 255 ]; then + if [[ $? -eq 255 ]]; then error "Trigger to ${HOSTNAME} failed" >> "${LOG}" else log "Trigger to ${HOSTNAME} succeed" >> "${LOG}" @@ -186,7 +187,7 @@ callback () { # # Set $PROGRAM to a string to have it added to the output. log () { - if [ -z "${PROGRAM}" ]; then + if [[ -z "${PROGRAM}" ]]; then echo "$(date +"%b %d %H:%M:%S") $(hostname -s) [$$] $@" else echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${PROGRAM}[$$]: $@" @@ -197,7 +198,7 @@ log () { # to the address configured in MAILTO (if non-empty) error () { log "$@" - if [ -n "${MAILTO}" ]; then + if [[ -n "${MAILTO}" ]]; then echo "$@" | mail -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO} fi } @@ -208,13 +209,13 @@ error () { hook () { ARGS='HOOK[@]' local "${!ARGS}" - if [ -n "${HOOKSCR}" ]; then + if [[ -n ${HOOKSCR} ]]; then log "Running hook $HOOKNR: ${HOOKSCR}" set +e ${HOOKSCR} result=$? set -e - if [ ${result} -ne 0 ] ; then + if [[ ${result} -ne 0 ]] ; then error "Back from hook $HOOKNR, got returncode ${result}" else log "Back from hook $HOOKNR, got returncode ${result}" @@ -239,14 +240,14 @@ get2stage() { savelog() { torotate="$1" count=${2:-${LOGROTATE}} - while [ ${count} -gt 0 ]; do + while [[ ${count} -gt 0 ]]; do prev=$(( count - 1 )) - if [ -e "${torotate}.${prev}" ]; then + if [[ -e ${torotate}.${prev} ]]; then mv "${torotate}.${prev}" "${torotate}.${count}" fi count=$prev done - if [ -e "${torotate}" ]; then + if [[ -e ${torotate} ]]; then mv "${torotate}" "${torotate}.0" fi } -- cgit v1.2.3