|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- #
|
|
|
|
|
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
|
|
|
|
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
|
|
|
|
# #
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
|
|
|
# not use this file except in compliance with the License. You may obtain #
|
|
|
|
@ -16,37 +16,40 @@
|
|
|
|
|
# limitations under the License. #
|
|
|
|
|
#--------------------------------------------------------------------------- #
|
|
|
|
|
|
|
|
|
|
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX")
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Umount the directory and remove it
|
|
|
|
|
cleanup()
|
|
|
|
|
{
|
|
|
|
|
[ "$MOUNT" = "yes" ] && umount "${TMP_DIR}"
|
|
|
|
|
rm -rf "${TMP_DIR}"
|
|
|
|
|
[ "$MOUNTED" = "yes" ] && umount -l "${ROOTFS_DIR}"
|
|
|
|
|
rm -r "${TMP_DIR}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get files that should be copy from
|
|
|
|
|
get_files()
|
|
|
|
|
{
|
|
|
|
|
diff -qr "$1" "$2" | grep "Only in $1" | cut -d ':' -f2 | awk '{$1=$1};1'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ "${RECREATE_TMPFS^^}" = "YES" ]; then
|
|
|
|
|
MOUNT=yes
|
|
|
|
|
|
|
|
|
|
mount --bind -o ro / "${TMP_DIR}"
|
|
|
|
|
|
|
|
|
|
IFS=$'\n'
|
|
|
|
|
|
|
|
|
|
# Copy only files that are in /run but not in /var/run
|
|
|
|
|
files=$(get_files "${TMP_DIR}"/run /var/run)
|
|
|
|
|
|
|
|
|
|
for file in $files;
|
|
|
|
|
do
|
|
|
|
|
cp -pr "${TMP_DIR}"/run/"${file}" /var/run &> /dev/null
|
|
|
|
|
done
|
|
|
|
|
if [ "${RECREATE_RUN^^}" = "YES" ] && [ "$(uname -s)" = 'Linux' ]; then
|
|
|
|
|
# Detection of real run-time variable data directory in case there
|
|
|
|
|
# would be images with (unusual) reverse symlink /run -> /var/run
|
|
|
|
|
if [ -d /run ] && ! [ -L /run ]; then
|
|
|
|
|
RUN_DIR=/run
|
|
|
|
|
elif [ -d /var/run ] && ! [ -L /var/run ]; then
|
|
|
|
|
RUN_DIR=/var/run
|
|
|
|
|
else
|
|
|
|
|
# this shouldn't happen
|
|
|
|
|
echo 'ERROR: No suitable run-time data directory in image!' >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX")
|
|
|
|
|
ROOTFS_DIR="${TMP_DIR}/rootfs"
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
chmod 0700 "${TMP_DIR}"
|
|
|
|
|
mkdir "${ROOTFS_DIR}"
|
|
|
|
|
|
|
|
|
|
mount --bind -o ro,nodev,noexec,nosuid / "${ROOTFS_DIR}"
|
|
|
|
|
MOUNTED=yes
|
|
|
|
|
|
|
|
|
|
# copy, but don't overwrite
|
|
|
|
|
# NOTE: using -i </dev/null is a workaround for silly cp in busybox without -n support
|
|
|
|
|
cp -aiv "${ROOTFS_DIR}/${RUN_DIR}" "$(dirname "${RUN_DIR}")" 2>/dev/null </dev/null
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
|
|
exit 0
|