Browse code

git-sync.sh - v0.1 - Dry run added

Fred authored on13/09/2014 23:51:03
Showing2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,2 +0,0 @@
1
-Add --no-check-certificate option
2
-Don't update file if they are in use (important for script) => maybe make a separate list for scripts
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 0.0
3
+# Version: 0.1
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in:
6
+# Modified in: 2014-09-13
7 7
 # Licence : GPL v3
8 8
 
9 9
 
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from git server (master branch) on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v0.1 - 2014-09-23: dry-run option added / no check certifcate option added for wget
23 24
 # v0.0 - 2014-09-03: creation
24 25
 
25 26
 
... ...
@@ -39,16 +40,18 @@ function test_dep {
39 40
 # Usage message
40 41
 function usage {
41 42
     echo -e "
42
-    \e[32m${0##*/}\e[00m -l|--list list -h|--help
43
+    \e[32m${0##*/}\e[00m -l|--list list -d|--dry-run -h|--help
43 44
 
44 45
 Aim: $aim
45 46
 
46 47
 Options:
47
-    -l, --list      file containing remote path and local path of a file to synchronize.
48
+    -l, --list      File containing remote path and local path of a file to synchronize.
48 49
                     The list file must have a unique path pair per line and each path must
49 50
                     be semi-colon separated. The remote path must be http path.
50 51
 
51
-    -h, --help      this message
52
+    -d, --dry-run   Run the synchronization but print a message instead of updating the files. 
53
+
54
+    -h, --help      This message
52 55
 "
53 56
 }
54 57
 
... ...
@@ -83,9 +86,10 @@ test_dep git
83 86
 while [[ $# -gt 0 ]]
84 87
 do
85 88
     case $1 in
86
-        -l|--list   ) list="$2" ; shift 2 ;;
87
-        -h|--help   ) usage ; exit 0 ;;
88
-        *           ) error "Invalid option: $1\n$(usage)\n" 1 ;;
89
+        -l|--list    ) list="$2" ; shift 2 ;;
90
+        -d|--dry-run ) dry=1 ; shift ;;
91
+        -h|--help    ) usage ; exit 0 ;;
92
+        *            ) error "Invalid option: $1\n$(usage)\n" 1 ;;
89 93
     esac
90 94
 done
91 95
 
... ...
@@ -120,18 +124,23 @@ do
120 124
     mydst_tmp="/tmp/${mydst##*/}"
121 125
 
122 126
     # Download file
123
-    wget -O "$mydst_tmp" "$mysrc"
127
+    wget --no-check-certificate -O "$mydst_tmp" "$mysrc"
124 128
 
125 129
     # Check for errors
126 130
     if [[ $? != 0 ]]
127 131
     then
128
-        warning "${mydst##*/}: An error occur during the downloading. Skipping..."
132
+        warning "${mydst##*/}: An error occured during the downloading. Skipping..."
129 133
         continue
130 134
     else
131 135
         # Compare downloaded file and destination file (update file if need)
132 136
         if [[ $(md5sum "$mydst_tmp") -ne $(md5sum "$mydst") ]]
133 137
         then
134
-            mv "$mydst_tmp" "$mydst"
138
+            if [[ $dry == 1 ]]
139
+            then
140
+                warning "${mydst##*/}: A new version is available."
141
+            else
142
+                mv "$mydst_tmp" "$mydst"
143
+            fi
135 144
         else
136 145
             rm "$mydst_tmp"
137 146
         fi