Skip to content

Commit

Permalink
initial rework of scripts directory and install flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Rye committed Jan 23, 2019
1 parent 4004f03 commit 1b1fc1b
Show file tree
Hide file tree
Showing 67 changed files with 468 additions and 134 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pyudev==0.21.0
whitenoise==4.1
django-bootstrap-static==4.0.0
django-tempus-dominus==5.0.1.2
pyftdi==0.29.2
17 changes: 0 additions & 17 deletions scripts/backup/forward_ports.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/dac.sh

This file was deleted.

18 changes: 18 additions & 0 deletions scripts/database/create_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Log creation status
echo 'Creating database...'

# Create database on linux operating system
if [[ "$OSTYPE" == "linux"* ]]; then
sudo -u postgres psql -c "CREATE DATABASE openag_brain OWNER openag;"

# Create database on darwin operating system
elif [[ "$OSTYPE" == "darwin"* ]]; then
psql postgres -c "CREATE DATABASE openag_brain OWNER openag;"

# Unsupported operating system
else
echo "Unable to create database, unsupported operating system: $OSTYPE"
exit 1
fi
20 changes: 20 additions & 0 deletions scripts/database/create_postgres_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Log creation status
echo 'Creating postgres user...'

# Create database on linux operating system
if [[ "$OSTYPE" == "linux"* ]]; then
sudo -u postgres psql -c "CREATE USER openag WITH PASSWORD 'openag';"
sudo -u postgres psql -c "ALTER USER openag SUPERUSER;"

# Create database on darwin operating system
elif [[ "$OSTYPE" == "darwin"* ]]; then
psql postgres -c "CREATE USER openag WITH PASSWORD 'openag';"
psql postgres -c "ALTER USER openag SUPERUSER;"

# Unsupported operating system
else
echo "Unable to create database, unsupported operating system: $OSTYPE"
exit 1
fi
27 changes: 27 additions & 0 deletions scripts/database/create_project_users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Log creation status
echo "Creating project users..."

# Check virtual environment is activated
if [[ -z "${VIRTUAL_ENV}" ]] ; then
echo "Please activate your virtual environment then re-run script"
exit 1
fi

# Check project root exists
if [[ -z "$PROJECT_ROOT" ]]; then
echo "Please set your project root in your virtual environment then re-run script"
exit 1
fi

# Check python3.6 is installed
INSTALL_PATH=`which python3.6`
if [[ ! -f "$INSTALL_PATH" ]]; then
echo "Please install python3.6 then re-run script"
exit 1
fi

# Create project users
echo "from django.contrib.auth.models import User; User.objects.filter(email='[email protected]').delete(); User.objects.create_superuser('openag', '[email protected]', 'openag')" | python3.6 $PROJECT_ROOT/manage.py shell
echo "from django.contrib.auth.models import User; User.objects.create_superuser('backdoor', '[email protected]', 'B@ckd00r')" | python3.6 $PROJECT_ROOT/manage.py shell
18 changes: 18 additions & 0 deletions scripts/database/drop_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Log recreation status
echo 'Dropping database...'

# Recreate on linux operating system
if [[ "$OSTYPE" == "linux"* ]]; then
sudo -u postgres psql -c "DROP DATABASE openag_brain;"

# Recreate on darwin operating system
elif [[ "$OSTYPE" == "darwin"* ]]; then
psql postgres -c "DROP DATABASE openag_brain;"

# Invalid operating system
else
echo "Unable to drop database, unsupported operating system: $OSTYPE"
exit 1
fi
18 changes: 18 additions & 0 deletions scripts/database/drop_state_table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Log drop status
echo 'Dropping state table...'

# Drop state table on linux operating system
if [[ "$OSTYPE" == "linux"* ]]; then
sudo -u postgres psql openag_brain -c "DELETE FROM app_statemodel;"

# Drop state table on darwin operating system
elif [[ "$OSTYPE" == "linux"* ]]; then
psql postgres openag_brain -c "DELETE FROM app_statemodel;"

# Invalid operating system
else
echo "Unable to drop state table, unsupported operating system: $OSTYPE"
exit 1
fi
3 changes: 3 additions & 0 deletions scripts/database/list_databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

psql --username=openag openag_brain -c '\l'
3 changes: 3 additions & 0 deletions scripts/database/list_tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

psql --username=openag openag_brain -c '\dt'
26 changes: 26 additions & 0 deletions scripts/database/migrate_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Log migration status
echo "Migrating database..."

# Check virtual environment is activated
if [[ -z "${VIRTUAL_ENV}" ]] ; then
echo "Please activate your virtual environment then re-run script"
exit 1
fi

# Check project root exists
if [[ -z "$PROJECT_ROOT" ]]; then
echo "Please set your project root in your virtual environment then re-run script"
exit 1
fi

# Check python3.6 is installed
INSTALL_PATH=`which python3.6`
if [[ ! -f "$INSTALL_PATH" ]]; then
echo "Please install python3.6 then re-run script"
exit 1
fi

# Migrate database
python3.6 $PROJECT_ROOT/manage.py migrate
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions scripts/install.sh → scripts/deprecated/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Install python 3 and postgres on linux machine
if [[ "$OSTYPE" == "linux"* ]]; then
# Our production install for Debian 9.3 on the BBB. (also Ubuntu for dev)
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install postgresql -y
Expand All @@ -10,8 +10,8 @@ if [[ "$OSTYPE" == "linux"* ]]; then
sudo apt-get install libpq-dev -y
sudo apt-get install python3-pip -y

# Install python 3 and postgres on osx machine
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Development install on OSX
# Please run "brew upgrade" if it is recommended (it will fix python3 issues)
if ! type brew >/dev/null 2>&1; then
echo 'Installing brew:'
Expand All @@ -28,21 +28,20 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install python3
fi

# Always need to install/reinstall venv
echo 'Installing virtualenv:'
pip3 install virtualenv

if ! type postgres >/dev/null 2>&1; then
echo 'Installing postgresql:'
brew install postgresql
# Start postgres now, and upon every reboot
brew services start postgresql
fi

else
echo "Unsupported OS: $OSTYPE, please manually install postgres and python3"
fi

# Always need to install/reinstall venv
echo 'Installing virtualenv:'
pip3 install virtualenv

# Install the python static type checker - used when testing.
python3 -m pip install -U mypy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ echo "from django.contrib.auth.models import User; User.objects.filter(email='op
echo "from django.contrib.auth.models import User; User.objects.create_superuser('backdoor', '[email protected]', 'B@ckd00r')" | python3.6 manage.py shell


# How to list the databases:
# psql --username=openag openag_brain -c '\l'

# How to list the tables in our database:
# psql --username=openag openag_brain -c '\dt'

# How to log into postgres interactively:
# psql --username=openag openag_brain

15 changes: 0 additions & 15 deletions scripts/download_pip_packages.sh

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/drop_database.sh

This file was deleted.

9 changes: 0 additions & 9 deletions scripts/drop_db_state.sh

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/fresh_pi_install.sh

This file was deleted.

11 changes: 0 additions & 11 deletions scripts/get_status_sht25.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 0 additions & 27 deletions scripts/initialize_raspi_access_point_toggle.sh

This file was deleted.

File renamed without changes.
38 changes: 38 additions & 0 deletions scripts/install/create_virtual_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Log creation status
echo "Creating virtual environment..."

# Install on linux or darwin operating system
if [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "darwin"* ]]; then

# Ensure virtualenv is installed
INSTALL_PATH=`which virtualenv`
if [[ ! -f "$INSTALL_PATH" ]]; then

# Log install status
echo "Installing virtualenv..."

# Check pip3.6 is installed
INSTALL_PATH=`which pip3.6`
if [[ ! -f "$INSTALL_PATH" ]]; then
echo "Unable to install virtualenv, pip3.6 is not installed"
exit 1
fi

# Install virtualenv
pip3.6 install virtualenv

fi

# Remove any existing virtual environment
rm -fr venv

# Create virtual environment
virtualenv -p python3.6 venv

# Invalid operating system
else
echo "Unable to create virtual environment, unsupported operating system: $OSTYPE"
exit 1
fi
14 changes: 14 additions & 0 deletions scripts/install/initialize_virtual_environment_activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Initialize passed in variables
PROJECT_ROOT=$1

# TODO: Make sure we received project root as passed in parameter

# Set project root as environment variable in virtual environment
printf "\n# Set project root\n" >> $PROJECT_ROOT/venv/bin/activate
echo "export PROJECT_ROOT=$PROJECT_ROOT" >> $PROJECT_ROOT/venv/bin/activate

# Set platform environment variables in virtual environment
printf "\n# Set platform variables\n" >> $PROJECT_ROOT/venv/bin/activate
echo "source $PROJECT_ROOT/scripts/platform/get_platform_info.sh" >> $PROJECT_ROOT/venv/bin/activate
Loading

0 comments on commit 1b1fc1b

Please sign in to comment.