-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·116 lines (95 loc) · 2.15 KB
/
bootstrap
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
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
#
# Setup tools and functions taken from:
# https://github.com/spf13/spf13-vim
#
# Setup tools
msg() {
printf '%b\n' "$1" >&2
}
success() {
if [[ "$ret" != "0" ]]; then
msg "\33[32m[✔]\33[0m ${1}${2}"
fi
}
error() {
msg "\33[31m[✘]\33[0m ${1}${2}"
exit 1
}
debug() {
if [[ "$debug_mode" == 1 ]] && [[ "$ret" > 1 ]]; then
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line " \
"${BASH_LINENO[$i+1]}, we're sorry for that."
fi
}
program_exists() {
local ret='0'
command -v $1 >/dev/null 2>&1 || { local ret='1'; }
# fail on non-zero return value
if [[ "$ret" -ne 0 ]]; then
return 1
fi
return 0
}
program_must_exist() {
program_exists $1
# throw error on non-zero return value
if [[ "$?" -ne 0 ]]; then
error "You must have '$1' installed to continue."
else
success "$1 already installed"
fi
}
# Setup function
sync_repo() {
local repo_path="$1"
local repo_uri="$2"
local repo_branch="$3"
local repo_name="$4"
msg "Trying to update $repo_name"
if [[ ! -e "$repo_path" ]]; then
mkdir -p "$repo_path"
git clone -b "$repo_branch" "$repo_uri" "$repo_path"
ret="$?"
success "Successfully cloned $repo_name."
else
pushd "$repo_path" && git pull origin "$repo_branch"
popd
ret="$?"
success "Successfully updated $repo_name"
fi
debug
}
#
# Main
#
for program in curl git nvim stow tmux; do
program_must_exist "${program}"
done
# GNU/Linux
if [[ ${OSTYPE} == "linux-gnu" ]]; then
for repo in st/my-0.8.4 dmenu/my-4.10 slock/my-1.5; do
sync_repo "${HOME}/work/github.com/manitua/${repo%/*}" \
"https://github.com/manitua/${repo%/*}" \
"${repo#*/}" \
"${repo%/*}"
done
fi
# Arch Linux
# TODO
# macOS
if [[ ${OSTYPE} == darwin* ]]; then
program_must_exist "brew"
brew install $(cat package_list)
fi
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
sync_repo "${HOME}/.tmux/plugins/tpm" \
"https://github.com/tmux-plugins/tpm" \
"master" \
"tpm"
for F in $(ls .); do
if [[ -d ${F} ]]; then
stow -vv ${F}
fi
done