-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathself-install.sh
executable file
·203 lines (131 loc) · 5.56 KB
/
self-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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# @package exadra37-docker/php-development
# @link https://gitlab.com/u/exadra37-docker/php-development
# @since 11 February 2017
# @license GPL-3.0
# @author Exadra37(Paulo Silva) <exadra37ingmailpointcom>
#
# Social Links:
# @link Auhthor: https://exadra37.com
# @link Gitlab: https://gitlab.com/Exadra37
# @link Github: https://github.com/Exadra37
# @link Linkedin: https://uk.linkedin.com/in/exadra37
# @link Twitter: https://twitter.com/Exadra37
set -e
########################################################################################################################
# Functions
########################################################################################################################
function Print_Fatal_Error()
{
printf "\n \e[1;101m ${1}: \e[30;48;5;229m ${2} \e[0m \n"
echo
exit 1
}
function Print_Info()
{
printf "\n\e[1;36m ${1}:\e[0m ${2} \n"
}
function Print_Warning()
{
printf "\n\e[1;33m ${1}:\e[0m ${2} \n"
}
function Print_Success()
{
printf "\n\e[1;42m ${1}:\e[30;48;5;229m ${2} \e[0m \n"
}
function Abort_If_Url_Not_Available()
{
### VARIABLES ARGUMENTS ###
local _url="${1}"
### VARIABLES COMPOSITION ###
local _http_status_code=$( curl -L -s -o /dev/null -w "%{http_code}" "${_url}")
### EXECCUTION ###
if [ "${_http_status_code}" -gt 299 ]
then
Print_Warning "Http Status Code" "${_http_status_code}"
Print_Fatal_Error "Url not Available" "${_url}"
fi
}
function Abort_If_Sym_Link_Already_Exists()
{
### VARIABLES ARGUMENTS ###
local _sym_link_name="${1?}"
### EXECUTION ###
if [ -L "${_sym_link_name}" ]
then
Print_Fatal_Error "Sym Link already exists" "${_sym_link_name}"
fi
}
function Abort_If_Already_Installed()
{
### VARIABLES ARGUMENTS ###
local _package_manager_script="${1:?}"
### EXECUTION ###
if [ -f "${_package_manager_script}" ]
then
Print_Fatal_Error "Bash Package Manager is already installed" "${_package_manager_script}"
fi
}
function Install_Bash_Package_Manager()
{
### VARIABLES ARGUMENTS ###
local _bash_package_manager_version="${1?}"
local _git_url="${2?}"
local _package_manager_dir="${3?}"
### EXECUTION ###
Print_Info "Installing Bash Package Manager tag/branch '${_bash_package_manager_version}' from" "${_git_url}"
mkdir -p "${_package_manager_dir}"
cd "${_package_manager_dir}"
git clone -q --depth 1 -b "${_bash_package_manager_version}" "${_git_url}" .
# we want to ignore this type of errors:
# fatal: A branch named 'last-stable-release' already exists.
git checkout -q -b "${_bash_package_manager_version}" 2>/dev/null || true
cd - > /dev/null
}
function Create_Sym_Link()
{
### VARIABLES ARGUMENTS ###
local _from_script="${1?}"
local _sym_link="${2?}"
### EXECUTION ###
Print_Info "${_sym_link} is a Sym Link pointing to" "${_from_script}"
ln -s "${_from_script}" "${_sym_link}"
}
function Tweet_Me()
{
### VARIABLES DEFAULTS ###
local _message="I invite #Developers, #DevOps and #SysAdmins to take for a spin the awesome #Bash_Package_Manager by @exadra37."
local _message="${_message// /\%%20}"
local _message="${_message//#/\%%23}"
local _twitter_url="https://twitter.com/home?status=${_message}"
### EXECCUTION ###
Print_Info "Share Me On Twitter" "${_twitter_url}"
echo
}
########################################################################################################################
# Variables Defaults
########################################################################################################################
sym_link_name="bpm"
script_name="package-manager"
git_url=https://gitlab.com/exadra37-bash/package-manager.git
########################################################################################################################
# Variables Arguments
########################################################################################################################
bash_package_manager_version="${1:-last-stable-release}"
bin_dir="${2:-/home/${USER}/bin}"
package_manager_dir="${bin_dir}/vendor/exadra37-bash/package-manager"
package_manager_script="${package_manager_dir}/src/${script_name}.sh"
sym_link="${bin_dir}/${sym_link_name}"
########################################################################################################################
# Execution
########################################################################################################################
Abort_If_Url_Not_Available "${git_url}"
Abort_If_Sym_Link_Already_Exists "${sym_link}"
Abort_If_Sym_Link_Already_Exists "${bin_dir}/${script_name}"
Abort_If_Already_Installed "${package_manager_script}"
Install_Bash_Package_Manager "${bash_package_manager_version}" "${git_url}" "${package_manager_dir}"
Create_Sym_Link "${package_manager_script}" "${sym_link}"
# Let's test it
bpm --version
bpm --help
Tweet_Me