|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | function help_and_exit() { |
4 | | - echo "Usage: $0 [-go] [-verbose]" |
| 4 | + echo "Usage: $0 [-go] [-verbose] [-force]" |
5 | 5 | echo |
6 | 6 | echo "Moves minified CSS and JS to distribution directories and" |
7 | 7 | echo "creates a branch in SVN." |
8 | 8 | echo |
9 | 9 | echo " -go: Run commands instead of just echoing them." |
10 | 10 | echo " -verbose: More verbose logging." |
| 11 | + echo " -force: Ignore sanity checks for testing." |
| 12 | + echo " Incompatible with -go." |
11 | 13 | exit "$1" |
12 | 14 | } |
13 | 15 |
|
14 | 16 | # 1 for verbose logging |
15 | 17 | export VERBOSE="0" |
16 | 18 | # 1 if commands that have side-effects should actually be run instead of logged |
17 | 19 | export EFFECT="0" |
| 20 | +# 1 to not exit on panic. |
| 21 | +export NO_PANIC="0" |
18 | 22 |
|
19 | 23 | function panic() { |
20 | | - echo "$*" |
21 | | - exit -1 |
| 24 | + echo "PANIC: $*" |
| 25 | + |
| 26 | + if ! (( $NO_PANIC )); then |
| 27 | + exit -1 |
| 28 | + fi |
22 | 29 | } |
23 | 30 |
|
24 | 31 | function command() { |
25 | 32 | if (( $VERBOSE )) || ! (( $EFFECT )); then |
26 | | - echo '$' "$*" |
| 33 | + echo '$' "$*" |
27 | 34 | fi |
28 | 35 | if (( $EFFECT )); then |
29 | | - "$@" || panic "command failed: $@" |
| 36 | + "$@" || panic "command failed: $@" |
30 | 37 | fi |
31 | 38 | } |
32 | 39 |
|
33 | 40 | function mime_for_file() { |
34 | 41 | local path="$1" |
35 | 42 | case "${path##*.}" in |
36 | | - js) echo -n "text/javascript;charset=UTF-8";; |
37 | | - css) echo -n "text/css;charset=UTF-8";; |
38 | | - html) echo -n "text/html;charset=UTF-8";; |
39 | | - *) panic "unrecognized extension for $path";; |
| 43 | + js) echo -n "text/javascript;charset=UTF-8";; |
| 44 | + css) echo -n "text/css;charset=UTF-8";; |
| 45 | + html) echo -n "text/html;charset=UTF-8";; |
| 46 | + *) panic "unrecognized extension for $path";; |
40 | 47 | esac |
41 | 48 | } |
42 | 49 |
|
43 | 50 | for var in "$@"; do |
44 | 51 | case "$var" in |
45 | 52 | -verbose) |
46 | | - VERBOSE="1" |
47 | | - ;; |
| 53 | + VERBOSE="1" |
| 54 | + ;; |
48 | 55 | -go) |
49 | | - EFFECT="1" |
50 | | - ;; |
| 56 | + EFFECT="1" |
| 57 | + ;; |
| 58 | + -force) |
| 59 | + NO_PANIC="1" |
| 60 | + ;; |
51 | 61 | -h) |
52 | | - help_and_exit 0 |
53 | | - ;; |
| 62 | + help_and_exit 0 |
| 63 | + ;; |
54 | 64 | *) |
55 | | - echo "Unrecognized variable $var" |
56 | | - help_and_exit -1 |
57 | | - ;; |
| 65 | + echo "Unrecognized variable $var" |
| 66 | + help_and_exit -1 |
| 67 | + ;; |
58 | 68 | esac |
59 | 69 | done |
60 | 70 |
|
| 71 | +if (( $NO_PANIC )) && (( $EFFECT )); then |
| 72 | + NO_PANIC="0" |
| 73 | + panic "-force is incompatible with -go" |
| 74 | +fi |
| 75 | + |
61 | 76 | # Find svn root |
62 | 77 | export VERSION_BASE="$( |
63 | 78 | pushd "$(dirname "$0")/.." > /dev/null; pwd; popd > /dev/null)" |
@@ -118,33 +133,35 @@ function sync() { |
118 | 133 | local src_file |
119 | 134 | local dest_file |
120 | 135 | for ext in $exts; do |
121 | | - for src_file in "$src_dir"/*."$ext"; do |
122 | | - dest_file="$dest_dir"/"$(basename "$src_file")" |
123 | | - if ! [ -e "$dest_file" ] || diff -q "$src_file" "$dest_file"; then |
124 | | - "$action" "$src_file" "$dest_file" |
125 | | - fi |
126 | | - done |
127 | | - for dest_file in "$dest_dir"/*."$ext"; do |
128 | | - src_file="$src_dir"/"$(basename "$dest_file")" |
129 | | - if ! [ -e "$src_file" ]; then |
130 | | - "$action" "$src_file" "$dest_file" |
131 | | - fi |
132 | | - done |
| 136 | + for src_file in "$src_dir"/*."$ext"; do |
| 137 | + if [ "$src_file" == "$src_dir/\*.$ext" ]; then continue; fi |
| 138 | + dest_file="$dest_dir"/"$(basename "$src_file")" |
| 139 | + if ! [ -e "$dest_file" ] || diff -q "$src_file" "$dest_file"; then |
| 140 | + "$action" "$src_file" "$dest_file" |
| 141 | + fi |
| 142 | + done |
| 143 | + for dest_file in "$dest_dir"/*."$ext"; do |
| 144 | + if [ "$dest_file" == "$dest_dir/\*.$ext" ]; then continue; fi |
| 145 | + src_file="$src_dir"/"$(basename "$dest_file")" |
| 146 | + if ! [ -e "$src_file" ]; then |
| 147 | + "$action" "$src_file" "$dest_file" |
| 148 | + fi |
| 149 | + done |
133 | 150 | done |
134 | 151 | } |
135 | 152 |
|
136 | 153 | function svn_sync() { |
137 | 154 | local src_file="$1" |
138 | 155 | local dest_file="$2" |
139 | 156 | if ! [ -e "$src_file" ]; then |
140 | | - command svn delete "$dest_file" |
| 157 | + command svn delete "$dest_file" |
141 | 158 | else |
142 | | - command cp "$src_file" "$dest_file" |
143 | | - if ! [ -e "$dest_file" ]; then |
144 | | - command svn add "$dest_file" |
145 | | - command svn propset svn:mime-type "$(mime_for_file "$src_file")" \ |
146 | | - "$dest_file" |
147 | | - fi |
| 159 | + command cp "$src_file" "$dest_file" |
| 160 | + if ! [ -e "$dest_file" ]; then |
| 161 | + command svn add "$dest_file" |
| 162 | + command svn propset svn:mime-type "$(mime_for_file "$src_file")" \ |
| 163 | + "$dest_file" |
| 164 | + fi |
148 | 165 | fi |
149 | 166 | } |
150 | 167 |
|
|
0 commit comments