1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pytition_ynh.git synced 2024-09-03 20:16:08 +02:00
pytition_ynh/scripts/install

229 lines
8.1 KiB
Text
Raw Normal View History

2014-10-20 18:55:53 +02:00
#!/bin/bash
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
#=================================================
2017-06-17 17:49:26 +02:00
# MANAGE SCRIPT FAILURE
2017-06-02 18:23:51 +02:00
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_clean_setup () {
2022-08-28 14:03:45 +02:00
true
2018-06-28 22:05:35 +02:00
}
2017-06-17 17:49:26 +02:00
# Exit if an error occurs during the execution of the script
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_abort_if_errors
2017-06-02 18:23:51 +02:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
#REMOVEME? path=$YNH_APP_ARG_PATH
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
#REMOVEME? language=$YNH_APP_ARG_LANGUAGE
#REMOVEME? password=$YNH_APP_ARG_PASSWORD
2022-07-29 23:30:24 +02:00
2023-04-26 17:44:04 +02:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2014-10-20 18:55:53 +02:00
2017-06-02 18:23:51 +02:00
#=================================================
2017-06-17 17:49:26 +02:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2017-06-02 18:23:51 +02:00
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1
2014-10-20 18:55:53 +02:00
2023-04-26 17:44:04 +02:00
#REMOVEME? install_dir=/var/www/$app
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
2017-08-28 23:55:51 +02:00
2022-07-29 23:30:24 +02:00
# Register (book) web path
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
2014-10-20 18:55:53 +02:00
2017-06-02 18:23:51 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
2019-04-16 00:32:39 +02:00
ynh_app_setting_set --app=$app --key=language --value=$language
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=password --value=$password
2017-06-02 18:23:51 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=3
2017-06-02 18:23:51 +02:00
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
2017-06-02 18:23:51 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2017-06-02 18:23:51 +02:00
#=================================================
2017-06-17 17:49:26 +02:00
# CREATE A MYSQL DATABASE
2017-06-02 18:23:51 +02:00
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Creating a MySQL database..." --weight=1
2018-06-28 22:05:35 +02:00
2023-04-26 17:44:04 +02:00
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
#REMOVEME? db_user=$db_name
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
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
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
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/"
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
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:44:04 +02:00
#REMOVEME? 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
DJANGO_SUPERUSER_PASSWORD='$password' \
python3 manage.py createsuperuser --noinput --username admin --email 'admin@$domain'
"
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
#=================================================
# 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"
2017-06-02 18:23:51 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1
2017-06-02 18:23:51 +02:00
# Make app public if necessary
2023-04-26 17:44:04 +02:00
#REMOVEME? if [ $is_public -eq 1 ]
2017-06-02 18:23:51 +02:00
then
2022-07-29 23:30:24 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
2014-10-20 18:55:53 +02:00
fi
2017-06-02 18:23:51 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2019-02-10 15:02:38 +01:00
2023-04-26 17:44:04 +02:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
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