#!/bin/bash # This is my installation script for Artix/Arch Linux. # Check if the required config files are present if [ ! -f "install_config/info.conf" ] || [ ! -f "install_config/packs.list" ] || [ ! -f "install_config/aur_packs.list" ] || [ ! -f "install_config/services.list" ] ; then echo "You need to create the following files to commence installation: " echo "install_config/info.conf: For system information." echo "install_config/packs.list: For native packages." echo "install_config/aur_pack.list: For AUR packages." echo "install_config/services.list: For startup services." echo "Until this issue is resolved, I cannot allow you to install." exit 1 fi # make sure the script is run as root if [ "$EUID" -ne 0 ]; then echo "You must be the root user to run this script." && exit 1 fi echo "Greetings my fellow edgelord!" echo "You are about to install the world's best linux distribution: Artix/Arch Linux." # Gather information from configuration files echo "Gathering information..." echo "Reading system configuration information..." username=$(grep username install_config/info.conf | awk ' { print $3 } ') password=$(grep password install_config/info.conf | awk ' { print $3 } ') passlength=$(echo "$password" | wc -m) hostname=$(grep hostname install_config/info.conf | awk ' { print $3 } ') disk=$(grep disk install_config/info.conf | awk ' { print $3 } ') # Git repository to clone from gitserver="172.16.0.100" # read package list echo "Reading native package and AUR package list..." pack_list=$(grep -vi "#" install_config/packs.list | tr '\n' ' ') aur_pack_list=$(grep -vi "#" install_config/aur_packs.list | tr '\n' ' ') aur_pack_list=$(grep -vi "#" install_config/aur_packs.list | tr '\n' ' ') service_list=$(grep -vi "#" install_config/services.list | tr '\n' ' ') timezone=$(curl ifconfig.co/json | grep time_zone | awk ' { print $2 } ' | tr -d '"",') countryiso=$(curl ifconfig.co/country-iso) # test package lists for testing only if [ $test -eq 1 ]; then aur_pack_list=$(cat test_aur_packs.list | tr '\n' ' ') pack_list=$(cat test_packs.list | tr '\n' ' ') service_list=$(cat test_services.list | tr '\n' ' ') fi # determine if system is running BIOS or EFI echo "Determining boot mode..." if [[ -d "/sys/firmware/efi" ]]; then bootmode="efi" elif [[ ! -d "/sys/firmware/efi" ]]; then bootmode="bios" fi # determine init system echo "Determining init system..." case "$(readlink /sbin/init)" in "../lib/systemd/systemd") initsys="systemd" ;; "openrc-init") initsys="openrc" ;; "runit-init") initsys="runit" ;; "s6-init") initsys="s6" ;; "dinit-init") initsys="dinit" ;; * ) echo "Sorry, but $initsys is not supported" exit 1 esac # determine distro echo "Determining distro..." distro=$(lsb_release -is | tr [:upper:] [:lower:]) # get the memory amount to determine how big the swap partition should be memory=$(awk '/MemTotal/ { print $2 } ' /proc/meminfo) memory=$(($memory * 1024)) #memory=$(numfmt --to=iec $memory | tr '.' ',' | sed 's/,.//g') memory=$(numfmt --to=iec $memory) if grep -E "." <<< "${memory}"; then ramnum=$(echo $memory | tr -dc '0-9 .') ramletter=$(echo $memory | tr -dc 'A-Z') ramnum=$(printf '%.*f\n' 0 $ramnum) memory=$ramnum$ramletter fi echo "You have $memory of memory." # verify settings echo "Are these are the properties you want your system to have." echo " " echo "Username: ${username}" echo "Password: ${passlength} characters long." echo "Hostname: ${hostname} " echo "Installation disk: ${disk} " echo "Timezone: ${timezone} " echo "Boot mode: ${bootmode} " echo "Distro: ${distro} " echo "Init system: ${initsys} " echo " " echo "!!! The partition table for ${disk} will be overwritten. !!!" echo "!!! ALL DATA ON ${disk} WILL BE LOST FOREVER (A LONG TIME!) !!!" # prompt user for confirmation read -r -p "Is this information correct? " choice case "$choice" in y|Y|yes|Yes ) echo "Yes. Installation confirmed!";; n|N|no|No ) echo "No. Now aborting installation..." && exit 0;; * ) echo "$choice is an invalid response" && exit 1;; esac sleep 1 # prepare live system for setup echo "Preparing for setup..." # Enable Parallel Downloads, Package Verbosity, Highlighting, and Disk Space Checking sed -i 's/^#ParallelDownloads = 5/ParallelDownloads = 10/' /etc/pacman.conf sed -i 's/^#Color/Color/' /etc/pacman.conf sed -i 's/^#CheckSpace/CheckSpace/' /etc/pacman.conf case "$distro" in "artix") if [ ! -z $(grep "universe" "/etc/pacman.conf") ]; then # add the universe repository echo -e "\n[universe]\nInclude = /etc/pacman.d/mirrorlist-universe" >> /etc/pacman.conf echo " Server = https://universe.artixlinux.org/\$arch Server = https://mirror1.artixlinux.org/universe/\$arch Server = https://mirror.pascalpuffke.de/artix-universe/\$arch Server = https://artixlinux.qontinuum.space/artixlinux/universe/os/\$arch Server = https://mirror1.cl.netactuate.com/artix/universe/\$arch Server = https://ftp.crifo.org/artix-universe/ " >> /etc/pacman.d/mirrorlist-universe fi ;; esac pacman -Sy --noconfirm pacman-contrib gptfdisk rsync git espeak-ng lsb-release # wipe disk echo "Wiping..." umount -l -v "${disk}" sgdisk -Z "${disk}" sgdisk -a 2048 -i "${disk}" echo "And it's gone. I really hope nothing important was there..." # partition disk echo "Partitioning..." sgdisk -n 1::+1M --typecode=1:ef02 --change-name=1:'BIOSBOOT' "${disk}" # part 1 (BIOS Boot) will take up 1 MB not be mounted or formated sgdisk -n 2::+1G --typecode=2:ef00 --change-name=2:'EFIBOOT' "${disk}" # part 2 (UEFI Boot) will take up 1 GB and will be formatted as FAT32 sgdisk -n 3::+"${memory}" --typecode=3:8200 --change-name=3:'SWAP' "${disk}" # part 3 (SWAP) will take up same as memory sgdisk -n 4::+50G --typecode=4:8300 --change-name=4:'ROOT' "${disk}" # part 4 (ROOT) will take up 50 G be mounted on / and will be formated as ext4 sgdisk -n 5::-0 --typecode=5:8300 --change-name=5:'HOME' "${disk}" # part 5 (HOME) will take up remaining space and be mounted on /home and will be formated as ext4 # format partitions echo "Formating..." mkfs.fat -n "EFIBOOT" -F 32 "${disk}2" mkswap -L "SWAP" "${disk}3" mkfs.ext4 -L "ROOT" "${disk}4" mkfs.ext4 -L "HOME" "${disk}5" # mount partitions echo "Mounting..." swapon "${disk}3" mkdir -v /mnt mount -v -t ext4 "${disk}4" /mnt mkdir -v /mnt/boot mount -t vfat -L EFIBOOT /mnt/boot/ mkdir -pv /mnt/boot/efi mkdir -v /mnt/home mount -v -t ext4 "${disk}5" /mnt/home mkdir -v /mnt/media lsblk # refresh mirrors now if using arch case $distro in "arch" ) echo "Refreshing mirrors..." reflector --verbose -c $countryiso -a 48 -f 10 -l 10 --sort rate -p https --save /etc/pacman.d/mirrorlist ;; esac # commence installation echo "Bootstraping time!" case $distro in "arch") while true; do ping -c 1 archlinux.org pacstrap /mnt base base-devel linux linux-headers linux-lts linux-lts-headers grub efibootmgr vim git dash opendoas sudo openresolv zsh reflector archlinux-keyring archiso && break || sleep 5 done # generate /etc/fstab genfstab -U /mnt > /mnt/etc/fstab ;; "artix") while true; do ping -c 1 artixlinux.org basestrap /mnt base base-devel linux linux-headers linux-lts linux-lts-headers grub efibootmgr ${initsys} elogind-${initsys} pacman-contrib vim git opendoas dash sudo openresolv zsh artix-keyring artix-archlinux-support artools iso-profiles && break || sleep 5 done # generate /etc/fstab fstabgen -U /mnt > /mnt/etc/fstab ;; "parabola") while true; do ping -c 1 parabola.nu #initsys="openrc" pacstrap /mnt base base-devel linux-libre linux-libre-headers linux-libre-lts linux-libre-lts-headers ${initsys} elogind-${initsys} grub efibootmgr libelogind udev-init-scripts pacman-contrib vim git opendoas dash sudo openresolv zsh archlinux-keyring parabola-keyring && break || sleep 5 done esac # mount psuedo filesystems because normal chroot requires it mount -v -t proc /proc /mnt/proc mount -v -t sysfs /sys /mnt/sys mount -v --rbind /dev /mnt/dev # copy live resolv.conf to new system cp -v /etc/resolv.conf /mnt/etc/resolv.conf # test to make sure the servers works chroot /mnt ping -c 1 archlinux.org || exit 1 chroot /mnt ping -c 1 artixlinux.org || exit 1 # setup account echo "Setting up user account..." chroot /mnt useradd -m -G wheel,audio,video,optical,storage -s /bin/zsh ${username} # setup passwords chroot /mnt echo "root:${password}" | chpasswd chroot /mnt /bin/sh -c "echo ${username}:${password} | chpasswd" # setup grub and mkinit echo "Setting up grub bootloader..." case "$bootmode" in "bios" ) echo "Setting up GRUB for BIOS..." grub-install --boot-directory=/mnt/boot "${disk}" ;; "efi" ) echo "Setting up GRUB for UEFI..." grub-install --boot-directory=/mnt/boot --target=x86_64-efi --efi-directory=/mnt/boot --bootloader-id=GRUB "${disk}" ;; esac sed -i 's/^GRUB_TIMEOUT=5/GRUB_TIMEOUT=1/' /mnt/etc/default/grub sed -i 's/^#GRUB_SAVEDEFAULT=true/GRUB_DEFAULT=true/' /mnt/etc/default/grub sed -i 's/^#GRUB_DISABLE_SUBMENU=true/GRUB_DISABLE_SUBMENU=true/' /mnt/etc/default/grub chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg echo "Setting up mkinitcpio..." chroot /mnt mkinitcpio -P #tweak config files cp /etc/pacman.conf /mnt/etc/pacman.conf cp /etc/pacman.d/mirrorlist-universe /mnt/etc/pacman.d/mirrorlist-universe # Add support for Arch Linux Repositories if running artix linux and refresh mirrors case "$distro" in "arch" ) echo "Refreshing mirrorlist..." chroot /mnt reflector --verbose -c $countryiso -a 48 -f 10 -l 10 --sort rate -p https --save /etc/pacman.d/mirrorlist ;; "artix" ) echo "You are running Artix Linux. Now enabling required repositories..." for repo in extra community; do echo "Adding $repo..." grep "^\[$repo\]" /mnt/etc/pacman.conf || echo -e "\n[$repo]\nInclude = /etc/pacman.d/mirrorlist-arch" >> /mnt/etc/pacman.conf done echo "Refreshing Artix mirrorlist..." # grab the mirror urls and sort them using rankmirrors curl -s "https://gitea.artixlinux.org/packagesA/artix-mirrorlist/raw/branch/master/trunk/mirrorlist" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 10 - > /mnt/etc/pacman.d/mirrorlist echo "Refreshing Arch mirrorlist..." curl -s "https://archlinux.org/mirrorlist/?country=US&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 10 - > /mnt/etc/pacman.d/mirrorlist-arch ;; esac echo "Refreshing mirrors..." # refresh package repositories while true; do chroot /mnt pacman -Syy --noconfirm && break || sleep 5; done echo "Editing config files..." # hostname echo "$hostname" > /mnt/etc/hostname # hosts echo "127.0.0.1 localhost" >> /mnt/etc/hosts echo "::1 localhost" >> /mnt/etc/hosts # resolvconf.conf echo "name_servers="1.1.1.1 1.0.0.1"" >> /mnt/etc/resolvconf.conf # gpg conf echo "keyserver hkp://keyserver.ubuntu.com" >> /mnt/etc/pacman.d/gnupg/gpg.conf # locale.gen sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /mnt/etc/locale.gen # sudoers.conf sed -i 's/^# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /mnt/etc/sudoers sed -i 's/^# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/' /mnt/etc/sudoers # doas.conf echo "permit persist :wheel" > /mnt/etc/doas.conf # make.conf echo "Calculating CPU cores..." cpu_cores=$(grep -c ^processor /proc/cpuinfo) sed -i "s/#MAKEFLAGS=\"-j2\"/MAKEFLAGS=\"-j$cpu_cores\"/g" /mnt/etc/makepkg.conf sed -i "s/COMPRESSXZ=(xz -c -z -)/COMPRESSXZ=(xz -c -T $cpu_cores -z -)/g" /mnt/etc/makepkg.conf # pacman.conf sed -i 's/^#ParallelDownloads = 5/ParallelDownloads = 10/' /mnt/etc/pacman.conf sed -i 's/^#Color/Color/' /mnt/etc/pacman.conf sed -i 's/^#CheckSpace/CheckSpace/' /mnt/etc/pacman.conf sed -i "/\[multilib\]/,/Include/"'s/^#//' /mnt/etc/pacman.conf # setup timezone echo "Setting up time..." chroot /mnt ln -sf /usr/share/zoneinfo/${timezone} /etc/localtime chroot /mnt hwclock --systohc # setup locale echo "Setting up locale..." chroot /mnt locale-gen # replace bash symlink with dash symlink chroot /mnt ln -sfT /bin/dash /bin/sh echo "[Trigger] Type = Package Operation = Install Operation = Upgrade Target = bash [Action] Description = Re-pointing /bin/sh symlink to dash... When = PostTransaction Exec = /usr/bin/ln -sfT dash /usr/bin/sh Depends = dash" > /usr/share/libalpm/hooks/bash_update.hook # drivers echo "Installing drivers..." # install firmware chroot /mnt pacman -Sy --noconfirm linux-firmware # microcode echo "Detecting CPU..." proc_type=$(lscpu) if grep -E "GenuineIntel" <<< ${proc_type}; then echo "Installing Intel microcode" chroot /mnt pacman -S --noconfirm intel-ucode chroot /mnt proc_ucode=intel-ucode.img elif grep -E "AuthenticAMD" <<< ${proc_type}; then echo "Installing AMD microcode" chroot /mnt pacman -S --noconfirm amd-ucode chroot /mnt proc_ucode=amd-ucode.img fi # Detect and and install drivers for graphics echo "Detecting graphics card..." gpu_type=$(lspci) if grep -E "NVIDIA|GeForce" <<< "${gpu_type}"; then echo "Installing Nvidia drivers..." chroot /mnt pacman -S nvidia --noconfirm --needed chroot /mnt nvidia-xconfig elif grep -E "Radeon|AMD" <<< "${gpu_type}"; then echo "Installing AMD drivers..." chroot /mnt pacman -S --noconfirm --needed xf86-video-amdgpu vulkan-radeon elif grep -E "Integrated Graphics Controller" <<< ${gpu_type}; then echo "Installing Intel drivers..." chroot /mnt pacman -S --noconfirm --needed libva-intel-driver libvdpau-va-gl vulkan-intel libva-intel-driver libva-utils elif grep -E "Intel Corporation UHD" <<< ${gpu_type}; then echo "Installing Intel UHD drivers..." chroot /mnt pacman -S --noconfirm --needed libva-intel-driver libvdpau-va-gl vulkan-intel libva-intel-driver libva-utils fi # install native packages echo "Installing native packages..." while true; do chroot /mnt pacman -Sy --noconfirm --needed ${pack_list} && break || sleep 5; done echo "Enabling services..." case "$initsys" in "systemd" ) echo "Setting up services for systemd..." for service in $service_list; do chroot /mnt systemctl enable "${service}" chroot /mnt systemctl enable "${service}d" done ;; "openrc") echo "Setting up services for openrc..." for service in $service_list; do echo "Setting up service: $service" chroot /mnt pacman -S --noconfirm "${service}-openrc" chroot /mnt rc-update add "${service}" done ;; "runit") echo "Setting up services for runit..." for service in $service_list; do echo "Setting up service: $service" chroot /mnt pacman -S --noconfirm "${service}-runit" chroot /mnt ln -sf /etc/runit/sv/"${service}" /etc/runit/runsvdir/current done ;; "s6" ) echo "Setting up services for s6" for service in $service_list; do echo "Setting up service: $service" chroot /mnt pacman -S --noconfirm "${service}-s6" chroot /mnt s6-rc-bundle-update -c /etc/s6/rc/compiled add default "${service}" done ;; "dinit" ) echo "Setting up services for dinit" for service in $service_list; do echo "Setting up service: $service" chroot /mnt pacman -S --noconfirm "${service}-dinit" chroot /mnt ln -s ../"${service}" /etc/dinit.d/boot.d done ;; esac # install yay echo "Installing yay..." ping -c 1 https://aur.archlinux.org chroot /mnt git clone https://aur.archlinux.org/yay.git /opt/yay chroot /mnt chown -R ${username}:${username} /opt/yay chroot --userspec=$username:$username /mnt /bin/sh -c "export HOME=/home/${username} && cd /opt/yay && makepkg -si --noconfirm" # get ready to install aur packages chroot /mnt /bin/sh -c mkdir /home/$username/.gnupg chroot /mnt chown -R $username:$username /home/$username # install aur packages echo "Installing AUR packages..." while true; do chroot --userspec=$username:$username /mnt /bin/sh -c "export HOME=/home/${username} && yay -S --noconfirm ${aur_pack_list}" && break || sleep 5; done # clone repositories ping -c 1 "$gitserver" || echo "Warning! The git server $gitserver might be down!" git clone "git://$gitserver/dotfiles" /mnt/tmp/dotfiles cp -rv /mnt/tmp/dotfiles/.* /mnt/home/user rm -rfv /mnt/tmp/dotfiles/ /mnt/home/$username/.git git clone "git://$gitserver/dwm" /mnt/home/$username/.local/src/dwm git clone "git://$gitserver/dwmblocks" /mnt/home/$username/.local/src/dwmblocks git clone "git://$gitserver/st" /mnt/home/$username/.local/src/st git clone "git://$gitserver/dmenu" /mnt/home/$username/.local/src/dmenu chroot /mnt /bin/sh -c "chown -R ${username}:${username} /home/${username}/.*" chroot --userspec=$username:$username /mnt sudo make clean install -C /home/$username/.local/src/dwm chroot --userspec=$username:$username /mnt sudo make clean install -C /home/$username/.local/src/dwmblocks chroot --userspec=$username:$username /mnt sudo make clean install -C /home/$username/.local/src/st chroot --userspec=$username:$username /mnt sudo make clean install -C /home/$username/.local/src/dmenu chroot /mnt chown -R ${username}:${username} /home/${username} chroot /mnt /bin/sh -c "chown -R ${username}:${username} /home/${username}" # revert sudo rights to the way its meant to be sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL/# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /mnt/etc/sudoers sed -i 's/^%wheel ALL=(ALL) NOPASSWD: ALL/# %wheel ALL=(ALL) NOPASSWD: ALL/' /mnt/etc/sudoers sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /mnt/etc/sudoers sed -i 's/^#VerbosePkgLists/VerbosePkgLists/' /mnt/etc/pacman.conf # success!! (hopefully) echo "Installation complete!" espeak-ng "Installation complete!" echo "Artix Linux installation has completed btw." chroot /mnt neofetch # unmount filesystems echo "Unmounting filesystems..." umount -l -v -f /mnt lsblk echo "Be sure to disconnect the installation media before you reboot." #read -r -p "Would you like to reboot now? " choice #case $choice in # y|Y|yes|Yes ) reboot now || exit 1;; # n|N|no|No ) exit 0;; # * ) echo "$choice is an invalid response" && exit 1;; #esac exit 0