Skip to content

Commit

Permalink
mkinitramfs-ll.{ba,z}sh: Added -e|--extension command line switch (su…
Browse files Browse the repository at this point in the history
…ggestion from PR #42)
  • Loading branch information
tokiclover committed Oct 31, 2016
1 parent 4fb8332 commit 0903142
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
22 changes: 12 additions & 10 deletions mkinitramfs-ll.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# $Header: mkinitramfs-ll/mkinitramfs-ll.bash Exp $
# $Author: (c) 2011-6 tokiclover <[email protected]> Exp $
# $License: 2-clause/new/simplified BSD Exp $
# $Version: 0.22.0 2016/06/02 12:33:03 Exp $
# $Version: 0.22.0 2016/10/31 12:33:03 Exp $
#

typeset -A PKGINFO
Expand All @@ -20,6 +20,7 @@ function usage {
Usage: ${PKGINFO[name]}.${PKGINFO[shell]} [-a|-all] [options]
-a, --all Short variant of '-lLgtq -H:btrfs:zfs:zram'
-e, --extension=cpio.img Extension to use (default to cpio.\$compressor)
-f, --font=REGEX Fonts to include in the initramfs
-F, --firmware=REGEX Firmware file/directory to include
-k, --kernel-version=KV Build an initramfs for kernel version VERSION
Expand Down Expand Up @@ -114,8 +115,8 @@ function donod {
shopt -qs extglob nullglob
typeset -a opt
opt=(
"-o" "ab:c:f:F:gk:lH:KLm:p:qrs:thu:y:?"
"-l" "all,bin:,compressor:,firmware:,font:,gpg,help"
"-o" "ab:c:e:f:F:gk:lH:KLm:p:qrs:thu:y:?"
"-l" "all,bin:,compressor:,extension:,firmware:,font:,gpg,help"
"-l" "hook:,luks,lvm,keep-tmpdir,module:,keymap:,kernel-version:"
"-l" "module-boot:,module-gpg:,module-remdev:,module-squashd:,module-tuxonice:"
"-l" "prefix:,rebuild,splash:,squashd,toi,usrdir:"
Expand All @@ -136,7 +137,7 @@ while true; do
(-[cdkp]|--[cpu]*|--kernel-*)
opts[${1/--/-}]="$2"
shift 2;;
(-[FHbfmsy]|--[bfks]*|--hook|--module*)
(-[FHbefmsy]|--[befks]*|--hook|--module*)
opts[${1/--/-}]+=":$2"
shift 2;;
(--)
Expand Down Expand Up @@ -238,7 +239,7 @@ fi
# @FUNCTION: CPIO image builder
# @ARG: <out-file>
function docpio {
local ext=.cpio initramfs=${1:-/boot/${opts[-initramfs]}}
local extension ext=cpio initramfs=${1:-/boot/${opts[-initramfs]}}
local cmd="find . -print0 | cpio -0 -ov -Hnewc"

case ${opts[-compressor]%% *} in
Expand All @@ -251,14 +252,15 @@ function docpio {
(lz4) ext+=.lz4;;
(*) opts[-compressor]=; warn "initramfs will not be compressed";;
esac
if [[ -f ${initramfs}${ext} ]]; then
mv ${initramfs}${ext}{,.old}
: ${extension:=${opt[-e]:-${opt[-extension]:-${ext}}}}
if [[ -f ${initramfs}.${extension} ]]; then
mv ${initramfs}.${extension}{,.old}
fi
if [[ -n "${ext#.cpio}" ]]; then
if [[ -n "${extension#cpio}" ]]; then
cmd+=" | ${opts[-compressor]} -c"
fi
eval ${cmd} > /${initramfs}${ext} ||
die "Failed to build ${initramfs}${ext} initramfs"
eval ${cmd} > /${initramfs}.${extension} ||
die "Failed to build ${initramfs}.${extension} initramfs"
}

echo -e "\e[1;32m>>>\e[0m building ${opts[-initramfs]}..."
Expand Down
22 changes: 12 additions & 10 deletions mkinitramfs-ll.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# $Header: mkinitramfs-ll/mkinitramfs-ll.zsh Exp $
# $Author: (c) 2011-6 tokiclover <[email protected]> Exp $
# $License: 2-clause/new/simplified BSD Exp $
# $Version: 0.22.0 2016/06/02 12:33:03 Exp $
# $Version: 0.22.0 2016/10/31 12:33:03 Exp $
#

typeset -A PKGINFO
Expand All @@ -20,6 +20,7 @@ function usage {
Usage: ${PKGINFO[name]}.${PKGINFO[shell]} [-a|-all] [options]
-a, --all Short variant of '-lLgtq -H:btrfs:zfs:zram'
-e, --extension=cpio.img Extension to use (default to cpio.\$compressor)
-f, --font=REGEX Fonts to include in the initramfs
-F, --firmware=REGEX Firmware file/directory to include
-k, --kernel-version=KV Build an initramfs for kernel version VERSION
Expand Down Expand Up @@ -119,8 +120,8 @@ typeset -A opts
typeset -a opt

opt=(
"-o" "ab:c:f:F:gk:lH:KLm:p:qrs:thu:y:?"
"-l" "all,bin:,compressor:,firmware:,font:,gpg,help"
"-o" "ab:c:e:f:F:gk:lH:KLm:p:qrs:thu:y:?"
"-l" "all,bin:,compressor:,extension:,firmware:,font:,gpg,help"
"-l" "hook:,luks,lvm,keep-tmpdir,module:,keymap:,kernel-version:"
"-l" "module-boot:,module-gpg:,module-remdev:,module-squashd:,module-tuxonice:"
"-l" "prefix:,rebuild,splash:,squashd,toi,usrdir:"
Expand All @@ -137,7 +138,7 @@ while true; do
(-[cdkp]|--[cpu]*|--kernel-*)
opts[${1/--/-}]=$2
shift 2;;
(-[FHbfmsy]|--[bfks]*|--hool|--module-*)
(-[FHbefmsy]|--[befks]*|--hool|--module-*)
opts[${1/--/-}]+=:$2
shift 2;;
(--)
Expand Down Expand Up @@ -233,7 +234,7 @@ if (( ${+config} )) {
# @FUNCTION: CPIO image builder
# @ARG: <out-file>
function docpio {
local ext=.cpio initramfs=${1:-/boot/${opts[-initramfs]}}
local extension ext=cpio initramfs=${1:-/boot/${opts[-initramfs]}}
local cmd="find . -print0 | cpio -0 -ov -Hnewc"

case ${opts[-compressor][(w)1]} {
Expand All @@ -246,14 +247,15 @@ function docpio {
(lz4) ext+=.lz4;;
(*) opts[-compressor]=; warn "initramfs will not be compressed";;
}
if [[ -f ${initramfs}${ext} ]] {
mv ${initramfs}${ext}{,.old}
: ${extension:=${opts[-e]:-${opts[-extension]:-${ext}}}}
if [[ -f ${initramfs}.${extension} ]] {
mv ${initramfs}.${extension}{,.old}
}
if [[ -n ${ext#.cpio} ]] {
if [[ -n ${extension#cpio} ]] {
cmd+=" | ${=opts[-compressor]} -c"
}
eval ${=cmd} > ${initramfs}${ext} ||
die "Failed to build ${initramfs}${ext} initramfs"
eval ${=cmd} > ${initramfs}.${extension} ||
die "Failed to build ${initramfs}.${extension} initramfs"
}

print -P "%F{blue}>>>%f building ${opts[-initramfs]}..."
Expand Down

0 comments on commit 0903142

Please sign in to comment.