Browse code

Version 0.1

Several bugs corrected and functions added (see version part of the script for more details)

Fred authored on01/09/2014 23:33:36
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Title: git-repo-creator.sh
3
-# Version: 0.0
3
+# Version: 0.1
4 4
 # Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5 5
 # Created in: 2014-08-31
6
-# Modified in:
6
+# Modified in: 2014-09-01
7 7
 # Licence : GPL v3
8 8
 
9 9
 
... ...
@@ -20,7 +20,8 @@ aim="Create a git repository locally and remotely on a given server using ssh."
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
-# v0.0: creation
23
+# v0.1 - 2014-09-01: default value for -d using structure of -r added / if remote repository exist, skip instead of interrupt the script / addition of missing part of initialisation step when done for the first time / bug correction in the reinitialisation of remote path
24
+# v0.0 - 2014-08-31: creation
24 25
 
25 26
 
26 27
 
... ...
@@ -45,7 +46,7 @@ Aim: $aim
45 46
 
46 47
 Options:
47 48
     -r, --rep       name or path of the repository created locally
48
-    -d, --drep      name or path of the repository created on the server
49
+    -d, --drep      name or path of the repository created on the server [default: value of -r]
49 50
     -s, --svr       name of the server
50 51
     -u, --usr       user name for server connection
51 52
     -h, --help      this message
... ...
@@ -66,6 +67,7 @@ function warning {
66 67
 }
67 68
 
68 69
 
70
+
69 71
 #==============#
70 72
 # Dependencies #
71 73
 #==============#
... ...
@@ -98,10 +100,23 @@ then
98 100
     error "The option -r is required. Exiting...\n$(usage)\n" 1
99 101
 fi
100 102
 
103
+# Check variable value for remote repository
101 104
 if [[ -n "$drep" ]]
102 105
 then
103 106
     [[ -z "$svr" ]] && error "Server destination missing. Exiting...\n$(usage)\n" 1
104 107
     [[ -z "$usr" ]] && error "Server user missing. Exiting...\n$(usage)\n" 1
108
+elif [[ -n "$svr" ]]
109
+then
110
+    [[ -z "$usr" ]] && error "Server user missing. Exiting...\n$(usage)\n" 1
111
+elif [[ -n "$usr" ]]
112
+then
113
+    [[ -z "$svr" ]] && error "Server destination missing. Exiting...\n$(usage)\n" 1
114
+fi
115
+
116
+# Set default value for remote repository
117
+if [[ -n "$usr" && -n "$svr" && -z "$drep" ]]
118
+then
119
+    drep="$rep"
105 120
 fi
106 121
 
107 122
 
... ...
@@ -127,28 +142,32 @@ then
127 142
     if [[ $? == 0 ]]
128 143
     then
129 144
         warning "Remote directory exists already on the server."
130
-        read -p "Continue? [y/N] " answer
131
-        if [[ -z "$answer" || "$answer" =~ [NO]|[no] ]]
145
+        read -p "Skipping? [Y/n] " answer
146
+        if [[ -z "$answer" || "$answer" =~ [YES]|[yes] ]]
132 147
         then
133
-            echo "Aborting..."
134
-            exit 1
148
+            echo "Skipping..."
149
+            skip_flag=1
135 150
         fi
136 151
     fi
152
+    
153
+    if [[ -z $skip_flag ]]
154
+    then
155
+        # Creation of the local sturcture in /tmp
156
+        git --bare init "/tmp/$drep" &> /dev/null
137 157
 
138
-    # Creation of the local sturcture in /tmp
139
-    git --bare init "/tmp/$drep" &> /dev/null
140
-
141
-    # Upload of the structure on the server
142
-    old_pwd="$PWD"
143
-    cd /tmp
144
-    scp -p -r "${drep%%/*}" $usr@$svr: &> /dev/null
145
-    cd "$old_pwd"
158
+        # Upload of the structure on the server
159
+        old_pwd="$PWD"
160
+        cd /tmp
161
+        scp -p -r "${drep%%/*}" $usr@$svr: &> /dev/null
162
+        cd "$old_pwd"
146 163
 
147
-    # Removing of the tmp files
148
-    rm -R "/tmp/$drep"
164
+        # Removing of the tmp files
165
+        rm -R "/tmp/$drep"
166
+    fi
149 167
 fi
150 168
 
151
-# Creation of the directory
169
+
170
+# Creation of the local directory
152 171
 echo -e "Setting local repository up..."
153 172
 mkdir -p "$rep" 2> /dev/null
154 173
 
... ...
@@ -163,16 +182,19 @@ then
163 182
     then
164 183
         echo "Skipping..."
165 184
     else
166
-        git init "$rep"
185
+        git init
167 186
     fi
187
+else
188
+    git init
168 189
 fi
169 190
 
191
+
170 192
 # Adding remote destination
171 193
 if [[ -n "$drep" ]]
172 194
 then
173 195
     echo -e "Adding remote destination in the local repository..."
174 196
 
175
-    if [[ $(git remote &> /dev/null; echo $?) == 0 ]]
197
+    if [[ $(git remote | wc -l) -gt 0 ]]
176 198
     then
177 199
         warning "Remote destination has already been set up for this repository."
178 200
         read -p "Reinitialisation? [y/N] " answer