This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·241 lines (208 loc) · 8.45 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
set -e
# Read a single char from /dev/tty, prompting with "$*"
# Note: pressing enter will return a null string. Perhaps a version terminated with X and then remove it in caller?
# See https://unix.stackexchange.com/a/367880/143394 for dealing with multi-byte, etc.
function get_keypress {
local REPLY IFS=
>/dev/tty printf '%s' "$*"
[[ $ZSH_VERSION ]] && read -rk1 # Use -u0 to read from STDIN
# See https://unix.stackexchange.com/q/383197/143394 regarding '\n' -> ''
[[ $BASH_VERSION ]] && </dev/tty read -rn1
printf '%s' "$REPLY"
}
# Get a y/n from the user, return yes=0, no=1 enter=$2
# Prompt using $1.
# If set, return $2 on pressing enter, useful for cancel or defualting
function get_yes_keypress {
local prompt="${1:-Are you sure} [y/n]? "
local enter_return=$2
local REPLY
# [[ ! $prompt ]] && prompt="[y/n]? "
while REPLY=$(get_keypress "$prompt"); do
[[ $REPLY ]] && printf '\n' # $REPLY blank if user presses enter
case "$REPLY" in
Y|y) return 0;;
N|n) return 1;;
'') [[ $enter_return ]] && return "$enter_return"
esac
done
}
# Credit: http://unix.stackexchange.com/a/14444/143394
# Prompt to confirm, defaulting to NO on <enter>
# Usage: confirm "Dangerous. Are you sure?" && rm *
function confirm {
local prompt="${*:-Are you sure} [y/N]? "
get_yes_keypress "$prompt" 1
}
# Prompt to confirm, defaulting to YES on <enter>
function confirm_yes {
local prompt="${*:-Are you sure}"
get_yes_keypress "$prompt" 0
}
promptAndWaitForAnyKeyPress() {
printf "%s" "$1"
read -r
}
# =============================================================================== Pre-run warnings
printf "\n\nWARNING: If you didn't run this script with the syntax '. ./setup.sh' or 'source ./setup.sh' you will
need to open a new terminal window or source your bash profile to have the environment variables set. \n\n"
promptAndWaitForAnyKeyPress "If you are happy with how you ran the script then press any key to continue... OR ctrl+c to exit."
printf "\n"
if [[ "$SHELL" == *"bash"* ]]; then
read -rp "Press 1 to use ~/.bashrc. Press 2 to use ~/.bash_profile? " opt
case $opt in
"1") profileHome=~/.bashrc ;;
"2") profileHome=~/.bash_profile ;;
*)
echo "Please enter 1 or 2"
exit
;;
esac
elif [[ "$SHELL" == *"zsh"* ]]; then
profileHome=~/.zshrc
fi
# =============================================================================== Detect system
operatingSystem=$(uname -s)
printf "\n\nDetected Operating System: '%s'\n\n" "$operatingSystem"
# =============================================================================== Brew(Mac Only)
if [[ ${operatingSystem} == "Darwin" ]]; then
if ! command -v brew &> /dev/null ; then
confirm_yes "Install Homebrew? Will require manual setup if no." || exit 1
printf "\n\nHomeBrew installation not detected: Installing Brew!\n\n"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
brew update
fi
# =============================================================================== Sudo(Linux Only)
elif [[ ${operatingSystem} == "Linux" ]]; then
printf "\n\nUpdating Repositories...\n\n"
sudo apt-get update
fi
# =============================================================================== Node
if ! command -v node &> /dev/null; then
printf "\n\nNode installation not found.\n\n"
if confirm_yes "Install node?"; then
if [[ ${operatingSystem} == "Linux" ]]; then
sudo snap install node --classic
elif [[ ${operatingSystem} == "Darwin" ]]; then
brew install node
fi
fi
fi
# =============================================================================== Yarn
if ! command -v yarn &> /dev/null; then
printf "\n\nYarn installation not found.\n\n"
if confirm_yes "Install yarn globally with homebrew?"; then
if [[ ${operatingSystem} == "Linux" ]]; then
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn
elif [[ ${operatingSystem} == "Darwin" ]]; then
brew install yarn
fi
fi
fi
# =============================================================================== Direnv
if ! command -v direnv &> /dev/null; then
printf "\n\ndirenv installation not found.\n\n"
if confirm_yes "Install direnv to manage TSR's environment variables?"; then
if [[ ${operatingSystem} == "Linux" ]]; then
sudo apt-get install direnv
elif [[ ${operatingSystem} == "Darwin" ]]; then
brew install direnv
fi
if ! grep -q "direnv hook" "${profileHome}"; then
echo "eval \"\$(direnv hook ${SHELL})\"" >>$profileHome
fi
fi
fi
# =============================================================================== Java 17
installOpenJDKMac() {
if confirm_yes "Would you like to install OpenJDK17 with homebrew and manage Java with the jenv package?"; then
printf "\n\nTapping Adoptium (AdoptOpenJDK)...\n\n"
brew install jenv
# configure jenv
jenv init -
printf "Added jenv to your PATH in %s" $profileHome
echo "export PATH=""$HOME""/.jenv/bin:""$PATH""" >> $profileHome
echo "eval ""$(jenv init -)""" >> $profileHome
# add or replace $JAVA_HOME
if ! grep -q "JAVA_HOME" "${profileHome}"; then
printf "Added JAVA_HOME to your %s" $profileHome
echo "JAVA_HOME=""$HOME""/.jenv/shims/java" >>$profileHome
else
sed -i '' 's#^JAVA_HOME=.*$#JAVA_HOME="$HOME/.jenv/shims/java"#' $profileHome
fi
# If upgrading from previous adoptopenjdk versions of java in setup, uninstall
printf "AdoptOpenJDK has been officially discontinued upstream.
To remove previous installations run the following:
brew uninstall adoptopenjdk15
brew untap AdoptOpenJDK/openjdk
"
brew tap homebrew/cask-versions
printf "\n\nInstalling AdoptOpenJDK17...\n\n"
brew install --cask temurin17
# configure jenv with temurin17 installation
jenv add /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
jenv local openjdk64-17.0.2
else
printf "Please setup Java17's manual configuration then rerun the setup script."
exit 1
fi
}
installOpenJDKUbuntu() {
# uses `update-alternatives` to manage java versions
if confirm_yes "Would you like to install OpenJDK17?"; then
printf "Downloading OpenJDK17 tar"
curl https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz --output openjdk-17_linux-x64_bin.tar.gz
sudo mkdir -p /usr/java
sudo tar -xzf openjdk-17_linux-x64_bin.tar.gz -C /usr/java
rm openjdk-17_linux-x64_bin.tar.gz
JAVA_HOME="/usr/java/jdk-17.0.2"
if ! grep -q "JAVA_HOME" "${profileHome}"; then
printf "Added JAVA_HOME to your %s" $profileHome
echo "JAVA_HOME=$JAVA_HOME" >>$profileHome
else
sed -i 's#^JAVA_HOME=.*$#JAVA_HOME=/usr/java/jdk-17.0.2#' $profileHome
fi
sudo update-alternatives --install /usr/bin/java java "${JAVA_HOME%*/}"/bin/java 20000
sudo update-alternatives --install /usr/bin/javac javac "${JAVA_HOME%*/}"/bin/javac 20000
sudo update-alternatives --config java
sudo update-alternatives --config javac
else
printf "Please setup Java17's manual configuration then rerun the setup script."
exit 1
fi
}
printf "\n\nChecking Java installation...\n\n"
if ! command -v java &> /dev/null; then
printf "\n\nJava installation not found: Installing Java!\n\n"
if [[ ${operatingSystem} == "Linux" ]]; then
installOpenJDKUbuntu
elif [[ ${operatingSystem} == "Darwin" ]]; then
installOpenJDKMac
fi
else
FULL_JAVA_VER=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\"/\1/p;' | cut -c1-6)
JAVA_VER=$(echo "$FULL_JAVA_VER" | cut -c1-2)
if [[ ${JAVA_VER} != "17" ]]; then
printf "\n\nFound Java installation with incorrect version: %s: Installing OpenJDK17!\n\n" "$FULL_JAVA_VER"
if [[ ${operatingSystem} == "Linux" ]]; then
installOpenJDKUbuntu
elif [[ ${operatingSystem} == "Darwin" ]]; then
installOpenJDKMac
fi
fi
fi
printf "\n\nRequired software downloaded successfully.\n\n"
./docker_go.sh
## =============================================================================== Linking dependencies
printf "\n\n\nLinking dependencies...\n\n\n"
pushd client || exit
yarn install
yarn build
popd || exit
./gradlew clean assemble
printf "\n\n\nYour setup is complete.\nYou may need to run a direnv allow to approve the contents of .envrc\n\n"