bash format

This commit is contained in:
mfgbhatti 2022-01-29 17:38:53 +00:00
parent 99e648635e
commit 6569ceca5b
1 changed files with 206 additions and 201 deletions

View File

@ -4,7 +4,7 @@
# user name, password, etc.
# shellcheck disable=SC2207,SC2120
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Set up a config file
CONFIG_FILE=$SCRIPT_DIR/setup.conf
@ -20,7 +20,7 @@ set_option() {
sed -i -e "/^${1}.*/d" "$CONFIG_FILE"
fi
# Else add option
echo "${1}=${2}" >> "$CONFIG_FILE"
echo "${1}=${2}" >>"$CONFIG_FILE"
}
# Adding global functions and variables to use in this script
@ -47,23 +47,23 @@ connection_test() {
}
# Check coutry for mirrorlist
check_country () {
check_country() {
_ISO=$(curl --fail https://ifconfig.co/country-iso)
set_option "ISO" "$_ISO"
}
# Install fonts
install_font () {
install_font() {
pacman -S --noconfirm --needed terminus-font
}
# timedatectl set-ntp true
set_ntp () {
set_ntp() {
timedatectl set-ntp true
}
# Check for UEFI
efi_check () {
efi_check() {
if [[ -d "/sys/firmware/efi/" ]]; then
if (mount | grep /sys/firmware/efi/efivars); then
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
@ -77,7 +77,7 @@ efi_check () {
}
# if btrfs is selected
set_btrfs () {
set_btrfs() {
# Used -a to get more than one argument
echo "Please enter your btrfs subvolumes separated by space"
echo "usualy they start with @ like @home, @temp etc."
@ -99,7 +99,7 @@ set_btrfs () {
fi
done
# Check for duplicates
IFS=" " read -r -a SUBS <<< "$(tr ' ' '\n' <<< "${NAMES[@]}" | sort -u | tr '\n' ' ')"
IFS=" " read -r -a SUBS <<<"$(tr ' ' '\n' <<<"${NAMES[@]}" | sort -u | tr '\n' ' ')"
# Set to config file
set_option "SUBVOLUMES" "${SUBS[*]}"
fi
@ -131,7 +131,7 @@ set_password() {
}
# Make a title
title () {
title() {
echo -ne "\n"
echo -ne "------------------------------------------------------------------------\n"
echo -ne "\t\t\"$1\"\n"
@ -140,7 +140,7 @@ title () {
# Write shared functions to to setup.conf
write_to_config() {
cat << EOF > "$CONFIG_FILE"
cat <<EOF >"$CONFIG_FILE"
#!/usr/bin/env bash
title () {
@ -177,13 +177,12 @@ echo -ne "
EOF
}
# Ask user for option
PROMPT="Please enter your option: "
# This will be shown on every set as user is progressing
logo () {
echo -ne "
logo() {
echo -ne "
------------------------------------------------------------------------
█████╗ ██████╗ ██████╗██╗ ██╗████████╗██╗████████╗██╗ ██╗███████╗
@ -196,7 +195,7 @@ echo -ne "
}
# Backround checks
background_check () {
background_check() {
if connection_test; then
echo -ne "ERROR! There seems to be no internet connection.\n"
exit 1
@ -245,20 +244,18 @@ set_partion_layout() {
;;
*)
invalid_option
setpartionlayout
set_partion_layout
;;
esac
else
invalid_option
filesystem
set_partion_layout
fi
done
}
# This function will handle file systems.
set_filesystem () {
set_filesystem() {
title "Setup File System"
FILESYS=("btrfs" "ext2" "ext3" "ext4" "f2fs" "jfs" "nilfs2" "ntfs" "reiserfs" "vfat" "xfs")
PS3="$PROMPT"
@ -278,7 +275,7 @@ set_filesystem () {
}
# Added this from arch wiki https://wiki.archlinux.org/title/System_time
set_timezone () {
set_timezone() {
title "Setup Time Zone"
_TIMEZONE="$(curl --fail https://ipapi.co/timezone)"
_ZONE=($(timedatectl list-timezones | sed 's/\/.*$//' | uniq))
@ -286,10 +283,10 @@ set_timezone () {
echo -ne "\n"
read -r -p "Is this correct? yes/no: " ANSWER
case "$ANSWER" in
y|Y|yes|Yes|YES)
y | Y | yes | Yes | YES)
set_option TIMEZONE "$_TIMEZONE"
;;
n|N|no|NO|No)
n | N | no | NO | No)
title "Manually setting timezone"
PS3="$PROMPT"
echo -ne "Please select your zone: \n"
@ -315,12 +312,15 @@ set_timezone () {
done
;;
*) echo "Wrong option. Try again";timezone;;
*)
echo "Wrong option. Try again"
set_timezone
;;
esac
}
# These are default key maps as presented in official arch repo archinstall
set_keymap () {
set_keymap() {
title "Setup Keymap"
KEYMAPS=("by" "ca" "cf" "cz" "de" "dk" "es" "et" "fa" "fi" "fr" "gr" "hu" "il" "it" "lt" "lv" "mk" "nl" "no" "pl" "ro" "ru" "sg" "ua" "uk" "us")
PS3="$PROMPT"
@ -330,30 +330,33 @@ set_keymap () {
break
else
invalid_option
keymap
set_keymap
fi
done
}
# Confirm if ssd is present
ssd_drive () {
ssd_drive() {
title "SSD Drive Confirmation"
read -r -p "Is this system using an SSD? yes/no: " _SSD
case "$_SSD" in
y|Y|yes|Yes|YES)
y | Y | yes | Yes | YES)
set_option "SSD" 1
set_option "MOUNTOPTION" "noatime,compress=zstd,ssd,commit=120"
;;
n|N|no|NO|No)
n | N | no | NO | No)
set_option "SSD" 0
set_option "MOUNTOPTION" "noatime,compress=zstd,commit=120"
;;
*) echo "Wrong option. Try again";ssddrive;;
*)
echo "Wrong option. Try again"
ssd_drive
;;
esac
}
# Selection for disk type
disk_selection () {
disk_selection() {
# show disks present on system
title "Disk Selection"
DISKLIST="$(lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print "/dev/"$2" - "$3}')" # show disks with /dev/ prefix and size
@ -371,7 +374,7 @@ disk_selection () {
done
}
user_info () {
user_info() {
title "Add Your Information"
read -r -p "Please enter your username: " USERNAME
set_option "USERNAME" "${USERNAME,,}" # convert to lower case as in issue #109
@ -381,7 +384,7 @@ user_info () {
}
# Set locale
set_locale (){
set_locale() {
title "Setup Locale"
LOCALES=($(grep UTF-8 /etc/locale.gen | sed 's/\..*$//' | sed '/@/d' | awk '{print $1}' | uniq | sed 's/#//g'))
PS3="$PROMPT"
@ -455,7 +458,8 @@ set_desktop() {
set_option "WM" "i3-gaps"
break
;;
*) echo "Wrong option. Try again"
*)
echo "Wrong option. Try again"
break
;;
esac
@ -468,7 +472,7 @@ set_desktop() {
}
# Make choice for installation
make_choice () {
make_choice() {
title "Your system choice"
CHOICE=("Default Install" "Custom Install")
PS3="$PROMPT"
@ -520,7 +524,8 @@ make_choice () {
set_desktop
break
;;
*) echo "Wrong option. Try again"
*)
echo "Wrong option. Try again"
break
;;
esac