-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·72 lines (60 loc) · 2.43 KB
/
setup.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
#!/usr/bin/env bash
# Configs
function close {
echo "Ensure that you complete the pg_cron installation, further instructions can be found at: \n https://github.com/citusdata/pg_cron#setting-up-pg_cron"
echo "Optionally you may wish to add a password to the database"
}
trap close EXIT
# colours ~~ :)
CYAN='\033[0;36m'
RED='\033[0;38m'
NC='\033[0m'
USERDIR=$(eval echo ~${USER})
API_DIR=$(find ${USERDIR} "mynsb-api")
# -------- Downloads -----------
# PostgreSQL
service postgres status
if [ "$?" -gt "0" ]; then
echo -e "${CYAN}Installing PostgreSQL...${NC}"
# Repository setup
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
# installation
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
echo -e "${CYAN}Finished Installing Postgres${NC}"
fi
# Time to install the postgres packages
# Determine if they are there
# Pretty hacky for checking if an extension exists
DATA_DUMP=$(sudo -u postgres -H -- psql -c "select count(*) from pg_available_extensions where name='pg_cron';")
if echo "${DATA_DUMP}" | grep '[0]' >/dev/null; then
# pg_cron doesn't exist
echo -e "${CYAN}Installing pg_cron...${NC}"
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt-get -y install postgresql-10-cron
echo -e "${CYAN}Finished Installing pg_cron...${NC}"
fi
# Golang
if ! (command -v go | grep -q ^ >/dev/null); then
echo -e "${CYAN}Installing Golang...${NC}"
curl -O https://storage.googleapis.com/golang/go1.11.2.linux-amd64.tar.gz
tar -xvf go1.11.2.linux-amd64.tar.gz
sudo mv go ${USERDIR}
mkdir ${USERDIR}/workspace
echo "export GOROOT=\$HOME/go" >> ${USERDIR}/.bashrc
echo "export GOPATH=\$HOME/workspace" >> ${USERDIR}/.bashrc
echo "export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin" >> ${USERDIR}/.bashrc
source ${USERDIR}/.bashrc
echo -e "${CYAN}Finished Installing Golang...${NC}"
fi
# ----------- Setting Up -----------
# PostgreSQL
mv ${API_DIR} ${GOPATH}/src
# install db
sudo -u postgres -H -- psql -c "\i ${GOROOT}/src/mynsb-api/database/setup.sql" >/dev/null
# API
# install the api
go install mynsb-api
echo -e "${CYAN}CONGRATULATIONS! FINALLY INSTALLED MYNSB....${NC}"