implement system-wide installation

This commit is contained in:
illiliti 2020-03-08 04:18:07 +03:00
parent 537b89819f
commit 5413ec2f38
2 changed files with 28 additions and 18 deletions

View File

@ -3,8 +3,6 @@
# tiny initramfs generation tool # tiny initramfs generation tool
msg() { msg() {
# print message
case "$1" in case "$1" in
info) info)
printf "info >> %s\n" "$2" >&2 printf "info >> %s\n" "$2" >&2
@ -24,8 +22,6 @@ msg() {
} }
usage() { usage() {
# TODO more options
cat << EOF cat << EOF
usage: $0 [options] usage: $0 [options]
-o, --output <file> set initramfs image name -o, --output <file> set initramfs image name
@ -34,7 +30,7 @@ usage: $0 [options]
-k, --kernel <ver> set kernel version -k, --kernel <ver> set kernel version
-F, --files <dir> set files directory -F, --files <dir> set files directory
-d, --debug enable debug mode -d, --debug enable debug mode
-f, --force overwrite existing initramfs image -f, --force overwrite initramfs image
EOF EOF
} }
@ -83,16 +79,32 @@ parse_args() {
done done
} }
parse_conf() { prepare_environment() {
. "${_config:-./config}" || if [ -f "$_config" ]; then
msg panic "failed to parse config" . "$_config"
elif [ -f /etc/tinyramfs/config ]; then
. /etc/tinyramfs/config
elif [ -f ./config ]; then
. ./config
else
msg panic "failed to source config"
fi
if [ -d "$_filesdir" ]; then
filesdir="$_filesdir"
elif [ -d /usr/share/tinyramfs ]; then
filesdir="/usr/share/tinyramfs"
elif [ -d ./usr/share/tinyramfs ]; then
filesdir="./usr/share/initramfs"
else
msg panic "failed to find required files"
fi
kernel="${_kernel:-${kernel:-$(uname -r)}}" kernel="${_kernel:-${kernel:-$(uname -r)}}"
moddir="${_moddir:-${moddir:-/lib/modules}}" moddir="${_moddir:-${moddir:-/lib/modules}}"
filesdir="${_filesdir:-./usr/share/tinyramfs}"
debug="${_debug:-${debug:-0}}" debug="${_debug:-${debug:-0}}"
force="${_force:-${force:-0}}" force="${_force:-${force:-0}}"
initramfs="${_initramfs:-${initramfs:-./initramfs-${kernel}}}" initramfs="${_initramfs:-${initramfs:-/tmp/initramfs-${kernel}}}"
modker="${moddir}/${kernel}" modker="${moddir}/${kernel}"
} }
@ -125,7 +137,7 @@ install_requirements() {
install_binary "$_binary" install_binary "$_binary"
done done
# install mandatory binaries # install required binaries
for _binary in busybox modprobe; do for _binary in busybox modprobe; do
install_binary "$_binary" install_binary "$_binary"
done done
@ -387,7 +399,7 @@ install_library() {
install_files() { install_files() {
msg info "installing files" msg info "installing files"
cat << EOF > "${workdir}/config" cat > "${workdir}/config" << EOF
debug="$debug" debug="$debug"
init="$init" init="$init"
root="$root" root="$root"
@ -435,11 +447,11 @@ 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 prepare_environment
# remove workdir on signals # remove workdir on signals
# we are doing unset EXIT signal to avoid endless loop # we are doing unset EXIT signal to avoid endless loop
# because afterwards we execute 'exit' command. # because afterwards we execute exit command.
# also some shells (dash,mksh,etc) doesn't exit on INT # also some shells (dash,mksh,etc) doesn't exit on INT
# signal. as workaround we manually execute exit command. # signal. as workaround we manually execute exit command.
# tested bash,dash,mksh,busybox sh # tested bash,dash,mksh,busybox sh
@ -447,8 +459,10 @@ parse_conf
trap "remove_workdir && trap - EXIT && exit" EXIT INT TERM HUP trap "remove_workdir && trap - EXIT && exit" EXIT INT TERM HUP
[ "$debug" = 1 ] && { [ "$debug" = 1 ] && {
# debug shell commands # debug shell commands
set -x set -x
# don't remove anything # don't remove anything
trap - EXIT INT TERM HUP trap - EXIT INT TERM HUP
} }

View File

@ -10,11 +10,7 @@ panic() {
} }
parse_cmdline() { parse_cmdline() {
# store output in variable
read -r cmdline < /proc/cmdline read -r cmdline < /proc/cmdline
# turn output into list
set -f && set +f -- $cmdline set -f && set +f -- $cmdline
for line in "$@"; do for line in "$@"; do