forked from atomantic/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.sh
118 lines (101 loc) · 2.64 KB
/
lib.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
###
# some bash library helpers
# @author Adam Eivy
###
# Colors
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
function ok() {
echo -e "$COL_GREEN[ok]$COL_RESET "$1
}
function bot() {
echo -e "\n$COL_GREEN\[._.]/$COL_RESET - "$1
}
function running() {
echo -en "$COL_YELLOW ⇒ $COL_RESET"$1": "
}
function action() {
echo -e "\n$COL_YELLOW[action]:$COL_RESET\n ⇒ $1..."
}
function warn() {
echo -e "$COL_YELLOW[warning]$COL_RESET "$1
}
function error() {
echo -e "$COL_RED[error]$COL_RESET "$1
}
function require_cask() {
running "brew cask $1"
brew cask list $1 > /dev/null 2>&1 | true
if [[ ${PIPESTATUS[0]} != 0 ]]; then
action "brew cask install $1 $2"
brew cask install $1
if [[ $? != 0 ]]; then
error "failed to install $1! aborting..."
exit -1
fi
fi
ok
}
function require_brew() {
running "brew $1 $2"
brew list $1 > /dev/null 2>&1 | true
if [[ ${PIPESTATUS[0]} != 0 ]]; then
action "brew install $1 $2"
brew install $1 $2
if [[ $? != 0 ]]; then
error "failed to install $1! aborting..."
exit -1
fi
fi
ok
}
function require_gem() {
running "gem $1"
if [[ $(gem list --local | grep $1 | head -1 | cut -d' ' -f1) != $1 ]];
then
action "gem install $1"
gem install $1
fi
ok
}
npmlist=`npm list -g`
function require_npm() {
running "npm $1"
echo $npmlist | grep $1@ > /dev/null
if [[ $? != 0 ]]; then
action "npm install -g $1"
npm install -g $1
fi
ok
}
function require_vagrant_plugin() {
running "vagrant plugin $1"
local vagrant_plugin=$1
local vagrant_plugin_version=$2
local grepExpect=$vagrant_plugin
local grepStatus=$(vagrant plugin list | grep $vagrant_plugin)
if [[ ! -z $vagrant_plugin_version ]]; then
grepExpect=$grepExpect' ('$vagrant_plugin_version')'
else
# we are only looking for the name
grepStatus=${grepStatus%% *}
fi
#echo 'checking if '$grepExpect' is installed via grepStatus: '$grepStatus
if [[ $grepStatus != $grepExpect ]];
then
action "installing vagrant plugin $1 $2"
if [[ ! -z $vagrant_plugin_version ]]; then
vagrant plugin install $vagrant_plugin --plugin-version $vagrant_plugin_version
else
vagrant plugin install $vagrant_plugin
fi
fi
ok
}