Browse code

git-sync.sh - v2.3 - remove steps added and chmod step improved

For more details, see version section of the script.

Fred authored on17/01/2016 23:08:52
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 2.2
4
-# Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
3
+# Version: 2.3
4
+# Author: Frédéric CHEVALIER <fcheval@txbiomed.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2016-01-07
6
+# Modified in: 2016-01-17
7 7
 # Licence: GPL v3
8 8
 
9 9
 
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from a git server on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v2.3 - 2016-01-17: email address updated / version in usage message / temporary files removed after downloading if present but error or after dry-run / "a" included in the list of checked letter for chmod
23 24
 # v2.2 - 2016-01-07: process of list file improved (tmp list not needed anymore) / Timestamp added to the downloaded file to avoid interference with several script instance running at the same time
24 25
 # v2.1 - 2015-03-12: evaluation of the variables created from the list in order to use environment variables (ie, $HOME) / directoy checked instead of created otherwise may lead to unwanted path if error in list file / usage message updated
25 26
 # v2.0 - 2015-02-27: error function improved / info function added / file installed and directory created if not already present / modification of file permission can be specified in the file list and apply to the file
... ...
@@ -30,6 +31,8 @@ aim="Synchronize files from a git server on this terminal."
30 31
 # v0.1 - 2014-09-23: dry-run option added / no check certifcate option added for wget
31 32
 # v0.0 - 2014-09-03: creation
32 33
 
34
+version=$(grep -i -m 1 "version" "$0" | cut -d ":" -f 2 | sed "s/ *//")
35
+
33 36
 
34 37
 
35 38
 #===========#
... ...
@@ -52,6 +55,8 @@ function usage {
52 55
 
53 56
 Aim: $aim
54 57
 
58
+Version: $version
59
+
55 60
 Options:
56 61
     -l, --list      Text file containing both remote and local path of
57 62
                     a given file for synchronization.
... ...
@@ -159,11 +164,7 @@ fi
159 164
 while read line
160 165
 do
161 166
 
162
-<<<<<<< HEAD
163
-    # Remove comments from list file
164
-=======
165 167
     # Remove comments from line
166
->>>>>>> git-sync.sh
167 168
     line=$(echo "$line" | sed "/^\s*#/d;s/\s*#.*$//")
168 169
     
169 170
     # Skip if empty line
... ...
@@ -205,6 +206,7 @@ do
205 206
     if [[ $? != 0 ]]
206 207
     then
207 208
         warning "${mydst##*/}: An error occured during the downloading. Skipping..."
209
+        [[ -f "$mydst_tmp" ]] && rm "$mydst_tmp"
208 210
         continue
209 211
     # Check if destination file exists
210 212
     elif [[ ! -e "$mydst" ]]
... ...
@@ -225,6 +227,7 @@ do
225 227
             if [[ $dry == 1 ]]
226 228
             then
227 229
                 info "${mydst##*/}: new version available."
230
+                rm "$mydst_tmp"
228 231
             else
229 232
                 mv "$mydst_tmp" "$mydst"
230 233
                 info "${mydst##*/} updated."
... ...
@@ -234,10 +237,10 @@ do
234 237
         fi
235 238
     fi
236 239
 
237
-    if [[ -z $dry && -n "$mymod" && -n $(echo "$mymod" | sed -n "/[u,o,g,][+,-][r,w,x,s,t,S,T]/p") ]]
240
+    if [[ -z $dry && -n "$mymod" && -n $(echo "$mymod" | sed -n "/[a,u,o,g,][+,-][r,w,x,s,t,S,T]/p") ]]
238 241
     then
239 242
         chmod "$mymod" "$mydst"
240
-    elif [[ -z $dry && -n "$mymod" && -z $(echo "$mymod" | sed -n "/[u,o,g,][+,-][r,w,x,s,t,S,T]/p") ]]
243
+    elif [[ -z $dry && -n "$mymod" && -z $(echo "$mymod" | sed -n "/[a,u,o,g,][+,-][r,w,x,s,t,S,T]/p") ]]
241 244
     then
242 245
         warning "${mydst##*/}: Impossible to change permission, \"$mymod\" does not follow the syntax of the chmod command (see help)."
243 246
         continue
Browse code

Merge branch 'git-sync.sh'

Conflicts:
git-sync.sh

Fred authored on07/01/2016 23:01:45
Showing0 changed files
Browse code

git-sync.sh - v2.2 - List processing improved and timestamp added

For more details, see version section of the script.

Fred authored on07/01/2016 22:57:20
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 2.1
3
+# Version: 2.2
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2015-03-12
6
+# Modified in: 2016-01-07
7 7
 # Licence: GPL v3
8 8
 
9 9
 
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from a git server on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v2.2 - 2016-01-07: process of list file improved (tmp list not needed anymore) / Timestamp added to the downloaded file to avoid interference with several script instance running at the same time
23 24
 # v2.1 - 2015-03-12: evaluation of the variables created from the list in order to use environment variables (ie, $HOME) / directoy checked instead of created otherwise may lead to unwanted path if error in list file / usage message updated
24 25
 # v2.0 - 2015-02-27: error function improved / info function added / file installed and directory created if not already present / modification of file permission can be specified in the file list and apply to the file
25 26
 # v1.3 - 2014-12-04: warning and error functions improved
... ...
@@ -137,9 +138,9 @@ then
137 138
     error "The option -l is required. Exiting...\n$(usage)\n" 1
138 139
 fi
139 140
 
140
-# Temporary list
141
-mydate=$(date +%N)
142
-tmp_list="/tmp/$(basename $list)-$mydate"
141
+
142
+# Timestamp
143
+myts=$(date +%N)
143 144
 
144 145
 
145 146
 
... ...
@@ -154,21 +155,25 @@ then
154 155
 fi
155 156
 
156 157
 
157
-# Remove comments from list file
158
-sed "/^\s*#/d;s/\s*#.*$//" "$list" > "$tmp_list"
159
-sed -i "/^$/d" "$tmp_list"
160
-
161
-
162 158
 # Synchronization
163 159
 while read line
164 160
 do
165 161
 
162
+    # Remove comments from line
163
+    line=$(echo "$line" | sed "/^\s*#/d;s/\s*#.*$//")
164
+    
165
+    # Skip if empty line
166
+    if [[ -z "$line" ]]
167
+    then 
168
+        continue
169
+    fi
170
+
166 171
     # Get paths
167 172
     eval mysrc=$(echo "$line" | cut -d ";" -f 1 | sed -e "s/^ *//" -e "s/ *$//")
168 173
     eval mydst=$(echo "$line" | cut -d ";" -f 2 | sed -e "s/^ *//" -e "s/ *$//")
169 174
     eval mymod=$(echo "$line" | cut -d ";" -f 3 | sed -e "s/^ *//" -e "s/ *$//")
170 175
 
171
-    mydst_tmp="/tmp/${mydst##*/}"
176
+    mydst_tmp="/tmp/${mydst##*/}-$myts"
172 177
 
173 178
 
174 179
     # Check if mydst variable is empty or contain directory
... ...
@@ -234,11 +239,7 @@ do
234 239
         continue
235 240
     fi
236 241
 
237
-done < "$tmp_list"
238
-
239
-
240
-# Remove temporary list
241
-rm "$tmp_list"
242
+done < "$list"
242 243
 
243 244
 
244 245
 exit 0
Browse code

git-sync.sh - v2.1 - List processing improved and timestamp added

For more details, see version section of the script.

Fred authored on07/01/2016 22:51:55
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 2.1
3
+# Version: 2.2
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2015-03-12
6
+# Modified in: 2016-01-07
7 7
 # Licence: GPL v3
8 8
 
9 9
 
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from a git server on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v2.2 - 2016-01-07: process of list file improved (tmp list not needed anymore) / Timestamp added to the downloaded file to avoid interference with several script instance running at the same time
23 24
 # v2.1 - 2015-03-12: evaluation of the variables created from the list in order to use environment variables (ie, $HOME) / directoy checked instead of created otherwise may lead to unwanted path if error in list file / usage message updated
24 25
 # v2.0 - 2015-02-27: error function improved / info function added / file installed and directory created if not already present / modification of file permission can be specified in the file list and apply to the file
25 26
 # v1.3 - 2014-12-04: warning and error functions improved
... ...
@@ -137,9 +138,9 @@ then
137 138
     error "The option -l is required. Exiting...\n$(usage)\n" 1
138 139
 fi
139 140
 
140
-# Temporary list
141
-mydate=$(date +%N)
142
-tmp_list="/tmp/$(basename $list)-$mydate"
141
+
142
+# Timestamp
143
+myts=$(date +%N)
143 144
 
144 145
 
145 146
 
... ...
@@ -154,21 +155,25 @@ then
154 155
 fi
155 156
 
156 157
 
157
-# Remove comments from list file
158
-sed "/^\s*#/d;s/\s*#.*$//" "$list" > "$tmp_list"
159
-sed -i "/^$/d" "$tmp_list"
160
-
161
-
162 158
 # Synchronization
163 159
 while read line
164 160
 do
165 161
 
162
+    # Remove comments from list file
163
+    line=$(echo "$line" | sed "/^\s*#/d;s/\s*#.*$//")
164
+    
165
+    # Skip if empty line
166
+    if [[ -z "$line" ]]
167
+    then 
168
+        continue
169
+    fi
170
+
166 171
     # Get paths
167 172
     eval mysrc=$(echo "$line" | cut -d ";" -f 1 | sed -e "s/^ *//" -e "s/ *$//")
168 173
     eval mydst=$(echo "$line" | cut -d ";" -f 2 | sed -e "s/^ *//" -e "s/ *$//")
169 174
     eval mymod=$(echo "$line" | cut -d ";" -f 3 | sed -e "s/^ *//" -e "s/ *$//")
170 175
 
171
-    mydst_tmp="/tmp/${mydst##*/}"
176
+    mydst_tmp="/tmp/${mydst##*/}-$myts"
172 177
 
173 178
 
174 179
     # Check if mydst variable is empty or contain directory
... ...
@@ -234,11 +239,7 @@ do
234 239
         continue
235 240
     fi
236 241
 
237
-done < "$tmp_list"
238
-
239
-
240
-# Remove temporary list
241
-rm "$tmp_list"
242
+done < "$list"
242 243
 
243 244
 
244 245
 exit 0
Browse code

git-sync.sh - v2.1 - Eval added and small updates

For more details, see version section of the script.

Fred authored on12/03/2015 23:46:56
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 2.0
3
+# Version: 2.1
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2015-02-27
6
+# Modified in: 2015-03-12
7 7
 # Licence: GPL v3
8 8
 
9 9
 
... ...
@@ -12,7 +12,7 @@
12 12
 # Aims #
13 13
 #======#
14 14
 
15
-aim="Synchronize files from git server (master branch) on this terminal."
15
+aim="Synchronize files from a git server on this terminal."
16 16
 
17 17
 
18 18
 
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from git server (master branch) on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v2.1 - 2015-03-12: evaluation of the variables created from the list in order to use environment variables (ie, $HOME) / directoy checked instead of created otherwise may lead to unwanted path if error in list file / usage message updated
23 24
 # v2.0 - 2015-02-27: error function improved / info function added / file installed and directory created if not already present / modification of file permission can be specified in the file list and apply to the file
24 25
 # v1.3 - 2014-12-04: warning and error functions improved
25 26
 # v1.2 - 2014-09-24: temp file bug corrected / check if local file exist
... ...
@@ -46,7 +47,7 @@ function test_dep {
46 47
 # Usage message
47 48
 function usage {
48 49
     echo -e "
49
-    \e[32m${0##*/}\e[00m -l|--list list -d|--dry-run -h|--help
50
+    \e[32m${0##*/}\e[00m -l|--list file -d|--dry-run -h|--help
50 51
 
51 52
 Aim: $aim
52 53
 
... ...
@@ -163,9 +164,9 @@ while read line
163 164
 do
164 165
 
165 166
     # Get paths
166
-    mysrc=$(echo "$line" | cut -d ";" -f 1 | sed -e "s/^ *//" -e "s/ *$//")
167
-    mydst=$(echo "$line" | cut -d ";" -f 2 | sed -e "s/^ *//" -e "s/ *$//")
168
-    mymod=$(echo "$line" | cut -d ";" -f 3 | sed -e "s/^ *//" -e "s/ *$//")
167
+    eval mysrc=$(echo "$line" | cut -d ";" -f 1 | sed -e "s/^ *//" -e "s/ *$//")
168
+    eval mydst=$(echo "$line" | cut -d ";" -f 2 | sed -e "s/^ *//" -e "s/ *$//")
169
+    eval mymod=$(echo "$line" | cut -d ";" -f 3 | sed -e "s/^ *//" -e "s/ *$//")
169 170
 
170 171
     mydst_tmp="/tmp/${mydst##*/}"
171 172
 
... ...
@@ -177,8 +178,8 @@ do
177 178
         continue
178 179
     elif [[ $(echo "$mydst" | grep "/") && ! -d "${mydst%/*}" ]]
179 180
     then
180
-        info "${mydst##*/}: ${mydst%/*} directory created."
181
-        mkdir "${mydst%/*}"
181
+        warning "${mydst##*/}: ${mydst%/*} directory does not exist. Skipping..."
182
+        continue
182 183
     fi
183 184
 
184 185
     # Check if remote path is http
Browse code

git-sync.sh - v2.0 - Several functions added (see version section)

Fred authored on28/02/2015 23:30:41
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 1.3
3
+# Version: 2.0
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2014-12-04
6
+# Modified in: 2015-02-27
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
+# v2.0 - 2015-02-27: error function improved / info function added / file installed and directory created if not already present / modification of file permission can be specified in the file list and apply to the file
23 24
 # v1.3 - 2014-12-04: warning and error functions improved
24 25
 # v1.2 - 2014-09-24: temp file bug corrected / check if local file exist
25 26
 # v1.1 - 2014-09-14: test_dep bug corrected
... ...
@@ -50,10 +51,17 @@ function usage {
50 51
 Aim: $aim
51 52
 
52 53
 Options:
53
-    -l, --list      File containing remote path and local path of a file to synchronize.
54
-                    The list file must have a unique path pair per line and each path must
55
-                    be semi-colon separated (path1 ; path2). The remote path must be http path.
56
-                    Comments beginning by # are allowed anywhere.
54
+    -l, --list      Text file containing both remote and local path of
55
+                    a given file for synchronization.
56
+                        - The list file must have a unique path pair
57
+                            per line and each path must be semi-colon
58
+                            separated (remote_path ; local_path).
59
+                            The \e[33mremote path\e[0m must be \e[33mhttp\e[0m a path.
60
+                        - Modification of file permission can be specified
61
+                            in a third column. The syntax is the chmod
62
+                            syntax (ie, remote_path ; local_path ; uog+rwx).
63
+                        - Comments beginning by # are allowed anywhere
64
+                            in the list file.
57 65
 
58 66
     -d, --dry-run   Run the synchronization but print a message instead of updating the files. 
59 67
 
... ...
@@ -67,11 +75,11 @@ function error {
67 75
     if [[ -t 1 ]]
68 76
     then
69 77
         echo -e "\e[31mError:\e[00m $1"
70
-        exit $2
71 78
     else
72 79
         echo -e "Error: $1"
73
-        exit $2
74 80
     fi
81
+    
82
+    exit $2
75 83
 }
76 84
 
77 85
 
... ...
@@ -86,6 +94,17 @@ function warning {
86 94
 }
87 95
 
88 96
 
97
+# Info message
98
+function info {
99
+    if [[ -t 1 ]]
100
+    then
101
+        echo -e "\e[32mInfo:\e[00m $1"
102
+    else
103
+        echo -e "Info: $1"
104
+    fi
105
+}
106
+
107
+
89 108
 
90 109
 #==============#
91 110
 # Dependencies #
... ...
@@ -128,7 +147,7 @@ tmp_list="/tmp/$(basename $list)-$mydate"
128 147
 #============#
129 148
 
130 149
 # Check file list
131
-if [[ $(awk -F ";" "END {print NF}" "$list") != 2 ]]
150
+if [[ $(awk -F ";" "END {print NF}" "$list") -gt 3 ]]
132 151
 then
133 152
     error "The list file "$list" is malformated. Each path pair must be on unique line and each path must be semi-colon (';') separated." 1
134 153
 fi
... ...
@@ -136,6 +155,7 @@ fi
136 155
 
137 156
 # Remove comments from list file
138 157
 sed "/^\s*#/d;s/\s*#.*$//" "$list" > "$tmp_list"
158
+sed -i "/^$/d" "$tmp_list"
139 159
 
140 160
 
141 161
 # Synchronization
... ...
@@ -145,17 +165,22 @@ do
145 165
     # Get paths
146 166
     mysrc=$(echo "$line" | cut -d ";" -f 1 | sed -e "s/^ *//" -e "s/ *$//")
147 167
     mydst=$(echo "$line" | cut -d ";" -f 2 | sed -e "s/^ *//" -e "s/ *$//")
168
+    mymod=$(echo "$line" | cut -d ";" -f 3 | sed -e "s/^ *//" -e "s/ *$//")
148 169
 
149 170
     mydst_tmp="/tmp/${mydst##*/}"
150 171
 
151
-    # Check if destination file exists
152
-    if [[ ! -e "$mydst" ]]
172
+
173
+    # Check if mydst variable is empty or contain directory
174
+    if [[ -z "$mydst" ]]
153 175
     then
154
-        warning "${mydst##*/}: Local file does not exist. Skipping..."
176
+        warning "The destination name is absent. Skipping..."
155 177
         continue
178
+    elif [[ $(echo "$mydst" | grep "/") && ! -d "${mydst%/*}" ]]
179
+    then
180
+        info "${mydst##*/}: ${mydst%/*} directory created."
181
+        mkdir "${mydst%/*}"
156 182
     fi
157 183
 
158
-
159 184
     # Check if remote path is http
160 185
     if [[ ! $(echo "$mysrc" | grep -i "^http") ]]
161 186
     then
... ...
@@ -171,6 +196,16 @@ do
171 196
     then
172 197
         warning "${mydst##*/}: An error occured during the downloading. Skipping..."
173 198
         continue
199
+    # Check if destination file exists
200
+    elif [[ ! -e "$mydst" ]]
201
+    then
202
+        if [[ $dry == 1 ]]
203
+        then
204
+            info "${mydst##*/}: file available but not installed."
205
+        else
206
+            mv "$mydst_tmp" "$mydst"
207
+            info "${mydst##*/} installed."
208
+        fi
174 209
     else
175 210
         # Compare downloaded file and destination file (update file if need)
176 211
         mydst_tmp_md=$(md5sum "$mydst_tmp" | cut -d " " -f 1)
... ...
@@ -179,15 +214,25 @@ do
179 214
         then
180 215
             if [[ $dry == 1 ]]
181 216
             then
182
-                warning "${mydst##*/}: A new version is available."
217
+                info "${mydst##*/}: new version available."
183 218
             else
184 219
                 mv "$mydst_tmp" "$mydst"
220
+                info "${mydst##*/} updated."
185 221
             fi
186 222
         else
187 223
             rm "$mydst_tmp"
188 224
         fi
189 225
     fi
190 226
 
227
+    if [[ -z $dry && -n "$mymod" && -n $(echo "$mymod" | sed -n "/[u,o,g,][+,-][r,w,x,s,t,S,T]/p") ]]
228
+    then
229
+        chmod "$mymod" "$mydst"
230
+    elif [[ -z $dry && -n "$mymod" && -z $(echo "$mymod" | sed -n "/[u,o,g,][+,-][r,w,x,s,t,S,T]/p") ]]
231
+    then
232
+        warning "${mydst##*/}: Impossible to change permission, \"$mymod\" does not follow the syntax of the chmod command (see help)."
233
+        continue
234
+    fi
235
+
191 236
 done < "$tmp_list"
192 237
 
193 238
 
Browse code

git-sync.sh - v1.3 - Error and warning functions improved

Fred authored on04/12/2014 22:44:34
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 1.2
3
+# Version: 1.3
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2014-09-24
6
+# Modified in: 2014-12-04
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
+# v1.3 - 2014-12-04: warning and error functions improved
23 24
 # v1.2 - 2014-09-24: temp file bug corrected / check if local file exist
24 25
 # v1.1 - 2014-09-14: test_dep bug corrected
25 26
 # v1.0 - 2014-09-14: git dependency check replaced by wget check (bug) / test_dep function improved / remove comments in list file / check for http path / remove spaces in path / checksum loop corrected
... ...
@@ -63,14 +64,25 @@ Options:
63 64
 
64 65
 # Error message
65 66
 function error {
66
-    echo -e "\e[31mError:\e[00m $1"
67
-    exit $2
67
+    if [[ -t 1 ]]
68
+    then
69
+        echo -e "\e[31mError:\e[00m $1"
70
+        exit $2
71
+    else
72
+        echo -e "Error: $1"
73
+        exit $2
74
+    fi
68 75
 }
69 76
 
70 77
 
71 78
 # Warning message
72 79
 function warning {
73
-    echo -e "\e[33mWarning:\e[00m $1"
80
+    if [[ -t 1 ]]
81
+    then
82
+        echo -e "\e[33mWarning:\e[00m $1"
83
+    else
84
+        echo -e "Warning: $1"
85
+    fi
74 86
 }
75 87
 
76 88
 
Browse code

git-sync.sh - v1.2 - Bug corrected and check step added

For more details, see version section of the script.

U-TXBMGENETICS\fcheval authored on24/09/2014 15:34:22
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 1.1
3
+# Version: 1.2
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2014-09-14
6
+# Modified in: 2014-09-24
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
+# v1.2 - 2014-09-24: temp file bug corrected / check if local file exist
23 24
 # v1.1 - 2014-09-14: test_dep bug corrected
24 25
 # v1.0 - 2014-09-14: git dependency check replaced by wget check (bug) / test_dep function improved / remove comments in list file / check for http path / remove spaces in path / checksum loop corrected
25 26
 # v0.1 - 2014-09-23: dry-run option added / no check certifcate option added for wget
... ...
@@ -106,7 +107,7 @@ fi
106 107
 
107 108
 # Temporary list
108 109
 mydate=$(date +%N)
109
-tmp_list="/tmp/$list-$mydate"
110
+tmp_list="/tmp/$(basename $list)-$mydate"
110 111
 
111 112
 
112 113
 
... ...
@@ -135,6 +136,14 @@ do
135 136
 
136 137
     mydst_tmp="/tmp/${mydst##*/}"
137 138
 
139
+    # Check if destination file exists
140
+    if [[ ! -e "$mydst" ]]
141
+    then
142
+        warning "${mydst##*/}: Local file does not exist. Skipping..."
143
+        continue
144
+    fi
145
+
146
+
138 147
     # Check if remote path is http
139 148
     if [[ ! $(echo "$mysrc" | grep -i "^http") ]]
140 149
     then
Browse code

git-sync.sh - v1.1 - Bug in test_dep function corrected

Fred authored on14/09/2014 20:34:57
Showing1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 1.0
3
+# Version: 1.1
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6 6
 # Modified in: 2014-09-14
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from git server (master branch) on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v1.1 - 2014-09-14: test_dep bug corrected
23 24
 # v1.0 - 2014-09-14: git dependency check replaced by wget check (bug) / test_dep function improved / remove comments in list file / check for http path / remove spaces in path / checksum loop corrected
24 25
 # v0.1 - 2014-09-23: dry-run option added / no check certifcate option added for wget
25 26
 # v0.0 - 2014-09-03: creation
... ...
@@ -32,7 +33,8 @@ aim="Synchronize files from git server (master branch) on this terminal."
32 33
 
33 34
 # Dependency test
34 35
 function test_dep {
35
-    if [[ ! $(which $1 &> /dev/null) ]]
36
+    which $1 &> /dev/null
37
+    if [[ $? != 0 ]]
36 38
     then
37 39
         error "Package $1 is needed. Exiting..." 1
38 40
     fi
Browse code

git-synch.sh - v1.0 - Several bug corrections and functions added

For more details, see versions section of the script.

Fred authored on14/09/2014 20:22:39
Showing1 changed files
... ...
@@ -1,10 +1,10 @@
1 1
 #!/bin/bash
2 2
 # Title: git-sync.sh
3
-# Version: 0.1
3
+# Version: 1.0
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-09-03
6
-# Modified in: 2014-09-13
7
-# Licence : GPL v3
6
+# Modified in: 2014-09-14
7
+# Licence: GPL v3
8 8
 
9 9
 
10 10
 
... ...
@@ -20,6 +20,7 @@ aim="Synchronize files from git server (master branch) on this terminal."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
+# v1.0 - 2014-09-14: git dependency check replaced by wget check (bug) / test_dep function improved / remove comments in list file / check for http path / remove spaces in path / checksum loop corrected
23 24
 # v0.1 - 2014-09-23: dry-run option added / no check certifcate option added for wget
24 25
 # v0.0 - 2014-09-03: creation
25 26
 
... ...
@@ -31,7 +32,7 @@ aim="Synchronize files from git server (master branch) on this terminal."
31 32
 
32 33
 # Dependency test
33 34
 function test_dep {
34
-    if [[ ! $(which $1) ]]
35
+    if [[ ! $(which $1 &> /dev/null) ]]
35 36
     then
36 37
         error "Package $1 is needed. Exiting..." 1
37 38
     fi
... ...
@@ -47,7 +48,8 @@ Aim: $aim
47 48
 Options:
48 49
     -l, --list      File containing remote path and local path of a file to synchronize.
49 50
                     The list file must have a unique path pair per line and each path must
50
-                    be semi-colon separated. The remote path must be http path.
51
+                    be semi-colon separated (path1 ; path2). The remote path must be http path.
52
+                    Comments beginning by # are allowed anywhere.
51 53
 
52 54
     -d, --dry-run   Run the synchronization but print a message instead of updating the files. 
53 55
 
... ...
@@ -74,7 +76,7 @@ function warning {
74 76
 # Dependencies #
75 77
 #==============#
76 78
 
77
-test_dep git
79
+test_dep wget
78 80
 
79 81
 
80 82
 
... ...
@@ -100,6 +102,10 @@ then
100 102
     error "The option -l is required. Exiting...\n$(usage)\n" 1
101 103
 fi
102 104
 
105
+# Temporary list
106
+mydate=$(date +%N)
107
+tmp_list="/tmp/$list-$mydate"
108
+
103 109
 
104 110
 
105 111
 #============#
... ...
@@ -113,18 +119,29 @@ then
113 119
 fi
114 120
 
115 121
 
122
+# Remove comments from list file
123
+sed "/^\s*#/d;s/\s*#.*$//" "$list" > "$tmp_list"
124
+
125
+
116 126
 # Synchronization
117 127
 while read line
118 128
 do
119 129
 
120 130
     # Get paths
121
-    mysrc=$(echo "$line" | cut -d ";" -f 1)
122
-    mydst=$(echo "$line" | cut -d ";" -f 2)
131
+    mysrc=$(echo "$line" | cut -d ";" -f 1 | sed -e "s/^ *//" -e "s/ *$//")
132
+    mydst=$(echo "$line" | cut -d ";" -f 2 | sed -e "s/^ *//" -e "s/ *$//")
123 133
 
124 134
     mydst_tmp="/tmp/${mydst##*/}"
125 135
 
136
+    # Check if remote path is http
137
+    if [[ ! $(echo "$mysrc" | grep -i "^http") ]]
138
+    then
139
+        warning "${mydst##*/}: Remote path is not http address. Skipping..."
140
+        continue
141
+    fi
142
+
126 143
     # Download file
127
-    wget --no-check-certificate -O "$mydst_tmp" "$mysrc"
144
+    wget --no-check-certificate -O "$mydst_tmp" "$mysrc" &> /dev/null
128 145
 
129 146
     # Check for errors
130 147
     if [[ $? != 0 ]]
... ...
@@ -133,7 +150,9 @@ do
133 150
         continue
134 151
     else
135 152
         # Compare downloaded file and destination file (update file if need)
136
-        if [[ $(md5sum "$mydst_tmp") -ne $(md5sum "$mydst") ]]
153
+        mydst_tmp_md=$(md5sum "$mydst_tmp" | cut -d " " -f 1)
154
+        mydst_md=$(md5sum "$mydst" | cut -d " " -f 1)
155
+        if [[ "$mydst_tmp_md" != "$mydst_md" ]]
137 156
         then
138 157
             if [[ $dry == 1 ]]
139 158
             then
... ...
@@ -146,7 +165,11 @@ do
146 165
         fi
147 166
     fi
148 167
 
149
-done < "$list"
168
+done < "$tmp_list"
169
+
170
+
171
+# Remove temporary list
172
+rm "$tmp_list"
150 173
 
151 174
 
152 175
 exit 0
Browse code

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

Fred authored on13/09/2014 23:51:03
Showing1 changed files
... ...
@@ -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
Browse code

git-sync.sh - v0.0 - Initial commit

Fred authored on03/09/2014 23:33:46
Showing1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,143 @@
1
+#!/bin/bash
2
+# Title: git-sync.sh
3
+# Version: 0.0
4
+# Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5
+# Created in: 2014-09-03
6
+# Modified in:
7
+# Licence : GPL v3
8
+
9
+
10
+
11
+#======#
12
+# Aims #
13
+#======#
14
+
15
+aim="Synchronize files from git server (master branch) on this terminal."
16
+
17
+
18
+
19
+#==========#
20
+# Versions #
21
+#==========#
22
+
23
+# v0.0 - 2014-09-03: creation
24
+
25
+
26
+
27
+#===========#
28
+# Functions #
29
+#===========#
30
+
31
+# Dependency test
32
+function test_dep {
33
+    if [[ ! $(which $1) ]]
34
+    then
35
+        error "Package $1 is needed. Exiting..." 1
36
+    fi
37
+}
38
+
39
+# Usage message
40
+function usage {
41
+    echo -e "
42
+    \e[32m${0##*/}\e[00m -l|--list list -h|--help
43
+
44
+Aim: $aim
45
+
46
+Options:
47
+    -l, --list      file containing remote path and local path of a file to synchronize.
48
+                    The list file must have a unique path pair per line and each path must
49
+                    be semi-colon separated. The remote path must be http path.
50
+
51
+    -h, --help      this message
52
+"
53
+}
54
+
55
+
56
+# Error message
57
+function error {
58
+    echo -e "\e[31mError:\e[00m $1"
59
+    exit $2
60
+}
61
+
62
+
63
+# Warning message
64
+function warning {
65
+    echo -e "\e[33mWarning:\e[00m $1"
66
+}
67
+
68
+
69
+
70
+#==============#
71
+# Dependencies #
72
+#==============#
73
+
74
+test_dep git
75
+
76
+
77
+
78
+#==========================#
79
+# Declaration of variables #
80
+#==========================#
81
+
82
+# Options
83
+while [[ $# -gt 0 ]]
84
+do
85
+    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
+    esac
90
+done
91
+
92
+
93
+# Check the existence of obligatory options
94
+if [[ -z "$list" ]]
95
+then
96
+    error "The option -l is required. Exiting...\n$(usage)\n" 1
97
+fi
98
+
99
+
100
+
101
+#============#
102
+# Processing #
103
+#============#
104
+
105
+# Check file list
106
+if [[ $(awk -F ";" "END {print NF}" "$list") != 2 ]]
107
+then
108
+    error "The list file "$list" is malformated. Each path pair must be on unique line and each path must be semi-colon (';') separated." 1
109
+fi
110
+
111
+
112
+# Synchronization
113
+while read line
114
+do
115
+
116
+    # Get paths
117
+    mysrc=$(echo "$line" | cut -d ";" -f 1)
118
+    mydst=$(echo "$line" | cut -d ";" -f 2)
119
+
120
+    mydst_tmp="/tmp/${mydst##*/}"
121
+
122
+    # Download file
123
+    wget -O "$mydst_tmp" "$mysrc"
124
+
125
+    # Check for errors
126
+    if [[ $? != 0 ]]
127
+    then
128
+        warning "${mydst##*/}: An error occur during the downloading. Skipping..."
129
+        continue
130
+    else
131
+        # Compare downloaded file and destination file (update file if need)
132
+        if [[ $(md5sum "$mydst_tmp") -ne $(md5sum "$mydst") ]]
133
+        then
134
+            mv "$mydst_tmp" "$mydst"
135
+        else
136
+            rm "$mydst_tmp"
137
+        fi
138
+    fi
139
+
140
+done < "$list"
141
+
142
+
143
+exit 0