formatting
This commit is contained in:
parent
3608109b78
commit
a0bd4caf46
228
generate
228
generate
@ -5,18 +5,18 @@
|
||||
# print message
|
||||
msg() {
|
||||
case "$1" in
|
||||
info)
|
||||
printf "info >> %s\n" "$2" >&2
|
||||
;;
|
||||
warn)
|
||||
printf "warning >> %s\n" "$2" >&2
|
||||
printf "do you want to continue? press enter or ctrl+c to exit\n"
|
||||
read -r _
|
||||
;;
|
||||
panic)
|
||||
printf "panic >> %s\n" "$2" >&2
|
||||
exit 1
|
||||
;;
|
||||
info)
|
||||
printf "info >> %s\n" "$2" >&2
|
||||
;;
|
||||
warn)
|
||||
printf "warning >> %s\n" "$2" >&2
|
||||
printf "do you want to continue? press enter or ctrl+c to exit\n"
|
||||
read -r _
|
||||
;;
|
||||
panic)
|
||||
printf "panic >> %s\n" "$2" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@ -47,8 +47,8 @@ remove_tmpdir() {
|
||||
check_currentdir() {
|
||||
script_dir=$(dirname $(readlink -f "$0"))
|
||||
[ "$PWD" = "$script_dir" ] || {
|
||||
msg info "changing directory to script dir"
|
||||
cd "$script_dir" || msg panic "failed to change directory"
|
||||
msg info "changing directory to script dir"
|
||||
cd "$script_dir" || msg panic "failed to change directory"
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,43 +57,43 @@ check_requirements() {
|
||||
msg info "checking requirements"
|
||||
|
||||
# check busybox installed
|
||||
command -v busybox >/dev/null 2>&1 && {
|
||||
# check busybox supports CONFIG_FEATURE_INSTALLER
|
||||
busybox --help | grep -q "\-\-install \[\-s\]" || msg panic "recompile busybox with CONFIG_FEATURE_INSTALLER"
|
||||
command -v busybox > /dev/null 2>&1 && {
|
||||
# check busybox supports CONFIG_FEATURE_INSTALLER
|
||||
busybox --help | grep -q "\-\-install \[\-s\]" || msg panic "recompile busybox with CONFIG_FEATURE_INSTALLER"
|
||||
|
||||
# check requirements for init
|
||||
for busybox_dep in mdev uevent switch_root; do
|
||||
busybox $busybox_dep --help >/dev/null 2>&1 || msg panic "recompile busybox with $busybox_dep"
|
||||
done
|
||||
# check requirements for init
|
||||
for busybox_dep in mdev uevent switch_root; do
|
||||
busybox $busybox_dep --help > /dev/null 2>&1 || msg panic "recompile busybox with $busybox_dep"
|
||||
done
|
||||
} || msg panic "busybox doesn't installed"
|
||||
|
||||
# check kmod modprobe installed
|
||||
command -v modprobe >/dev/null 2>&1 && {
|
||||
# busybox modprobe doesn't supported(yet)
|
||||
modprobe --version 2>&1 | grep -q "kmod" || msg panic "kmod modprobe version doesn't installed"
|
||||
command -v modprobe > /dev/null 2>&1 && {
|
||||
# busybox modprobe doesn't supported(yet)
|
||||
modprobe --version 2>&1 | grep -q "kmod" || msg panic "kmod modprobe version doesn't installed"
|
||||
} || msg panic "modprobe doesn't installed"
|
||||
|
||||
# check util-linux tools
|
||||
[ "$use_util_linux" = 1 ] && {
|
||||
# check mount installed
|
||||
if command -v mount >/dev/null 2>&1; then
|
||||
mount --version 2>&1 | grep -q "util-linux" || {
|
||||
msg warning "util-linux mount version doesn't installed. PARTUUID and filesystem type autodetection support will be missing"
|
||||
use_util_linux=0
|
||||
}
|
||||
else
|
||||
msg panic "mount doesn't installed"
|
||||
fi
|
||||
# check mount installed
|
||||
if command -v mount > /dev/null 2>&1; then
|
||||
mount --version 2>&1 | grep -q "util-linux" || {
|
||||
msg warning "util-linux mount version doesn't installed. PARTUUID and filesystem type autodetection support will be missing"
|
||||
use_util_linux=0
|
||||
}
|
||||
else
|
||||
msg panic "mount doesn't installed"
|
||||
fi
|
||||
|
||||
# check blkid installed
|
||||
if command -v blkid >/dev/null 2>&1; then
|
||||
blkid --version 2>&1 | grep -q "util-linux" || {
|
||||
msg warning "util-linux blkid version doesn't installed. PARTUUID support will be missing"
|
||||
use_util_linux=0
|
||||
}
|
||||
else
|
||||
msg panic "blkid doesn't installed"
|
||||
fi
|
||||
# check blkid installed
|
||||
if command -v blkid > /dev/null 2>&1; then
|
||||
blkid --version 2>&1 | grep -q "util-linux" || {
|
||||
msg warning "util-linux blkid version doesn't installed. PARTUUID support will be missing"
|
||||
use_util_linux=0
|
||||
}
|
||||
else
|
||||
msg panic "blkid doesn't installed"
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ install_requirements() {
|
||||
create_structure() {
|
||||
msg info "creating directory structure"
|
||||
for dir in dev tmp var run etc usr/lib usr/bin mnt/root proc root sys; do
|
||||
mkdir -p "${tmpdir}/${dir}"
|
||||
mkdir -p "${tmpdir}/${dir}"
|
||||
done
|
||||
}
|
||||
|
||||
@ -126,14 +126,14 @@ create_structure() {
|
||||
create_symlinks() {
|
||||
msg info "creating symlinks"
|
||||
( cd "$tmpdir" && {
|
||||
ln -s usr/lib lib
|
||||
ln -s usr/lib lib64
|
||||
ln -s usr/bin bin
|
||||
ln -s usr/bin sbin
|
||||
ln -s ../run var/run
|
||||
cd "${tmpdir}/usr"
|
||||
ln -s bin sbin
|
||||
ln -s lib lib64
|
||||
ln -s usr/lib lib
|
||||
ln -s usr/lib lib64
|
||||
ln -s usr/bin bin
|
||||
ln -s usr/bin sbin
|
||||
ln -s ../run var/run
|
||||
cd "${tmpdir}/usr"
|
||||
ln -s bin sbin
|
||||
ln -s lib lib64
|
||||
} )
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ install_udev() {
|
||||
msg info "installing udev"
|
||||
install_binaries udevd udevadm dmsetup
|
||||
# FIXME rewrite this piece of crap
|
||||
find /usr/lib/udev -type f | grep -v "rc_keymaps\|hwdb.d" | cpio -pd "$tmpdir" >/dev/null 2>&1
|
||||
find /usr/lib/udev -type f | grep -v "rc_keymaps\|hwdb.d" | cpio -pd "$tmpdir" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# handle lvm
|
||||
@ -176,18 +176,18 @@ install_lvm() {
|
||||
|
||||
# if hostonly mode enabled install only needed drivers
|
||||
[ "$hostonly" = 1 ] && {
|
||||
for lvm_driver in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
|
||||
for lvm_driver_dep in $(modprobe -D "$lvm_driver" 2>/dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$lvm_driver_dep" "${tmpdir}${lvm_driver_dep}"
|
||||
done
|
||||
done
|
||||
for lvm_driver in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
|
||||
for lvm_driver_dep in $(modprobe -D "$lvm_driver" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$lvm_driver_dep" "${tmpdir}${lvm_driver_dep}"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
if [ "$lvm_conf" = 1 ]; then
|
||||
install -Dm644 /etc/lvm/*.conf -t "${tmpdir}/etc/lvm" || msg panic "failed to install LVM config"
|
||||
install -Dm644 /etc/lvm/*.conf -t "${tmpdir}/etc/lvm" || msg panic "failed to install LVM config"
|
||||
else
|
||||
mkdir "${tmpdir}/etc/lvm"
|
||||
cat <<EOF > "${tmpdir}/etc/lvm/lvm.conf"
|
||||
mkdir "${tmpdir}/etc/lvm"
|
||||
cat << EOF > "${tmpdir}/etc/lvm/lvm.conf"
|
||||
devices {
|
||||
issue_discards = ${lvm_discard:-0}
|
||||
}
|
||||
@ -206,11 +206,11 @@ install_luks() {
|
||||
|
||||
# if hostonly mode enabled install only needed drivers
|
||||
[ "$hostonly" = 1 ] && {
|
||||
for luks_driver in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
|
||||
for luks_driver_dep in $(modprobe -D "$luks_driver" 2>/dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$luks_driver_dep" "${tmpdir}${luks_driver_dep}"
|
||||
done
|
||||
done
|
||||
for luks_driver in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
|
||||
for luks_driver_dep in $(modprobe -D "$luks_driver" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$luks_driver_dep" "${tmpdir}${luks_driver_dep}"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# avoid locking directory missing warning message
|
||||
@ -225,14 +225,14 @@ install_luks() {
|
||||
|
||||
# copy luks header
|
||||
[ -f "$luks_header" ] && {
|
||||
install -m400 "$luks_header" "${tmpdir}/root/luks_header" || msg panic "failed to copy LUKS header"
|
||||
luks_args="--header=/root/luks_header $luks_args"
|
||||
install -m400 "$luks_header" "${tmpdir}/root/luks_header" || msg panic "failed to copy LUKS header"
|
||||
luks_args="--header=/root/luks_header $luks_args"
|
||||
}
|
||||
|
||||
# copy luks keyfile
|
||||
[ -f "$luks_keyfile" ] && {
|
||||
install -m400 "$luks_keyfile" "${tmpdir}/root/luks_keyfile" || msg panic "failed to copy LUKS keyfile"
|
||||
luks_args="--key-file=/root/luks_keyfile $luks_args"
|
||||
install -m400 "$luks_keyfile" "${tmpdir}/root/luks_keyfile" || msg panic "failed to copy LUKS keyfile"
|
||||
luks_args="--key-file=/root/luks_keyfile $luks_args"
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,25 +243,25 @@ install_drivers() {
|
||||
|
||||
# perform autodetection of drivers via /sys
|
||||
find /sys/devices -name modalias -exec sort -u "{}" "+" | while read -r driver; do
|
||||
for driver_dep in $(modprobe -D "$driver" 2>/dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$driver_dep" "${tmpdir}${driver_dep}"
|
||||
for driver_dep in $(modprobe -D "$driver" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$driver_dep" "${tmpdir}${driver_dep}"
|
||||
done
|
||||
done
|
||||
|
||||
# TODO autodetect root fs driver
|
||||
# TODO separate root type option
|
||||
# install root fs driver
|
||||
for root_driver in $(modprobe -D "$root_type" 2>/dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
for root_driver in $(modprobe -D "$root_type" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$root_driver" "${tmpdir}${root_driver}"
|
||||
done
|
||||
|
||||
# install user specified drivers
|
||||
[ -n "$drivers" ] && {
|
||||
printf "%s\n" "$drivers" | while read -r custom_driver; do
|
||||
for custom_driver_dep in $(modprobe -D "$custom_driver" 2>/dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$custom_driver_dep" "${tmpdir}${custom_driver_dep}"
|
||||
done
|
||||
done
|
||||
printf "%s\n" "$drivers" | while read -r custom_driver; do
|
||||
for custom_driver_dep in $(modprobe -D "$custom_driver" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do
|
||||
install -Dm644 "$custom_driver_dep" "${tmpdir}${custom_driver_dep}"
|
||||
done
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ install_all_drivers() {
|
||||
"${modker}/kernel/drivers/usb/storage" \
|
||||
"${modker}/kernel/drivers/usb/host" \
|
||||
"${modker}/kernel/drivers/virtio" \
|
||||
-type f | cpio -pd "$tmpdir" >/dev/null 2>&1
|
||||
-type f | cpio -pd "$tmpdir" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# generate "modules" files
|
||||
@ -297,18 +297,18 @@ generate_depmod() {
|
||||
# handle binaries
|
||||
install_binaries() {
|
||||
printf "%s\n" "$@" | while read -r binary; do
|
||||
msg info "installing binary $binary"
|
||||
# check binary existence
|
||||
command -v "$binary" >/dev/null 2>&1 || msg panic "$binary doesn't exists"
|
||||
msg info "installing binary $binary"
|
||||
# check binary existence
|
||||
command -v "$binary" > /dev/null 2>&1 || msg panic "$binary doesn't exists"
|
||||
|
||||
# install and strip binary
|
||||
install -s -m755 "$(command -v $binary)" -t "${tmpdir}/usr/bin"
|
||||
# install and strip binary
|
||||
install -s -m755 "$(command -v $binary)" -t "${tmpdir}/usr/bin"
|
||||
|
||||
# check statically linking
|
||||
ldd "$(command -v $binary)" >/dev/null 2>&1 || continue
|
||||
ldd "$(command -v $binary)" > /dev/null 2>&1 || continue
|
||||
|
||||
# install libraries
|
||||
install_libraries $binary
|
||||
# install libraries
|
||||
install_libraries $binary
|
||||
done
|
||||
}
|
||||
|
||||
@ -316,26 +316,26 @@ install_binaries() {
|
||||
# handle libraries
|
||||
install_libraries() {
|
||||
for library in $(ldd "$(command -v $1)" | sed -nre 's,.* (/.*lib.*/.*.so.*) .*,\1,p' -e 's,.*(/lib.*/ld.*.so.*) .*,\1,p'); do
|
||||
msg info "installing library $library"
|
||||
# check symlink
|
||||
if [ -h "$library" ]; then
|
||||
# check lib already existence
|
||||
if [ ! -e "${tmpdir}/usr/lib/${library##*/}" ] && [ ! -e "${tmpdir}/$(readlink -f $library)" ]; then
|
||||
# regular
|
||||
install -s -m755 "$(readlink -f $library)" -t "${tmpdir}/usr/lib"
|
||||
msg info "installing library $library"
|
||||
# check symlink
|
||||
if [ -h "$library" ]; then
|
||||
# check lib already existence
|
||||
if [ ! -e "${tmpdir}/usr/lib/${library##*/}" ] && [ ! -e "${tmpdir}/$(readlink -f $library)" ]; then
|
||||
# regular
|
||||
install -s -m755 "$(readlink -f $library)" -t "${tmpdir}/usr/lib"
|
||||
|
||||
# FIXME handle all symlinks
|
||||
# symlink may link to symlink
|
||||
[ -h "/usr/lib/$(readlink $library)" ] && cp -a "/usr/lib/$(readlink $library)" "${tmpdir}/usr/lib"
|
||||
# FIXME handle all symlinks
|
||||
# symlink may link to symlink
|
||||
[ -h "/usr/lib/$(readlink $library)" ] && cp -a "/usr/lib/$(readlink $library)" "${tmpdir}/usr/lib"
|
||||
|
||||
# symlink
|
||||
cp -a "$library" "${tmpdir}/usr/lib"
|
||||
fi
|
||||
else
|
||||
if [ ! -e "${tmpdir}/usr/lib/${library##*/}" ]; then
|
||||
install -s -m755 "$library" -t "${tmpdir}/usr/lib"
|
||||
fi
|
||||
fi
|
||||
# symlink
|
||||
cp -a "$library" "${tmpdir}/usr/lib"
|
||||
fi
|
||||
else
|
||||
if [ ! -e "${tmpdir}/usr/lib/${library##*/}" ]; then
|
||||
install -s -m755 "$library" -t "${tmpdir}/usr/lib"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@ -344,7 +344,7 @@ install_files() {
|
||||
msg info "installing files"
|
||||
# FIXME eof broken
|
||||
# initialize config
|
||||
cat <<EOF > "${tmpdir}/config"
|
||||
cat << EOF > "${tmpdir}/config"
|
||||
debug="$debug"
|
||||
root="$root"
|
||||
root_type="$root_type"
|
||||
@ -358,7 +358,7 @@ luks_args="$luks_args"
|
||||
EOF
|
||||
|
||||
# needed for devmgr
|
||||
cat <<EOF > "${tmpdir}/etc/group"
|
||||
cat << EOF > "${tmpdir}/etc/group"
|
||||
root:x:0:
|
||||
tty:x:5:
|
||||
dialout:x:11:
|
||||
@ -376,7 +376,7 @@ floppy:x:8:
|
||||
EOF
|
||||
|
||||
# needed for devmgr
|
||||
cat <<EOF > "${tmpdir}/etc/passwd"
|
||||
cat << EOF > "${tmpdir}/etc/passwd"
|
||||
root:x:0:0::/root:/bin/sh
|
||||
nobody:x:99:99::/:/bin/false
|
||||
EOF
|
||||
@ -390,12 +390,14 @@ EOF
|
||||
create_initramfs() {
|
||||
msg info "creating initramfs image"
|
||||
{
|
||||
( cd "$tmpdir"
|
||||
find . |
|
||||
cpio -oH newc |
|
||||
gzip -9 ) |
|
||||
tee "${script_dir}/initramfs-${kernel}.img.gz"
|
||||
} >/dev/null 2>&1 || msg panic "failed to generate initramfs image"
|
||||
(
|
||||
cd "$tmpdir"
|
||||
find . \
|
||||
| cpio -oH newc \
|
||||
| gzip -9
|
||||
) \
|
||||
| tee "${script_dir}/initramfs-${kernel}.img.gz"
|
||||
} > /dev/null 2>&1 || msg panic "failed to generate initramfs image"
|
||||
}
|
||||
|
||||
# check root
|
||||
|
72
init
72
init
@ -22,9 +22,9 @@ mnt_pseudofs() {
|
||||
use_mdev() {
|
||||
# setup hotplugger
|
||||
if [ -e /proc/sys/kernel/hotplug ]; then
|
||||
printf /sbin/mdev >/proc/sys/kernel/hotplug
|
||||
printf /sbin/mdev > /proc/sys/kernel/hotplug
|
||||
else
|
||||
uevent mdev &
|
||||
uevent mdev &
|
||||
fi
|
||||
|
||||
# trigger mdev
|
||||
@ -32,10 +32,10 @@ use_mdev() {
|
||||
|
||||
# trigger uevent for usb devices
|
||||
for u in /sys/bus/usb/devices/*; do
|
||||
case ${u##*/} in
|
||||
[0-9]*-[0-9]*)
|
||||
printf add > "${u}/uevent"
|
||||
;;
|
||||
case ${u##*/} in
|
||||
[0-9]*-[0-9]*)
|
||||
printf add > "${u}/uevent"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@ -66,21 +66,21 @@ use_udev() {
|
||||
# shell findfs
|
||||
findfs_sh() {
|
||||
case "${1%%=*}" in
|
||||
LABEL)
|
||||
printf "/dev/disk/by-label/%s\n" "${1##*=}"
|
||||
;;
|
||||
UUID)
|
||||
printf "/dev/disk/by-uuid/%s\n" "${1##*=}"
|
||||
;;
|
||||
PARTUUID)
|
||||
printf "/dev/disk/by-partuuid/%s\n" "${1##*=}"
|
||||
;;
|
||||
/dev/*)
|
||||
printf "%s\n" "$1"
|
||||
;;
|
||||
*)
|
||||
panic "findfs option broken"
|
||||
;;
|
||||
LABEL)
|
||||
printf "/dev/disk/by-label/%s\n" "${1##*=}"
|
||||
;;
|
||||
UUID)
|
||||
printf "/dev/disk/by-uuid/%s\n" "${1##*=}"
|
||||
;;
|
||||
PARTUUID)
|
||||
printf "/dev/disk/by-partuuid/%s\n" "${1##*=}"
|
||||
;;
|
||||
/dev/*)
|
||||
printf "%s\n" "$1"
|
||||
;;
|
||||
*)
|
||||
panic "findfs option broken"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ unlock_luks() {
|
||||
|
||||
# manually trigger LVM if udev disabled
|
||||
trigger_lvm() {
|
||||
lvm vgchange --quiet --sysinit -a y >/dev/null
|
||||
lvm vgchange --quiet --sysinit -a y > /dev/null
|
||||
}
|
||||
|
||||
# mount rootfs to /mnt/root
|
||||
@ -119,23 +119,23 @@ mnt_rootfs() {
|
||||
# kill and unmount
|
||||
cleanup() {
|
||||
case "$devmgr" in
|
||||
mdev)
|
||||
# stop mdev
|
||||
{ printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
|
||||
;;
|
||||
mdevd)
|
||||
# stop mdevd
|
||||
killall mdevd
|
||||
;;
|
||||
udev)
|
||||
# stop udev
|
||||
udevadm control --exit
|
||||
;;
|
||||
mdev)
|
||||
# stop mdev
|
||||
{ printf "" > /proc/sys/kernel/hotplug || killall uevent; } > /dev/null 2>&1
|
||||
;;
|
||||
mdevd)
|
||||
# stop mdevd
|
||||
killall mdevd
|
||||
;;
|
||||
udev)
|
||||
# stop udev
|
||||
udevadm control --exit
|
||||
;;
|
||||
esac
|
||||
|
||||
# TODO re-do
|
||||
# if debug mode off then restore kernel logging
|
||||
[ "$debug" = 0 ] && printf 1 >/proc/sys/kernel/printk
|
||||
[ "$debug" = 0 ] && printf 1 > /proc/sys/kernel/printk
|
||||
|
||||
# unmount pseudofs's
|
||||
umount /dev /sys /proc /tmp
|
||||
@ -158,7 +158,7 @@ if [ "$debug" = 1 ]; then
|
||||
set -x
|
||||
else
|
||||
# silence is golden
|
||||
printf 0 >/proc/sys/kernel/printk
|
||||
printf 0 > /proc/sys/kernel/printk
|
||||
fi
|
||||
|
||||
#parse_cmdline
|
||||
|
Loading…
Reference in New Issue
Block a user