From 9edb1e040d7215baa1452bded61fb70731861b02 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 29 Jun 2021 13:29:56 -0400 Subject: [PATCH] * Imported tools to dump information about files in a container. The "dump-info" tool works only for Debian-based distro for now. --- containers/simg-dump-info-Debian.sh | 68 +++++++++++++++++++++++++++++ containers/simg-list-all-files.sh | 29 ++++++++++++ 2 files changed, 97 insertions(+) create mode 100755 containers/simg-dump-info-Debian.sh create mode 100755 containers/simg-list-all-files.sh diff --git a/containers/simg-dump-info-Debian.sh b/containers/simg-dump-info-Debian.sh new file mode 100755 index 0000000..767d62c --- /dev/null +++ b/containers/simg-dump-info-Debian.sh @@ -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" +) + diff --git a/containers/simg-list-all-files.sh b/containers/simg-list-all-files.sh new file mode 100755 index 0000000..fe40efd --- /dev/null +++ b/containers/simg-list-all-files.sh @@ -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 "$@"