Debian Codegraph @

src/grsync-batch

raw
1 #!/bin/bash
2
3 while [ "`echo $1 | head -c 1`" == "-" ]; do
4 if [ "$1" == "-d" ]; then
5 DRYRUN=true
6 shift
7 continue
8 fi
9 if [ "$1" == "-f" ]; then
10 FROMFILE=true
11 shift
12 continue
13 fi
14 echo "Unknown option"
15 exit 1
16 done
17
18 SESSION=$1
19 if [ "$SESSION" == "" ]; then
20 echo "Grsync batch session runner ver 1.3.1"
21 echo "Comes under the GPL v2 - Copyright 2007->2012 Piero Orsoni ([email protected])"
22 echo "This script is part of the grsync program, see www.opbyte.it for more information"
23 echo
24 echo "Usage: grsync-batch [-d] [-f] <session (or filename for -f)>"
25 echo " -d dry-run, simulate, do not really execute"
26 echo " -f read session from filename instead of the default configuration file"
27 exit 2
28 fi
29
30 if [ "$FROMFILE" == "" ]; then
31 # SESSCONF=`echo "\`cat ~/.grsync/grsync.ini\`\[" | grep -A999 "\[$SESSION\]" | tail -n +2 | grep -m 1 -B999 "\[" | head -n -2`
32 SESSCONF=`echo -e "\`cat ~/.grsync/grsync.ini\`\n\n\[" | grep -A999 "\[$SESSION\]" | tail -n +2 | grep -m 1 -B999 "^$"`
33 if [ "$SESSCONF" == "" ]; then
34 echo "Session not found in config file"
35 exit 3
36 fi
37 else
38 SESSCONF=`cat $SESSION | grep -A999 "\[" | tail -n +2`
39 if [ "$SESSCONF" == "" ]; then
40 echo "File not found or empty"
41 exit 4
42 fi
43 fi
44
45
46 # CONFIG=`cat ~/.grsync/grsync.ini | grep -A999 "\[__CONFIG\]" | tail -n +2 | grep -m 1 -B999 "\[" | head -n -2`
47 CONFIG=`cat ~/.grsync/grsync.ini | grep -A999 "\[__CONFIG\]" | tail -n +2 | grep -m 1 -B999 "^$"`
48 eval `echo -e "$SESSCONF\n$CONFIG" | sed s/=/=\"/ | sed s/\$/\"/`
49
50 if [ "$is_set" == "true" ]; then
51 echo "Session sets not yet supported"
52 exit 5
53 fi
54
55 OPTIONS="$text_addit"
56 if [ "$check_norecur" == "true" ]; then OPTIONS="-d $OPTIONS"; else OPTIONS="-r $OPTIONS"; fi
57 if [ "$DRYRUN" == "true" ]; then OPTIONS="-n $OPTIONS"; fi
58 if [ "$check_time" == "true" ]; then OPTIONS="-t $OPTIONS"; fi
59 if [ "$check_perm" == "true" ]; then OPTIONS="-p $OPTIONS"; fi
60 if [ "$check_owner" == "true" ]; then OPTIONS="-o $OPTIONS"; fi
61 if [ "$check_group" == "true" ]; then OPTIONS="-g $OPTIONS"; fi
62 if [ "$check_onefs" == "true" ]; then OPTIONS="-x $OPTIONS"; fi
63 if [ "$check_verbose" == "true" ]; then OPTIONS="-v $OPTIONS"; fi
64 if [ "$check_progr" == "true" ]; then OPTIONS="--progress $OPTIONS"; fi
65 if [ "$check_delete" == "true" ]; then OPTIONS="--delete $OPTIONS"; fi
66 if [ "$check_exist" == "true" ]; then OPTIONS="--ignore-existing $OPTIONS"; fi
67 if [ "$check_size" == "true" ]; then OPTIONS="--size-only $OPTIONS"; fi
68 if [ "$check_sum" == "true" ]; then OPTIONS="-c $OPTIONS"; fi
69 if [ "$check_symlink" == "true" ]; then OPTIONS="-l $OPTIONS"; fi
70 if [ "$check_hardlink" == "true" ]; then OPTIONS="-H $OPTIONS"; fi
71 if [ "$check_dev" == "true" ]; then OPTIONS="-D $OPTIONS"; fi
72 if [ "$check_update" == "true" ]; then OPTIONS="--existing $OPTIONS"; fi
73 if [ "$check_keepart" == "true" ]; then OPTIONS="-P $OPTIONS"; fi
74 if [ "$check_mapuser" == "true" ]; then OPTIONS="--numeric-ids $OPTIONS"; fi
75 if [ "$check_compr" == "true" ]; then OPTIONS="-z $OPTIONS"; fi
76 if [ "$check_backup" == "true" ]; then OPTIONS="-b $OPTIONS"; fi
77 if [ "$check_skipnew" == "true" ]; then OPTIONS="-u $OPTIONS"; fi
78 if [ "$check_windows" == "true" ]; then OPTIONS="--modify-window=1 $OPTIONS"; fi
79 if [ "$check_itemized" == "true" ]; then OPTIONS="-i $OPTIONS"; fi
80 if [ "$check_protectargs" == "true" ]; then OPTIONS="-s $OPTIONS"; fi
81
82 if [ "$check_com_before" == "true" ]; then
83 echo "*** Executing $text_com_before"
84 $text_com_before || [ "$check_com_halt" != "true" ] || exit
85 echo
86 fi
87
88 COMMAND="$command $OPTIONS "
89 echo "*** Executing $COMMAND\"$text_source\" \"$text_dest\""
90 $COMMAND "$text_source" "$text_dest"
91
92 if [ "$check_com_after" == "true" ]; then
93 echo
94 echo "*** Executing $text_com_after"
95 $text_com_after
96 fi