aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/install.sh
blob: 28039710b35e1d2a59a139d54695785d0019c87a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

set -e

CDPATH='' cd -- "$(dirname -- "$0")" || exit
TARGET=${TARGET:-$HOME}

if [ -r .installed ]; then
	read -r DOTFILES_INSTALLED <.installed
	export DOTFILES_INSTALLED
fi

printf "%s: Removing bad links\n" "$0"
{
	git log --name-only --no-renames --diff-filter=D --format=format: "$DOTFILES_INSTALLED" HEAD
	git diff --name-only --no-renames --diff-filter=D HEAD
	cat .untracked 2>/dev/null
} | sort -u | while read -r f; do
	if [ -L "$TARGET/${f#*/}" ] && [ ! -e "$TARGET/${f#*/}" ]; then
		rm -v "$TARGET/${f#*/}"
	fi
done

git ls-files --exclude-standard --others >.untracked
if [ ! -s .untracked ]; then
	rm -f .untracked
fi

printf "%s: Stowing packages\n" "$0"
# shellcheck disable=SC2086
stow "$@" ${1:-*}/

printf "%s: Installing packages\n" "$0"
for f in ${1:-*}/install.sh; do
	$f
done

git rev-parse ^@ >.installed