dotfiles/scripts/install-arch

106 lines
2.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# Setups an Arch Linux system the way I like it
# (requires sudo)
2017-11-02 16:48:43 +01:00
if ! which pacman &> /dev/null; then
echo "This is not an Arch Linux system (or pacman isn't installed)"
2017-11-02 16:48:43 +01:00
exit 1
fi
# Configuration
function prompt { # text
while true; do
read -p "$1 [yn] " yn
case $yn in
[Yy]* ) return 1;;
[Nn]* ) return 0;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Don't ask for things that are already there
2018-10-06 10:27:36 +02:00
if which aurman &> /dev/null; then
AURMAN=1
fi
2018-10-06 10:27:36 +02:00
if [ -z $AURMAN ]; then
prompt "Do you want aurman on this machine?"
AURMAN=$?
fi
# COMMON
# Install packages if they aren't installed
function inst {
2018-10-06 10:27:36 +02:00
# Could also use --needed but, meh
for pkg in $*; do
pacman -Q $pkg &> /dev/null
if [ $? == 1 ]; then
sudo pacman -S $pkg --noconfirm
fi
done
}
# Install package from PKGBUILD file
function installPKGBUILD { # url
2017-11-02 16:48:43 +01:00
# TODO Download snapshots
TMP_DIR="$(mktemp -d /tmp/pkgbuild.XXXXXXXXXX)"
cd "$TMP_DIR"
wget "$1" -O PKGBUILD
2017-11-02 16:48:43 +01:00
makepkg -si --noconfirm
cd -
rm -rf "$TMP_DIR"
}
# SYSTEM
inst wget
2017-11-02 16:48:43 +01:00
# Aur
2018-10-06 10:27:36 +02:00
pacman -Q aurman &> /dev/null
if [[ $AURMAN == 1 && $? == 1 ]]; then
2018-10-08 23:52:53 +02:00
gpg --recv-keys 465022E743D71E39
2018-10-06 10:27:36 +02:00
installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=aurman"
fi
2017-11-02 16:48:43 +01:00
# Git for /etc
2018-10-06 10:27:36 +02:00
inst etckeeper
2017-11-02 16:48:43 +01:00
sudo etckeeper init
2018-10-08 23:52:53 +02:00
(cd /etc/; sudo git config user.name "etckeeper on $(cat /etc/hostname)"; sudo git config user.email "etckeeper@$(cat /etc/hostname)")
2017-11-02 16:48:43 +01:00
sudo etckeeper commit "~/.dotfiles/scripts/install-arch commit"
2018-10-08 23:52:53 +02:00
2017-11-02 16:48:43 +01:00
# Uninstall Manjaro's pamac
if pacman -Q pamac &> /dev/null ; then
sudo pacman -Rsc pamac --noconfirm
fi
2017-11-02 16:48:43 +01:00
# Ccache
2018-10-06 10:27:36 +02:00
inst ccache
2017-11-02 16:48:43 +01:00
sudo sed 's|BUILDENV=\(.\+\)!ccache\(.\+\)|BUILDENV=\1ccache\2|' /etc/makepkg.conf -i
# TLP
2018-10-06 10:27:36 +02:00
inst tlp
2017-11-02 16:48:43 +01:00
sudo sed 's|SATA_LINKPWR_ON_BAT=min_power|SATA_LINKPWR_ON_BAT=max_performance|' /etc/default/tlp -i
sudo systemctl enable tlp.service tlp-sleep.service
sudo systemctl disable systemd-rfkill.service systemd-rfkill.socket
sudo tlp start
# Numlock on boot
echo -e "[Service]\nExecStartPre=/bin/sh -c 'setleds +num < /dev/%I'" | sudo systemctl edit getty\@.service
# Makeflags
sudo sed "s|#MAKEFLAGS=\"-j2\"|MAKEFLAGS=\"-j$(nproc)\"|" /etc/makepkg.conf -i
# Time synchronisation
2018-10-06 10:27:36 +02:00
inst ntp
2017-11-02 16:48:43 +01:00
sudo systemctl start ntpd
sudo systemctl enable ntpd
# MANUAL
# Hibernation
# Add resume=UUID=<UUID-of-swap-partition> to GRUB_CMDLINE_LINUX_DEFAULT and run `sudo grub-mkconfig -o /boot/grub/grub.cfg`