Commit 11d4ca34 authored by Ophélie Gagnard's avatar Ophélie Gagnard

installation/install.sh: Parse network related information during installation.

dracut.module/dracut.conf.in: Add templates for the network related kernel command-line parameter.
installation/env.sh: Change the wendelin reference.
parent 442cf434
......@@ -7,7 +7,8 @@ hostonly_cmdline=no
#linux /boot/vmlinuz-4.19.0-17-amd64 root=UUID=c962bb70-ee0c-4561-9edd-56c269ef7e51 ro single mitigations=off console=ttyS1,57600
#kernel_cmdline="root=LABEL=ROOT ip=dhcp rd.neednet=1 ro single mitigations=off console=ttyS1,57600"
#kernel_cmdline="root=UUID=%ROOT_PARTITION_ID% ip=dhcp rd.neednet=1 ro console=ttyS1,57600"
kernel_cmdline="root=UUID=%ROOT_PARTITION_ID% ip=195.90.118.203::195.90.118.193:255.255.255.224:douai-capri-009:enp193s0f1np1:off:1.1.1.1:8.8.8.8:130.79.14.172 rd.neednet=1 ro console=ttyS1,57600"
#kernel_cmdline="root=UUID=%ROOT_PARTITION_ID% ip=195.90.118.203::195.90.118.193:255.255.255.224:douai-capri-009:enp193s0f1np1:off:1.1.1.1:8.8.8.8:130.79.14.172 rd.neednet=1 ro console=ttyS1,57600"
kernel_cmdline="root=UUID=%ROOT_PARTITION_ID% ip=%DEFAULT_IP%::%DEFAULT_ROUTER%:%FORMATTED_NETMASK%:%HOSTNAME%:%DEFAULT_INTERFACE%:off:1.1.1.1:8.8.8.8:130.79.14.172 rd.neednet=1 ro console=ttyS1,57600"
#kernel_cmdline="ip=dhcp rd.neednet=1"
show_modules=yes
reproducible=yes
......
......@@ -13,7 +13,7 @@ FLUENTBIT_VERSION=1-1
TARGET_DISTRIBUTION=Debian_11
ARCH=amd64
PACKAGE_EXTENSION=.deb
WENDELIN_REFERENCE=douai001-capri009
WENDELIN_REFERENCE=douai002-capri009
# used mainly in dracut.module/configure
......
......@@ -22,10 +22,10 @@ get_partition_path () {
desired_partition_count=$(echo -e "$desired_partitions" | wc | awk '{print $1}')
if [ -z "$desired_partitions" ]; then
echo -e "No partition of type $1 (shouldbe 1)."
echo -e "No partition of type $1 (shouldbe 1). Exiting."
exit
elif [ "$desired_partition_count" -ne 1 ]; then
echo -e "$desired_partition_count partitions of type $1 (should be 1)."
echo -e "$desired_partition_count partitions of type $1 (should be 1). Exiting."
exit
else
echo -e "$desired_partitions" | awk '{print $1}'
......@@ -37,12 +37,85 @@ get_partition_id () {
echo -e "$(findmnt -fn -o UUID "$desired_partition_path")"
}
get_default_interface () {
default_results=$(ip route | grep default | wc | awk '{print $1}')
if [ "$default_results" -ne 1 ]; then
echo -e "$default_results default result(s) (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep default | sed 's|.*dev \([^ ]*\).*|\1|g')"
fi
}
get_default_router () {
default_results=$(ip route | grep default | wc | awk '{print $1'})
if [ "$default_results" -ne 1 ]; then
echo -e "$defaults_results default result(s) (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep default | sed 's|.*via \([^ ]*\).*|\1|g')"
fi
}
get_default_ip () {
default_interface=$(get_default_interface)
interface_results=$(ip route | grep -v default | grep "$default_interface" | wc | awk '{print $1}')
if [ "$interface_results" -ne 1 ]; then
echo -e "$interface_results results for \"${default_interface}\" (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep -v default | grep "$default_interface" | sed 's|.*src \([^ ]*\).*|\1|g')"
fi
}
get_default_netmask () {
default_interface=$(get_default_interface)
interface_results=$(ip route | grep -v default | grep "$default_interface" | wc | awk '{print $1}')
if [ "$interface_results" -ne 1 ]; then
echo -e "$interface_results results for \"${default_interface}\" (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep -v default | grep "$default_interface" | sed 's|^\([^ ]*\).*|\1|g')"
fi
}
int_to_generic_netmask () {
# get the mask size: the number right after the "/" (ex: <ipv4>/24 -> 24)
#mask_length=$(get_default_netmask | awk -F / '{print $2}')
mask_length=$1
mask=""
for i in {0..3}; do
#while [ $mask_length -gt 0 ]; do
if [ ${mask_length} -ge 8 ]; then
mask=${mask}255
elif [ ${mask_length} -eq 0 ]; then
mask=${mask}0
else
mask=${mask}$((256-2**(8-${mask_length})))
fi
if [ $i -ne 3 ]; then
mask=${mask}.
fi
mask_length=$((mask_length-8))
done
echo -e "${mask}"
}
# Get information about the partition layout
root_partition_type="Linux filesystem"
efi_partition_type="EFI System"
EFI_PARTITION_MOUNT_POINT=$(get_partition_path "$efi_partition_type")
ROOT_PARTITION_ID=$(get_partition_id "$root_partition_type")
default_boot_num=100
default_bootnum=100
# Get information about the network
DEFAULT_INTERFACE=$(get_default_interface)
DEFAULT_ROUTER=$(get_default_router)
DEFAULT_IP=$(get_default_ip)
default_netmask=$(get_default_netmask)
default_netmask_number=$(echo -e "${default_netmask}" | awk -F / '{print $2}')
FORMATTED_NETMASK=$(int_to_generic_netmask "${default_netmask_number}")
HOSTNAME=$(hostname)
# Install the module
cd dracut.module
......@@ -52,12 +125,13 @@ make install
cd -
# Generation of dracut.module/dracut.conf
dracut_conf_regex="s|%PROJECT_DIR%|${PROJECT_DIR}|g;s|%ROOT_PARTITION_ID%|${ROOT_PARTITION_ID}|g;s|%DEFAULT_INTERFACE%|${DEFAULT_INTERFACE}|g;s|%DEFAULT_ROUTER%|${DEFAULT_ROUTER}|g;s|%DEFAULT_IP%|${DEFAULT_IP}|g;s|%FORMATTED_NETMASK%|${FORMATTED_NETMASK}|g;s|%HOSTNAME%|${HOSTNAME}|g"
cd dracut.module
sed "s|%PROJECT_DIR%|${PROJECT_DIR}|g;s|%ROOT_PARTITION_ID%|${ROOT_PARTITION_ID}|g" dracut.conf.in > dracut.conf
sed "${dracut_conf_regex}" dracut.conf.in > dracut.conf
cd -
# TMP: Delete bootnum 0 so that there is only one boot option for an image created by this script
efibootmgr -b "$default_boot_num" -B || true
# Delete $default_bootnum so that there is only one boot option for an image created by this script
efibootmgr -b "$default_bootnum" -B || true
# Create an initramfs image
rm -f $dracut_output_file
......@@ -65,11 +139,7 @@ dracut -c ./dracut.module/dracut.conf --force |& tee -a $dracut_output_file
# the next line parses dracut output and extracts the path of the newly generated image
uefi_image_name=`grep "Creating image file" $dracut_output_file | sed -E "s|.*$EFI_IMAGE_DIR(.*)'.*|\1|g"`
# Why? The boot manager seems to forget the boot option if this is not done.
#mkdir -p $TARGET_EFI_DIR
#cp -rv $SOURCE_EFI_DIR/* $TARGET_EFI_DIR
# Set the image as a boot option
efibootmgr -b "$default_boot_num" --create --disk $EFI_PARTITION_MOUNT_POINT --label "test_deploy" --loader ${RELATIVE_EFI_IMAGE_DIR}/$uefi_image_name
efibootmgr -b "$default_bootnum" --create --disk $EFI_PARTITION_MOUNT_POINT --label "test_deploy" --loader ${RELATIVE_EFI_IMAGE_DIR}/$uefi_image_name
echo "New initramfs image: "${EFI_IMAGE_DIR}/$uefi_image_name
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment