You are on page 1of 7

# Install to what device?

get_install_device(){
clear
echo "Available installation media : " && echo
show_disks

echo && echo "Install to what device? (sda, nvme01, sbd, etc)"
read device
if$(efi_boot_mode); then
echo && echo "Formatting with EFI/GPT"
DISKTABLE='GPT'
else
echo && echo "Formatting with BIOS/MBR"
DISKTABLE='MBR'
fi

part_disk="$device"

}
#INSTALL ESSENTIAL PACKAGES
install_base(){
clear

#install lvm2 hook if we're using LVM


[[ $USE_LVM == 'TRUE' ]] && base_system+=( "lvm2" )
pacstrap /mnt "${base_system[@]}"
[[ -L /dev/mapper/arch_vg-ArchRoot ]] && lvm_hooks
echo && echo "Base System installed. Press any key to continue ..."; read empty
}

$ GENERATE FSTAB
gen_fstab(){
clear
echo "Generating fstab..."
genfstab -U /mnt >> /mnt/etc/fstab
sleep 3

# EDIT FSTAB IF NECCSSARY


clear
echo && echo "Here's the new /etc/fstab..."; cat /mnt/etc/fstab
echo && echo "Type any key to continue ..."; read empty
}

#TimeZone

set_tz(){
clear
echo && echo "setting timezone to $TIMEZONE..."
arch-chroot /mnt ln -sf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
arch-chroot /mnt hwclock --systohc --utc
arch-chroot /mnt date
echo && echo "Press any key to continue..."; read td_yn
#return 0

#Locale
set_locale(){
clear
echo && echo "setting locale to $LOCALE..."
sleep 3
arch-chroot /mnt sed -i "s/#$LOCALE/$LOCALE/g" /etc/locale.gen
arch-chroot /mnt locale-gen
sleep 3
echo "LANG=$LOCALE" > /mnt/etc/locale.conf
export LANG="$LOCALE"
sleep 3
cat /mnt/etc/locale.conf
echo && echo "Press any key to continue"; read loc_yn
#return 0

#HOSTNAME
set_hostname(){
clear
echo && echo "What is the hostname?"; read Trinetra
echo "$Trinetra" > /mnt/etc/hostname

cat > /mnt/etc/hosts <<HOSTS


127.0.0.1 localhost
::1 localhost
127.0.1.1 $Trinetra.localdomain Trinetra
HOSTS

echo && echo "etc/hostname and /etc/hosts files configured..."


cat /mnt/etc/hostname
cat /mnt/etc/hosts
echo && echo "Press any key to continue"; read etchosts_yn
#Return0
}

#SOME MORE ESSENTIAL NETWORK STUFF


install_essential(){
clear
echo && echo "Installing dhcpcd,ssd and NetworkManager services..."
echo
arch-chroot /mnt pacman -S "${base_essentials[@]}"
arch-chroot /mnt pacman -S "${network_essentials[@]}"

# ENABLE SERVICES
for service in "${my_services[@]}"; do
arch-chroot /mnt systemctl enable "$service"
done

echo && echo "Press any key to continue ..."; read empty
}
#ADD A User Acct
add_user_acct(){
clear
echo && echo "Adding sudo + user acct..."
sleep 2
arch-chroot /mnt pacman -S sudo bash-completion sshpass
arch-chroot /mnt sed -i 's/# %wheel/%wheel/g' /etc/sudoers
arch-chroot /mnt sed -i 's/wheel ALL=(ALL) NOPASSWD: ALL/# %wheel ALL=(ALL)
NOPASSWD: ALL/g' /etc/sudoers
echo && echo "Please provide a username: "; read sudo_user
echo && echo "Creating $sudo_user and adding $sudo_user to sudoers..."
arch-chroot /mnt useradd -m -G wheel "$sudo_user"
echo && echo "Password for $sudo_user?"
arch-chroot /mnt passwd "$sudo_user"
}
#This is if you have to restart the script after partitioning
set_variables(){
echo "Available block devices: "; lsblk
clear && echo "Installation device? (sda, nvme0n, sdb, etc)"; read inst_device
echo && echo "Install root to?(sda2?, nvme0np2?)"; read root_slice
echo && echo "Install swap to? (leave empty if no swap part)"; read swap_slice
echo && echo "Install EFI to? (leave empty if MBR disk)"; read efi_slice
echo && echo "Install HOME slice to?(leave empty if you don't want to seperate
home partition)"; read home_slice

if $(efi_boot_mode) ; then
DISKTABLE="GPT"
else
DISKTABLE="MBR"
fi
IN_DEVICE="/dev/$inst_device"
EFI_SLICE="/dev/$efi_slice"
SWAP_SLICE="/dev/$swap_slice"
ROOT_SLICE="/dev/$root_slice"
HOME_SLICE="/dev/$home_slice"
}
#INSTALL BOOTLOADER
install_grub(){
clear
echo "Installing grub..."
arch-chroot /mnt pacman -S grub os-prober

if $(efi_boot_mode); then
arch-chroot /mnt/pacman -S efibootmgr
# /boot/efi should be mounted
[[ ! -d /mnt/boot/efi ]] && echo "no /mnt/boot/efi directory!!!"
arch-chroot /mnt grub-install "$IN_DEVICE" --target=x86_64-efi --
bootloader-id=GRUB --efi-directory=/boot/efi
echo "efi grub bootloader installed ..."
else
arch-chroot /mnt grub-install "$IN_DEVICE"
echo "mbr bootloader installed..."
fi
echo "configuring /boot/grub/grub.cfg..."
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
echo "Press any key to continue..."; read empty
}

#Wifi (BCM4360) IF NECCESSARY

wl_wifi(){
clear && echo "Installing $wifi_drivers..."
arch-chroot /mnt pacman -S "${wifi_drivers[@]}"
[[ "$?" -eq 0 ]] && echo "Wifi drivers installed!"; sleep 3

#Install XORG and Desktop


install_desktop(){
#XORG AND DESKTOP
clear
echo "Installing Xorg and Desktop..."
#EXTRA Packages , FONTS , THEMES , CURSORS
arch-chroot /mnt pacman -S "${basic_x[@]}"
arch-chroot /mnt pacman -S "${basic_x1[@]}"
arch-chroot /mnt pacman -S "${basic_x2[@]}"
arch-chroot /mnt pacman -S "${basic_x3[@]}"
arch-chroot /mnt pacman -S "${devel_stuff[@]}"
arch-chroot /mnt pacman -S "${multimedia_stuff[@]}"
arch-chroot /mnt pacman -S "${printing_stuff[@]}"

#Driver for graphic card , desktop , display mgr


arch-chroot /mnt pacman -S "${display_mgr[@]}"
arch-chroot /mnt pacman -S "${graphics_driver[@]}"
#Insert your default desktop here
arch-chroot /mnt pacman -S "${kde_desktop[@]}"
arch-chroot /mnt systemctl enable "${display_mgr[@]}"
echo "Type any key to continue..."; read empty
}
install_extra_stuff(){
arch-chroot /mnt pacman -S "${all_extras[@]}"

#RESTART SERVICES SO LIGHTDM GETS ALL WM PICKS


for service in "${my_services[@]}"; do
arch-chroot /mnt systemctl enable "$Service"
done

echo "Type any key to continue..."; read empty


}

check_reflector(){
clear
echo "checking if reflector has finished updating mirrorlist yet..."
while true; do
pgrep -x reflector &>/dev/null || break
echo -n '.'
sleep 2
done
}
lvm_hooks(){
clear
echo "add lvm2 to mkinitcpio hooks HOOKS=( base udev ... block lvm2
filesystems)"
sleep 4
vim /mnt/etc/mkinitcpio.conf
arch-chroot /mnt/mkinitcpio -P
}
lv_create(){
USE_LVM='TRUE'
VOL_GROUP=arch_vg
LV_ROOT="ArchRoot"
LV_HOME="ArchHome"
LV_SWAP="ArchSwap"

#lsblk
show_disks
IN_DEVICE="/dev/$disk"
echo "What partition is your Physical Device for your volume Group?(sda2,
nvme0n1p2, sdb2, etc)"; read root_dev
ROOT_DEVICE="/dev/$root_dev"
echo "How big is your root partition or volume( 15G, 50G, 100G, etc)"; read
rootsize
ROOT_SIZE="/dev/$rootsize"
echo "How big is your swap partition or volume ?(2G, 4G, 8G, 16G, etc)"; read
swapsize
SWAP_SIZE="/dev/$swap_size"

if $(efi_boot_mode); then
echo "What Partition is your EFI device?(nvme0n1p1, sda1, etc)"; read
efi_dev
EFI_DEVICE="/dev/$efi_dev"
EFI_SIZE=512M
# Create the physical partitions

sgdisk -Z "$IN_DEVICE"
sgdisk -n::+"$EFI_SIZE" -t 1:ef00 -c 1:EFI "$IN_DEVICE"
sgdisk -n -t 2:8e00 -c 2:VOLGROUP "$IN_DEVICE"

# Format the EFI partition


mkfs.fat -F32 "$EFI_DEVICE"
else
echo "What partition is your BOOT device ?(nvme0n1p1,sda1, etc)"; read
boot_dev
BOOT_DEVICE="/dev/$boot_dev"
BOOT_SIZE=512M
cat > /tmp/sfdisk.cmd << EOF
$BOOT_DEVICE : start=2048, size=+BOOT_SIZE, type=83, bootable
$ROOT_DEVICE : type=83
EOF
#USING SFDISK BECAUSE WE'RE TALKING MBR DISKTABLE NOW...
sfdisk /dev/sda < /tmp/sfdisk.cmd
#format the boot partition
mkfs.ext4 "$BOOT_DEVICE"
fi
clear
# run cryptsetup on root device
[[ "$USE_CRYPT" == 'TRUE' ]] && crypt_setup "$ROOT_DEVICE"

# CREATE THE PHYSICAL VOLUMES


pvcreate "$ROOT_DEVICE"
# CREATE THE VOLUME GROUP
vgcreate "$VOL_GROUP" "$ROOT_DEVICE"
#YOU CAN EXTEND WITH VGEXTEND TO OTHER DEVICES TOO
lvcreate -L "$ROOT_SIZE" "$VOL_GROUP" -n "$LV_ROOT"
lvcreate -L "$SWAP_SIZE" "$VOL_GROUP" -n "$LV_SWAP"
lvcreate -l 100%FREE "$VOL_GROUP" -n "$LV_HOME"

#FORMAT SWAP
mkswap "/dev/$VOL_GROUP/$LV_SWAP
swapon "/dev/$VOL_GROUP/$LV_SWAP

modprobe dm_mod
vgchange -ay
mkfs.ext4 "/dev/$VOL_GROUP/$LV_ROOT"
mkfs.ext4 "/dev/$VOL_GROUP/$LV_HOME"
mount "/dev/$VOL_GROUP/$LV_ROOT" /mnt
mkdir /mnt/home
mount "/dev/$VOL_GROUP/$LV_HOME" /mnt/home
if $(efi_boot_mode); then
mkdir /mnt/boot && /mnt/boot/efi
mount "$EFI_DEVICE" /mnt/boot/efi
else
mkdir /mnt/boot
mount "$EFI_DEVICE" /mnt/boot
fi
lsblk
echo "LVs created and mounted. Press any key."; read empty;
startmenu
}

diskmenu(){
clear
check_tasks 2
while true ; do
echo -e "\n\n Prepare Installtion Disk(Choose one)"
echo -e " 1) Prepare Installation Disk with Normal Partitions"
echo -e " 2) Prepare Installation Disk with LVM"
echo -e " 3) Prepare Installation Disk Encryption and LVM"
echo -e " 4) Return to previous menu"
echo -e " \n\n"
echo -e "\n\n Your choice? "; read diskmenupick
case $diskmenupick in
1) get_install_device;;
2) lv_create;;
3) USE_CRYPT='TRUE'; lv_create;;
4) startmenu;;
*) echo "Please make a valid pick from menu";;
esac
done
}
########## Start Script ############
startmenu(){
check_reflector
while true ; do
clear
echo -e "\n\n Welcome to Trinetra! Jaideep's Archlinux Installer!"
echo -e "\n\n\n What to you want to do? \n\n"
echo -e "\n\n\n Check connection and date 2) Prepare Installition Disk"
echo -e "\n 3) Install Base System 4) New FSTAB and TZ/Locale"
echo -e "\n 5) Set new hostname 6) Set Root password"
echo-e "\n 7) Install more essentials 8) Add user+ sudo account"
echo -e "\n 9) Install Wifi Drivers 10)Install grub"
echo -e "\n 11) Install Xorg + Desktop 12) Install extra window mgrs
echo -e "\n 13)Repopulate variables 14)Check for pkg name changes
echo -e "\n 15)Exit Script "
echo -e "\n Tasks completed: ${completed_tasks[@]}"
echo -e "\n\n Your choice? "; read menupick

case $menupick in
1) check_connect; time_date; check_tasks 1;;
2) diskmenu;;
3) install_base; check_tasks 3;;
4) gen_fstab; set_tz; set_locale; check_tasks 4 ;;
5) set_hostname; check_tasks 5;;
6) echo "Setting ROOT password...";
arch-chroot /mnt passwd;
check_tasks 6
echo "Any key to continue..."; read continue;;
7) install_essential; check_tasks 7;;
8) add_user_acct; check_tasks 8;;
9) wl_wifi; check_tasks 9;;
10) install_grub; check_tasks 10;;
11) install_desktop; check_tasks 11;;
12) install_extra_stuff; check_tasks 12;;
13) set_variables ;;
14) validate_pkgs ;;
15) echo -e "\n Type 'Shutdown -h now' and then remove USB/DVD, then
reboot"
exit 0;
*) echo "Please make a valid pick from menu!";;
esac
done
}

startmenu

You might also like