-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·85 lines (67 loc) · 1.88 KB
/
install
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -o nounset
set -o pipefail
# Dotfile-wide variables begin with DOTFILES
export DOTFILES_HOME=$PWD
export DOTFILES_BIN=$DOTFILES_HOME/bin
PATH=$DOTFILES_BIN:$PATH
# Installation specific variables begin with DOTBOT_
export DOTBOT_FORCE=${DOTBOT_FORCE:-no}
DOTBOT_OS=$(uname -o)
export DOTBOT_OS
export DOTBOT_OS_SHORT=${DOTBOT_OS##*/}
run() {
local config_path=$1
local config_dir
config_dir="$(dirname "$config_path")"
local config
config="$(basename "$config_path")"
local name=${config_dir##*/}
if [[ ! -f $config_path ]]; then
echo "($name)(3) file does not exist"
return 1
fi
local old_pwd=$PWD
cd "$config_dir" || exit
bash "$config"
local exitcode=$?
if [[ $exitcode -eq 0 ]]; then
echo "($name) installed"
elif [[ $exitcode -lt 128 ]]; then
echo "($name)($exitcode) installation failed"
else
local errmsg
case "$exitcode" in
128) errmsg="command not installed - skipping" ;;
129) errmsg="unsupported OS '$DOTBOT_OS' - skipping" ;;
*) errmsg="unknown dotbot error - skipping" ;;
esac
echo "($name)($exitcode) $errmsg"
fi
cd "$old_pwd" || exit
return "$exitcode"
}
main() {
if [[ $# -ge 1 ]]; then
# Only install configs explicitly listed as CLI arguments.
for config in "$@"; do
run $config
done
elif [[ -f .dotbot.conf ]]; then
# Only install configs explicitly listed in the config file.
while read -r config_dotbot; do
if [[ $config_dotbot != */dotbot ]]; then
config_dotbot=config/$config_dotbot/dotbot
fi
run "$config_dotbot"
done <.dotbot.conf
else
# If no dotbot file is given as an argument, first run the root dotbot file,
# then run all dotbot files that can be found in the config/ directory.
run dotbot
for config_dotbot in config/*/dotbot; do
run "$config_dotbot"
done
fi
}
main "$@"