From b4be2a30cfe86e7f081b2fd7ef72a7ec3b3645b2 Mon Sep 17 00:00:00 2001 From: Charles Duffy Date: Thu, 26 Oct 2017 12:36:10 -0500 Subject: [PATCH] Add off-by-default --rsyncable option When active, this option compromises compression ratio and removes timestamps from the generated cpio archive to minimize differences between subsequent builds of the same content. - Requires gzip with --rsyncable support (present in 1.8) - Moves from BSD to GNU cpio for --reproducible option (requires 2.12) --- mkinitcpio | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 42b8290..7f37137 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -21,7 +21,7 @@ _d_presets=mkinitcpio.d _optmoduleroot= _optgenimg= _optcompress= _opttargetdir= _optshowautomods=0 _optsavetree=0 _optshowmods=0 -_optquiet=1 _optcolor=1 +_optquiet=1 _optcolor=1 _optrsyncable=0 _optskiphooks=() _optaddhooks=() _hooks=() _optpreset=() declare -A _runhooks _addedmodules _modpaths _autodetect_cache @@ -52,6 +52,7 @@ usage: ${0##*/} [options] -p, --preset Build specified preset from /etc/mkinitcpio.d -P, --allpresets Process all preset files in /etc/mkinitcpio.d -r, --moduleroot Root directory for modules (default: /) + -R, --rsyncable Attempt to generate builds with smaller deltas -S, --skiphooks Skip specified hooks, comma-separated, during build -s, --save Save build directory. (default: no) -d, --generatedir Write generated image into @@ -205,6 +206,11 @@ build_image() { cat) unset COMPRESSION_OPTIONS ;; + gzip) + if (( _optrsyncable )); then + COMPRESSION_OPTIONS+=(--rsyncable) + fi + ;; xz) COMPRESSION_OPTIONS+=(--check=crc32) ;; @@ -215,14 +221,21 @@ build_image() { cpio_opts=('-0' '-o' '-H' 'newc') (( _optquiet )) && cpio_opts+=('--quiet') + (( _optrsyncable )) && cpio_opts+=('--reproducible') + (( _optrsyncable )) && find "$BUILDROOT" -exec touch -d '@0' -- {} + if (( EUID != 0 )); then warning 'Not building as root, ownership cannot be preserved' - cpio_opts+=('-R' '0:0') + cpio_opts+=('-R' '+0:+0') fi pushd "$BUILDROOT" >/dev/null find -mindepth 1 -printf '%P\0' | - LANG=C bsdcpio "${cpio_opts[@]}" | + if (( _optrsyncable )); then + LC_COLLATE=C LC_CTYPE=C sort -z + else + cat + fi | + LANG=C cpio "${cpio_opts[@]}" | $compress "${COMPRESSION_OPTIONS[@]}" > "$out" pipesave=("${PIPESTATUS[@]}") # save immediately popd >/dev/null @@ -315,10 +328,11 @@ process_preset() ( trap 'cleanup 130' INT trap 'cleanup 143' TERM -_opt_short='A:c:g:H:hk:nLMPp:r:S:sd:t:Vvz:' +_opt_short='A:c:g:H:hk:nLMPp:r:RS:sd:t:Vvz:' _opt_long=('add:' 'addhooks:' 'config:' 'generate:' 'hookhelp:' 'help' 'kernel:' 'listhooks' 'automods' 'moduleroot:' 'nocolor' 'allpresets' - 'preset:' 'skiphooks:' 'save' 'generatedir:' 'builddir:' 'version' 'verbose' 'compress:') + 'preset:' 'rsyncable' 'skiphooks:' 'save' 'generatedir:' 'builddir:' + 'version' 'verbose' 'compress:') parseopts "$_opt_short" "${_opt_long[@]}" -- "$@" || exit 1 set -- "${OPTRET[@]}" @@ -407,6 +421,9 @@ while :; do shift _optmoduleroot=$1 ;; + -R|--rsyncable) + _optrsyncable=1 + ;; --) shift break 2 -- 2.14.3