summaryrefslogtreecommitdiffstats
path: root/install.sh
blob: 9922a43d86d6d7c18527f9194fb00b2cdc0986c8 (plain) (blame)
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
#!/bin/sh -e

if [ "$#" -ne 1 ]; then
	# make sure all submodules are there
	git submodule update --init --recursive

	# ensure mail directory exists
	mkdir -p ~/.mail/tharre3@gmail.com

	find . -maxdepth 1 ! -path . ! -name .git ! -name .gitmodules \
		! -name .gitignore ! -name .updated -name '.*' -exec "$0" {} \;
else
	canonical=$(echo $1 | sed "s|^\./||")
	target="$HOME/$canonical"
	origin="$(pwd)/$canonical"

	if [ ! -e "$target" ] || [ -L "$target" ]; then
		# target either doesn't exist or is a symbolic link and can thus be
		# safely replaced
		ln -sfn "$origin" "$target"
	elif [ -d "$target" ]; then
		# target is not a symbolic link, but a directory, thus we link
		# everything into that directory instead

		find "$canonical" -maxdepth 1 -mindepth 1 ! -name .gitignore \
			-exec "$0" {} \;
	else
		echo "Target file '$target' exists, but is not a symlink. Skipping."
	fi
fi