OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # Ensures the latest Chrome Canary is available, downloading it | 3 # Ensures the latest Chrome Canary is available, downloading it |
4 # if necessary. | 4 # if necessary. |
5 # | 5 # |
6 # Directory ~/.chrome/canary can safely be cached as the existing | 6 # Directory ~/.chrome/canary can safely be cached as the existing |
7 # version will be checked before reusing a previously downloaded | 7 # version will be checked before reusing a previously downloaded |
8 # canary. | 8 # canary. |
9 # | 9 # |
10 | 10 |
11 set -eu | 11 set -eu |
12 | 12 |
13 readonly CHROME_URL=https://storage.googleapis.com/chromium-browser-snapshots/Li
nux_x64 | 13 readonly CHROME_SNAPSHOTS=https://storage.googleapis.com/chromium-browser-snapsh
ots |
14 readonly CHROME_REV=$(curl -s ${CHROME_URL}/LAST_CHANGE) | 14 declare CHROME_URL |
| 15 declare CHROME_NAME |
| 16 declare CHROME_RELATIVE_BIN |
| 17 |
| 18 if [[ "$OSTYPE" == "linux"* ]]; then |
| 19 CHROME_URL=$CHROME_SNAPSHOTS/Linux_x64 |
| 20 CHROME_NAME=chrome-linux |
| 21 CHROME_RELATIVE_BIN=chrome |
| 22 elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 23 CHROME_URL=$CHROME_SNAPSHOTS/Mac |
| 24 CHROME_NAME=chrome-mac |
| 25 CHROME_RELATIVE_BIN=Chromium.app/Contents/MacOS/Chromium |
| 26 elif [[ "$OSTYPE" == "cygwin" ]]; then |
| 27 CHROME_URL=$CHROME_SNAPSHOTS/Win |
| 28 CHROME_NAME=chrome-win32 |
| 29 CHROME_RELATIVE_BIN=chrome.exe |
| 30 else |
| 31 echo "Unknown platform: $OSTYPE" >&2 |
| 32 exit 1 |
| 33 fi |
15 | 34 |
16 readonly CHROME_CANARY_DIR=$HOME/.chrome/canary | 35 readonly CHROME_CANARY_DIR=$HOME/.chrome/canary |
17 readonly CHROME_CANARY_BIN=$CHROME_CANARY_DIR/chrome-linux/chrome | 36 readonly CHROME_CANARY_BIN=$CHROME_CANARY_DIR/$CHROME_NAME/$CHROME_RELATIVE_BIN |
18 readonly CHROME_CANARY_REV_FILE=$CHROME_CANARY_DIR/VERSION | 37 readonly CHROME_CANARY_REV_FILE=$CHROME_CANARY_DIR/VERSION |
| 38 readonly CHROME_REV=$(curl -s ${CHROME_URL}/LAST_CHANGE) |
19 | 39 |
20 function getCanary() { | 40 function getCanary() { |
21 local existing_version="" | 41 local existing_version="" |
22 if [[ -f $CHROME_CANARY_REV_FILE && -x $CHROME_CANARY_BIN ]]; then | 42 if [[ -f $CHROME_CANARY_REV_FILE && -x $CHROME_CANARY_BIN ]]; then |
23 existing_version=`cat $CHROME_CANARY_REV_FILE` | 43 existing_version=`cat $CHROME_CANARY_REV_FILE` |
24 echo "Found cached Chrome Canary version: $existing_version" | 44 echo "Found cached Chrome Canary version: $existing_version" |
25 fi | 45 fi |
26 | 46 |
27 if [[ "$existing_version" != "$CHROME_REV" ]]; then | 47 if [[ "$existing_version" != "$CHROME_REV" ]]; then |
28 echo "Downloading Chrome Canary version: $CHROME_REV" | 48 echo "Downloading Chrome Canary version: $CHROME_REV" |
29 rm -fR $CHROME_CANARY_DIR | 49 rm -fR $CHROME_CANARY_DIR |
30 mkdir -p $CHROME_CANARY_DIR | 50 mkdir -p $CHROME_CANARY_DIR |
31 | 51 |
32 local file=chrome-linux.zip | 52 local file=$CHROME_NAME.zip |
33 curl ${CHROME_URL}/${CHROME_REV}/$file -o $file | 53 curl ${CHROME_URL}/${CHROME_REV}/$file -o $file |
34 unzip $file -d $CHROME_CANARY_DIR | 54 unzip $file -d $CHROME_CANARY_DIR |
35 rm $file | 55 rm $file |
36 echo $CHROME_REV > $CHROME_CANARY_REV_FILE | 56 echo $CHROME_REV > $CHROME_CANARY_REV_FILE |
37 fi | 57 fi |
38 } | 58 } |
39 | 59 |
40 getCanary >&2 | 60 getCanary >&2 |
41 | 61 |
42 echo $CHROME_CANARY_BIN | 62 echo $CHROME_CANARY_BIN |
OLD | NEW |