#! /bin/bash main() { set -e set -o pipefail set -u trap cleanup SIGINT ERR EXIT cd "$(dirname "$BASH_SOURCE")" mkdir -p "$PWD/tmp" build_authelia echo cp $GOPATH/src/github.com/authelia/authelia/compose/lite/authelia/* ./ start_sidecars } build_authelia_docker() { build_authelia rm -rf ./authelia cp -r $GOPATH/src/github.com/authelia/authelia ./authelia pushd authelia export GOFLAGS="" export GO111MODULE="" go mod vendor export GOFLAGS="-mod=vendor" export GO111MODULE="off" popd docker build -t bel/authelia:v0.0 . } build_authelia() { if which authelia &> /dev/null; then return fi export INLINE_RUNTIME_CHUNK=false export CGO_ENABLED=1 export GOFLAGS="" export GO111MODULE="" repo=github.com/authelia/authelia pushd $GOPATH/src/$repo if ! cat internal/server/public_html/index.html | grep -q .; then pushd web yarn install yarn build popd rm -rf ./internal/server/public_html mv web/build ./internal/server/public_html cp -r api ./internal/server/public_html/ fi rm -rf web/node_modules git_commit=$( ( git rev-list -1 HEAD if git diff | grep . > /dev/null; then echo "-dirty" fi ) 2> /dev/null | tr -d '\n' ) common=("-a" "-installsuffix" "cgo" "-ldflags" "-s -w -X main.GitCommit=$git_commit") pushd cmd/authelia go build -o $GOPATH/bin/authelia "${common[@]}" popd popd export GOFLAGS="-mod=vendor" export GO111MODULE="off" } start_sidecars() { start_cleanup start_rproxy3 & start_pretend & start_echo & start_authelia & wait -n 1 } start_cleanup() { trap cleanup SIGINT ERR EXIT } start_rproxy3() { rproxy3 \ -p 9500 \ -proxy authelia,http://localhost:9491$( start_port=9500 for i in {x..z}; do ((start_port+=1)) printf ",,%s,http://localhost:%d" $i $start_port done ) \ -crt ./*.crt \ -key ./*.key \ -authelia https://authelia.bel.lan:9500 \ } start_pretend() { pretend -config ./pretend.yaml } start_echo() { start_cleanup for p in {9502..9503}; do echo-server -p $p & done wait -n 1 } start_authelia() { #export ENVIRONMENT=dev authelia --config ./configuration.yml } cleanup() { jobs -p kill -9 $(jobs -p) jobs trap - SIGINT ERR EXIT } if [ "$0" == "$BASH_SOURCE" ]; then main "$@" fi