132 lines
4.1 KiB
Bash
132 lines
4.1 KiB
Bash
#!/bin/bash
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
ynh_app_setting_set --key=php_upload_max_filesize --value=500M
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
app_nb=$YNH_APP_INSTANCE_NUMBER
|
|
ssh_port=$(grep "^Port" /etc/ssh/sshd_config | awk '{print $2}')
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression "Validating installation parameters..."
|
|
|
|
[ $with_sftp -eq 0 ] || [ "$password" != "" ] || ynh_die "You need to set a password to enable SFTP"
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression "Storing installation settings..."
|
|
|
|
ynh_app_setting_set --key=password --value=$password
|
|
|
|
#=================================================
|
|
# CREATE A MYSQL DATABASE
|
|
#=================================================
|
|
|
|
if [ $database != "none" ]; then
|
|
ynh_script_progression "Creating a database..."
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
db_user=$db_name
|
|
db_pwd=$(ynh_string_random --length=30)
|
|
ynh_app_setting_set --key=db_name --value=$db_name
|
|
ynh_app_setting_set --key=db_user --value=$db_user
|
|
ynh_app_setting_set --key=db_pwd --value=$db_pwd
|
|
|
|
if [ $database == "mysql" ]; then
|
|
# FIXME ynh_mysql_create_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
elif [ $database == "postgresql" ]; then
|
|
# FIXME ynh_psql_create_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Configuring NGINX web server..."
|
|
|
|
nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d"
|
|
mkdir -p "$nginx_extra_conf_dir"
|
|
|
|
# Prepare nginx extra conf
|
|
if [ $php_version != "none" ]
|
|
then
|
|
ynh_config_add --template="nginx-php.conf" --destination="$nginx_extra_conf_dir/php.conf"
|
|
YNH_PHP_VERSION="$php_version"
|
|
fi
|
|
|
|
# Add the custom error build with the application
|
|
ynh_config_add --template="nginx-code-error.conf" --destination="$nginx_extra_conf_dir/error-code.conf"
|
|
ynh_app_setting_set --key=custom_error_file --value="true"
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_config_add_nginx
|
|
ynh_config_add --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression "Configuring system user..."
|
|
|
|
if [ $with_sftp -eq 1 ]
|
|
then
|
|
groups="sftp.app"
|
|
else
|
|
groups=""
|
|
fi
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$install_dir" --groups="$groups"
|
|
|
|
if [ $with_sftp -eq 1 ]
|
|
then
|
|
# Add the password to this user
|
|
chpasswd <<< "${app}:${password}"
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
|
|
mkdir -p "$install_dir/www"
|
|
|
|
if [ $with_sftp -eq 1 ]
|
|
then
|
|
ynh_config_add --template="../sources/www/index.html" --destination="$install_dir/www/index.html"
|
|
else
|
|
ynh_config_add --template="../sources/www/index_no_sftp.html" --destination="$install_dir/www/index.html"
|
|
fi
|
|
|
|
chown -R $app:www-data "$install_dir"
|
|
# Home directory of the user needs to be owned by root to allow
|
|
# SFTP connections
|
|
chown root:root "$install_dir"
|
|
setfacl -m g:$app:r-x "$install_dir"
|
|
setfacl -m g:www-data:r-x "$install_dir"
|
|
chmod 750 "$install_dir"
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
|
|
if [ $php_version != "none" ]
|
|
then
|
|
ynh_script_progression "Configuring PHP-FPM..."
|
|
|
|
ynh_config_add_phpfpm
|
|
fi
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Installation of $app completed"
|