ironic-python-agent-builder/dib/ironic-ramdisk-base/cleanup.d/99-ramdisk-create

49 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# dib-lint: disable=safe_sudo
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
[ -n "$TARGET_ROOT" ]
USER=${USER:-$(whoami)}
source $_LIB/img-functions
IMAGE_PATH=$(readlink -f $IMAGE_NAME)
cd $TARGET_ROOT
DIB_IPA_COMPRESS_CMD="${DIB_IPA_COMPRESS_CMD:-gzip}"
DIB_IPA_PATHS_TO_PRUNE="${DIB_IPA_PATHS_TO_PRUNE:-'./sys/*' './tmp/*' \
'./boot/*' './root/.cache' '*site-packages/babel/locale-data/*' \
'./usr/include/*' './usr/lib/locale/*' './usr/share/doc/*' \
'./usr/share/man/*' './usr/share/GeoIP/*' './usr/share/info/*' \
'./usr/share/licenses/*' './usr/share/locale/*' './usr/share/misc/m*' \
'./usr/src/kernels/*' './var/cache/*' './var/log/*'}"
echo "#disabled" > ./tmp/fstab.new
sudo mv ./tmp/fstab.new ./etc/fstab
sudo ln -s ./sbin/init ./
# Build up the command to find files to add to initramfs
# using configurable list of paths to prune
FIND_COMMAND="find . -xdev "
for path in $DIB_IPA_PATHS_TO_PRUNE; do
FIND_COMMAND="$FIND_COMMAND -path $path -prune -o "
done
FIND_COMMAND="$FIND_COMMAND -name '*.pyc' -prune -o "
FIND_COMMAND="$FIND_COMMAND -name '*.pyo' -prune -o -print "
sudo $FIND_COMMAND | sudo cpio -o -H newc | ${DIB_IPA_COMPRESS_CMD} > ${IMAGE_PATH}.initramfs
select_boot_kernel_initrd $TARGET_ROOT
sudo cp $BOOTDIR/$KERNEL ${IMAGE_PATH}.kernel
sudo chown $USER: ${IMAGE_PATH}.kernel
# Output image sizes for debugging
sudo ls -lh ${IMAGE_PATH}.*