2022-08-13 16:28:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-16 18:50:19 +01:00
|
|
|
INSTANCE_PATH="instance"
|
|
|
|
|
2022-08-13 16:28:57 +02:00
|
|
|
init () {
|
2024-01-16 18:50:19 +01:00
|
|
|
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"
|
2023-03-04 19:49:15 +01:00
|
|
|
|
2024-01-16 18:50:19 +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
|
2023-09-08 13:53:56 +02:00
|
|
|
|
2024-01-16 18:50:19 +01:00
|
|
|
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
|
2023-03-04 19:49:15 +01:00
|
|
|
[[ $CONFIRMATION == y ]] || exit 1
|
2022-08-13 16:28:57 +02:00
|
|
|
fi
|
2024-01-16 18:50:19 +01:00
|
|
|
sqlite3 "$INSTANCE_PATH/partitioncloud.sqlite" '.read partitioncloud/schema.sql'
|
2023-03-04 19:49:15 +01:00
|
|
|
echo "Base de données créé"
|
2024-01-16 18:50:19 +01:00
|
|
|
sqlite3 "$INSTANCE_PATH/partitioncloud.sqlite" '.read partitioncloud/init.sql'
|
2023-03-04 19:49:15 +01:00
|
|
|
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/
|
2022-08-30 18:18:38 +02:00
|
|
|
FLASK_APP=partitioncloud /usr/bin/gunicorn \
|
|
|
|
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"
|
|
|
|
[[ ! -x "$INSTANCE_PATH/config.py" ]] && load_config "$INSTANCE_PATH/config.py"
|
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
|