Personal configuration files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

261 lines
7.6 KiB

#!/bin/sh
DOTFILES_DIR=$HOME/dotfiles
CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}
# Create configuration and local directories
CONFIG_DIRS="$HOME/.config/vifm \
$HOME/.config/zsh \
$HOME/.config/tmux \
$HOME/.config/vifm \
$HOME/.config/taskell \
$HOME/.config/gcalcli \
$HOME/.config/emacs \
$HOME/.cache/zsh \
$HOME/.cache/mpd \
$HOME/.mozilla/firefox/profile \
$HOME/.local/bin \
$HOME/.local/share/gnupg \
$HOME/.local/share/fonts \
$HOME/.local/share/mpd/playlists \
$HOME/.local/share/abook \
$HOME/dev/todo \
"
pre_up() {
for dir in "$CONFIG_DIRS"; do
if [ ! -d "$dir" ]; then
case "$dir" in
"gnupg")
mkdir -p -m 700 "$dir"
;;
*)
mkdir -p "$dir"
;;
esac
fi
done
}
# Use stow to create symlinks and initialise some programs
do_up() {
if [ -x "$(command -v find)" ]; then
stow_dirs="$(find . -maxdepth 1 ! -name \
'assets' ! -name '.*' -type d -printf '%f\n')"
for dir in "$stow_dirs"; do
case "$dir" in
browser)
stow --adopt "$dir"
[ ! -d ~/.local/share/tridactyl ] &&
curl -fsSl \
https://raw.githubusercontent.com/tridactyl/tridactyl/master/native/install.sh \
-o /tmp/trinativeinstall.sh &&
bash /tmp/trinativeinstall.sh 1.20.2>/dev/null 2>&1
;;
key)
([ ! -d ~/.local/share/qmk ] && \
[ -x "$(command -v qmk)" ]) &&
qmk setup -H ~/.local/share/qmk
stow --adopt "$dir"
;;
mail)
stow --adopt "$dir"
inboxes="$(find "$DOTFILES_DIR"/mail/.config/mutt/accounts -type f -printf '%f\n')"
if [ ! -f ~/.local/share/password-store/.gpg-id ]; then
! find ~/.local/share/gnupg -iname "*.kbx" -o -iname "*.gpg" &&
gpg2 --generate-key
pass init \
$(gpg2 --list-keys | awk -F'[<|>]' '{print $2}')
for inbox in $inboxes; do
[ ! -d $HOME/.local/share/Mail/$inbox ] && mkdir -p $HOME/.local/share/Mail/$inbox
if [ ! -f ~/.local/share/password-store/mail/$inbox.gpg ]; then
pass add "mail/"$inbox""
else
continue
fi
done
else
for inbox in $inboxes; do
[ ! -d ~/.local/share/Mail/$inbox ] && mkdir -p ~/.local/share/Mail/$inbox
if [ ! -f ~/.local/share/password-store/mail/$inbox.gpg ]; then
pass add "mail/"$inbox""
else
continue
fi
done
fi
mbsync -c "$CONFIG_DIR"/isync/mbsyncrc -a
;;
"chat")
[ "$(find ~/.local/share/signal-cli/data -type f | wc -l)" -eq 0 ] && sl
stow --adopt "$dir"
;;
*)
stow --adopt "$dir" ;;
esac
done
fi
}
# Unlock gpg/ssh keys on login
keys() {
doas cat <<EOF >> /etc/pam.d/system-local-login
auth required pam_env.so user_readenv=1
auth optional pam_gnup.so
session optional pam_gnupg.so
EOF
# Grab the keygrip for the main GPG key
[ -f $CONFIG_DIR/pam-gnupg ] && gpg2 -K --with-keygrip | tail -n 2 | head -n 1 | awk -F"= " '{print $2}' > $HOME/.config/pam-gnupg
cat <<EOF > ~/.pam_environment
GNUPG DEFAULT=@{HOME}/.local/share/gnupg
EOF
echo "allow-preset-passphrase
max-cache-ttl 34560000" >> $XDG_DATA_HOME/gnupg/gpg-agent.conf
# Add a GPG subkey to currently used GPG key
gpg2 --expert --edit-key $(gpg2 --list-keys | awk '/uid/{print $4}' | tr -d '<>')
[ -f ~/.config/pam-gnupg ] && gpg2 -K --with-keygrip | tail -n 2 | head -n 1 | awk -F"= " '{print $2}' | tee -a $XDG_CONFIG_HOME/pam-gnupg $XDG_DATA_HOME/gnupg/sshcontrol
echo "enable-ssh-support
max-cache-ttl-ssh 34560000" >> $XDG_DATA_HOME/gnupg/gpg-agent.conf
# Specify SSH how to access gpg-agent
cat <<EOF >> $XDG_CONFIG_HOME/zsh/.zprofile
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent
EOF
# Copy newly generated keys to clipboard
ssh-add -L | xclip -se c
}
# Load kernel modules
mod() {
# modinfo -p to show info about available
# options of kernel modules
# lsbusb to get vid and pid
# if the parameters below don't work, one can try
# options snd-hda-intel dmic_detect=0
if [ -f /etc/modprobe.d/alsa.conf ]; then
$(command -v doas) && doas cat <<EOF > /etc/modprobe.d/alsa.conf
options snd-hda-intel index=0 model=alc255-asus,headset-mic
options snd-usb-audio index=1,2 vid=0x0c76,0x046d pid=0x161f,0x0826
EOF
fi
# Set up ddcutil
$(command -v ddcutil) &&
doas modprobe i2c-dev
echo "i2c-dev" | doas tee /usr/lib/modules-load.d/i2c-dev.conf
doas groupadd --system i2c
doas usermod -G i2c -a "$USER"
doas mkdir /etc/udev/rules.d
for device in i2c usb; do
doas cp /usr/share/ddcutil/data/45-ddcutil-${device}.rules /etc/udev/rules.d
done
# Enable bluetooth on startup
sed -i "s/AutoEnabled=no/AutoEnabled=yes" /etc/bluetooth/main.conf
}
# Unlock git-encrypted files
unlock() {
encrypted_files="$(git-crypt status | grep -v '^not')"
echo "The following files are encrypted\n\
$encrypted_files"
git-crypt unlock
}
# Create symlinks
sym() {
# Autoload wee-slack plugins on startup
for plugin in wee-slack weechat-notify-send weechat-matrix weechat-autosort; do
[ xpkg -L | grep "$plugin" ] &&
case "$plugin" in
slack)
curl -sfL https://raw.githubusercontent.com/wee-slack/wee-slack/master/weemoji.json -o ~/.config/weechat/weemoji.json ;;
esac
ln -s /usr/share/weechat/python/"$plugin".py ~/.config/weechat/python/autoload/
done
}
# Set up services
sv() {
for service in \
chronyd docker sshd wpa_supplicant \
mpd dbus dhcpcd elogind acpid crond cronie \
bluetoothd bluez-alsa socklog-unix \
nanoklogd sndiod transmission-daemon; do
doas ln -s /etc/sv/"$service" /var/service
done
# Unlink unused ttys
i=8
while [ "$i" -gt 2 ]; do
doas unlink /var/service/agetty-tty"$i"
i=$((i - 1))
done
# Set up sndio conf
[ -f /etc/sv/sndiod/conf ] &&
echo 'OPTS="-v 127 -f rsnd/PCH -F rsnd/Device"' | doas tee -a /etc/sv/sndiod/conf
# Set up Wireguard
doas chmod 700 /etc/wireguard/
}
# Generate a list of installed packages
bak() {
xbps-query -m > pkglist.txt && echo "Package list updated!"
}
# Permissions
perm() {
doas usermod -aG bluetooth,docker,socklog $USER
echo "
permit persist keepenv $USER as root
permit nopass $USER cmd shutdown
permit nopass $USER cmd xi
permit nopass $USER cmd input
permit nopass $USER cmd wg-quick
permit nopass $USER cmd wg
permit nopass $USER cmd find
permit nopass $USER cmd sv
permit nopass $USER cmd zzz
" | doas tee -a /etc/doas.conf
}
# Cronjobs
cron() {
(crontab -l; echo "*/10 * * * * /usr/bin/gcalcli remind 30 '/usr/bin/notify-send -i appointment-soon -a /usr/bin/gcalcli %s --military'") | crontab -
}
# Install Perl x32 headers for fzfimg
install_ph() {
[ xbps-query -m | grep -q 'glibc-devel-32bit' ] && cd /usr/include; h2ph -r -l;
}
# Remove packages that break base dependencies
ignore_pkg() {
echo "ignorepkg=sudo" | doas tee -a /etc/xbps.d/10-ignore.conf
doas xbps-remove sudo
doas ln -s doas /bin/sudo
}
# Set GUI settings
gui() {
if [ $(command -v gsettings) ]; then
gsettings set org.gtk.Settings.FileChooser show-hidden true
gsettings set org.gtk.Settings.FileChooser startup-mode cwd
gsettings set org.gtk.Settings.FileChooser sort-directories-first true
fi
}
case "$1" in
--dirs) pre_up ;;
--init) up ;;
--sub) sub ;;
--keys) gpg ;;
--audio) audio ;;
--unlock) unlock ;;
*)
pre_up && up && sub &&
gpg && audio && unlock
;;
esac