-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcreate-artifact-environment-pantheon
executable file
·59 lines (49 loc) · 1.4 KB
/
create-artifact-environment-pantheon
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
#!/bin/bash
#
# Ensure a multidev environment exists for a branch.
#
set -e
usage() {
echo "
Ensure a multidev environment exists for a branch.
Options:
-h: Show help
-b: Set the branch name (required)
-i: Set the Pantheon site that will be used (defaults to TERMINUS_SITE).
-s: Set the source environment (defaults to live)
-n: Dry run (does not create environment).
Usage:
Ensure a multidev site exists for the xyz branch:
$0 -b xzy -i mysite
"
}
error_out() {
echo $1 >&2
exit $2
}
pattern=".*"
site="$TERMINUS_SITE"
source="${TERMINUS_SOURCE_ENVIRONMENT:-live}"
dryrun=0
while getopts "hb:i:s:n" opt; do
case "$opt" in
h) usage; exit 0;;
b) branch=$OPTARG;;
i) site=$OPTARG;;
s) source=$OPTARG;;
n) dryrun=1;;
esac
done
test -n "$site" || error_out "Site must be set using the -s flag or the TERMINUS_SITE environment variable" 1
test -n "$source" || error_out "Source environment must be set."
test -n "$branch" || error_out "Branch name must be set using the -b flag."
# Auto-login if possible.
if [ -n "$TERMINUS_MACHINE_TOKEN" ]; then
[ -e ~/.terminus/cache/session ] || terminus auth:login --machine-token="$TERMINUS_MACHINE_TOKEN"
fi
if terminus env:info "$site.$branch" > /dev/null 2>&1; then
echo "Multidev environment exists for $branch"
else
echo "Creating environment for $branch"
[[ $dryrun -eq 1 ]] || terminus multidev:create "$site.$source" "$branch"
fi