forked from sickcodes/Docker-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
348 lines (309 loc) · 10.1 KB
/
test.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/bash
# ____ __ ____ ______ __
# / __ \____ _____/ /_____ _____/ __ \/ ___/ |/ /
# / / / / __ \/ ___/ //_/ _ \/ ___/ / / /\__ \| /
# / /_/ / /_/ / /__/ ,< / __/ / / /_/ /___/ / |
# /_____/\____/\___/_/|_|\___/_/ \____//____/_/|_| TESTS
#
# Title: Docker-OSX (Mac on Docker)
# Author: Sick.Codes https://twitter.com/sickcodes
# Version: 4.2
# License: GPLv3+
# Repository: https://github.com/sickcodes/Docker-OSX
# Website: https://sick.codes
#
# Status: Used internally to auto build, run and test images on DO.
#
help_text="Usage: ./test.sh --branch <string> --repo <string>
General options:
--branch, -b <string> Git branch, default is master
--repo, -r <url> Alternative link to build
--mirror-country, -m <SS> Two letter country code for Arch mirrors
--docker-username, -u <string> Docker hub username
--docker-password, -p <string> Docker hub password
--vnc-password, -v <string> Choose a VNC passwd.
Flags
--no-cache, -n Enable --no-cache (default already)
--no-no-cache, -nn Disable --no-cache docker builds
--help, -h, help Display this help and exit
"
# set -xeuf -o pipefail
# gather arguments
while (( "$#" )); do
case "${1}" in
--help | -h | h | help )
echo "${help_text}" && exit 0
;;
--branch=* | -b=* )
export BRANCH="${1#*=}"
shift
;;
--branch* | -b* )
export BRANCH="${2}"
shift
shift
;;
--repo=* | -r=* )
export REPO="${1#*=}"
shift
;;
--repo* | -r* )
export REPO="${2}"
shift
shift
;;
--mirror-country=* | -m=* )
export MIRROR_COUNTRY="${1#*=}"
shift
;;
--mirror-country* | -m* )
export MIRROR_COUNTRY="${2}"
shift
shift
;;
--vnc-password=* | -v=* | --vnc-passwd=* )
export VNC_PASSWORD="${1#*=}"
shift
;;
--vnc-password* | -v* | --vnc-passwd* )
export VNC_PASSWORD="${2}"
shift
shift
;;
--docker-username=* | -u=* )
export DOCKER_USERNAME="${1#*=}"
shift
;;
--docker-username* | -u* )
export DOCKER_USERNAME="${2}"
shift
shift
;;
--docker-password=* | -p=* )
export DOCKER_PASSWORD="${1#*=}"
shift
;;
--docker-password* | -p* )
export DOCKER_PASSWORD="${2}"
shift
shift
;;
--no-cache | -n )
export NO_CACHE='--no-cache'
shift
;;
--no-no-cache | -nn )
export NO_CACHE=
shift
;;
*)
echo "Invalid option: ${1}"
exit 1
;;
esac
done
BRANCH="${BRANCH:=master}"
REPO="${REPO:=https://github.com/sickcodes/Docker-OSX.git}"
VNC_PASSWORD="${VNC_PASSWORD:=testing}"
MIRROR_COUNTRY="${MIRROR_COUNTRY:=US}"
NO_CACHE="${NO_CACHE:=--no-cache}"
TEST_BUILDS=(
'docker-osx:naked'
'docker-osx:naked-auto'
'docker-osx:auto'
)
TEST_BUILDS=(
'docker-osx:naked'
'docker-osx:naked-auto'
'docker-osx:auto'
)
VERSION_BUILDS=(
'high-sierra'
'mojave'
'catalina'
'big-sur'
'monterey'
'ventura'
)
warning () {
clear
for j in {15..1}; do
echo "############# WARNING: THIS SCRIPT IS NOT INTENDED FOR USE BY ################"
echo "############# IT IS USED BY THE PROJECT TO BUILD AND PUSH TO DOCKERHUB #######"
echo ""
echo " Press Ctrl C to stop. "
MAX_COLS=$((${COLUMNS}/2))
printf "$j %.0s" {1..20}
echo
sleep 1
done
}
install_docker () {
apt remove docker docker-engine docker.io containerd runc -y \
; apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& apt-key fingerprint 0EBFCD88 \
&& > /etc/apt/sources.list.d/docker.list \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
&& apt update -y \
&& apt install docker-ce docker-ce-cli containerd.io -y \
&& usermod -aG docker "${USER}" \
&& su hook docker run --rm hello-world
}
install_vnc () {
apt update -y \
&& apt install xorg openbox tigervnc-standalone-server tigervnc-common tigervnc-xorg-extension tigervnc-viewer -y \
&& mkdir -p ${HOME}/.vnc \
&& touch ~/.vnc/config \
&& tee -a ~/.vnc/config <<< 'geometry=1920x1080' \
&& tee -a ~/.vnc/config <<< 'localhost' \
&& tee -a ~/.vnc/config <<< 'alwaysshared' \
&& touch ./vnc.sh \
&& printf '\n%s\n' \
'sudo rm -f /tmp/.X99-lock' \
'export DISPLAY=:99' \
'/usr/bin/Xvnc -geometry 1920x1080 -rfbauth ~/.vnc/passwd :99 &' > ./vnc.sh \
&& tee vncpasswd_file <<< "${VNC_PASSWORD:=testing}" && echo "${VNC_PASSWORD:="$(tr -dc '[:graph:]' </dev/urandom | head -c8)"}" \
&& vncpasswd -f < vncpasswd_file > ${HOME}/.vnc/passwd \
&& chmod 600 ~/.vnc/passwd \
&& apt install qemu qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager -y \
&& sudo systemctl enable libvirtd.service \
&& sudo systemctl enable virtlogd.service \
&& echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs \
&& sudo modprobe kvm \
&& echo 'export DISPLAY=:99' >> ~/.bashrc \
&& printf '\n\n\n\n%s\n%s\n\n\n\n' '===========VNC_PASSWORD========== ' "$(<vncpasswd_file)"
# ufw allow 5999
}
install_scrotcat () {
apt update -y
apt install git curl wget vim xvfb scrot build-essential sshpass -y
git clone https://github.com/stolk/imcat.git
make -C ./imcat
sudo cp ./imcat/imcat /usr/bin/imcat
touch /usr/bin/scrotcat
tee /usr/bin/scrotcat <<< '/usr/bin/imcat <(scrot -o /dev/stdout)'
chmod +x /usr/bin/scrotcat
}
export_display_99 () {
touch ~/.bashrc
tee -a ~/.bashrc <<< 'export DISPLAY=:99'
export DISPLAY=:99
}
start_xvfb () {
nohup Xvfb :99 -screen 0 1920x1080x16 &
}
start_vnc () {
nohup bash vnc.sh &
}
enable_kvm () {
echo 1 | tee /sys/module/kvm/parameters/ignore_msrs
}
clone_repo () {
git clone --branch="${1}" "${2}" Docker-OSX
}
docker-osx:naked () {
docker build ${NO_CACHE} \
--squash \
--build-arg RANKMIRRORS=true \
--build-arg MIRROR_COUNTRY="${MIRROR_COUNTRY}" \
-f ./Dockerfile.naked \
-t docker-osx:naked .
docker tag docker-osx:naked sickcodes/docker-osx:naked
}
docker-osx:naked-auto () {
docker build ${NO_CACHE} \
--squash \
--build-arg RANKMIRRORS=true \
--build-arg MIRROR_COUNTRY="${MIRROR_COUNTRY}" \
-f ./Dockerfile.naked-auto \
-t docker-osx:naked-auto .
docker tag docker-osx:naked-auto sickcodes/docker-osx:naked-auto
}
docker-osx:auto () {
docker build ${NO_CACHE} \
--build-arg RANKMIRRORS=true \
--build-arg MIRROR_COUNTRY="${MIRROR_COUNTRY}" \
-f ./Dockerfile.auto \
-t docker-osx:auto .
docker tag docker-osx:auto sickcodes/docker-osx:auto
}
# docker-osx:auto-big-sur () {
# docker build ${NO_CACHE} \
# --build-arg RANKMIRRORS=true \
# --build-arg MIRROR_COUNTRY="${MIRROR_COUNTRY}" \
# --build-arg IMAGE_URL='https://images.sick.codes/mac_hdd_ng_auto_big_sur.img' \
# -f ./Dockerfile.auto \
# -t docker-osx:auto-big-sur .
# docker tag docker-osx:auto-big-sur sickcodes/docker-osx:auto-big-sur
# }
docker-osx:version () {
SHORTNAME="${1}"
docker build ${NO_CACHE} \
--build-arg BRANCH="${BRANCH}" \
--build-arg RANKMIRRORS=true \
--build-arg SHORTNAME="${SHORTNAME}" \
--build-arg MIRROR_COUNTRY="${MIRROR_COUNTRY}" \
-f ./Dockerfile \
-t "docker-osx:${SHORTNAME}" .
docker tag "docker-osx:${SHORTNAME}" "sickcodes/docker-osx:${SHORTNAME}"
}
reset_docker_hard () {
tee /etc/docker/daemon.json <<'EOF'
{
"experimental": true
}
EOF
systemctl disable --now docker
systemctl disable --now docker.socket
systemctl stop docker
systemctl stop docker.socket
rm -rf /var/lib/docker
systemctl enable --now docker
}
warning
tee -a ~/.bashrc <<EOF
export DEBIAN_FRONTEND=noninteractive
export TZ=UTC
EOF
export DEBIAN_FRONTEND=noninteractive
export TZ=UTC
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime
tee -a /etc/timezone <<< "${TZ}"
apt update -y
apt-get install keyboard-configuration -y
docker -v | grep '\ 20\.\|\ 19\.' || install_docker
yes | apt install -y --no-install-recommends tzdata -y
install_scrotcat
yes | install_vnc
export_display_99
apt install xvfb -y
start_xvfb
# start_vnc
enable_kvm
reset_docker_hard
# echo killall Xvfb
clone_repo "${BRANCH}" "${REPO}"
cd ./Docker-OSX
git pull
for SHORTNAME in "${VERSION_BUILDS[@]}"; do
docker-osx:version "${SHORTNAME}"
done
docker tag docker-osx:catalina sickcodes/docker-osx:latest
for TEST_BUILD in "${TEST_BUILDS[@]}"; do
"${TEST_BUILD}"
done
# boot each image and test
bash ./tests/boot-images.sh || exit 1
if [[ "${DOCKER_USERNAME}" ]] && [[ "${DOCKER_PASSWORD}" ]]; then
docker login --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}" \
&& for SHORTNAME in "${VERSION_BUILDS[@]}"; do
docker push "sickcodes/docker-osx:${SHORTNAME}"
done \
&& touch PUSHED
docker push sickcodes/docker-osx:naked
docker push sickcodes/docker-osx:auto
docker push sickcodes/docker-osx:naked-auto
fi
# connect remotely to your server to use VNC
# ssh -N [email protected] -L 5999:127.0.0.1:5999