-
Notifications
You must be signed in to change notification settings - Fork 10
/
dropFastRefreshModule.sh
executable file
·79 lines (61 loc) · 2.35 KB
/
dropFastRefreshModule.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
#! /bin/bash
#File: dropFastRefreshModule.sh
#Desc:
#
# Amendment History:
# Date: Who: Desc:
# 28/10/19 T.Mullen Initial;
#
. ./module_set_variables.sh
export LOG_FILE=/tmp/dropFastRefreshModule_`date +%Y%m%d-%H%M`.log
echo "INFO: Set variables" >> $LOG_FILE
echo "INFO: LOG_FILE parameter set to $LOG_FILE" >> $LOG_FILE
echo "INFO: MODULEOWNER parameter set to $MODULEOWNER" >> $LOG_FILE
echo "INFO: PGUSERNAME parameter set to $PGUSERNAME" >> $LOG_FILE
echo "INFO: SOURCEUSERNAME parameter set to $SOURCEUSERNAME" >> $LOG_FILE
echo "INFO: MVUSERNAME parameter set to $PGUSERNAME" >> $LOG_FILE
echo "INFO: HOSTNAME parameter set to $HOSTNAME" >> $LOG_FILE
echo "INFO: PORT parameter set to $PORT" >> $LOG_FILE
echo "INFO: DBNAME parameter set to $DBNAME" >> $LOG_FILE
echo "INFO: MODULE_HOME parameter set to $MODULE_HOME" >> $LOG_FILE
PGPASS=$PGPASSWORD
function removecronperms
{
echo "INFO: Remove cron permissions" >> $LOG_FILE
PGPASSWORD=$PGPASS
psql --host=$HOSTNAME --port=$PORT --username=$PGUSERNAME --dbname=postgres -v MODULE_HOME=$MODULE_HOME -v MODULEOWNER=$MODULEOWNER << EOF1 >> $LOG_FILE 2>&1
\i :MODULE_HOME/BuildScripts/revokeCronPrivs.sql;
\q
EOF1
}
function dropmodule
{
echo "INFO: Truncating modules tables" >> $LOG_FILE
PGPASSWORD=$PGPASS
psql --host=$HOSTNAME --port=$PORT --username=$PGUSERNAME --dbname=$DBNAME << EOF2 >> $LOG_FILE 2>&1
REVOKE ALL PRIVILEGES ON DATABASE "$DBNAME" from $MODULEOWNER;
DROP USER MAPPING IF EXISTS FOR $MODULEOWNER SERVER pgmv\$_instance;
DROP USER MAPPING IF EXISTS FOR $MODULEOWNER SERVER pgmv\$cron_instance;
DROP SERVER IF EXISTS pgmv\$_instance CASCADE;
DROP SERVER IF EXISTS pgmv\$cron_instance CASCADE;
DROP EXTENSION IF EXISTS postgres_fdw;
DROP EXTENSION IF EXISTS dblink;
DROP SCHEMA $MODULEOWNER CASCADE;
DROP ROLE pgmv\$_role;
REVOKE $MODULEOWNER from $PGUSERNAME;
DROP EXTENSION IF EXISTS "uuid-ossp";
DROP ROLE $MODULEOWNER;
DROP ROLE pgmv\$_execute;
DROP ROLE pgmv\$_view;
DROP ROLE pgmv\$_usage;
EOF2
}
read -p "Are you sure you want to remove the module schema - $MODULEOWNER (y/n)?" choice
case "$choice" in
y|Y ) echo "yes selected the schemas - $MODULEOWNER will be dropped"
removecronperms
dropmodule;;
n|N ) echo "no selected so exiting";;
* ) echo "invalid choice exiting";;
esac
echo "INFO: Drop Module Schema complete check logfile for status - $LOG_FILE"