aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/install.sh
blob: 338b9761445b66fe2f758953c7cd71962f390e27 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

SCRIPT="$(basename "$0")"
SCRIPT_DIR="$(dirname -- "$(readlink -f -- "$0")")"
INSTALL_DIR="$(dirname "$SCRIPT_DIR")"

long='clean-only,help'
short='ch'

if ! opts="$(getopt -o $short -l $long -n "$SCRIPT" -- "$@")"; then
	exit 1
fi

eval set -- "$opts"

help() {
	cat <<-EOF
		$SCRIPT
		Toby Vincent <tobyv@tobyvin.dev>

		$SCRIPT
		    Installer script that is a simple wrapper around GNU stow that removes broken symlinks
		    found in $INSTALL_DIR, stows all packages, and runs all ./*/install.sh scripts.

		USAGE:
		    $SCRIPT [OPTION ...]

		OPTIONS:
		    -h, --help            Show this help.
	EOF
}

clean_only=false
while true; do
	case "$1" in
	-h | --help)
		help
		exit 0
		;;
	-c | --clean-only)
		clean_only=true
		shift
		;;
	--)
		shift
		break
		;;
	*)
		exit 1
		;;
	esac
done

find . -type l -exec sh -c 'for x; do [ -e "$x" ] || rm -v "$x"; done' _ {} +

if $clean_only; then
	exit 0
fi

stow "$@" -- */

for f in "$SCRIPT_DIR"/*/install.sh; do
	$f
done