-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbash-fx.sh
executable file
ยท168 lines (131 loc) ยท 3.29 KB
/
bash-fx.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
#!/usr/bin/env bash
# when the including script is sourced directly from the user shell (zzalias) we cannot use this
if [ "$0" != 'bash' ] && [ "$0" != '-bash' ]; then
SCRIPT_FULLPATH=$(readlink -f "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_FULLPATH")/
fi
if [ "$0" != 'bash' ] && [ "$0" != '-bash' ] && [ -z "$SCRIPT_NAME" ]; then
SCRIPT_NAME=$(basename "$SCRIPT_FULLPATH" .sh)
fi
INSTALL_DIR_PARENT=/usr/local/turbolab.it/
INSTALL_DIR=${INSTALL_DIR_PARENT}${SCRIPT_NAME}/
BASHFX_INSTALL_DIR="/usr/local/turbolab.it/bash-fx/"
function fxDate()
{
date +"๐๏ธ %T | %A, %B %d, %Y on $(hostname)"
}
function fxHeader()
{
local CHAR_NUM=${#1}
echo -e "\e[1;46m"
printf '%0.s=' $(seq 0 $CHAR_NUM)
echo ""
echo "${1}"
printf '%0.s=' $(seq 0 $CHAR_NUM)
echo ""
fxDate
if [ ! -z "${APP_ENV}" ]; then
echo "๐ณ Env: ${APP_ENV}"
fi
echo -e "\e[0m"
}
function fxTitle()
{
local CHAR_NUM=${#1}
local UNDERLINE=$(printf '%0.s-' $(seq 0 $CHAR_NUM))
echo ""
echo -e "\e[1;44m${1}\e[0m"
echo -e "\e[1;44m${UNDERLINE}\e[0m"
echo ""
}
function fxMessage()
{
echo -e "\e[1;45m${1}\e[0m"
}
function fxInfo()
{
echo -e "\e[1;34mโน๏ธ ${1}\e[0m"
}
function fxOK()
{
local MESSAGE=$1
if [ -z "$MESSAGE" ]; then
MESSSAGE=OK
fi
echo -e "\e[1;32mโ ${MESSAGE}\e[0m"
}
function fxImportantMessage()
{
echo -e "\e[1;33m${1}\e[0m"
}
function fxWarning()
{
echo -e "\e[1;33mโ โ โ ${1}\e[0m"
}
function fxCatastrophicError()
{
echo ""
echo -e "\e[1;41mvvvvvvvvvvvvvvvvvvvvvvvv\e[0m"
echo -e "\e[1;41m๐ Catastrophic error ๐\e[0m"
echo -e "\e[1;41m^^^^^^^^^^^^^^^^^^^^^^^^\e[0m"
echo -e "\e[1;41m${1}\e[0m"
if [ -z "$2" ]; then
fxEndFooter failure
exit
fi
}
function fxExitOnNonZero()
{
if [ "$1" != 0 ]; then
fxCatastrophicError "๐ Critical command failure! Forced exit"
fi
}
function fxEndFooter()
{
if [ ! -z "$INITIAL_DIR" ] && [ "$(pwd)" != "$INITIAL_DIR" ]; then
fxTitle "Switching back to $INITIAL_DIR"
cd "$INITIAL_DIR"
pwd
fi
local CHAR_NUM=20
if [ "$1" = "failure" ]; then
echo -e "\e[1;41m"
else
echo -e "\e[1;42m"
fi
printf '%0.s=' $(seq 0 $CHAR_NUM)
echo ""
echo "๐ The End ๐"
printf '%0.s=' $(seq 0 $CHAR_NUM)
echo ""
fxDate
echo "Total time: $((($(date +%s)-$TIME_START)/60)) min."
echo -e "\e[0m"
echo ""
}
function fxSourceLocalOrRemote()
{
local LOCAL_FILE=/usr/local/turbolab.it/bash-fx/${1}
if [ -f "$LOCAL_FILE" ]; then
source "$LOCAL_FILE"
else
source <(curl -s https://raw.githubusercontent.com/TurboLabIt/bash-fx/main/${1})
fi
}
fxSourceLocalOrRemote "scripts/timer.sh"
fxSourceLocalOrRemote "scripts/validators.sh"
fxSourceLocalOrRemote "scripts/config-loader.sh"
fxSourceLocalOrRemote "scripts/iptables-plus.sh"
fxSourceLocalOrRemote "scripts/network.sh"
fxSourceLocalOrRemote "scripts/hash.sh"
fxSourceLocalOrRemote "scripts/link.sh"
fxSourceLocalOrRemote "scripts/user.sh"
fxSourceLocalOrRemote "scripts/git.sh"
fxSourceLocalOrRemote "scripts/app-env.sh"
fxSourceLocalOrRemote "scripts/app-installer.sh"
fxSourceLocalOrRemote "scripts/ask.sh"
fxSourceLocalOrRemote "scripts/lock.sh"
fxSourceLocalOrRemote "scripts/replace.sh"
fxSourceLocalOrRemote "scripts/ssh.sh"
fxSourceLocalOrRemote "scripts/mail.sh"
fxSourceLocalOrRemote "scripts/hardware-info.sh"