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}"
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
# 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: -c, --commands - Commands to execute.
|
||||
ynh_composer_exec () {
|
||||
# Declare an array to define the options of this helper.
|
||||
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 phpversion
|
||||
local workdir
|
||||
|
@ -18,32 +20,36 @@ ynh_composer_exec () {
|
|||
workdir="${workdir:-$final_path}"
|
||||
phpversion="${phpversion:-7.0}"
|
||||
|
||||
COMPOSER_HOME="$workdir/.composer" \
|
||||
exec_as $user php${phpversion} "$workdir/composer.phar" $commands \
|
||||
exec_as $user COMPOSER_HOME="$workdir/.composer" \
|
||||
php${phpversion} "$workdir/composer.phar" $commands \
|
||||
-d "$workdir" --quiet --no-interaction
|
||||
}
|
||||
|
||||
# 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.
|
||||
ynh_install_composer () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=vw
|
||||
declare -Ar args_array=( [v]=phpversion= [w]=workdir= )
|
||||
local legacy_args=uvw
|
||||
declare -Ar args_array=( [u]=user= [v]=phpversion= [w]=workdir= )
|
||||
local user
|
||||
local phpversion
|
||||
local workdir
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
user="${user:-root}"
|
||||
workdir="${workdir:-$final_path}"
|
||||
phpversion="${phpversion:-7.0}"
|
||||
|
||||
curl -sS https://getcomposer.org/installer \
|
||||
| COMPOSER_HOME="$workdir/.composer" \
|
||||
exec_as $app php${phpversion} -- --quiet --install-dir="$workdir" \
|
||||
| exec_as $user COMPOSER_HOME="$workdir/.composer" \
|
||||
php${phpversion} -- --quiet --install-dir="$workdir" \
|
||||
|| ynh_die "Unable to install Composer."
|
||||
|
||||
# update dependencies to create composer.lock
|
||||
#ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \
|
||||
# || ynh_die "Unable to update core dependencies with Composer."
|
||||
ynh_composer_exec --user=$app --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \
|
||||
|| 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
|
||||
#=================================================
|
||||
|
||||
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
|
||||
ynh_abort_if_errors
|
||||
|
||||
|
@ -99,49 +103,6 @@ ynh_print_info --message="Installing 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
|
||||
#=================================================
|
||||
|
@ -151,6 +112,19 @@ ynh_app_setting_set $app db_name $db_name
|
|||
ynh_mysql_setup_db $db_name $db_name
|
||||
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
|
||||
#=================================================
|
||||
|
@ -165,6 +139,16 @@ fi
|
|||
# Create a dedicated 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
|
||||
#=================================================
|
||||
|
@ -172,6 +156,18 @@ ynh_add_nginx_config
|
|||
# Create a dedicated php-fpm config
|
||||
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
|
||||
#=================================================
|
||||
|
@ -235,7 +231,6 @@ sql_command="REPLACE INTO \`settings\` (\`key\`, \`value\`) VALUES
|
|||
('mail_port', '587');"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
|
||||
|
||||
# Install and activate the SSOwat auth extension
|
||||
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"
|
||||
|
@ -262,7 +257,8 @@ esac
|
|||
|
||||
if [ $bazaar_extension -eq 1 ]; then
|
||||
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
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -88,10 +88,6 @@ if [ ! -z "$protected_uris" ]; then
|
|||
ynh_app_setting_delete --app=$app --key=protected_uris
|
||||
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
|
||||
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
|
||||
#=================================================
|
||||
# COMPOSER UPGRADE
|
||||
# COMPOSER AND FLARUM UPGRADE
|
||||
#=================================================
|
||||
|
||||
if ! type "$final_path/composer.phar" > /dev/null; then
|
||||
ynh_install_composer $php_version $final_path
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# FLARUM UPGRADE
|
||||
#=================================================
|
||||
|
||||
if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo true) ]]; then
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
||||
|
||||
# Backing up the app directory
|
||||
tmpbak="/tmp/${app}backup"
|
||||
|
@ -197,38 +187,15 @@ if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo
|
|||
# Deleting current app directory
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
# Create working directory
|
||||
mkdir -p "$final_path/.composer"
|
||||
chown -R $app:www-data $final_path
|
||||
chmod -R 0775 $final_path
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
|
||||
#=================================================
|
||||
# COMPOSER INSTALLATION
|
||||
#=================================================
|
||||
# Install Composer and Flarum
|
||||
ynh_install_composer --user=$app --phpversion=$php_version --workdir=$final_path
|
||||
|
||||
ynh_script_progression --message="Installing Composer..." --time --weight=1
|
||||
ynh_install_composer $php_version $final_path
|
||||
# Copy config.php back into Flarum
|
||||
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
|
||||
if [ -d $tmpbak/assets ]; then
|
||||
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
|
||||
cp -Rf $tmpbak/public/assets $final_path/public
|
||||
fi
|
||||
|
||||
# Clean temp directory
|
||||
ynh_secure_remove $tmp
|
||||
ynh_secure_remove $tmpbak
|
||||
|
||||
# Set right permissions for the post-installation
|
||||
# Set right permissions
|
||||
chown -R $app: $final_path
|
||||
chown -R $app:www-data $final_path/storage
|
||||
chmod -R 0775 $final_path
|
||||
fi
|
||||
chmod -R 775 $final_path
|
||||
|
||||
# Perform migrations and clear cache
|
||||
pushd $final_path
|
||||
ynh_composer_exec $app $php_version $final_path "update --prefer-dist --no-dev -a --with-all-dependencies"
|
||||
# Perform migrations and clear cache
|
||||
pushd $final_path
|
||||
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 cache:clear
|
||||
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
|
||||
popd
|
||||
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"
|
||||
# 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
|
||||
#=================================================
|
||||
# FLARUM EXTENSIONS
|
||||
#=================================================
|
||||
|
||||
if ! exec_as $app php$php_version flarum info | grep -q "tituspijean-auth-ssowat" | grep -q $ssowat_version;
|
||||
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
|
||||
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"
|
||||
fi
|
||||
|
||||
# Clear Flarum's cache
|
||||
exec_as $app php$php_version flarum cache:clear
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
|
@ -309,7 +282,7 @@ ynh_use_logrotate --non-append
|
|||
# Set permissions on app files
|
||||
chown -R $app: $final_path
|
||||
chown -R $app:www-data $final_path/storage
|
||||
chmod -R 0775 $final_path
|
||||
chmod -R 775 $final_path
|
||||
|
||||
#=================================================
|
||||
# SETUP PERMISSIONS
|
||||
|
|
Loading…
Reference in a new issue