ambevar-dotfiles/.local/bin/homeinit

132 lines
3.0 KiB
Plaintext
Raw Normal View History

#!/bin/sh
## Home session initialization.
if [ "$1" = "-h" ]; then
cat <<EOF>&2
Usage: ${0##*/}
Initialize home folder.
Options:
-u: Skip large updates (packages, etc.)
EOF
exit
fi
OPT_UPDATE=true
OPT_GO="-u"
if [ "$1" = "-u" ]; then
OPT_UPDATE=false
OPT_GO=""
shift
fi
2016-10-12 11:03:57 +02:00
SOURCEDIR="$HOME/personal"
2012-10-29 15:29:54 +01:00
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
[ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share"
## ln no-clobber
lnn() {
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
}
## git-update <repo> <dest-folder>
git_update() {
if [ -e "$2" ]; then
pushd "$2"
git pull
popd
else
git clone "$1" "$2"
fi
}
2017-07-29 10:31:30 +02:00
echo "==> System packages"
if command -v pacman >/dev/null 2>&1; then
pacman_list=""
if [ -f ~/.pkglists/arch-official ]; then
pacman_list="$(cat ~/.pkglists/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 ~/.pkglists/arch-aur ]; then
pacaur --noconfirm --noedit -y --needed "$(cat ~/.pkglists/arch-aur)"
fi
pacman_list=$(pacman -Qdtq)
if [ -n "$pacman_list" ]; then
sudo pacman --noconfirm -Rs "$pacman_list"
fi
fi
echo "==> 'temp' folder"
mkdir -pv "$HOME/temp"
echo "==> Bookmarks"
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/"
if command -v emacs >/dev/null 2>&1; then
if $OPT_UPDATE; then
echo "==> Emacs ELPA packages"
yes | emacs --batch -l ~/.emacs.d/init.el --eval '(progn (package-refresh-contents) (package-install-selected-packages))'
fi
echo "==> Emacs extra packages"
mkdir -pv ~/.emacs.d/site-lisp
fi
echo "==> Go path"
2016-09-24 03:48:47 +02:00
mkdir -pv "$HOME/go" "$HOME/.go-tools"
if command -v go >/dev/null 2>&1; then
echo "==> Go extra dev tools"
2016-09-24 03:48:47 +02:00
export GOPATH="$HOME/.go-tools"
export PATH="$PATH:$GOPATH/bin"
go get -v $OPT_GO -ldflags "-s -w" github.com/alecthomas/gometalinter && gometalinter -i $OPT_GO
strip -s "$GOPATH"/bin/*
## See https://dominik.honnef.co/posts/2014/12/an_incomplete_list_of_go_tools/.
## https://dominik.honnef.co/go/
go get -v $OPT_GO -ldflags "-s -w" \
github.com/nsf/gocode \
github.com/rogpeppe/godef
fi
echo "==> Mail"
lnn "$SOURCEDIR/mail/mbsyncrc" "$HOME/.mbsyncrc"
lnn "$SOURCEDIR/mail/authinfo.gpg" "$HOME/.authinfo.gpg"
mkdir -pv "$HOME/.cache/mail/"
if $OPT_UPDATE; then
while IFS= read -r i; do
## We get a shell command, so we need to evaluate it to expand "~".
eval "$i"
done <<EOF
2017-07-29 10:31:30 +02:00
$(awk '/^Path/ {$1="mkdir -pv"; print}' ~/.mbsyncrc)
EOF
fi
2017-07-29 10:31:30 +02:00
if $OPT_UPDATE; then
mbsync -aV
mu index --maildir=~/.cache/mail
fi