diff --git a/manifest.json b/manifest.json index 3e66647..8c51d36 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "Open source asset management" }, - "version": "4.6.15~ynh1", + "version": "4.6.15~ynh2", "url": "https://snipeitapp.com/", "license": "MIT", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 2d0da4d..25f54e4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -29,37 +29,53 @@ exec_as() { fi } - -# Execute a composer command from a given directory -# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...] -exec_composer() { - local AS_USER=$1 - local WORKDIR=$2 - shift 2 - - exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \ - php "${WORKDIR}/composer.phar" $@ \ - -d "${WORKDIR}" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# usage: init_composer destdir -init_composer() { - local AS_USER=$1 - local WORKDIR=$2 - - # install composer - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="${WORKDIR}/.composer" \ - php -- --quiet --install-dir="$WORKDIR" \ - || ynh_die "Unable to install Composer" - - - # update dependencies to create composer.lock - exec_composer "$AS_USER" "$WORKDIR" install --no-dev --prefer-source \ - || ynh_die "Unable to update core dependencies with Composer" -} - #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +# Execute a command with Composer +# +# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" +# | 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=vwc + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) + local phpversion + local workdir + local commands + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + 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] +# | 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 phpversion + local workdir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + curl -sS https://getcomposer.org/installer \ + | 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." +} \ No newline at end of file diff --git a/scripts/install b/scripts/install index 5694509..7383cb3 100755 --- a/scripts/install +++ b/scripts/install @@ -161,15 +161,15 @@ ynh_script_progression --message="Configuring php-fpm..." --time --weight=1 # Create a dedicated php-fpm config ynh_add_fpm_config -( cd $final_path && curl -sS https://getcomposer.org/installer | php ) -( cd $final_path && /usr/bin/php composer.phar install --no-dev --prefer-source ) - #================================================= # SPECIFIC SETUP #================================================= -# ... +# INSTALL AND INITIALIZE COMPOSER #================================================= +ynh_script_progression --message="Installing composer..." --time --weight=1 +# Install composer +ynh_install_composer #================================================= # MODIFY A CONFIG FILE diff --git a/scripts/upgrade b/scripts/upgrade index 41ea18d..c373be5 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -136,9 +136,15 @@ ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE #================================================= +# INSTALL AND INITIALIZE COMPOSER +#================================================= +ynh_script_progression --message="Installing composer..." --time --weight=1 + +# Install composer +ynh_install_composer + +ynh_exec_warn_less ynh_composer_exec --commands=\"dump-autoload\" -( cd $final_path && sudo /usr/bin/php composer.phar install --no-dev --prefer-source ) -( cd $final_path && sudo /usr/bin/php composer.phar dump-autoload ) ( cd $final_path && sudo /usr/bin/php artisan migrate -n ) ( cd $final_path && sudo /usr/bin/php artisan config:clear -n ) ( cd $final_path && sudo /usr/bin/php artisan config:cache -n )