You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.9 KiB
68 lines
1.9 KiB
#!/bin/bash
|
|
#
|
|
# Tool to dump info from a singularity image
|
|
# Run this as "root" from _inside_ the container image,
|
|
# because it will interrogate the system using the image's
|
|
# contained files.
|
|
#
|
|
# This is for Debian-based image
|
|
#
|
|
# Usage:
|
|
# simg-dump-info.sh INFO_DIR CONT_NAME [IMAGE_ROOT_DIR]
|
|
#
|
|
# INFO_DIR is the location to dump the info files
|
|
# CONT_NAME is the name of the container (to be used as the basenames)
|
|
#
|
|
# Info dumped so far:
|
|
# - ${CONT_NAME}.files - actual list of files
|
|
# - ${CONT_NAME}.files-dpkg - registration of files according to dpkg
|
|
# - ${CONT_NAME}.lists-dpkg.tar - registration of files according to dpkg
|
|
# (individual list files)
|
|
# - ${CONT_NAME}.dpkg-l - list of installed packages
|
|
|
|
|
|
_simg_list_all_files () {
|
|
local ROOT_DIR="${1:-.}"
|
|
|
|
find "$ROOT_DIR" -mount \
|
|
| sort \
|
|
| awk -v ROOT="$ROOT_DIR" '
|
|
BEGIN {
|
|
ROOTX = ROOT
|
|
gsub(/\/+$/, "", ROOTX)
|
|
ROOTX = (ROOTX "/")
|
|
len_ROOTX = length(ROOTX)
|
|
}
|
|
$0 == ROOT { next }
|
|
(substr($0, 1, len_ROOTX) == ROOTX) {
|
|
print(substr($0, len_ROOTX))
|
|
next
|
|
}
|
|
'
|
|
}
|
|
|
|
|
|
set -e
|
|
|
|
MYSELF=$0
|
|
MYDIR=$(dirname "$MYSELF")
|
|
|
|
INFO_DIR=${1:?INFO_DIR required as arg 1}
|
|
CONT_NAME=${2:?CONT_NAME required as arg 2}
|
|
CONT_IMAGE_ROOT_DIR=${3:-/}
|
|
|
|
|
|
# Get the view of the files *ACTUALLY* residing in the container
|
|
_simg_list_all_files "${CONT_IMAGE_ROOT_DIR}" > "${INFO_DIR}/${CONT_NAME}.files"
|
|
|
|
dpkg -l > "${INFO_DIR}/${CONT_NAME}.dpkg-l"
|
|
|
|
# Get the view of files registered to dpkg
|
|
# (In some containers the files do not exist there because they
|
|
# were somehow deleted, e.g. doc files, man pages, ...)
|
|
(
|
|
cd /var/lib/dpkg/info
|
|
tar cf "${INFO_DIR}/${CONT_NAME}.lists-dpkg.tar" *.list
|
|
cat *.list | sort | uniq > "${INFO_DIR}/${CONT_NAME}.dpkg-files"
|
|
)
|
|
|
|
|