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-10-20 02:27:52 +02:00
|
|
|
true
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
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
|
2022-06-17 13:32:01 +02:00
|
|
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
2022-02-17 01:23:35 +01:00
|
|
|
fi
|
|
|
|
if [ "$app_version" = "8" ]; then
|
2022-06-17 13:32:01 +02:00
|
|
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
2022-02-17 01:23:35 +01:00
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# 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
|
2022-06-17 13:32:01 +02:00
|
|
|
:
|
2022-05-29 16:07:32 +02:00
|
|
|
else
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Adding swap..." --weight=1
|
2022-06-17 13:32:01 +02:00
|
|
|
ynh_add_swap --size=$swap_needed
|
2022-05-29 16:07:32 +02:00
|
|
|
fi
|
2022-02-17 01:23:35 +01:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Building app..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
|
2022-06-17 13:32:01 +02:00
|
|
|
# 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
|
2022-02-13 22:09:18 +01:00
|
|
|
fi
|
|
|
|
pushd $final_path
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$final_path"/.rustup CARGO_HOME="$final_path"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
|
|
|
|
export PATH="$PATH:$final_path/.cargo/bin:$final_path/.local/bin:/usr/local/sbin"
|
2022-06-17 13:32:01 +02:00
|
|
|
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
|
|
|
|
python3 -m venv venv
|
|
|
|
venv/bin/pip3 install --upgrade pip
|
|
|
|
venv/bin/pip3 install wheel
|
|
|
|
venv/bin/pip3 install -r $appname/requirements.txt
|
|
|
|
else
|
|
|
|
virtualenv venv
|
|
|
|
venv/bin/pip3 install --upgrade pip
|
|
|
|
venv/bin/pip install wheel
|
|
|
|
venv/bin/pip install -r $appname/requirements.txt
|
|
|
|
fi
|
|
|
|
ynh_secure_remove --file="$final_path/.cargo"
|
|
|
|
ynh_secure_remove --file="$final_path/.rustup"
|
2022-02-13 22:09:18 +01:00
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP DATABASE
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Setuping the database..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
yunohost service add $app --log="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
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
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|