-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib_env_utils.sh
More file actions
executable file
·122 lines (85 loc) · 3.04 KB
/
lib_env_utils.sh
File metadata and controls
executable file
·122 lines (85 loc) · 3.04 KB
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
#!/usr/bin/env bash
#### Description: Loads environment variables from .env file
#### Written by: Guillermo de Ignacio - gdeignacio on 01-2023
#### THIS FILE USED TO BE SOURCED. THINK TWICE BEFORE UPDATE.
#### EXECUTING BY YOURSELF WILL ONLY TAKE EFFECT IN YOUR CURRENT SHELL.
###################################
### LOAD ENV UTILS ###
###################################
##################################################################
##################################################################
lib_env_utils.check_os(){
local unameOut="$(uname -s)"
local machine="UNKNOWN:${unameOut}"
local isLinux=0
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
# echo "Your OS is ${machine} according uname=${unameOut}"
isLinux=0
# Assign mode 1 if so is linux or mac, 0 otherwise
if [[ ${machine} == "Linux" || ${machine} == "Mac" ]]; then
isLinux=1
fi
echo "${isLinux}"
}
##################################################################
##################################################################
lib_env_utils.check_docker(){
local cmnd=docker
# echo ""
# echo "Checking ${cmnd} settings ..."
local dckr=/dev/null
if command -v ${cmnd} > /dev/null; then
dckr=$(command -v ${cmnd})
# echo "${cmnd} is available at ${dckr}"
#else
# echo "${cmnd} is not available. ${cmnd} set to ${dckr}"
fi
echo "${dckr}"
}
##################################################################
##################################################################
lib_env_utils.check_R(){
local cmnd=R
#echo ""
#echo "Checking ${cmnd} settings ..."
local rpath=/dev/null
if command -v ${cmnd} > /dev/null; then
rpath=$(command -v ${cmnd})
# echo "${cmnd} is available at ${rpath}"
#else
# echo "${cmnd} is not available. ${cmnd} set to ${rpath}"
fi
echo "${rpath}"
}
##################################################################
##################################################################
lib_env_utils.loadenv(){
echo ""
echo "[$(date +"%Y-%m-%d %T")] Loading env..."
echo ""
while read line; do
# Define the string value
# Set space as the delimiter
IFS='='
#Read the split words into an array based on space delimiter
read -a strarr <<< "$line"
#Count the total words
#echo "There are ${#strarr[*]} words in the text."
key="${strarr[0]}"
value="${strarr[1]}"
export $key=$(eval echo $value)
echo "$key : $(eval echo \${$key})"
done < <(cat $1/.env | grep -v "#" | grep -v "^$")
}
##################################################################
##################################################################
lib_env_utils.loaded(){
echo lib_env_utils.sh loaded
echo lib_string_utils.sh may be required
}