-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup-standalone-env.sh
executable file
·203 lines (153 loc) · 5.93 KB
/
setup-standalone-env.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
#!/bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Load common env ..."
source $SCRIPT_DIR/../../envs/.env
if [[ ! -e ${SCRIPT_DIR}/../../envs/user.env ]]; then
echo "${SCRIPT_DIR}/../../envs/user.env doesn't exist. Runs ./server/envs/generate_user_env.sh to generate it."
$SCRIPT_DIR/../../envs/generate_user_env.sh
fi
echo "Load user env ..."
source $SCRIPT_DIR/../../envs/user.env
if [[ -z ${DM_PACKAGES_URL} ]]; then
echo "[setup] Missing DM_PACKAGES_URL environment variable"
exit 1
fi
# Platform SDKs
if [[ ! -e ${PLATFORMSDK_DIR} ]]; then
mkdir -p ${PLATFORMSDK_DIR}
echo "[setup] Created SDK directory at ${PLATFORMSDK_DIR}."
fi
# Logs
if [[ ! -e ${LOG_DIRECTORY} ]]; then
mkdir -p ${LOG_DIRECTORY}
echo "[setup] Created logs directory at ${LOG_DIRECTORY}."
fi
CURL_CMD=$(which curl)
TMP_DOWNLOAD_DIR=/tmp/_extender_download
function check_url() {
local url=$1
echo "[check url]" ${url}
STATUS_CODE=$(curl --head --write-out "%{http_code}" --silent --output /dev/null ${url})
if (( STATUS_CODE == 200 ))
then
echo "${STATUS_CODE}"
else
echo -e "\033[0;31mError: Url returned status code ${STATUS_CODE}: ${url} \033[m"
exit 1
fi
}
function download_package() {
local package_name=$1
local out_package_name=$package_name
local url=${DM_PACKAGES_URL}/${package_name}.tar.gz
if [[ "$package_name" == *darwin ]]; then
out_package_name=$(sed "s/.darwin//g" <<< ${package_name})
fi
# if it has grown old, we want to know as soon as possible
check_url ${url}
if [[ ! -e ${PLATFORMSDK_DIR}/${out_package_name} ]]; then
mkdir -p ${TMP_DOWNLOAD_DIR}
echo "[setup] Downloading" ${url} "to" ${TMP_DOWNLOAD_DIR}
${CURL_CMD} ${url} | tar xz -C ${TMP_DOWNLOAD_DIR}
# The folder inside the package is something like "iPhoneOS.sdk"
local folder=`(cd ${TMP_DOWNLOAD_DIR} && ls)`
echo "[setup] Found folder" ${folder}
if [[ -n ${folder} ]]; then
mv ${TMP_DOWNLOAD_DIR}/${folder} ${PLATFORMSDK_DIR}/${out_package_name}
echo "[setup] Installed" ${PLATFORMSDK_DIR}/${package_name}
else
echo "[setup] Failed to install" ${package_name}
fi
rm -rf ${TMP_DOWNLOAD_DIR}
else
echo "[setup] Package" ${PLATFORMSDK_DIR}/${package_name} "already installed"
fi
}
function download_zig() {
local url=$1
local package_name=$2
local folder=$3
local full_url=${url}/${package_name}
# if it has grown old, we want to know as soon as possible
check_url ${full_url}
if [[ ! -e ${folder} ]]; then
mkdir -p ${TMP_DOWNLOAD_DIR}/zig-tmp
echo "[setup] Downloading" ${url}/${package_name} "to" ${TMP_DOWNLOAD_DIR}/zig-tmp
${CURL_CMD} ${url}/${package_name} | tar xJ --strip-components=1 -C ${TMP_DOWNLOAD_DIR}/zig-tmp
echo "[setup] Rename folder to" ${folder}
mv ${TMP_DOWNLOAD_DIR}/zig-tmp ${folder}
rm -rf ${TMP_DOWNLOAD_DIR}
echo "[setup] Installed" ${folder}
else
echo "[setup] Package" ${folder} "already installed"
fi
}
function install_dotnet() {
# https://dotnet.microsoft.com/en-us/download/dotnet/9.0
# https://github.com/dotnet/core/blob/main/release-notes/9.0/install.md
local version="9.0.100-rc.2.24474.11"
if [[ ! -e ${DOTNET_ROOT} ]]; then
mkdir -p ${DOTNET_ROOT}
local os=$(uname)
if [ "Darwin" == "${os}" ] || [ "Linux" == "${os}" ]; then
echo "Downloading dotnet-install.sh ..."
${CURL_CMD} -L https://dot.net/v1/dotnet-install.sh --output ./dotnet-install.sh
chmod +x ./dotnet-install.sh
echo "Installing dotnet ..."
./dotnet-install.sh --version ${version} --install-dir ${DOTNET_ROOT}
rm ./dotnet-install.sh
else
echo "Windows not supported standalone yet"
# https://github.com/dotnet/core/blob/main/release-notes/9.0/install.md
fi
echo "[setup] Installed dotnet"
else
echo "[setup] Package" ${DOTNET_ROOT} "already installed"
fi
local DOTNET=${DOTNET_ROOT}/dotnet
DOTNET_VERSION=$(${DOTNET} --info | grep -e "Host:" -A 1 | grep -e "Version:" | awk '{print $2}')
echo ${DOTNET_VERSION} > ${DOTNET_VERSION_FILE}
echo "[setup] Using dotnet:" ${DOTNET} " version:" $(${DOTNET} --version) " sdk:" ${DOTNET_VERSION}
if [[ ! -e ${NUGET_PACKAGES} ]]; then
mkdir -p ${NUGET_PACKAGES}
echo "[setup] Created Nuget directory at ${NUGET_PACKAGES}."
fi
echo "Set Nuget package folder to ${NUGET_PACKAGES}"
echo "${DOTNET} nuget config set globalPackagesFolder ${NUGET_PACKAGES}"
${DOTNET} nuget config set globalPackagesFolder ${NUGET_PACKAGES}
echo "[setup] Using NUGET_PACKAGES=${NUGET_PACKAGES}"
}
if [[ $(uname) == "Darwin" ]]; then
echo "Setup Macos environment"
echo "Load macos environment..."
source $SCRIPT_DIR/../../envs/macos.env
# Keep Apple's naming convention to avoid bugs
PACKAGES=(
iPhoneOS${IOS_16_VERSION}.sdk
iPhoneOS${IOS_17_VERSION}.sdk
iPhoneSimulator${IOS_16_VERSION}.sdk
iPhoneSimulator${IOS_17_VERSION}.sdk
MacOSX${MACOS_13_VERSION}.sdk
MacOSX${MACOS_14_VERSION}.sdk
XcodeDefault${XCODE_14_VERSION}.xctoolchain.darwin
XcodeDefault${XCODE_15_VERSION}.xctoolchain.darwin
)
function download_packages() {
for package_name in ${PACKAGES[@]}; do
download_package ${package_name}
done
}
echo "[setup] Downloading packages"
download_packages
fi
ZIG_ARCH=x86_64
if [[ $(uname -m) == "arm64" ]]; then
ZIG_ARCH=aarch64
fi
ZIG_PACKAGE_NAME=zig-macos-${ZIG_ARCH}-${ZIG_VERSION}.tar.xz
ZIG_URL=https://ziglang.org/download/${ZIG_VERSION}
echo "[setup] Downloading Zig"
download_zig ${ZIG_URL} ${ZIG_PACKAGE_NAME} ${ZIG_PATH_0_11}
echo "[setup] Installing dotnet"
install_dotnet