fix TODO's, minor improvements

This commit is contained in:
illiliti 2020-04-21 17:35:55 +03:00
parent 67dc4e50dd
commit 4b5645f3b0
3 changed files with 78 additions and 49 deletions

4
config
View File

@ -40,7 +40,9 @@
# compression program # compression program
# #
# default - gzip -9 # default - gzip -9
# example - compress="pigz -9" # example -
# compress="pigz -9"
# compress="none" # disable compress
# #
#compress="" #compress=""

View File

@ -5,9 +5,16 @@
# false positive # false positive
# shellcheck disable=2154 # shellcheck disable=2154
# TODO add some colors ? print()
panic() { printf "panic >> %s\n" "$1" >&2; panic=1; exit 1; } {
info() { printf "info >> %s\n" "$1"; } printf "%b %s\n" "${2:-\033[1;37m>>\033[m}" "$1"
}
panic()
{
print "$1" "\033[1;31m!!\033[m" >&2
exit 1
}
usage() usage()
{ {
@ -69,7 +76,7 @@ parse_args()
prepare_environment() prepare_environment()
{ {
info "preparing environment" print "preparing environment"
# false positive # false positive
# shellcheck disable=1090 # shellcheck disable=1090
@ -96,21 +103,35 @@ prepare_environment()
workdirlib="${workdir}/usr/lib/" workdirlib="${workdir}/usr/lib/"
modker="${moddir}/${kernel}" modker="${moddir}/${kernel}"
OLD_IFS="$IFS" OLD_IFS="$IFS"
trap trap_helper EXIT INT
# false positive
# shellcheck disable=2015
[ "$debug" = 1 ] && set -x ||:
} }
remove_workdir() trap_helper()
{ {
info "removing working directory" # TODO need cleanup
ret="$?"
rm -rf "$workdir" trap - EXIT INT
[ "$debug" != 1 ] && {
print "removing working directory"
rm -rf "$workdir"
}
[ "$ret" != 0 ] && panic "something went wrong"
} }
install_requirements() install_requirements()
{ {
info "installing requirements" print "installing requirements"
# install user specified and required binaries # install user specified and required binaries
for _binary in $binaries \[ sh ln sleep mount printf setsid switch_root; do for _binary in \[ sh ln sleep mount printf setsid switch_root $binaries; do
install_binary "$_binary" install_binary "$_binary"
done done
@ -129,7 +150,7 @@ install_requirements()
create_structure() create_structure()
{ {
info "creating directory structure" print "creating directory structure"
mkdir -p \ mkdir -p \
"${workdir}/etc" \ "${workdir}/etc" \
@ -145,7 +166,7 @@ create_structure()
create_symlinks() create_symlinks()
{ {
info "creating symlinks" print "creating symlinks"
ln -s usr/lib "${workdir}/lib" ln -s usr/lib "${workdir}/lib"
ln -s usr/lib "${workdir}/lib64" ln -s usr/lib "${workdir}/lib64"
@ -157,7 +178,7 @@ create_symlinks()
install_devmgr() install_devmgr()
{ {
info "installing device manager" print "installing device manager"
install_device_helper() install_device_helper()
{ {
@ -214,7 +235,7 @@ install_devmgr()
install_lvm() install_lvm()
{ {
info "installing LVM" print "installing LVM"
for _binary in lvchange vgchange; do for _binary in lvchange vgchange; do
install_binary "$_binary" install_binary "$_binary"
@ -256,7 +277,7 @@ install_lvm()
install_luks() install_luks()
{ {
info "installing LUKS" print "installing LUKS"
install_binary cryptsetup install_binary cryptsetup
@ -310,7 +331,7 @@ install_module()
install_hostonly_modules() install_hostonly_modules()
{ {
info "installing hostonly modules" print "installing hostonly modules"
# perform autodetection of modules via /sys # perform autodetection of modules via /sys
find /sys -name modalias -exec sort -u {} + | find /sys -name modalias -exec sort -u {} + |
@ -346,7 +367,7 @@ install_hostonly_modules()
install_all_modules() install_all_modules()
{ {
info "installing all modules" print "installing all modules"
find \ find \
"${modker}/kernel/arch" \ "${modker}/kernel/arch" \
@ -420,9 +441,7 @@ install_binary()
while read -r _library || [ "$_library" ]; do while read -r _library || [ "$_library" ]; do
# strip unneeded stuff # strip unneeded stuff
for _exclude_library in vdso gate; do [ "${_library##*vdso*}" ] || continue
case "$_library" in *"$_exclude_library"*) continue 2 ;; esac
done
_library="${_library#* => }" _library="${_library#* => }"
_library="${_library% *}" _library="${_library% *}"
@ -451,17 +470,20 @@ install_library()
create_initramfs() create_initramfs()
{ {
info "creating initramfs image" print "creating initramfs image"
# TODO add uncompressed option
# check if image already exist # check if image already exist
[ "$force" != 1 ] && [ -e "$output" ] && [ "$force" != 1 ] && [ -e "$output" ] &&
panic "initramfs image already exist" panic "initramfs image already exist"
( (
cd "$workdir" cd "$workdir"; find . |
find . | cpio -oH newc | ${compress:-gzip -9}
if [ "$compress" = none ]; then
cpio -oH newc
else
cpio -oH newc | ${compress:-gzip -9}
fi
) > "$output" 2> /dev/null || ) > "$output" 2> /dev/null ||
panic "failed to generate initramfs image" panic "failed to generate initramfs image"
@ -474,17 +496,6 @@ create_initramfs()
parse_args "$@" parse_args "$@"
prepare_environment prepare_environment
[ "$debug" = 1 ] && set -x
# hacky, but compatible with all posix shells
trap '
ret="$?"
trap - EXIT INT
[ "$debug" != 1 ] && remove_workdir
[ "$ret" != 0 ] && [ "$panic" != 1 ] && panic "something went wrong"
' EXIT INT
create_structure create_structure
create_symlinks create_symlinks
@ -517,9 +528,10 @@ create_initramfs()
install_binary "$_binary" install_binary "$_binary"
done done
cp "${modker}/modules.builtin" \ install -m644 \
"${modker}/modules.order" \ "${modker}/modules.builtin" \
"${workdir}${modker}" "${modker}/modules.order" \
"${workdir}${modker}"
depmod -b "$workdir" "$kernel" depmod -b "$workdir" "$kernel"
} }
@ -528,5 +540,5 @@ create_initramfs()
install_requirements install_requirements
create_initramfs create_initramfs
info "done! check out - $output" print "done! check out $output"
} }

View File

@ -8,8 +8,17 @@
# false positive # false positive
# shellcheck disable=2154,2163,1091 # shellcheck disable=2154,2163,1091
panic() { printf "panic >> %s\n" "$1" >&2; shell; } print()
info() { printf "info >> %s\n" "$1"; shell; } {
printf "%b %s\n" "${2:-\033[1;37m>>\033[m}" "$1"
shell
}
panic()
{
print "$1" "\033[1;31m!!\033[m" >&2
shell
}
shell() shell()
{ {
@ -38,7 +47,7 @@ findfs()
# avoid race condition # avoid race condition
while [ ! -e "$device" ]; do while [ ! -e "$device" ]; do
[ "$value" = 80 ] && panic "failed to lookup partition" [ "$value" = 30 ] && panic "failed to lookup partition"
value=$(( value + 1 )); sleep 1 value=$(( value + 1 )); sleep 1
done done
} }
@ -84,6 +93,12 @@ parse_cmdline()
debug | debug=1) debug | debug=1)
set -x set -x
;; ;;
rootfstype=*)
root_type="$line"
;;
rootflags=*)
root_opts="$line"
;;
ro | rw) ro | rw)
rorw="-o $line" rorw="-o $line"
;; ;;
@ -102,7 +117,7 @@ parse_cmdline()
setup_devmgr() setup_devmgr()
{ {
[ "$break" = devmgr ] && info "break before setup device manager" [ "$break" = devmgr ] && print "break before setup device manager"
case "$devmgr" in case "$devmgr" in
udev) udev)
@ -128,7 +143,7 @@ setup_devmgr()
unlock_luks() unlock_luks()
{ {
[ "$break" = luks ] && info "break before unlock LUKS" [ "$break" = luks ] && print "break before unlock LUKS"
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; } { IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
@ -160,7 +175,7 @@ unlock_luks()
trigger_lvm() trigger_lvm()
{ {
[ "$break" = lvm ] && info "break before trigger LVM" [ "$break" = lvm ] && print "break before trigger LVM"
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; } { IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
@ -197,7 +212,7 @@ trigger_lvm()
mount_root() mount_root()
{ {
[ "$break" = root ] && info "break before mount root" [ "$break" = root ] && print "break before mount root"
findfs "$root" findfs "$root"
@ -211,7 +226,7 @@ mount_root()
cleanup() cleanup()
{ {
[ "$break" = cleanup ] && info "break before cleanup" [ "$break" = cleanup ] && print "break before cleanup"
case "$devmgr" in case "$devmgr" in
udev) udevadm control -e ;; udev) udevadm control -e ;;
@ -228,7 +243,7 @@ cleanup()
boot_system() boot_system()
{ {
[ "$break" = boot ] && info "break before boot system" [ "$break" = boot ] && print "break before boot system"
set -- "/mnt/root" "${init:-/sbin/init}" set -- "/mnt/root" "${init:-/sbin/init}"
exec switch_root $@ 2> /dev/null || panic "failed to boot system" exec switch_root $@ 2> /dev/null || panic "failed to boot system"