diff --git a/LICENSE b/LICENSE index e055643..b157657 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Sebastian Hugentobler +Copyright (c) Sebastian Hugentobler Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c87aa19..b68b18e 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,35 @@ -# UNMAINTAINED - -I no longer use void linux, excellent distribution that it is. - # Install Scripts for Void Linux on Pinebook Pro - Before using either of the scripts in this repository, read through them to clearly understand what they do. They are very opinionated and specifically -written to cater to my own needs (for example the use of `sudo`, other people +written to cater to my own needs (for example the use of `sudo`, other people might have different setups). It is, however, easy to change things around. -By default, the `bootstrap` script creates a minimal installation on the emmc -storage, with full disk encryption (with an unencrypted boot partition) via lvm -on luks. Two volumes `swap` and `root` are created, the latter is formatted with -an xfs filesystem. Additionally one user is created (with access to sudo via the -wheel group) and keymap, hostname and timezone get set. +By default, the `bootstrap` script creates a minimal installation on the emmc storage, +with full disk encryption via lvm on luks. Two volumes `swap` and `root` are created, +the latter is formatted with an xfs filesystem. Additionally one user is created +(with access to sudo via the wheel group) and keymap, hostname and timezone get set. -This gets you to a booting system, going on from there is out of scope here as -there are many ways to do that (for myself, I use `stow` to set up everything). +This gets you to a booting system, going on from there is out of scope here +as there are many ways to do that (for myself, I use `stow` to set up everything). -An important thing to keep in mind is that not all commands in the `bootstrap` -script are idempotent, that makes it all the more important to understand what -they do and to be sure to backup all important data. +An important thing to keep in mind is that not all commands in the `bootstrap` +script are idempotent, that makes it all the more important to understand what they +do and to be sure to backup all important data. -Pre-built images can be downloaded from the -[releases](https://code.vanwa.ch/sebastian/void-linux-installer/-/releases) page +Pre-built images can be downloaded from the [releases](https://code.vanwa.ch/sebastian/void-linux-installer/-/releases) page (those might be outdated though). -User and password for the live image are the standard void linux ones -(`root/voidlinux`). - # Scripts - ## mk_pbp_img - -Create a live image to boot void linux on the pinebook pro. Needs to be run on -an existing void linux system (docker might be possible with a working buildx -and some adaptions with the mounting of filesystems). +Create a live image to boot void linux on the pinebook pro. Needs to be run on an +existing void linux system (docker might be possible with a working buildx and some adaptions with the mounting of filesystems). A copy of the [void-mklive](https://github.com/void-linux/void-mklive.git) repository is downloaded next to the script into `.void-mklive` and used for -building the image. +building the image. -The script assumes it is running on an `x86_64` architecture, if that is not the -case, it needs to be changed (this applies to the use of `qemu-aarch64-static` -to get a chroot). +The script assumes it is running on an `x86_64` architecture, if that is not the case, +it needs to be changed (this applies to the use of `qemu-aarch64-static` to get a chroot). The following tools need to be accessible in `PATH`: @@ -53,40 +39,29 @@ The following tools need to be accessible in `PATH`: - sudo - xz -If there is an argument provided to the script, it is treated as the folder to -where the compressed image is written, if no argument is given, the current -working directory is used. +If there is an argument provided to the script, it is treated as the folder to where +the compressed image is written, if no argument is given, the current working +directory is used. -After a successful build, the finished image can be found in the directory -described above with a filename of `void-pbp.img.xz` - -Write it to a microSD card as such: +After a successful build, the finished image can be found in the directory described +above with a filename of `void-pbp.img.xz` +Write it to a microSD card as such: - `xz -d < void-pbp.img.xz | sudo dd of=/dev/mmcblk0 bs=4M status=progress` - `sudo sync` + +Be ***very*** careful to get the parameter for `of` right, otherwise you can destroy your system. -Be **_very_** careful to get the parameter for `of` right, otherwise you can -destroy your system. - -MicroSD cards can be fickle, it sometimes is helpful to not take them out -immediately, even after running `sync`. If booting from the card hangs, write -the image again onto it or use a different card. +MicroSD cards can be fickle, it sometimes is helpful to not take them out immediately, even after running `sync`. +If booting from the card hangs, write the image again onto it or use a different card. ## bootstrap - -Install void linux to the internal mmc storage of the pinebook pro or use it for -some maintenance task. - -Be aware that the time needs to be set in **\*UTC**, otherwise package -installation might not work. - -If running on a pinebook pro with an ISO keyboard, run `loadkeys uk` to load the -correct keymap. +Install void linux to the internal mmc storage of the pinebook pro or use it for some +maintenance task. Run it in either of two ways: ### non-interactive - `bootstrap full` Run a full installation, this will overwrite all data on the storage. @@ -94,14 +69,14 @@ Run a full installation, this will overwrite all data on the storage. Runs the `full_install` command internally. ### interactive - `bootstrap` -Run `help` to get a list of commands you can run and quit interactive mode with -typing `exit`. +Run `help` to get a list of commands you can run and quit interactive mode +with typing `exit`. -A useful thing to do here is the `repair` command. It sets up all the needed -filesystems and opens a chroot. +A useful thing to do here is the `repair` command. Sets up all the needed filesystems +and opens a chroot. + +Again, it is highly recommended to read what the respective commands do and to adapt +them to your own needs. -Again, it is highly recommended to read what the respective commands do and to -adapt them to your own needs. diff --git a/bootstrap b/bootstrap index 7d30c83..b4f686e 100755 --- a/bootstrap +++ b/bootstrap @@ -26,16 +26,12 @@ get_value() { secure="s" fi - # shellcheck source=/dev/null . "$CONFIG" - if [ -z "${!var_name}" ]; then local def_val="${default_values[$var_name]}" read -${secure}rp "$white$prompt [$def_val]:$nocolour " value echo "export $var_name=\"${value:-$def_val}\"" >> "$CONFIG" - - # shellcheck source=/dev/null . "$CONFIG" fi @@ -49,15 +45,13 @@ network() { ip link set "$wifi_if" up - nmcli device wifi list - local wifi_ssid wifi_ssid="$(get_value "wifi_ssid" "wifi ssid")" local wifi_pw wifi_pw="$(get_value "wifi_pw" "wifi password" 1)" - nmcli con delete "$wifi_ssid" || true - nmcli device wifi connect "$wifi_ssid" password "$wifi_pw" + wpa_supplicant -B -i "$wifi_if" -c <(wpa_passphrase "$wifi_ssid" "$wifi_pw") + sv restart dhcpcd } datetime() { @@ -106,7 +100,7 @@ create_lvm() { pvcreate /dev/mapper/void vgcreate void /dev/mapper/void - lvcreate -L 48G void -n swap + lvcreate -L 4G void -n swap lvcreate -l 100%FREE void -n root } @@ -119,32 +113,13 @@ make_filesystems() { mkfs.xfs -f -L ROOT /dev/void/root } -ensure_mount() { - local src="$1" - local dest="$2" - local with_rbind="$3" - - local rbind="" - - if [ ! -z "$with_rbind" ]; then - rbind="--rbind" - fi - - mount $rbind "$src" "$dest" - - if [ ! -z "$with_rbind" ]; then - mount --make-rslave "$dest" - fi -} - mount_filesystems() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - ensure_mount "/dev/void/root" "/mnt" - + mount /dev/void/root /mnt mkdir -p /mnt/boot - ensure_mount "$install_dev"p1 "/mnt/boot" + mount "$install_dev"p1 /mnt/boot swapon /dev/void/swap } @@ -162,19 +137,17 @@ EOF } mount_special_filesystems() { - ensure_mount "/sys" "/mnt/sys" 1 - ensure_mount "/dev" "/mnt/dev" 1 - ensure_mount "/proc" "/mnt/proc" 1 - ensure_mount "/tmp" "/mnt/tmp" 1 + mount --rbind /sys /mnt/sys && mount --make-rslave /mnt/sys + mount --rbind /dev /mnt/dev && mount --make-rslave /mnt/dev + mount --rbind /proc /mnt/proc && mount --make-rslave /mnt/proc + mount --rbind /tmp /mnt/tmp && mount --make-rslave /mnt/tmp } set_fstab() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - local boot_uuid - boot_uuid="$(blkid | grep "${install_dev}p1" | awk '{print $2}')" - + local boot_uuid="$(blkid | grep ${install_dev}p1 | awk '{print $2}')" cat >/mnt/etc/fstab </dev/null | hexdump -v -e '/1 " %02X"' | tr '[:upper:]' '[:lower:]')" - - local root_uuid - root_uuid="$(blkid | grep "${install_dev}p2" | awk '{print $2}' | sed 's/"//g')" - - sed -i "s/setenv macaddr.*/setenv macadr $mac/g" "$boot_txt" + local root_uuid="$(blkid | grep ${install_dev}p2 | awk '{print $2}' | sed 's/"//g')" sed -i "s|root=PARTUUID=|root=/dev/void/root rd.auto=1 cryptdevice=${root_uuid}:lvm|g" "$boot_txt" cp "$boot_txt" "$boot_txt_mine" @@ -214,14 +181,14 @@ set_user() { user_name="$(get_value "user_name" "username")" local user_pw - user_pw="$(get_value "user_pw" "user password" 1)" + user_pw="$(get_value "user_pw" "user password")" chroot /mnt /bin/env -i \ user_name="$user_name" \ user_pw="$user_pw" \ /bin/bash <<"EOT" useradd --groups wheel --create-home --shell /bin/bash --user-group $user_name -echo -e "$user_pw\n$user_pw" | passwd "$user_name" +echo "$user_name:$user_pw" | chpasswd EOT } @@ -238,7 +205,7 @@ set_base_conf() { local locale locale="$(get_value "locale" "locale")" - echo "$locale" >> /mnt/etc/default/libc-locales + echo "$locale" >> /etc/default/libc-locales chroot /mnt /bin/env -i \ timezone="$timezone" \ @@ -295,17 +262,7 @@ EOF } tidy_up() { - sync - - if grep -qe "/mnt " /proc/mounts; then - umount -R /mnt - fi - - swapoff /dev/void/swap > /dev/null 2>&1 || true - - vgchange --activate n - - cryptsetup close void > /dev/null 2>&1 || true + umount -R /mnt } full_install() { @@ -393,7 +350,7 @@ cmd_loop() { while [[ "$cmd" != "exit" ]]; do read -rp "${white}>$nocolour " cmd - if [[ "${commands[*]}" == *"${cmd}"* ]]; then + if [[ " ${commands[@]} " =~ " ${cmd} " ]]; then $cmd else if [ "$cmd" != "exit" ]; then @@ -403,8 +360,6 @@ cmd_loop() { done } -trap tidy_up 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM - if [ "$1" == "full" ]; then full_install else diff --git a/mk_pbp_img b/mk_pbp_img index e3fd8d9..9896d68 100755 --- a/mk_pbp_img +++ b/mk_pbp_img @@ -28,7 +28,7 @@ cleanup_mounts() { } check_tools() { - for tool in "${TOOLS[@]}"; do + for tool in ${TOOLS[@]}; do if ! command -v "$tool" &> /dev/null then echo "$tool could not be found" @@ -62,15 +62,22 @@ build_img() { cd "$GIT_DIR" sudo ./mkrootfs.sh -o "$rootfs_file" aarch64 - sudo ./mkplatformfs.sh -p "dracut lvm2 cryptsetup dbus NetworkManager" -o "$platformfs_file" pinebookpro "$rootfs_file" - sudo ./mkimage.sh -B 256MiB -s 3GB -o "$img" "$platformfs_file" + sudo ./mkplatformfs.sh -p "dracut lvm2 cryptsetup" -o "$platformfs_file" pinebookpro "$rootfs_file" + sudo ./mkimage.sh -B 256MiB -o "$img" "$platformfs_file" - # shellcheck disable=SC2024 - # it is correct that the decompressed image is written as the unprivileged user sudo xz --decompress --stdout "$img.xz" > "$img" + local loop_dev="$(sudo losetup --show -f -P "$img")" - local loop_dev - loop_dev="$(sudo losetup --show -f -P "$img")" + if [ ! -z "$DISCOVER_DEV" ]; then # needed if building inside a docker container + local partitions=$(lsblk --raw --output "MAJ:MIN" --noheadings ${loop_dev} | tail -n +2) + counter=1 + for i in $partitions; do + local maj=$(echo $i | cut -d: -f1) + local min=$(echo $i | cut -d: -f2) + if [ ! -e "${loop_dev}p${counter}" ]; then mknod ${loop_dev}p${counter} b $maj $min; fi + counter=$((counter + 1)) + done + fi sudo mount "$loop_dev"p2 "$TMP_DIR_MOUNT" sudo mount "$loop_dev"p1 "$TMP_DIR_MOUNT"/boot @@ -81,18 +88,16 @@ build_img() { sudo cp "$(which qemu-aarch64-static)" "$TMP_DIR_MOUNT/usr/bin/" sudo chroot "$TMP_DIR_MOUNT" qemu-aarch64-static /bin/bash <<"EOT" -ln -s /etc/sv/dbus /etc/runit/runsvdir/default/ -ln -s /etc/sv/NetworkManager /etc/runit/runsvdir/default/ -ln -s /etc/sv/sshd /etc/runit/runsvdir/default/ +ln -s /etc/sv/dhcpcd /etc/runit/runsvdir/default/ EOT sudo rm "$TMP_DIR_MOUNT/usr/bin/qemu-aarch64-static" cleanup_mounts mkdir -p "$OUT_DIR" - xz --threads=0 --compress --stdout "$img" > "$OUT_DIR/$(basename "$img.xz")" + xz --threads=0 --compress --stdout "$img" > "$OUT_DIR/$(basename $img.xz)" - echo "built pinebookpro image: $OUT_DIR/$(basename "$img.xz")" + echo "built pinebookpro image: $OUT_DIR/$(basename $img.xz)" } trap cleanup 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM