mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
[enh] various enhancements
* retrieving sources instead of create-project * exec_as in composer helpers * reorder install and upgrade steps
This commit is contained in:
parent
dc4918b2f4
commit
8ba8b17ac9
5 changed files with 106 additions and 126 deletions
6
conf/app.src
Normal file
6
conf/app.src
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
SOURCE_URL=https://github.com/flarum/flarum/archive/v0.1.0-beta.12.zip
|
||||||
|
SOURCE_SUM=E2C02B75D2A38F7AFD08DB981418ED1EE6604E450DFB87F0A0EF834687329631
|
||||||
|
SOURCE_SUM_PRG=sha256sum
|
||||||
|
SOURCE_FORMAT=zip
|
||||||
|
SOURCE_IN_SUBDIR=true
|
||||||
|
SOURCE_FILENAME=
|
|
@ -292,4 +292,3 @@ ynh_add_app_dependencies () {
|
||||||
|
|
||||||
ynh_install_app_dependencies "${current_dependencies}${package}"
|
ynh_install_app_dependencies "${current_dependencies}${package}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
|
|
||||||
# Execute a command with Composer
|
# Execute a command with Composer
|
||||||
#
|
#
|
||||||
# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands"
|
# usage: ynh_composer_exec --user=user --phpversion=phpversion [--workdir=$final_path] --commands="commands"
|
||||||
|
# | arg: -u, --user - The user to perform the command with.
|
||||||
|
# | arg: -v, --phpversion - The php version to perform the command with.
|
||||||
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
||||||
# | arg: -c, --commands - Commands to execute.
|
# | arg: -c, --commands - Commands to execute.
|
||||||
ynh_composer_exec () {
|
ynh_composer_exec () {
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=uvwc
|
local legacy_args=uvwc
|
||||||
declare -Ar args_array=( [u]=user [v]=phpversion= [w]=workdir= [c]=commands= )
|
declare -Ar args_array=( [u]=user= [v]=phpversion= [w]=workdir= [c]=commands= )
|
||||||
local user
|
local user
|
||||||
local phpversion
|
local phpversion
|
||||||
local workdir
|
local workdir
|
||||||
|
@ -18,32 +20,36 @@ ynh_composer_exec () {
|
||||||
workdir="${workdir:-$final_path}"
|
workdir="${workdir:-$final_path}"
|
||||||
phpversion="${phpversion:-7.0}"
|
phpversion="${phpversion:-7.0}"
|
||||||
|
|
||||||
COMPOSER_HOME="$workdir/.composer" \
|
exec_as $user COMPOSER_HOME="$workdir/.composer" \
|
||||||
exec_as $user php${phpversion} "$workdir/composer.phar" $commands \
|
php${phpversion} "$workdir/composer.phar" $commands \
|
||||||
-d "$workdir" --quiet --no-interaction
|
-d "$workdir" --quiet --no-interaction
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install and initialize Composer in the given directory
|
# Install and initialize Composer in the given directory
|
||||||
#
|
#
|
||||||
# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path]
|
# usage: ynh_install_composer --user=user --phpversion=phpversion [--workdir=$final_path]
|
||||||
|
# | arg: -u, --user - The user to perform the command with.
|
||||||
|
# | arg: -v, --phpversion - The php version to perform the command with.
|
||||||
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
||||||
ynh_install_composer () {
|
ynh_install_composer () {
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=vw
|
local legacy_args=uvw
|
||||||
declare -Ar args_array=( [v]=phpversion= [w]=workdir= )
|
declare -Ar args_array=( [u]=user= [v]=phpversion= [w]=workdir= )
|
||||||
|
local user
|
||||||
local phpversion
|
local phpversion
|
||||||
local workdir
|
local workdir
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
user="${user:-root}"
|
||||||
workdir="${workdir:-$final_path}"
|
workdir="${workdir:-$final_path}"
|
||||||
phpversion="${phpversion:-7.0}"
|
phpversion="${phpversion:-7.0}"
|
||||||
|
|
||||||
curl -sS https://getcomposer.org/installer \
|
curl -sS https://getcomposer.org/installer \
|
||||||
| COMPOSER_HOME="$workdir/.composer" \
|
| exec_as $user COMPOSER_HOME="$workdir/.composer" \
|
||||||
exec_as $app php${phpversion} -- --quiet --install-dir="$workdir" \
|
php${phpversion} -- --quiet --install-dir="$workdir" \
|
||||||
|| ynh_die "Unable to install Composer."
|
|| ynh_die "Unable to install Composer."
|
||||||
|
|
||||||
# update dependencies to create composer.lock
|
# update dependencies to create composer.lock
|
||||||
#ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \
|
ynh_composer_exec --user=$app --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \
|
||||||
# || ynh_die "Unable to update core dependencies with Composer."
|
|| ynh_die "Unable to update core dependencies with Composer."
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ source experimental_helpers/ynh_send_readme_to_admin__2
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|
true
|
||||||
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
@ -99,49 +103,6 @@ ynh_print_info --message="Installing dependencies..."
|
||||||
|
|
||||||
ynh_install_app_dependencies "$pkg_dependencies"
|
ynh_install_app_dependencies "$pkg_dependencies"
|
||||||
|
|
||||||
#===================================================
|
|
||||||
# CREATE DEDICATED USER
|
|
||||||
#===================================================
|
|
||||||
|
|
||||||
ynh_system_user_create $app $final_path
|
|
||||||
usermod -a -G www-data $app
|
|
||||||
# Create working directory
|
|
||||||
mkdir -p "$final_path/.composer"
|
|
||||||
chown -R $app:www-data $final_path
|
|
||||||
chmod -R 0775 $final_path
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# COMPOSER INSTALLATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_script_progression --message="Installing Composer..." --time --weight=1
|
|
||||||
ynh_install_composer $php_version $final_path
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FLARUM INSTALLATION
|
|
||||||
#=================================================
|
|
||||||
# Prepare Flarum temp directory
|
|
||||||
tmp=/tmp/$app
|
|
||||||
ynh_secure_remove --file="$tmp"
|
|
||||||
mkdir -p $tmp
|
|
||||||
chown -R $app:www-data $tmp
|
|
||||||
chmod -R 0775 $tmp
|
|
||||||
|
|
||||||
# Install Flarum
|
|
||||||
ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3
|
|
||||||
|
|
||||||
# First, create the project with core and all basic extensions
|
|
||||||
ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
|
|
||||||
|
|
||||||
# Copy Flarum to working directory and clean temp directory
|
|
||||||
cp -Rf $tmp/* $final_path
|
|
||||||
ynh_secure_remove $tmp
|
|
||||||
|
|
||||||
# Set right permissions for the post-installation
|
|
||||||
chown -R $app: $final_path
|
|
||||||
chown -R $app:www-data $final_path/storage
|
|
||||||
chmod -R 0775 $final_path
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A MYSQL DATABASE
|
# CREATE A MYSQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -151,6 +112,19 @@ ynh_app_setting_set $app db_name $db_name
|
||||||
ynh_mysql_setup_db $db_name $db_name
|
ynh_mysql_setup_db $db_name $db_name
|
||||||
ynh_app_setting_set "$app" db_pwd "$db_pwd"
|
ynh_app_setting_set "$app" db_pwd "$db_pwd"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setting up source files..." --time --weight=1
|
||||||
|
|
||||||
|
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
||||||
|
### downloaded from an upstream source, like a git repository.
|
||||||
|
### `ynh_setup_source` use the file conf/app.src
|
||||||
|
|
||||||
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -165,6 +139,16 @@ fi
|
||||||
# Create a dedicated nginx config
|
# Create a dedicated nginx config
|
||||||
ynh_add_nginx_config
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#===================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#===================================================
|
||||||
|
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
ynh_system_user_create $app $final_path
|
||||||
|
# Adding it to www-data group
|
||||||
|
usermod -a -G www-data $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PHP-FPM CONFIGURATION
|
# PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -172,6 +156,18 @@ ynh_add_nginx_config
|
||||||
# Create a dedicated php-fpm config
|
# Create a dedicated php-fpm config
|
||||||
ynh_add_fpm_config $php_version
|
ynh_add_fpm_config $php_version
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# COMPOSER INSTALLATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Installing Composer and Flarum..." --time --weight=1
|
||||||
|
|
||||||
|
# Setting user rights
|
||||||
|
chown -R $app:www-data $final_path
|
||||||
|
chmod -R 775 $final_path
|
||||||
|
|
||||||
|
# Install Composer and Flarum
|
||||||
|
ynh_install_composer --user=$app --phpversion=$php_version --workdir=$final_path
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -235,7 +231,6 @@ sql_command="REPLACE INTO \`settings\` (\`key\`, \`value\`) VALUES
|
||||||
('mail_port', '587');"
|
('mail_port', '587');"
|
||||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||||
|
|
||||||
|
|
||||||
# Install and activate the SSOwat auth extension
|
# Install and activate the SSOwat auth extension
|
||||||
ynh_script_progression --message="Installing SSOwat extension..." --time --weight=2
|
ynh_script_progression --message="Installing SSOwat extension..." --time --weight=2
|
||||||
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
|
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
|
||||||
|
@ -262,7 +257,8 @@ esac
|
||||||
|
|
||||||
if [ $bazaar_extension -eq 1 ]; then
|
if [ $bazaar_extension -eq 1 ]; then
|
||||||
ynh_script_progression --message="Installing Bazaar extension..." --time --weight=2
|
ynh_script_progression --message="Installing Bazaar extension..." --time --weight=2
|
||||||
ynh_composer_exec $app $php_version $final_path "require extiverse/bazaar --ansi"
|
ynh_composer_exec --user=$app --phpversion=$php_version --workdir=$final_path \
|
||||||
|
--commands="require extiverse/bazaar --ansi"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -88,10 +88,6 @@ if [ ! -z "$protected_uris" ]; then
|
||||||
ynh_app_setting_delete --app=$app --key=protected_uris
|
ynh_app_setting_delete --app=$app --key=protected_uris
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If some settings are missing, assume older package version
|
|
||||||
[ -z "$old_project_version" ] && old_project_version="0.1.0-beta.7"
|
|
||||||
[ -z "$old_ssowat_version" ] && old_ssowat_version="0.6"
|
|
||||||
|
|
||||||
# Remove the v before version number
|
# Remove the v before version number
|
||||||
if [[ $old_project_version == "v*" ]]; then $old_project_version = ${old_project_version:1}; fi
|
if [[ $old_project_version == "v*" ]]; then $old_project_version = ${old_project_version:1}; fi
|
||||||
|
|
||||||
|
@ -175,18 +171,12 @@ ynh_add_fpm_config $php_version
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC UPGRADE
|
# SPECIFIC UPGRADE
|
||||||
#=================================================
|
#=================================================
|
||||||
# COMPOSER UPGRADE
|
# COMPOSER AND FLARUM UPGRADE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if ! type "$final_path/composer.phar" > /dev/null; then
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
ynh_install_composer $php_version $final_path
|
then
|
||||||
fi
|
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FLARUM UPGRADE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo true) ]]; then
|
|
||||||
|
|
||||||
# Backing up the app directory
|
# Backing up the app directory
|
||||||
tmpbak="/tmp/${app}backup"
|
tmpbak="/tmp/${app}backup"
|
||||||
|
@ -197,38 +187,15 @@ if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo
|
||||||
# Deleting current app directory
|
# Deleting current app directory
|
||||||
ynh_secure_remove --file="$final_path"
|
ynh_secure_remove --file="$final_path"
|
||||||
|
|
||||||
# Create working directory
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
mkdir -p "$final_path/.composer"
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
chown -R $app:www-data $final_path
|
|
||||||
chmod -R 0775 $final_path
|
|
||||||
|
|
||||||
#=================================================
|
# Install Composer and Flarum
|
||||||
# COMPOSER INSTALLATION
|
ynh_install_composer --user=$app --phpversion=$php_version --workdir=$final_path
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_script_progression --message="Installing Composer..." --time --weight=1
|
# Copy config.php back into Flarum
|
||||||
ynh_install_composer $php_version $final_path
|
cp -f $tmpbak/config.php $final_path
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FLARUM INSTALLATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Prepare Flarum temp directory
|
|
||||||
tmp=/tmp/$app
|
|
||||||
mkdir -p $tmp
|
|
||||||
chown -R $app:www-data $tmp
|
|
||||||
chmod -R 0775 $tmp
|
|
||||||
|
|
||||||
# Install Flarum
|
|
||||||
ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3
|
|
||||||
|
|
||||||
# First, create the project with core and all basic extensions
|
|
||||||
ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
|
|
||||||
|
|
||||||
# Copy Flarum to working directory
|
|
||||||
cp -Rf $tmp/* $final_path
|
|
||||||
# Copy config.php from old app version
|
|
||||||
cp -Rf $tmpbak/config.php $final_path
|
|
||||||
# Copy assets from old app version. Can be either in root folder or in "public" folder
|
# Copy assets from old app version. Can be either in root folder or in "public" folder
|
||||||
if [ -d $tmpbak/assets ]; then
|
if [ -d $tmpbak/assets ]; then
|
||||||
cp -Rf $tmpbak/assets $final_path/public
|
cp -Rf $tmpbak/assets $final_path/public
|
||||||
|
@ -236,34 +203,37 @@ if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo
|
||||||
if [ -d $tmpbak/public/assets ]; then
|
if [ -d $tmpbak/public/assets ]; then
|
||||||
cp -Rf $tmpbak/public/assets $final_path/public
|
cp -Rf $tmpbak/public/assets $final_path/public
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean temp directory
|
# Clean temp directory
|
||||||
ynh_secure_remove $tmp
|
|
||||||
ynh_secure_remove $tmpbak
|
ynh_secure_remove $tmpbak
|
||||||
|
|
||||||
# Set right permissions for the post-installation
|
# Set right permissions
|
||||||
chown -R $app: $final_path
|
chown -R $app: $final_path
|
||||||
chown -R $app:www-data $final_path/storage
|
chown -R $app:www-data $final_path/storage
|
||||||
chmod -R 0775 $final_path
|
chmod -R 775 $final_path
|
||||||
fi
|
|
||||||
|
|
||||||
# Perform migrations and clear cache
|
# Perform migrations and clear cache
|
||||||
pushd $final_path
|
pushd $final_path
|
||||||
ynh_composer_exec $app $php_version $final_path "update --prefer-dist --no-dev -a --with-all-dependencies"
|
exec_as $app ynh_composer_exec --phpversion=$php_version --workdir=$final_path \
|
||||||
|
--commands="update --prefer-dist --no-dev -a --with-all-dependencies"
|
||||||
exec_as $app php$php_version flarum migrate
|
exec_as $app php$php_version flarum migrate
|
||||||
exec_as $app php$php_version flarum cache:clear
|
exec_as $app php$php_version flarum cache:clear
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2
|
|
||||||
if [[ $project_version == "0.1.0-beta.7.2" ]]; then
|
|
||||||
curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install and activate the SSOwat auth extension
|
#=================================================
|
||||||
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
|
# FLARUM EXTENSIONS
|
||||||
# Configure SSOwat auth extension
|
#=================================================
|
||||||
ssowatdomain=$(</etc/yunohost/current_host)
|
|
||||||
sql_command="INSERT IGNORE INTO \`settings\` (\`key\`, \`value\`) VALUES ('tituspijean-auth-ssowat.domain', '$ssowatdomain'), ('tituspijean-auth-ssowat.onlyUse', '0');"
|
if ! exec_as $app php$php_version flarum info | grep -q "tituspijean-auth-ssowat" | grep -q $ssowat_version;
|
||||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
then
|
||||||
|
# Install and activate the SSOwat auth extension
|
||||||
|
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
|
||||||
|
# Configure SSOwat auth extension
|
||||||
|
ssowatdomain=$(</etc/yunohost/current_host)
|
||||||
|
sql_command="INSERT IGNORE INTO \`settings\` (\`key\`, \`value\`) VALUES ('tituspijean-auth-ssowat.domain', '$ssowatdomain'), ('tituspijean-auth-ssowat.onlyUse', '0');"
|
||||||
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||||
|
fi
|
||||||
|
|
||||||
# Install, activate and set language extensions
|
# Install, activate and set language extensions
|
||||||
case $language in
|
case $language in
|
||||||
|
@ -292,6 +262,9 @@ if [ $bazaar_extension -eq 1 ]; then
|
||||||
install_and_activate_extension $app $php_version $final_path $db_name "flagrow/bazaar" "flagrow-bazaar"
|
install_and_activate_extension $app $php_version $final_path $db_name "flagrow/bazaar" "flagrow-bazaar"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clear Flarum's cache
|
||||||
|
exec_as $app php$php_version flarum cache:clear
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -309,7 +282,7 @@ ynh_use_logrotate --non-append
|
||||||
# Set permissions on app files
|
# Set permissions on app files
|
||||||
chown -R $app: $final_path
|
chown -R $app: $final_path
|
||||||
chown -R $app:www-data $final_path/storage
|
chown -R $app:www-data $final_path/storage
|
||||||
chmod -R 0775 $final_path
|
chmod -R 775 $final_path
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP PERMISSIONS
|
# SETUP PERMISSIONS
|
||||||
|
|
Loading…
Reference in a new issue