partitioncloud-server/make.sh

80 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2022-08-13 16:28:57 +02:00
#!/bin/bash
INSTANCE_PATH="instance"
2022-08-13 16:28:57 +02:00
init () {
mkdir -p "$INSTANCE_PATH"
mkdir -p "$INSTANCE_PATH/partitions"
mkdir -p "$INSTANCE_PATH/attachments"
mkdir -p "$INSTANCE_PATH/search-partitions"
2024-01-16 21:03:01 +01:00
mkdir -p "$INSTANCE_PATH/cache/thumbnails"
mkdir -p "$INSTANCE_PATH/cache/search-thumbnails"
2024-02-25 15:56:40 +01:00
if ! test -f "$INSTANCE_PATH/config.py"; then
2024-01-16 21:03:01 +01:00
echo "SECRET_KEY=\"$(python3 -c 'import secrets; print(secrets.token_hex())')\"" > "$INSTANCE_PATH/config.py"
2023-09-08 13:59:22 +02:00
fi
if test -f "$INSTANCE_PATH/partitioncloud.sqlite"; then
2022-08-13 16:28:57 +02:00
printf "Souhaitez vous supprimer la base de données existante ? [y/n] "
read -r CONFIRMATION
[[ $CONFIRMATION == y ]] || exit 1
2024-02-25 15:56:40 +01:00
rm "$INSTANCE_PATH/partitioncloud.sqlite"
2022-08-13 16:28:57 +02:00
fi
sqlite3 "$INSTANCE_PATH/partitioncloud.sqlite" '.read partitioncloud/schema.sql'
echo "Base de données créé"
sqlite3 "$INSTANCE_PATH/partitioncloud.sqlite" '.read partitioncloud/init.sql'
echo "Utilisateur root:root ajouté"
2022-08-13 16:28:57 +02:00
}
2024-01-25 16:22:04 +01:00
translations () {
# Rajouter les chaînes non traduites
pybabel extract -F babel.cfg -k _l -o partitioncloud/translations/messages.pot .
pybabel update -i partitioncloud/translations/messages.pot -d partitioncloud/translations/
# Compiler
pybabel compile -d partitioncloud/translations/
}
2022-08-13 16:28:57 +02:00
start () {
2024-01-26 19:32:22 +01:00
pybabel compile -d partitioncloud/translations/
2022-08-30 18:18:38 +02:00
flask run --port=$PORT
}
production () {
2024-01-26 19:32:22 +01:00
pybabel compile -d partitioncloud/translations/
2024-02-25 15:56:40 +01:00
FLASK_APP=partitioncloud gunicorn \
2022-08-30 18:18:38 +02:00
wsgi:app \
--bind 0.0.0.0:$PORT
2022-08-13 16:28:57 +02:00
}
2024-01-25 16:22:04 +01:00
load_config () {
# Load variables PORT and INSTANCE_PATH
eval $(cat $1 | grep -E "^PORT=")
eval $(cat $1 | grep -E "^INSTANCE_PATH=")
}
2022-08-13 16:28:57 +02:00
usage () {
echo "Usage:"
echo -e "\t$0 init"
echo -e "\t$0 start"
2024-01-25 16:22:04 +01:00
echo -e "\t$0 production"
echo -e "\t$0 translations"
2022-08-13 16:28:57 +02:00
}
2024-01-26 19:32:22 +01:00
2024-01-25 16:22:04 +01:00
RESULT=$(type "$1")
if [[ $1 && $RESULT = *"is a"*"function"* || $RESULT == *"est une fonction"* ]]; then
2024-01-16 21:13:04 +01:00
# Import config
2024-01-25 16:22:04 +01:00
load_config "default_config.py"
2024-02-25 15:56:40 +01:00
if test -f "instance/config.py"; then
load_config "instance/config.py"
fi
2022-08-30 18:18:38 +02:00
$1 ${*:2} # Call the function
2022-08-13 16:28:57 +02:00
else
usage
2024-01-25 16:22:04 +01:00
echo $RESULT
2022-08-13 16:28:57 +02:00
exit 1
2022-08-13 23:36:10 +02:00
fi