Skip to content
Snippets Groups Projects
Commit 74cf505f authored by Mateusz Żebrak's avatar Mateusz Żebrak Committed by Bartek Wrona
Browse files

Add auxiliary bash scripts to setup db and postgres

parent 351cb63e
No related branches found
No related tags found
2 merge requests!584Changes to be delivered to master as 1.27 release,!558Merge develop-haf with current develop
#! /bin/bash
set -euo pipefail
exec > >(tee "${LOG_FILE}") 2>&1
log_exec_params() {
echo
echo -n "$0 parameters: "
for arg in "$@"; do echo -n "$arg "; done
echo
}
do_clone_commit() {
local commit="$1"
local src_dir=$2
local repo_url=$3
echo "Cloning commit: $commit from $repo_url into: $src_dir ..."
mkdir -p "$src_dir"
pushd "$src_dir"
git init
git remote add origin "$repo_url"
git fetch --depth 1 origin "$commit"
git checkout FETCH_HEAD
git submodule update --init --recursive
popd
}
do_clone_branch() {
local branch=$1
local src_dir="$2"
local repo_url="$3"
echo "Cloning branch: $branch from $repo_url ..."
git clone --recurse-submodules --shallow-submodules --single-branch --depth=1 --branch "$branch" -- "$repo_url" "$src_dir"
}
do_clone() {
local branch=$1
local src_dir="$2"
local repo_url="$3"
local commit="$4"
if [[ "$commit" != "" ]]; then
do_clone_commit $commit "$src_dir" $repo_url
else
do_clone_branch "$branch" "$src_dir" $repo_url
fi
}
#! /bin/bash
set -euo pipefail
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
LOG_FILE=setup_db.log
source "$SCRIPTPATH/common.sh"
log_exec_params "$@"
# Script reponsible for execution of all actions required to finish configuration of the database holding a HAF database to work correctly with hivemind.
print_help () {
echo "Usage: $0 [OPTION[=VALUE]]..."
echo
echo "Allows to setup a database already filled by HAF instance, to work with hivemind application."
echo "OPTIONS:"
echo " --host=VALUE Allows to specify a PostgreSQL host location (defaults to /var/run/postgresql)"
echo " --port=NUMBER Allows to specify a PostgreSQL operating port (defaults to 5432)"
echo " --postgres-url=URL Allows to specify a PostgreSQL URL (in opposite to separate --host and --port options)"
echo " --help Display this help screen and exit"
echo
}
POSTGRES_HOST="/var/run/postgresql"
POSTGRES_PORT=5432
POSTGRES_URL=""
while [ $# -gt 0 ]; do
case "$1" in
--host=*)
POSTGRES_HOST="${1#*=}"
;;
--port=*)
POSTGRES_PORT="${1#*=}"
;;
--postgres-url=*)
POSTGRES_URL="${1#*=}"
;;
--help)
print_help
exit 0
;;
-*)
echo "ERROR: '$1' is not a valid option"
echo
print_help
exit 1
;;
*)
echo "ERROR: '$1' is not a valid argument"
echo
print_help
exit 2
;;
esac
shift
done
if [ -z "$POSTGRES_URL" ]; then
POSTGRES_ACCESS="postgresql://haf_app_admin@$POSTGRES_HOST:$POSTGRES_PORT/haf_block_log"
else
POSTGRES_ACCESS=$POSTGRES_URL
fi
psql $POSTGRES_ACCESS -v ON_ERROR_STOP=on -c "CREATE EXTENSION IF NOT EXISTS intarray;"
#! /bin/bash
set -euo pipefail
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
LOG_FILE=setup_postgres.log
source "$SCRIPTPATH/common.sh"
log_exec_params "$@"
# Script reponsible for setup of specified postgres instance.
#
# - creates all builtin hivemind roles on pointed PostgreSQL server instance
print_help () {
echo "Usage: $0 [OPTION[=VALUE]]..."
echo
echo "Allows to setup a database already filled by HAF instance, to work with hivemind application."
echo "OPTIONS:"
echo " --host=VALUE Allows to specify a PostgreSQL host location (defaults to /var/run/postgresql)"
echo " --port=NUMBER Allows to specify a PostgreSQL operating port (defaults to 5432)"
echo " --postgres-url=URL Allows to specify a PostgreSQL URL (in opposite to separate --host and --port options)"
echo " --help Display this help screen and exit"
echo
}
supplement_builtin_roles() {
local pg_access="$1"
echo "Attempting to supplement definition of hivemind builtin roles..."
psql $pg_access -v ON_ERROR_STOP=on -c 'GRANT hivemind TO haf_app_admin;'
}
POSTGRES_HOST="/var/run/postgresql"
POSTGRES_PORT=5432
POSTGRES_URL=""
while [ $# -gt 0 ]; do
case "$1" in
--host=*)
POSTGRES_HOST="${1#*=}"
;;
--port=*)
POSTGRES_PORT="${1#*=}"
;;
--postgres-url=*)
POSTGRES_URL="${1#*=}"
;;
--help)
print_help
exit 0
;;
-*)
echo "ERROR: '$1' is not a valid option"
echo
print_help
exit 1
;;
*)
echo "ERROR: '$1' is not a valid argument"
echo
print_help
exit 2
;;
esac
shift
done
if [ -z "$POSTGRES_URL" ]; then
POSTGRES_ACCESS="postgresql://haf_app_admin@${POSTGRES_HOST}:${POSTGRES_PORT}/haf_block_log"
else
POSTGRES_ACCESS=$POSTGRES_URL
fi
"$SCRIPTPATH/../haf/scripts/create_haf_app_role.sh" --postgres-url="$POSTGRES_ACCESS" --haf-app-account="hivemind"
supplement_builtin_roles "$POSTGRES_ACCESS"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment