dotfiles/provision_linux

300 lines
6.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env fish
#
set general_help '
A collection of useful functions for provisioning arch/debian linux.
Either run a function like ./provision_linux <function> [arg [arg [...]]
or source the file and run them as commands:
$ source ./provision_linux
$ lint [args]
Run ./provision_linux <function_name> to see it\'s definition.
'
### Config ###
2021-01-19 05:43:37 +00:00
set -g distro
2021-01-19 05:43:37 +00:00
for line in (cat /etc/os-release)
set -l items (string split --max 1 '=' $line)
if test $items[1] = ID
2021-01-19 05:43:37 +00:00
set distro $items[2]
end
end
### Commands ###
function terminal_env -d 'Install base terminal utilities and sync configurations'
if test $distro = arch
log 'Installing pikaur from AUR'
install_pkgs --needed base-devel
set -l cwd (pwd)
set -l tmp_dir (mktemp --directory)
git clone https://aur.archlinux.org/pikaur.git $tmp_dir
and cd $tmp_dir
and makepkg --clean --install --rmdeps --syncdeps --noconfirm
cd $cwd
rm -rf $tmp_dir
end
set -l base_pkgs \
fish \
git \
neovim \
tmux \
rsync \
curl \
kitty-terminfo \
fzf \
nnn
set -l arch_pkgs \
$base_pkgs \
python-neovim \
the_silver_searcher \
bat \
sysz
set -l debian_pkgs \
$base_pkgs \
silversearcher-ag
log 'Installing base terminal utilities'
install_pkgs
or return $status
log 'Setting m\'s default shell to fish'
sudo chsh -s /usr/bin/fish m
log 'Running sync script'
./sync --desktop
log 'Installing asdf-vm'
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
and cd ~/.asdf
and git checkout (git describe --abbrev=0 --tags)
end
function desktop_env -d 'Install base desktop utilities and configure theme'
set -l base_pkgs \
xclip \
bspwm \
sxhkd \
picom \
feh \
rofi \
kitty \
qutebrowser \
wget \
unzip \
physlock \
pipewire \
playerctl \
tar \
xz
set -l arch_pkgs \
$base_pkgs \
xorg-server \
xorg-xinit \
ttf-ibm-plex \
ttf-jetbrains-mono \
pavucontrol \
wmname \
pipewire-pulse \
pipewire-alsa \
polybar \
light \
slock
set -l debian_pkgs \
$base_pkgs \
xinit \
fonts-ibm-plex \
suckless-tools \
polybar
log 'Installing base desktop environment utilities'
install_pkgs
or return $status
log 'Setting xinitrc'
echo '#!/bin/sh
userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap
# merge in defaults and keymaps
if [ -f $sysresources ]; then
xrdb -merge $sysresources
fi
if [ -f $sysmodmap ]; then
xmodmap $sysmodmap
fi
if [ -f "$userresources" ]; then
xrdb -merge "$userresources"
fi
if [ -f "$usermodmap" ]; then
xmodmap "$usermodmap"
fi
# start some nice programs
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
[ -x "$f" ] && . "$f"
done
unset f
fi
rm -f $HOME/.bspwm_no_lock
exec bspwm' >~/.xinitrc
log 'Installing arc-gruvbox theme'
mkdir -p ~/.themes
xzcat ./oomox-arc-gruvbox.tar.xz | tar --extract --directory=$HOME/.themes
if test $distro = debian
log 'Installing JetBrains Mono font manually'
set -l cwd (pwd)
set -l tmp_dir (mktemp --directory)
cd $tmp_dir
wget -q https://github.com/JetBrains/JetBrainsMono/releases/download/v2.002/JetBrainsMono-2.002.zip
and unzip -q JetBrainsMono-2.002.zip
and mkdir -p ~/.local/share/fonts/truetype/JetBrainsMono
and cp ./ttf/*.ttf ~/.local/share/fonts/truetype/JetBrainsMono/
cd $cwd
rm -r $tmp_dir
end
log 'Setting gtk theme'
mkdir ~/.config/gtk-3.0
echo "
[Settings]
gtk-icon-theme-name = Adwaita
gtk-theme-name = oomox-arc-gruvbox
gtk-font-name = IBM Plex Sans 11" >~/.config/gtk-3.0/settings.ini
end
function m_net -d 'Install syncthing and keepassxc'
log 'Installing m-net utilities'
install_pkgs \
wireguard-tools \
keepassxc \
syncthing
or return $status
log 'Enabling syncthing service'
sudo systemctl enable syncthing@m.service
end
function libvirt -d 'Provision libvirt and virt-manager'
log 'Installing libvirt, qemu, and virt-manager'
install_libvirt
end
function vagrant -d 'Provision vagrant with libvirt'
install_libvirt
or return $status
log 'Installing vagrant and libvirt plugin'
set -l arch_pkgs vagrant
set -l debian_pkgs vagrant-libvirt
install_pkgs
or return $status
vagrant plugin install vagrant-libvirt
end
function install_libvirt
set -l base_pkgs \
virt-manager \
virt-install \
virt-viewer
set -l arch_pkgs \
$base_pkgs \
libvirt \
qemu \
dnsmasq \
ebtables
set -l debian_pkgs \
$base_pkgs \
qemu-system \
libvirt-clients \
libvirt-daemon-system
install_pkgs
log 'Adding m to libvirt group and enabling libvirtd service'
switch $distro
case debian
sudo adduser m libvirt
case arch
sudo gpasswd -a m libvirt
end
sudo systemctl enable libvirtd.service
end
function install_pkgs -S
switch $distro
case arch
set -l cmd pacman
if command -q pikaur
set cmd pikaur
end
sudo $cmd --sync --refresh --sysupgrade --noconfirm
sudo $cmd --sync --noconfirm $arch_pkgs $argv
case debian
sudo apt-get --quiet --yes update
sudo apt-get --quiet --yes upgrade
sudo apt-get --quiet --yes install $debian_pkgs $argv
end
end
function log -a message
echo \n"--- $message ---"\n
end
# --- execution/help handling ---
function help -a function_name -d 'Displays help for internal function'
if test -n "$function_name"
functions $function_name
else
echo $general_help
end
end
argparse --ignore-unknown h/help -- $argv
if test -n "$_flag_h"
help $argv
else if test -n "$argv"
$argv
else
echo $general_help
end