* Imported tools to dump information about files in a container.
The "dump-info" tool works only for Debian-based distro for now.
This commit is contained in:
68
containers/simg-dump-info-Debian.sh
Executable file
68
containers/simg-dump-info-Debian.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/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"
|
||||
)
|
||||
|
||||
29
containers/simg-list-all-files.sh
Executable file
29
containers/simg-list-all-files.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Dumps all the filenames on the container.
|
||||
# By default, run this on the root directory of the container.
|
||||
# This tool does NOT assume that the root directory is "/"
|
||||
# to allow access to sandbox _outside_ the container itself.
|
||||
# All external mount points are ignored.
|
||||
|
||||
_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
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
_simg_list_all_files "$@"
|
||||
Reference in New Issue
Block a user