-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
53 lines (43 loc) · 1.19 KB
/
install.sh
File metadata and controls
53 lines (43 loc) · 1.19 KB
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
#!/usr/bin/env bash
set -eu -o pipefail
errorf() {
printf "%s\n" "$*" >&2
exit 1
}
script_dir() {
local script_source
local resolved_dir
script_source="${BASH_SOURCE[0]}"
if [[ ! -f "${script_source}" ]]; then
errorf "remote execution is disabled; clone the repository locally and run ./install.sh"
fi
resolved_dir="$(cd -- "$(dirname -- "${script_source}")" && pwd -P)"
if [[ ! -f "${resolved_dir}/Makefile" ]] || [[ ! -f "${resolved_dir}/install.sh" ]]; then
errorf "remote execution is disabled; clone the repository locally and run ./install.sh"
fi
printf "%s\n" "${resolved_dir}"
}
require_local_checkout() {
if [[ ! -f "${DOTPATH}/Makefile" ]]; then
errorf "${DOTPATH}: Makefile not found"
fi
if [[ ! -f "${DOTPATH}/install.sh" ]]; then
errorf "${DOTPATH}: install.sh not found"
fi
if [[ ! -d "${DOTPATH}/.git" ]]; then
errorf "${DOTPATH}: not a git checkout; clone the repository locally before running install.sh"
fi
}
link() {
echo "Linking dotfiles..."
make -C "${DOTPATH}" link
echo "Finish linking"
}
install() {
require_local_checkout
link
}
DOTPATH="$(script_dir)"
export DOTPATH
trap "echo 'terminated' 1>&2; exit 1" INT ERR
install