-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path_functions_string.sh
73 lines (62 loc) · 1.68 KB
/
_functions_string.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
#!/bin/bash -eu
# Don't load it several times
set +u
${_FUNCTIONS_STRING_LOADED:-false} && return
set -u
# if the script was started from the base directory, then the
# expansion returns a period
if test "${SCRIPT_DIR}" == "."; then
SCRIPT_DIR="$PWD"
# if the script was not called with an absolute path, then we need to add the
# current working directory to the relative path of the script
elif test "${SCRIPT_DIR:0:1}" != "/"; then
SCRIPT_DIR="$PWD/${SCRIPT_DIR}"
fi
# #############################################################################
# Load shared functions
# #############################################################################
source "${SCRIPT_DIR}/_functions_core.sh"
# Converts $1 in upper case
toupper() {
echo "$1" | tr '[:lower:]' '[:upper:]'
}
# Converts $1 in lower case
tolower() {
echo "$1" | tr '[:upper:]' '[:lower:]'
}
# $1 : scheme : http, ..
# $2 : host
# $3 : port
# $4 : path
do_build_url() {
if [ $# -lt 4 ]; then
echo_error "No enough parameters for function do_build_url !"
exit 1;
fi
#
# Function parameters
#
local _scheme="$1";
shift;
local _host="$1";
shift;
local _port="$1";
shift;
local _path="$1";
shift;
local _result="${_scheme}://${_host}";
if [ "$_port" == "80" ]; then
_result="${_result}${_path}";
else
_result="${_result}:${_port}${_path}";
fi
echo ${_result}
}
# $1 : string length (default: 12)
getrandomstring() {
cat /dev/urandom | tr -dc '[:alpha:][0-9]' | fold -w ${1:-12} | head -n 1
}
# #############################################################################
# Env var to not load it several times
_FUNCTIONS_STRING_LOADED=true
echo_debug "_functions_string.sh Loaded"