archsetup

bootstrapping script for Arch Linux
git clone git://git.hanetzok.net/archsetup
Log | Files | Refs | README

post-install.sh (4410B)


      1 #!/bin/bash
      2 
      3 set -e
      4 
      5 # variables used in the script
      6 tz="Europe/Berlin"
      7 locale="de_DE.UTF-8"
      8 suckless="git://git.hanetzok.net"
      9 
     10 ### functions
     11 
     12 slinstall() {
     13   (
     14 	sudo -u "$user" git clone "$suckless/$1" "/home/$user/src/$1"
     15 	cd "/home/$user/src/$1"
     16 	sudo -u "$user" make > /dev/null
     17 	make install >/dev/null
     18   )
     19 }
     20 
     21 if [ "$(id -u)" -ne 0 ]; then
     22   echo "Please run as root"
     23   exit 1
     24 fi
     25 
     26 # enable multilib repo and run system update
     27 grep -q '\[multilib\]' /etc/pacman.conf || printf '\n[multilib]\nInclude = /etc/pacman.d/mirrorlist\n' >> /etc/pacman.conf
     28 pacman -Syu --noconfirm --needed zsh
     29 
     30 cp ./progs.list /tmp
     31 
     32 clear
     33 read -p "Enter username: " user
     34 if [[ ! "$user" =~ ^[a-z_][a-z0-9_-]*$ ]]; then
     35   echo "Invalid username"; exit 1
     36 fi
     37 read -p "Enter hostname: " hostname
     38 if [[ ! "$hostname" =~ ^[a-zA-Z0-9-]+$ ]]; then
     39   echo "Invalid hostname"; exit 1
     40 fi
     41 echo "User: $user - Hostname: $hostname"
     42 
     43 read -p "Is this correct? [Y/n] " start
     44 case "$start" in
     45   Y | y | yes | Yes | YES) clear;;
     46   *) exit 0;;
     47 esac
     48 
     49 echo "!!! Set ROOT password !!!"
     50 passwd
     51 
     52 # user creation
     53 echo "Add user $user..."
     54 useradd -m -G wheel -s /usr/bin/zsh "$user"
     55 echo "Set user password..."
     56 passwd "$user"
     57 
     58 # sudo
     59 echo "%wheel ALL=(ALL:ALL) ALL" > /etc/sudoers.d/wheel
     60 chmod 440 /etc/sudoers.d/wheel
     61 
     62 # timezone & locale
     63 echo "Set timezone and locale..."
     64 grep -q "$locale UTF-8" /etc/locale.gen || echo "$locale UTF-8" >> /etc/locale.gen
     65 locale-gen > /dev/null
     66 echo "LANG=$locale" > /etc/locale.conf
     67 ln -sf /usr/share/zoneinfo/"$tz" /etc/localtime
     68 hwclock --systohc
     69 
     70 
     71 # set hostname
     72 echo "$hostname" > /etc/hostname
     73 
     74 # delete comments from progs.list
     75 [ -f /tmp/progs.list ] || { echo "progs.list not found"; exit 1; }
     76 sed '/^#/d' /tmp/progs.list > /tmp/progscleared.list
     77 
     78 # install packages
     79 echo "Installing packages from the official repos..."
     80 while IFS= read -r prog || [ -n "$prog" ]; do
     81 	echo "Installing $prog..."
     82 	pacman --noconfirm --needed -S "$prog" > /dev/null
     83 done < /tmp/progscleared.list
     84 
     85 rm /tmp/progscleared.list
     86 
     87 # check if yay is already installed
     88 if ! hash yay 2>/dev/null; then
     89 	echo "Download and install yay..."
     90 	git clone https://aur.archlinux.org/yay-bin /opt/yay-bin > /dev/null
     91 	chown "$user":"$user" -R /opt/yay-bin
     92 	cd /opt/yay-bin
     93 	sudo -u "$user" makepkg -s --noconfirm > /dev/null
     94 	sudo pacman -U --noconfirm /opt/yay-bin/*.pkg.tar.* > /dev/null
     95 fi
     96 cd /tmp
     97 
     98 # install GRUB (UEFI)
     99 echo "Install GRUB..."
    100 grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB > /dev/null
    101 
    102 # set GRUB theme
    103 echo "Install GRUB theme..."
    104 git clone https://github.com/krypciak/crossgrub /tmp/crossgrub > /dev/null
    105 bash /tmp/crossgrub/install.sh
    106 
    107 grep -q 'GRUB_THEME' /etc/default/grub \
    108   && sed -i 's|.*GRUB_THEME=.*|GRUB_THEME=/boot/grub/themes/crossgrub/theme.txt|' /etc/default/grub \
    109   || echo "GRUB_THEME=/boot/grub/themes/crossgrub/theme.txt" >> /etc/default/grub
    110 
    111 grub-mkconfig -o /boot/grub/grub.cfg > /dev/null
    112 
    113 # set ZDOTDIR in zshenv to keep $HOME clean(er)
    114 grep -q 'ZDOTDIR' /etc/zsh/zshenv || echo 'export ZDOTDIR="$HOME/.config/zsh"' >> /etc/zsh/zshenv
    115 
    116 # disable hardware speaker bell
    117 rmmod pcspkr 2>/dev/null || true
    118 echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf
    119 
    120 # dotfiles
    121 echo "Get dotfiles..."
    122 find "/home/$user" -maxdepth 1 -name '.bash*' -delete
    123 git clone git://git.hanetzok.net/dotfiles /tmp/dotfiles > /dev/null
    124 find /tmp/dotfiles -mindepth 1 -maxdepth 1 -name '.*' -exec cp -r {} "/home/$user/" \;
    125 chown "$user":"$user" -R "/home/$user"
    126 
    127 # install stuff via git
    128 echo "Install dominant_colours from GitHub (might take a while)..."
    129 git clone "https://github.com/alexwlchan/dominant_colours.git" /tmp/dominant_colours > /dev/null
    130 chown -R "$user":"$user" /tmp/dominant_colours
    131 cd /tmp/dominant_colours
    132 sudo -u "$user" rustup default stable > /dev/null
    133 sudo -u "$user" cargo install --path . > /dev/null
    134 
    135 # install suckless suite
    136 sudo -u "$user" mkdir /home/"$user"/src
    137 slinstall dwm
    138 slinstall st
    139 slinstall dmenu
    140 slinstall slock
    141 
    142 
    143 # misc
    144 echo "Set options for GNOME keyring..."
    145 grep -q 'pam_gnome_keyring' /etc/pam.d/login || {
    146   echo "auth       optional     pam_gnome_keyring.so" >> /etc/pam.d/login
    147   echo "session    optional     pam_gnome_keyring.so auto_start" >> /etc/pam.d/login
    148 }
    149 
    150 echo "Enabling services"
    151 systemctl enable NetworkManager > /dev/null
    152 systemctl enable cups > /dev/null
    153 
    154 echo "Done. You can now log in with your new user and run AUR installs if needed."