mirror of
https://github.com/YunoHost-Apps/opensondage_ynh.git
synced 2024-09-03 19:46:28 +02:00
Add helpers and style
This commit is contained in:
parent
133a66296f
commit
29ccb4642c
7 changed files with 347 additions and 197 deletions
|
@ -1,5 +1,5 @@
|
|||
location PATHTOCHANGE {
|
||||
alias ALIASTOCHANGE;
|
||||
location __PATH__ {
|
||||
alias __FINALPATH__/;
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ location PATHTOCHANGE {
|
|||
try_files $uri $uri/ /index.php;
|
||||
location ~ [^/]\.php(/|$) {
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-YNH_APP_INSTANCE_NAME.sock;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
|
||||
include fastcgi_params;
|
||||
fastcgi_param REMOTE_USER $remote_user;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
|
@ -18,6 +18,6 @@ location PATHTOCHANGE {
|
|||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
||||
|
||||
location ~ ^PATHTOCHANGE/(data|config|\.ht|db_structure\.xml|README) {
|
||||
location ~ ^__PATH__/(data|config|\.ht|db_structure\.xml|README) {
|
||||
deny all;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
; Start a new pool named 'www'.
|
||||
; the variable $pool can we used in any directive and will be replaced by the
|
||||
; pool name ('www' here)
|
||||
[NAMETOCHANGE]
|
||||
[__NAMETOCHANGE__]
|
||||
|
||||
; Per pool prefix
|
||||
; It only applies on the following directives:
|
||||
|
@ -24,7 +24,7 @@
|
|||
; specific port;
|
||||
; '/path/to/unix/socket' - to listen on a unix socket.
|
||||
; Note: This value is mandatory.
|
||||
listen = /var/run/php5-fpm-NAMETOCHANGE.sock
|
||||
listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
|
||||
|
||||
; Set listen(2) backlog. A value of '-1' means unlimited.
|
||||
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
|
||||
|
@ -170,7 +170,7 @@ request_slowlog_timeout = 5s
|
|||
; The log file for slow requests
|
||||
; Default Value: not set
|
||||
; Note: slowlog is mandatory if request_slowlog_timeout is set
|
||||
slowlog = /var/log/nginx/NAMETOCHANGE.slow.log
|
||||
slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log
|
||||
|
||||
; Set open file descriptor rlimit.
|
||||
; Default Value: system defined value
|
||||
|
@ -195,7 +195,7 @@ rlimit_core = 0
|
|||
; Chdir to this directory at the start.
|
||||
; Note: relative path can be used.
|
||||
; Default Value: current directory or / when chroot
|
||||
chdir = /var/www/NAMETOCHANGE
|
||||
chdir = __FINALPATH__
|
||||
|
||||
; Redirect worker stdout and stderr into main error log. If not set, stdout and
|
||||
; stderr will be redirected to /dev/null according to FastCGI specs.
|
||||
|
|
|
@ -27,20 +27,35 @@ ynh_abort_if_errors
|
|||
|
||||
# See comments in install script
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
db_name=$(ynh_app_setting_get "$app" db_name)
|
||||
dbuser=$app
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
# Backup sources & data
|
||||
ynh_backup "/var/www/$app"
|
||||
|
||||
# Dump the database
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Copy NGINX configuration
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
# Copy PHP-FPM pool configuration
|
||||
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
|
||||
ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "php-fpm.ini"
|
||||
#=================================================
|
||||
# BACKUP THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
|
||||
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_mysql_dump_db "$db_name" > db.sql
|
||||
|
|
150
scripts/install
150
scripts/install
|
@ -24,30 +24,56 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
admin=$YNH_APP_ARG_ADMIN
|
||||
language=$YNH_APP_ARG_LANGUAGE
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
legal='no'
|
||||
|
||||
# Check if admin exists
|
||||
ynh_user_exists $admin \
|
||||
|| ynh_die "Wrong admin"
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
|
||||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
|
||||
ynh_app_setting_set "$app" domain "$domain"
|
||||
ynh_app_setting_set "$app" path_url "$path_url"
|
||||
ynh_app_setting_set "$app" admin "$admin"
|
||||
ynh_app_setting_set "$app" language "$language"
|
||||
ynh_app_setting_set "$app" legal "$legal"
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
# Deprecated
|
||||
ynh_app_setting_set "$app" public_site "$is_public"
|
||||
|
||||
# Check domain/path availability
|
||||
yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Copy files to the right place
|
||||
final_path=/var/www/$app
|
||||
mkdir -p $final_path
|
||||
ynh_install_app_dependencies php-fpdf
|
||||
|
||||
#=================================================
|
||||
# CREATE A MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
# Generate MySQL password and create database
|
||||
dbuser=$app
|
||||
db_name=$app
|
||||
dbpass=$(ynh_string_random 12)
|
||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
||||
ynh_app_setting_set "$app" db_name "$db_name"
|
||||
ynh_mysql_create_db "$db_name" "$dbuser" "$dbpass"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
|
@ -57,12 +83,25 @@ ynh_app_setting_set "$app" final_path "$final_path"
|
|||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source "$final_path"
|
||||
|
||||
# Generate MySQL password and create database
|
||||
dbuser=$app
|
||||
dbname=$app
|
||||
dbpass=$(ynh_string_random 12)
|
||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
# Create config.php
|
||||
#=================================================
|
||||
|
||||
config="$final_path/app/inc/config.php"
|
||||
cp ../conf/config.php $config
|
||||
|
@ -70,54 +109,67 @@ cp ../conf/config.php $config
|
|||
# Change variables in configuration
|
||||
ynh_replace_string "__DBUSER__" "$dbuser" $config
|
||||
ynh_replace_string "__DBPWD__" "$dbpass" $config
|
||||
ynh_replace_string "__DBNAME__" "$dbname" $config
|
||||
ynh_replace_string "__DBNAME__" "$db_name" $config
|
||||
ynh_replace_string "__ADMINMAIL__" "$admin" $config
|
||||
ynh_replace_string "__LANGUAGE__" "$language" $config
|
||||
ynh_replace_string "__DOMAIN__" "$domain" $config
|
||||
ynh_replace_string "__PATH__" "$path" $config
|
||||
ynh_replace_string "__PATH__" "$path_url" $config
|
||||
|
||||
#=================================================
|
||||
# Replace logo image (default is FramaDate)
|
||||
#=================================================
|
||||
|
||||
cp ../img/logo.png $final_path/images
|
||||
|
||||
#=================================================
|
||||
# STORE THE CHECKSUM OF THE CONFIG FILE
|
||||
#=================================================
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum "$config"
|
||||
|
||||
#=================================================
|
||||
# Create log file
|
||||
#=================================================
|
||||
|
||||
# Create log file
|
||||
touch $final_path/admin/stdout.log
|
||||
chmod 700 $final_path/admin/stdout.log
|
||||
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set permissions
|
||||
chown -R www-data: $final_path
|
||||
|
||||
#=================================================
|
||||
# Run database initilization
|
||||
#=================================================
|
||||
|
||||
init_composer "www-data" "$final_path"
|
||||
|
||||
-u "www-data" php "$final_path/admin/migration.php"
|
||||
sudo -u "www-data" php "$final_path/admin/migration.php"
|
||||
|
||||
# Modify PHP-FPM pool configuration and copy it to the pool directory
|
||||
ynh_replace_string "NAMETOCHANGE" "$app" ../conf/php-fpm.conf
|
||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||
cp ../conf/php-fpm.conf $finalphpconf
|
||||
chown root: $finalphpconf
|
||||
chmod 644 $finalphpconf
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
|
||||
cp ../conf/php-fpm.ini $finalphpini
|
||||
chown root: $finalphpini
|
||||
chmod 644 $finalphpini
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
service php5-fpm restart
|
||||
|
||||
ynh_package_install php-fpdf
|
||||
yunohost app addaccess $app -u $admin
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
ynh_replace_string "PATHTOCHANGE" "$path" ../conf/nginx.conf
|
||||
ynh_replace_string "ALIASTOCHANGE" "$final_path" ../conf/nginx.conf
|
||||
ynh_replace_string "YNH_APP_INSTANCE_NAME" "$app" ../conf/nginx.conf
|
||||
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
service nginx reload
|
||||
ynh_app_setting_set "$app" skipped_uris "/"
|
||||
if [[ $is_public -eq 0 ]];
|
||||
then
|
||||
ynh_app_setting_set "$app" protected_uris "/admin,/index.php,/choix_date.php,/choix_autre.php,/infos_sondage.php,/scripts"
|
||||
else
|
||||
ynh_app_setting_set "$app" protected_uris "/admin/index.php,/admin/logs_studs.txt,/scripts"
|
||||
ynh_app_setting_set "$app" protected_uris "/admin/index.php,/admin/stdout.log,/scripts"
|
||||
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
|
||||
|
||||
ynh_store_file_checksum "$finalnginxconf"
|
||||
fi
|
||||
yunohost app ssowatconf
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
|
|
|
@ -18,20 +18,40 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
# Remove sources
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
db_name=$app
|
||||
dbuser=$app
|
||||
ynh_mysql_remove_db "$db_name" "$dbuser"
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_secure_remove "/var/www/$app"
|
||||
|
||||
# Remove configuration files
|
||||
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_secure_remove /etc/php5/fpm/pool.d/$app.conf
|
||||
ynh_secure_remove /etc/php5/fpm/conf.d/20-$app.ini
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
# Drop MySQL database and user
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
ynh_mysql_drop_db "$dbname" || true
|
||||
ynh_mysql_drop_user "$dbuser" || true
|
||||
#=================================================
|
||||
# REMOVE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
service nginx reload
|
||||
service php5-fpm reload
|
||||
# Remove the dedicated php-fpm config
|
||||
ynh_remove_fpm_config
|
||||
|
|
112
scripts/restore
112
scripts/restore
|
@ -30,77 +30,75 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
# Retrieve old app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
admin=$(ynh_app_setting_get "$app" admin)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
public_site=$(ynh_app_setting_get "$app" public_site)
|
||||
legal=$(ynh_app_setting_get "$app" legal)
|
||||
db_name=$(ynh_app_setting_get "$app" db_name)
|
||||
dbuser=$app
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
|
||||
# Check domain/path availability
|
||||
yunohost app checkurl $domain$path -a $app \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#================================================
|
||||
|
||||
ynh_webpath_available $domain $path_url \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die "There is already a directory: $final_path"
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
# Set permissions
|
||||
chown -R www-data:www-data $final_path
|
||||
|
||||
|
||||
final_path=/var/www/$app
|
||||
if [ -d $final_path ]; then
|
||||
ynh_die "There is already a directory: $final_path "
|
||||
fi
|
||||
#=================================================
|
||||
# RESTORE THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
conf=/etc/nginx/conf.d/$domain.d/$app.conf
|
||||
if [ -f $conf ]; then
|
||||
ynh_die "There is already a nginx conf file at this path: $conf "
|
||||
fi
|
||||
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
|
||||
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
|
||||
phpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||
if [ -f $phpconf ]; then
|
||||
ynh_die "There is already a php-fpm conf file at this path: $phpconf "
|
||||
fi
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
phpini=/etc/php5/fpm/conf.d/20-$app.ini
|
||||
if [ -f $phpini ]; then
|
||||
ynh_die "There is already a php-fpm ini file at this path: $phpini "
|
||||
fi
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
ynh_mysql_setup_db "$db_name" "$db_name" "$db_pwd"
|
||||
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Dependences
|
||||
ynh_package_install php-fpdf
|
||||
|
||||
# Restore sources & data
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
||||
|
||||
# Set permissions
|
||||
chmod 700 $final_path/admin/logs_studs.txt
|
||||
chown -R www-data:www-data $final_path
|
||||
|
||||
# Restore conf files
|
||||
cp -a ./nginx.conf $conf
|
||||
cp -a ./php-fpm.conf $phpconf
|
||||
chown root: $phpconf
|
||||
chmod 644 $phpconf
|
||||
cp -a ./php-fpm.ini $phpini
|
||||
chown root: $phpini
|
||||
chmod 644 $phpini
|
||||
|
||||
# Set Administrator
|
||||
if ynh_user_exists $admin; then
|
||||
yunohost app addaccess $app -u $admin
|
||||
fi
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
|
||||
# Reload Nginx
|
||||
service php5-fpm restart
|
||||
service nginx reload
|
||||
|
||||
# Set ssowat config
|
||||
ynh_app_setting_set "$app" skipped_uris "/"
|
||||
if [[ $is_public -eq 0 ]];
|
||||
then
|
||||
ynh_app_setting_set "$app" protected_uris "/admin,/index.php,/choix_date.php,/choix_autre.php,/infos_sondage.php,/scripts"
|
||||
else
|
||||
ynh_app_setting_set "$app" protected_uris "/admin/index.php,/admin/logs_studs.txt,/scripts"
|
||||
fi
|
||||
yunohost app ssowatconf
|
||||
|
|
185
scripts/upgrade
185
scripts/upgrade
|
@ -24,102 +24,167 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
# Retrieve arguments
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
admin=$(ynh_app_setting_get "$app" admin)
|
||||
public_site=$(ynh_app_setting_get "$app" public_site)
|
||||
legal=$(ynh_app_setting_get "$app" legal)
|
||||
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
if [[ "$is_public" = "" ]];
|
||||
then
|
||||
if [ $public_site = "No" ];
|
||||
then
|
||||
is_public=0
|
||||
else
|
||||
is_public=1
|
||||
fi
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
dbuser=$app
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
final_path=(ynh_app_setting_get "$app" final_path)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
|
||||
# Fix is_public as a boolean value
|
||||
if [ "$is_public" = "Yes" ]; then
|
||||
ynh_app_setting_set $app is_public 1
|
||||
is_public=1
|
||||
elif [ "$is_public" = "No" ]; then
|
||||
ynh_app_setting_set $app is_public 0
|
||||
is_public=0
|
||||
fi
|
||||
|
||||
# If db_name doesn't exist, create it
|
||||
if [ -z $db_name ]; then
|
||||
db_name=$(ynh_sanitize_dbid $app)
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
fi
|
||||
|
||||
# If final_path doesn't exist, create it
|
||||
if [ -z $final_path ]; then
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set $app final_path $final_path
|
||||
fi
|
||||
|
||||
# make sure default language is set
|
||||
language=$(ynh_app_setting_get "$app" language)
|
||||
if [[ "$language" = "" ]];
|
||||
then
|
||||
language=$(grep LANGUE /var/www/$app/variables.php | grep -Po "'.*?'" | cut -d"'" -f2)
|
||||
fi
|
||||
|
||||
# Check if admin is not null
|
||||
if [[ "$admin" = "" || "$language" = "" ]]; then
|
||||
ynh_die "Unable to upgrade, please contact support"
|
||||
fi
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
||||
# Remove trailing "/" for next commands
|
||||
path=${path%/}
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
root_pwd=$(cat /etc/yunohost/mysql)
|
||||
dbname=$app
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
dbuser=$app
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
#=================================================
|
||||
|
||||
### Execute potential SQL statements here
|
||||
# Copy files to the right place
|
||||
final_path=/var/www/$app
|
||||
# Normalize the URL path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
ynh_app_setting_set "$app" final_path "$final_path"
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source "$final_path"
|
||||
|
||||
cp ../conf/constants.php.template $final_path/app/inc/constants.php
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# Create config.php
|
||||
#=================================================
|
||||
|
||||
config="$final_path/app/inc/config.php"
|
||||
cp ../conf/config.php $config
|
||||
|
||||
# Change variables in configuration
|
||||
sed -i "s/yunouser/$dbuser/g" $final_path/app/inc/constants.php
|
||||
sed -i "s/yunopass/$dbpass/g" $final_path/app/inc/constants.php
|
||||
sed -i "s/yunobase/$dbname/g" $final_path/app/inc/constants.php
|
||||
sed -i "s/yunoadmin/$admin/g" $final_path/app/inc/constants.php
|
||||
sed -i "s/I18NTOCHANGE/$language/g" $final_path/app/inc/constants.php
|
||||
sed -i "s@yunourl@$domain$path@g" $final_path/app/inc/constants.php
|
||||
sed -i "s@yunodomain@$domain@g" $final_path/app/inc/constants.php
|
||||
sed -i "s@yunoabout@$legal@g" $final_path/app/inc/constants.php
|
||||
ynh_replace_string "__DBUSER__" "$dbuser" $config
|
||||
ynh_replace_string "__DBPWD__" "$dbpass" $config
|
||||
ynh_replace_string "__DBNAME__" "$db_name" $config
|
||||
ynh_replace_string "__ADMINMAIL__" "$admin" $config
|
||||
ynh_replace_string "__LANGUAGE__" "$language" $config
|
||||
ynh_replace_string "__DOMAIN__" "$domain" $config
|
||||
ynh_replace_string "__PATH__" "$path_url" $config
|
||||
|
||||
#=================================================
|
||||
# Replace logo image (default is FramaDate)
|
||||
#=================================================
|
||||
|
||||
cp ../img/logo.png "$final_path/images"
|
||||
|
||||
#=================================================
|
||||
# STORE THE CHECKSUM OF THE CONFIG FILE
|
||||
#=================================================
|
||||
|
||||
# Verify the checksum and backup the file if it's different
|
||||
ynh_backup_if_checksum_is_different "$config"
|
||||
# Recalculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum "$config"
|
||||
|
||||
#=================================================
|
||||
# Create log file
|
||||
#=================================================
|
||||
|
||||
# Create log file
|
||||
cp ../conf/logs_studs.txt $final_path/admin/
|
||||
chmod 700 $final_path/admin/logs_studs.txt
|
||||
touch $final_path/admin/stdout.log
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set permissions to roundcube directory
|
||||
chown -R www-data: $final_path
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
||||
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/nginx.conf
|
||||
#=================================================
|
||||
# Run database initilization
|
||||
#=================================================
|
||||
|
||||
if ynh_user_exists $admin; then
|
||||
yunohost app addaccess $app -u $admin
|
||||
fi
|
||||
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
init_composer "www-data" "$final_path"
|
||||
|
||||
sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
|
||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||
cp ../conf/php-fpm.conf $finalphpconf
|
||||
chown root: $finalphpconf
|
||||
chmod 644 $finalphpconf
|
||||
sudo -u "www-data" php "$final_path/admin/migration.php"
|
||||
|
||||
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
|
||||
cp ../conf/php-fpm.ini $finalphpini
|
||||
chown root: $finalphpini
|
||||
chmod 644 $finalphpini
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
service php5-fpm restart
|
||||
# Reload Nginx
|
||||
service nginx reload
|
||||
ynh_app_setting_set "$app" skipped_uris "/"
|
||||
if [ $is_public -eq 0 ];
|
||||
then
|
||||
ynh_app_setting_set "$app" protected_uris "/admin,/index.php,/choix_date.php,/choix_autre.php,/infos_sondage.php,/scripts"
|
||||
ynh_app_setting_set "$app" protected_uris "/admin,/index.php,/choix_date.php,/choix_autre.php,/infos_sondage.php,/scripts"
|
||||
else
|
||||
ynh_app_setting_set "$app" protected_uris "/admin/index.php,/admin/logs_studs.txt,/scripts"
|
||||
ynh_app_setting_set "$app" protected_uris "/admin/index.php,/admin/stdout.log,/scripts"
|
||||
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
|
||||
|
||||
ynh_store_file_checksum "$finalnginxconf"
|
||||
fi
|
||||
yunohost app ssowatconf
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
|
|
Loading…
Add table
Reference in a new issue