mirror of
https://github.com/YunoHost-Apps/ffsync_ynh.git
synced 2024-09-03 18:26:38 +02:00
204 lines
6.5 KiB
Bash
204 lines
6.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# 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
|
|
#=================================================
|
|
|
|
# Retrieve arguments
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
|
|
# Check destination directory
|
|
final_path="/var/www/$app"
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
# Normalize the url path syntax
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
|
|
|
# Check web path availability
|
|
ynh_webpath_available "$domain" "$path_url"
|
|
# Register (book) web path
|
|
ynh_webpath_register "$app" "$domain" "$path_url"
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
|
|
ynh_app_setting_set "$app" domain "$domain"
|
|
ynh_app_setting_set "$app" path_url "$path_url"
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
# Check depends installation
|
|
ynh_install_app_dependencies python-dev python-virtualenv \
|
|
uwsgi uwsgi-plugin-python
|
|
|
|
#=================================================
|
|
# 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
|
|
#=================================================
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source "$final_path"
|
|
|
|
# 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" == "/" ]
|
|
then
|
|
# $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"
|
|
else
|
|
# add rewrite for alias_traversal protection
|
|
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
ynh_system_user_create "$app" "$final_path"
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# create config file syncserver.ini
|
|
#=================================================
|
|
|
|
# Generate random password and save
|
|
secret=$(ynh_string_random)
|
|
ynh_app_setting_set "$app" secret "$secret"
|
|
|
|
# Copy Files
|
|
cp ../conf/syncserver.ini "$final_path/syncserver.ini"
|
|
ynh_replace_string "__APP__" "$app" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__PATH__" "$path_url" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__NAME__" "$app" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__SECRET__" "$secret" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__DB_USER__" "$db_user" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/syncserver.ini"
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/syncserver.ini"
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# 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
|
|
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"
|
|
)
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# no need, keep the default root:root
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
|
|
ynh_use_logrotate
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
yunohost service add "$app" -l /var/log/$app/$app.log
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
|
|
# accessible by everyone (authentification is done by firefox accounts)
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
systemctl start "$app.service"
|
|
systemctl reload nginx
|