diff --git a/config b/config index 8965bb5..6884be0 100644 --- a/config +++ b/config @@ -3,7 +3,7 @@ # # debug mode -#debug=0 +debug=1 # custom init #init="" @@ -18,11 +18,11 @@ #compress="" # root fs ( device,partuuid,uuid,label ) -#root="" +root="UUID=07729c48-25d8-4096-acaf-ce5322915680" # root type # change this if you using busybox util-linux -#root_type="" +root_type="ext4" # root options #root_opts="" @@ -30,13 +30,13 @@ # disable this if you want to get rid of util-linux # NOTE busybox util-linux implemetation doesn't have # PARTUUID support and proper filesystem type autodetection -#util_linux=0 +util_linux=1 # device manager ( mdev,mdevd,udev ) -#devmgr="" +devmgr="mdev" # hostonly mode -#hostonly=0 +hostonly=0 # custom drivers #drivers="" @@ -45,7 +45,7 @@ #binaries="" # LVM support -#lvm=0 +lvm=1 # LVM logical volume name #lvm_name="" @@ -54,19 +54,19 @@ #lvm_group="" # LVM include config -#lvm_conf=0 +#lvm_conf=1 # LVM issue_discards -#lvm_discard=0 +lvm_discard=1 # LVM options #lvm_args="" # LUKS support -#luks=0 +luks=1 # LUKS encrypted root ( device,partuuid,uuid,label ) -#luks_root="" +luks_root="PARTUUID=b04395be-f467-458b-8630-9a429b487600" # luks mapper name ( /dev/mapper/ ) #luks_name="" @@ -78,7 +78,7 @@ #luks_keyfile="/path/to/keyfile" # LUKS allow_discards -#luks_discard=0 +luks_discard=1 # LUKS options #luks_args="" diff --git a/generate b/generate index 9071571..741b518 100755 --- a/generate +++ b/generate @@ -21,10 +21,11 @@ msg() { } usage() { + # TODO more options cat << EOF usage: $0 [options] -o, --output output file. default is $(readlink -f $(dirname "$0"))/initramfs-$(uname -r) - -f, --files files directory. default is $(readlink -f $(dirname "$0")) + -f, --files files directory. default is $(readlink -f $(dirname "$0")) EOF } @@ -53,6 +54,22 @@ parse_args() { done } +parse_conf() { + while read -r line; do + + # ignore comments + if [ ! "${line##\#*}" ]; then + continue + + # check if variable already exists via 'variable indirection' method + # if no exists then 'source' variable + # see https://stackoverflow.com/q/36235612 + elif [ ! "$(eval printf "%s" "\"\$${line%%=*}\"")" ]; then + eval "$line" + fi + done < "${filesdir:-$(readlink -f $(dirname "$0"))}/config" || msg panic "failed to parse config" +} + create_wrkdir() { msg info "creating working directory" @@ -102,6 +119,7 @@ create_symlinks() { msg info "creating symlinks" + # TODO remove grouping ( cd "$wrkdir" && { ln -s usr/lib lib ln -s usr/lib lib64 @@ -261,7 +279,7 @@ generate_depmod() { modker="${moddir}/${kernel}" - cp "${modker}/modules.builtin" "${modker}/modules.order" "${wrkdir}/${modker}" + cp "${modker}/modules.builtin" "${modker}/modules.order" "${wrkdir}${modker}" depmod -b "$wrkdir" "$kernel" } @@ -275,7 +293,7 @@ install_binary() { fullbin=$(command -v "$binary") - # check binary existence + # check if binary exists [ "$fullbin" ] || msg panic "$binary doesn't exists" # install and strip binary @@ -308,9 +326,9 @@ install_library() { # check symlink if [ -h "$library" ]; then - # check lib already existence - [ -e "${wrkdirlib}${namelib}" ] || - [ -e "${wrkdir}${fulllib}" ] || + # check if library already exists + [ -e "${wrkdirlib}${fulllib##*/}" ] || + [ -e "${wrkdirlib}${namelib}" ] || { # regular install -s -m755 "${fulllib}" -t "${wrkdirlib}" @@ -385,12 +403,16 @@ EOF create_initramfs() { msg info "creating initramfs image" + + # TODO add uncompressed option + # TODO remove grouping + { ( cd "$wrkdir" find . | cpio -oH newc | ${compress:-gzip -9} - ) | tee "${initramfs:-${filesdir}/initramfs-${kernel}}" + ) | tee "$initramfs" } > /dev/null 2>&1 || msg panic "failed to generate initramfs image" } @@ -399,11 +421,12 @@ create_initramfs() { [ "$(id -u)" = 0 ] || msg panic "must be run as root" parse_args "$@" +parse_conf -. "${filesdir:=$(readlink -f $(dirname "$0"))}/config" || msg panic "failed to source config" - -# remove wrkdir on exit or unexpected error -trap remove_wrkdir EXIT INT +: "${kernel:=$(uname -r)}" +: "${moddir:=/lib/modules}" +: "${filesdir:=$(readlink -f $(dirname "$0"))}" +: "${initramfs:=${filesdir}/initramfs-${kernel}}" [ "$debug" = 1 ] && { # debug shell commands @@ -412,8 +435,8 @@ trap remove_wrkdir EXIT INT trap - EXIT INT } -kernel="${kernel:-$(uname -r)}" -moddir="/lib/modules" +# remove wrkdir on exit or unexpected error +trap remove_wrkdir EXIT INT create_wrkdir create_structure @@ -440,4 +463,4 @@ esac install_files create_initramfs -msg info "done! check out ${initramfs:-${filesdir}/initramfs-${kernel}}" +msg info "done! check out $initramfs"