April 23, 2024

Archinstall – GNU / Linux.ch

Monday 17th April 2023, Ishome

Today I would like to present my little project that may interest some people. What do you do, or what do you do? Install Arch Linux! But you don’t have to write about it. However, I’ve learned a lot about BASH scripting in the process, and I want to share this with the community.

story

Now something about the origin story: One evening I discovered the systemd-boot command on Youtube and realized I had to use Arch Linux if I wanted to play with it. But it didn’t work on the right hardware because it wasn’t available. I found the eflinux Youtube channel, which gives examples of Arch settings in VMs and explains a lot and gave me very good instructions. Since he had a script there silly person I’ve tried this and found that this script doesn’t quite do what I want. So I started with my script. Once I understood what was possible with this approach, I began to think about what my dream system should look like. Thanks to Lennart Poettering’s blog Pid 1, I understood the concept of systemd relatively well and wanted to try out the individual parts like systemd-networkd, systemd -olved, etc. With a do-it-yourself approach, when building and configuring “your” system, you can take parts from repositories such as a build kit and piece them together.

Before moving on to the story and challenges, I should probably touch on the objective briefly. My goal of the project is to create a secure system with many up-to-date software. The keywords for this are Secure Boot, TPM, systemd-boot, Btrfs, LUKS (cryptenroll), systemd -olved, and iwd as a replacement for wpa_supplicant.

See also  Torment's New Gadgets section is now available • Nintendo Connect

Further in the story. Fedora (my main system) made me familiar with BTRFS and I wanted to play around with it. Fedora also showed me Pipewire as background audio. Since Fedora only switches to BTRFS with a fresh install, I wanted to gain experience with Arch. Since I am also interested in IT security, I also wanted to learn about cryptography under Linux. I realized during the project that you may not always want to code. Hardware differences also exist (keyword: microcode). This script gave the user the first queries and I thought: Humans can create a small installer with these options. But since the script must be run on Arch-Iso and unfortunately no such tool as dialog (a program for making graphical queries in the terminal) is installed, I “had” to deal with bash and syntax it. In doing so, I discovered some things that gave me new ideas such as a default value for queries, so that confirmation is not required until after.

Examples:

read -r -p "Name for the cryptrootdevice (defaults to cryptroot): " cryptrootname
: "${cryptrootname:=cryptroot}"
echo "The cryptrootdevice will be named: ${cryptrootname}"

This code asks for input and if it is not given and you simply press return, the second line will default to writing "cryptroot" to the variable. The colon and space at the beginning of the line tell bash not to interpret the following as a command.

echo "Select Kernel (Defaults to Linux):"
echo "1) Linux 2) Linux LTS 3) Linux Zen"
read -r kernel
: "${kernel:=1}"

tempString="";
for range in ${kernel//,/ }; do
    tempString="$tempString{${range//-/..}}";
done;
tempString=${tempString//\}{/\} {};
tempString=$(echo $tempString | tr [:blank:] '\n' | sed 's/{\([0-9]\{1,2\}\)}/\1/' | tr '\n' ',');
tempString=${tempString/%,/};
result="";
for range2 in ${tempString//,/ }; do
    result+=$(eval echo $range2);
    result+=";";
done;
result=${result/%;};
result=${result//;/ };
echo $result

for index in ${result}; do
  echo -n "Ausgewählt: "
    case $index in
        *1*)
      echo "Linux"
      selectedKernel+="linux "
      header+="linux-headers "
      ;;
        *2*)
      echo "Linux LTS"
      selectedKernel+="linux-lts "
      header+="linux-lts-headers "
      ;;
        *3*)
      echo "Linux Zen"
      selectedKernel+="linux-zen "
      header+="linux-zen-headers "
      ;;
        *) echo "Error, aborting" ;;
    esac
done

This code makes it possible to select different kernels. All kernel combinations are possible. With 3 entries to choose from, this isn't really necessary, but this pattern can be used with any number of entries. For example, if you have 10 entries and you want to select all but the 5th entry, you can specify that like this: 1-4,6-10 This is then converted to individual values. In this case 1 2 3 4 6 7 8 9 10 This shows how powerful this syntax is. I came up with the idea for the syntax after I was allowed to choose which parts to install when installing the basic meta package.

See also  Whatsapp: The huge update brings four new features for voice messages

between line tempString=""; And echo $result All magic happens. The first is in the input 1-3,5,6-8 The comma has been replaced by a space and by elements 1-3 5 And 6-8 pass through the for loop. There is a minus, if any - by two points .. replacing. after the loop in the variable $tempString {1..3}{5}{6..8} In the following lines between }{ You entered a space } {, removing curly braces and removing a comma at the end due to configuration. In another episode, it becomes the chain 1..3 5 6..8 Through the magic of bash (expand) and semicolon in the string 1 2 3;5;6 7 8;. Finally, the semicolon at the end is removed and the remaining semicolons are replaced with spaces. Now we have a string containing all the entries we want.

sources

Bash guide
my project
arc wiki

And some posts on stackoverflow and unix.stackexchange

Image source: https://archlinux.org/