1
0
Fork 0

init commit

This commit is contained in:
Pratham Patel 2022-11-20 16:57:35 +05:30
commit bf23fa1e84
5 changed files with 590 additions and 0 deletions

235
install-archlinux.sh Executable file
View File

@ -0,0 +1,235 @@
#!/usr/bin/env bash
#set -x
################################################################################
# PRE-INSTALLATION
################################################################################
# check for internet connectivity
ping -c 1 google.com >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "No internet access :("
exit 1
fi
# check if the user is root
if [[ $EUID -ne 0 ]]; then
echo "This script needs to be run as the root user :("
exit 1
fi
# detect if Arch Linux booted into Legacy BIOS or UEFI
if [[ ! "$(ls -A /sys/firmware/efi/efivars)" ]]; then
echo "This script was tailored for a system with UEFI."
echo "Please modify this script manually :("
exit 1
fi
################################################################################
# SELECT THE FASTEST "HTTPS" MIRRORS
################################################################################
pacman -Sy --noconfirm reflector
MIRRORLIST_FILE="/etc/pacman.d/mirrorlist"
# check if reflector is already running
pgrep reflector >/dev/null
if [[ $? -eq 0 ]]; then
IS_REFLECTOR_RUNNING=y
else
IS_REFLECTOR_RUNNING=n
fi
# remove $MIRRORLIST_FILE if file modification time is more than 10 days
if [[ ! $(find "$MIRRORLIST_FILE" -mtime +10) && $IS_REFLECTOR_RUNNING == "n" ]]; then
rm -f "$MIRRORLIST_FILE"
fi
# pacman config
sed -i "s/#ParallelDownloads = 5/ParallelDownloads = 10/" /etc/pacman.conf || echo "ParallelDownloads = 10" | tee -a /etc/pacman.conf
# start finding the best mirrors in the background
if [[ ! -f "$MIRRORLIST_FILE" && $IS_REFLECTOR_RUNNING == "n" ]]; then
reflector \
--connection-timeout 2 \
--latest 100 \
--sort rate \
--fastest 10 \
--protocol https \
--save /etc/pacman.d/mirrorlist >/dev/null 2>&1 &
fi
################################################################################
# SET THINGS UP FOR INSTALLATION
################################################################################
# set some global variables
FONT_BOLD=$(tput bold)
FONT_NORM=$(tput sgr0)
YES_NO_OPTION="$FONT_BOLD(y/n)$FONT_NORM"
# update system clock
timedatectl set-ntp true
################################################################################
# CHOOSE A DRIVE ON WHICH ARCH LINUX WILL BE INSTALLED
################################################################################
# choose the drive to install Arch Linux on
OS_DRIVE=empty
CORRECTLY_CHOSEN=n
VM_SYS_NAME=$(dmidecode -s system-manufacturer)
if [[ $(grep 'AuthenticAMD' /proc/cpuinfo) ]]; then
CPU_VENDOR_NAME="amd"
elif [[ $(grep 'GenuineIntel' /proc/cpuinfo) ]]; then
CPU_VENDOR_NAME="intel"
else
CPU_VENDOR_NAME="nanyabusiness"
fi
while [[ $CORRECTLY_CHOSEN == "n" || $CORRECTLY_CHOSEN == "N" ]]; do
tput -x clear
fdisk -l
echo -e "\n\nPlease input the full path of the storage device onto which Arch Linux should be installed: (eg: $FONT_BOLD/dev/sda$FONT_NORM)"
read OS_DRIVE
tput -x clear
fdisk -l "$OS_DRIVE"
echo -e "\n\nIs this the drive you want to install Arch Linux on? $YES_NO_OPTION"
read CORRECTLY_CHOSEN
done
################################################################################
# FORMAT THE DRIVE ON WHICH ARCH LINUX WILL BE INSTALLED
################################################################################
# partition the drive
FORMAT_YES=no
SEPARATE_HOME_ROOT=no
TOTAL_DEV_SIZE_IN_BYTES=$(blockdev --getsize64 ${OS_DRIVE})
UEFI_PART_SIZE=513MiB
ROOT_PART_SIZE=10GiB
tput -x clear
echo "Do you want a separate \`home\` and \`root\` partition? $YES_NO_OPTION"
read SEPARATE_HOME_ROOT
if [[ $SEPARATE_HOME_ROOT == "Y" || $SEPARATE_HOME_ROOT == "y" ]]; then
tput -x clear
echo "You chose that you want separate home and root partitions."
echo "You will$FONT_BOLD not$FONT_NORM be asked for the Home partition's size. It will occupy the remaining space.\n"
echo "Please enter the size of root partition in GiB (without the unit)."
echo -e "10% or 12GB (whichever is greater) of the total drive space is usually a good idea.\n"
read ROOT_PART_SIZE
ROOT_PART_SIZE="$ROOT_PART_SIZE""GiB"
fi
################################################################################
# CREATE PARTITIONS
################################################################################
# create the disk partitions
tput -x clear
echo -e "Your drive will be split into 3 partitions:\n\n"
echo -e " mount point | filesystem | size "
echo -e "-------------|------------|----------"
echo -e " /boot/ | EFI | 512Mib "
echo -e " / | ext4 | $ROOT_PART_SIZE"
echo -e " /home | ext4 | <remaining space>"
echo -e "\n\nDoes the above look good to you? $YES_NO_OPTION\n"
read FORMAT_YES
if [[ $FORMAT_YES == "y" || $FORMAT_YES == "Y" ]]; then
parted -s "$OS_DRIVE" mklabel gpt
parted -s "$OS_DRIVE" mkpart primary fat32 1 513MiB
parted -s "$OS_DRIVE" mkpart logical ext4 514MiB $ROOT_PART_SIZE
parted -s "$OS_DRIVE" mkpart logical ext4 $ROOT_PART_SIZE 100%
parted -s "$OS_DRIVE" set 1 boot on
else
exit 1
fi
################################################################################
# MOUNT PARTITIONS
################################################################################
# check what kind of storage device $OS_DRIVE is
if [[ "$OS_DRIVE" =~ "sd" || "$OS_DRIVE" =~ "vd" ]]; then
UEFI_PARTITION="$OS_DRIVE""1"
ROOT_PARTITION="$OS_DRIVE""2"
HOME_PARTITION="$OS_DRIVE""3"
elif [[ "$OS_DRIVE" =~ "nvme" ]]; then
UEFI_PARTITION="$OS_DRIVE""p1"
ROOT_PARTITION="$OS_DRIVE""p2"
HOME_PARTITION="$OS_DRIVE""p3"
fi
# format partitions
mkfs.fat -F32 "$UEFI_PARTITION"
mkfs.ext4 -F "$HOME_PARTITION"
mkfs.ext4 -F "$ROOT_PARTITION"
# mount the partitions
mount ${ROOT_PARTITION} /mnt
mount --mkdir ${UEFI_PARTITION} /mnt/boot
mount --mkdir ${HOME_PARTITION} /mnt/home
################################################################################
# INITIATE PACKAGE INSTALLATION
################################################################################
# check and copy mirrorlist
while [[ ! -f "$MIRRORLIST_FILE" ]]; do
tput -x clear
echo "$(date +'%Y/%m/%d %H:%M:%S') => Waiting for the mirrorlist to be generated. Please be patient."
sleep 10
done
mkdir -p /mnt/etc/pacman.d/
cp ${MIRRORLIST_FILE} /mnt"$MIRRORLIST_FILE"
# update pacman db
pacman --sync --refresh --refresh
# install packages
bash scripts/install-packages.sh "$CPU_VENDOR_NAME"
# generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# chroot setup
mkdir -p /mnt/chroot-scripts
cp scripts/chroot-setup.sh /mnt/chroot-scripts/
arch-chroot /mnt bash /chroot-scripts/chroot-setup.sh "$CPU_VENDOR_NAME" "$ROOT_PARTITION"
if [[ $? -ne 0 ]]; then
exit 1
fi
# copy the setup script that can only be done after pratham logs in
cp scripts/pratham-setup.sh /mnt/home/pratham/pratham-setup.sh
arch-chroot /mnt chmod +x /home/pratham/pratham-setup.sh
arch-chroot /mnt chown -v pratham:pratham /home/pratham/pratham-setup.sh
################################################################################
# POST-INSTALL PROCEDURE
################################################################################
# unmount filesystems
umount -R /mnt

9
reflector Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
reflector \
--connection-timeout 2 \
--latest 100 \
--sort rate \
--fastest 10 \
--protocol https \
--save /etc/pacman.d/mirrorlist

119
scripts/chroot-setup.sh Normal file
View File

@ -0,0 +1,119 @@
#!/usr/bin/env bash
# $1: CPU Vendor (AMD/Intel)
# $2: Device that is mounted at "$ESP_PATH"
################################################################################
ROOT_CRONTAB="# remove cache every 2 hours and update local db
0 */2 * * * paccache -r >/dev/null 2>&1
0 * * * * pacman --sync --refresh >/dev/null 2>&1
# update the on-disk database every 6 hours
0 */6 * * * updatedb >/dev/null 2>&1
"
################################################################################
tput -x clear
################################################################################
# BASIC CHROOT SETUP
################################################################################
# exit early if mirrorlist does not exist
if [[ ! -f "/etc/pacman.d/mirrorlist" ]]; then
echo "A mirrorlist does not exist :("
exit 1
fi
# exit early if $1 is an unknown vendor
if [[ "$1" == "nanyabusiness" ]]; then
echo "CPU Vendor is not AMD nor Intel. This will interfere with generating \"\$ESP_PATH\"/loader/entries/arch.conf"
exit 1
fi
# set timezone
ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
hwclock --systohc
# generate locale
echo "en_IN UTF-8" > /etc/locale.gen
locale-gen
# set the machine hostname
echo "vasudev" > /etc/hostname
# create a new initramfs just to be safe
mkinitcpio -P
echo "initramfs successfully created"
################################################################################
# BASIC CHROOT SETUP
################################################################################
# pacman config
sed -i "s/#ParallelDownloads = 5/ParallelDownloads = 10/" /etc/pacman.conf || echo "ParallelDownloads = 10" | tee -a /etc/pacman.conf
# update pacman db
pacman --sync --refresh --refresh --sysupgrade
################################################################################
# USER SETUP
################################################################################
# setup the user pratham
useradd -m -G adm,ftp,games,http,log,rfkill,sys,systemd-journal,uucp,wheel -s /bin/zsh pratham
usermod --password $(echo pratham | openssl passwd -1 -stdin) pratham
passwd -e pratham
# setup the root user
usermod --password $(echo root | openssl passwd -1 -stdin) root
# setup doas for pratham
echo "permit persist keepenv pratham" | tee -a /etc/doas.conf
# setup root user's cron jobs
echo "${ROOT_CRONTAB}" | crontab -
################################################################################
# BOOT MANAGER
################################################################################
ESP_PATH="/boot"
# install a boot manager
bootctl --esp-path="$ESP_PATH" --path="$ESP_PATH" install
# configure systemd-boot
mkdir -p "$ESP_PATH"/loader/entries
cat <<EOF > "$ESP_PATH"/loader/loader.conf
default arch.conf
timeout 0
console-mode auto
editor no
auto-firmware no
EOF
cat <<EOF > "$ESP_PATH"/loader/entries/arch.conf
title Arch Linux btw
linux /vmlinuz-linux
initrd /$1-ucode.img
initrd /initramfs-linux.img
options root=UUID=$(blkid $2 -s UUID -o value) rw systemd.show_status=false mem_sleep_default=deep splash
EOF
# enable services
systemctl enable systemd-boot-update.service
systemctl enable sddm.service
systemctl enable NetworkManager.service
systemctl enable sshd.service
# update bootloader
bootctl update
# check bootloader config
bootctl list
read wait_until_input

View File

@ -0,0 +1,96 @@
#!/usr/bin/env bash
################################################################################
# install packages
################################################################################
# update pacman db
pacman --sync --refresh --refresh
# absolutely necessary for _MY_ experience
PKGS_TO_INSTALL=(base bash cron curl dhcpcd dnsutils doas efibootmgr findutils grub iputils less libdrm linux linux-firmware lsb-release lsof man man-db man-pages nano neovim openssh openssl os-prober pacman-contrib reflector rsync tmux wireguard-tools zsh zsh-completions zsh-syntax-highlighting)
# power management
PKGS_TO_INSTALL+=(acpi_call iasl)
# add-on
PKGS_TO_INSTALL+=(flatpak ffmpeg light)
# monitoring
PKGS_TO_INSTALL+=(btop htop iotop iperf iperf3 nload)
# containersation stuff
#PKGS_TO_INSTALL+=(aardvark-dns bridge-utils fuse-overlayfs podman podman-compose podman-dnsname slirp4netns)
# download clients
PKGS_TO_INSTALL+=(aria2 wget yt-dlp)
# android-stuff
PKGS_TO_INSTALL+=(android-tools)
# *utils-rust
PKGS_TO_INSTALL+=(bat fd ripgrep tre)
# system utilities
PKGS_TO_INSTALL+=(hd-idle hdparm tldr smartmontools wol)
# compression
PKGS_TO_INSTALL+=(tar unrar unzip xz zip)
# software devel
# kernel devel
PKGS_TO_INSTALL+=(base-devel bc cpio gcc git graphviz imagemagick inetutils kmod libelf linux-headers pahole perl python-sphinx python-sphinx_rtd_theme tar texlive-latexextra xmlto xz)
# virtualisation
# network filesystems
PKGS_TO_INSTALL+=(avahi nfs-utils samba smbclient)
PKGS_TO_INSTALL+=(kdenetwork-filesharing)
#PKGS_TO_INSTALL+=(gvfs-smb
# zfs
# GPU
PKGS_TO_INSTALL+=(mesa qemu-hw-display-virtio-gpu qemu-hw-display-virtio-gpu-gl qemu-hw-display-virtio-gpu-pci qemu-hw-display-virtio-gpu-pci-gl qemu-hw-s390x-virtio-gpu-ccw)
#PKGS_TO_INSTALL+=(libva-mesa-driver mesa radeontop vulkan-radeon)
#PKGS_TO_INSTALL+=(intel-media-driver libva-intel-driver mesa vulkan-intel)
# Display Server (Wayland)
PKGS_TO_INSTALL+=(libdrm wayland)
# Window Manager (Wayland)
# Desktop Environment (Wayland)
PKGS_TO_INSTALL+=(kcalc kcharselect kdf kdialog ktimer print-manager plasma plasma-meta kde-system-meta plasma-wayland-session)
# GUI
PKGS_TO_INSTALL+=(alacritty firefox meld mpv slurp)
# Sound
PKGS_TO_INSTALL+=(pipewire pipewire-pulse)
#PKGS_TO_INSTALL+=(alsa-firmware alsa-lib alsa-utils gst-plugins-good gstreamer libao libcanberra-gstreamer libcanberra-pulse pulseaudio pulseaudio-alsa)
# ???
#PKGS_TO_INSTALL+=(exfatprogs netcfg otf-overpass)
# xorg
#PKGS_TO_INSTALL+=(libdrm libva-mesa-driver qemu-hw-display-virtio-gpu qemu-hw-display-virtio-gpu-gl qemu-hw-display-virtio-gpu-pci qemu-hw-display-virtio-gpu-pci-gl qemu-hw-s390x-virtio-gpu-ccw xf86-input-libinput xf86-input-synaptics xf86-input-wacom xf86-video-qxl xf86-video-vmware xorg xorg-apps xorg-fonts-alias xorg-fonts-encodings xorg-fonts-misc xorg-server xorg-xauth xorg-xinit xorg-xkbutils)
#PKGS_TO_INSTALL+=(intel-media-driver libva-intel-driver vulkan-intel)
#PKGS_TO_INSTALL+=(xf86-video-amdgpu radeontop vulkan-radeon)
# install x86 microcode
if [[ "$1" == "amd" ]]; then
PKGS_TO_INSTALL+=(amd-ucode)
elif [[ "$1" == "intel" ]]; then
PKGS_TO_INSTALL+=(intel-ucode)
fi
pacstrap -K /mnt "${PKGS_TO_INSTALL[@]}"

131
scripts/pratham-setup.sh Normal file
View File

@ -0,0 +1,131 @@
#!/usr/bin/env bash
################################################################################
# INITIAL SETUP
################################################################################
# set hostname
WHAT_IS_MY_HOSTNAME=$(cat /etc/hostname)
if [[ $WHAT_IS_MY_HOSTNAME != "vasudev" ]]; then
hostnamectl set-hostname vasudev
WHAT_IS_MY_HOSTNAME=whoopsie
fi
# set timezone
WHAT_IS_MY_TZ=$(readlink /etc/localtime)
if [[ ! $WHAT_IS_MY_TZ =~ "Asia/Kolkata" ]]; then
timedatectl set-timezone Asia/Kolkata
WHAT_IS_MY_TZ=whoopsie
fi
# reboot to bring hostname in effect
if [[ $WHAT_IS_MY_TZ == "whoopsie" || $WHAT_IS_MY_HOSTNAME == "whoopsie" ]]; then
systemctl reboot
fi
################################################################################
# SETUP DEV ENVIRONMENT
################################################################################
# rust-lang
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stable
rustup component add rust-src rust-analyzer
rustup component add rust-analysis
cargo install cargo-outdated cargo-tree
# neovim (vim-plug)
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
# create ssh keys
if [[ ! -d $HOME/.ssh ]]; then
mkdir $HOME/.ssh
chmod 700 $HOME/.ssh
fi
pushd $HOME/.ssh
ssh-keygen -t ed25519 -f bluefeds
ssh-keygen -t ed25519 -f flameboi
ssh-keygen -t ed25519 -f gitea
ssh-keygen -t ed25519 -f github
ssh-keygen -t ed25519 -f gitlab
ssh-keygen -t ed25519 -f sentinel
popd
# IP address for server is hidden behind cloudflare proxy
tput -x clear
cat <<EOF > $HOME/.ssh/config
Host git.thefossguy.com
Hostname ::?
User git
IdentityFile ~/.ssh/gitea
Port 22
EOF
echo "Populate Hostname (IP addr) for \"git.thefossguy.com\" in ~/.ssh/config"
bash
# get dotfiles
cat $HOME/.ssh/gitea.pub
echo -ne "\n\n\n\n"
pushd $HOME
git clone git@git.thefossguy.com:thefossguy/dotfiles-priv.git
git clone git@git.thefossguy.com:thefossguy/dotfiles.git
popd
rsync \
--verbose --recursive --size-only --human-readable \
--progress --stats \
--itemize-changes --checksum \
--exclude=".git" --exclude=".gitignore" --exclude="README.md" \
~/dotfiles/ ~/
rsync \
--verbose --recursive --size-only --human-readable \
--progress --stats \
--itemize-changes --checksum \
--exclude=".git" --exclude=".gitignore" \
~/dotfiles-priv/ ~/
# podman?
#grep net.ipv4.ping_group_range /etc/sysctl.conf || echo "net.ipv4.ping_group_range=0 $(grep pratham /etc/subuid | awk -F ":" '{print $2 + $3}')" | doas tee -a /etc/sysctl.conf
################################################################################
# AUR-RELATED
################################################################################
# install necessary packages for installing \`paru\`
doas pacman -S --needed base-devel
# build paru
mkdir /tmp/parutemp-PARU
pushd /temp/parutemp-PARU
git clone --depth 1 https://aur.archlinux.org/paru.git
makepkg -si
if [[ $? -ne 0 ]]; then
tput -x clear
echo "paru wasn't installed successfully :("
exit 1
fi
popd
# AUR pkgs
paru -S qomui noisetorch ssmtp
paru -S zfs-dkms
# wayland-WM
#paru -S hyperland
# intel
#paru -S libva-intel-driver-g45-h264 intel-hybrid-codec-driver
################################################################################
# WRAP UP
################################################################################
tput -x clear
echo "vim-plug for nvim has been installed, please fetch the plugins using the \'`:PlugInstall\` command"