-
Notifications
You must be signed in to change notification settings - Fork 7
/
dbdeployer_install.sh
executable file
·167 lines (146 loc) · 4.45 KB
/
dbdeployer_install.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
error_state='false' #initialize error state
package_name='dbdeployer' #name of package/folder to reference
package_base_data_dir='/var/lib' #location to install data dir
package_data_dir="${package_base_data_dir}/${package_name}" #full path to data dir
package_database_dir="${package_data_dir}/databases" #default path for user databases
bin_dir='/usr/bin' #location to install binary
config_base_dir='/etc' #location to install config dir
config_dir="${config_base_dir}/${package_name}" #full path to config dir
function_base_dir='/usr/libexec' #location to install functions dir
function_dir="${function_base_dir}/${package_name}" #full path to functions dir
plugin_dir="${function_dir}" #location for plugin/module directory
log_dir="/var/log/${package_name}" #default log location
group_name='dbdeployer' #name of the group (used for log file permission)
BASEDIR=$(dirname $0)
cd $BASEDIR
#verify suitable user to install (root)
if [ `whoami` != 'root' ]
then
echo "Must be root to run install"
error_state='true'
fi
#verify directories exist
for x in dbtype dbtype/postgres 'functions' sample_structure deployments ${bin_dir} ${config_base_dir} ${function_base_dir} ${package_base_data_dir}
do
if ! [ -d "${x}" ]
then
echo "Directory ${x} was not found"
error_state='true'
fi
done
#verify files exist
for x in dbdeployer config.sh dbdeployer_release
do
if ! [ -f "${x}" ]
then
echo "File ${x} was not found"
error_state='true'
fi
done
#check error_state and exit if true
if [ ${error_state} = 'true' ]
then
echo "Errors were found in the pre-check, exiting"
exit 1
fi
#make necessary directories on filesystem
for x in ${config_dir} ${function_dir} ${package_data_dir} ${package_database_dir} ${log_dir}
do
if ! [ -d ${x} ]
then
mkdir ${x}
if [ $? -ne 0 ]
then
echo "Failed to create directory '${x}', exiting"
exit 1
fi #end error check
fi #end directory exists check
done
#copy config file
#if ! [ -f ${config_dir}/config.sh ]
#then
cp config.sh ${config_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy config file, exiting"
exit 1
fi #end error check
#fi #end config file exists
#copy version file
cp dbdeployer_release ${config_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy version file, exiting"
exit 1
fi #end error check
#copy executable file
cp dbdeployer ${bin_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy executable file, exiting"
exit 1
fi #end error check
#copy pluginsdirectory
cp -R 'plugins' ${plugin_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy plugin directory, exiting"
exit 1
fi #end error check
#copy functions directory
cp -R 'functions' ${function_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy functions directory, exiting"
exit 1
fi #end error check
#copy dbtype functions directory
cp -R dbtype ${function_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy dbtype functions directory, exiting"
exit 1
fi #end error check
#copy sample_structure directory
cp -R sample_structure ${package_data_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy sample_structure directory, exiting"
exit 1
fi #end error check
#copy deployments directory
cp -R deployments ${package_data_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy deployments directory, exiting"
exit 1
fi #end error check
#create group
if [ `grep "${group_name}" /etc/group | wc -l` -eq 0 ]
then
groupadd "${group_name}"
if [ $? -ne 0 ]
then
echo "Failed to add group to system, exiting"
exit 1
fi #end error check
fi
#set permissions on log_dir
chown root:${group_name} ${log_dir}
if [ $? -ne 0 ]
then
echo "Failed to set ownership of log directory, exiting"
exit 1
fi #end error check
chmod 775 ${log_dir}
if [ $? -ne 0 ]
then
echo "Failed to set permission on log directory, exiting"
exit 1
fi #end error check
#installation is complete
echo "Installation has completed successfully."
#warn that they will have to add users to the dbdeployer group before deploying files
echo "Please add any users that will be deploying files to the 'dbdeployer' group."
echo "Can be done with this command on RHEL systems: usermod -aG dbdeployer [username]"