2013-12-12 12:12:22 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
source _common.sh
|
2017-10-30 17:52:57 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2017-10-30 17:52:57 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2016-12-08 16:12:16 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-04-16 23:33:43 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2022-07-28 02:38:24 +02:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-04-16 23:33:43 +02:00
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
secret=$(ynh_string_random)
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
2018-08-04 00:35:34 +02:00
|
|
|
final_path="/opt/yunohost/$app"
|
2020-04-16 23:33:43 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2013-12-12 12:12:22 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
# STORE SETTINGS FROM MANIFEST
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2018-08-20 22:51:26 +02:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
ynh_app_setting_set --app=$app --key=secret --value="$secret"
|
2018-08-20 22:51:26 +02:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
# INSTALL DEPENDENCIES
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=7
|
2022-07-28 02:38:24 +02:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
# CREATE A MYSQL DATABASE
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a MySQL database..."
|
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=10
|
2020-04-16 23:33:43 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-11-01 22:04:11 +01:00
|
|
|
install_sources
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
# Modify assets to take path into account
|
|
|
|
# TODO: try to include this as a patch if still needed
|
|
|
|
# find ../sources/syncserver/page/sync_files/ -type f -exec sed -i -e "s@media\/img@$path_url\/media\/img@g" {} \;
|
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
# NGINX CONFIGURATION
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
if [ "$path_url" == "/" ]
|
2014-11-15 17:24:32 +01:00
|
|
|
then
|
2017-10-30 17:52:57 +01:00
|
|
|
# $finalnginxconf comes from ynh_add_nginx_config
|
|
|
|
# uwsgi_param is only needed for non-root installation
|
2020-12-07 16:26:56 +01:00
|
|
|
is_subpath="# "
|
|
|
|
else
|
|
|
|
is_subpath=" "
|
2014-11-15 17:24:32 +01:00
|
|
|
fi
|
2022-07-28 02:38:24 +02:00
|
|
|
ynh_add_nginx_config
|
2020-04-16 23:33:43 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
# CONFIGURE APPLICATION
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Configuring application..."
|
2022-07-28 02:38:24 +02:00
|
|
|
|
|
|
|
ynh_secure_remove --file="$final_path/syncserver.ini"
|
2018-09-05 22:23:48 +02:00
|
|
|
ln -s "/etc/uwsgi/apps-available/$app.ini" "$final_path/syncserver.ini"
|
|
|
|
|
|
|
|
# configure uwsgi
|
|
|
|
ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name'
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
# ADD A CONFIGURATION
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
#ynh_script_progression --message="Adding a configuration file..."
|
|
|
|
|
2018-09-05 22:23:48 +02:00
|
|
|
# TODO: fix this css patch
|
|
|
|
# ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/firefox_sync-bundle.css
|
|
|
|
# ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/responsive-bundle.css
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Protecting directory"
|
2020-04-16 23:33:43 +02:00
|
|
|
|
|
|
|
# Set permissions to app files
|
2019-11-01 22:04:11 +01:00
|
|
|
set_permissions
|
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name "uwsgi-app@$app.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log"
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
# SETUP SSOWAT
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions"
|
2020-04-16 23:33:43 +02:00
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
# Everyone can access the app. (authentification is done by firefox accounts)
|
2021-03-15 12:03:05 +01:00
|
|
|
ynh_permission_update --permission=main --add=visitors --protected=true --show_tile=true
|
2020-04-16 23:33:43 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
# RELOAD NGINX
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2022-07-28 02:38:24 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2020-04-16 23:33:43 +02:00
|
|
|
|
2022-07-28 02:38:24 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2020-12-07 16:26:56 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|