ambevar-dotfiles/.local/bin/homeinit

215 lines
5.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
## Initialize and update user profile.
[ -z "$SOURCEDIR" ] && SOURCEDIR="$HOME/personal"
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
[ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share"
[ -z "$EMACS_MIN_VERSION" ] && EMACS_MIN_VERSION=26
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
cat <<EOF>&2
Usage: ${0##*/}
Initialize home folder.
Options:
-u: Skip large updates (packages, emails, etc.)
Environment variables:
SOURCEDIR=$SOURCEDIR
XDG_CONFIG_HOME=$XDG_CONFIG_HOME
XDG_DATA_HOME=$XDG_DATA_HOME
EMACS_MIN_VERSION=$EMACS_MIN_VERSION
EOF
exit
fi
OPT_UPDATE=true
if [ "$1" = "-u" ]; then
OPT_UPDATE=false
shift
fi
RED='\033[0;31m\033[1m'
GREEN='\033[0;32m\033[1m'
YELLOW='\033[0;33m\033[1m'
BOLD='\033[0m\033[1m'
NORMAL='\033[0m'
section() {
echo -e "$GREEN==> $@$NORMAL"
}
message() {
echo -e "$YELLOW:: $@$NORMAL"
}
warning() {
echo -e "${YELLOW}WARNING:: $@$NORMAL"
}
## "ln" wrapper.
## If $2 is a folder, create the link in it using the basename of $1.
## Existing files are no clobbered, unless they already are a symlink.
lnn() { # $1=TARGET $2=LINK|FOLDER
2018-01-11 11:19:20 +01:00
if [ -d "$2" ]; then
set -- "$1" "$2/$(basename "$1")"
fi
if [ ! -e "$2" ] || [ -h "$2" ]; then
ln -svnf "$1" "$2"
fi
}
################################################################################
section "Initial packages"
if command -v guix >/dev/null 2>&1; then
guix package --install gnupg git stow password-store
elif command -v pacman >/dev/null 2>&1; then
sudo pacman --noconfirm -S --needed gnupg git stow password-store
fi
section "GPG"
if [ -d ~/.gnupg ]; then
chmod go-rwx ~/.gnupg ~/.gnupg/*
## TODO: Got to start gpg-agent first?
if [ -e "$SOURCEDIR" ]; then
git -C "$SOURCEDIR" pull
else
git clone git@gitlab.com:Ambrevar/personal
fi
if [ -e ~/.password-store ]; then
git -C ~/.password-store pull
else
git clone git@gitlab.com:Ambrevar/password-store ~/.password-store
## The following is necessary to make sure the 'diff' GPG filter is properly set up.
pass git init
fi
else
warning "~/.gnupg not found."
fi
section "Persistent folders"
for i in .emacs.d .local/share projects temp; do
mkdir -pv "$HOME/$i"
done
section "dotfiles"
if [ -e ~/dotfiles ]; then
git -C ~/dotfiles remote set-url origin git@gitlab.com:Ambrevar/dotfiles
git -C ~/dotfiles pull
else
git clone git@gitlab.com:Ambrevar/dotfiles
fi
pushd ~/dotfiles
stow -v .
popd
2017-07-29 10:31:30 +02:00
section "System packages"
if command -v guix >/dev/null 2>&1; then
## TODO: The manifest will uninstall other unspecified packages. Is this
## really what we want?
guix package --manifest=~/.package-lists/guix
## TODO: Delete setup generation (gnupg, git, stow)?
elif command -v pacman >/dev/null 2>&1; then
pacman_list=""
if [ -f ~/.package-lists/arch-official ]; then
pacman_list="$(cat ~/.package-lists/arch-official)"
fi
sudo pacman --noconfirm -S --needed base base-devel $pacman_list
if ! command -v cower >/dev/null 2>&1; then
mkdir -p /tmp/cower
pushd /tmp/cower
curl https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=cower > PKGBUILD
makepkg --noconfirm -si
popd
fi
if ! command -v pacaur >/dev/null 2>&1; then
mkdir -p /tmp
cower -d pacaur
pushd /tmp/pacaur
makepkg --noconfirm -si
popd
fi
if $OPT_UPDATE && [ -f ~/.package-lists/arch-aur ]; then
pacaur --noconfirm --noedit -y --needed "$(cat ~/.package-lists/arch-aur)"
fi
pacman_list=$(pacman -Qdtq)
if [ -n "$pacman_list" ]; then
sudo pacman --noconfirm -Rs "$pacman_list"
fi
fi
section "Bookmarks"
if command -v qutebrowser >/dev/null 2>&1; then
mkdir -pv "$XDG_CONFIG_HOME/qutebrowser/bookmarks"
lnn "$SOURCEDIR/bookmarks/bookmarks" "$XDG_CONFIG_HOME/qutebrowser/bookmarks/urls"
lnn "$SOURCEDIR/bookmarks/quickmarks" "$XDG_CONFIG_HOME/qutebrowser/"
fi
section "Emacs"
if ! command -v emacs >/dev/null 2>&1 || \
[ $(emacs --quick --batch --eval '(message "%s" emacs-major-version)' 2>&1) -lt $EMACS_MIN_VERSION ]; then
message "Emacs: Installing latest development version"
pushd "$HOME/projects"
[ -e emacs ] || git clone https://git.savannah.gnu.org/git/emacs.git
mkdir -pv ../emacs-build
cd ../emacs-build
../emacs/configure \
--disable-gtk-deprecation-warnings \
--without-pop \
--without-kerberos \
--without-kerberos5 \
--with-x-toolkit=gtk3 \
--with-jpeg \
--with-tiff \
--with-gif \
--with-png \
--with-rsvg \
--with-xml2 \
--with-imagemagick \
--with-xft \
--with-libotf \
--without-gsettings \
--without-gconf \
--with-gnutls \
--with-modules \
--with-threads
sudo make install
popd
2018-02-16 14:18:28 +01:00
fi
if command -v emacs >/dev/null 2>&1; then
message "Emacs cache folder"
2018-02-16 14:18:28 +01:00
mkdir -pv "$HOME/.cache/emacs/"
if ! command -v guix >/dev/null 2>&1; then
if $OPT_UPDATE; then
message "Emacs ELPA packages"
yes | emacs --batch -l ~/.emacs.d/init.el --eval '(progn (package-refresh-contents) (package-install-selected-packages))'
fi
fi
message "Emacs local packages"
2018-05-18 11:33:53 +02:00
mkdir -pv ~/.local/share/emacs/site-lisp
for i in ~/.local/share/emacs/site-lisp/*; do
echo "$i"
git -C "$i" pull
done
fi
section "Mail"
lnn "$SOURCEDIR/mail/mbsyncrc" "$HOME/.mbsyncrc"
lnn "$SOURCEDIR/mail/authinfo.gpg" "$HOME/.authinfo.gpg"
mkdir -pv "$HOME/.cache/mail/"
while IFS= read -r i; do
mkdir -pv $i
done <<EOF
$(awk '/^Path/ {print $2}' ~/.mbsyncrc)
EOF
2017-07-29 10:31:30 +02:00
if $OPT_UPDATE; then
mbsync -aV
mu index --maildir=~/.cache/mail
fi