forked from jan-auer/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·97 lines (74 loc) · 1.63 KB
/
install.sh
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
#!/usr/bin/env zsh
set -e
# Pretty printing
info () {
printf " [ \033[00;34m..\033[0m ] $1"
}
user () {
printf "\r [ \033[0;33m?\033[0m ] $1 "
}
success () {
printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"
}
warn () {
printf "\r\033[2K [ \033[00;33mWARN\033[0m ] $1\n"
}
skip () {
printf "\r\033[2K [ \033[00;33mSKIP\033[0m ] $1\n"
}
fail () {
printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"
echo ''
exit
}
# OS detection
function is_osx () {
[[ "$OSTYPE" =~ ^darwin ]] || return 1
}
function is_linux () {
[[ "$OSTYPE" == "linux-gnu" ]] || return 1
}
function is_cygwin () {
[[ "$OSTYPE" == "cygwin" ]] || return 1
}
function is_ubuntu () {
[[ "$(cat /etc/issue 2> /dev/null)" =~ Ubuntu ]] || return 1
}
function get_os () {
for os in osx ubuntu linux cygwin; do
is_$os; [[ $? == ${1:-0} ]] && echo $os
done
}
# Helpers
function ensure_path () {
mkdir -p "$(dirname "$1")"
}
# Installation Process
ROOT=$(dirname $0:A)
DEST="$HOME"
function init_file () {
local name="$(basename "$1")"
info "Running installer $name\n"
source "$ROOT/init/$1"
success "Installed $name" ||
fail "Installer $name completed with errors"
}
function copy_file () {
info "Copying $1"
ensure_path "$DEST/$1"
cp -a "$ROOT/copy/$1" "$DEST/.$1" && success "Copied $1" || fail "Linking $1 failed"
}
function link_file () {
info "Linking $1"
ensure_path "$DEST/$1"
ln -sf "$ROOT/link/$1" "$DEST/.$1" && success "Linked $1" || fail "Copying $1 failed"
}
function process () {
for file in $(cd "$ROOT/$1" && find -H . -type f | sort) ; do
"$1_file" "${file:2}"
done
}
# Let's go
for job in {link,copy,init} ; do
process $job
done