-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
138 lines (108 loc) · 3.14 KB
/
bootstrap.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
# vi: ts=4 sts=4 expandtab shiftwidth=4
############################ SETUP PARAMETERS
app_name='atla'
bashrc_include='atla.sh'
bashrc='.bashrc'
# Linux or Darwin?(MAC OS X)
if ! [ $(uname -a | awk '{print $1}') = "Linux" ];then
bashrc='.bash_profile'
fi
git_uri='https://github.com/xembill/atla'
git_branch='master'
debug_mode='1'
############################ BASIC SETUP TOOLS
msg() {
printf '%b\n' "$1" >&2
}
success() {
if [ "$ret" -eq '0' ]; then
msg "\e[32m[✔]\e[0m ${1}${2}"
fi
}
error() {
msg "\e[31m[✘]\e[0m ${1}${2}"
exit 1
}
debug() {
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
msg "An error occured in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
fi
}
program_exists() {
local ret='0'
type $1 >/dev/null 2>&1 || { local ret='1'; }
# throw error on non-zero return value
if [ ! "$ret" -eq '0' ]; then
error "$2"
fi
}
############################ SETUP FUNCTIONS
# Brief: make soft link if exist <src_dir>
# Usage: lnif <"src_dir"> <"dest_dir">
lnif() {
if [ -e "$1" ]; then
ln -sf "$1" "$2"
fi
ret="$?"
debug
}
do_backup() {
if [ -e "$2" ] || [ -e "$3" ] || [ -e "$4" ]; then
today=`date +%Y%m%d_%s`
for i in "$2" "$3" "$4"; do
[ -e "$i" ] && [ ! -L "$i" ] && mv "$i" "$i.$today";
done
ret="$?"
success "$1"
debug
fi
}
upgrade_repo() {
msg "trying to update $1"
cd "$HOME/.$app_name" &&
git pull origin "$git_branch"
ret="$?"
success "$2"
debug
}
clone_repo() {
program_exists "git" "Sorry, we cannot continue without GIT, please install it first."
endpath="$HOME/.$app_name"
if [ ! -e "$endpath/.git" ]; then
git clone --recursive -b "$git_branch" "$git_uri" "$endpath"
ret="$?"
success "$1"
debug
else
upgrade_repo "$app_name" "Successfully updated $app_name"
fi
}
setup_bashrc() {
is_include_exist_in_bashrc=$(grep "source ~/.$app_name/$bashrc_include" $HOME/$bashrc | wc -l)
no="0"
# .bashrc에 추가하기
if [ $is_include_exist_in_bashrc = $no ]; then
echo "" >> $HOME/$bashrc
echo "source ~/.$app_name/$bashrc_include" >> $HOME/$bashrc
echo "source ~/.$app_name/$bashrc_include"
ret="$?"
success "$1"
debug
else
ret="0"
success "$1"
debug
fi
}
############################ SPECIAL FUNCTIONS
############################ MAIN()
program_exists "git" "$app_name 'yı kullanabilmek için ilk önce Git yükleyin."
do_backup "Your old git stuff has a suffix now and looks like $HOME/.$app_name.`date +%Y%m%d%S`" \
"$HOME/.$app_name"
clone_repo " $app_name başarıyla kopyalandı."
setup_bashrc " '$HOME/$bashrc' dizinine başarıyla yüklendi, Teşekkürler... "
msg "\n * Kurulumu bitirmek için > 'source $HOME/$bashrc' komutunu girin..."
msg " * Yada bir sonraki oturumunuzda otomatik etkinleştirilecektir. "
msg "\nTeşekkürler $app_name."
msg "© `date +%Y` $git_uri \n"