2014-10-20 18:55:53 +02:00
|
|
|
#!/bin/bash
|
2015-10-27 16:03:21 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# GENERIC START
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-05 13:11:48 +02:00
|
|
|
source _common.sh
|
2017-06-02 18:23:51 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-04-27 19:29:20 +02:00
|
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
|
|
|
|
2023-07-31 14:36:20 +02:00
|
|
|
if [[ "$email" == "admin_legacy" ]]; then
|
|
|
|
ynh_die --message="Please select a regular user as admin of the app, NOT the admin user!" --ret_code=1
|
|
|
|
fi
|
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2022-07-29 23:30:24 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-04-26 17:44:04 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/pytition"
|
2022-04-05 16:15:54 +02:00
|
|
|
|
2023-04-26 17:44:04 +02:00
|
|
|
mkdir -p "$install_dir/static"
|
|
|
|
mkdir -p "$install_dir/mediaroot"
|
2022-04-05 16:15:54 +02:00
|
|
|
|
2023-04-26 17:44:04 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
setfacl -dR -m g:"www-data":rX -m u:$app:rwX "$install_dir/mediaroot/"
|
|
|
|
setfacl -R -m g:"www-data":rX -m u:$app:rwX "$install_dir/mediaroot/"
|
2021-03-17 16:32:11 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
2022-07-29 23:30:24 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
2018-05-27 15:44:58 +02:00
|
|
|
ynh_add_nginx_config
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2022-07-29 23:30:24 +02:00
|
|
|
# INSTALL PYTHON DEPENDENCIES
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2023-04-26 17:51:32 +02:00
|
|
|
ynh_script_progression --message="Installing python dependencies..." --weight=4
|
2022-04-05 16:15:54 +02:00
|
|
|
|
|
|
|
# Setup virtualenv and install dependencies
|
2023-04-26 17:44:04 +02:00
|
|
|
virtualenv --python=python3 --system-site-packages "${install_dir}/venv"
|
2022-04-05 16:15:54 +02:00
|
|
|
(
|
|
|
|
set +o nounset
|
2023-04-26 17:44:04 +02:00
|
|
|
source "${install_dir}/venv/bin/activate"
|
2022-04-05 16:15:54 +02:00
|
|
|
set -o nounset
|
|
|
|
|
|
|
|
python3 -m pip install --upgrade pip
|
2023-04-26 17:44:04 +02:00
|
|
|
python3 -m pip install -r "$install_dir/pytition/requirements.txt"
|
2022-04-05 16:15:54 +02:00
|
|
|
)
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2021-04-23 20:00:41 +02:00
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
2022-07-29 23:30:24 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
|
|
|
|
2022-04-11 17:16:03 +02:00
|
|
|
secret_key=$(generate_secret_key)
|
2021-04-23 20:00:41 +02:00
|
|
|
|
2023-04-26 17:44:04 +02:00
|
|
|
config_path="$install_dir/pytition/pytition/pytition/settings/config.py"
|
2022-04-05 16:15:54 +02:00
|
|
|
ynh_add_config --template="../conf/config.py" --destination="$config_path"
|
2021-04-23 20:00:41 +02:00
|
|
|
|
|
|
|
# FIXME: this should be handled by the core in the future
|
|
|
|
# You may need to use chmod 600 instead of 400,
|
|
|
|
# for example if the app is expected to be able to modify its own config
|
2022-04-05 16:15:54 +02:00
|
|
|
chmod 400 "$config_path"
|
|
|
|
chown $app:$app "$config_path"
|
2021-04-23 20:00:41 +02:00
|
|
|
|
2023-04-26 17:44:04 +02:00
|
|
|
ynh_add_config --template="../conf/uwsgi.yaml" --destination="$install_dir/uwsgi.yaml"
|
|
|
|
chmod 400 "$install_dir/uwsgi.yaml"
|
|
|
|
chown $app:$app "$install_dir/uwsgi.yaml"
|
2021-04-23 20:00:41 +02:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-07-29 23:30:24 +02:00
|
|
|
# RUN APP CONFIGURATION
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Running app configuration..." --weight=3
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2022-04-05 16:15:54 +02:00
|
|
|
ynh_exec_as $app bash -c "
|
|
|
|
set +o nounset
|
2023-04-26 17:44:04 +02:00
|
|
|
source '$install_dir/venv/bin/activate'
|
2022-04-05 16:15:54 +02:00
|
|
|
set -o nounset
|
2023-04-26 17:44:04 +02:00
|
|
|
cd '$install_dir/pytition/pytition'
|
2022-04-05 16:15:54 +02:00
|
|
|
export DJANGO_SETTINGS_MODULE=pytition.settings.config
|
|
|
|
python3 manage.py migrate
|
|
|
|
python3 manage.py collectstatic
|
|
|
|
python3 manage.py compilemessages
|
2023-04-27 19:34:11 +02:00
|
|
|
DJANGO_SUPERUSER_PASSWORD='$password' python3 manage.py createsuperuser --noinput --username $admin --email $email
|
2022-04-05 16:15:54 +02:00
|
|
|
"
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2023-04-26 17:44:04 +02:00
|
|
|
chmod 750 "$install_dir/static"
|
|
|
|
chown -R $app:www-data "$install_dir/static"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-04-05 16:15:54 +02:00
|
|
|
# SETUP SYSTEMD
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2022-04-05 16:15:54 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# GENERIC FINALIZATION
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2022-07-29 23:30:24 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chmod 750 "/var/log/$app"
|
|
|
|
chown -R $app:www-data "/var/log/$app"
|
|
|
|
|
2017-06-17 17:49:26 +02:00
|
|
|
# Use logrotate to manage application logfile(s)
|
2022-07-29 23:30:24 +02:00
|
|
|
ynh_use_logrotate
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-11-27 19:34:37 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2022-04-05 16:15:54 +02:00
|
|
|
yunohost service add $app --description="Pytition uWSGI app $app" --log="/var/log/$app/$app.log"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2019-05-02 20:44:22 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2019-05-02 20:44:22 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-04-13 10:43:02 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|