mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

deploy-sieve (985B)


      1 #!/bin/bash
      2 
      3 # Deploy sieve folder $1 to remote location $2 but check it passes tests
      4 
      5 set -e
      6 
      7 SCRIPT="$1/main.sieve"
      8 TESTS="$1/test.dat"
      9 CONFIG="$1/dovecot.conf"
     10 MACHINE="$2"
     11 
     12 grep -v '^#' "$TESTS" | while read test
     13 do
     14   FILE=$(echo "$test" | cut -d' ' -f1)
     15   FOLDER=$(echo "$test" | cut -d' ' -f2)
     16   EXPECTED="store message in folder: $FOLDER"
     17   if sieve-test -c "$CONFIG" "$SCRIPT" "$FILE" 2>&1 |
     18       grep "final result: success" > /dev/null
     19   then
     20     if sieve-test -c "$CONFIG" "$SCRIPT" "$FILE" 2>/dev/null |
     21       grep "$EXPECTED" > /dev/null
     22     then
     23       continue
     24     fi
     25   fi
     26   echo "TEST FAILED for $FILE"
     27   sieve-test -c "$CONFIG" "$SCRIPT" "$FILE"
     28   echo "expected: $EXPECTED"
     29   exit 1
     30 done
     31 
     32 # exit if loop subshell exited
     33 if [[ $? -eq 1 ]]; then
     34   exit 1
     35 fi
     36 
     37 echo "Passed all tests: `wc -l $TESTS`"
     38 
     39 cd "$1"
     40 git commit -m 'update sieve' *.sieve
     41 git push
     42 ssh "$MACHINE" "cd $1; git pull"
     43 ssh "$MACHINE" "sudo service dovecot reload"
     44 echo "sieve deployment successful"
     45 
     46