installer script: work in progress (4)

This commit is contained in:
Daniel Langbein 2021-05-01 12:25:25 +02:00
parent a32bb78c2e
commit a7aa52184f
6 changed files with 180 additions and 162 deletions

View File

@ -4,7 +4,8 @@
source installer.cfg || { exit 1; }
# load functions
source helper.sh || { exit 1; }
source lib/util.sh || { exit 1; }
source lib/user-input.sh || { exit 1; }
function check_network() {
@ -29,107 +30,6 @@ function increase_cow_space() {
mount -o remount,size=2G /run/archiso/cowspace || return $?
}
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_text_input: all given args must not be empty";
return 1;
fi
done
local -n ptr=$1
if [ -z "$ptr" ]; then
# if ptr has no value yet, ask user for input!
echo "$2"
read -r ptr || return $?
fi
# check string length to be greater than zero!
if [ "${#ptr}" -lt 1 ]; then
echo "get_text_input must not be empty!";
return 1;
fi
}
function get_single_choice {
# If variable with name $1 is zero, then ask user to select one option.
#
# $1: name of variable to store the selected option
# $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_single_choice requires three args!";
return 1
fi
for i in "$@"; do
if [ -z "$i" ]; then
echo "get_single_choice: all given args must not be empty";
return 1;
fi
done
local -n ptr=$1
if [ -z "$ptr" ]; then
# if ptr has no value yet, ask user for input!
local -n MENU_OPTIONS=$3
ptr=$(dialog --stdout --menu "$2" 0 0 0 ${MENU_OPTIONS}) || {
echo "Error during menu selection!"
exit 1
}
clear
fi
}
function get_multi_choice {
# If variable with name $1 is zero, then ask user to select one ore more options.
#
# $1: name of variable to store array of selected options
# $2: text to display
# $3: name of variable with space-separated menu options to display (each menu option consists of an item, a description and on/off if preselected or not)
if [ "$#" -ne 3 ]; then
echo "get_multi_choice requires three args!";
return 1
fi
for i in "$@"; do
if [ -z "$i" ]; then
echo "get_multi_choice: all given args must not be empty";
return 1;
fi
done
local -n ptr=$1
if [ -z "$ptr" ]; then
# if ptr has no value yet, ask user for input!
local -n MENU_OPTIONS=$3
TMP1=$(dialog --stdout --checklist "$2" 0 0 0 ${MENU_OPTIONS}) || {
echo "Error during menu selection!"
exit 1
}
clear
# Result of dialog is space separated list
# Store this as an array
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
# readarray -d " " -t ptr < <(printf '%s' "$TMP1")
#
space_separated_to_array TMP1 "$1"
fi
}
function get_user_input() {
# return: the following variables:
# BIOS_TYPE (uefi or bios)
@ -142,13 +42,13 @@ function get_user_input() {
get_block_devices_with_size || return $?
get_single_choice TARGET_BLOCK_DEVICE "Select target device for installation" BLOCK_DEVICE_SIZES || return $?
TMP1="uefi Newer-mainboards bios Legacy-BIOS-on-older-mainboards"
TMP1=('uefi' 'Newer mainboards' 'bios' 'Legacy BIOS on older mainboards')
get_single_choice BIOS_TYPE "Select your bios type" TMP1 || return $?
TMP1="linux-lts Long-Time-Stable-Linux-kernel linux Latest-Linux-kernel"
TMP1=('linux-lts' 'Long-Time-Stable Linux kernel' 'linux' 'Latest Linux kernel')
get_single_choice 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"
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_single_choice FS "Select filesystem to use" TMP1 || return $?
get_text_input HOSTNAME "Enter hostname:" || return $?
@ -234,13 +134,13 @@ function choose_mount_options() {
# - The noatime option fully disables writing file access times to the drive every time you read a file.
# This works well for almost all applications, except for those that need to know if a file has been
# read since the last time it was modified.
TMP1="noatime Don't-write-file/folder-access-times off ssd Only-enable-when-on-ssd-or-nvme off"
TMP1=('noatime' "Don't write file/folder access times" 'on' 'ssd' 'Enable if using SSD/NVMe' 'off')
;;
EXT4)
TMP1="noatime Don't-write-file/folder-access-times off"
TMP1=('noatime'" Don't write file/folder access times" 'on')
;;
F2FS)
TMP1="noatime Don't-write-file/folder-access-times off"
TMP1=('noatime' "Don't write file/folder access times" 'on')
;;
*)
echo "Filesystem $FS not yet supported!"

View File

@ -1,50 +0,0 @@
function newline_to_space() {
# Replaces all newlines with spaces
# $1: name of variable
local -n ptr=$1
# Replace newlines with spaces
# See bash string substitution: https://gist.github.com/JPvRiel/b279524d3e56229a896477cb8082a72b
# echo "removing newlines in str: -->$ptr<--"
ptr="${ptr//$'\n'/' '}"
# echo "new str is: -->$ptr<--"
}
function space_separated_to_array() {
# $1: name of variable with space separated list
# $2: name of array to store values into
local -n ptr=$1
local -n ptr2=$2
# ptr space separated list.
# Store this as array ptr2.
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
readarray -d " " -t ptr2 < <(printf '%s' "$ptr")
}
function get_block_devices() {
# return: the following variables:
# BLOCK_DEVICES (array with each block device as one entry)
# get list of devices, one per line
local tmp
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)"
# replace newlines with spaces
newline_to_space BLOCK_DEVICE_SIZES
}

View File

@ -0,0 +1,100 @@
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_text_input: all given args must not be empty";
return 1;
fi
done
local -n ptr=$1
if [ -z "$ptr" ]; then
# if ptr has no value yet, ask user for input!
echo "$2"
read -r ptr || return $?
fi
# check string length to be greater than zero!
if [ "${#ptr}" -lt 1 ]; then
echo "get_text_input must not be empty!";
return 1;
fi
}
function get_single_choice {
# If variable with name $1 is zero, then ask user to select one option.
#
# $1: name of variable to store the selected option
# $2: text to display
# $3: name of variable with array of options to display (for each option there must be two entries in the array: Item and description)
if [ "$#" -ne 3 ]; then
echo "get_single_choice requires three args!";
return 1
fi
for i in "$@"; do
if [ -z "$i" ]; then
echo "get_single_choice: all given args must not be empty";
return 1;
fi
done
local -n ptr=$1
if [ -z "$ptr" ]; then
# if ptr has no value yet, ask user for input!
local -n MENU_OPTIONS=$3
ptr=$(dialog --stdout --menu "$2" 0 0 0 "${MENU_OPTIONS[@]}") || {
echo "Error during menu selection!"
exit 1
}
clear
fi
}
function get_multi_choice {
# If variable with name $1 is zero, then ask user to select one ore more options.
#
# $1: name of variable to store array of selected options
# $2: text to display
# $3: name of variable with array of options to display (for each option there must be three entries in the array: Item, description, on/off)
if [ "$#" -ne 3 ]; then
echo "get_multi_choice requires three args!";
return 1
fi
for i in "$@"; do
if [ -z "$i" ]; then
echo "get_multi_choice: all given args must not be empty";
return 1;
fi
done
local -n ptr=$1
if [ -z "$ptr" ]; then
# if ptr has no value yet, ask user for input!
local -n MENU_OPTIONS=$3
TMP1=$(dialog --stdout --checklist "$2" 0 0 0 "${MENU_OPTIONS[@]}") || {
echo "Error during menu selection!"
exit 1
}
clear
# Result of dialog is space separated list
# Store this as an array
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
# readarray -d " " -t ptr < <(printf '%s' "$TMP1")
#
space_separated_to_array TMP1 "$1"
fi
}

View File

@ -0,0 +1,69 @@
function newline_to_space() {
# Replaces all newlines with spaces
# $1: name of variable
local -n ptr=$1
# Replace newlines with spaces
# See bash string substitution: https://gist.github.com/JPvRiel/b279524d3e56229a896477cb8082a72b
# echo "replacing newlines in str: -->$ptr<--"
ptr="${ptr//$'\n'/' '}"
# echo "new str is: -->$ptr<--"
}
function newline_separated_to_array() {
# Watch out for tailing newlines as these will get an empty array entry at the end.
# $1 and $2 can be equal (if the result shall be written to the input variable)
#
# $1: name of variable with newline separated list
# $2: name of array to store values into
local -n ptr=$1
local -n ptr2=$2
# ptr newline separated list.
# Store this as array ptr2.
readarray -t ptr2 <<<"$ptr"
}
function space_separated_to_array() {
# $1: name of variable with space separated list
# $2: name of array to store values into
local -n ptr=$1
local -n ptr2=$2
# ptr space separated list.
# Store this as array ptr2.
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
readarray -d " " -t ptr2 < <(printf '%s' "$ptr")
}
function get_block_devices() {
# return: the following variables:
# BLOCK_DEVICES (array with one entry for each block device)
# Get list of devices, one per line
BLOCK_DEVICES=$(lsblk -dplnx size -o name | grep -Ev "boot|rpmb|loop" | tac)
newline_separated_to_array BLOCK_DEVICES BLOCK_DEVICES
}
function get_block_devices_with_size() {
# return: the following variables:
# BLOCK_DEVICE_SIZES (array with two entries for each block device: device path and device size)
# Get list of devices and their sizes, one pair per line
# 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" | sed 's|\s\s*| |' | tac)"
newline_to_space BLOCK_DEVICE_SIZES
space_separated_to_array BLOCK_DEVICE_SIZES BLOCK_DEVICE_SIZES
# # DEBUG
# for i in "${BLOCK_DEVICE_SIZES[@]}"; do
# echo "<$i>"
# done
# exit
}

View File

@ -2,7 +2,7 @@
_pkgname=repo
_reponame=arch
pkgname="de-p1st-$_pkgname"
pkgver=0.1.5
pkgver=0.1.6
pkgrel=1
pkgdesc="Bash script to manage remote Arch Linux repository"
arch=('any')

View File

@ -10,8 +10,7 @@ source /etc/de-p1st-repo/arch-repo.cfg || exit
function main(){
echo "Running 'pacman -Sy' ..."
sudo pacman -Sy || return $? # update mirrors -> this will also get the latest version of repository-db $REMOTE_DB_NAME
echo "Note: You may run 'arch-repo-push-new' and 'pacman -Sy' first ..."
all_pkg_vers || return $?
check_aur_updates || return $?