mirror of
				https://github.com/samply/bridgehead.git
				synced 2025-11-04 08:20:17 +01:00 
			
		
		
		
	add generic bash function addBasicAuthUser
This commit is contained in:
		@@ -183,3 +183,27 @@ function bk_is_running {
 | 
			
		||||
##Setting Network properties
 | 
			
		||||
# currently not needed
 | 
			
		||||
#export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}');
 | 
			
		||||
addBasicAuthUser() {
 | 
			
		||||
  USER="${1}"
 | 
			
		||||
  PASSWORD="${2}"
 | 
			
		||||
  NAME="${3}"
 | 
			
		||||
  PROJECT="${4}"
 | 
			
		||||
  FILE="/etc/bridgehead/${PROJECT}.local.conf"
 | 
			
		||||
  ENCRY_CREDENTIALS="$(docker run --rm docker.verbis.dkfz.de/cache/httpd:alpine htpasswd -nb $USER $PASSWORD  | tr -d '\n' | tr -d '\r')"
 | 
			
		||||
  if [ -f $FILE ] && grep -R -q "$NAME=" $FILE # if a basic auth user already exists:
 | 
			
		||||
  then
 | 
			
		||||
    sed -i "/$NAME/ s/$/,$ENCRY_CREDENTIALS/" $FILE
 | 
			
		||||
  else
 | 
			
		||||
    echo -e "\n## Basic Authentication Credentials for:\n$NAME=$ENCRY_CREDENTIALS" >> $FILE;
 | 
			
		||||
  fi
 | 
			
		||||
  read -p "Do you want to have your cleartext credentials saved in your $FILE: [y/n]" yn
 | 
			
		||||
  case $yn in
 | 
			
		||||
      [yYjJ] )
 | 
			
		||||
        echo "ok, variables are saved in $FILE"
 | 
			
		||||
        echo -e "# User: $USER\n# Password: $PASSWORD" >> $FILE;
 | 
			
		||||
        ;;
 | 
			
		||||
      [nN] )
 | 
			
		||||
        echo "skip saving cleartext LDM credentials; make sure to save them somewhere else"
 | 
			
		||||
        ;;
 | 
			
		||||
  esac
 | 
			
		||||
}
 | 
			
		||||
@@ -34,7 +34,7 @@ if [ -z "$LDM_PASSWORD" ]; then
 | 
			
		||||
  generated_passwd="$(cat /proc/sys/kernel/random/uuid | sed 's/[-]//g' | head -c 32)"
 | 
			
		||||
 | 
			
		||||
  log "INFO" "Your generated credentials are:\n            user: $PROJECT\n            password: $generated_passwd"
 | 
			
		||||
  echo -e "## Local Data Management Basic Authentication\n# User: $PROJECT\nLDM_PASSWORD=$generated_passwd" >> /etc/bridgehead/${PROJECT}.local.conf;
 | 
			
		||||
  addBasicAuthUser $PROJECT $generated_passwd "LDM_LOGIN" $PROJECT
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
log "INFO" "Registering system units for bridgehead and bridgehead-update"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								lib/sitespecific-functions.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								lib/sitespecific-functions.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
#!/bin/bash -e
 | 
			
		||||
source lib/functions.sh
 | 
			
		||||
PROJECT="ccp"
 | 
			
		||||
log "INFO" "Adding custom encrypted credentials in /etc/bridgehead/$PROJECT.local.conf"
 | 
			
		||||
read -p "Please enter custom user: " user
 | 
			
		||||
read -s -p "Please enter password (will not be echoed): "$'\n' password
 | 
			
		||||
addBasicAuthUser $user $password "NNGM_AUTH" $PROJECT
 | 
			
		||||
		Reference in New Issue
	
	Block a user