mirror of
https://github.com/YunoHost-Apps/libreerp_ynh.git
synced 2024-09-03 19:36:13 +02:00
220 lines
7.2 KiB
Bash
220 lines
7.2 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
true
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url="/"
|
|
export is_public=0
|
|
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
|
|
|
|
export conf_file=/etc/$app/main.conf
|
|
export final_path=/var/www/$app
|
|
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
|
|
export preinstall=0
|
|
|
|
#=================================================
|
|
# 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
|
|
export db_pass=$(ynh_string_random)
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
# Make sure that postgresql is installed and running
|
|
ynh_psql_test_if_first_run
|
|
|
|
# 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..."
|
|
|
|
setup_database
|
|
|
|
#=================================================
|
|
# 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_app_setting_set $app unprotected_uris "/"
|
|
|
|
if [[ $is_public -eq 0 ]]; then
|
|
ynh_app_setting_set $app protected_uris "/web/database/manager"
|
|
fi
|
|
sudo yunohost app ssowatconf
|
|
|
|
#=================================================
|
|
# 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"
|