From cfdf8a7686ef1bcab31134d521916761b1ecbfeb Mon Sep 17 00:00:00 2001 From: mfgbhatti Date: Sat, 4 Dec 2021 19:09:05 +0000 Subject: [PATCH 1/3] added more control on setup.conf and changed variables, addressed issue #109, #93, #99 added more control on setup.conf and changed variables, addressed issue #109, #93, #99 --- startup.sh | 62 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/startup.sh b/startup.sh index bc5f0c9..5c4dba3 100644 --- a/startup.sh +++ b/startup.sh @@ -1,5 +1,21 @@ #!/usr/bin/env bash -# This script will ask users about their prefrences like disk, file system, +# This script will ask users about their prefrences +# like disk, file system, timezone, keyboard layout, +# user name, password, etc. + +# set up a config file +CONFIG_FILE=setup.conf +if [ ! -f $CONFIG_FILE ]; then # check if file exists + touch -f $CONFIG_FILE # create file if not exists +fi + +# set options in setup.conf +set_option() { + if grep -Eq "^${1}.*" $CONFIG_FILE; then # check if option exists + sed -i -e "/^${1}.*/d" $CONFIG_FILE # delete option if exists + fi + echo "${1}=${2}" >>$CONFIG_FILE # add option +} logo () { # This will be shown on every set as user is progressing echo -ne " @@ -27,13 +43,13 @@ echo -ne " " read FS case $FS in -1) echo "FS=btrfs" >> setup.conf;; -2) echo "FS=ext4" >> setup.conf;; +1) set_option FS btrfs;; +2) set_option FS ext4;; 3) echo -ne "Please enter your luks password: " -read luks_password -echo "luks_password=$luks_password" >> setup.conf -echo "FS=luks" >> setup.conf;; +read -s luks_password # read password without echo +set_option luks_password $luks_password +set_option FS luks;; 0) exit ;; *) echo "Wrong option please select again"; filesystem;; esac @@ -41,16 +57,16 @@ esac timezone () { # Added this from arch wiki https://wiki.archlinux.org/title/System_time time_zone="$(curl --fail https://ipapi.co/timezone)" -echo -ne "System detected your timezone to be '$time_zone'" +echo -ne "System detected your timezone to be '$time_zone' \n" echo -ne "Is this correct? yes/no:" read answer case $answer in y|Y|yes|Yes|YES) - echo "timezone=$time_zone" >> setup.conf;; + set_option TIMEZONE $time_zone;; n|N|no|NO|No) echo "Please enter your desired timezone e.g. Europe/London :" read new_timezone - echo "timezone=$new_timezone" >> setup.conf;; + set_option TIMEZONE $new_timezone;; *) echo "Wrong option. Try again";timezone;; esac } @@ -88,10 +104,13 @@ Please select key board layout from this list " read -p "Your key boards layout:" keymap -echo "keymap=$keymap" >> setup.conf +set_option KEYMAP $keymap } + +# selection for disk type diskpart () { -lsblk +# show disks present on system +lsblk -n --output TYPE,KNAME | awk '$1=="disk"{print NR,"/dev/"$2}' # show disks with /dev/ prefix echo -ne " ------------------------------------------------------------------------ THIS WILL FORMAT AND DELETE ALL DATA ON THE DISK @@ -99,25 +118,22 @@ echo -ne " after formating your disk there is no way to get data back ------------------------------------------------------------------------ -Please enter disk to work on: (example /dev/sda): +Please enter full path to disk: (example /dev/sda): " read option -echo "DISK=$option" >> setup.conf +set_option DISK $option } userinfo () { -echo -ne "Please enter username: " -read username -echo "username=$username" >> setup.conf -echo -ne "Please enter your password: " -read password -echo "password=$password" >> setup.conf -echo -ne "Please enter your hostname: " -read hostname -echo "hostname=$hostname" >> setup.conf +read -p "Please enter your username: " username +set_option USERNAME ${username,,} # convert to lower case as in issue #109 +echo -ne "Please enter your password: \n" +read -s password # read password without echo +set_option PASSWORD $password +read -rep "Please enter your hostname: " hostname +set_option HOSTNAME $hostname } # More features in future # language (){} -rm -rf setup.conf &>/dev/null userinfo clear logo From 661f42313f184bb48c525f68d8d01d5d33f48266 Mon Sep 17 00:00:00 2001 From: mfgbhatti Date: Sat, 4 Dec 2021 19:35:44 +0000 Subject: [PATCH 2/3] changed variable type to block --- 1-setup.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-setup.sh b/1-setup.sh index 1633cda..4cb8822 100755 --- a/1-setup.sh +++ b/1-setup.sh @@ -48,12 +48,12 @@ echo -ne " " sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen locale-gen -timedatectl --no-ask-password set-timezone ${timezone} +timedatectl --no-ask-password set-timezone ${TIMEZONE} timedatectl --no-ask-password set-ntp 1 localectl --no-ask-password set-locale LANG="en_US.UTF-8" LC_TIME="en_US.UTF-8" # Set keymaps -localectl --no-ask-password set-keymap ${keymap} +localectl --no-ask-password set-keymap ${KEYMAP} # Add sudo no password rights sed -i 's/^# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/' /etc/sudoers @@ -109,13 +109,13 @@ echo -ne " ------------------------------------------------------------------------- " if [ $(whoami) = "root" ]; then - useradd -m -G wheel,libvirt -s /bin/bash $username + useradd -m -G wheel,libvirt -s /bin/bash $USERNAME # use chpasswd to enter $username:$password - echo "$username:$password" | chpasswd - cp -R /root/$SCRIPTHOME /home/$username/ - chown -R $username: /home/$username/$SCRIPTHOME + echo "$USERNAME:$PASSWORD" | chpasswd + cp -R /root/$SCRIPTHOME /home/$USERNAME/ + chown -R $USERNAME: /home/$USERNAME/$SCRIPTHOME # enter $hostname to /etc/hostname - echo $hostname > /etc/hostname + echo $HOSTNAME > /etc/hostname else echo "You are already a user proceed with aur installs" fi From 89550db1a43f47359e9f21fabf091414e3fc688d Mon Sep 17 00:00:00 2001 From: mfgbhatti Date: Sat, 4 Dec 2021 20:29:47 +0000 Subject: [PATCH 3/3] logic to connect wifi logic to connect wifi --- startup.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/startup.sh b/startup.sh index 5c4dba3..ea94469 100644 --- a/startup.sh +++ b/startup.sh @@ -134,6 +134,38 @@ set_option HOSTNAME $hostname } # More features in future # language (){} +network (){ +echo -ne " +Make sure your wifi device is active from the bios settings. +You can also use rfkill to device listing. This script +support only wifi connections. +" +iwctl device list # list devices present +read -p "Select interface for connecting: " WLAN +iwctl station $WLAN scan +sleep 1 +echo "Getting network." +sleep 1 +echo "Getting network.." +sleep 1 +echo "Getting network..." +iwctl station $WLAN get-networks +read -p "Enter SSID to connect: " SSID +echo "Enter network passphrase: \n" +read -s PASS +iwctl --passphrase '$PASS' station '$WLAN' connect '$SSID' +echo "Checking connection" + +if ping -c 1 archlinux.org &>/dev/null; then + echo "Hurray!! You are connected." +else + echo "There is something this script cannot deal with!" +fi +} +# Starting functions +network +clear +logo userinfo clear logo