Skip to content

Commit

Permalink
Add automatic database creation to install script
Browse files Browse the repository at this point in the history
The installation script will now automatically install
the augur database schemas if prompted by the user.

Signed-off-by: Carter Landis <[email protected]>
  • Loading branch information
ccarterlandis committed Sep 20, 2019
1 parent f34241e commit 39a481d
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 123,069 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ __pycache__/
*$py.class
*.pyc
augur_venv/

runtime/
logs/

# C extensions
*.so
Expand Down
5 changes: 3 additions & 2 deletions augur/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def upgrade(app, from_directory):
"""
Print the location of the interpreter that is running this
"""
app.log.info(pyrcss.util.self_upgrade(from_directory=from_directory, dry_run=True))
pyrcss.util.self_upgrade(from_directory=from_directory)
pass
# app.log.info(pyrcss.util.self_upgrade(from_directory=from_directory, dry_run=true))
# pyrcss.util.self_upgrade(from_directory=from_directory)


@cli.command('test', short_help='Test Augur')
Expand Down
2 changes: 2 additions & 0 deletions augur_localstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

./augur_localkill.sh

# TODO: make sure the logs/ directory is present

if [[ $(ps x -o pid= -p $(cat logs/augur_backend_pid.txt) | wc -l) -ge 1 ]]; then
echo "Backend server already running."
else
Expand Down
1 change: 0 additions & 1 deletion logs/augur_backend.err

This file was deleted.

1 change: 0 additions & 1 deletion logs/augur_backend_pid.txt

This file was deleted.

1 change: 0 additions & 1 deletion logs/augur_backend_pid.txt.orig

This file was deleted.

122,936 changes: 0 additions & 122,936 deletions logs/augur_frontend.err

This file was deleted.

1 change: 0 additions & 1 deletion logs/augur_frontend_pid.txt

This file was deleted.

1 change: 0 additions & 1 deletion logs/augur_frontend_pid.txt.orig

This file was deleted.

1 change: 0 additions & 1 deletion logs/backend.pid

This file was deleted.

177 changes: 67 additions & 110 deletions util/scripts/install/augurinstall.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

PS3="Press the number corresponding to your selection.
PS3="
Please type the number corresponding to your selection and then press the Enter/Return key.
Your choice: "

echo
Expand Down Expand Up @@ -68,7 +69,7 @@ echo "Checking for virtual environment..."
echo "**********************************"
echo
if [[ -z $VIRTUAL_ENV ]]; then
echo "*** We noticed you're not using a virtual environment. It is STRONGLY recommended to install Augur in its own virutal environment. ***"
echo "*** We noticed you're not using a virtual environment. It is STRONGLY recommended to install Augur in its own virtual environment. ***"
echo "*** Would you like to create a virtual environment? ***"
select choice in "Yes" "No"
do
Expand Down Expand Up @@ -107,115 +108,71 @@ else
echo "Virtual environment detected under `echo $VIRTUAL_ENV`. Resuming installation..."
fi

echo
echo "**********************************"
echo "Installing backend dependencies..."
echo "**********************************"
echo

rm -rf build/*; rm -rf dist/*; rm $VIRTUAL_ENV/bin/*worker*;
pip install pipreqs sphinx xlsxwriter;
pip install -e .;
pip install xlsxwriter;
pip install ipykernel;
python -m ipykernel install --user --name augur --display-name "Python (augur)";
npm install apidoc;
python setup.py install;

echo
echo "**********************************"
echo "Installing workers and their dependencies..."
echo "**********************************"
echo
for OUTPUT in $(ls -d workers/*/)
do
if [[ $OUTPUT == *"_worker"* ]]; then
cd $OUTPUT
echo "Running setup for $(basename $(pwd))"
rm -rf build/*;
rm -rf dist/*;
python setup.py install;
pip install -e .
cd ../..
fi
done

echo "Would you like to install Augur's frontend dependencies?"
select choice in "Yes" "No"
do
case $choice in
"Yes" )
echo
echo "**********************************"
echo "Installing frontend dependencies..."
echo "**********************************"
echo
cd frontend/;
npm install brunch canvas vega @vue/cli;
npm install;
npm run build;
cd ../;
break
;;
"No" )
echo "Skipping frontend dependencies..."
break
;;
esac
done
# echo
# echo "**********************************"
# echo "Installing backend dependencies..."
# echo "**********************************"
# echo

# rm -rf build/*; rm -rf dist/*; rm $VIRTUAL_ENV/bin/*worker*;
# pip install pipreqs sphinx xlsxwriter;
# pip install -e .;
# pip install xlsxwriter;
# pip install ipykernel;
# python -m ipykernel install --user --name augur --display-name "Python (augur)";
# npm install apidoc;
# python setup.py install;

# echo
# echo "**********************************"
# echo "Installing workers and their dependencies..."
# echo "**********************************"
# echo
# for OUTPUT in $(ls -d workers/*/)
# do
# if [[ $OUTPUT == *"_worker"* ]]; then
# cd $OUTPUT
# echo "Running setup for $(basename $(pwd))"
# rm -rf build/*;
# rm -rf dist/*;
# python setup.py install;
# pip install -e .
# cd ../..
# fi
# done

# echo "Would you like to install Augur's frontend dependencies?"
# select choice in "Yes" "No"
# do
# case $choice in
# "Yes" )
# echo
# echo "**********************************"
# echo "Installing frontend dependencies..."
# echo "**********************************"
# echo
# cd frontend/;
# npm install brunch canvas vega @vue/cli;
# npm install;
# npm run build;
# cd ../;
# break
# ;;
# "No" )
# echo "Skipping frontend dependencies..."
# break
# ;;
# esac
# done

# echo
# echo "**********************************"
# echo "Setting up API documentation..."
# echo "**********************************"
# echo

# cd docs && apidoc --debug -f "\.py" -i ../augur/ -o api/; rm -rf ../frontend/public/api_docs; mv api ../frontend/public/api_docs; cd ..

echo
echo "**********************************"
echo "Setting up API documentation..."
echo "**********************************"
echo

cd docs && apidoc --debug -f "\.py" -i ../augur/ -o api/; rm -rf ../frontend/public/api_docs; mv api ../frontend/public/api_docs; cd ..

echo
echo "**********************************"
echo "Setting up the database configuration..."
echo "**********************************"
echo

function generate_config_file() {
echo
echo "**********************************"
echo "Generating configuration file..."
echo "**********************************"
echo
python make_config.py
rm temp.config.json
}

function enter_db_credentials() {

cd util/scripts/install

read -p "database: " database
read -p "host: " host
read -p "port: " port
read -p "user: " user
read -p "password: " password
read -p "key: " key

config="
{
\"database\": \"$database\",
\"host\": \"$host\",
\"port\": \"$port\",
\"user\": \"$user\",
\"password\": \"$password\",
\"key\": \"$key\"
}"

rm temp.config.json
touch temp.config.json
echo $config > temp.config.json

python make_config.py
rm temp.config.json
}

on_command_line=false
echo
Expand Down
118 changes: 104 additions & 14 deletions util/scripts/install/setup_db.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,119 @@
#!/bin/bash

PS3="
Please type the number corresponding to your selection and then press the Enter/Return key.
Your choice: "

echo
echo "**********************************"
echo "Setting up the database configuration..."
echo "**********************************"
echo

function generate_config_file() {

echo
echo "**********************************"
echo "Generating configuration file..."
echo "**********************************"
echo

INSTALL_SCRIPT_HOME="util/scripts/install"
cd $INSTALL_SCRIPT_HOME

rm temp.config.json
touch temp.config.json

echo $1 > temp.config.json

python make_config.py

rm temp.config.json

cd ../../.. #get back to augur root
}

function set_remote_db_credentials() {

read -p "database: " database
read -p "host: " host
read -p "port: " port
read -p "user: " user
read -p "password: " password
read -p "key: " key

config="
{
\"database\": \"$database\",
\"host\": \"$host\",
\"port\": \"$port\",
\"user\": \"$user\",
\"password\": \"$password\",
\"key\": \"$key\"
}"

# generate_config_file $config
}

function set_local_db_credentials() {

read -p "database: " database
read -p "user: " user
read -p "port: " port
read -p "password: " password
read -p "key: " key

config="
{
\"database\": \"$database\",
\"host\": \"localhost\",
\"port\": \"$port\",
\"user\": \"$augur\",
\"password\": \"$password\",
\"key\": \"$key\"
}"

# generate_config_file $config
}

echo "If you need to install Postgres, the downloads can be found here: https://www.postgresql.org/download/"
installpostgreslocally="Would you like to use a pre-existing Postgres 10 or 11 installation to which you can install the Augur schema?"
installpostgresremotely="Would you like to use a pre-existing Postgres 10 or 11 installation to which someone else can install the Augur schema?"
postgresalreadyinstalled="Would you like to use a pre-existing Postgres 10 or 11 installation with the Augur schema already installed? "
echo
install_locally="Would you like to use a LOCAL Postgres 10 or 11 installation without the database already installed?"
install_remotely="Would you like to use a REMOTE Postgres 10 or 11 installation without the database already installed?"
already_installed="Would you like to use a pre-existing Postgres 10 or 11 installation with the Augur database ALREADY installed? "
SKIP="Skip this section"
echo

select haveinstalledpostgres in "$installpostgreslocally" "$installpostgresremotely" "$postgresalreadyinstalled" "$SKIP"
select install_location in "$install_locally" "$install_remotely" "$already_installed" "$SKIP"
do
case $haveinstalledpostgres in
case $install_location in
$SKIP )
echo
echo "Skipping database configuration..."
echo
break
;;
$installpostgreslocally )
echo "After you have installed the Augur schema to your database, please return to this point in the installation."
echo "Please enter the credentials for your database."
enter_db_credentials
$install_locally )
echo "Please set the credentials for your database."
set_local_db_credentials
psql -c "create database $database;"
psql -c "create user $user with encrypted password '$password';"
psql -c "alter database $database owner to $user;"
psql -c "grant all privileges on database $database to $user;"
psql -h "localhost" -d $database -U $user -p $port -a -w -f augur/persistence_schema/0-all.sql
break
;;
$installpostgresremotely )
echo "Once the Augur schema has been installed on to your database for you, please return to this point in the installation."
echo "Please enter the credentials for your database."
enter_db_credentials
$install_remotely )
echo "Please set the credentials for your database."
set_remote_db_credentials
psql -h $host -p $port -c "create database $database;"
psql -h $host -p $port -c "create user $user with encrypted password '$password';"
psql -h $host -p $port -c "alter database $database owner to $user;"
psql -h $host -p $port -c "grant all privileges on database $database to $user;"
psql -h $host -d $database -U $user -p $port -a -w -f augur/persistence_schema/0-all.sql
break
;;
$postgresalreadyinstalled )
$already_installed )
echo "Please enter the credentials for your database."
enter_db_credentials
break
Expand Down

0 comments on commit 39a481d

Please sign in to comment.