From 95aee44f00cf0a2c77f7758f71281b53f5976472 Mon Sep 17 00:00:00 2001 From: demondave Date: Sun, 6 Feb 2022 23:04:59 +0100 Subject: [PATCH] Added build repo --- build/.gitignore | 5 ++++ build/build.sh | 53 ++++++++++++++++++++++++++++++++++++++++ build/watch.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 build/.gitignore create mode 100644 build/build.sh create mode 100644 build/watch.sh diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..ff54b6b --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,5 @@ +.env +out/ +backend/ +frontend/ +TheAdversary/ diff --git a/build/build.sh b/build/build.sh new file mode 100644 index 0000000..b82e708 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +src_dir=${SRCDIR:=./TheAdversary} +out_dir=${OUTDIR:=./out} + +local=false + +while getopts :l opts; do + case $opts in + l) local=true;; + esac +done + +pwd=$PWD + +if ! $local; then + read -p "Git username: " username + read -sp "$username git password: " password + + for name in backend frontend; do + path=$src_dir/$name + if [ -d "$path" ]; then + cd $path + git pull + cd $pwd + else + git clone https://$username:$password@mhsl.eu/gitea/TheAdversary/$name.git $path + fi + done +fi + +if [ ! -d "$out_dir" ]; then + mkdir $out_dir +fi + +# echo "INFO: Building sass files" +# for f in $(ls $src_dir/frontend/sass/*.sass); do +# sass --update $f $src_dir/frontend/sass/$(basename $f .sass).css +# done + +echo "INFO: Building backend" +cd $src_dir/backend +go build . TheAdversary +cd $pwd + +echo "INFO: Copying output to output directory" +for f in $src_dir/backend/{TheAdversary,database.sqlite3,.env}; do + cp -rf $f $out_dir +done + +for f in $src_dir/frontend; do + cp -rf $f $out_dir/frontend/ +done diff --git a/build/watch.sh b/build/watch.sh new file mode 100644 index 0000000..053828e --- /dev/null +++ b/build/watch.sh @@ -0,0 +1,63 @@ +init() { + for dir in frontend backend out; do + if [ ! -d $dir ]; then + mkdir $dir + if [ $dir != "out" ]; then + echo Cloning $dir + git clone https://mhsl.eu/gitea/TheAdversary/$dir.git + fi + fi + done +} + +build() { + pwd=$PWD + cd out/backend/ + go build . + cp -rf TheAdversary database.sqlite3 ../ + if [ ! -f ../../.env ]; then + cp -rf .env ../ + else + cp ../../.env ../ + fi + cd $pwd +} + +start() { + pwd=$PWD + cd out/ + ./TheAdversary + cd $pwd +} + +stop() { + kill $(pidof TheAdversary) +} + +process() { + sleep 5 + + cp -rf frontend/ backend/ out/ + build + echo "Restarting" + stop + start & +} + +main() { + init + cp -rf frontend/ backend/ out/ + build + if [ $? -eq 0 ]; then + start & + fi + + while inotifywait -r -e modify frontend/ backend/; do + if [ -d /proc/$! ]; then + kill $! + fi + process & + done +} + +main