#!/bin/bash # set -e echo (){ /bin/echo "#########################################" /bin/echo "$@" /bin/echo "#########################################" } #LICENSE#{{{ # Copyright (c) 2012 Tom Wambold # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. #}}} #ABOUT#{{{ # This script will set up an Arch installation with a 100 MB /boot partition # and an encrypted LVM partition with swap and / inside. It also installs # and configures systemd as the init system (removing sysvinit). # # You should read through this script before running it in case you want to # make any modifications, in particular, the variables just below, and the # following functions: # # partition_drive - Customize to change partition sizes (/boot vs LVM) # setup_lvm - Customize for partitions inside LVM # install_packages - Customize packages installed in base system # (desktop environment, etc.) # install_aur_packages - More packages after packer (AUR helper) is # installed # set_netcfg - Preload netcfg profiles #}}} # CONFIGURE THESE VARIABLES{{{ # Drive to install to. DRIVE='/dev/sda' # Hostname of the installed machine. HOSTNAME='arch' # Encrypt everything (except /boot). Leave blank to disable. ENCRYPT_DRIVE='' # Passphrase used to encrypt the drive (leave blank to be prompted). DRIVE_PASSPHRASE='' # Root password (leave blank to be prompted). ROOT_PASSWORD='' # Main user to create (by default, added to wheel group, and others). USER_NAME='lelgenio' # Link to users dotfiles repo(git) # Assumed to have stow-able modules on its root(cd .dotfiles;stow*/) DOTFILES_URL="https://gitlab.com/$USER_NAME/dotfiles" USER_SHELL='zsh' # The main user's password (leave blank to be prompted). USER_PASSWORD='' # System timezone. TIMEZONE='America/Sao_Paulo' # Have /tmp on a tmpfs or not. Leave blank to disable. # Only leave this blank on systems with very little RAM. TMP_ON_TMPFS='TRUE' KEYMAP='br-abnt2' # KEYMAP='dvorak' LANG=pt_BR.UTF-8 # Choose your video driver # For Intel VIDEO_DRIVER="i915" # For nVidia #VIDEO_DRIVER="nouveau" # For ATI #VIDEO_DRIVER="radeon" # For generic stuff #VIDEO_DRIVER="vesa" REMOVE_PKGS=false FULL_INSTALL=false #}}} # PACKAGES{{{ set_pkgs() { # sudo to allow to run as a user later sudo pacman -Sy &> /dev/null pkgs_base+=' base linux-zen linux-firmware intel-ucode lvm2 ' pkgs_base+=' zsh networkmanager bluez cronie git man-db' pkgs_base+=" $(pacman -Sgq base-devel)" if $IS_BIOS;then pkgs_base+=' grub' fi pkgs+=" $pkgs_base" # DE pkgs+=' sway waybar ruby-fusuma light mako udiskie bemenu wofi-hg stow yay' pkgs+=' bemenu wofi-hg j4-dmenu-desktop' # pkgs+=' i3 termite scrot pamixer' pkgs+=' nemo redshift-wlr-gamma-control ' pkgs+=' pkgfile kitty neovim moreutils htop-vim-git' # Audio pkgs+=' pulseaudio pavolume-git' # Fonts pkgs+=' ttf-hack inter-font' if $FULL_INSTALL; then # Screenshot pkgs+=' grim slurp wl-clipboard wf-recorder-git' pkgs+=' httpie jq python-keepmenu-git' # Theme pkgs+=' materia-custom-accent papirus-icon-theme' pkgs+=' papirus-folders-git capitaine-cursors ' pkgs+=' flashfocus-git ' # Terminal pkgs+=' tmux ranger atool p7zip tree' pkgs+=' neofetch powerline-fonts otf-fira-code' pkgs+=' lolcat cmatrix' # Network pkgs+=' wget curl bluez-utils rsync rclone nmap gnu-netcat tor mtr speedtest-cli' pkgs+=' openssh sshfs fail2ban' # Browser pkgs+=' qutebrowser youtube-dl' # Email pkgs+=' neomutt isync' # Files pkgs+=' syncthing nextcloud-client ' pkgs+=' deluge deezloader-remix-bin smloadr' # Media pkgs+=' sxiv mpv mpd mpc ncmpcpp mpv-mpris mpdris2 playerctl' pkgs+=' blender gimp kdenlive picard image_optim' # Office pkgs+=' libreoffice-fresh libreoffice-fresh-pt-br hunspell-pt-br papirus-libreoffice-theme' # Programing pkgs+=' code neovim python-pynvim neovim-symlinks ipython how2' pkgs+=' gdb clang' # Virt pkgs+=' qemu' # Gtk pkgs+=' gtk3-nocsd-git' # Qt pkgs+=' qt5-base qt5-wayland qt5ct kvantum-qt5' # Chat pkgs+=' discord telegram-desktop telegram-cli-git' # Gaming pkgs+=' steam lutris gamemode lutris-wine-meta wine wine-mono winetricks' if [ "$VIDEO_DRIVER" == "i915" ];then pkgs+=' xf86-video-intel ' pkgs+=' lib32-mesa vulkan-intel lib32-vulkan-intel vulkan-icd-loader lib32-vulkan-icd-loader' elif [ "$VIDEO_DRIVER" == "radeon" ];then pkgs+=' xf86-video-ati' pkgs+=' lib32-mesa vulkan-radeon lib32-vulkan-radeon vulkan-icd-loader lib32-vulkan-icd-loader' elif [ "$VIDEO_DRIVER" == "nouveau" ];then pkgs+=' xf86-video-nouveau' pkgs+=' nvidia nvidia-utils lib32-nvidia-utils nvidia-settings vulkan-icd-loader lib32-vulkan-icd-loader' elif [ "$VIDEO_DRIVER" = "vesa" ];then packages+=' xf86-video-vesa' fi fi } #}}} # Initial Setup{{{ # Base install{{{ setup() { local boot_dev="$DRIVE"1 local lvm_dev="$DRIVE"2 echo 'Cleaning disk' disk_clean echo 'Creating partitions' partition_drive "$DRIVE" if [ -n "$ENCRYPT_DRIVE" ] then local lvm_part="/dev/mapper/lvm" if [ -z "$DRIVE_PASSPHRASE" ] then echo 'Enter a passphrase to encrypt the disk:' read -s DRIVE_PASSPHRASE fi echo 'Encrypting partition' encrypt_drive "$lvm_dev" "$DRIVE_PASSPHRASE" lvm else local lvm_part="$lvm_dev" fi echo 'Setting up LVM' setup_lvm "$lvm_part" vg00 echo 'Formatting filesystems' format_filesystems "$boot_dev" echo 'Mounting filesystems' mount_filesystems "$boot_dev" echo 'Installing base system' install_base echo 'Setting fstab' set_fstab echo 'Chrooting into installed system to continue setup...' cp "$0" "/mnt/setup.sh" chmod +x "/mnt/setup.sh" arch-chroot /mnt "./setup.sh" if [ -f "/mnt/setup.sh" ] then echo 'ERROR: Something failed inside the chroot, not unmounting filesystems so you can investigate.' echo 'Make sure you unmount everything before you try to run this script again.' else echo 'Unmounting filesystems' unmount_filesystems echo 'Done! Reboot system.' fi } #}}} # Remove old LVMs{{{ disk_clean(){ echo 'cleaning disk' umount -R /mnt || true swapoff -a pvs "$DRIVE"2 || return 0 for vg in $(pvs -o vg_name --nohead "$DRIVE"2) do vgremove "$vg" --yes done pvremove "$DRIVE"2 } #}}} # Partition Drive{{{ partition_drive() { local dev="$1"; shift # 100 MB /boot partition, everything else under LVM if $IS_BIOS;then parted -s "$dev" \ mklabel msdos \ mkpart primary fat32 1M 100M \ mkpart primary ext4 100M 100% \ set 1 boot on \ set 2 lvm on else parted -s "$dev" \ mklabel gpt \ mkpart boot 1 100M \ mkpart lvm 100M 100% \ set 1 boot on\ set 2 lvm on fi } #}}} # Encrypt_drive {{{ encrypt_drive() { local dev="$1"; shift local passphrase="$1"; shift local name="$1"; shift /bin/echo -en "$passphrase" | cryptsetup luksFormat "$dev" /bin/echo -en "$passphrase" | cryptsetup luksOpen "$dev" lvm } #}}} # setup_lvm{{{ setup_lvm() { local partition="$1"; shift local volgroup="$1"; shift local d_size=$(lsblk --noheadings --nodeps --bytes --raw $DRIVE) pvcreate "$partition" vgcreate "$volgroup" "$partition" # Create a 1GB swap partition lvcreate --yes -C y -L1G "$volgroup" -n swap # if the disk has more than if [ "$d_size" -gt $(( 50*10**9 )) ] then # Create a 50GB root partition lvcreate --yes -L '50G' "$volgroup" -n root else # Create root partition on 50% of free space lvcreate --yes -l '+50%FREE' "$volgroup" -n root fi # Use the rest of the space for home lvcreate --yes -l '+100%FREE' "$volgroup" -n home # Enable the new volumes vgchange -ay } #}}} # format_filesystems #{{{ format_filesystems() { local boot_dev="$1"; shift mkfs.fat "$boot_dev" mkfs.ext4 -L root /dev/vg00/root mkfs.ext4 -L home /dev/vg00/home mkswap /dev/vg00/swap } #}}} # mount_filesystems #{{{ mount_filesystems() { local boot_dev="$1"; shift mount /dev/vg00/root /mnt mkdir /mnt/home mount /dev/vg00/home /mnt/home mkdir /mnt/boot mount "$boot_dev" /mnt/boot swapon /dev/vg00/swap } #}}} # install_base #{{{ install_base() { pacstrap /mnt $pkgs_base } #}}} # Set fstab {{{ set_fstab() { genfstab -Up /mnt > /mnt/etc/fstab } #}}} # Unmount filesystems #{{{ unmount_filesystems() { umount -R /mnt swapoff /dev/vg00/swap vgchange -an if [ -n "$ENCRYPT_DRIVE" ] then cryptsetup luksClose lvm fi } #}}} # is_bios{{{ if ls /sys/firmware/efi/efivars/ &> /dev/null then IS_BIOS=false else IS_BIOS=true fi #}}} #}}} # Configuration{{{ # configure() {#{{{ configure() { local boot_dev="$DRIVE"1 local lvm_dev="$DRIVE"2 echo 'Setting repos' set_repos echo 'Setting hostname' set_hostname "$HOSTNAME" echo 'Setting timezone' set_timezone "$TIMEZONE" echo 'Setting locale' set_locale echo 'Setting console keymap' set_inputs echo 'Configuring initial ramdisk' set_initcpio echo 'Setting initial daemons' set_daemons "$TMP_ON_TMPFS" echo 'Configuring Bluetooth' set_bluetooth echo 'Configuring bootloader' set_bootctl "$boot_dev" "$lvm_dev" echo 'Configuring sudo' set_sudoers echo 'Configuring PAM' set_pam if [ -z "$ROOT_PASSWORD" ] then echo 'Enter the root password:' read -s ROOT_PASSWORD fi echo 'Setting root password' set_root_password "$ROOT_PASSWORD" if [ -z "$USER_PASSWORD" ] then echo "Enter the password for user $USER_NAME" read -s USER_PASSWORD fi echo 'Creating initial user' create_user "$USER_NAME" "$USER_PASSWORD" echo 'setting up user' cp $0 "/home/$USER_NAME/setup.sh" chown $USER_NAME "/home/$USER_NAME/setup.sh" su $USER_NAME -c "/home/$USER_NAME/setup.sh" echo 'Updating pkgfile database' update_pkgfile shred "$0" rm "$0" } #}}} # set_repos() {{{{ set_repos() { # /etc/pacman.conf{{{ cat > /etc/pacman.conf < /etc/mirrorlist < /etc/hostname cat > /etc/hosts < /etc/locale.conf < /etc/locale.gen < /etc/X11/xorg.conf.d/30-touchpad.conf < /etc/mkinitcpio.conf < /etc/bluetooth/main.conf <> /etc/default/grub < /boot/loader/entries/arch.conf < /etc/sudoers < /etc/pam.d/login < /dev/null # Mark some packages as explicit yay -D --asexplicit $pkgs > /dev/null # Query orphan dependencies TO_REMOVE=$(yay -Qtdq) if [ -n "$TO_REMOVE" ];then # Remove queried packages yay -Rns --noconfirm $TO_REMOVE fi } #}}} # Stow dotfiles{{{ stow_dots() { if [ ! -d ~/.dotfiles ];then git clone $DOTFILES_URL ~/.dotfiles fi cd ~/.dotfiles stow */ cd - } #}}} #}}} # Update installer {{{ update_installer(){ echo "Updating installer..." INSTALLER=$(mktemp) wget -qO $INSTALLER $DOTFILES_URL/raw/master/arch_install chmod +x $INSTALLER $INSTALLER updated $@ | tee arch_install.log exit 0 } [ "$1" == "updated" ] && shift || is_chroot || update_installer $@ echo "Installer updated :D" #}}} set_pkgs if [ ! "$USER" == "root" ];then user_setup elif is_chroot;then configure else setup fi # vim:foldmethod=marker