Skip to content
Snippets Groups Projects
Commit 0d3cb564 authored by Jörg Sachse's avatar Jörg Sachse
Browse files

rafactor: remove Postgres data injection

parent bad5cf40
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
set -e
set -o nounset # Treat unset variables as an error
# invocation: sudo /usr/local/bin/test_exit_strategy.sh [prod|test|dev]
### INIT ###
# Variables
RED="\\e[31m"
WHITE="\\e[0m"
ERROR="${RED}[ERROR]\t${WHITE}"
INFO="[INFO]\t"
MOUNTPOINT=""
DATE="$(date +%Y-%m-%d_%H-%M-%S)"
# check user privileges
if [ $UID -ne 0 ] ; then
"Insufficient privileges. Please use sudo to run this script. Aborting..."
"${ERROR}Insufficient privileges. Please use sudo to run this script. Aborting..."
exit
fi
cd ~ || exit 1
# Variables
MOUNTPOINT=""
DATE="$(date +%Y-%m-%d_%H-%M-%S)"
SQLFILE="/tmp/exit_${DATE}.sql"
LOGFILE="/tmp/exit_${DATE}.log"
touch "${LOGFILE}"
touch "${SQLFILE}"
chown {{ vault_db_user }}.{{ vault_db_group }} "${LOGFILE}"
chown {{ vault_db_user }}.{{ vault_db_group }} "${SQLFILE}"
chmod 0640 "${LOGFILE}"
chmod 0640 "${SQLFILE}"
# find correct mountpoint
case $1 in
prod*)
MOUNTPOINT="/mnt/rosetta-prod/permanent_storage/"
MESSAGE="Production system chosen."
MESSAGE="${INFO}Production system chosen."
;;
test*)
MOUNTPOINT="/mnt/rosetta-test/permanent_storage/"
MESSAGE="Test system chosen."
MESSAGE="${INFO}Test system chosen."
;;
dev*)
MOUNTPOINT="/mnt/rosetta-dev/permanent_storage/"
MESSAGE="Dev system chosen."
MESSAGE="${INFO}Dev system chosen."
;;
*)
MESSAGE="Not a valid system. Please choose one of 'prod', 'test' or 'dev'."
MESSAGE="${ERROR}Not a valid system. Please choose one of 'prod', 'test' or 'dev'."
exit 1
;;
esac
......@@ -54,20 +53,12 @@ EXIT_PERL="${HOME}/rosettaExitStrategy/perl/exit_strategy.pl"
### GENERATE EXIT SQL SCRIPT ###
date | tee -a "${LOGFILE}"
echo -e "\n### GENERATE EXIT SQL SCRIPT ###\n" | tee -a "${LOGFILE}"
#perl /usr/local/bin/exit_strategy.pl "${MOUNTPOINT}" > "${SQLFILE}" 2>> "${LOGFILE}"
perl "${EXIT_PERL}" "${SQLFILE}" "${MOUNTPOINT}" 2>> "${LOGFILE}"
[[ $? -ne 0 ]] && echo "ERROR: Couldn't create SQL instruction file, exiting." && exit 10
[[ $? -ne 0 ]] && echo "ERROR: Couldn't create SQLite database, exiting." && exit 10
date | tee -a "${LOGFILE}"
### IMPORT SQL FILE INTO POSTGRES DB
echo -e "\n### IMPORT SQL FILE INTO POSTGRES DB ###\n" | tee -a "${LOGFILE}"
sudo -i -u {{ vault_db_user }} /bin/bash /usr/local/bin/test_exit_insert_into_DB.sh "${SQLFILE}" "${LOGFILE}"
[[ $? -ne 0 ]] && echo "ERROR: Couldn't insert SQL instruction file into DB, exiting." && exit 10
date | tee -a "${LOGFILE}"
### TIDY UP ###
rm -r ~/rosettaExitStrategy
rm "${SQLFILE}"
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment