mirror of
https://gitea.publichub.eu/oscar.krause/fastapi-dls.git
synced 2025-11-03 09:26:32 +00:00
refactorings
This commit is contained in:
1
.DEBIAN/conffiles
Normal file
1
.DEBIAN/conffiles
Normal file
@@ -0,0 +1 @@
|
||||
/etc/fastapi-dls/env
|
||||
9
.DEBIAN/control
Normal file
9
.DEBIAN/control
Normal file
@@ -0,0 +1,9 @@
|
||||
Package: fastapi-dls
|
||||
Version: 1.0.0
|
||||
Architecture: all
|
||||
Maintainer: Oscar Krause oscar.krause@collinwebdesigns.de
|
||||
Depends: python3, python3-fastapi, python3-uvicorn, python3-dotenv, python3-dateutil, python3-jose, python3-sqlalchemy, python3-pycryptodome, python3-markdown, uvicorn, openssl
|
||||
Recommends: curl
|
||||
Installed-Size: 10240
|
||||
Homepage: https://git.collinwebdesigns.de/oscar.krause/fastapi-dls
|
||||
Description: Minimal Delegated License Service (DLS).
|
||||
101
.DEBIAN/postinst
Normal file
101
.DEBIAN/postinst
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
|
||||
WORKING_DIR=/usr/share/fastapi-dls
|
||||
CONFIG_DIR=/etc/fastapi-dls
|
||||
|
||||
echo "> Create config directory ..."
|
||||
mkdir -p $CONFIG_DIR
|
||||
|
||||
echo "> Install service ..."
|
||||
cat <<EOF >/etc/systemd/system/fastapi-dls.service
|
||||
[Unit]
|
||||
Description=Service for fastapi-dls
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
Group=www-data
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
WorkingDirectory=$WORKING_DIR/app
|
||||
EnvironmentFile=$CONFIG_DIR/env
|
||||
ExecStart=uvicorn main:app \\
|
||||
--env-file /etc/fastapi-dls/env \\
|
||||
--host \$DLS_URL --port \$DLS_PORT \\
|
||||
--app-dir $WORKING_DIR/app \\
|
||||
--ssl-keyfile /etc/fastapi-dls/webserver.key \\
|
||||
--ssl-certfile /etc/fastapi-dls/webserver.crt \\
|
||||
--proxy-headers
|
||||
Restart=always
|
||||
KillSignal=SIGQUIT
|
||||
Type=simple
|
||||
NotifyAccess=all
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
if [[ ! -f $CONFIG_DIR/env ]]; then
|
||||
echo "> Writing initial config ..."
|
||||
touch $CONFIG_DIR/env
|
||||
cat <<EOF >$CONFIG_DIR/env
|
||||
DLS_URL=127.0.0.1
|
||||
DLS_PORT=443
|
||||
LEASE_EXPIRE_DAYS=90
|
||||
DATABASE=sqlite:///$CONFIG_DIR/db.sqlite
|
||||
INSTANCE_KEY_RSA=$CONFIG_DIR/instance.private.pem
|
||||
INSTANCE_KEY_PUB=$CONFIG_DIR/instance.public.pem
|
||||
|
||||
EOF
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
while true; do
|
||||
read -p "> Do you wish to create self-signed webserver certificate? [Y/n]" yn
|
||||
yn=${yn:-y} # ${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]*)
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $CONFIG_DIR/webserver.key -out $CONFIG_DIR/webserver.crt
|
||||
break
|
||||
;;
|
||||
[Nn]*) 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/status
|
||||
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 ${CONFIG_DIR}/env #
|
||||
# #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
EOF
|
||||
8
.DEBIAN/postrm
Executable file
8
.DEBIAN/postrm
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -f /etc/systemd/system/fastapi-dls.service ]]; then
|
||||
echo "> Removing service file."
|
||||
rm /etc/systemd/system/fastapi-dls.service
|
||||
fi
|
||||
|
||||
# todo
|
||||
5
.DEBIAN/prerm
Executable file
5
.DEBIAN/prerm
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo -e "> Starting uninstallation of 'fastapi-dls'!"
|
||||
|
||||
# todo
|
||||
Reference in New Issue
Block a user