-
Notifications
You must be signed in to change notification settings - Fork 2
/
publish.sh
executable file
·78 lines (54 loc) · 2.5 KB
/
publish.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
#
# Install bootstrap.sh and ezvm local content to Google Cloud Storage
# where it can be accessed by new VMs as they come online.
#
cd "$(dirname $0)"
BASE_DIR="$(dirname $(pwd))"
fatal() {
r=$1; shift;
echo "ERROR: $@" 1>&2
exit $r
}
if [ ! -e $BASE_DIR/configuration ]; then
fatal 1 "CONFIG: You did not create the configuration file: $BASE_DIR/configuration"
fi
. $BASE_DIR/configuration || fatal 2 "CONFIG: Cannot read $BASE_DIR/configuration"
if [ -z "$GS_EZVM_LOCAL_ARCHIVE" -o "$GS_EZVM_LOCAL_ARCHIVE" = "__CONFIGURE_GS_ARCHIVE_URL__" ]; then
fatal 3 "CONFIG: You did not configure GS_EZVM_LOCAL_ARCHIVE in $BASE_DIR/configuration"
fi
if [ -z "$GS_BOOTSTRAP_SH" -o "$GS_BOOTSTRAP_SH" = "__CONFIGURE_GS_BOOTSTRAP_URL__" ]; then
fatal 3 "CONFIG: You did not configure GS_BOOTSTRAP_SH in $BASE_DIR/configuration"
fi
# Create the build dir if needed
[ -d "$BASE_DIR/build" ] || mkdir -p "$BASE_DIR/build" || fatal 5 "Cannot create $BASE_DIR/build directory"
archive=$(basename "$GS_EZVM_LOCAL_ARCHIVE")
# bootstrap.sh cannot read a configuration file because it is being stored
# in GS, where no files can be read. Thus we just replace the strings in
# there with the actual values, so it is stand-alone ready.
echo "# Building bootstrap.sh"
cat $BASE_DIR/scripts/bootstrap.sh \
| sed -e "s,__CONFIGURE_GS_ARCHIVE_URL__,$GS_EZVM_LOCAL_ARCHIVE,g" \
| sed -e "s,__CONFIGURE_GS_BOOTSTRAP_URL__,$GS_BOOTSTRAP_SH,g" \
> $BASE_DIR/build/bootstrap.sh \
|| fatal $? "Failed to customize bootstrap.sh"
echo "# Building $archive"
cd "$BASE_DIR/local" || fatal $? "cd $BASE_DIR/local failed"
# Copy the configuration file into the local dir, where it will be packaged
# up and distributed with the archive.
( cat <<EOF
###
### This file is automatically copied by ../scripts/publish.sh
### It copied the file from ../configuration to this location
### DO NOT EDIT THIS FILE, YOUR CHANGES WILL BE LOST.
###
EOF
cat $BASE_DIR/configuration
) > $BASE_DIR/local/configuration || fatal $? "Cannot copy configuration"
# Now zip up the archive, including the copied configuration file
tar -czf "$BASE_DIR/build/$archive" * || fatal $? "Create $archive failed"
# Copy files up to Google Cloud Storage
echo "# Uploading to Google Cloud Storage"
cd "$BASE_DIR" || fatal $? "cd $BASE_DIR failed"
gsutil cp build/bootstrap.sh "$GS_BOOTSTRAP_SH" || fatal $? "gsutil cp failed for $GS_BOOTSTRAP_SH"
gsutil cp "build/$archive" "$GS_EZVM_LOCAL_ARCHIVE" || fatal $? "gsutil cp failed for $GS_EZVM_LOCAL_ARCHIVE"