2015-02-13 18:10:02 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-12-13 16:12:58 +01:00
|
|
|
|
2015-02-13 18:10:02 +01:00
|
|
|
# Retrieve arguments
|
2017-10-30 17:52:57 +01:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2018-07-25 08:44:48 +02:00
|
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
2017-10-30 17:52:57 +01:00
|
|
|
db_name=$(ynh_app_setting_get "$app" db_name)
|
2017-11-16 23:23:51 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
|
2017-10-30 17:52:57 +01:00
|
|
|
db_user=$app
|
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
secret=$(ynh_app_setting_get "$app" secret)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z "$db_name" ]; then
|
|
|
|
db_name=$(ynh_sanitize_dbid "$app")
|
|
|
|
ynh_app_setting_set $app db_name "$db_name"
|
2016-01-13 21:14:06 +01:00
|
|
|
fi
|
2015-02-13 18:10:02 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
2018-08-04 00:35:34 +02:00
|
|
|
final_path=/opt/yunohost/$app
|
2017-10-30 17:52:57 +01:00
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
2015-02-13 18:10:02 +01:00
|
|
|
fi
|
|
|
|
|
2018-01-29 22:44:33 +01:00
|
|
|
# If path_url doesn't exist, create it
|
|
|
|
if [ -z "$path_url" ]; then
|
|
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
2018-07-25 08:44:48 +02:00
|
|
|
ynh_app_setting_set "$app" path "$path_url"
|
2018-01-29 22:44:33 +01:00
|
|
|
ynh_app_setting_delete "$app" path
|
|
|
|
fi
|
|
|
|
|
2017-11-16 23:23:51 +01:00
|
|
|
# Detect old installation style
|
2018-08-04 00:35:34 +02:00
|
|
|
if [ -e /etc/init.d/ffsync ]; then
|
2017-11-16 23:23:51 +01:00
|
|
|
service ffsync stop
|
|
|
|
update-rc.d -f ffsync remove
|
|
|
|
|
|
|
|
ynh_secure_remove /etc/init.d/ffsync
|
|
|
|
ynh_secure_remove /var/log/ffsync.log
|
|
|
|
ynh_secure_remove /opt/yunohost/ffsync
|
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
yunohost service remove "$app"
|
2017-11-16 23:23:51 +01:00
|
|
|
fi
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check depends installation
|
2018-06-28 23:09:33 +02:00
|
|
|
ynh_install_app_dependencies python-dev python-virtualenv \
|
2018-08-03 23:42:47 +02:00
|
|
|
uwsgi uwsgi-plugin-python \
|
|
|
|
`# ARM support: ` \
|
|
|
|
build-essential libssl-dev libffi-dev
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP UWSGI
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_add_uwsgi_service
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2018-06-28 23:11:51 +02:00
|
|
|
ynh_setup_source "$final_path"
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
if [ "$path_url" == "/" ]
|
2015-02-13 18:10:02 +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
|
|
|
|
ynh_replace_string "uwsgi_param " "#uwsgi_param " "$finalnginxconf"
|
|
|
|
ynh_replace_string "uwsgi_modifier1 " "#uwsgi_modifier1 " "$finalnginxconf"
|
|
|
|
|
|
|
|
ynh_store_file_checksum "$finalnginxconf"
|
2018-01-29 22:44:33 +01:00
|
|
|
else
|
|
|
|
# add rewrite for alias_traversal protection
|
|
|
|
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
|
2015-02-13 18:10:02 +01:00
|
|
|
fi
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create "$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Copy Files
|
2018-07-05 23:21:03 +02:00
|
|
|
ynh_replace_string "__APP__" "$app" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__NAME__" "$app" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__SECRET__" "$secret" "$finaluwsgiini"
|
|
|
|
|
|
|
|
ynh_replace_string "__DB_USER__" "$db_user" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "$finaluwsgiini"
|
|
|
|
|
|
|
|
rm "$final_path/syncserver.ini"
|
|
|
|
ln -s "$finaluwsgiini" "$final_path/syncserver.ini"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# pip installation
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
virtualenv "$final_path/local"
|
|
|
|
# Init virtualenv
|
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "$final_path/local/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
cd "$final_path"
|
|
|
|
pip install --upgrade pip
|
2018-08-20 23:55:00 +02:00
|
|
|
pip install pyramid_chameleon
|
2018-07-05 23:21:03 +02:00
|
|
|
CFLAGS="-Wno-error -Wno-error=format-security" \
|
|
|
|
ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" \
|
|
|
|
pip install --requirement "$final_path/requirements.txt"
|
|
|
|
|
|
|
|
python "$final_path/setup.py" develop
|
|
|
|
|
|
|
|
touch "$final_path/local/COMPLETE"
|
|
|
|
)
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2018-08-20 23:55:00 +02:00
|
|
|
# Add nice homepage
|
|
|
|
cp -r ../sources/page $final_path/syncserver/
|
|
|
|
(cd "$final_path/syncserver" && patch -p1 < $YNH_CWD/../sources/homepage.patch) || echo "Unable to apply patches"
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-19 13:46:34 +01:00
|
|
|
# no need, keep the default root:root
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
systemctl start "uwsgi-app@$app.service"
|
2017-10-30 17:52:57 +01:00
|
|
|
systemctl reload nginx
|