]> git.proxmox.com Git - mirror_lxc.git/blob - templates/lxc-download.in
lxc-download: Bump compat level to 4
[mirror_lxc.git] / templates / lxc-download.in
1 #!/bin/sh
2
3 # Client script for LXC container images.
4 #
5 # Copyright © 2014 Stéphane Graber <stgraber@ubuntu.com>
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20 # USA
21
22 set -eu
23
24 LOCALSTATEDIR="@LOCALSTATEDIR@"
25 LXC_HOOK_DIR="@LXCHOOKDIR@"
26 LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
27
28 # Defaults
29 DOWNLOAD_ARCH=
30 DOWNLOAD_BUILD=
31 DOWNLOAD_COMPAT_LEVEL=4
32 DOWNLOAD_DIST=
33 DOWNLOAD_FLUSH_CACHE="false"
34 DOWNLOAD_FORCE_CACHE="false"
35 DOWNLOAD_INTERACTIVE="false"
36 DOWNLOAD_KEYID="0xE7FB0CAEC8173D669066514CBAEFF88C22F6E216"
37 DOWNLOAD_KEYSERVER="hkp://pool.sks-keyservers.net"
38 DOWNLOAD_LIST_IMAGES="false"
39 DOWNLOAD_MODE="system"
40 DOWNLOAD_READY_GPG="false"
41 DOWNLOAD_RELEASE=
42 DOWNLOAD_SERVER="images.linuxcontainers.org"
43 DOWNLOAD_SHOW_GPG_WARNING="true"
44 DOWNLOAD_SHOW_HTTP_WARNING="true"
45 DOWNLOAD_TARGET="system"
46 DOWNLOAD_URL=
47 DOWNLOAD_USE_CACHE="false"
48 DOWNLOAD_VALIDATE="true"
49 DOWNLOAD_VARIANT="default"
50
51 LXC_MAPPED_GID=
52 LXC_MAPPED_UID=
53 LXC_NAME=
54 LXC_PATH=
55 LXC_ROOTFS=
56
57 # Deal with GPG over http proxy
58 if [ -n "${http_proxy:-}" ]; then
59 DOWNLOAD_KEYSERVER="hkp://p80.pool.sks-keyservers.net:80"
60 fi
61
62 # Make sure the usual locations are in PATH
63 export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
64
65 # Some useful functions
66 cleanup() {
67 if [ -d "$DOWNLOAD_TEMP" ]; then
68 rm -Rf $DOWNLOAD_TEMP
69 fi
70 }
71
72 wget_wrapper() {
73 for i in $(seq 3); do
74 if wget $@; then
75 return 0
76 fi
77 done
78
79 return 1
80 }
81
82 download_file() {
83 if ! wget_wrapper -T 30 -q https://${DOWNLOAD_SERVER}/$1 -O $2 >/dev/null 2>&1; then
84 if ! wget_wrapper -T 30 -q http://${DOWNLOAD_SERVER}/$1 -O $2 >/dev/null 2>&1; then
85 if [ "$3" = "noexit" ]; then
86 return 1
87 else
88 echo "ERROR: Failed to download http://${DOWNLOAD_SERVER}/$1" 1>&2
89 exit 1
90 fi
91 elif [ "$DOWNLOAD_SHOW_HTTP_WARNING" = "true" ]; then
92 DOWNLOAD_SHOW_HTTP_WARNING="false"
93 echo "WARNING: Failed to download the file over HTTPs." 1>&2
94 echo -n " The file was instead download over HTTP. " 1>&2
95 echo "A server replay attack may be possible!" 1>&2
96 fi
97 fi
98 }
99
100 download_sig() {
101 if ! download_file $1 $2 noexit; then
102 if [ "$DOWNLOAD_VALIDATE" = "true" ]; then
103 if [ "$3" = "normal" ]; then
104 echo "ERROR: Failed to download http://${DOWNLOAD_SERVER}/$1" 1>&2
105 exit 1
106 else
107 return 1
108 fi
109 else
110 return 0
111 fi
112 fi
113 }
114
115 gpg_setup() {
116 if [ "$DOWNLOAD_VALIDATE" = "false" ]; then
117 return
118 fi
119
120 if [ "$DOWNLOAD_READY_GPG" = "true" ]; then
121 return
122 fi
123
124 echo "Setting up the GPG keyring"
125
126 mkdir -p "$DOWNLOAD_TEMP/gpg"
127 chmod 700 "$DOWNLOAD_TEMP/gpg"
128 export GNUPGHOME="$DOWNLOAD_TEMP/gpg"
129
130 success=
131 for i in $(seq 3); do
132 if gpg --keyserver $DOWNLOAD_KEYSERVER \
133 --recv-keys ${DOWNLOAD_KEYID} >/dev/null 2>&1; then
134 success=1
135 break
136 fi
137 done
138
139 if [ -z "$success" ]; then
140 echo "ERROR: Unable to fetch GPG key from keyserver."
141 exit 1
142 fi
143
144 DOWNLOAD_READY_GPG="true"
145 }
146
147 gpg_validate() {
148 if [ "$DOWNLOAD_VALIDATE" = "false" ]; then
149 if [ "$DOWNLOAD_SHOW_GPG_WARNING" = "true" ]; then
150 echo "WARNING: Running without gpg validation!" 1>&2
151 fi
152 DOWNLOAD_SHOW_GPG_WARNING="false"
153 return 0
154 fi
155
156 if ! gpg --verify $1 >/dev/zero 2>&1; then
157 echo "ERROR: Invalid signature for $1" 1>&2
158 exit 1
159 fi
160 }
161
162 in_userns() {
163 [ -e /proc/self/uid_map ] || { echo no; return; }
164 while read line; do
165 fields=$(echo $line | awk '{ print $1 " " $2 " " $3 }')
166 [ "$fields" = "0 0 4294967295" ] && { echo no; return; } || true
167 echo $fields | grep -q " 0 1$" && { echo userns-root; return; } || true
168 done < /proc/self/uid_map
169
170 [ "$(cat /proc/self/uid_map)" = "$(cat /proc/1/uid_map)" ] && \
171 { echo userns-root; return; }
172 echo yes
173 }
174
175 relevant_file() {
176 FILE_PATH="${LXC_CACHE_PATH}/$1"
177 if [ -e "${FILE_PATH}-${DOWNLOAD_MODE}" ]; then
178 FILE_PATH="${FILE_PATH}-${DOWNLOAD_MODE}"
179 fi
180 if [ -e "$FILE_PATH.${DOWNLOAD_COMPAT_LEVEL}" ]; then
181 FILE_PATH="${FILE_PATH}.${DOWNLOAD_COMPAT_LEVEL}"
182 fi
183
184 echo $FILE_PATH
185 }
186
187 usage() {
188 cat <<EOF
189 LXC container image downloader
190
191 Special arguments:
192 [ -h | --help ]: Print this help message and exit.
193 [ -l | --list ]: List all available images and exit.
194
195 Required arguments:
196 [ -d | --dist <distribution> ]: The name of the distribution
197 [ -r | --release <release> ]: Release name/version
198 [ -a | --arch <architecture> ]: Architecture of the container
199
200 Optional arguments:
201 [ --variant <variant> ]: Variant of the image (default: "default")
202 [ --server <server> ]: Image server (default: "images.linuxcontainers.org")
203 [ --keyid <keyid> ]: GPG keyid (default: 0x...)
204 [ --keyserver <keyserver> ]: GPG keyserver to use
205 [ --no-validate ]: Disable GPG validation (not recommended)
206 [ --flush-cache ]: Flush the local copy (if present)
207 [ --force-cache ]: Force the use of the local copy even if expired
208
209 LXC internal arguments (do not pass manually!):
210 [ --name <name> ]: The container name
211 [ --path <path> ]: The path to the container
212 [ --rootfs <rootfs> ]: The path to the container's rootfs
213 [ --mapped-uid <map> ]: A uid map (user namespaces)
214 [ --mapped-gid <map> ]: A gid map (user namespaces)
215 EOF
216 return 0
217 }
218
219 options=$(getopt -o d:r:a:hl -l dist:,release:,arch:,help,list,variant:,\
220 server:,keyid:,keyserver:,no-validate,flush-cache,force-cache,name:,path:,\
221 rootfs:,mapped-uid:,mapped-gid: -- "$@")
222
223 if [ $? -ne 0 ]; then
224 usage
225 exit 1
226 fi
227 eval set -- "$options"
228
229 while :; do
230 case "$1" in
231 -h|--help) usage && exit 1;;
232 -l|--list) DOWNLOAD_LIST_IMAGES="true"; shift 1;;
233 -d|--dist) DOWNLOAD_DIST=$2; shift 2;;
234 -r|--release) DOWNLOAD_RELEASE=$2; shift 2;;
235 -a|--arch) DOWNLOAD_ARCH=$2; shift 2;;
236 --variant) DOWNLOAD_VARIANT=$2; shift 2;;
237 --server) DOWNLOAD_SERVER=$2; shift 2;;
238 --keyid) DOWNLOAD_KEYID=$2; shift 2;;
239 --keyserver) DOWNLOAD_KEYSERVER=$2; shift 2;;
240 --no-validate) DOWNLOAD_VALIDATE="false"; shift 1;;
241 --flush-cache) DOWNLOAD_FLUSH_CACHE="true"; shift 1;;
242 --force-cache) DOWNLOAD_FORCE_CACHE="true"; shift 1;;
243 --name) LXC_NAME=$2; shift 2;;
244 --path) LXC_PATH=$2; shift 2;;
245 --rootfs) LXC_ROOTFS=$2; shift 2;;
246 --mapped-uid) LXC_MAPPED_UID=$2; shift 2;;
247 --mapped-gid) LXC_MAPPED_GID=$2; shift 2;;
248 *) break;;
249 esac
250 done
251
252 # Check for required binaries
253 for bin in tar xz wget; do
254 if ! type $bin >/dev/null 2>&1; then
255 echo "ERROR: Missing required tool: $bin" 1>&2
256 exit 1
257 fi
258 done
259
260 # Check for GPG
261 if [ "$DOWNLOAD_VALIDATE" = "true" ]; then
262 if ! type gpg >/dev/null 2>&1; then
263 echo "ERROR: Missing recommended tool: gpg" 1>&2
264 echo "You can workaround this by using --no-validate." 1>&2
265 exit 1
266 fi
267 fi
268
269 # Check that we have all variables we need
270 if [ -z "$LXC_NAME" ] || [ -z "$LXC_PATH" ] || [ -z "$LXC_ROOTFS" ]; then
271 if [ "$DOWNLOAD_LIST_IMAGES" != "true" ]; then
272 echo "ERROR: Not running through LXC." 1>&2
273 exit 1
274 fi
275 fi
276
277 USERNS=$(in_userns)
278
279 if [ "$USERNS" != "no" ]; then
280 if [ "$USERNS" = "yes" ]; then
281 if [ -z "$LXC_MAPPED_UID" ] || [ "$LXC_MAPPED_UID" = "-1" ]; then
282 echo "ERROR: In a user namespace without a map." 1>&2
283 exit 1
284 fi
285 DOWNLOAD_MODE="user"
286 DOWNLOAD_TARGET="user"
287 else
288 DOWNLOAD_MODE="user"
289 DOWNLOAD_TARGET="system"
290 fi
291 fi
292
293 if [ -z "$DOWNLOAD_DIST" ] || [ -z "$DOWNLOAD_RELEASE" ] || \
294 [ -z "$DOWNLOAD_ARCH" ]; then
295 DOWNLOAD_INTERACTIVE="true"
296 fi
297
298 # Trap all exit signals
299 trap cleanup EXIT HUP INT TERM
300
301 if ! type mktemp >/dev/null 2>&1; then
302 DOWNLOAD_TEMP=/tmp/lxc-download.$$
303 mkdir -p $DOWNLOAD_TEMP
304 else
305 DOWNLOAD_TEMP=$(mktemp -d)
306 fi
307
308 # Simply list images
309 if [ "$DOWNLOAD_LIST_IMAGES" = "true" ] || \
310 [ "$DOWNLOAD_INTERACTIVE" = "true" ]; then
311 # Initialize GPG
312 gpg_setup
313
314 # Grab the index
315 DOWNLOAD_INDEX_PATH=/meta/1.0/index-${DOWNLOAD_MODE}
316
317 echo "Downloading the image index"
318 if ! download_file ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL} \
319 ${DOWNLOAD_TEMP}/index noexit ||
320 ! download_sig ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL}.asc \
321 ${DOWNLOAD_TEMP}/index.asc noexit; then
322 download_file ${DOWNLOAD_INDEX_PATH} ${DOWNLOAD_TEMP}/index normal
323 download_sig ${DOWNLOAD_INDEX_PATH}.asc \
324 ${DOWNLOAD_TEMP}/index.asc normal
325 fi
326
327 gpg_validate ${DOWNLOAD_TEMP}/index.asc
328
329 # Parse it
330 echo ""
331 echo "---"
332 printf "DIST\tRELEASE\tARCH\tVARIANT\tBUILD\n"
333 echo "---"
334 while read line; do
335 # Basic CSV parser
336 OLD_IFS=$IFS
337 IFS=";"
338 set -- $line
339 IFS=$OLD_IFS
340
341 [ -n "$DOWNLOAD_DIST" ] && [ "$1" != "$DOWNLOAD_DIST" ] && continue
342 [ -n "$DOWNLOAD_RELEASE" ] && [ "$2" != "$DOWNLOAD_RELEASE" ] && continue
343 [ -n "$DOWNLOAD_ARCH" ] && [ "$3" != "$DOWNLOAD_ARCH" ] && continue
344 [ -n "$DOWNLOAD_VARIANT" ] && [ "$4" != "$DOWNLOAD_VARIANT" ] && continue
345 [ -z "$5" ] || [ -z "$6" ] && continue
346
347 printf "$1\t$2\t$3\t$4\t$5\n"
348 done < ${DOWNLOAD_TEMP}/index
349 echo "---"
350
351 if [ "$DOWNLOAD_LIST_IMAGES" = "true" ]; then
352 exit 1
353 fi
354
355 # Interactive mode
356 echo ""
357
358 if [ -z "$DOWNLOAD_DIST" ]; then
359 echo -n "Distribution: "
360 read DOWNLOAD_DIST
361 fi
362
363 if [ -z "$DOWNLOAD_RELEASE" ]; then
364 echo -n "Release: "
365 read DOWNLOAD_RELEASE
366 fi
367
368 if [ -z "$DOWNLOAD_ARCH" ]; then
369 echo -n "Architecture: "
370 read DOWNLOAD_ARCH
371 fi
372
373 echo ""
374 fi
375
376 # Setup the cache
377 if [ "$DOWNLOAD_TARGET" = "system" ]; then
378 LXC_CACHE_BASE="$LOCALSTATEDIR/cache/lxc/"
379 else
380 LXC_CACHE_BASE="$HOME/.cache/lxc/"
381 fi
382
383 # Allow the setting of the LXC_CACHE_PATH with the usage of environment variables.
384 LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LXC_CACHE_BASE"}
385 LXC_CACHE_PATH=$LXC_CACHE_PATH/download/$DOWNLOAD_DIST
386 LXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_RELEASE/$DOWNLOAD_ARCH/"
387 LXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_VARIANT"
388
389 if [ -d "$LXC_CACHE_PATH" ]; then
390 if [ "$DOWNLOAD_FLUSH_CACHE" = "true" ]; then
391 echo "Flushing the cache..."
392 rm -Rf $LXC_CACHE_PATH
393 elif [ "$DOWNLOAD_FORCE_CACHE" = "true" ]; then
394 DOWNLOAD_USE_CACHE="true"
395 else
396 DOWNLOAD_USE_CACHE="true"
397 if [ -e "$(relevant_file expiry)" ]; then
398 if [ "$(cat $(relevant_file expiry))" -lt $(date +%s) ]; then
399 echo "The cached copy has expired, re-downloading..."
400 DOWNLOAD_USE_CACHE="false"
401 fi
402 fi
403 fi
404 fi
405
406 # Download what's needed
407 if [ "$DOWNLOAD_USE_CACHE" = "false" ]; then
408 # Initialize GPG
409 gpg_setup
410
411 # Grab the index
412 DOWNLOAD_INDEX_PATH=/meta/1.0/index-${DOWNLOAD_MODE}
413
414 echo "Downloading the image index"
415 if ! download_file ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL} \
416 ${DOWNLOAD_TEMP}/index noexit ||
417 ! download_sig ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL}.asc \
418 ${DOWNLOAD_TEMP}/index.asc noexit; then
419 download_file ${DOWNLOAD_INDEX_PATH} ${DOWNLOAD_TEMP}/index normal
420 download_sig ${DOWNLOAD_INDEX_PATH}.asc \
421 ${DOWNLOAD_TEMP}/index.asc normal
422 fi
423
424 gpg_validate ${DOWNLOAD_TEMP}/index.asc
425
426 # Parse it
427 while read line; do
428 # Basic CSV parser
429 OLD_IFS=$IFS
430 IFS=";"
431 set -- $line
432 IFS=$OLD_IFS
433
434 if [ "$1" != "$DOWNLOAD_DIST" ] || \
435 [ "$2" != "$DOWNLOAD_RELEASE" ] || \
436 [ "$3" != "$DOWNLOAD_ARCH" ] || \
437 [ "$4" != "$DOWNLOAD_VARIANT" ] || \
438 [ -z "$6" ]; then
439 continue
440 fi
441
442 DOWNLOAD_BUILD=$5
443 DOWNLOAD_URL=$6
444 break
445 done < ${DOWNLOAD_TEMP}/index
446
447 if [ -z "$DOWNLOAD_URL" ]; then
448 echo "ERROR: Couldn't find a matching image." 1>&1
449 exit 1
450 fi
451
452 if [ -d "$LXC_CACHE_PATH" ] && [ -f "$LXC_CACHE_PATH/build_id" ] && \
453 [ "$(cat $LXC_CACHE_PATH/build_id)" = "$DOWNLOAD_BUILD" ]; then
454 echo "The cache is already up to date."
455 echo "Using image from local cache"
456 else
457 # Download the actual files
458 echo "Downloading the rootfs"
459 download_file $DOWNLOAD_URL/rootfs.tar.xz \
460 ${DOWNLOAD_TEMP}/rootfs.tar.xz normal
461 download_sig $DOWNLOAD_URL/rootfs.tar.xz.asc \
462 ${DOWNLOAD_TEMP}/rootfs.tar.xz.asc normal
463 gpg_validate ${DOWNLOAD_TEMP}/rootfs.tar.xz.asc
464
465 echo "Downloading the metadata"
466 download_file $DOWNLOAD_URL/meta.tar.xz \
467 ${DOWNLOAD_TEMP}/meta.tar.xz normal
468 download_sig $DOWNLOAD_URL/meta.tar.xz.asc \
469 ${DOWNLOAD_TEMP}/meta.tar.xz.asc normal
470 gpg_validate ${DOWNLOAD_TEMP}/meta.tar.xz.asc
471
472 if [ -d $LXC_CACHE_PATH ]; then
473 rm -Rf $LXC_CACHE_PATH
474 fi
475 mkdir -p $LXC_CACHE_PATH
476 mv ${DOWNLOAD_TEMP}/rootfs.tar.xz $LXC_CACHE_PATH
477 if ! tar Jxf ${DOWNLOAD_TEMP}/meta.tar.xz -C $LXC_CACHE_PATH; then
478 echo "ERROR: Invalid rootfs tarball." 2>&1
479 exit 1
480 fi
481
482 echo $DOWNLOAD_BUILD > $LXC_CACHE_PATH/build_id
483
484 if [ -n "$LXC_MAPPED_UID" ] && [ "$LXC_MAPPED_UID" != "-1" ]; then
485 chown -R $LXC_MAPPED_UID $LXC_CACHE_BASE >/dev/null 2>&1 || true
486 fi
487 if [ -n "$LXC_MAPPED_GID" ] && [ "$LXC_MAPPED_GID" != "-1" ]; then
488 chgrp -R $LXC_MAPPED_GID $LXC_CACHE_BASE >/dev/null 2>&1 || true
489 fi
490 echo "The image cache is now ready"
491 fi
492 else
493 echo "Using image from local cache"
494 fi
495
496 # Unpack the rootfs
497 echo "Unpacking the rootfs"
498
499 EXCLUDES=""
500 excludelist=$(relevant_file excludes)
501 if [ -f "${excludelist}" ]; then
502 while read line; do
503 EXCLUDES="$EXCLUDES --exclude=$line"
504 done < $excludelist
505 fi
506
507 tar --anchored ${EXCLUDES} --numeric-owner -xpJf \
508 ${LXC_CACHE_PATH}/rootfs.tar.xz -C ${LXC_ROOTFS}
509
510 mkdir -p ${LXC_ROOTFS}/dev/pts/
511
512 # Setup the configuration
513 configfile=$(relevant_file config)
514 fstab=$(relevant_file fstab)
515 if [ ! -e $configfile ]; then
516 echo "ERROR: meta tarball is missing the configuration file" 1>&2
517 exit 1
518 fi
519
520 ## Extract all the network config entries
521 sed -i -e "/lxc.network/{w ${LXC_PATH}/config-network" -e "d}" \
522 ${LXC_PATH}/config
523
524 ## Extract any other config entry
525 sed -i -e "/lxc./{w ${LXC_PATH}/config-auto" -e "d}" ${LXC_PATH}/config
526
527 ## Append the defaults
528 echo "" >> ${LXC_PATH}/config
529 echo "# Distribution configuration" >> ${LXC_PATH}/config
530 cat $configfile >> ${LXC_PATH}/config
531
532 ## Add the container-specific config
533 echo "" >> ${LXC_PATH}/config
534 echo "# Container specific configuration" >> ${LXC_PATH}/config
535 if [ -e "${LXC_PATH}/config-auto" ]; then
536 cat ${LXC_PATH}/config-auto >> ${LXC_PATH}/config
537 rm ${LXC_PATH}/config-auto
538 fi
539 if [ -e "$fstab" ]; then
540 echo "lxc.mount = ${LXC_PATH}/fstab" >> ${LXC_PATH}/config
541 fi
542 echo "lxc.utsname = ${LXC_NAME}" >> ${LXC_PATH}/config
543
544 ## Re-add the previously removed network config
545 if [ -e "${LXC_PATH}/config-network" ]; then
546 echo "" >> ${LXC_PATH}/config
547 echo "# Network configuration" >> ${LXC_PATH}/config
548 cat ${LXC_PATH}/config-network >> ${LXC_PATH}/config
549 rm ${LXC_PATH}/config-network
550 fi
551
552 TEMPLATE_FILES="${LXC_PATH}/config"
553
554 # Setup the fstab
555 if [ -e $fstab ]; then
556 cp ${fstab} ${LXC_PATH}/fstab
557 TEMPLATE_FILES="$TEMPLATE_FILES ${LXC_PATH}/fstab"
558 fi
559
560 # Look for extra templates
561 if [ -e "$(relevant_file templates)" ]; then
562 while read line; do
563 fullpath=${LXC_ROOTFS}/$line
564 [ ! -e "$fullpath" ] && continue
565 TEMPLATE_FILES="$TEMPLATE_FILES $fullpath"
566 done < $(relevant_file templates)
567 fi
568
569 # Replace variables in all templates
570 for file in $TEMPLATE_FILES; do
571 [ ! -f "$file" ] && continue
572
573 sed -i "s#LXC_NAME#$LXC_NAME#g" $file
574 sed -i "s#LXC_PATH#$LXC_PATH#g" $file
575 sed -i "s#LXC_ROOTFS#$LXC_ROOTFS#g" $file
576 sed -i "s#LXC_TEMPLATE_CONFIG#$LXC_TEMPLATE_CONFIG#g" $file
577 sed -i "s#LXC_HOOK_DIR#$LXC_HOOK_DIR#g" $file
578 done
579
580 # prevent mingetty from calling vhangup(2) since it fails with userns on CentOS / Oracle
581 if [ -f ${LXC_ROOTFS}/etc/init/tty.conf ]; then
582 sed -i 's|mingetty|mingetty --nohangup|' ${LXC_ROOTFS}/etc/init/tty.conf
583 fi
584
585 if [ -n "$LXC_MAPPED_UID" ] && [ "$LXC_MAPPED_UID" != "-1" ]; then
586 chown $LXC_MAPPED_UID $LXC_PATH/config $LXC_PATH/fstab >/dev/null 2>&1 || true
587 fi
588 if [ -n "$LXC_MAPPED_GID" ] && [ "$LXC_MAPPED_GID" != "-1" ]; then
589 chgrp $LXC_MAPPED_GID $LXC_PATH/config $LXC_PATH/fstab >/dev/null 2>&1 || true
590 fi
591
592 if [ -e "$(relevant_file create-message)" ]; then
593 echo ""
594 echo "---"
595 cat "$(relevant_file create-message)"
596 fi
597
598 exit 0