dev/provisioning/modules/puppi/files/scripts/wait.sh
changeset 28 b0b56e0f8c7f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
       
     1 #!/bin/bash
       
     2 # wait.sh - Made for Puppi
       
     3 
       
     4 # Sources common header for Puppi scripts
       
     5 . $(dirname $0)/header || exit 10
       
     6 
       
     7 # Show help
       
     8 showhelp () {
       
     9     echo "This script is used to introduce pauses during the deploy workflow"
       
    10     echo
       
    11     echo "It has the following options:"
       
    12     echo "-s <seconds> - The number of seconds to wait"
       
    13     echo "-p <filename> - Wait until filename is present"
       
    14     echo "-a <filename> - Wait until filename is absent"
       
    15     echo "-f <pattern> <filename> - Wait until is found the pattern in the filename"
       
    16 }
       
    17 
       
    18 while [ $# -gt 0 ]; do
       
    19   case "$1" in
       
    20     -s)
       
    21       sleep $2
       
    22       exit 0
       
    23       ;;
       
    24     -p)
       
    25       while true
       
    26          do
       
    27             [ -e $2 ] && break
       
    28          sleep 1
       
    29       done
       
    30       exit 0
       
    31       ;;
       
    32     -a)
       
    33       while true
       
    34          do
       
    35             [ ! -e $2 ] && break
       
    36          sleep 1
       
    37       done
       
    38       exit 0
       
    39       ;;
       
    40     -f)
       
    41       while true
       
    42          do
       
    43             grep $2 $3 && break
       
    44          sleep 1
       
    45       done
       
    46       exit 0
       
    47       ;;
       
    48     *)
       
    49       showhelp
       
    50       exit
       
    51       ;;
       
    52   esac
       
    53 done
       
    54