mirror of
				https://gitea.publichub.eu/oscar.krause/fastapi-dls.git
				synced 2025-11-04 01:16:07 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
#!/bin/bash
 | 
						|
 | 
						|
WORKING_DIR=/usr/share/fastapi-dls
 | 
						|
CONFIG_DIR=/etc/fastapi-dls
 | 
						|
 | 
						|
while true; do
 | 
						|
  [ -f $CONFIG_DIR/webserver.key ] && default_answer="N" || default_answer="Y"
 | 
						|
  [ $default_answer == "Y" ] && V="Y/n" || V="y/N"
 | 
						|
  read -p "> Do you wish to create self-signed webserver certificate? [${V}]" yn
 | 
						|
  yn=${yn:-$default_answer} # ${parameter:-word} If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
 | 
						|
  case $yn in
 | 
						|
  [Yy]*)
 | 
						|
    echo "> Generating keypair ..."
 | 
						|
    openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $CONFIG_DIR/webserver.key -out $CONFIG_DIR/webserver.crt
 | 
						|
    break
 | 
						|
    ;;
 | 
						|
  [Nn]*) echo "> Generating keypair skipped! (exists)"; break ;;
 | 
						|
  *) echo "Please answer [y] or [n]." ;;
 | 
						|
  esac
 | 
						|
done
 | 
						|
 | 
						|
if [ -f $CONFIG_DIR/webserver.key ]; then
 | 
						|
  echo "> Starting service ..."
 | 
						|
  systemctl start fastapi-dls.service
 | 
						|
 | 
						|
  if [ -x "$(command -v curl)" ]; then
 | 
						|
    echo "> Testing API ..."
 | 
						|
    source $CONFIG_DIR/env
 | 
						|
    curl --insecure -X GET https://$DLS_URL:$DLS_PORT/-/health
 | 
						|
  else
 | 
						|
    echo "> Testing API failed, curl not available. Please test manually!"
 | 
						|
  fi
 | 
						|
fi
 | 
						|
 | 
						|
chown -R www-data:www-data $CONFIG_DIR
 | 
						|
chown -R www-data:www-data $WORKING_DIR
 | 
						|
 | 
						|
cat <<EOF
 | 
						|
 | 
						|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 | 
						|
#                                                                             #
 | 
						|
#    fastapi-dls is now installed.                                            #
 | 
						|
#                                                                             #
 | 
						|
#    Service should be up and running.                                        #
 | 
						|
#      Webservice is listen to https://localhost                              #
 | 
						|
#                                                                             #
 | 
						|
#    Configuration is stored in /etc/fastapi-dls/env.                         #
 | 
						|
#                                                                             #
 | 
						|
#                                                                             #
 | 
						|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 | 
						|
 | 
						|
EOF
 |