-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup
executable file
·103 lines (81 loc) · 1.8 KB
/
setup
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
fi
}
red() { print_in_color "\e[31m" "$*"; }
green() { print_in_color "\e[32m" "$*"; }
green_bold() { print_in_color "\e[1;32m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }
section() {
printf "\n=== %s\n" "$(green_bold "$@")"
}
copy() {
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2"
cp "$1" "$2"
}
sudo_copy() {
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2"
$sudo cp "$1" "$2"
}
copy_executable() {
sudo_copy "$1" "/usr/local/bin/"
$sudo chmod a+x "/usr/local/bin/$1"
}
copy_man() {
for file in "$1"/*.[1-8]; do
section="${file##*.}"
target_dir="/usr/local/share/man/man$section/"
if [[ ! -d "$target_dir" ]]; then
$sudo mkdir -p "$target_dir"
fi
sudo_copy "$file" "$target_dir"
done
if command_exist makewhatis; then
$sudo makewhatis /usr/local/man
fi
}
command_exist() {
[[ -x "$(command -v "$1")" ]]
}
need() {
command_exist "$1" || fail "Cannot run $1"
printf "%s found\n" "$(blue " $1")"
}
onerror() {
local exit_status=$?
printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")"
exit $exit_status
}
fail() {
printf "$(red 'ERR') %s\n" "$*"
return 1
}
initialize() {
set -e
trap 'onerror' ERR
# Figure out if we need sudo or not
sudo=''
if [[ $EUID -ne 0 ]]; then
sudo='sudo'
fi
repo="$1"
repo_url="https://github.com/${repo}.git"
pushd "$(mktemp -d)" >/dev/null
}
section "Initializing"
initialize "DannyBen/alf"
section "Checking for pre-requisites"
need git
section "Cloning $repo"
git clone --depth 1 "$repo_url" .
section "Copying files"
copy_executable 'alf'
copy_man 'doc'
section "Done"
alf --version