From ab496871adc94ec5a015d37e975cbebea413154b Mon Sep 17 00:00:00 2001 From: ghe0 Date: Thu, 7 Nov 2024 00:58:20 +0200 Subject: [PATCH] created install script --- .gitignore | 1 + create.sh | 7 ++++++- creator_functions.sh | 15 +++++++++++---- init_functions.sh | 2 +- install.sh | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100755 install.sh diff --git a/.gitignore b/.gitignore index d59a62b..733831f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +dtrfs.tar build tmp diff --git a/create.sh b/create.sh index b204762..f3d2932 100755 --- a/create.sh +++ b/create.sh @@ -8,13 +8,18 @@ cd build echo_blue "Starting installation at $ROOT." +echo_blue "Adding kernel binaries..." install_busybox install_binary $(which modprobe) install_binary $(which switch_root) +echo_blue "Adding scripts..." install_init_script -install_module btrfs +echo_blue "Adding kernel modules..." +install_module "$(df -T / | awk '{ print $2 }' | tail -1)" +install_module msr install_module sev-guest install_module dm_crypt cp /lib/modules/${KERNEL}/modules.{order,builtin,builtin.modinfo} "${ROOT}/lib/modules/${KERNEL}/" depmod -b "$ROOT" "$KERNEL" +echo_blue "Creating archive..." create_archive diff --git a/creator_functions.sh b/creator_functions.sh index 5bc64f4..122ba88 100644 --- a/creator_functions.sh +++ b/creator_functions.sh @@ -22,7 +22,7 @@ install_dep() { [[ -f "${ROOT}${lib}" ]] || { mkdir -p $(dirname "${ROOT}${lib}") - echo_blue "Adding dependency to root: $lib" + echo_blue "Adding dependency: $lib" cp "$lib" "${ROOT}${lib}" } } @@ -37,7 +37,7 @@ install_binary() { exit 1 } - echo_blue "Adding binary to root: $binary" + echo_blue "Adding binary: $binary" cp "$binary" "${ROOT}/usr/bin/" ldd_deps="$(ldd "$binary")" @@ -69,15 +69,22 @@ install_init_script() { } create_archive() { - echo_blue "Creating archive..." + local archive="detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz" + echo_blue "Creating archive $archive" + echo $archive > .archive_name find . | cpio -o -H newc | gzip > detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz } install_module() { local module="$1" depends='' dep='' filename='' - filename="$( modinfo -k $KERNEL $module | grep '^filename:' | awk '{ print $2 }' )" + [[ "$filename" == "(builtin)" ]] && { + echo_yellow "Module $module is builtin. Installation not needed." + return 0 + } + install_dep "$filename" + echo "insmod $filename" >> "${ROOT}/load_modules.sh" depends="$(modinfo -k $KERNEL $module | grep '^depends:' | awk '{ print $2 }' | sed 's/,/\n/g')" diff --git a/init_functions.sh b/init_functions.sh index cc034fe..0f2c7f3 100644 --- a/init_functions.sh +++ b/init_functions.sh @@ -9,7 +9,7 @@ echo_red() { } load_modules() { - modprobe btrfs msr sev-guest || exit 1 + cat /load_modules.sh | sort -u | bash } create_mounts() { diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..17a7635 --- /dev/null +++ b/install.sh @@ -0,0 +1,39 @@ +#!/bin/bash +cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" + +dir="/tmp/dtrfs" + +if [ -z $1 ]; then + echo "You must specify the server as the first parameter." + echo "Example: ./install.sh 10.10.10.73 root 22" + echo "The 2nd (ssh user) and 3rd (ssh port) arguments are optional." + exit 1 +fi + +server="$1" + +if ! [ -z $2 ]; then + server="${2}@${server}" +fi + +if [ -z $3 ]; then + ssh="ssh" + scp="scp" +else + ssh="ssh -p $3" + scp="scp -P $3" +fi + +echo Starting installation... + +tar cf dtrfs.tar *.sh +$ssh $server rm -rf ${dir} +$ssh $server mkdir -p ${dir} +$scp dtrfs.tar ${server}:${dir} +$ssh $server tar -xf ${dir}/dtrfs.tar -C ${dir} +$ssh $server ${dir}/create.sh +set -e +archive=$($ssh $server cat ${dir}/build/.archive_name) +mkdir -p tmp +$scp ${server}:${dir}/build/${archive} tmp/ +echo initrd downloaded to: $(pwd)/tmp/${archive}