From e9fec2c55e4ded3e51d4f2c248aead4ca6252b76 Mon Sep 17 00:00:00 2001 From: Lorenzo Carbonell Date: Mon, 3 Oct 2022 20:34:39 +0200 Subject: [PATCH] binary --- snibox/bin/restart | 2 ++ snibox/bin/setup | 56 ++++++++++++++++++++++++++++++++++++++++++++++ snibox/bin/start | 2 ++ snibox/bin/stop | 2 ++ 4 files changed, 62 insertions(+) create mode 100755 snibox/bin/restart create mode 100755 snibox/bin/setup create mode 100755 snibox/bin/start create mode 100755 snibox/bin/stop diff --git a/snibox/bin/restart b/snibox/bin/restart new file mode 100755 index 0000000..a59cca6 --- /dev/null +++ b/snibox/bin/restart @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose restart $@ diff --git a/snibox/bin/setup b/snibox/bin/setup new file mode 100755 index 0000000..4619703 --- /dev/null +++ b/snibox/bin/setup @@ -0,0 +1,56 @@ +#!/bin/bash + +set -e + +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[0;33m' +NC='\033[0m' + +DEFAULT_SECRET='paste_your_key' + +function report_status() { + if [ $? -eq 0 ] + then + echo -e "${GREEN}Done${NC}" + else + echo -e "${RED}Unable to complete task${NC}" + exit 1 + fi +} + +echo -e "Copy .env.sample to .env:" +if [ ! -f .env ] +then + cp .env.sample .env + report_status +else + echo -e "${GREEN}File .env already exists${NC}" +fi + +echo -e "\nPull images:" +docker-compose pull +report_status + +echo -e "\nInject secret key:" +if grep -Rq "$DEFAULT_SECRET" .env +then + secret=$(docker-compose run --rm --no-deps backend ./bin/rake secret) + echo "$secret" + # based on https://stackoverflow.com/a/22084103 + sed -i.bak "s/$DEFAULT_SECRET/$secret/" .env + rm .env.bak + report_status +else + echo -e "${GREEN}Personal secret key exists${NC}" +fi + +echo -e "\nCreate database:" +docker-compose run --rm backend ./bin/rake db:create +report_status + +echo -e "\nRun migrations:" +docker-compose run --rm backend ./bin/rake db:migrate +report_status + +echo -e "\n${GREEN}Setup completed!${NC}" diff --git a/snibox/bin/start b/snibox/bin/start new file mode 100755 index 0000000..af59c8a --- /dev/null +++ b/snibox/bin/start @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose up -d $@ diff --git a/snibox/bin/stop b/snibox/bin/stop new file mode 100755 index 0000000..9bc4043 --- /dev/null +++ b/snibox/bin/stop @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose stop $@