2015-09-14 17:12:17 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-07-05 15:22:12 +02:00
|
|
|
|
2017-05-18 23:28:18 +02:00
|
|
|
source _common.sh
|
2022-02-13 22:09:18 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2018-12-14 03:36:58 +01:00
|
|
|
ynh_abort_if_errors
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url="/"
|
2017-05-18 23:28:18 +02:00
|
|
|
export is_public=0
|
2022-02-13 22:09:18 +01:00
|
|
|
export app_version=$YNH_APP_ARG_VERSION
|
|
|
|
oca=$YNH_APP_ARG_OCA
|
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
|
|
|
lang=$YNH_APP_ARG_LANG
|
|
|
|
tz=$YNH_APP_ARG_TZ
|
|
|
|
|
|
|
|
export app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-12-14 03:36:58 +01:00
|
|
|
export conf_file=/etc/$app/main.conf
|
2022-02-13 22:09:18 +01:00
|
|
|
export final_path=/var/www/$app
|
2022-02-13 19:55:00 +01:00
|
|
|
export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin"
|
2018-12-14 19:24:55 +01:00
|
|
|
if [ "$app_version" = "9" ]; then
|
2022-02-13 19:55:00 +01:00
|
|
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
2018-12-14 03:36:58 +01:00
|
|
|
fi
|
2018-12-14 19:24:55 +01:00
|
|
|
if [ "$app_version" = "8" ]; then
|
2022-02-13 19:55:00 +01:00
|
|
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
2018-12-14 03:36:58 +01:00
|
|
|
fi
|
2019-04-17 22:45:59 +02:00
|
|
|
export preinstall=0
|
2017-05-18 23:28:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-02-13 22:09:18 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=app_version --value=$app_version
|
|
|
|
ynh_app_setting_set --app=$app --key=oca --value=$oca
|
|
|
|
ynh_app_setting_set --app=$app --key=lang --value=$lang
|
|
|
|
ynh_app_setting_set --app=$app --key=tz --value=$tz
|
|
|
|
ynh_app_setting_set --app=$app --key=conf_file --value=$conf_file
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Finding an available port..."
|
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=8069)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port_chat=$(ynh_find_port --port=8072)
|
|
|
|
ynh_app_setting_set --app=$app --key=port_chat --value=$port_chat
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
|
|
|
|
|
|
|
export db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
2018-12-14 20:21:31 +01:00
|
|
|
export db_pass=$(ynh_string_random)
|
2022-02-13 22:09:18 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
|
|
|
|
# Make sure that postgresql is installed and running
|
2018-12-14 20:21:31 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Create the database
|
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass
|
|
|
|
export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
setup_files
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building $app..."
|
|
|
|
|
|
|
|
ynh_add_swap 1024
|
|
|
|
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
|
|
|
|
# The debian package has a bug so we deploy a more recent version
|
|
|
|
if [ -f '../manifest.json' ] ; then
|
|
|
|
ynh_setup_source /usr/
|
|
|
|
else
|
|
|
|
OLD_YNH_CWD=$YNH_CWD
|
|
|
|
YNH_CWD=$YNH_CWD/../settings/conf
|
|
|
|
ynh_setup_source /usr/
|
|
|
|
YNH_CWD=$OLD_YNH_CWD
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
pushd $final_path
|
|
|
|
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
|
|
|
|
python3 -m venv venv
|
|
|
|
venv/bin/pip3 install wheel
|
|
|
|
venv/bin/pip3 install -r $appname/requirements.txt
|
|
|
|
else
|
|
|
|
virtualenv venv
|
|
|
|
venv/bin/pip install wheel
|
|
|
|
venv/bin/pip install -r $appname/requirements.txt
|
|
|
|
fi
|
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setuping the database..."
|
|
|
|
|
2017-05-18 23:28:18 +02:00
|
|
|
setup_database
|
2016-12-14 21:45:41 +01:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
|
|
|
yunohost service add $app --log="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
|
|
|
|
ynh_sso_access "/web/database/manager"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|