refactor config
This commit is contained in:
parent
ec2dedc461
commit
ce3a47922e
24
config
24
config
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# debug mode
|
# debug mode
|
||||||
#debug=0
|
debug=1
|
||||||
|
|
||||||
# custom init
|
# custom init
|
||||||
#init=""
|
#init=""
|
||||||
@ -18,11 +18,11 @@
|
|||||||
#compress=""
|
#compress=""
|
||||||
|
|
||||||
# root fs ( device,partuuid,uuid,label )
|
# root fs ( device,partuuid,uuid,label )
|
||||||
#root=""
|
root="UUID=07729c48-25d8-4096-acaf-ce5322915680"
|
||||||
|
|
||||||
# root type
|
# root type
|
||||||
# change this if you using busybox util-linux
|
# change this if you using busybox util-linux
|
||||||
#root_type=""
|
root_type="ext4"
|
||||||
|
|
||||||
# root options
|
# root options
|
||||||
#root_opts=""
|
#root_opts=""
|
||||||
@ -30,13 +30,13 @@
|
|||||||
# disable this if you want to get rid of util-linux
|
# disable this if you want to get rid of util-linux
|
||||||
# NOTE busybox util-linux implemetation doesn't have
|
# NOTE busybox util-linux implemetation doesn't have
|
||||||
# PARTUUID support and proper filesystem type autodetection
|
# PARTUUID support and proper filesystem type autodetection
|
||||||
#util_linux=0
|
util_linux=1
|
||||||
|
|
||||||
# device manager ( mdev,mdevd,udev )
|
# device manager ( mdev,mdevd,udev )
|
||||||
#devmgr=""
|
devmgr="mdev"
|
||||||
|
|
||||||
# hostonly mode
|
# hostonly mode
|
||||||
#hostonly=0
|
hostonly=0
|
||||||
|
|
||||||
# custom drivers
|
# custom drivers
|
||||||
#drivers=""
|
#drivers=""
|
||||||
@ -45,7 +45,7 @@
|
|||||||
#binaries=""
|
#binaries=""
|
||||||
|
|
||||||
# LVM support
|
# LVM support
|
||||||
#lvm=0
|
lvm=1
|
||||||
|
|
||||||
# LVM logical volume name
|
# LVM logical volume name
|
||||||
#lvm_name=""
|
#lvm_name=""
|
||||||
@ -54,19 +54,19 @@
|
|||||||
#lvm_group=""
|
#lvm_group=""
|
||||||
|
|
||||||
# LVM include config
|
# LVM include config
|
||||||
#lvm_conf=0
|
#lvm_conf=1
|
||||||
|
|
||||||
# LVM issue_discards
|
# LVM issue_discards
|
||||||
#lvm_discard=0
|
lvm_discard=1
|
||||||
|
|
||||||
# LVM options
|
# LVM options
|
||||||
#lvm_args=""
|
#lvm_args=""
|
||||||
|
|
||||||
# LUKS support
|
# LUKS support
|
||||||
#luks=0
|
luks=1
|
||||||
|
|
||||||
# LUKS encrypted root ( device,partuuid,uuid,label )
|
# LUKS encrypted root ( device,partuuid,uuid,label )
|
||||||
#luks_root=""
|
luks_root="PARTUUID=b04395be-f467-458b-8630-9a429b487600"
|
||||||
|
|
||||||
# luks mapper name ( /dev/mapper/<name> )
|
# luks mapper name ( /dev/mapper/<name> )
|
||||||
#luks_name=""
|
#luks_name=""
|
||||||
@ -78,7 +78,7 @@
|
|||||||
#luks_keyfile="/path/to/keyfile"
|
#luks_keyfile="/path/to/keyfile"
|
||||||
|
|
||||||
# LUKS allow_discards
|
# LUKS allow_discards
|
||||||
#luks_discard=0
|
luks_discard=1
|
||||||
|
|
||||||
# LUKS options
|
# LUKS options
|
||||||
#luks_args=""
|
#luks_args=""
|
||||||
|
47
generate
47
generate
@ -21,6 +21,7 @@ msg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
# TODO more options
|
||||||
cat << EOF
|
cat << EOF
|
||||||
usage: $0 [options]
|
usage: $0 [options]
|
||||||
-o, --output <file> output file. default is $(readlink -f $(dirname "$0"))/initramfs-$(uname -r)
|
-o, --output <file> output file. default is $(readlink -f $(dirname "$0"))/initramfs-$(uname -r)
|
||||||
@ -53,6 +54,22 @@ parse_args() {
|
|||||||
done
|
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() {
|
create_wrkdir() {
|
||||||
msg info "creating working directory"
|
msg info "creating working directory"
|
||||||
|
|
||||||
@ -102,6 +119,7 @@ create_symlinks() {
|
|||||||
|
|
||||||
msg info "creating symlinks"
|
msg info "creating symlinks"
|
||||||
|
|
||||||
|
# TODO remove grouping
|
||||||
( cd "$wrkdir" && {
|
( cd "$wrkdir" && {
|
||||||
ln -s usr/lib lib
|
ln -s usr/lib lib
|
||||||
ln -s usr/lib lib64
|
ln -s usr/lib lib64
|
||||||
@ -261,7 +279,7 @@ generate_depmod() {
|
|||||||
|
|
||||||
modker="${moddir}/${kernel}"
|
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"
|
depmod -b "$wrkdir" "$kernel"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +293,7 @@ install_binary() {
|
|||||||
|
|
||||||
fullbin=$(command -v "$binary")
|
fullbin=$(command -v "$binary")
|
||||||
|
|
||||||
# check binary existence
|
# check if binary exists
|
||||||
[ "$fullbin" ] || msg panic "$binary doesn't exists"
|
[ "$fullbin" ] || msg panic "$binary doesn't exists"
|
||||||
|
|
||||||
# install and strip binary
|
# install and strip binary
|
||||||
@ -308,9 +326,9 @@ install_library() {
|
|||||||
# check symlink
|
# check symlink
|
||||||
if [ -h "$library" ]; then
|
if [ -h "$library" ]; then
|
||||||
|
|
||||||
# check lib already existence
|
# check if library already exists
|
||||||
|
[ -e "${wrkdirlib}${fulllib##*/}" ] ||
|
||||||
[ -e "${wrkdirlib}${namelib}" ] ||
|
[ -e "${wrkdirlib}${namelib}" ] ||
|
||||||
[ -e "${wrkdir}${fulllib}" ] ||
|
|
||||||
{
|
{
|
||||||
# regular
|
# regular
|
||||||
install -s -m755 "${fulllib}" -t "${wrkdirlib}"
|
install -s -m755 "${fulllib}" -t "${wrkdirlib}"
|
||||||
@ -385,12 +403,16 @@ EOF
|
|||||||
|
|
||||||
create_initramfs() {
|
create_initramfs() {
|
||||||
msg info "creating initramfs image"
|
msg info "creating initramfs image"
|
||||||
|
|
||||||
|
# TODO add uncompressed option
|
||||||
|
# TODO remove grouping
|
||||||
|
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
cd "$wrkdir"
|
cd "$wrkdir"
|
||||||
find . | cpio -oH newc | ${compress:-gzip -9}
|
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"
|
} > /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"
|
[ "$(id -u)" = 0 ] || msg panic "must be run as root"
|
||||||
|
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
parse_conf
|
||||||
|
|
||||||
. "${filesdir:=$(readlink -f $(dirname "$0"))}/config" || msg panic "failed to source config"
|
: "${kernel:=$(uname -r)}"
|
||||||
|
: "${moddir:=/lib/modules}"
|
||||||
# remove wrkdir on exit or unexpected error
|
: "${filesdir:=$(readlink -f $(dirname "$0"))}"
|
||||||
trap remove_wrkdir EXIT INT
|
: "${initramfs:=${filesdir}/initramfs-${kernel}}"
|
||||||
|
|
||||||
[ "$debug" = 1 ] && {
|
[ "$debug" = 1 ] && {
|
||||||
# debug shell commands
|
# debug shell commands
|
||||||
@ -412,8 +435,8 @@ trap remove_wrkdir EXIT INT
|
|||||||
trap - EXIT INT
|
trap - EXIT INT
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel="${kernel:-$(uname -r)}"
|
# remove wrkdir on exit or unexpected error
|
||||||
moddir="/lib/modules"
|
trap remove_wrkdir EXIT INT
|
||||||
|
|
||||||
create_wrkdir
|
create_wrkdir
|
||||||
create_structure
|
create_structure
|
||||||
@ -440,4 +463,4 @@ esac
|
|||||||
install_files
|
install_files
|
||||||
create_initramfs
|
create_initramfs
|
||||||
|
|
||||||
msg info "done! check out ${initramfs:-${filesdir}/initramfs-${kernel}}"
|
msg info "done! check out $initramfs"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user