diff --git a/build-archiso.sh b/build-archiso.sh index 78b0cf9..72a8366 100755 --- a/build-archiso.sh +++ b/build-archiso.sh @@ -3,13 +3,16 @@ # https://wiki.archlinux.org/index.php/Archiso#Prepare_a_custom_profile # # Arch installer with some additional packages: -# -> de-p1st-installer +# -> TODO: set custom welchme messae in /etc/motd +# -> de-p1st-installer (TODO) # -> de-p1st mirror in pacman.conf +# -> german mirrors preselected # -> german keyboard +# -> nano with syntax highlighting # -> git # BUILD_DIR=./archlive -PKGS=('git' 'de-p1st-keyboard' 'de-p1st-pacman' 'de-p1st-pacman-mirrorlist' 'de-p1st-systemd' 'de-p1st-installer') +PKGS=('git' 'de-p1st-keyboard' 'de-p1st-nano' 'de-p1st-pacman' 'de-p1st-pacman-mirrorlist' 'de-p1st-systemd') PACMAN_CFG_ADDITION='pkg/de-p1st-pacman/pacman.d/de-p1st' # will be used to extend the builder's pacman.conf @@ -34,6 +37,7 @@ fi cp -r "$PROFILE" "$BUILD_DIR"/profile || exit +# extend the builder's pacman.conf (add de-p1st mirrors) # https://wiki.archlinux.org/index.php/Archiso#Custom_local_repository cat "${PACMAN_CFG_ADDITION}" >> "$BUILD_DIR"/profile/pacman.conf || exit diff --git a/pkg/de-p1st-installer/PKGBUILD_TODO.txt b/pkg/de-p1st-installer/PKGBUILD_TODO.txt index 4926147..24ab62b 100644 --- a/pkg/de-p1st-installer/PKGBUILD_TODO.txt +++ b/pkg/de-p1st-installer/PKGBUILD_TODO.txt @@ -9,7 +9,7 @@ arch=('any') url="https://codeberg.org/privacy1st/${_reponame}" license=('MIT') groups=() -depends=() +depends=('dialog') makedepends=('git') optdepends=() provides=() diff --git a/pkg/de-p1st-installer/de-p1st-installer.sh b/pkg/de-p1st-installer/de-p1st-installer.sh old mode 100644 new mode 100755 index 05a7907..e493455 --- a/pkg/de-p1st-installer/de-p1st-installer.sh +++ b/pkg/de-p1st-installer/de-p1st-installer.sh @@ -1,2 +1,187 @@ #!/bin/bash +# load config +source installer.cfg || { exit 1; } + + +function check_network() { + echo "Sending ping to wikipedia.de ..." + ping -c 1 wikipedia.de || { + echo "Pleas set up network access." + return 1 + } +} + +function increase_cow_space() { + # May be useful when running 'pacman -Syu' on the live medium. + # Usually not necessary! + + # make sure that we are on a live medium: + findmnt /run/archiso/cowspace || { + echo "Not on live medium, did not increase cowspace!" + return 1 + } + + echo "Increasing cowspace partition of live medium ..." + mount -o remount,size=2G /run/archiso/cowspace || return $? +} + +function get_block_devices(){ + # return: the following variables: + # BLOCK_DEVICES (array with each block device as one entry) + + local tmp +# # get list of devices , one per line +# # +# # -> remove everything after first whitespace +# # -> with sed; alternative: awk '{print $1}' +# # -> add "/dev/" at start of each line +# tmp=$(lsblk --noheadings --nodeps | sed 's|\s.*$||; s|^|&/dev/|') || return $? + tmp=$(lsblk -dplnx size -o name | grep -Ev "boot|rpmb|loop") + + readarray -t BLOCK_DEVICES <<<"$tmp" +} + +function get_block_devices_with_size() { + # return: the following variables: + # BLOCK_DEVICE_SIZES (space separated list of block devices and their sizes) + + # one could use sed to remove multiple white spaces + # sed 's|\s\s*| |' + BLOCK_DEVICE_SIZES="$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | tac)" +} + +function get_text_input { + # If variable with name $1 is zero, then ask user for input. + # Only one line user input is allowed. + # User input must not be empty. + # + # $1: name of variable to store user input + # $2: text to display (e.g. "Enter hostname:") + if [ "$#" -ne 2 ]; then + echo "get_text_input requires two args!"; + return 1 + fi + for i in "$@"; do + if [ -z "$i" ]; then + echo "get_menu_selections: all given args must not be empty"; + return 1; + fi + done + + local -n VAR=$1 + if [ -z "$VAR" ]; then + # if VAR has no value yet, ask user for input! + echo "$2" + read -r VAR || return $? + fi + + # check string length to be greater than zero! + if [ "${#VAR}" -lt 1 ]; then + echo "get_text_input must not be empty!"; + return 1; + fi +} + +function get_menu_selection { + # If variable with name $1 is zero, then ask user to select one option. + # + # $1: name of variable to store user selection + # $2: text to display + # $3: name of variable with space-separated menu options to display (each menu option consists of an item and a description) + if [ "$#" -ne 3 ]; then + echo "get_menu_selection requires three args!"; + return 1 + fi + for i in "$@"; do + if [ -z "$i" ]; then + echo "get_menu_selections: all given args must not be empty"; + return 1; + fi + done + + + local -n VAR=$1 + if [ -z "$VAR" ]; then + # if VAR has no value yet, ask user for input! + + local -n MENU_OPTIONS=$3 + VAR=$(dialog --stdout --menu "$2" 0 0 0 ${MENU_OPTIONS}) || { + echo "Error during menu selection!" + exit 1 + } + clear + fi +} + +function get_user_input() { + # return: the following variables: + # BIOS_TYPE (uefi or bios) + # KERNEL (linux or linux-lts) + # FS (BTRFS, EXT4, F2FS) + # HOSTNAME + # USERNAME, USER_PWD + # LUKS_PWD + + # get_block_devices || return $? + get_block_devices_with_size || return $? + get_menu_selection TARGET_BLOCK_DEVICE "Select target device for installation" BLOCK_DEVICE_SIZES || return $? + + TMP1="uefi Newer-mainboards bios Legacy-BIOS-on-older-mainboards" + get_menu_selection BIOS_TYPE "Select your bios type" TMP1 || return $? + + TMP1="linux-lts Long-Time-Stable-Linux-kernel linux Latest-Linux-kernel" + get_menu_selection KERNEL "Select kernel version" TMP1 || return $? + + TMP1="BTRFS allows-snapshots-and-dynamic-extension-of-the-fs EXT4 default-fs-of-many-distributions F2FS Flash-Friendly-fs-for-SSD-or-NVMe" + get_menu_selection FS "Select filesystem to use" TMP1 || return $? + + get_text_input HOSTNAME "Enter hostname:" || return $? + get_text_input USERNAME "Enter username:" || return $? + + if [ -z "${USER_PWD}" ]; then + get_text_input USER_PWD "Enter a user password:" || return $? + get_text_input USER_PWD2 "Please enter the password again:" || return $? + [[ "${USER_PWD}" == "${USER_PWD2}" ]] || { + echo "Passwords did not match"; + exit 1; + } + fi + if [ -z "${LUKS_PWD}" ]; then + get_text_input LUKS_PWD "Enter a disk encryption password:" || return $? + get_text_input LUKS_PWD2 "Please enter the password again:" || return $? + [[ "${LUKS_PWD}" == "${LUKS_PWD2}" ]] || { + echo "Passwords did not match"; + exit 1; + } + fi +} + +function get_cpu_vendor() { + # return: the following variables: + # CPU_VENDOR ("amd", "intel", "none") + + if [ -z "${CPU_VENDOR}" ]; then + # if CPU_VENDOR has no value yet, ask user for input! + + local vendor_id + vendor_id=$(cat /proc/cpuinfo | grep vendor_id | head -1 | sed 's|vendor_id\s*:\s*||') + + if [ "$vendor_id" = "AuthenticAMD" ]; then + CPU_VENDOR="amd" + elif [ "$vendor_id" = "GenuineIntel" ]; then + CPU_VENDOR="intel" + else + echo "Unknown CPU vendor: $vendor_id" + return 1 + fi + fi +} + +function main() { + check_network || return $? + get_user_input || return $? + get_cpu_vendor || return $? +} + +main "$@" diff --git a/pkg/de-p1st-installer/installer.cfg b/pkg/de-p1st-installer/installer.cfg new file mode 100644 index 0000000..1e2cefe --- /dev/null +++ b/pkg/de-p1st-installer/installer.cfg @@ -0,0 +1,15 @@ +# Example config +# for test in virtual machine + +HOSTNAME=yodaTest +USERNAME=arch +USER_PWD=test +LUKS_PWD=test + +KERNEL=linux + +TARGET_BLOCK_DEVICE=/dev/sda +FS=BTRFS + +CPU_VENDOR=none +BIOS_TYPE=uefi diff --git a/pkg/de-p1st-installer/name-reference-test.sh b/pkg/de-p1st-installer/name-reference-test.sh new file mode 100644 index 0000000..0da1c49 --- /dev/null +++ b/pkg/de-p1st-installer/name-reference-test.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# source: https://stackoverflow.com/a/52678279/6334421 + +# A variable can be assigned the nameref attribute using the -n option +# to the declare or local builtin commands (see Bash Builtins) to create +# a nameref, or a reference to another variable. This allows variables to +# be manipulated indirectly. + +function text_input { + # If variable of name $1 is zero, then ask user for input. + # Only one line user input is allowed. + # User input must not be empty. + # + # $1: variable name to store input to + # $2: text to display (e.g. "Enter hostname:") + if [ -z "$1" ] || [ -z "$2" ]; then + echo "text_input requires two args!"; + return 1 + fi + + local -n VAR=$1 + if [ -z "$VAR" ]; then + echo "$2" + read -r VAR || return $? + fi + + # check string length to be greater than zero! + if [ "${#VAR}" -lt 1 ]; then + echo "text_input must not be empty!"; + return 1; + fi +} + +text_input foo "Enter something funny:" +echo "Input: $foo" + +bar="" +text_input bar "Enter something even funnier:" +echo "Input: $bar"