1 | #!/bin/bash
|
---|
2 | ## @file
|
---|
3 | # Post installation script template for local gateway image.
|
---|
4 | #
|
---|
5 | # Note! This script expects to be running chrooted (inside new sytem).
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2020 Oracle Corporation
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | # available from http://www.virtualbox.org. This file is free software;
|
---|
13 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | # General Public License (GPL) as published by the Free Software
|
---|
15 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | #
|
---|
19 |
|
---|
20 |
|
---|
21 | #
|
---|
22 | # Globals.
|
---|
23 | #
|
---|
24 | MY_TARGET="/mnt/sysimage"
|
---|
25 | MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
|
---|
26 | MY_CHROOT_CDROM="/cdrom"
|
---|
27 | MY_CDROM_NOCHROOT="/tmp/vboxcdrom"
|
---|
28 | MY_EXITCODE=0
|
---|
29 | MY_DEBUG="" # "yes"
|
---|
30 |
|
---|
31 | @@VBOX_COND_HAS_PROXY@@
|
---|
32 | PROXY="@@VBOX_INSERT_PROXY@@"
|
---|
33 | export http_proxy="${PROXY}"
|
---|
34 | export https_proxy="${PROXY}"
|
---|
35 | echo "HTTP proxy is ${http_proxy}" | tee -a "${MY_LOGFILE}"
|
---|
36 | echo "HTTPS proxy is ${https_proxy}" | tee -a "${MY_LOGFILE}"
|
---|
37 | @@VBOX_COND_END@@
|
---|
38 |
|
---|
39 | #
|
---|
40 | # Do we need to exec using target bash? If so, we must do that early
|
---|
41 | # or ash will bark 'bad substitution' and fail.
|
---|
42 | #
|
---|
43 | if [ "$1" = "--need-target-bash" ]; then
|
---|
44 | # Try figure out which directories we might need in the library path.
|
---|
45 | if [ -z "${LD_LIBRARY_PATH}" ]; then
|
---|
46 | LD_LIBRARY_PATH="${MY_TARGET}/lib"
|
---|
47 | fi
|
---|
48 | for x in \
|
---|
49 | ${MY_TARGET}/lib \
|
---|
50 | ${MY_TARGET}/usr/lib \
|
---|
51 | ${MY_TARGET}/lib/*linux-gnu/ \
|
---|
52 | ${MY_TARGET}/lib32/ \
|
---|
53 | ${MY_TARGET}/lib64/ \
|
---|
54 | ${MY_TARGET}/usr/lib/*linux-gnu/ \
|
---|
55 | ${MY_TARGET}/usr/lib32/ \
|
---|
56 | ${MY_TARGET}/usr/lib64/ \
|
---|
57 | ;
|
---|
58 | do
|
---|
59 | if [ -e "$x" ]; then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${x}"; fi;
|
---|
60 | done
|
---|
61 | export LD_LIBRARY_PATH
|
---|
62 |
|
---|
63 | # Append target bin directories to the PATH as busybox may not have tee.
|
---|
64 | PATH="${PATH}:${MY_TARGET}/bin:${MY_TARGET}/usr/bin:${MY_TARGET}/sbin:${MY_TARGET}/usr/sbin"
|
---|
65 | export PATH
|
---|
66 |
|
---|
67 | # Drop the --need-target-bash argument and re-exec.
|
---|
68 | shift
|
---|
69 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
70 | echo "** Relaunching using ${MY_TARGET}/bin/bash $0 $*" >> "${MY_LOGFILE}"
|
---|
71 | echo "** LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> "${MY_LOGFILE}"
|
---|
72 | echo "** PATH=${PATH}" >> "${MY_LOGFILE}"
|
---|
73 | exec "${MY_TARGET}/bin/bash" "$0" "$@"
|
---|
74 | fi
|
---|
75 |
|
---|
76 |
|
---|
77 | #
|
---|
78 | # Commands.
|
---|
79 | #
|
---|
80 |
|
---|
81 | # Logs execution of a command.
|
---|
82 | log_command()
|
---|
83 | {
|
---|
84 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
85 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
86 | echo "** Executing: $*" >> "${MY_LOGFILE}"
|
---|
87 | "$@" 2>&1 | tee -a "${MY_LOGFILE}"
|
---|
88 | MY_TMP_EXITCODE="${PIPESTATUS[0]}" # bashism - whatever.
|
---|
89 | if [ "${MY_TMP_EXITCODE}" != "0" ]; then
|
---|
90 | if [ "${MY_TMP_EXITCODE}" != "${MY_IGNORE_EXITCODE}" ]; then
|
---|
91 | echo "** exit code: ${MY_TMP_EXITCODE}" | tee -a "${MY_LOGFILE}"
|
---|
92 | MY_EXITCODE=1;
|
---|
93 | else
|
---|
94 | echo "** exit code: ${MY_TMP_EXITCODE} (ignored)" | tee -a "${MY_LOGFILE}"
|
---|
95 | fi
|
---|
96 | fi
|
---|
97 | }
|
---|
98 |
|
---|
99 | # Logs execution of a command inside the target.
|
---|
100 | log_command_in_target()
|
---|
101 | {
|
---|
102 | log_command chroot "${MY_TARGET}" "$@"
|
---|
103 | }
|
---|
104 |
|
---|
105 | # Checks if $1 is a command on the PATH inside the target jail.
|
---|
106 | chroot_which()
|
---|
107 | {
|
---|
108 | for dir in /bin /usr/bin /sbin /usr/sbin;
|
---|
109 | do
|
---|
110 | if [ -x "${MY_TARGET}${dir}/$1" ]; then
|
---|
111 | return 0;
|
---|
112 | fi
|
---|
113 | done
|
---|
114 | return 1;
|
---|
115 | }
|
---|
116 |
|
---|
117 | #
|
---|
118 | # Log header.
|
---|
119 | #
|
---|
120 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
121 | echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
|
---|
122 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
123 | echo "** Started: $0 $*" >> "${MY_LOGFILE}"
|
---|
124 |
|
---|
125 |
|
---|
126 | #
|
---|
127 | # We want the ISO available inside the target jail.
|
---|
128 | #
|
---|
129 | if [ -d "${MY_TARGET}${MY_CHROOT_CDROM}" ]; then
|
---|
130 | MY_RMDIR_TARGET_CDROM=
|
---|
131 | else
|
---|
132 | MY_RMDIR_TARGET_CDROM="yes"
|
---|
133 | log_command mkdir -p ${MY_TARGET}${MY_CHROOT_CDROM}
|
---|
134 | fi
|
---|
135 |
|
---|
136 | if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
|
---|
137 | MY_UNMOUNT_TARGET_CDROM=
|
---|
138 | echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
|
---|
139 | else
|
---|
140 | MY_UNMOUNT_TARGET_CDROM="yes"
|
---|
141 | log_command mount -o bind "${MY_CDROM_NOCHROOT}" "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
142 | if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
|
---|
143 | echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
|
---|
144 | else
|
---|
145 | echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
|
---|
146 | fi
|
---|
147 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
148 | log_command find "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
149 | fi
|
---|
150 | fi
|
---|
151 |
|
---|
152 |
|
---|
153 | #
|
---|
154 | # Debug
|
---|
155 | #
|
---|
156 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
157 | log_command id
|
---|
158 | log_command ps
|
---|
159 | log_command ps auxwwwf
|
---|
160 | log_command env
|
---|
161 | log_command df
|
---|
162 | log_command mount
|
---|
163 | log_command_in_target df
|
---|
164 | log_command_in_target mount
|
---|
165 | #log_command find /
|
---|
166 | MY_EXITCODE=0
|
---|
167 | fi
|
---|
168 |
|
---|
169 |
|
---|
170 | #
|
---|
171 | # Proxy hack for yum
|
---|
172 | #
|
---|
173 | @@VBOX_COND_HAS_PROXY@@
|
---|
174 | echo "" >> "${MY_TARGET}/etc/yum.conf"
|
---|
175 | echo "proxy=@@VBOX_INSERT_PROXY@@" >> "${MY_TARGET}/etc/yum.conf"
|
---|
176 | @@VBOX_COND_END@@
|
---|
177 |
|
---|
178 | #
|
---|
179 | # Packages needed for GAs.
|
---|
180 | #
|
---|
181 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
182 | echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
|
---|
183 | log_command_in_target yum -y install "kernel-devel-$(uname -r)"
|
---|
184 | log_command_in_target yum -y install "kernel-headers-$(uname -r)"
|
---|
185 | log_command_in_target yum -y install gcc
|
---|
186 | log_command_in_target yum -y install binutils
|
---|
187 | log_command_in_target yum -y install make
|
---|
188 | log_command_in_target yum -y install dkms
|
---|
189 | log_command_in_target yum -y install make
|
---|
190 | log_command_in_target yum -y install bzip2
|
---|
191 | log_command_in_target yum -y install perl
|
---|
192 |
|
---|
193 |
|
---|
194 | #
|
---|
195 | # GAs
|
---|
196 | #
|
---|
197 | @@VBOX_COND_IS_INSTALLING_ADDITIONS@@
|
---|
198 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
199 | echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
|
---|
200 | MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
|
---|
201 | log_command_in_target /bin/bash "${MY_CHROOT_CDROM}/vboxadditions/VBoxLinuxAdditions.run" --nox11
|
---|
202 | log_command_in_target /bin/bash -c "udevadm control --reload-rules" # GAs doesn't yet do this.
|
---|
203 | log_command_in_target /bin/bash -c "udevadm trigger" # (ditto)
|
---|
204 | MY_IGNORE_EXITCODE=
|
---|
205 | log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
|
---|
206 | @@VBOX_COND_END@@
|
---|
207 |
|
---|
208 | #
|
---|
209 | # Local gateway support
|
---|
210 | #
|
---|
211 | log_command_in_target yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
|
---|
212 | #log_command_in_target yum -y update
|
---|
213 | log_command_in_target yum -y install openvpn
|
---|
214 | log_command_in_target yum -y install connect-proxy
|
---|
215 | log_command_in_target usermod -a -G wheel "@@VBOX_INSERT_USER_LOGIN@@"
|
---|
216 |
|
---|
217 | echo "** Creating ${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/cloud-bridge.conf..." | tee -a "${MY_LOGFILE}"
|
---|
218 | cat >"${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/cloud-bridge.conf" <<'EOT'
|
---|
219 | # port 1194
|
---|
220 | # proto udp
|
---|
221 | port 443
|
---|
222 | proto tcp-server
|
---|
223 | dev tap0
|
---|
224 | secret static.key
|
---|
225 | keepalive 10 120
|
---|
226 | compress lz4-v2
|
---|
227 | push "compress lz4-v2"
|
---|
228 | persist-key
|
---|
229 | persist-tun
|
---|
230 | status /var/log/openvpn-status.log
|
---|
231 | log-append /var/log/openvpn.log
|
---|
232 | verb 3
|
---|
233 | EOT
|
---|
234 |
|
---|
235 | echo "** Creating ${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/cloud-bridge.sh..." | tee -a "${MY_LOGFILE}"
|
---|
236 | cat >"${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/cloud-bridge.sh" <<'EOT'
|
---|
237 | # Initialize variables
|
---|
238 | br="br0"
|
---|
239 | tap="tap0"
|
---|
240 | vnic1=$1
|
---|
241 | vnic2=$2
|
---|
242 | vnic2_gw=$3
|
---|
243 | target_mac=$4
|
---|
244 |
|
---|
245 | # Install openvpn if it is missing
|
---|
246 | if ! yum list installed openvpn; then
|
---|
247 | sudo yum -y install openvpn
|
---|
248 | fi
|
---|
249 |
|
---|
250 | # Let openvpn traffic through Linux firewall
|
---|
251 | #sudo iptables -I INPUT -p udp --dport 1194 -j ACCEPT
|
---|
252 | sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
|
---|
253 |
|
---|
254 | # Switch to secondary VNIC
|
---|
255 | sudo ip route change default via $vnic2_gw dev $vnic2
|
---|
256 | sudo ip link set dev $vnic1 down
|
---|
257 |
|
---|
258 | # Bring up the cloud end of the tunnel
|
---|
259 | sudo openvpn --config cloud-bridge.conf --daemon
|
---|
260 |
|
---|
261 | # Use target MAC for primary VNIC
|
---|
262 | sudo ip link set dev $vnic1 address $target_mac
|
---|
263 |
|
---|
264 | # Bridge tap and primary VNIC
|
---|
265 | sudo ip link add name $br type bridge
|
---|
266 | sudo ip link set dev $vnic1 master $br
|
---|
267 | sudo ip link set dev $tap master $br
|
---|
268 |
|
---|
269 | # Bring up all interfaces
|
---|
270 | sudo ip link set dev $tap up
|
---|
271 | sudo ip link set dev $vnic1 up
|
---|
272 | sudo ip link set dev $br up
|
---|
273 | EOT
|
---|
274 | log_command chmod +x "${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/cloud-bridge.sh"
|
---|
275 |
|
---|
276 | echo "** Creating ${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/local-bridge.conf..." | tee -a "${MY_LOGFILE}"
|
---|
277 | cat >"${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/local-bridge.conf" <<'EOT'
|
---|
278 | dev tap0
|
---|
279 | # proto udp
|
---|
280 | # port 1194
|
---|
281 | proto tcp-client
|
---|
282 | port 443
|
---|
283 | persist-key
|
---|
284 | persist-tun
|
---|
285 | secret static.key
|
---|
286 | compress lz4-v2
|
---|
287 | log-append /var/log/openvpn.log
|
---|
288 | verb 3
|
---|
289 | EOT
|
---|
290 |
|
---|
291 | echo "** Creating ${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/local-bridge.sh..." | tee -a "${MY_LOGFILE}"
|
---|
292 | cat >"${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/local-bridge.sh" <<'EOT'
|
---|
293 | echo Complete command line for debugging purposes:
|
---|
294 | echo $0 $*
|
---|
295 |
|
---|
296 | # Make sure we are at home
|
---|
297 | cd ~
|
---|
298 |
|
---|
299 | # Initialize variables
|
---|
300 | user=opc
|
---|
301 | cbr_ip1=$1
|
---|
302 | cbr_ip2=$2
|
---|
303 | target_mac=$3
|
---|
304 | br="br0"
|
---|
305 | tap="tap0"
|
---|
306 | eth="enp0s8"
|
---|
307 |
|
---|
308 | proxy1_ssh=""
|
---|
309 | proxy2_ssh=""
|
---|
310 | proxy2_vpn=""
|
---|
311 | case $4 in
|
---|
312 | HTTP | HTTPS)
|
---|
313 | proxy1_ssh="connect-proxy -w 30 -H $5:$6 %h %p"
|
---|
314 | ;;
|
---|
315 | SOCKS | SOCKS5)
|
---|
316 | proxy1_ssh="connect-proxy -w 30 -S $5:$6 %h %p"
|
---|
317 | ;;
|
---|
318 | SOCKS4)
|
---|
319 | proxy1_ssh="connect-proxy -w 30 -4 -S $5:$6 %h %p"
|
---|
320 | ;;
|
---|
321 | esac
|
---|
322 | case $7 in
|
---|
323 | HTTP | HTTPS)
|
---|
324 | proxy2_ssh="connect-proxy -w 30 -H $8:$9 %h %p"
|
---|
325 | proxy2_vpn="--http-proxy $8 $9"
|
---|
326 | ;;
|
---|
327 | SOCKS | SOCKS5)
|
---|
328 | proxy2_ssh="connect-proxy -w 30 -S $8:$9 %h %p"
|
---|
329 | proxy2_vpn="--socks-proxy $8 $9"
|
---|
330 | ;;
|
---|
331 | SOCKS4)
|
---|
332 | proxy2_ssh="connect-proxy -w 30 -4 -S $8:$9 %h %p"
|
---|
333 | proxy2_vpn="--socks-proxy $8 $9"
|
---|
334 | ;;
|
---|
335 | esac
|
---|
336 |
|
---|
337 | # Generate pre-shared secret and share it with the server, bypassing proxy if necessary
|
---|
338 | /usr/sbin/openvpn --genkey --secret static.key
|
---|
339 | for i in 1 2 3 4
|
---|
340 | do
|
---|
341 | # Go via proxy if set
|
---|
342 | scp ${proxy1_ssh:+ -o ProxyCommand="$proxy1_ssh"} static.key cloud-bridge.conf cloud-bridge.sh $user@$cbr_ip1:
|
---|
343 | if [ $? -eq 0 ]; then break; fi; sleep 15
|
---|
344 | # Go direct even if proxy is set
|
---|
345 | scp static.key cloud-bridge.conf cloud-bridge.sh $user@$cbr_ip1:
|
---|
346 | if [ $? -eq 0 ]; then proxy1_ssh=""; break; fi; sleep 15
|
---|
347 | done
|
---|
348 |
|
---|
349 | # Get metadata info from the cloud bridge
|
---|
350 | for i in 1 2 3 4; do metadata=$(ssh ${proxy1_ssh:+ -o ProxyCommand="$proxy1_ssh"} $user@$cbr_ip1 sudo oci-network-config) && break || sleep 15; done
|
---|
351 |
|
---|
352 | # Extract primary VNIC info
|
---|
353 | vnic1_md=`echo "$metadata"|grep -E "^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+0\s"`
|
---|
354 | vnic1_dev=`echo $vnic1_md|cut -d ' ' -f 8`
|
---|
355 | vnic1_mac=`echo $vnic1_md|cut -d ' ' -f 12`
|
---|
356 | # Extract secondary VNIC info
|
---|
357 | vnic2_md=`echo "$metadata"|grep -E "^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+1\s"`
|
---|
358 | vnic2_dev=`echo $vnic2_md|cut -d ' ' -f 8`
|
---|
359 | vnic2_gw=`echo $vnic2_md|cut -d ' ' -f 5`
|
---|
360 |
|
---|
361 | # Configure secondary VNIC
|
---|
362 | ssh ${proxy1_ssh:+ -o ProxyCommand="$proxy1_ssh"} $user@$cbr_ip1 sudo oci-network-config -c
|
---|
363 |
|
---|
364 | # Bring up the cloud bridge
|
---|
365 | ssh ${proxy2_ssh:+ -o ProxyCommand="$proxy2_ssh"} $user@$cbr_ip2 /bin/sh -x cloud-bridge.sh $vnic1_dev $vnic2_dev $vnic2_gw $target_mac
|
---|
366 | if [ $? -eq 0 ]
|
---|
367 | then
|
---|
368 | # SSH was able to reach cloud via proxy, establish a tunnel via proxy as well
|
---|
369 | sudo /usr/sbin/openvpn $proxy2_vpn --config local-bridge.conf --daemon --remote $cbr_ip2
|
---|
370 | else
|
---|
371 | # Retry without proxy
|
---|
372 | ssh $user@$cbr_ip2 /bin/sh -x cloud-bridge.sh $vnic1_dev $vnic2_dev $vnic2_gw $target_mac
|
---|
373 | # Establish a tunnel to the cloud bridge
|
---|
374 | sudo /usr/sbin/openvpn --config local-bridge.conf --daemon --remote $cbr_ip2
|
---|
375 | fi
|
---|
376 |
|
---|
377 | # Bridge the openvpn tap device and the local Ethernet interface
|
---|
378 | sudo ip link set dev $eth down
|
---|
379 | sudo ip link add name $br type bridge
|
---|
380 | sudo ip link set dev $eth master $br
|
---|
381 | sudo ip link set dev $tap master $br
|
---|
382 |
|
---|
383 | # Bring up all interfaces
|
---|
384 | sudo ip link set dev $tap up
|
---|
385 | sudo ip link set dev $eth up
|
---|
386 | sudo ip link set dev $br up
|
---|
387 | EOT
|
---|
388 | log_command chmod +x "${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/local-bridge.sh"
|
---|
389 |
|
---|
390 | echo "** Creating ${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/.ssh/config..." | tee -a "${MY_LOGFILE}"
|
---|
391 | log_command mkdir "${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/.ssh"
|
---|
392 | cat >"${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/.ssh/config" <<'EOT'
|
---|
393 | Host *
|
---|
394 | StrictHostKeyChecking no
|
---|
395 | EOT
|
---|
396 | log_command chmod 400 "${MY_TARGET}/home/@@VBOX_INSERT_USER_LOGIN@@/.ssh/config"
|
---|
397 |
|
---|
398 | log_command_in_target chown -R @@VBOX_INSERT_USER_LOGIN@@:@@VBOX_INSERT_USER_LOGIN@@ "/home/@@VBOX_INSERT_USER_LOGIN@@"
|
---|
399 |
|
---|
400 | echo '** Creating /etc/systemd/system/keygen.service...' | tee -a "${MY_LOGFILE}"
|
---|
401 | cat >"${MY_TARGET}/etc/systemd/system/keygen.service" <<'EOT'
|
---|
402 | [Unit]
|
---|
403 | Description=Boot-time ssh key pair generator
|
---|
404 | After=vboxadd.service
|
---|
405 |
|
---|
406 | [Service]
|
---|
407 | ExecStart=/bin/sh -c 'su - vbox -c "cat /dev/zero | ssh-keygen -q -N \\\"\\\""'
|
---|
408 | ExecStartPost=/bin/sh -c 'VBoxControl guestproperty set "/VirtualBox/Gateway/PublicKey" "`cat ~vbox/.ssh/id_rsa.pub`" --flags TRANSIENT'
|
---|
409 | Type=oneshot
|
---|
410 | RemainAfterExit=yes
|
---|
411 |
|
---|
412 | [Install]
|
---|
413 | WantedBy=multi-user.target
|
---|
414 | EOT
|
---|
415 | log_command chmod 644 "${MY_TARGET}/etc/systemd/system/keygen.service"
|
---|
416 | log_command_in_target systemctl enable keygen.service
|
---|
417 |
|
---|
418 | echo '** Creating /etc/sudoers.d/020_vbox_sudo...' | tee -a "${MY_LOGFILE}"
|
---|
419 | echo "@@VBOX_INSERT_USER_LOGIN@@ ALL=(ALL) NOPASSWD: ALL" > "${MY_TARGET}/etc/sudoers.d/020_vbox_sudo"
|
---|
420 |
|
---|
421 | #
|
---|
422 | # Test Execution Service.
|
---|
423 | #
|
---|
424 | @@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
|
---|
425 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
426 | echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
|
---|
427 | log_command_in_target test "${MY_CHROOT_CDROM}/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
|
---|
428 | log_command mkdir -p "${MY_TARGET}/opt/validationkit" "${MY_TARGET}/media/cdrom"
|
---|
429 | log_command cp -R ${MY_CDROM_NOCHROOT}/vboxvalidationkit/* "${MY_TARGET}/opt/validationkit/"
|
---|
430 | log_command chmod -R u+rw,a+xr "${MY_TARGET}/opt/validationkit/"
|
---|
431 | if [ -e "${MY_TARGET}/usr/bin/chcon" -o -e "${MY_TARGET}/bin/chcon" -o -e "${MY_TARGET}/usr/sbin/chcon" -o -e "${MY_TARGET}/sbin/chcon" ]; then
|
---|
432 | MY_IGNORE_EXITCODE=1
|
---|
433 | log_command_in_target chcon -R -t usr_t "/opt/validationkit/"
|
---|
434 | MY_IGNORE_EXITCODE=
|
---|
435 | fi
|
---|
436 |
|
---|
437 | # systemd service config:
|
---|
438 | MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
|
---|
439 | test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
|
---|
440 | if [ -d "${MY_UNIT_PATH}" ]; then
|
---|
441 | log_command cp "${MY_TARGET}/opt/validationkit/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
|
---|
442 | log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
|
---|
443 | log_command_in_target systemctl -q enable vboxtxs
|
---|
444 |
|
---|
445 | # System V like:
|
---|
446 | elif [ -e "${MY_TARGET}/etc/init.d/" ]; then
|
---|
447 |
|
---|
448 | # Install the script. On rhel6 scripts are under /etc/rc.d/ with /etc/init.d and /etc/rc?.d being symlinks.
|
---|
449 | if [ -d "${MY_TARGET}/etc/rc.d/init.d/" ]; then
|
---|
450 | MY_INIT_D_PARENT_PATH="${MY_TARGET}/etc/rc.d"
|
---|
451 | log_command ln -s "../../../opt/validationkit/linux/vboxtxs" "${MY_INIT_D_PARENT_PATH}/init.d/"
|
---|
452 | else
|
---|
453 | MY_INIT_D_PARENT_PATH="${MY_TARGET}/etc"
|
---|
454 | log_command ln -s "../../opt/validationkit/linux/vboxtxs" "${MY_INIT_D_PARENT_PATH}/init.d/"
|
---|
455 | fi
|
---|
456 |
|
---|
457 | # Use runlevel management script if found.
|
---|
458 | if chroot_which chkconfig; then # Redhat based sysvinit systems
|
---|
459 | log_command_in_target chkconfig --add vboxtxs
|
---|
460 | elif chroot_which insserv; then # SUSE-based sysvinit systems
|
---|
461 | log_command_in_target insserv vboxtxs
|
---|
462 | elif chroot_which update-rc.d; then # Debian/Ubuntu-based systems
|
---|
463 | log_command_in_target update-rc.d vboxtxs defaults
|
---|
464 | elif chroot_which rc-update; then # Gentoo Linux
|
---|
465 | log_command_in_target rc-update add vboxtxs default
|
---|
466 | # Fall back on hardcoded symlinking.
|
---|
467 | else
|
---|
468 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc0.d/K65vboxtxs"
|
---|
469 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc1.d/K65vboxtxs"
|
---|
470 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc6.d/K65vboxtxs"
|
---|
471 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc2.d/S35vboxtxs"
|
---|
472 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc3.d/S35vboxtxs"
|
---|
473 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc4.d/S35vboxtxs"
|
---|
474 | log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc5.d/S35vboxtxs"
|
---|
475 | fi
|
---|
476 | else
|
---|
477 | echo "** error: Unknown init script system." | tee -a "${MY_LOGFILE}"
|
---|
478 | fi
|
---|
479 |
|
---|
480 | @@VBOX_COND_END@@
|
---|
481 |
|
---|
482 |
|
---|
483 | #
|
---|
484 | # Run user command.
|
---|
485 | #
|
---|
486 | @@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
|
---|
487 | echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
|
---|
488 | log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
|
---|
489 | @@VBOX_COND_END@@
|
---|
490 |
|
---|
491 |
|
---|
492 | #
|
---|
493 | # Unmount the cdrom if we bound it and clean up the chroot if we set it up.
|
---|
494 | #
|
---|
495 | if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
|
---|
496 | echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
|
---|
497 | log_command umount "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
498 | fi
|
---|
499 |
|
---|
500 | if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
|
---|
501 | log_command rmdir "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
502 | fi
|
---|
503 |
|
---|
504 |
|
---|
505 | #
|
---|
506 | # Log footer.
|
---|
507 | #
|
---|
508 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
509 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
510 | echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
|
---|
511 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
512 |
|
---|
513 | exit ${MY_EXITCODE}
|
---|
514 |
|
---|