bridgehead/lib/add_bc_user.sh

29 lines
950 B
Bash
Raw Normal View History

2022-03-28 15:34:57 +02:00
#!/bin/bash -e
2022-05-09 12:57:24 +02:00
source lib/functions.sh
2022-03-28 15:34:57 +02:00
2022-05-09 12:57:24 +02:00
log "This script add's a user with password to the bridghead"
2022-04-11 15:28:11 +02:00
if [ $# -eq 0 ]; then
2022-05-09 12:57:24 +02:00
log "No arguments provided, please provide the project name"
2022-04-11 15:28:11 +02:00
exit 1
fi
if [ ! -f /etc/systemd/system/bridgehead@$1.service.d/override.conf ]; then
2022-05-09 12:57:24 +02:00
log "Please create a Service first, with setup-bridgehead-units.sh"
2022-04-11 15:28:11 +02:00
exit
fi
2022-03-28 15:34:57 +02:00
read -p 'Username: ' bc_user
read -sp 'Password: ' bc_password
2022-04-11 15:28:11 +02:00
echo
bc=`docker run --rm -it httpd:latest htpasswd -nb $bc_user $bc_password`
2022-03-28 15:34:57 +02:00
2022-04-11 15:28:11 +02:00
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
2022-04-04 14:02:03 +02:00
fi