-
Notifications
You must be signed in to change notification settings - Fork 27
/
local_storage_validate.sh
99 lines (84 loc) · 2.64 KB
/
local_storage_validate.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
#!/bin/bash
check_directory(){
if [[ ! "$2" = /* ]] || [[ ! -d $2 ]]; then
echo "Error - $1 Please enter the absolute path or make sure the directory is present."; fail=1
fi
dir_owner=`stat -c '%U' $2`
if ! [[ $dir_owner == $system_user_name ]]; then
echo "Error - $1 directory owner not matchiing."; fail=1
fi
if ! [[ -r "$2" ]]; then
echo "Error - '$1' please give read permission to directory."; fail=1
fi
if ! [[ -w "$2" ]]; then
echo "Error - '$1' please give write permission to directory."; fail=1
fi
if ! [[ -x "$2" ]]; then
echo "Error - '$1' please give execute permission to directory."; fail=1
fi
if ! [[ "$2" = */ ]]; then
echo "Error - $1 Please make sure the absolute path values should end with '/'"; fail=1
fi
}
get_local_storage_config_values(){
key=$1
vals[$key]=$(awk ''/^$key:' /{ if ($2 !~ /#.*/) {print $2}}' local_storage_config.yml)
}
bold=$(tput bold)
normal=$(tput sgr0)
fail=0
if [[ ! $# -eq 0 ]]; then
core_install=$1
else
core_install="NA"
fi
echo -e "\e[0;33m${bold}Validating the local_storage_config file...${normal}"
# An array of mandatory values
declare -a arr=("input_directory" "output_directory" "emission_directory")
# Create and empty array which will store the key and value pair from config file
declare -A vals
system_user_name=$(awk ''/^system_user_name:' /{ if ($2 !~ /#.*/) {print $2}}' config.yml)
# Iterate the array and retrieve values for mandatory fields from config file
for i in ${arr[@]}
do
get_local_storage_config_values $i
done
for i in ${arr[@]}
do
key=$i
value=${vals[$key]}
case $key in
input_directory)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_directory $key $value
fi
;;
output_directory)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_directory $key $value
fi
;;
emission_directory)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_directory $key $value
fi
;;
*)
if [[ $value == "" ]]; then
echo -e "\e[0;31m${bold}Error - Value for $key cannot be empty. Please fill this value${normal}"; fail=1
fi
;;
esac
done
if [[ $fail -eq 1 ]]; then
echo -e "\e[0;34m${bold}local_storage_Config file has errors. Please rectify the issues and restart the installation${normal}"
exit 1
else
echo -e "\e[0;32m${bold}local_storage_Config file successfully validated${normal}"
fi