diff --git a/lib/add_bc_user.sh b/lib/add_bc_user.sh index 3034c0a..6ff4c92 100755 --- a/lib/add_bc_user.sh +++ b/lib/add_bc_user.sh @@ -1,15 +1,29 @@ #!/bin/bash -e echo "This script add's a user with password to the bridghead" + +if [ $# -eq 0 ]; then + echo "No arguments provided, please provide the prject name" + exit 1 +fi + +if [ ! -f /etc/systemd/system/bridgehead@$1.service.d/override.conf ]; then + echo "Please create a Service first, with setup-bridgehead-units.sh" + exit +fi + read -p 'Username: ' bc_user read -sp 'Password: ' bc_password -echo +echo -bc=$(docker run --rm -ti xmartlabs/htpasswd $bc_user $bc_password) -if [ -z $bc_auth_users ]; then - printf "Please run: export bc_auth_users=\"%q\"" $bc -else - echo "Please run: export bc_auth_users=\"${bc},$bc_auth_users\"" +bc=`docker run --rm -it httpd:latest htpasswd -nb $bc_user $bc_password` + +if grep -q -E "Environment=bc_auth_users=" /etc/systemd/system/bridgehead@$1.service.d/override.conf ; then + x=`grep -E "Environment=bc_auth_users=" /etc/systemd/system/bridgehead@$1.service.d/override.conf` + sed -i "/Environment=bc_auth_users=/c\\$x,$bc" /etc/systemd/system/bridgehead@$1.service.d/override.conf + +else + echo "Environment=bc_auth_users=${bc}" >> /etc/systemd/system/bridgehead@$1.service.d/override.conf fi \ No newline at end of file diff --git a/start-bridgehead.sh b/start-bridgehead.sh index 0d534e9..cbeef04 100755 --- a/start-bridgehead.sh +++ b/start-bridgehead.sh @@ -1,6 +1,11 @@ #!/bin/bash ### Note: Currently not complete, needs some features before useable for production +if [ $# -eq 0 ]; then + echo "No arguments provided" + exit 1 +fi + source lib/functions.sh if ! lib/prerequisites.sh; then