Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -x
- set -o errexit
- PASSWORD=$(date +%s | sha256sum | base64 | head -c 32)
- INITSQL=/opt/postgres/initscripts/init_quac_db.sql
- CONTAINERS="guacamole guacd postgres"
- pause() {
- read -p "Enter to continue..."
- }
- clean() {
- stop
- docker system prune -a --force --volumes
- }
- clean_full() {
- echo "Removing all unused and dangling Docker Containers/Images/Volumes"
- clean
- # TODO put in check and warn if data is found before removing
- rm -rf /opt/postgres/data
- rm -rf /opt/postgres/initscripts
- mkdir -p /opt/postgres/data
- mkdir -p /opt/postgres/initscripts
- }
- #--attach STDOUT \
- s_postgres() {
- docker run \
- --name postgres \
- --detach \
- -e POSTGRES_PASSWORD=$PASSWORD \
- --volume /opt/postgres/data:/var/lib/postgresql/data \
- --volume /opt/postgres/initscripts:/docker-entrypoint-initdb.d \
- postgres
- }
- s_guacd() {
- docker run --name guacd -d guacamole/guacd
- }
- s_guacamole() {
- docker run --name guacamole \
- --link guacd:guacd \
- --link postgres:postgres \
- -e POSTGRES_DATABASE=guacamole_db \
- -e POSTGRES_USER=guacamole_user \
- -e POSTGRES_PASSWORD=$PASSWORD \
- -d -p 127.0.0.1:8080:8080 guacamole/guacamole
- }
- start() {
- s_postgres
- s_guacd
- s_guacamole
- }
- stop() {
- for C in $CONTAINERS; do
- if [ -n "$(docker ps -q --filter "Name=$C")" ]; then
- docker stop $C
- fi
- done
- }
- restart() {
- stop
- start
- }
- create_init_sql() {
- # Stop any running guac envs
- # Clean previous installed guac envs
- clean_full
- ID=$(docker create guacamole/guacamole)
- echo "CREATE DATABASE guacamole_db;" > $INITSQL
- echo "\connect guacamole_db" >> $INITSQL
- docker cp $ID:/opt/guacamole/postgresql/schema/001-create-schema.sql - | tar -xO >> $INITSQL
- docker cp $ID:/opt/guacamole/postgresql/schema/002-create-admin-user.sql - | tar -xO >> $INITSQL
- docker rm -v $ID
- echo "CREATE USER guacamole_user WITH PASSWORD '$PASSWORD';" >> $INITSQL
- echo "GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA public TO guacamole_user;" >> $INITSQL
- echo "GRANT SELECT,USAGE ON ALL SEQUENCES IN SCHEMA public TO guacamole_user;" >> $INITSQL
- echo "GRANT ALL PRIVILEGES ON DATABASE guacamole_db TO guacamole_user;" >> $INITSQL
- chmod 777 /opt/postgres/initscripts
- chmod 777 $INITSQL
- stop
- }
- # Create guacamole db init scripts
- create_init_sql
- # Start Guac env with mapping created sql init scripts.
- start
Add Comment
Please, Sign In to add comment