more functions
This commit is contained in:
parent
2f4adfe2d9
commit
62b8798b5a
155
startup.sh
155
startup.sh
|
|
@ -1,34 +1,34 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# This script will ask users about their prefrences
|
# This script will ask users about their prefrences
|
||||||
# like disk, file system, timezone, keyboard layout,
|
# like disk, file system, timezone, keyboard layout,
|
||||||
# user name, password, etc.
|
# user name, password, etc.
|
||||||
# shellcheck disable=SC2207
|
# shellcheck disable=SC2207
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
# check if file exists
|
# Check if file exists
|
||||||
if [ ! -f "$CONFIG_FILE" ]; then
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
# create file if not exists
|
# Create file if not exists
|
||||||
touch -f "$CONFIG_FILE"
|
touch -f "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set options in setup.conf
|
# Set options in setup.conf
|
||||||
set_option() {
|
set_option() {
|
||||||
# check if option exists
|
# Check if option exists
|
||||||
if grep -Eq "^${1}.*" "$CONFIG_FILE"; then
|
if grep -Eq "^${1}.*" "$CONFIG_FILE"; then
|
||||||
# delete option if exists
|
# delete option if exists
|
||||||
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!"
|
||||||
|
|
@ -36,7 +36,7 @@ check_root() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if distro is arch
|
# Check if distro is arch
|
||||||
check_arch() {
|
check_arch() {
|
||||||
if [[ ! -e /etc/arch-release ]]; then
|
if [[ ! -e /etc/arch-release ]]; then
|
||||||
echo -ne "ERROR! This script has to be run under Arch Linux!"
|
echo -ne "ERROR! This script has to be run under Arch Linux!"
|
||||||
|
|
@ -44,36 +44,50 @@ check_arch() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# check for internet connection
|
# Check for internet connection
|
||||||
connection_test() {
|
connection_test() {
|
||||||
ping -q -w 1 -c 1 "$(ip r | grep default | awk 'NR==1 {print $3}')" &>/dev/null && return 1 || return 0
|
ping -q -w 1 -c 1 "$(ip r | grep default | awk 'NR==1 {print $3}')" &>/dev/null && return 1 || return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check for UEFI
|
||||||
|
efi_check () {
|
||||||
|
if [[ -d "/sys/firmware/efi/" ]]; then
|
||||||
|
if (mount | grep /sys/firmware/efi/efivars); then
|
||||||
|
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
|
||||||
|
fi
|
||||||
|
# UEFI detected
|
||||||
|
set_option "UEFI" 1
|
||||||
|
else
|
||||||
|
# No UEFI detected
|
||||||
|
set_option "UEFI" 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Backround checks
|
# Backround checks
|
||||||
background () {
|
background () {
|
||||||
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
|
||||||
else
|
else
|
||||||
check_root
|
check_root
|
||||||
check_arch
|
check_arch
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if an element exists
|
||||||
elements_present() {
|
elements_present() {
|
||||||
# check if an element exists
|
|
||||||
for e in "${@:2}"; do [[ "$e" == "$1" ]] && break; done
|
for e in "${@:2}"; do [[ "$e" == "$1" ]] && break; done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Invalid option message
|
||||||
invalid_option() {
|
invalid_option() {
|
||||||
# invalid option message
|
|
||||||
echo -ne "Please select a valid option: \n"
|
echo -ne "Please select a valid option: \n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Password helper function
|
||||||
set_password() {
|
set_password() {
|
||||||
# password helper function
|
# Read password without echoing (-s)
|
||||||
# read password without echoing (-s)
|
read -rs -p "Please enter password: " PASSWORD1
|
||||||
read -rs -p "Please enter password: " PASSWORD1
|
|
||||||
echo -ne "\n"
|
echo -ne "\n"
|
||||||
read -rs -p "Please re-enter password: " PASSWORD2
|
read -rs -p "Please re-enter password: " PASSWORD2
|
||||||
echo -ne "\n"
|
echo -ne "\n"
|
||||||
|
|
@ -85,7 +99,7 @@ set_password() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# make a title
|
# Make a title
|
||||||
title () {
|
title () {
|
||||||
echo -ne "\n"
|
echo -ne "\n"
|
||||||
echo -ne "------------------------------------------------------------------------\n"
|
echo -ne "------------------------------------------------------------------------\n"
|
||||||
|
|
@ -93,11 +107,34 @@ title () {
|
||||||
echo -ne "------------------------------------------------------------------------\n"
|
echo -ne "------------------------------------------------------------------------\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ask user for option
|
# Write shared functions to to setup.conf
|
||||||
|
write_to_config() {
|
||||||
|
cat << EOF >> "$CONFIG_FILE"
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
title () {
|
||||||
|
echo -ne "\n"
|
||||||
|
echo -ne "------------------------------------------------------------------------\n"
|
||||||
|
echo -ne "\t\t\t$1\n"
|
||||||
|
echo -ne "------------------------------------------------------------------------\n"
|
||||||
|
}
|
||||||
|
install_pkg () {
|
||||||
|
pacman -S --noconfirm --needed "$@"
|
||||||
|
}
|
||||||
|
refresh_pacman() {
|
||||||
|
pacman -Syy
|
||||||
|
}
|
||||||
|
# Setup for logging
|
||||||
|
LOG="${SCRIPT_DIR}/main.log"
|
||||||
|
[[ -f $LOG ]] && rm -f "$LOG"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Ask user for option
|
||||||
PROMPT="Please enter your option: "
|
PROMPT="Please enter your option: "
|
||||||
|
|
||||||
logo () {
|
|
||||||
# This will be shown on every set as user is progressing
|
# This will be shown on every set as user is progressing
|
||||||
|
logo () {
|
||||||
echo -ne "
|
echo -ne "
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -111,8 +148,8 @@ echo -ne "
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set partioning layouts
|
||||||
setpartionlayout() {
|
setpartionlayout() {
|
||||||
# Set partioning layouts
|
|
||||||
title "Setup Partioning Layout"
|
title "Setup Partioning Layout"
|
||||||
LAYOUTS=("Default" "LVM" "LVM+LUKS" "Maintain Current")
|
LAYOUTS=("Default" "LVM" "LVM+LUKS" "Maintain Current")
|
||||||
PS3="$PROMPT"
|
PS3="$PROMPT"
|
||||||
|
|
@ -153,16 +190,15 @@ setpartionlayout() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This function will handle file systems.
|
||||||
filesystem () {
|
filesystem () {
|
||||||
# This function will handle file systems. At this movement we are handling only
|
|
||||||
# btrfs and ext4. Others will be added in future.
|
|
||||||
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
|
||||||
# used -a to get more than one argument
|
# Used -a to get more than one argument
|
||||||
echo -ne "Please enter your btrfs subvolumes separated by space\n"
|
echo -ne "Please enter your btrfs subvolumes separated by space\n"
|
||||||
echo -ne "usualy they start with @ for root or @home, @temp etc.\n"
|
echo -ne "usualy they start with @ for root or @home, @temp etc.\n"
|
||||||
echo -ne "Defaults are @, @home, @var, @tmp, @.snapshots \n"
|
echo -ne "Defaults are @, @home, @var, @tmp, @.snapshots \n"
|
||||||
|
|
@ -177,7 +213,7 @@ filesystem () {
|
||||||
# push values to array
|
# push values to array
|
||||||
NAMES+=("$i")
|
NAMES+=("$i")
|
||||||
done
|
done
|
||||||
# set to config file
|
# Set to config file
|
||||||
set_option "SUBVOLUMES" "(${NAMES[*]})"
|
set_option "SUBVOLUMES" "(${NAMES[*]})"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
@ -191,8 +227,8 @@ filesystem () {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Added this from arch wiki https://wiki.archlinux.org/title/System_time
|
||||||
timezone () {
|
timezone () {
|
||||||
# Added this from arch wiki https://wiki.archlinux.org/title/System_time
|
|
||||||
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))
|
||||||
|
|
@ -233,8 +269,8 @@ timezone () {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# These are default key maps as presented in official arch repo archinstall
|
||||||
keymap () {
|
keymap () {
|
||||||
# These are default key maps as presented in official arch repo archinstall
|
|
||||||
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"
|
||||||
|
|
@ -249,8 +285,8 @@ keymap () {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Confirm if ssd is present
|
||||||
drivessd () {
|
drivessd () {
|
||||||
# confirm if ssd is present
|
|
||||||
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
|
||||||
|
|
@ -266,8 +302,8 @@ drivessd () {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Selection for disk type
|
||||||
diskSELECTION () {
|
diskSELECTION () {
|
||||||
# Selection for disk type
|
|
||||||
# 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
|
||||||
|
|
@ -288,14 +324,14 @@ diskSELECTION () {
|
||||||
userinfo () {
|
userinfo () {
|
||||||
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
|
||||||
set_password "PASSWORD"
|
set_password "PASSWORD"
|
||||||
read -r -p "Please enter your hostname: " HOSTNAME
|
read -r -p "Please enter your hostname: " HOSTNAME
|
||||||
set_option "HOSTNAME" "$HOSTNAME"
|
set_option "HOSTNAME" "$HOSTNAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set locale
|
||||||
setlocale (){
|
setlocale (){
|
||||||
# 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"
|
||||||
|
|
@ -310,6 +346,7 @@ setlocale (){
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Disktop selection
|
||||||
setdisktop() {
|
setdisktop() {
|
||||||
title "Select either Disktop Environment or Window Manager"
|
title "Select either Disktop Environment or Window Manager"
|
||||||
SELECTION=("KDE" "Gnome" "XFCE" "Mate" "LXQT" "Minimal" "Awesome" "OpenBox" "i3" "i3-Gaps")
|
SELECTION=("KDE" "Gnome" "XFCE" "Mate" "LXQT" "Minimal" "Awesome" "OpenBox" "i3" "i3-Gaps")
|
||||||
|
|
@ -317,13 +354,13 @@ setdisktop() {
|
||||||
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
|
||||||
|
|
@ -377,11 +414,11 @@ setdisktop() {
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Make choice for installation
|
||||||
makechoice () {
|
makechoice () {
|
||||||
# make choice for installation
|
|
||||||
title "Make your choice"
|
title "Make your choice"
|
||||||
CHOICE=("Default Install" "Custom Install")
|
CHOICE=("Default Install" "Custom Install")
|
||||||
PS3="$PROMPT"
|
PS3="$PROMPT"
|
||||||
|
|
@ -409,26 +446,26 @@ makechoice () {
|
||||||
background
|
background
|
||||||
logo
|
logo
|
||||||
makechoice
|
makechoice
|
||||||
# setdisktop
|
# Setdisktop
|
||||||
|
|
||||||
# check_root
|
# Check_root
|
||||||
# Starting functions
|
# Starting functions
|
||||||
# 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"
|
||||||
# userinfo
|
# Userinfo
|
||||||
# setpartionlayout
|
# Setpartionlayout
|
||||||
# filesystem
|
# Filesystem
|
||||||
# clear
|
# Clear
|
||||||
# logo
|
# Logo
|
||||||
# diskselection
|
# Diskselection
|
||||||
# drivessd
|
# Drivessd
|
||||||
# clear
|
# Clear
|
||||||
# logo
|
# Logo
|
||||||
# timezone
|
# Timezone
|
||||||
# clear
|
# Clear
|
||||||
# logo
|
# Logo
|
||||||
# keymap
|
# Keymap
|
||||||
# clear
|
# Clear
|
||||||
# logo
|
# Logo
|
||||||
# setlocale
|
# Setlocale
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue