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 () {
|
2022-02-17 01:23:35 +01:00
|
|
|
ynh_clean_check_starting
|
2022-02-13 22:09:18 +01:00
|
|
|
}
|
|
|
|
# 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="/"
|
|
|
|
export app_version=$YNH_APP_ARG_VERSION
|
|
|
|
oca=$YNH_APP_ARG_OCA
|
|
|
|
lang=$YNH_APP_ARG_LANG
|
|
|
|
tz=$YNH_APP_ARG_TZ
|
2022-06-15 02:10:40 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
export app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-12-14 03:36:58 +01:00
|
|
|
export conf_file=/etc/$app/main.conf
|
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..."
|
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
export final_path=/var/www/$app
|
2022-02-13 22:09:18 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin"
|
|
|
|
if [ "$app_version" = "9" ]; then
|
|
|
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
|
|
|
fi
|
|
|
|
if [ "$app_version" = "8" ]; then
|
|
|
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
|
|
|
fi
|
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
# 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..."
|
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2022-02-13 22:09:18 +01: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"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
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
|
2022-02-17 01:23:35 +01:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
export db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
|
|
|
|
# Make sure that its encoding is UTF-8
|
|
|
|
ynh_psql_execute_as_root --sql="update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name'"
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
2022-02-17 01:23:35 +01:00
|
|
|
#=================================================
|
|
|
|
# ADD SWAP
|
|
|
|
#=================================================
|
|
|
|
|
2022-05-29 16:07:32 +02:00
|
|
|
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
|
|
|
:
|
|
|
|
else
|
2022-06-01 23:17:58 +02:00
|
|
|
ynh_script_progression --message="Adding swap..."
|
2022-05-29 16:07:32 +02:00
|
|
|
ynh_add_swap --size=$swap_needed
|
|
|
|
fi
|
2022-02-17 01:23:35 +01:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building $app..."
|
|
|
|
|
|
|
|
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..."
|
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2022-02-16 20:17:10 +01:00
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
# Only the admin can access the admin panel of the app (if the app has an admin panel)
|
|
|
|
ynh_permission_create --permission="admin" --url="/web/database/manager" --allowed="all_users"
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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"
|