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. # user name, password, etc.
# shellcheck disable=SC2207,SC2120 # 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 # Set up a config file
CONFIG_FILE=$SCRIPT_DIR/setup.conf CONFIG_FILE=$SCRIPT_DIR/setup.conf
@ -20,17 +20,17 @@ set_option() {
sed -i -e "/^${1}.*/d" "$CONFIG_FILE" sed -i -e "/^${1}.*/d" "$CONFIG_FILE"
fi fi
# Else add option # Else add option
echo "${1}=${2}" >> "$CONFIG_FILE" echo "${1}=${2}" >>"$CONFIG_FILE"
} }
# Adding global functions and variables to use in this script # Adding global functions and variables to use in this script
# Check for root user # Check for root user
check_root() { check_root() {
if [[ "$(id -u)" != "0" ]]; then if [[ "$(id -u)" != "0" ]]; then
echo -ne "ERROR! This script has to be run under the 'root' user!" echo -ne "ERROR! This script has to be run under the 'root' user!"
exit 1 exit 1
fi fi
} }
# Check if distro is arch # Check if distro is arch
@ -47,37 +47,37 @@ connection_test() {
} }
# Check coutry for mirrorlist # Check coutry for mirrorlist
check_country () { check_country() {
_ISO=$(curl --fail https://ifconfig.co/country-iso) _ISO=$(curl --fail https://ifconfig.co/country-iso)
set_option "ISO" "$_ISO" set_option "ISO" "$_ISO"
} }
# Install fonts # Install fonts
install_font () { install_font() {
pacman -S --noconfirm --needed terminus-font pacman -S --noconfirm --needed terminus-font
} }
# timedatectl set-ntp true # timedatectl set-ntp true
set_ntp () { set_ntp() {
timedatectl set-ntp true timedatectl set-ntp true
} }
# Check for UEFI # Check for UEFI
efi_check () { efi_check() {
if [[ -d "/sys/firmware/efi/" ]]; then if [[ -d "/sys/firmware/efi/" ]]; then
if (mount | grep /sys/firmware/efi/efivars); then if (mount | grep /sys/firmware/efi/efivars); then
mount -t efivarfs efivarfs /sys/firmware/efi/efivars mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi fi
# UEFI detected # UEFI detected
set_option "UEFI" 1 set_option "UEFI" 1
else else
# No UEFI detected # No UEFI detected
set_option "UEFI" 0 set_option "UEFI" 0
fi fi
} }
# if btrfs is selected # if btrfs is selected
set_btrfs () { set_btrfs() {
# Used -a to get more than one argument # Used -a to get more than one argument
echo "Please enter your btrfs subvolumes separated by space" echo "Please enter your btrfs subvolumes separated by space"
echo "usualy they start with @ like @home, @temp etc." echo "usualy they start with @ like @home, @temp etc."
@ -92,14 +92,14 @@ set_btrfs () {
for i in "${ARR[@]}"; do for i in "${ARR[@]}"; do
# Check for user input for @ # Check for user input for @
if [[ $i =~ [@] ]]; then if [[ $i =~ [@] ]]; then
# push values to array # push values to array
NAMES+=("$i") NAMES+=("$i")
else else
NAMES+=(@"${i}") NAMES+=(@"${i}")
fi fi
done done
# Check for duplicates # 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 to config file
set_option "SUBVOLUMES" "${SUBS[*]}" set_option "SUBVOLUMES" "${SUBS[*]}"
fi fi
@ -107,7 +107,7 @@ set_btrfs () {
# Check if an element exists # Check if an element exists
elements_present() { elements_present() {
for e in "${@:2}"; do [[ "$e" == "$1" ]] && break; done for e in "${@:2}"; do [[ "$e" == "$1" ]] && break; done
} }
# Invalid option message # Invalid option message
@ -123,7 +123,7 @@ set_password() {
read -rs -p "Please re-enter password: " PASSWORD2 read -rs -p "Please re-enter password: " PASSWORD2
echo -ne "\n" echo -ne "\n"
if [[ "$PASSWORD1" == "$PASSWORD2" ]]; then if [[ "$PASSWORD1" == "$PASSWORD2" ]]; then
set_option "$1" "$PASSWORD1" set_option "$1" "$PASSWORD1"
else else
echo -ne "Passwords do not match \n" echo -ne "Passwords do not match \n"
set_password set_password
@ -131,7 +131,7 @@ set_password() {
} }
# Make a title # Make a title
title () { title() {
echo -ne "\n" echo -ne "\n"
echo -ne "------------------------------------------------------------------------\n" echo -ne "------------------------------------------------------------------------\n"
echo -ne "\t\t\"$1\"\n" echo -ne "\t\t\"$1\"\n"
@ -140,7 +140,7 @@ title () {
# Write shared functions to to setup.conf # Write shared functions to to setup.conf
write_to_config() { write_to_config() {
cat << EOF > "$CONFIG_FILE" cat <<EOF >"$CONFIG_FILE"
#!/usr/bin/env bash #!/usr/bin/env bash
title () { title () {
@ -177,13 +177,12 @@ echo -ne "
EOF EOF
} }
# Ask user for option # Ask user for option
PROMPT="Please enter your option: " PROMPT="Please enter your option: "
# This will be shown on every set as user is progressing # This will be shown on every set as user is progressing
logo () { logo() {
echo -ne " echo -ne "
------------------------------------------------------------------------ ------------------------------------------------------------------------
█████╗ ██████╗ ██████╗██╗ ██╗████████╗██╗████████╗██╗ ██╗███████╗ █████╗ ██████╗ ██████╗██╗ ██╗████████╗██╗████████╗██╗ ██╗███████╗
@ -196,7 +195,7 @@ echo -ne "
} }
# Backround checks # Backround checks
background_check () { background_check() {
if connection_test; then if connection_test; then
echo -ne "ERROR! There seems to be no internet connection.\n" echo -ne "ERROR! There seems to be no internet connection.\n"
exit 1 exit 1
@ -221,52 +220,50 @@ set_partion_layout() {
select OPT in "${LAYOUTS[@]}"; do select OPT in "${LAYOUTS[@]}"; do
if elements_present "$OPT" "${LAYOUTS[@]}"; then if elements_present "$OPT" "${LAYOUTS[@]}"; then
case "$REPLY" in case "$REPLY" in
1) 1)
set_option "LAYOUT" 1 set_option "LAYOUT" 1
break break
;; ;;
2) 2)
# set_option "LAYOUT" "$OPT" # set_option "LAYOUT" "$OPT"
set_option "LVM" 1 set_option "LVM" 1
set_option "LUKS" 0 set_option "LUKS" 0
break break
;; ;;
3) 3)
# set_option "LAYOUT" "$OPT" # set_option "LAYOUT" "$OPT"
set_option "LUKS" 1 set_option "LUKS" 1
set_option "LVM" 1 set_option "LVM" 1
set_password "LUKS_PASSWORD" set_password "LUKS_PASSWORD"
break break
;; ;;
4) 4)
echo -ne "Maintaining current settings" echo -ne "Maintaining current settings"
set_option "LAYOUT" 0 set_option "LAYOUT" 0
break break
;; ;;
*) *)
invalid_option invalid_option
setpartionlayout set_partion_layout
;; ;;
esac esac
else else
invalid_option invalid_option
filesystem set_partion_layout
fi fi
done done
} }
# This function will handle file systems. # This function will handle file systems.
set_filesystem () { set_filesystem() {
title "Setup File System" title "Setup File System"
FILESYS=("btrfs" "ext2" "ext3" "ext4" "f2fs" "jfs" "nilfs2" "ntfs" "reiserfs" "vfat" "xfs") FILESYS=("btrfs" "ext2" "ext3" "ext4" "f2fs" "jfs" "nilfs2" "ntfs" "reiserfs" "vfat" "xfs")
PS3="$PROMPT" PS3="$PROMPT"
select OPT in "${FILESYS[@]}"; do select OPT in "${FILESYS[@]}"; do
if elements_present "$OPT" "${FILESYS[@]}"; then if elements_present "$OPT" "${FILESYS[@]}"; then
if [ "$OPT" == "btrfs" ]; then if [ "$OPT" == "btrfs" ]; then
set_btrfs set_btrfs
break break
fi fi
set_option "FS" "$OPT" set_option "FS" "$OPT"
break break
@ -278,49 +275,52 @@ set_filesystem () {
} }
# Added this from arch wiki https://wiki.archlinux.org/title/System_time # Added this from arch wiki https://wiki.archlinux.org/title/System_time
set_timezone () { set_timezone() {
title "Setup Time Zone" title "Setup Time Zone"
_TIMEZONE="$(curl --fail https://ipapi.co/timezone)" _TIMEZONE="$(curl --fail https://ipapi.co/timezone)"
_ZONE=($(timedatectl list-timezones | sed 's/\/.*$//' | uniq)) _ZONE=($(timedatectl list-timezones | sed 's/\/.*$//' | uniq))
echo -ne "System detected your timezone to be '$_TIMEZONE'" echo -ne "System detected your timezone to be '$_TIMEZONE'"
echo -ne "\n" echo -ne "\n"
read -r -p "Is this correct? yes/no: " ANSWER read -r -p "Is this correct? yes/no: " ANSWER
case "$ANSWER" in case "$ANSWER" in
y|Y|yes|Yes|YES) y | Y | yes | Yes | YES)
set_option TIMEZONE "$_TIMEZONE" set_option TIMEZONE "$_TIMEZONE"
;; ;;
n|N|no|NO|No) n | N | no | NO | No)
title "Manually setting timezone" title "Manually setting timezone"
PS3="$PROMPT" PS3="$PROMPT"
echo -ne "Please select your zone: \n" echo -ne "Please select your zone: \n"
select ZONE in "${_ZONE[@]}"; do select ZONE in "${_ZONE[@]}"; do
if elements_present "$ZONE" "${_ZONE[@]}"; then if elements_present "$ZONE" "${_ZONE[@]}"; then
_SUBZONE=($(timedatectl list-timezones | grep "${ZONE}" | sed 's/^.*\///')) _SUBZONE=($(timedatectl list-timezones | grep "${ZONE}" | sed 's/^.*\///'))
PS3="$PROMPT" PS3="$PROMPT"
echo -ne "Please select your subzone: \n" echo -ne "Please select your subzone: \n"
select SUBZONE in "${_SUBZONE[@]}"; do select SUBZONE in "${_SUBZONE[@]}"; do
if elements_present "$SUBZONE" "${_SUBZONE[@]}"; then if elements_present "$SUBZONE" "${_SUBZONE[@]}"; then
set_option "TIMEZONE" "${ZONE}/${SUBZONE}" set_option "TIMEZONE" "${ZONE}/${SUBZONE}"
break break
else else
invalid_option invalid_option
break break
fi fi
done done
break break
else else
invalid_option invalid_option
break break
fi fi
done done
;; ;;
*) echo "Wrong option. Try again";timezone;; *)
echo "Wrong option. Try again"
set_timezone
;;
esac esac
} }
# These are default key maps as presented in official arch repo archinstall # These are default key maps as presented in official arch repo archinstall
set_keymap () { set_keymap() {
title "Setup 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") 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" PS3="$PROMPT"
@ -330,30 +330,33 @@ set_keymap () {
break break
else else
invalid_option invalid_option
keymap set_keymap
fi fi
done done
} }
# Confirm if ssd is present # Confirm if ssd is present
ssd_drive () { ssd_drive() {
title "SSD Drive Confirmation" title "SSD Drive Confirmation"
read -r -p "Is this system using an SSD? yes/no: " _SSD read -r -p "Is this system using an SSD? yes/no: " _SSD
case "$_SSD" in case "$_SSD" in
y|Y|yes|Yes|YES) y | Y | yes | Yes | YES)
set_option "SSD" 1 set_option "SSD" 1
set_option "MOUNTOPTION" "noatime,compress=zstd,ssd,commit=120" 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 "SSD" 0
set_option "MOUNTOPTION" "noatime,compress=zstd,commit=120" set_option "MOUNTOPTION" "noatime,compress=zstd,commit=120"
;; ;;
*) echo "Wrong option. Try again";ssddrive;; *)
echo "Wrong option. Try again"
ssd_drive
;;
esac esac
} }
# Selection for disk type # Selection for disk type
disk_selection () { disk_selection() {
# show disks present on system # show disks present on system
title "Disk Selection" title "Disk Selection"
DISKLIST="$(lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print "/dev/"$2" - "$3}')" # show disks with /dev/ prefix and size 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 done
} }
user_info () { user_info() {
title "Add Your Information" title "Add Your Information"
read -r -p "Please enter your username: " USERNAME read -r -p "Please enter your username: " USERNAME
set_option "USERNAME" "${USERNAME,,}" # convert to lower case as in issue #109 set_option "USERNAME" "${USERNAME,,}" # convert to lower case as in issue #109
@ -381,7 +384,7 @@ user_info () {
} }
# Set locale # Set locale
set_locale (){ set_locale() {
title "Setup Locale" title "Setup Locale"
LOCALES=($(grep UTF-8 /etc/locale.gen | sed 's/\..*$//' | sed '/@/d' | awk '{print $1}' | uniq | sed 's/#//g')) LOCALES=($(grep UTF-8 /etc/locale.gen | sed 's/\..*$//' | sed '/@/d' | awk '{print $1}' | uniq | sed 's/#//g'))
PS3="$PROMPT" PS3="$PROMPT"
@ -404,60 +407,61 @@ set_desktop() {
select OPT in "${SELECTION[@]}"; do select OPT in "${SELECTION[@]}"; do
if elements_present "$OPT" "${SELECTION[@]}"; then if elements_present "$OPT" "${SELECTION[@]}"; then
case "$REPLY" in case "$REPLY" in
1) 1)
# More packages can be added here # More packages can be added here
set_option "DE" "plasma" set_option "DE" "plasma"
set_option "DM" "sddm" set_option "DM" "sddm"
break break
;; ;;
2) 2)
set_option "DE" "gnome" set_option "DE" "gnome"
set_option "DM" "gdm" set_option "DM" "gdm"
break break
;; ;;
3) 3)
set_option "DE" "xfce4" set_option "DE" "xfce4"
set_option "DM" "lightdm" set_option "DM" "lightdm"
break break
;; ;;
4) 4)
set_option "DE" "mate" set_option "DE" "mate"
set_option "DM" "lightdm" set_option "DM" "lightdm"
break break
;; ;;
5) 5)
set_option "DE" "lxqt" set_option "DE" "lxqt"
set_option "DM" "lightdm" set_option "DM" "lightdm"
break break
;; ;;
6) 6)
set_option "DE" 0 set_option "DE" 0
set_option "DM" 0 set_option "DM" 0
break break
;; ;;
7) 7)
set_option "DE" 0 set_option "DE" 0
set_option "WM" "awesome" set_option "WM" "awesome"
break break
;; ;;
8) # openbox 8) # openbox
set_option "DE" 0 set_option "DE" 0
set_option "WM" "openbox" set_option "WM" "openbox"
break break
;; ;;
9) # i3 9) # i3
set_option "DE" 0 set_option "DE" 0
set_option "WM" "i3" set_option "WM" "i3"
break break
;; ;;
10) # i3-gaps 10) # i3-gaps
set_option "DE" 0 set_option "DE" 0
set_option "WM" "i3-gaps" set_option "WM" "i3-gaps"
break break
;; ;;
*) echo "Wrong option. Try again" *)
break echo "Wrong option. Try again"
;; break
;;
esac esac
else else
invalid_option invalid_option
@ -468,11 +472,11 @@ set_desktop() {
} }
# Make choice for installation # Make choice for installation
make_choice () { make_choice() {
title "Your system choice" title "Your system choice"
CHOICE=("Default Install" "Custom Install") CHOICE=("Default Install" "Custom Install")
PS3="$PROMPT" PS3="$PROMPT"
echo "Default installation comprises of the settings and the packages used" echo "Default installation comprises of the settings and the packages used"
echo "by Chris Titus himself. More specifically, it uses 3 partitions, GPT" echo "by Chris Titus himself. More specifically, it uses 3 partitions, GPT"
echo "btrfs as file systems, KDE Plasma as desktop environment and sddm as " echo "btrfs as file systems, KDE Plasma as desktop environment and sddm as "
@ -483,46 +487,47 @@ make_choice () {
select OPT in "${CHOICE[@]}"; do select OPT in "${CHOICE[@]}"; do
if elements_present "$OPT" "${CHOICE[@]}"; then if elements_present "$OPT" "${CHOICE[@]}"; then
case "$REPLY" in case "$REPLY" in
1) 1)
clear clear
logo logo
# title "Please select presetup \n\t\t\tsettings for your system" # title "Please select presetup \n\t\t\tsettings for your system"
user_info user_info
disk_selection disk_selection
clear clear
set_locale set_locale
clear clear
set_timezone set_timezone
set_keymap set_keymap
ssd_drive ssd_drive
set_btrfs set_btrfs
set_option "FS" "btrfs" set_option "FS" "btrfs"
set_option "DE" "plasma" set_option "DE" "plasma"
set_option "DM" "sddm" set_option "DM" "sddm"
set_option "LAYOUT" 1 set_option "LAYOUT" 1
break break
;; ;;
2) 2)
clear clear
logo logo
user_info user_info
disk_selection disk_selection
clear clear
set_locale set_locale
clear clear
set_timezone set_timezone
set_keymap set_keymap
ssd_drive ssd_drive
# Advance options # Advance options
set_partion_layout set_partion_layout
set_filesystem set_filesystem
set_desktop set_desktop
break break
;; ;;
*) echo "Wrong option. Try again" *)
break echo "Wrong option. Try again"
;; break
;;
esac esac
else else
invalid_option invalid_option
@ -534,4 +539,4 @@ background_check
# write_to_config # write_to_config
clear clear
logo logo
make_choice make_choice