-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·52 lines (45 loc) · 2.52 KB
/
setup.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
#!/usr/bin/env bash
# This wont work in dash because dash doesn't support process substitution:
# https://mywiki.wooledge.org/ProcessSubstitution
# bash <(curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh) trigger-sopupdate
# so we're going to have to do either
# bash -c "bash <(curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh) trigger-sopupdate"
# where we call bash directly and pass it the commands we need to run OR we can use named pipes to get around the limitation
# dash> curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh | { bash /dev/fd/3 trigger-sopupdate; } 3<&0
# see https://mywiki.wooledge.org/NamedPipes
# We pipe the output of curl to a compound command, but duplicate the stdout to named pipe 3, which is then available
# inside the compound command as /dev/fd/3 where we can pass it to bash and include our command argument
# alternatively, we could scan PATH for an `.environment` file and then cat our new export of PATH to the bottom
# https://github.com/platformsh/source-operations.git
# Repo for our source ops support scripts
gitSourceOps="https://github.com/platformsh/source-operations.git"
# A writable location where we can store things: cache directory on a psh environment, TMPDIR in most systems, or fallback
tmpDir=${PLATFORM_CACHE_DIR:-${TMPDIR:-/tmp}}
dirSourceOps="${tmpDir}/source-operations"
#Does the temp directory exist and more importantly, can we write to it?
if [ ! -d "${tmpDir}" ] || [ ! -w "${tmpDir}" ]; then
printf "The directory %s either doesn't exist, or I am unable to write to it. Exiting.\n" "${tmpDir}"
exit 1
else
printf "Using directory %s for the toolkit.\n" "${dirSourceOps}"
fi
#check and see if we already have the repo cloned in /tmp
# we dont really care what the status is other than does it exist, hence the &>/dev/null
git -C "${dirSourceOps}" status &>/dev/null
gitCheck=$?
# we dont have the repo cloned so let's clone it
if (( 0 != gitCheck )) || [[ ! -d "${dirSourceOps}" ]]; then
printf "Installing the source operations support tools..."
git -C "${tmpDir}" clone --quiet "${gitSourceOps}"
printf " Done.\n"
else
# we have it so let's make sure we're up-to-date
printf "Ensuring we have the latest version of the source operations support tools..."
git -C "${dirSourceOps}" pull origin --quiet
printf " Done.\n"
fi
# Add our directory to PATH so we can call it
export PATH="${dirSourceOps}:${PATH}"
sourceOp "${1:-'nothing'}"
#return the exit code from sourceOp
exit $?