Mail archive
alpine-aports

[alpine-aports] [PATCH] Cmdline override opts, rootdir support, honor $TMPDIR.

From: Linus Swälas <linus.swalas_at_borderless.se>
Date: Thu, 6 Oct 2016 04:58:56 +0200

Changes to the more intuitive behaviour that options given on the
command line overrides options given in the config file.

Now honors $TMPDIR if -t is not given.

Adds support for having basedir and rootdir, config comes from
the rootdir, contents for the initramfs comes from the basedir.
---
 ...ine-override_rootdir-support_honor-tmpdir.patch | 182 +++++++++++++++++++++
 main/mkinitfs/APKBUILD                             |  12 +-
 2 files changed, 190 insertions(+), 4 deletions(-)
 create mode 100644 main/mkinitfs/0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch
diff --git a/main/mkinitfs/0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch b/main/mkinitfs/0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch
new file mode 100644
index 0000000..94abbe7
--- /dev/null
+++ b/main/mkinitfs/0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch
_at_@ -0,0 +1,182 @@
+--- mkinitfs-3.0.5/mkinitfs.in	2016-10-05 23:18:32.000000000 +0200
++++ mkinitfs-3.0.5.new/mkinitfs.in	2016-10-06 01:59:55.000000000 +0200
+_at_@ -9,6 +9,8 @@
+ fstab="$datadir"/fstab
+ passwd="$datadir"/passwd
+ group="$datadir"/group
++basedir=''
++tmpdir=''
+ 
+ startdir=$PWD
+ 
+_at_@ -126,15 +128,19 @@
+ 	rm -rf "$tmpdir"/lib/firmware
+ 	mkdir -p "$tmpdir"/lib/firmware
+ 	find "$tmpdir"/lib/modules -type f -name "*.ko" | xargs modinfo -F firmware | sort -u | while read FW; do
+-		[ -e "${basedir}/lib/firmware/${FW}" ] && install -pD "${basedir}/lib/firmware/${FW}" "$tmpdir"/lib/firmware/$FW
++		[ -e "${basedir}/lib/firmware/${FW}" ] && install -pD "${basedir}/lib/firmware/${FW}" "${tmpdir}/lib/firmware/${FW}"
+ 	done
+ 	return 0
+ }
+ 
+ initfs_apk_keys() {
+-	mkdir -p "$tmpdir"/etc/apk/keys
+-	[ "$hostkeys" ] && cp "/etc/apk/keys/"* "$tmpdir"/etc/apk/keys/
+-	cp "${basedir}etc/apk/keys/"* "$tmpdir"/etc/apk/keys/
++	# If the basedir has nothing to copy, and we're not asked to copy the host's keys, don't do anything.
++	if [ ! -d "${basedir}etc/apk/keys/" ] && [ -z "$hostkeys" ]; then
++		return
++	fi
++	mkdir -p "${tmpdir}/etc/apk/keys"
++	[ -n "$hostkeys" ] && cp "/etc/apk/keys/"* "${tmpdir}/etc/apk/keys/"
++	cp "${basedir}etc/apk/keys/"* "${tmpdir}/etc/apk/keys/"
+ }
+ 
+ initfs_cpio() {
+_at_@ -142,9 +148,9 @@
+ 		(cd "$tmpdir" && find . )
+ 		return
+ 	fi
+-	rm -f $outfile
++	rm -f "$outfile"
+ 	umask 0022
+-	(cd "$tmpdir" && find . | cpio --quiet -o -H newc | gzip -9) > $outfile
++	(cd "$tmpdir" && find . | cpio --quiet -o -H newc | gzip -9) > "$outfile"
+ }
+ 
+ usage() {
+_at_@ -164,41 +170,62 @@
+ 	-L  list available features
+ 	-o  set another outfile
+ 	-q  Quiet mode
++	-r  use another root dir
+ 	-t  use tempdir when creating initramfs image
+ 
++  Config and output is based at rootdir, files and modules to be included in
++  the initramfs comes from basedir.
+ EOF
+ 	exit 1
+ }
+ 
+ # main
+ 
+-
+-while getopts "b:c:f:F:hi:kKLlo:qt:" opt; do
++while getopts "b:c:f:F:hi:kKLlo:qr:t:" opt; do
+ 	case "$opt" in
+-		b) basedir="$OPTARG";;
+-		c) config="$OPTARG";;
+-		F) myfeatures="$OPTARG";;
+-		f) fstab="$OPTARG";;
++		b) arg_basedir="$OPTARG";;
++		c) arg_config="$OPTARG";;
++		F) arg_features="$OPTARG";;
++		f) arg_fstab="$OPTARG";;
+ 		h) usage;;
+-		i) init=$OPTARG;;
+-		k) keeptmp=1;;
+-		K) hostkeys=1;;
++		i) arg_init=$OPTARG;;
++		k) arg_keeptmp=1;;
++		K) arg_hostkeys=1;;
+ 		L) list_features=1;;
+ 		l) list_sources=1;;
+-		o) outfile="$OPTARG";;
++		o) arg_outfile="$OPTARG";;
+ 		q) quiet=1;;
+-		t) tmpdir="$OPTARG";;
++		r) arg_rootdir="$OPTARG";;
++		t) arg_tmpdir="$OPTARG";;
+ 		*) usage;;
+ 	esac
+ done
+ shift $(( $OPTIND - 1 ))
+ 
++
+ . $(readlink -f "$config")
+-features_dir=${features_dir:-"${basedir%/:-}/${sysconfdir#/}/features.d"}
+-[ -n "$myfeatures" ] && features="$myfeatures"
++
++# Override any options read from the config with what the
++# user has specifed on the commandline.
++[ -n "$arg_basedir"  ] && basedir="$arg_basedir"
++[ -n "$arg_config"   ] && config="$arg_config"
++[ -n "$arg_features" ] && features="$arg_features"
++[ -n "$arg_fstab"    ] && fstab="$arg_fstab"
++[ -n "$arg_init"     ] && init="$arg_init"
++[ -n "$arg_keeptmp"  ] && keeptmp="$arg_keeptmp"
++[ -n "$arg_hostkeys" ] && hostkeys="$arg_hostkeys"
++[ -n "$arg_outfile"  ] && outfile="$arg_outfile"
++[ -n "$arg_rootdir"  ] && rootdir="$arg_rootdir"
++[ -n "$arg_tmpdir"   ] && tmpdir="$arg_tmpdir"
++
++
++rootdir="${rootdir%/}/"
++[ "${rootdir}" = "${rootdir#/}" ] && rootdir="${PWD}/${rootdir}"
++
++features_dir=${features_dir:-"${rootdir%/}/${sysconfdir#/}/features.d"}
+ 
+ if [ -n "$list_features" ]; then
+-	for i in $features_dir/*.files $features_dir/*.modules; do
++	for i in "$features_dir"/*.files "$features_dir"/*.modules; do
+ 		[ -e "$i" ] || continue
+ 		local file=${i##*/}
+ 		echo ${file%.*}
+_at_@ -206,24 +233,27 @@
+ 	exit 0
+ fi
+ 
+-basedir="${basedir%/}/"
+-[ "${basedir}" = "${basedir#/}" ] && basedir="${PWD}/${basedir}"
++if [ -z "$basedir" ]; then
++	basedir="$rootdir"
++else
++	[ "${basedir}" = "${basedir#/}" ] && basedir="${PWD}/${basedir}"
++fi
+ 
+ 
+ [ -n "$1" ] && kernel="$1"
+ [ -z "$kernel" ] && kernel=$(uname -r)
+ kerneldir="${basedir}lib/modules/$kernel"
+ 
++if [ ! -d "$kerneldir" ]; then
++	echo "$kerneldir does not exist or is not a directory"
++	exit 1
++fi
++
+ kflavor=${kernel##*-}
+ [ "$kflavor" = "$kernel" ] && kflavor=vanilla
+ 
+ if [ -z "$outfile" ]; then
+-	outfile="${basedir}boot/initramfs-${kflavor}"
+-fi
+-
+-if [ ! -d "$kerneldir" ]; then
+-	echo "$kerneldir does not exist or is not a directory"
+-	exit 1
++	outfile="${rootdir}boot/initramfs-${kernel}"
+ fi
+ 
+ if [ -n "$DEBUG_KMOD" ]; then
+_at_@ -232,13 +262,19 @@
+ fi
+ 
+ if [ -z "$tmpdir" ]; then
+-	tmpdir=$(mktemp -d /tmp/mkinitfs.XXXXXX)
++	tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/mkinitfs.XXXXXX")
+ else
+ 	mkdir -p "$tmpdir"
+ fi
+ 
++tmpdir=$(readlink -f "$tmpdir")
++if [ '/' == "$tmpdir" ] ; then
++	echo "tmpdir must not be /"
++	exit 1
++fi
++
+ if [ -z "$keeptmp" ]; then
+-	[ -d "$tmpdir" ] && rm -rf "$tmpdir"/*
++	[ -d "$tmpdir" ] && rm -rf "$tmpdir"
+ fi
+ 
+ if [ -z "$list_sources" ] && [ -z "$quiet" ]; then
diff --git a/main/mkinitfs/APKBUILD b/main/mkinitfs/APKBUILD
index a7a3d9e..c75961c 100644
--- a/main/mkinitfs/APKBUILD
+++ b/main/mkinitfs/APKBUILD
_at_@ -2,7 +2,7 @@
 pkgname=mkinitfs
 pkgver=3.0.5
 _ver=${pkgver%_git*}
-pkgrel=4
+pkgrel=5
 pkgdesc="Tool to generate initramfs images for Alpine"
 url="http://git.alpinelinux.org/cgit/mkinitfs"
 makedepends_build=""
_at_@ -16,6 +16,7 @@ source="http://dev.alpinelinux.org/archive/$pkgname/$pkgname-$_ver.tar.xz
 	0001-init-dont-use-local-in-global-scope.patch
 	0001-group-sync-with-alpine-baselayout.patch
 	0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch
+	0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch
 	"
 arch="all"
 license="GPL2"
_at_@ -35,14 +36,17 @@ md5sums="de3f95912a542dfabbf0573620549a29  mkinitfs-3.0.5.tar.xz
 a4227598291fa7338ad1128bfef3720c  0001-init-add-support-for-ttyMFD-and-ttyUSB-serial-consol.patch
 a74631b5f40001dd259a2a6ebcaec544  0001-init-dont-use-local-in-global-scope.patch
 db888a1a502fe281bbe0b1add81bf62f  0001-group-sync-with-alpine-baselayout.patch
-a46eb97de6742400ca04777a0a8478b2  0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch"
+a46eb97de6742400ca04777a0a8478b2  0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch
+fadbbb5e49ead2c6fd8d4e880c83bafa  0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch"
 sha256sums="3f13619f161c506796b91f2db17644eba25c2ffc923aa0c8fff0213d1f660aa4  mkinitfs-3.0.5.tar.xz
 17547dbc77bd19d940550ea6243b44212d21a6797aee4202e4e22c31143bf9e6  0001-init-add-support-for-ttyMFD-and-ttyUSB-serial-consol.patch
 7253cd8ebc1487e4bfb98d81edd68b24a4364e9fa8e48c73fc6903f2077b056e  0001-init-dont-use-local-in-global-scope.patch
 17b8a04db505eea9e176da00f9389ca80f65ed88c0288f6785f9ab108164361a  0001-group-sync-with-alpine-baselayout.patch
-8daccc844576f0b06fc9c15a30d750bfecda019b476a0be4cf9bcd7139e219cf  0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch"
+8daccc844576f0b06fc9c15a30d750bfecda019b476a0be4cf9bcd7139e219cf  0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch
+c24fb5b60a1bdd9d0888cd9ce76996fe5c45cb384b0e30a8837e3cf3724a7727  0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch"
 sha512sums="246f25ce3fb65ea19dbe611ad44a106930c28b2c7111908462d4a252433011280715b2cf87ee81cc6f0860679fd1d0a109d03040647498137e42b22ccc711662  mkinitfs-3.0.5.tar.xz
 35b4cf3f74e394d87b321d335ec4dff6973bfd9a38cdc81609e21e025ee3fb9af7d2744cf9941531603df829af1f7fba433074915ba88a688d375cfe40dad07a  0001-init-add-support-for-ttyMFD-and-ttyUSB-serial-consol.patch
 ca1bd66bc6d366dc74da389397f3e0d81b3afa21a534269230ab33f415e633b19ce54327b78713847461b67d6d23a85019c79e1fbbf1a964ee0bd26013ddf33f  0001-init-dont-use-local-in-global-scope.patch
 2736650e0c06d47f2cd0dcc4a9c3d575b2b5284ee8d1aa0cccd45b5855ff6704171f5b7761b8c88536c8dca84943810e9332db9f2e03681f6355c5068a3a3092  0001-group-sync-with-alpine-baselayout.patch
-712038089d3b58a3937549f25412803291690c992bd8e3002f02a46fc9c24903c94086704b5def3aecb422d46d7c501beeaa665000bc7da6ec20965e52eca5a1  0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch"
+712038089d3b58a3937549f25412803291690c992bd8e3002f02a46fc9c24903c94086704b5def3aecb422d46d7c501beeaa665000bc7da6ec20965e52eca5a1  0001-mkinitfs-add-K-flag-to-copy-host-keys-to-new-initram.patch
+81880870195b6c64d55570954be2c8e879f58f779ec165ae34504bac43b969dfcb79b0469ab96100df12fb17a7e7b362bb52bbc3402705a931cd41f7304c6d0d  0002-mkinitfs_cmdline-override_rootdir-support_honor-tmpdir.patch"
-- 
2.10.0
-- 
A: Because it messes up the order in which people normally read text. 
Q: Why is top-posting such a bad thing? 
---
Unsubscribe:  alpine-aports+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-aports+help_at_lists.alpinelinux.org
---
Received on Thu Oct 06 2016 - 04:58:56 GMT