Skip to content

Commit 5ea8f6a

Browse files
committed
Add basescripts for nginx-proxy
1 parent 6b0e1cb commit 5ea8f6a

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

basescript-free/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
This is an open (free) version of basescript!
2+
3+
# Base Scripts
4+
5+
Some handy scripts to make your life easier.
6+
7+
## Thoughts
8+
9+
The scripts was designed thinking of a few baselines:
10+
11+
- Simplicity
12+
- Reusability
13+
- Meaningful reading
14+
15+
and the Unix concept of DOTADIW:
16+
- Do One Thing And Do It Well
17+
18+
## Versioning
19+
20+
Every change should be non breakable, if it worked for you in some *main version* it should continue to work in all corrections and new functions.
21+
22+
Versioning: v**X.Y**
23+
24+
'X': main version
25+
26+
'Y': corrections / new functions
27+
28+
## Documentation
29+
30+
There will be a specific page for documentation and samples of every function in this repo.
31+
32+
Please check
33+
34+
[Docs](https://github.com/evertramos/basescript/blob/master/docs/README.md)
35+

basescript-free/bootstrap.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#-----------------------------------------------------------------------
2+
#
3+
# Basescript function
4+
#
5+
# The basescript functions were designed to work as abstract function,
6+
# so it could be used in many different contexts executing specific job
7+
# always remembering Unix concept DOTADIW - "Do One Thing And Do It Well"
8+
#
9+
# Developed by
10+
# Evert Ramos <evert.ramos@gmail.com>
11+
#
12+
# Copyright Evert Ramos
13+
#
14+
#-----------------------------------------------------------------------
15+
#
16+
# Be carefull when editing this file, it is part of a bigger script!
17+
#
18+
# Basescript - https://github.com/evertramos/basescript
19+
#
20+
#-----------------------------------------------------------------------
21+
22+
#-----------------------------------------------------------------------
23+
# This script has one main objective:
24+
# 1. Load all functions in local folder and subfolders
25+
#
26+
#-----------------------------------------------------------------------
27+
28+
#-----------------------------------------------------------------------
29+
# Fill out local variables
30+
#-----------------------------------------------------------------------
31+
# Get Current directory
32+
LOCAL_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
33+
34+
# Bootstrap file name
35+
BOOTSTRAP_FILE_NAME="bootstrap.sh"
36+
37+
#-----------------------------------------------------------------------
38+
# Debug message
39+
#-----------------------------------------------------------------------
40+
[[ "$DEBUG" == true ]] && "Reading base script files... [bootstrap.sh]"
41+
42+
#-----------------------------------------------------------------------
43+
# Read files with extension '.sh'
44+
#-----------------------------------------------------------------------
45+
# Loop the base folder and source all files in root folder
46+
for file in $LOCAL_PATH/*.sh
47+
do
48+
[[ $file != $LOCAL_PATH/$BOOTSTRAP_FILE_NAME ]] && source $file
49+
done
50+
51+
# Loop through all folders in the base folder and source all files inside
52+
for dir in $LOCAL_PATH/*/
53+
do
54+
local_dir=${dir%*/}
55+
56+
for file in $local_dir/*.sh
57+
do
58+
[[ $file != $LOCAL_PATH/$BOOTSTRAP_FILE_NAME ]] && source $file
59+
done
60+
done
61+
62+
return 0
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#-----------------------------------------------------------------------
2+
#
3+
# Basescript function
4+
#
5+
# The basescript functions were designed to work as abstract function,
6+
# so it could be used in many different contexts executing specific job
7+
# always remembering Unix concept DOTADIW - "Do One Thing And Do It Well"
8+
#
9+
# Developed by
10+
# Evert Ramos <evert.ramos@gmail.com>
11+
#
12+
# Copyright Evert Ramos
13+
#
14+
#-----------------------------------------------------------------------
15+
#
16+
# Be carefull when editing this file, it is part of a bigger script!
17+
#
18+
# Basescript - https://github.com/evertramos/basescript
19+
#
20+
#-----------------------------------------------------------------------
21+
22+
#-----------------------------------------------------------------------
23+
# This function has one main objective:
24+
# 1. Call other functions in the environment passing parameter through
25+
#
26+
# You must/might inform the parameters below:
27+
# 1. Function name
28+
# 2. [optional] (default: null) you can pass up to 4 parameters ]
29+
#
30+
#-----------------------------------------------------------------------
31+
32+
run_function() {
33+
34+
[[ $1 == "" ]] && echoerr "You must inform an argument to the function '${FUNCNAME[0]}', \nplease check the docs."
35+
36+
# Check $SILENT mode
37+
if [[ "$SILENT" == true ]]; then
38+
if [[ ! -z $5 ]]; then
39+
$1 "$2" "$3" "$4" "$5"
40+
elif [[ ! -z $4 ]]; then
41+
$1 "$2" "$3" "$4"
42+
elif [[ ! -z $3 ]]; then
43+
$1 "$2" "$3"
44+
elif [[ ! -z $2 ]]; then
45+
$1 "$2"
46+
else
47+
$1
48+
fi
49+
else
50+
echo "${yellow}[start]---------------------------------------------------------------${reset}"
51+
52+
# Call the specified function
53+
if [[ -n "$(type -t "$1")" ]] && [[ "$(type -t "$1")" = function ]]; then
54+
echo "${cyan}...running function \"${1}\":${reset}"
55+
if [[ ! -z $5 ]]; then
56+
$1 "$2" "$3" "$4" "$5"
57+
elif [[ ! -z $4 ]]; then
58+
$1 "$2" "$3" "$4"
59+
elif [[ ! -z $3 ]]; then
60+
$1 "$2" "$3"
61+
elif [[ ! -z $2 ]]; then
62+
$1 "$2"
63+
else
64+
$1
65+
fi
66+
else
67+
echo "${red}----------------------------------------------------------------------${reset}"
68+
echo "${red}|${reset}"
69+
echo "${red}| [ERROR] Function \"$1\" not found!${reset}"
70+
echo "${red}|${reset}"
71+
echo "${red}----------------------------------------------------------------------${reset}"
72+
echo "${yellow}[ended with ${red}[ERROR]${yellow}]--------------------------------------------------${reset}"
73+
exit 1
74+
fi
75+
76+
# Show result from the function execution
77+
if [[ $? -ne 0 ]]; then
78+
echo "${red}----------------------------------------------------------------------${reset}"
79+
echo "${red}|${reset}"
80+
echo "${red}| Ups! Something went wrong...${reset}"
81+
echo "${red}|${reset}"
82+
printf "${red}| ${MESSAGE//\\n/\\n|}${reset}"
83+
echo
84+
echo "${red}|${reset}"
85+
echo "${red}----------------------------------------------------------------------${reset}"
86+
echo "${yellow}[ended with ${red}ERROR${yellow}/WARNING ($?)-----------------------------------------${reset}"
87+
exit 1
88+
else
89+
echo "${green}>>> Success!${reset}"
90+
fi
91+
92+
echo "${yellow}[end]-----------------------------------------------------------------${reset}"
93+
echo
94+
fi
95+
}

0 commit comments

Comments
 (0)