1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/openproject_ynh.git synced 2024-09-03 19:56:10 +02:00
openproject_ynh/scripts/install

193 lines
6.2 KiB
Text
Raw Normal View History

2019-10-01 14:40:53 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
2022-02-27 23:22:06 +01:00
# IMPORT GENERIC HELPERS
#=================================================
2019-10-01 14:40:53 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2022-02-27 23:22:06 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
2019-10-01 14:40:53 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
2022-02-27 23:22:06 +01:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2019-10-01 14:40:53 +02:00
#=================================================
2022-02-27 23:22:06 +01:00
2019-10-01 14:40:53 +02:00
domain=$YNH_APP_ARG_DOMAIN
2022-02-27 23:22:06 +01:00
path_url="/"
2019-10-01 14:40:53 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
2022-02-27 23:22:06 +01:00
2019-10-01 14:40:53 +02:00
app=$YNH_APP_INSTANCE_NAME
# Installer variables
2019-10-01 14:40:53 +02:00
_homedir="/var/$app/"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Validating installation parameters..."
2019-11-05 14:49:54 +01:00
2019-10-01 14:40:53 +02:00
# Register (book) web path
2022-02-27 23:22:06 +01:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2019-10-01 14:40:53 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Storing installation settings..."
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --app=$app --key=_homedir --value=$_homedir
2022-02-27 23:22:06 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
2019-10-01 14:40:53 +02:00
#=================================================
2022-02-27 23:22:06 +01:00
# INSTALL DEPENDENCIES
2019-10-01 14:40:53 +02:00
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Installing OpenProject & its dependencies..."
debian_release=$(lsb_release -r -s)
ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://dl.packager.io/srv/deb/opf/openproject/stable/$PROJECT_VERSION/debian $debian_release main" --package="$extra_pkg_dependencies" --key="https://dl.packager.io/srv/opf/openproject/key"
2019-10-01 14:40:53 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app
2019-10-01 14:40:53 +02:00
#=================================================
2022-02-27 23:22:06 +01:00
# CREATE A POSTGRESQL DATABASE
2019-10-01 14:40:53 +02:00
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Creating a PostgreSQL database..."
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
ynh_psql_test_if_first_run
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
2019-10-01 14:40:53 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Configuring NGINX web server..."
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
# Create a dedicated NGINX config
2019-10-01 14:40:53 +02:00
ynh_add_nginx_config
2022-02-27 23:22:06 +01:00
#=================================================
# SPECIFIC SETUP
2019-10-01 14:40:53 +02:00
#=================================================
# OPENPROJECT CONFIGURATION
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Configuring OpenProject..."
mkdir -p "/etc/openproject/"
_openproject_install_dat="/etc/openproject/installer.dat"
2019-10-03 15:38:06 +02:00
#TODO Not sure about this email sending. To be tested.
2022-02-27 23:22:06 +01:00
cat >> "$_openproject_install_dat"<< EOF
2019-10-03 15:38:06 +02:00
postgres/autoinstall reuse
postgres/db_host 127.0.0.1
postgres/db_port 5432
postgres/db_username $db_user
postgres/db_password $db_pwd
postgres/db_name $db_name
server/autoinstall skip
2022-02-27 23:22:06 +01:00
server/hostname $domain
server/protocol HTTPS
2019-10-03 15:38:06 +02:00
smtp/autoinstall smtp
smtp/authentication none
smtp/host 127.0.0.1
smtp/port 25
smtp/domain $domain
smtp/admin_email admin@$domain
memcached/autoinstall install
server/hostname $domain
server/ssl no
2019-10-01 14:40:53 +02:00
EOF
2019-10-03 15:38:06 +02:00
ynh_store_file_checksum --file="$_openproject_install_dat"
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
chmod 750 "/etc/openproject/"
chmod -R o-rwx "/etc/openproject/"
chown -R $app:$app "/etc/openproject/"
2019-10-04 14:55:06 +02:00
2022-02-27 23:22:06 +01:00
openproject config:set PORT=$port
openproject config:set SERVER_PROTOCOL_FORCE_HTTPS="true"
openproject config:set SERVER_HOSTNAME=$domain
openproject config:set SERVER_PATH_PREFIX=$path_url
2019-10-01 14:40:53 +02:00
2019-11-05 14:49:54 +01:00
openproject configure >> "$YNH_STDINFO"
2019-10-01 14:40:53 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2022-02-27 23:22:06 +01:00
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
yunohost service add $app
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
#=================================================
2019-10-01 14:40:53 +02:00
# START SYSTEMD SERVICE
2022-02-27 23:22:06 +01:00
#=================================================
ynh_script_progression --message="Starting a systemd service..."
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
2019-10-01 14:40:53 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true"
2019-10-01 14:40:53 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2019-10-01 14:40:53 +02:00
2022-02-27 23:22:06 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2019-10-01 14:40:53 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2022-02-27 23:22:06 +01:00
ynh_script_progression --message="Installation of $app completed"