diff --git a/README.md b/README.md index 4e5a884..62a63d1 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,19 @@

Arch Installer

-

Quick & Simple Arch Linux Installer

-## ✨ Features +## Features -- Partitions the drive with support of UEFI & BIOS -- Installs necessary packages (bluetooth, audio, firewall) -- Rices with [my dotfiles](https://github.com/GhoulBoii/dotfiles) +- Uses [archinstall](https://github.com/archlinux/archinstall) to provide a minimal arch install +- Provides post-install scripts to rice the system - Setup a working environment in less than **30 minutes** -## 🔧 Usage +## Usage + +1) + +- Input config.json +- Set mirror region +- Partition drives +- Set timezone - Grab the latest [Arch Linux ISO](https://archlinux.org/download/) - Flash it on a USB Drive using [Ventoy](https://github.com/ventoy/Ventoy) [**Recommended**] or [Balena Etcher](https://github.com/balena-io/etcher) @@ -21,11 +26,11 @@ cd arch-installer ./arch-installer.sh ``` -## 📜 License +## License This project is licensed under the GPL-3.0 License - see the [License file](LICENSE.md) for details. -## ❤️ Credits +## Credits - [Bugswriter](https://github.com/Bugswriter/arch-linux-magic) - [Chris Titus Tech](https://github.com/ChrisTitusTech/ArchTitus) diff --git a/arch-installer.sh b/arch-installer.sh index 4aa7fd7..53bb288 100755 --- a/arch-installer.sh +++ b/arch-installer.sh @@ -5,389 +5,81 @@ green=$(tput setaf 2) blue=$(tput setaf 6) normal=$(tput sgr0) -input_drive() { - local drive - lsblk >&2 - read -p "Enter drive (Ex. - /dev/sda): " drive - cfdisk $drive >&2 - echo "$drive" -} - -input_linux_part() { - local linux - lsblk >&2 - read -p "Enter the Linux Partition (Ex. - /dev/sda2): " linux - echo "$linux" -} - -input_efi_part() { - local efi - read -p "Enter EFI partition (Ex. - /dev/sda2): " efi - echo "$efi" -} - -input_host() { - local hostname - while true :; do - read -p "Enter the hostname: " hostname - if [[ "${hostname}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]]; then - break - fi - echo -e "${red}Incorrect Hostname!${normal}" >&2 - done - echo "$hostname" -} - -input_user() { - local username - while true :; do - read -p "Enter username: " username - if [[ "${username}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]]; then - break - fi - echo -e "${red}Incorrect Username!${normal}" >&2 - done - echo "$username" -} - -input_pass() { - local pass1 pass2 - while true :; do - read -sp "Enter password: " pass1 - echo "" >&2 - read -sp "Re-enter password: " pass2 - if [[ "${pass1}" = "${pass2}" ]]; then - break - fi - echo -e "\n${red}Passwords don't match.${normal}" >&2 - done - echo "$pass1" -} - -input_nvidia() { - local nvidia - echo -e "\nAmd and Intel Drivers will automatically work with the mesa package. The option below is only for Nvidia Graphics Card users." >&2 - read -p "Enter which graphics driver you use [Enter \"1\" for Nvidia or \"2\" for Legacy Nvidia Drivers (Driver 390)]: " nvidia - echo "$nvidia" -} - -create_subvol() { - local drive="$1" - echo -e "${cyan}CREATING SUBVOLUMES${normal}" - mkfs.btrfs -fL Linux "$drive" - mount "$drive" /mnt - btrfs subvolume create /mnt/@ - btrfs subvolume create /mnt/@home - btrfs subvolume create /mnt/@swap - btrfs subvolume create /mnt/@var - btrfs subvolume create /mnt/@tmp - umount /mnt -} - -mount_subvol() { - local drive="$1" - echo -e "${cyan}MOUNTING SUBVOLUMES${normal}" - mount -o noatime,discard=async,compress=zstd:2,subvol=@ "$drive" /mnt - mkdir /mnt/{home,swap,var,tmp} - mount -o noatime,compress=zstd:2,subvol=@home "$drive" /mnt/home - mount -o nodatacow,subvol=@swap "$drive" /mnt/swap - mount -o nodatacow,subvol=@var "$drive" /mnt/var - mount -o noatime,compress=zstd:2,subvol=@tmp "$drive" /mnt/tmp -} - -create_swap() { - echo -e "${cyan}CREATING SWAP${normal}" - btrfs filesystem mkswapfile --size 2G /mnt/swap/swapfile - swapon /mnt/swap/swapfile -} - -create_efi() { - local efi="$1" - echo -e "${cyan}CREATING UEFI PARTITION${normal}" - mkfs.fat -F 32 "$efi" - mkdir /mnt/boot - mount "$efi" /mnt/boot -} - -install_base_pkg() { - echo -e "${cyan}INSTALLING BASIC PACKAGES${normal}" - local packages=( - base - base-devel - linux-zen - linux-zen-headers - linux-firmware - btrfs-progs - intel-ucode - grub - networkmanager - git - libvirt - reflector - rsync - xdg-user-dirs - xdg-utils - zsh - bluez - bluez-utils - blueman - xorg-server - xorg-xinit - libxft - libxinerama - ufw - ) - pacstrap /mnt "${packages[@]}" - genfstab -U /mnt >>/mnt/etc/fstab +# TODO: Secure boot + +# TODO: Check if this works or not +# Update the sudo timestamp immediately +if ! sudo -v; then + echo "${red}Password incorrect or sudo failed. Exiting.${normal}" + exit 1 +fi + +# BACKGROUND JOB: Keep-alive for sudo +# This loop runs in the background and refreshes the sudo timeout every 60 seconds. +# It checks if the parent process ($$) is still running; if not, it exits. +while true; do + sudo -n true + sleep 60 + kill -0 "$$" || exit +done 2>/dev/null & + +conf_makepkg() { + echo -e "${green}MAKEPKG CONFIG${normal}" + nc=$(grep -c ^processor /proc/cpuinfo) + sudo sed -i "s/#MAKEFLAGS=\"-j2\"/MAKEFLAGS=\"-j$nc\"/g" /etc/makepkg.conf + sudo sed -i "s/COMPRESSXZ=(xz -c -z -)/COMPRESSXZ=(xz -c -T $nc -z -)/g" /etc/makepkg.conf } conf_pacman() { echo -e "${green}PACMAN CONFIG${normal}" - sed -i "s/^#ParallelDownloads = 5$/ParallelDownloads = 10/" /mnt/etc/pacman.conf - grep -q "ILoveCandy" /mnt/etc/pacman.conf || sed -i "/#VerbosePkgLists/a ILoveCandy" /mnt/etc/pacman.conf - sed -i "/^#ParallelDownloads/s/=.*/= 5/;s/^#Color$/Color/" /mnt/etc/pacman.conf - sed -i "/\[multilib\]/,/Include/"'s/^#//' /mnt/etc/pacman.conf -} - -conf_locale_hosts() { - local hostname="$1" - arch-chroot /mnt ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime - arch-chroot /mnt hwclock --systohc - echo "en_US.UTF-8 UTF-8" >>/mnt/etc/locale.gen - arch-chroot /mnt locale-gen - echo "LANG=en_US.UTF-8" >>/mnt/etc/locale.conf - echo "$hostname" >/mnt/etc/hostname - echo "127.0.0.1 localhost" >>/mnt/etc/hosts - echo "::1 localhost" >>/mnt/etc/hosts - echo "127.0.1.1 $hostname.localdomain $hostname" >>/mnt/etc/hosts + grep -q "ILoveCandy" /etc/pacman.conf || sudo sed -i "/#VerbosePkgLists/a ILoveCandy" /etc/pacman.conf + sudo sed -i "s/^#Color$/Color/" /etc/pacman.conf } -install_grub() { - local efi="$1" - local drive="$2" - echo -e "${green}GRUB${normal}" - case "$efi" in - /dev/*) - arch-chroot /mnt pacman -Sy --noconfirm efibootmgr - arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB - ;; - *) - arch-chroot /mnt grub-install --target=i386-pc $drive - ;; - esac - arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg -} - -create_user() { - local username="$1" - echo -e "${green}USER CREATION${normal}" - arch-chroot /mnt systemctl enable NetworkManager libvirtd paccache.timer bluetooth ufw.service - arch-chroot /mnt useradd -mG wheel -s /bin/zsh $username - arch-chroot /mnt usermod -aG libvirt $username +setup_aur() { + if [ ! -d "$HOME/.local/src/aur_helper" ]; then + echo "AUR helper present. Skipping." + return + fi + echo -e "${blue}AUR Helper${normal}" + git clone --depth=1 https://aur.archlinux.org/yay-bin.git ~/.local/src/aur_helper + makepkg --clean --install --noconfirm --rmdeps --syncdeps --dir ~/.local/src/aur_helper + rm -rf ~/.local/src/aur_helper } -pass_user() { - local username="$1" - local pass="$2" - arch-chroot /mnt bash -c "echo $username:$pass | chpasswd" +install_packages() { + echo -e "${blue}PACKAGES${normal}" + # Read file into 'packages' array, filtering out: + # 1. Comments (^#) + # 2. Empty lines (^$) + mapfile -t packages < <(grep -vE '^#|^$' packages.txt) + yay -S --noconfirm --needed "${packages[@]}" } -setup_ufw() { - arch-chroot /mnt < /etc/zsh/zshenv #TODO Check if this works -EOF -} - -setup_paru() { - local username="$1" - arch-chroot /mnt sudo -i -u "$username" bash <>/mnt/etc/sudoers - nc=$(grep -c ^processor /proc/cpuinfo) - sed -i "s/#MAKEFLAGS=\"-j2\"/MAKEFLAGS=\"-j$nc\"/g" /mnt/etc/makepkg.conf - sed -i "s/COMPRESSXZ=(xz -c -z -)/COMPRESSXZ=(xz -c -T $nc -z -)/g" /mnt/etc/makepkg.conf + setup_aur + install_packages - setup_dotfiles "$username" - setup_paru "$username" - setup_dwm "$username" - setup_dwmblocks "$username" - setup_st "$username" - setup_dmenu "$username" - setup_neovim "$username" + setup_firewall + setup_dotfiles + setup_neovim + rm -rf ~/.bash* - install_packages "$username" - install_nvidia "$nvidia" "$username" - post_install_cleanup "$username" + # systemctl enable paccache.timer - echo -e "${green}Script finished without errors! Reboot now and enjoy ^_^${normal}" + echo -e "${green}Script finished without errors ^_^${normal}" } main "$@" diff --git a/config.json b/config.json new file mode 100644 index 0000000..ec90aa2 --- /dev/null +++ b/config.json @@ -0,0 +1,68 @@ +{ + "app_config": { + "audio_config": { + "audio": "pipewire" + }, + "bluetooth_config": { + "enabled": true + }, + "power_management_config": { + "power_management": "power-profiles-daemon" + }, + "print_service_config": { + "enabled": false + } + }, + "archinstall-language": "English", + "auth_config": {}, + "bootloader_config": { + "bootloader": "Systemd-boot", + "removable": false, + "uki": true + }, + "custom_commands": [], + "hostname": "arch", + "kernels": [ + "linux", + "linux-lts", + "linux-zen" + ], + "locale_config": { + "kb_layout": "us", + "sys_enc": "UTF-8", + "sys_lang": "en_US.UTF-8" + }, + "mirror_config": { + "custom_repositories": [], + "custom_servers": [], + "optional_repositories": [ + "multilib" + ] + }, + "network_config": { + "type": "nm_iwd" + }, + "ntp": true, + "packages": ["base-devel", "chezmoi", "git", "neovim"], + "parallel_downloads": 0, + "profile_config": { + "gfx_driver": null, + "greeter": null, + "profile": { + "custom_settings": {}, + "details": [], + "main": "Minimal" + } + }, + "script": null, + "services": [], + "swap": { + "algorithm": "zstd", + "enabled": true + }, + "version": "3.0.15", + "custom-commands": [ + "read -p \"Enter your username: \" u", + "curl https://raw.githubusercontent.com/ksharizard/arch-installer/refs/heads/master/arch-installer.sh | sudo -u \"$u\" bash" + ] +} diff --git a/packages.txt b/packages.txt new file mode 100644 index 0000000..923cee3 --- /dev/null +++ b/packages.txt @@ -0,0 +1,20 @@ +# Hyprland +hyprland +hyprlock +hyprpolkitagent +xdg-desktop-portal-hyprland + +# AUR +blesh-git +brave-bin +dracula-gtk-theme +duplicati-bin +gamescope-git +kanata-bin +localsend-bin +paru-bin +spicetify-cli +spicetify-marketplace-bin +wayfreeze-git +zen-browser-bin +