-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreach
114 lines (105 loc) · 3.86 KB
/
reach
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
if [ ! "$REACH_ALLOW_SU" = '1' ] && [ "$(id -u)" -eq 0 ]; then
echo "Reach isn't intended to be run with superuser privileges."
echo
echo "Please try again while logged into a normal, non-root account, and without using \
\`sudo\`, \`su\`, or \`doas\` to grant elevated permissions."
echo
case "$(uname -s)" in
Linux)
if ! (groups "$(logname)" 2>&1 | grep -q docker 2>/dev/null); then
echo "Adding your account to the \`docker\` group should make this possible:"
echo "https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user"
echo
echo "Once you've done this, make sure to log out and back in before retrying."
echo
else
echo "Try logging out and back in if you've recently made yourself a member of the \`docker\` group but are unable to run Reach without \`sudo\`."
echo
fi
;;
*) : ;; # Docker Desktop for macOS doesn't use the `docker` group
esac
exit 1
fi
if [ -n "$DOCKER_HOST" ] && ! (echo "$DOCKER_HOST" | grep -q '^unix:'); then
echo "Reach only supports connecting to Docker via a local UNIX socket."
echo
echo "Please follow the directions from the link below to \`unset DOCKER_HOST\` or explicitly override it, e.g.:"
echo " $ DOCKER_HOST= $0 $*"
echo
echo "https://docs.docker.com/engine/install/linux-postinstall/#cannot-connect-to-the-docker-daemon"
echo
exit 1
fi
IMG='reachsh/reach-cli:latest'
TMP=$(mktemp -d "/tmp/reach.$(date -u '+%Y-%m-%dT%H-%M-%SZ')-XXXX")
CNF="${XDG_CONFIG_HOME:-$HOME/.config}/reach"; CNF="$(mkdir -p "$CNF" && cd "$CNF" && pwd)"
export TMP
run_d () {
REACH_HS="$(cd "$(dirname "$0")" && pwd)/hs"
export REACH_DIR_EMBED="${REACH_DIR_EMBED:-"$(cd "$(dirname "$0")" && pwd)/hs/app/reach/embed"}"
export REACH_STACK_YAML="${REACH_STACK_YAML:-"$(cd "$(dirname "$0")" && pwd)/hs/stack.yaml"}"
if [ "$REACH_DOCKER" = "0" ] \
&& [ -d "$REACH_DIR_EMBED" ] \
&& [ -f "$REACH_STACK_YAML" ] \
&& which stack >/dev/null 2>&1; then
export STACK_YAML="$REACH_STACK_YAML"
REACH_EX="$0" $(cd "${REACH_HS}" && make hs-build 1>&2 && stack exec -- which reach 2>/dev/null) \
--dir-embed="$REACH_DIR_EMBED" \
--dir-project-container="$(pwd)" \
--dir-project-host="$(pwd)" \
--dir-tmp-container="$TMP" \
--dir-tmp-host="$TMP" \
--dir-config-container="$CNF" \
--dir-config-host="$CNF" \
"$@"
else
docker run -i --rm \
-e "REACH_EX=$0" \
-e "REACH_CONNECTOR_MODE" \
-e "REACH_DEBUG" \
-e "REACH_IDE" \
-e "REACH_RPC_KEY" \
-e "REACH_RPC_PORT" \
-e "REACH_RPC_SERVER" \
-e "REACH_RPC_TLS_CRT" \
-e "REACH_RPC_TLS_KEY" \
-e "REACH_RPC_TLS_PASSPHRASE" \
-e "REACH_RPC_TLS_REJECT_UNVERIFIED" \
-e "REACH_VERSION" \
-e "CI" \
-e "SHELL" \
-u "$(id -ru):$(id -rg)" \
-v "$(pwd):/app/src" \
-v "$TMP:/app/tmp" \
-v "$CNF:/app/config" \
"$IMG" --dir-project-host="$(pwd)" --dir-tmp-host="$TMP" --dir-config-host="$CNF" "$@"
fi
}
run_s () {
chmod 700 "$TMP/out.sh"
sh -ac "$TMP/out.sh" "$0"
}
for DEP in make curl docker docker-compose; do
if ! (which "${DEP}" >/dev/null 2>&1); then
echo "Reach relies on an installation of ${DEP}"
exit 1
fi
done
if [ ! "$CIRCLECI" = "true" ] && [ "$(docker image ls -q $IMG)" = '' ]; then
if ! docker pull "$IMG"; then exit 1; fi
fi
run_d "$@"
case "$?" in
42) run_s; case "$?" in
60) rm -r "$TMP" && exit 60 ;; # Updates available
0) [ -d "$TMP" ] && rm -r "$TMP"; exit 0 ;;
*) [ -z "$(ls -A "$TMP")" ] && rm -r "$TMP"; exit 1 ;;
esac
;;
50) docker pull "$IMG" && curl https://docs.reach.sh/reach -o "$0" && chmod +x "$0" && rm -r "$TMP" && exit 0 ;;
60) rm -r "$TMP" && exit 60 ;; # Updates available
0) rm -r "$TMP" ;;
*) [ -z "$(ls -A "$TMP")" ] && rm -r "$TMP"; exit 1 ;;
esac