aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/install.sh
blob: 27864993cda8996886a69e89d73f8c379b78ef85 (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
39
#!/bin/sh
# shellcheck disable=SC2035,SC2086

set -e

CDPATH='' cd -- "$(dirname -- "$0")" || exit

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
	if [ -f .untracked ]; then
		cat .untracked
	fi
} | sort -u | sed -n 's/^[^/]\+\//..\//p' | while read -r f; do
	if [ -L "$f" ] && [ ! -e "$f" ]; then
		rm -v "$f"
	fi
done

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

printf "%s: Stowing packages\n" "$0"
stow "$@" ${1:-*}/

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

git rev-parse ^@ >.installed