Reputation: 761
$ install -m755 -d "/tmp/usr/lib/modules/4.14.4-1-ARCH/kernel"
creates multiple new directory entries inside a bash script that creates a Linux initramfs file. For the file/folder metadata to be consistent between runs, the idea is to reference the folder timestamps to the kernel itself, with touch --reference=<source_file> <new_created_directory>
.
The individually to be touched folders can be retrieved via install --verbose
command, like:
$ install -v -m755 -d "/tmp/usr/lib/modules/4.14.4-1-ARCH/kernel"
install: creating directory '/tmp/usr'
install: creating directory '/tmp/usr/lib'
install: creating directory '/tmp/usr/lib/modules'
install: creating directory '/tmp/usr/lib/modules/4.14.4-1-ARCH'
install: creating directory '/tmp/usr/lib/modules/4.14.4-1-ARCH/kernel'
install -v -d
output can be immediately piped into a readline type of code block./tmp
in the example above.How to create a directory structure with identical metadata on consecutive runs? For example the necessary touch command loop and parameter expansions (PE) to match the newly created directories by install
?
The parent bash script is writing a skeleton minimal Linux file and folder structure to a temporary location, that will finally be compressed into an initramfs structure. The goal is to be able to recreate binary identical initramfs files on consecutive script runs. By default the files are identical, but the metadata is not due to different creation/access timestamps.
Upvotes: 1
Views: 181
Reputation: 124704
After the directory structure is ready to create the initramfs
based on it,
set the timestamp of all files and directories to a reference point.
You can use the find
command for this:
find path/to/basedir -exec touch -r "$reference_file" {} +
If you want to touch only files that were created by install
commands,
than you can create a marker file that you can use with the -newer
predicate of find
, for example:
marker=/tmp/marker
touch "$marker"
install ...
find path/to/basedir -newer "$marker" -exec touch -r "$reference_file" {} +
If you want touch specifically the files printed by install -v -d ...
,
where all the output lines are expected to have this format:
install: creating directory '...'
Then you could pipe the output of install
to a loop that reads line by line,
and extracts the paths by chopping the prefix of the line until the first '
,
and chopping off everything from the last '
:
... | while read -r line; do
[[ $line = *'install: creating directory '* ]] || continue
line=${line#*\'}
line=${line%\'*}
touch -r "$reference_file" "$line"
done
Upvotes: 2