-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-env.sh
executable file
·62 lines (53 loc) · 1.33 KB
/
check-env.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
#!/bin/bash
# Check if the .env file is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <path_to_env_file>"
echo "Please provide the path to the .env file."
exit 1
fi
# Load environment variables from the specified .env file
if [ -f "$1" ]; then
source "$1"
else
echo ".env file not found! Exiting."
exit 1
fi
# Define required environment variables
REQUIRED_VARS=(
"PGUSER"
"PGHOST"
"PGPORT"
"BACKUP_DIR"
"PGVERSION"
"PGCLUSTER"
)
missing_vars=false
# Check for the presence of each required variable
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ]; then
echo "Error: Required variable $var is not set in the .env file."
missing_vars=true
fi
done
# If no errors were found, print success message
if [ "$missing_vars" = true ]; then
echo "Please correct the above issues before proceeding."
exit 1
else
echo "All required variables are set correctly!"
fi
# Define required environment variables
MAYBE_VARS=(
"PGPASSWD"
)
# Check for the presence of each required variable
for var in "${MAYBE_VARS[@]}"; do
if [ -z "${!var}" ]; then
echo "Warning: Variable $var is not set in the .env file, it may be required"
missing_vars=true
fi
done
# If no errors were found, print success message
if [ "$missing_vars" = false ]; then
echo "All required variables are set correctly!"
fi