]> git.proxmox.com Git - mirror_lxc.git/blame - templates/lxc-download.in
github: Update for main branch
[mirror_lxc.git] / templates / lxc-download.in
CommitLineData
71d3a659
SG
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
22set -eu
23
3cc0ec84
CB
24LOCALSTATEDIR=@LOCALSTATEDIR@
25LXC_HOOK_DIR=@LXCHOOKDIR@
26LXC_TEMPLATE_CONFIG=@LXCTEMPLATECONFIG@
71d3a659
SG
27
28# Defaults
71d3a659 29DOWNLOAD_ARCH=
f74e080c 30DOWNLOAD_BUILD=
7a930fe7 31DOWNLOAD_COMPAT_LEVEL=7
f74e080c 32DOWNLOAD_DIST=
71d3a659 33DOWNLOAD_FLUSH_CACHE="false"
41670b35 34DOWNLOAD_FORCE_CACHE="false"
f74e080c 35DOWNLOAD_INTERACTIVE="false"
f74e080c 36DOWNLOAD_LIST_IMAGES="false"
71d3a659 37DOWNLOAD_MODE="system"
f74e080c
SG
38DOWNLOAD_RELEASE=
39DOWNLOAD_SERVER="images.linuxcontainers.org"
f74e080c
SG
40DOWNLOAD_TARGET="system"
41DOWNLOAD_URL=
42DOWNLOAD_USE_CACHE="false"
f74e080c 43DOWNLOAD_VARIANT="default"
edb5452c 44DOWNLOAD_TEMP=
71d3a659 45
f74e080c
SG
46LXC_MAPPED_GID=
47LXC_MAPPED_UID=
71d3a659
SG
48LXC_NAME=
49LXC_PATH=
50LXC_ROOTFS=
71d3a659 51
207bf0e4 52# Make sure the usual locations are in PATH
655d10ed 53export PATH="$PATH:/usr/sbin:/usr/bin:/sbin:/bin"
207bf0e4 54
71d3a659
SG
55# Some useful functions
56cleanup() {
832cb182
CB
57 if [ -d "${DOWNLOAD_TEMP}" ]; then
58 rm -Rf "${DOWNLOAD_TEMP}"
59 fi
71d3a659
SG
60}
61
acabe1fa 62wget_wrapper() {
832cb182
CB
63 for _ in $(seq 3); do
64 if wget "$@"; then
65 return 0
66 fi
67 done
acabe1fa 68
832cb182 69 return 1
acabe1fa
SG
70}
71
71d3a659 72download_file() {
dcc08eb5 73 if ! wget_wrapper --user-agent="lxc/@PACKAGE_VERSION@ compat:${DOWNLOAD_COMPAT_LEVEL}" -T 30 -q "https://${DOWNLOAD_SERVER}/$1" -O "$2" >/dev/null 2>&1; then
58520263
SG
74 if [ "$3" = "noexit" ]; then
75 return 1
832cb182 76 else
58520263
SG
77 echo "ERROR: Failed to download https://${DOWNLOAD_SERVER}/$1" 1>&2
78 exit 1
71d3a659 79 fi
832cb182 80 fi
71d3a659
SG
81}
82
83in_userns() {
832cb182
CB
84 [ -e /proc/self/uid_map ] || { echo no; return; }
85 while read -r line; do
86 fields="$(echo "$line" | awk '{ print $1 " " $2 " " $3 }')"
87 if [ "${fields}" = "0 0 4294967295" ]; then
88 echo no;
89 return;
90 fi
91 if echo "${fields}" | grep -q " 0 1$"; then
92 echo userns-root;
93 return;
94 fi
95 done < /proc/self/uid_map
96
16a312e1
LP
97 if [ -e /proc/1/uid_map ]; then
98 if [ "$(cat /proc/self/uid_map)" = "$(cat /proc/1/uid_map)" ]; then
99 echo userns-root
100 return
101 fi
102 fi
832cb182 103 echo yes
71d3a659
SG
104}
105
106relevant_file() {
832cb182
CB
107 FILE_PATH="${LXC_CACHE_PATH}/$1"
108
109 if [ -e "${FILE_PATH}-${DOWNLOAD_MODE}" ]; then
110 FILE_PATH="${FILE_PATH}-${DOWNLOAD_MODE}"
111 fi
71d3a659 112
832cb182
CB
113 if [ -e "${FILE_PATH}.${DOWNLOAD_COMPAT_LEVEL}" ]; then
114 FILE_PATH="${FILE_PATH}.${DOWNLOAD_COMPAT_LEVEL}"
115 fi
116
117 echo "${FILE_PATH}"
71d3a659
SG
118}
119
120usage() {
832cb182 121 cat <<EOF
71d3a659
SG
122LXC container image downloader
123
7d540a26 124Special arguments:
832cb182
CB
125[ -h | --help ]: Print this help message and exit
126[ -l | --list ]: List all available images and exit
7d540a26 127
71d3a659
SG
128Required arguments:
129[ -d | --dist <distribution> ]: The name of the distribution
130[ -r | --release <release> ]: Release name/version
131[ -a | --arch <architecture> ]: Architecture of the container
71d3a659
SG
132
133Optional arguments:
134[ --variant <variant> ]: Variant of the image (default: "default")
135[ --server <server> ]: Image server (default: "images.linuxcontainers.org")
71d3a659 136[ --flush-cache ]: Flush the local copy (if present)
e145b7bb 137[ --force-cache ]: Force the use of the local copy even if expired
71d3a659
SG
138
139LXC internal arguments (do not pass manually!):
140[ --name <name> ]: The container name
141[ --path <path> ]: The path to the container
142[ --rootfs <rootfs> ]: The path to the container's rootfs
2133f58c
SH
143[ --mapped-uid <map> ]: A uid map (user namespaces)
144[ --mapped-gid <map> ]: A gid map (user namespaces)
d2e5c5d1 145
71d3a659 146EOF
832cb182 147 return 0
71d3a659
SG
148}
149
3f7be9d0 150if ! options=$(getopt -o d:r:a:hl -l dist:,release:,arch:,help,list,variant:,\
58520263 151server:,flush-cache,force-cache,name:,path:,\
3f7be9d0 152rootfs:,mapped-uid:,mapped-gid: -- "$@"); then
832cb182
CB
153 usage
154 exit 1
71d3a659
SG
155fi
156eval set -- "$options"
157
158while :; do
832cb182
CB
159 case "$1" in
160 -h|--help) usage && exit 1;;
161 -l|--list) DOWNLOAD_LIST_IMAGES="true"; shift 1;;
162 -d|--dist) DOWNLOAD_DIST="$2"; shift 2;;
163 -r|--release) DOWNLOAD_RELEASE="$2"; shift 2;;
164 -a|--arch) DOWNLOAD_ARCH="$2"; shift 2;;
165 --variant) DOWNLOAD_VARIANT="$2"; shift 2;;
166 --server) DOWNLOAD_SERVER="$2"; shift 2;;
832cb182
CB
167 --flush-cache) DOWNLOAD_FLUSH_CACHE="true"; shift 1;;
168 --force-cache) DOWNLOAD_FORCE_CACHE="true"; shift 1;;
169 --name) LXC_NAME="$2"; shift 2;;
170 --path) LXC_PATH="$2"; shift 2;;
171 --rootfs) LXC_ROOTFS="$2"; shift 2;;
172 --mapped-uid) LXC_MAPPED_UID="$2"; shift 2;;
173 --mapped-gid) LXC_MAPPED_GID="$2"; shift 2;;
174 *) break;;
175 esac
71d3a659
SG
176done
177
178# Check for required binaries
179for bin in tar xz wget; do
832cb182
CB
180 if ! command -V "${bin}" >/dev/null 2>&1; then
181 echo "ERROR: Missing required tool: ${bin}" 1>&2
182 exit 1
183 fi
71d3a659
SG
184done
185
71d3a659 186# Check that we have all variables we need
3f7be9d0 187if [ -z "${LXC_NAME}" ] || [ -z "${LXC_PATH}" ] || [ -z "${LXC_ROOTFS}" ]; then
832cb182
CB
188 if [ "${DOWNLOAD_LIST_IMAGES}" != "true" ]; then
189 echo "ERROR: Please pass the name, path, and rootfs for the container" 1>&2
190 exit 1
191 fi
71d3a659
SG
192fi
193
3f7be9d0 194USERNS="$(in_userns)"
f74e080c 195
3f7be9d0 196if [ "${USERNS}" != "no" ]; then
832cb182
CB
197 if [ "${USERNS}" = "yes" ]; then
198 if [ -z "${LXC_MAPPED_UID}" ] || [ "${LXC_MAPPED_UID}" = "-1" ]; then
199 echo "ERROR: In a user namespace without a map" 1>&2
200 exit 1
71d3a659 201 fi
832cb182
CB
202 DOWNLOAD_MODE="user"
203 DOWNLOAD_TARGET="user"
204 else
205 DOWNLOAD_MODE="user"
206 DOWNLOAD_TARGET="system"
207 fi
71d3a659
SG
208fi
209
832cb182
CB
210if [ -z "${DOWNLOAD_DIST}" ] || [ -z "${DOWNLOAD_RELEASE}" ] || [ -z "${DOWNLOAD_ARCH}" ]; then
211 DOWNLOAD_INTERACTIVE="true"
71d3a659
SG
212fi
213
214# Trap all exit signals
215trap cleanup EXIT HUP INT TERM
843a5874 216
edb5452c
SC
217# /tmp may be mounted in tmpfs or noexec
218if mountpoint -q /tmp; then
832cb182 219 DOWNLOAD_TEMP="${LXC_PATH}"
edb5452c
SC
220fi
221
3f7be9d0 222if ! command -V mktemp >/dev/null 2>&1; then
832cb182 223 DOWNLOAD_TEMP="${DOWNLOAD_TEMP}/tmp/lxc-download.$$"
30c8676e
CB
224elif [ -n "${DOWNLOAD_TEMP}" ]; then
225 mkdir -p "${DOWNLOAD_TEMP}"
eb44984a 226 DOWNLOAD_TEMP="$(mktemp -p "${DOWNLOAD_TEMP}" -d)"
30c8676e
CB
227else
228 DOWNLOAD_TEMP="${DOWNLOAD_TEMP}$(mktemp -d)"
843a5874 229fi
71d3a659 230
10a5fab6 231# Simply list images
832cb182 232if [ "${DOWNLOAD_LIST_IMAGES}" = "true" ] || [ "${DOWNLOAD_INTERACTIVE}" = "true" ]; then
832cb182
CB
233 # Grab the index
234 DOWNLOAD_INDEX_PATH="/meta/1.0/index-${DOWNLOAD_MODE}"
235
236 echo "Downloading the image index"
58520263 237 if ! download_file "${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL}" "${DOWNLOAD_TEMP}/index" noexit; then
832cb182 238 download_file "${DOWNLOAD_INDEX_PATH}" "${DOWNLOAD_TEMP}/index" normal
832cb182
CB
239 fi
240
832cb182
CB
241 # Parse it
242 echo ""
243 echo "---"
244 printf "DIST\tRELEASE\tARCH\tVARIANT\tBUILD\n"
245 echo "---"
246 while IFS=';' read -r f1 f2 f3 f4 f5 f6; do
247 [ -n "${DOWNLOAD_DIST}" ] && [ "$f1" != "${DOWNLOAD_DIST}" ] && continue
248 [ -n "${DOWNLOAD_RELEASE}" ] && [ "$f2" != "${DOWNLOAD_RELEASE}" ] && continue
249 [ -n "${DOWNLOAD_ARCH}" ] && [ "$f3" != "${DOWNLOAD_ARCH}" ] && continue
250 [ -n "${DOWNLOAD_VARIANT}" ] && [ "$f4" != "${DOWNLOAD_VARIANT}" ] && continue
251 [ -z "${f5}" ] || [ -z "${f6}" ] && continue
252
253 printf "%s\t%s\t%s\t%s\t%s\n" "${f1}" "${f2}" "${f3}" "${f4}" "${f5}"
254 unset f1 f2 f3 f4 f5 f6
255 done < "${DOWNLOAD_TEMP}/index"
256 echo "---"
257
258 if [ "${DOWNLOAD_LIST_IMAGES}" = "true" ]; then
259 exit 1
260 fi
b0f0932a 261
832cb182
CB
262 # Interactive mode
263 echo ""
b0f0932a 264
832cb182
CB
265 if [ -z "${DOWNLOAD_DIST}" ]; then
266 echo "Distribution: "
267 read -r DOWNLOAD_DIST
268 fi
b0f0932a 269
832cb182
CB
270 if [ -z "${DOWNLOAD_RELEASE}" ]; then
271 echo "Release: "
272 read -r DOWNLOAD_RELEASE
273 fi
b0f0932a 274
832cb182
CB
275 if [ -z "${DOWNLOAD_ARCH}" ]; then
276 echo "Architecture: "
277 read -r DOWNLOAD_ARCH
278 fi
b0f0932a 279
832cb182 280 echo ""
10a5fab6
SG
281fi
282
71d3a659 283# Setup the cache
3f7be9d0 284if [ "${DOWNLOAD_TARGET}" = "system" ]; then
832cb182 285 LXC_CACHE_BASE="${LOCALSTATEDIR}/cache/lxc/"
71d3a659 286else
832cb182 287 LXC_CACHE_BASE="${HOME}/.cache/lxc/"
71d3a659
SG
288fi
289
6dc6f80b 290# Allow the setting of the LXC_CACHE_PATH with the usage of environment variables.
3f7be9d0
WG
291LXC_CACHE_PATH="${LXC_CACHE_PATH:-"${LXC_CACHE_BASE}"}"
292LXC_CACHE_PATH="${LXC_CACHE_PATH}/download/${DOWNLOAD_DIST}"
293LXC_CACHE_PATH="${LXC_CACHE_PATH}/${DOWNLOAD_RELEASE}/${DOWNLOAD_ARCH}/"
294LXC_CACHE_PATH="${LXC_CACHE_PATH}/${DOWNLOAD_VARIANT}"
b56661fe 295
3f7be9d0 296if [ -d "${LXC_CACHE_PATH}" ]; then
832cb182
CB
297 if [ "${DOWNLOAD_FLUSH_CACHE}" = "true" ]; then
298 echo "Flushing the cache..."
299 rm -Rf "${LXC_CACHE_PATH}"
300 elif [ "${DOWNLOAD_FORCE_CACHE}" = "true" ]; then
301 DOWNLOAD_USE_CACHE="true"
302 else
303 DOWNLOAD_USE_CACHE="true"
304 if [ -e "$(relevant_file expiry)" ]; then
305 if [ "$(cat "$(relevant_file expiry)")" -lt "$(date +%s)" ]; then
306 echo "The cached copy has expired, re-downloading..."
307 DOWNLOAD_USE_CACHE="false"
308 fi
71d3a659 309 fi
832cb182 310 fi
71d3a659
SG
311fi
312
313# Download what's needed
3f7be9d0 314if [ "${DOWNLOAD_USE_CACHE}" = "false" ]; then
832cb182
CB
315 # Grab the index
316 DOWNLOAD_INDEX_PATH="/meta/1.0/index-${DOWNLOAD_MODE}"
317
318 echo "Downloading the image index"
58520263 319 if ! download_file "${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL}" "${DOWNLOAD_TEMP}/index" noexit; then
832cb182 320 download_file "${DOWNLOAD_INDEX_PATH}" "${DOWNLOAD_TEMP}/index" normal
832cb182
CB
321 fi
322
832cb182
CB
323 # Parse it
324 while IFS=';' read -r f1 f2 f3 f4 f5 f6; do
325 if [ "${f1}" != "${DOWNLOAD_DIST}" ] || \
326 [ "${f2}" != "${DOWNLOAD_RELEASE}" ] || \
327 [ "${f3}" != "${DOWNLOAD_ARCH}" ] || \
328 [ "${f4}" != "${DOWNLOAD_VARIANT}" ] || \
329 [ -z "${f6}" ]; then
330 continue
71d3a659
SG
331 fi
332
832cb182
CB
333 DOWNLOAD_BUILD="${f5}"
334 DOWNLOAD_URL="${f6}"
71d3a659 335
832cb182
CB
336 unset f1 f2 f3 f4 f5 f6
337 break
338 done < "${DOWNLOAD_TEMP}/index"
3f7be9d0 339
832cb182
CB
340 if [ -z "${DOWNLOAD_URL}" ]; then
341 echo "ERROR: Couldn't find a matching image" 1>&1
342 exit 1
343 fi
71d3a659 344
832cb182
CB
345 if [ -d "${LXC_CACHE_PATH}" ] && [ -f "${LXC_CACHE_PATH}/build_id" ] && \
346 [ "$(cat "${LXC_CACHE_PATH}/build_id")" = "${DOWNLOAD_BUILD}" ]; then
347 echo "The cache is already up to date"
348 echo "Using image from local cache"
349 else
350 # Download the actual files
351 echo "Downloading the rootfs"
352 download_file "${DOWNLOAD_URL}/rootfs.tar.xz" "${DOWNLOAD_TEMP}/rootfs.tar.xz" normal
832cb182
CB
353
354 echo "Downloading the metadata"
355 download_file "${DOWNLOAD_URL}/meta.tar.xz" "${DOWNLOAD_TEMP}/meta.tar.xz" normal
832cb182
CB
356
357 if [ -d "${LXC_CACHE_PATH}" ]; then
358 rm -Rf "${LXC_CACHE_PATH}"
359 fi
360 mkdir -p "${LXC_CACHE_PATH}"
361 mv "${DOWNLOAD_TEMP}/rootfs.tar.xz" "${LXC_CACHE_PATH}"
362 if ! tar Jxf "${DOWNLOAD_TEMP}/meta.tar.xz" -C "${LXC_CACHE_PATH}"; then
363 echo "ERROR: Invalid rootfs tarball." 2>&1
364 exit 1
365 fi
3f7be9d0 366
832cb182 367 echo "${DOWNLOAD_BUILD}" > "${LXC_CACHE_PATH}/build_id"
71d3a659 368
832cb182
CB
369 if [ -n "${LXC_MAPPED_UID}" ] && [ "${LXC_MAPPED_UID}" != "-1" ]; then
370 # As the script is run in strict mode (set -eu), all commands
371 # exiting with non 0 would make the script stop.
372 # || true or || : (more portable) prevents that.
373 chown -R "${LXC_MAPPED_UID}" "${LXC_CACHE_BASE}" >/dev/null 2>&1 || :
71d3a659 374 fi
832cb182
CB
375 if [ -n "${LXC_MAPPED_GID}" ] && [ "${LXC_MAPPED_GID}" != "-1" ]; then
376 chgrp -R "${LXC_MAPPED_GID}" "${LXC_CACHE_BASE}" >/dev/null 2>&1 || :
71d3a659 377 fi
832cb182
CB
378 echo "The image cache is now ready"
379 fi
71d3a659 380else
832cb182 381 echo "Using image from local cache"
71d3a659
SG
382fi
383
384# Unpack the rootfs
385echo "Unpacking the rootfs"
fecf101c
SG
386
387EXCLUDES=""
388excludelist=$(relevant_file excludes)
389if [ -f "${excludelist}" ]; then
832cb182
CB
390 while read -r line; do
391 EXCLUDES="${EXCLUDES} --exclude=${line}"
392 done < "${excludelist}"
71d3a659
SG
393fi
394
3f7be9d0
WG
395# Do not surround ${EXCLUDES} by quotes. This does not work. The solution could
396# use array but this is not POSIX compliant. The only POSIX compliant solution
397# is to use a function wrapper, but the latter can't be used here as the args
398# are dynamic. We thus need to ignore the warning brought by shellcheck.
399# shellcheck disable=SC2086
832cb182 400tar --anchored ${EXCLUDES} --numeric-owner -xpJf "${LXC_CACHE_PATH}/rootfs.tar.xz" -C "${LXC_ROOTFS}"
fecf101c 401
3f7be9d0 402mkdir -p "${LXC_ROOTFS}/dev/pts/"
fecf101c 403
71d3a659 404# Setup the configuration
3f7be9d0
WG
405configfile="$(relevant_file config)"
406fstab="$(relevant_file fstab)"
407if [ ! -e "${configfile}" ]; then
832cb182
CB
408 echo "ERROR: meta tarball is missing the configuration file" 1>&2
409 exit 1
71d3a659
SG
410fi
411
412## Extract all the network config entries
832cb182 413sed -i -e "/lxc.net.0/{w ${LXC_PATH}/config-network" -e "d}" "${LXC_PATH}/config"
71d3a659
SG
414
415## Extract any other config entry
3f7be9d0 416sed -i -e "/lxc./{w ${LXC_PATH}/config-auto" -e "d}" "${LXC_PATH}/config"
71d3a659
SG
417
418## Append the defaults
832cb182
CB
419{
420 echo ""
421 echo "# Distribution configuration"
422 cat "$configfile"
423} >> "${LXC_PATH}/config"
71d3a659
SG
424
425## Add the container-specific config
832cb182
CB
426{
427 echo ""
428 echo "# Container specific configuration"
429 if [ -e "${LXC_PATH}/config-auto" ]; then
430 cat "${LXC_PATH}/config-auto"
3f7be9d0 431 rm "${LXC_PATH}/config-auto"
832cb182
CB
432 fi
433 if [ -e "${fstab}" ]; then
434 echo "lxc.mount.fstab = ${LXC_PATH}/fstab"
435 fi
436 echo "lxc.uts.name = ${LXC_NAME}"
437} >> "${LXC_PATH}/config"
71d3a659
SG
438
439## Re-add the previously removed network config
440if [ -e "${LXC_PATH}/config-network" ]; then
832cb182
CB
441 {
442 echo ""
443 echo "# Network configuration"
444 cat "${LXC_PATH}/config-network"
3f7be9d0 445 rm "${LXC_PATH}/config-network"
832cb182 446 } >> "${LXC_PATH}/config"
71d3a659
SG
447fi
448
449TEMPLATE_FILES="${LXC_PATH}/config"
450
451# Setup the fstab
3f7be9d0 452if [ -e "${fstab}" ]; then
832cb182
CB
453 cp "${fstab}" "${LXC_PATH}/fstab"
454 TEMPLATE_FILES="${TEMPLATE_FILES};${LXC_PATH}/fstab"
71d3a659
SG
455fi
456
457# Look for extra templates
458if [ -e "$(relevant_file templates)" ]; then
832cb182
CB
459 while read -r line; do
460 fullpath="${LXC_ROOTFS}/${line}"
461 [ ! -e "${fullpath}" ] && continue
462 TEMPLATE_FILES="${TEMPLATE_FILES};${fullpath}"
463 done < "$(relevant_file templates)"
71d3a659
SG
464fi
465
466# Replace variables in all templates
3f7be9d0
WG
467OLD_IFS=${IFS}
468IFS=";"
469for file in ${TEMPLATE_FILES}; do
470 [ ! -f "${file}" ] && continue
832cb182
CB
471 sed -i "s#LXC_NAME#${LXC_NAME}#g" "${file}"
472 sed -i "s#LXC_PATH#${LXC_PATH}#g" "${file}"
473 sed -i "s#LXC_ROOTFS#${LXC_ROOTFS}#g" "${file}"
474 sed -i "s#LXC_TEMPLATE_CONFIG#${LXC_TEMPLATE_CONFIG}#g" "${file}"
475 sed -i "s#LXC_HOOK_DIR#${LXC_HOOK_DIR}#g" "${file}"
71d3a659 476done
3f7be9d0 477IFS=${OLD_IFS}
71d3a659 478
491a01cf 479# prevent mingetty from calling vhangup(2) since it fails with userns on CentOS / Oracle
3f7be9d0 480if [ -f "${LXC_ROOTFS}/etc/init/tty.conf" ]; then
832cb182 481 sed -i 's|mingetty|mingetty --nohangup|' "${LXC_ROOTFS}/etc/init/tty.conf"
6e53ca56
SC
482fi
483
3f7be9d0 484if [ -n "${LXC_MAPPED_UID}" ] && [ "${LXC_MAPPED_UID}" != "-1" ]; then
832cb182 485 chown "${LXC_MAPPED_UID}" "${LXC_PATH}/config" "${LXC_PATH}/fstab" >/dev/null 2>&1 || :
71d3a659 486fi
832cb182 487
3f7be9d0 488if [ -n "${LXC_MAPPED_GID}" ] && [ "${LXC_MAPPED_GID}" != "-1" ]; then
832cb182 489 chgrp "${LXC_MAPPED_GID}" "${LXC_PATH}/config" "${LXC_PATH}/fstab" >/dev/null 2>&1 || :
2133f58c 490fi
71d3a659
SG
491
492if [ -e "$(relevant_file create-message)" ]; then
832cb182
CB
493 echo ""
494 echo "---"
495 cat "$(relevant_file create-message)"
71d3a659
SG
496fi
497
498exit 0