2013-12-12 12:12:22 +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
|
|
|
|
#=================================================
|
2016-12-08 16:12:16 +01:00
|
|
|
|
2013-12-12 12:12:22 +01:00
|
|
|
# Retrieve arguments
|
2017-10-30 17:52:57 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2013-12-12 12:12:22 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2018-08-04 00:35:34 +02:00
|
|
|
final_path="/opt/yunohost/$app"
|
2013-12-12 12:12:22 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
|
|
|
|
2018-08-20 22:51:26 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check destination directory
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available "$domain" "$path_url"
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register "$app" "$domain" "$path_url"
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2013-12-12 12:12:22 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2016-01-13 21:14:06 +01:00
|
|
|
|
2014-11-15 17:24:32 +01:00
|
|
|
# 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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Use 'FSyncMS' as database name and user
|
|
|
|
db_user=$app
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
|
|
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
|
|
|
ynh_mysql_setup_db "$db_user" "$db_name"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2014-11-15 17:24:32 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
# 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
|
|
|
|
|
|
|
# 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" {} \;
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
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
|
|
|
|
ynh_replace_string "uwsgi_param " "#uwsgi_param " "$finalnginxconf"
|
|
|
|
ynh_replace_string "uwsgi_modifier1 " "#uwsgi_modifier1 " "$finalnginxconf"
|
2014-11-15 17:24:32 +01:00
|
|
|
fi
|
2018-09-06 14:57:35 +02:00
|
|
|
ynh_store_file_checksum "$finalnginxconf"
|
|
|
|
systemctl reload nginx
|
2014-11-15 17:24:32 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2016-12-15 21:33:40 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
ynh_system_user_create "$app" "$final_path"
|
2016-12-15 21:33:40 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2018-04-28 13:42:17 +02:00
|
|
|
# pip installation
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
2014-11-15 17:24:32 +01:00
|
|
|
|
2019-02-12 20:15:04 +01:00
|
|
|
virtualenv --python=$(which python2 python | head -n 1) "$final_path/local"
|
2014-11-15 17:24:32 +01:00
|
|
|
# Init virtualenv
|
2017-10-30 17:52:57 +01:00
|
|
|
(
|
2018-04-28 13:42:17 +02:00
|
|
|
set +o nounset
|
|
|
|
source "$final_path/local/bin/activate"
|
|
|
|
set -o nounset
|
2017-10-30 17:52:57 +01:00
|
|
|
cd "$final_path"
|
2018-04-28 13:42:17 +02:00
|
|
|
pip install --upgrade pip
|
2019-02-12 20:15:04 +01:00
|
|
|
pip install --upgrade pyramid_chameleon
|
2018-04-28 13:42:17 +02:00
|
|
|
CFLAGS="-Wno-error -Wno-error=format-security" \
|
|
|
|
ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" \
|
2019-02-12 20:15:04 +01:00
|
|
|
pip install --upgrade --requirement "$final_path/requirements.txt"
|
2018-04-28 13:42:17 +02:00
|
|
|
|
|
|
|
python "$final_path/setup.py" develop
|
|
|
|
|
|
|
|
touch "$final_path/local/COMPLETE"
|
2017-10-30 17:52:57 +01:00
|
|
|
)
|
2014-11-15 17:24:32 +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"
|
|
|
|
|
2018-09-05 20:43:08 +02:00
|
|
|
#=================================================
|
2018-09-05 22:23:48 +02:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
2018-09-05 20:43:08 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-09-05 22:23:48 +02:00
|
|
|
chown $app -R $final_path
|
|
|
|
chmod u=rwX,g=rX,o= -R $final_path
|
|
|
|
|
2018-09-05 20:43:08 +02:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
2018-09-05 22:23:48 +02:00
|
|
|
# SETUP UWSGI
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
2018-09-05 22:23:48 +02:00
|
|
|
|
|
|
|
# Generate random password and save
|
|
|
|
secret=$(ynh_string_random)
|
|
|
|
ynh_app_setting_set "$app" secret "$secret"
|
|
|
|
|
|
|
|
# create config file syncserver.ini
|
|
|
|
rm "$final_path/syncserver.ini"
|
|
|
|
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'
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
|
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
|
|
|
|
2018-09-05 22:23:48 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-16 23:23:51 +01:00
|
|
|
# accessible by everyone (authentification is done by firefox accounts)
|
2017-10-30 17:52:57 +01:00
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|