HosipLan

Untitled

Feb 22nd, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.85 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function rsync_rules () {
  4.     rules=""
  5.     while read path; do
  6.         exclude=0
  7.         if [ "${path:0:1}" == "!" ]; then
  8.             exclude=1
  9.             path=${path:1}
  10.         fi
  11.         if [[ "$path" == *..* ]]; then
  12.             echo "Error: Invalid path $path, skipping"
  13.             continue
  14.         fi
  15.         if [ ! -d "$(pwd)/$path" ]; then
  16.             echo "Warning: File not found $path"
  17.         fi
  18.  
  19.         if [ $exclude == 1 ]; then
  20.             rules="$rules --exclude=\"$path\""
  21.         else
  22.             rules="$rules --include=\"$path\""
  23.         fi
  24.     done < $1
  25. }
  26.  
  27. rsync_rules "$(pwd)/.rsync"
  28.  
  29. echo $rules
  30. . ./test4.sh $rules
  31.  
  32.  
  33. ### output
  34.  
  35. $ ./test3.sh
  36. Warning: File not found app/blabla
  37. --exclude="app/temp" --exclude="app/log" --include="app/temp/cache" --include="app/blabla" --include="app/fucking dir"
  38. test4 6 --exclude="app/temp" --exclude="app/log" --include="app/temp/cache" --include="app/blabla" --include="app/fucking dir"
Advertisement
Add Comment
Please, Sign In to add comment