2022-12-22 09:41:07 +00:00
#!/bin/bash
2022-12-28 06:40:44 +00:00
WORKING_DIR=/usr/share/fastapi-dls
2022-12-28 06:03:41 +00:00
CONFIG_DIR=/etc/fastapi-dls
2023-01-04 10:02:54 +00:00
if [[ ! -f $CONFIG_DIR/instance.private.pem ]]; then
echo "> Create dls-instance keypair ..."
openssl genrsa -out $CONFIG_DIR/instance.private.pem 2048
openssl rsa -in $CONFIG_DIR/instance.private.pem -outform PEM -pubout -out $CONFIG_DIR/instance.public.pem
else
echo "> Create dls-instance keypair skipped! (exists)"
2022-12-28 08:04:35 +00:00
fi
2022-12-22 09:41:07 +00:00
while true; do
2023-01-04 10:02:54 +00:00
[[ -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.
2022-12-22 09:41:07 +00:00
case $yn in
[Yy]*)
2023-01-04 10:02:54 +00:00
echo "> Generating keypair ..."
2022-12-22 09:41:07 +00:00
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $CONFIG_DIR/webserver.key -out $CONFIG_DIR/webserver.crt
break
;;
2023-01-04 10:02:54 +00:00
[Nn]*) echo "> Generating keypair skipped! (exists)"; break ;;
2022-12-22 09:41:07 +00:00
*) 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 ..."
2022-12-28 08:04:35 +00:00
source $CONFIG_DIR/env
2022-12-29 09:31:25 +00:00
curl --insecure -X GET https://$DLS_URL:$DLS_PORT/-/health
2022-12-22 09:41:07 +00:00
else
echo "> Testing API failed, curl not available. Please test manually!"
fi
fi
2022-12-28 07:35:59 +00:00
chown -R www-data:www-data $CONFIG_DIR
2022-12-28 06:40:44 +00:00
chown -R www-data:www-data $WORKING_DIR
2022-12-28 06:14:24 +00:00
2022-12-22 09:41:07 +00:00
cat <<EOF
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# fastapi-dls is now installed. #
# #
# Service should be up and running. #
# Webservice is listen to https://localhost #
# #
2023-01-04 10:14:26 +00:00
# Configuration is stored in /etc/fastapi-dls/env. #
2022-12-22 09:41:07 +00:00
# #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2022-12-27 21:18:02 +00:00
2022-12-22 09:41:07 +00:00
EOF