310 lines
11 KiB
Bash
310 lines
11 KiB
Bash
#!/usr/bin/bash
|
|
|
|
# vim:ft=sh:fdm=marker:fmr={,}
|
|
# shellcheck disable=2153
|
|
|
|
# archlabs installer library script file
|
|
# this file is not meant to be run directly
|
|
# sourcing this file in a non bash shell is not advised
|
|
|
|
readonly RUN="/run/archiso/bootmnt/arch/boot"
|
|
readonly VM="$(dmesg | grep -i "hypervisor")"
|
|
|
|
install() {
|
|
# function calls prefixed with 'oneshot' will only ever be run once
|
|
# otherwise the main function can be called repeatedly
|
|
clear; tput cnorm
|
|
|
|
# unpack the file system
|
|
oneshot install_base
|
|
|
|
# generate /etc/fstab and touch it up if we used a swapfile
|
|
genfstab -U $MNT > $MNT/etc/fstab 2>$ERR
|
|
echeck "genfstab -U $MNT > $MNT/etc/fstab"
|
|
[[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" $MNT/etc/fstab
|
|
|
|
if [[ $HAS_NETWORK == true ]]; then
|
|
# update the mirrorlist.. MUST be done before updating or it may be slow
|
|
# this may already have been done if
|
|
oneshot mirrorlist_sort
|
|
|
|
# MUST be before bootloader and running mkinitcpio
|
|
oneshot package_operations
|
|
else
|
|
chrun 'pacman -Rns archlabs-installer --noconfirm'
|
|
fi
|
|
|
|
# mkinitcpio and bootloader install should only be done after installing the packages
|
|
# and updating the mirrorlist, otherwise the chosen kernel may not be fully set up
|
|
run_mkinitcpio
|
|
install_bootloader
|
|
|
|
# hwclock setup, falls back to setting --directisa if the default fails
|
|
chrun "hwclock --systohc --utc" || chrun "hwclock --systohc --utc --directisa"
|
|
|
|
# create the user
|
|
oneshot create_user
|
|
|
|
# set up user login.. MUST be done after package operation and user creation
|
|
oneshot login_manager
|
|
|
|
# drop off the user at the config editing menu
|
|
edit_system_configs
|
|
}
|
|
|
|
install_base() {
|
|
if [[ -e /run/archiso/sfs/airootfs/ ]]; then
|
|
printf "\nUnpacking base system --- Total: ~ 2.9G\n\n"
|
|
rsync -ah --info=progress2 /run/archiso/sfs/airootfs/ $MNT/
|
|
else
|
|
# update the mirrorlist.. MUST be done before pacstrapping or it may be slow
|
|
oneshot mirrorlist_sort
|
|
|
|
printf "\nPacstrapping the base system.\n\n"
|
|
local packages
|
|
packages="$(grep -hv '^#' /usr/share/archlabs/installer/packages.txt)"
|
|
local vmpkgs=""
|
|
if [[ $VM ]]; then
|
|
vmpkgs="virtualbox-guest-utils"
|
|
[[ $KERNEL == 'linux-lts' ]] &&
|
|
vmpkgs+=" virtualbox-guest-dkms linux-lts-headers" || vmpkgs+=" virtualbox-guest-modules-arch"
|
|
fi
|
|
pacstrap $MNT base $KERNEL $UCODE $packages $vmpkgs
|
|
fi
|
|
|
|
# remove archiso init files and clean up install files
|
|
rm -rf $MNT/etc/mkinitcpio-archiso.conf
|
|
find $MNT/usr/lib/initcpio -name 'archiso*' -type f -exec rm '{}' \;
|
|
|
|
# journal
|
|
sed -i 's/volatile/auto/g' $MNT/etc/systemd/journald.conf
|
|
|
|
# allow members of group 'wheel' to execute sudo commands
|
|
sed -i "s/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g" $MNT/etc/sudoers
|
|
|
|
if [[ $VM ]]; then
|
|
# in a VM remove xorg configs, these cause issues
|
|
rm -rf $MNT/etc/X11/xorg.conf.d
|
|
elif [[ $(lspci | grep ' VGA ' | grep 'Intel') != "" ]]; then
|
|
# xorg config for intel, this should never happen in a VM
|
|
cat > $MNT/etc/X11/xorg.conf.d/20-intel.conf <<EOF
|
|
Section "Device"
|
|
Identifier "Intel Graphics"
|
|
Driver "intel"
|
|
Option "TearFree" "true"
|
|
EndSection
|
|
EOF
|
|
fi
|
|
|
|
if [[ -e /run/archiso/sfs/airootfs ]]; then
|
|
# copy the kernel image for the regular kernel
|
|
[[ $KERNEL != 'linux-lts' ]] && cp -f $RUN/x86_64/vmlinuz $MNT/boot/vmlinuz-linux
|
|
|
|
# copy CPU micro-code if set. manufacturer_ucode.img -> manufacturer-ucode.img
|
|
[[ $UCODE ]] && cp -f $RUN/${UCODE/-/_}.img $MNT/boot/${UCODE}.img
|
|
fi
|
|
|
|
# copy network settings
|
|
[[ -e /etc/NetworkManager/system-connections ]] && cp -rf /etc/NetworkManager/system-connections $MNT/etc/NetworkManager/
|
|
cp -f /etc/resolv.conf $MNT/etc/
|
|
|
|
# set the locale and timezone
|
|
cat > $MNT/etc/locale.conf << EOF
|
|
LANG=$LOCALE
|
|
EOF
|
|
cat > $MNT/etc/default/locale << EOF
|
|
LANG=$LOCALE
|
|
EOF
|
|
sed -i "s/#en_US.UTF-8/en_US.UTF-8/g; s/#${LOCALE}/${LOCALE}/g" $MNT/etc/locale.gen
|
|
chrun "locale-gen" 2>/dev/null
|
|
chrun "ln -sf /usr/share/zoneinfo/$ZONE/$SUBZONE /etc/localtime" 2>/dev/null
|
|
|
|
# set the keymaps
|
|
cat > $MNT/etc/X11/xorg.conf.d/00-keyboard.conf <<EOF
|
|
# Use localectl(1) to instruct systemd-localed to update it.
|
|
Section "InputClass"
|
|
Identifier "system-keyboard"
|
|
MatchIsKeyboard "on"
|
|
Option "XkbLayout" "$KEYMAP"
|
|
EndSection
|
|
EOF
|
|
cat > $MNT/etc/default/keyboard <<EOF
|
|
# KEYBOARD CONFIGURATION FILE
|
|
# Consult the keyboard(5) manual page.
|
|
XKBMODEL=""
|
|
XKBLAYOUT="$KEYMAP"
|
|
XKBVARIANT=""
|
|
XKBOPTIONS=""
|
|
BACKSPACE="guess"
|
|
EOF
|
|
# console keymap
|
|
cat > $MNT/etc/vconsole.conf <<EOF
|
|
KEYMAP=$CMAP
|
|
FONT=$FONT
|
|
EOF
|
|
# set the hostname
|
|
cat > $MNT/etc/hostname << EOF
|
|
$HOSTNAME
|
|
EOF
|
|
cat > $MNT/etc/hosts << EOF
|
|
127.0.0.1 localhost
|
|
127.0.1.1 $HOSTNAME
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
ff02::1 ip6-allnodes
|
|
ff02::2 ip6-allrouters
|
|
EOF
|
|
return 0
|
|
}
|
|
|
|
create_user() {
|
|
# set root password
|
|
chrun "chpasswd <<< 'root:$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$ROOT_PASS")'"
|
|
|
|
# Create the user, set password, then remove temporary password file
|
|
local groups='audio,autologin,floppy,log,network,rfkill,scanner,storage,optical,power,wheel'
|
|
chrun "groupadd -r autologin"
|
|
chrun "useradd -m -u 1000 -g users -G $groups -s $MYSHELL $NEWUSER" 2>$ERR
|
|
chrun "chpasswd <<< '$NEWUSER:$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$USER_PASS")'"
|
|
chrun "chown -Rf $NEWUSER:users /home/$NEWUSER"
|
|
|
|
# remove welcome message
|
|
[[ $INSTALL_WMS =~ i3-gaps ]] || rm -rf $MNT/home/$NEWUSER/.config/i3
|
|
[[ $INSTALL_WMS =~ bspwm ]] || rm -rf $MNT/home/$NEWUSER/.config/{bspwm,sxhkd}
|
|
[[ $INSTALL_WMS =~ openbox ]] || rm -rf $MNT/home/$NEWUSER/.config/{openbox,skippy-xd,jgmenu,conky,tint2}
|
|
[[ $INSTALL_WMS =~ (openbox|i3-gaps|bspwm) ]] || rm -rf $MNT/home/$NEWUSER/.config/polybar
|
|
|
|
# for neovim copy the default vimrc and colorscheme to ~/.config/nvim
|
|
if [[ $PACKAGES =~ neovim ]]; then
|
|
mkdir -p $MNT/home/$NEWUSER/.config/nvim
|
|
cp -f $MNT/home/$NEWUSER/.vimrc $MNT/home/$NEWUSER/.config/nvim/init.vim
|
|
cp -rf $MNT/home/$NEWUSER/.vim/colors $MNT/home/$NEWUSER/.config/nvim/colors
|
|
fi
|
|
|
|
[[ $INSTALL_WMS =~ dwm ]] && suckless_install
|
|
return 0
|
|
}
|
|
|
|
login_manager() {
|
|
local service="$MNT/etc/systemd/system/getty@tty1.service.d"
|
|
|
|
# remove welcome message
|
|
sed -i '/printf/d' $MNT/root/.zshrc
|
|
|
|
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
|
|
rm -rf $service
|
|
chrun 'systemctl enable lightdm.service && systemctl set-default graphical.target'
|
|
cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf << EOF
|
|
# LightDM GTK+ Configuration
|
|
|
|
[greeter]
|
|
active-monitor=0
|
|
default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png
|
|
background=/usr/share/backgrounds/archlabs/archlabs.jpg
|
|
theme-name=Adwaita-dark
|
|
icon-theme-name=Adwaita
|
|
font-name=DejaVu Sans Mono 11
|
|
position=30%,end 50%,end
|
|
EOF
|
|
else
|
|
# xinit login
|
|
if [[ -e $MNT/home/$NEWUSER/.xinitrc ]]; then
|
|
sed -i "s/openbox-session/${LOGIN_WM}/g" $MNT/home/$NEWUSER/.xinitrc
|
|
else
|
|
printf "%s\n" "exec $LOGIN_WM" > $MNT/home/$NEWUSER/.xinitrc
|
|
fi
|
|
|
|
# automatic startx for login shells
|
|
[[ $MYSHELL == '/bin/bash' ]] && local loginrc=".bash_profile" || local loginrc=".zprofile"
|
|
EDIT_FILES[11]+="/home/$NEWUSER/$loginrc"
|
|
|
|
cat >> $MNT/home/$NEWUSER/$loginrc << EOF
|
|
# ~/$loginrc
|
|
# sourced by $(basename $MYSHELL) when used as a login shell
|
|
|
|
# automatically run startx when logging in on tty1
|
|
if [ -z "\$DISPLAY" ] && [ \$XDG_VTNR -eq 1 ]; then
|
|
exec startx -- vt1 >/dev/null 2>&1
|
|
fi
|
|
EOF
|
|
if [[ $AUTOLOGIN == true ]]; then
|
|
sed -i "s/root/${NEWUSER}/g" $service/autologin.conf
|
|
else
|
|
rm -rf $service
|
|
fi
|
|
fi
|
|
}
|
|
|
|
run_mkinitcpio() {
|
|
local add=""
|
|
# setup a keyfile for LUKS.. Only when choosing grub and system is UEFI
|
|
[[ $LUKS && ! $LVM && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]] && luks_keyfile
|
|
|
|
# new hooks needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM
|
|
[[ $LVM ]] && add="lvm2"
|
|
[[ $LUKS ]] && add="encrypt$([[ $add ]] && printf " %s" "$add")"
|
|
sed -i "s/block filesystems/block ${add} filesystems ${MKINIT_HOOKS}/g" $MNT/etc/mkinitcpio.conf
|
|
|
|
chrun "mkinitcpio -p $KERNEL" 2>$ERR
|
|
echeck "mkinitcpio -p $KERNEL"
|
|
}
|
|
|
|
mirrorlist_sort() {
|
|
printf "\n\n%s\n\n" "Sorting the mirrorlist"
|
|
if hash reflector >/dev/null 2>&1; then
|
|
$MIRROR_CMD --save $MNT/etc/pacman.d/mirrorlist --verbose ||
|
|
reflector --score 100 -l 50 -f 10 --sort rate --verbose --save $MNT/etc/pacman.d/mirrorlist
|
|
else
|
|
{ eval $MIRROR_CMD || curl -s 'https://www.archlinux.org/mirrorlist/all/'; } |
|
|
sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 10 - > $MNT/etc/pacman.d/mirrorlist
|
|
fi
|
|
}
|
|
|
|
package_operations() {
|
|
local inpkg="$PACKAGES" # add the packages chosen during setup
|
|
local rmpkg="archlabs-installer" # always remove the installer
|
|
|
|
# the LTS kernel uses different packages
|
|
if [[ $KERNEL == 'linux-lts' ]]; then
|
|
rmpkg+=" virtualbox-guest-modules-arch linux"
|
|
inpkg+=" linux-lts"
|
|
# if the system is a VM then install the needed packages otherwise remove the guest utils
|
|
[[ $VM ]] && inpkg+=" virtualbox-guest-dkms linux-lts-headers" || rmpkg+=" virtualbox-guest-utils"
|
|
else
|
|
# if the system is not a VM then remove the guest utils
|
|
[[ $VM ]] || rmpkg+=" virtualbox-guest-modules-arch virtualbox-guest-utils"
|
|
fi
|
|
|
|
# for only gnome or cinnamon we don't need the xfce provided stuff
|
|
[[ $INSTALL_WMS =~ (gnome|cinnamon) ]] && rmpkg+=" $(pacman -Qssq 'xfce4*' 2>/dev/null)"
|
|
|
|
# when not using grub bootloader remove it's package and configurations
|
|
if [[ $BOOTLDR != 'grub' ]]; then
|
|
rmpkg+=" grub"
|
|
rm -f $MNT/etc/default/grub
|
|
find $MNT/boot/ -name 'grub*' -exec rm -rf '{}' \; >/dev/null 2>&1
|
|
elif [[ $BOOTLDR != 'syslinux' ]]; then
|
|
# do the same when not using syslinux as the bootloader
|
|
find $MNT/boot/ -name 'syslinux*' -exec rm -rf '{}' \; >/dev/null 2>&1
|
|
fi
|
|
|
|
# iputils, base-devel, and git are all needed and should always be installed separately
|
|
chrun "pacman -Syyu --noconfirm"
|
|
chrun "pacman -S iputils --noconfirm; pacman -S base-devel git --needed --noconfirm"
|
|
chrun "pacman -S $inpkg --needed --noconfirm"
|
|
chrun "pacman -Rs $rmpkg --noconfirm"
|
|
return 0
|
|
}
|
|
|
|
suckless_install() {
|
|
# install and setup dwm
|
|
printf "\n\n%s\n\n" "Installing and setting up dwm."
|
|
mkdir -pv $MNT/home/$NEWUSER/suckless
|
|
for i in dwm dmenu st; do
|
|
p="/home/$NEWUSER/suckless/$i"
|
|
chrun "git clone https://bitbucket.org/natemaia/$i $p && { cd $p; rm -f $p/config.h 2>/dev/null; make clean install && make clean; }"
|
|
done
|
|
printf "\n\n%s\n\n" "To configure dwm edit /home/$NEWUSER/suckless/dwm/config.h and recompile with 'sudo make clean install'"
|
|
sleep 2
|
|
}
|
|
|