diff --git a/scripts/_common.sh b/scripts/_common.sh index a1c1d9e..24fbe97 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -38,34 +38,6 @@ exec_as() { # Composer helpers # -# Execute a composer command from a given directory -# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...] -exec_composer() { - local WORKDIR=$1 - shift 1 - - COMPOSER_HOME="${WORKDIR}/.composer" \ - # sudo /usr/bin/php7.2 "${WORKDIR}/composer.phar" $@ \ - /usr/bin/php7.2 "${WORKDIR}/composer.phar" $@ \ - -d "${WORKDIR}" --no-interaction -} - -# Install and initialize Composer in the given directory -# usage: init_composer DESTDIR [AS_USER] -init_composer() { - local DESTDIR=$1 - local AS_USER=${2:-admin} - - # install composer - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="${DESTDIR}/.composer" \ - sudo /usr/bin/php7.2 -- --quiet --install-dir="$DESTDIR" \ - || ynh_die "Unable to install Composer" - - # update dependencies to create composer.lock - exec_composer "$DESTDIR" install --no-dev --prefer-dist --no-scripts \ - || ynh_die "Unable to update firefly-iii core dependencies" -} sudo_path () { sudo env "PATH=$PATH" $@ diff --git a/scripts/backup b/scripts/backup index 69c295a..5eda3df 100755 --- a/scripts/backup +++ b/scripts/backup @@ -11,9 +11,14 @@ if [ ! -e _common.sh ]; then cp ../settings/scripts/_common.sh ./_common.sh chmod a+rx _common.sh fi + source _common.sh +source ynh_add_extra_apt_repos__3 +source ynh_install_php__3 +source ynh_composer source /usr/share/yunohost/helpers + #================================================= # MANAGE SCRIPT FAILURE #================================================= diff --git a/scripts/install b/scripts/install index cf31f87..80c5dfa 100755 --- a/scripts/install +++ b/scripts/install @@ -48,7 +48,6 @@ ynh_script_progression --message="Validating installation parameters..." --time final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -#mkdir $final_path # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -143,9 +142,9 @@ ynh_replace_string "yunoappurl" "$domain$path_url" "$final_path/.env" #init_composer $final_path $app -cd $final_path && php$phpversion artisan migrate:refresh --seed -cd $final_path && php$phpversion artisan firefly-iii:upgrade-database -cd $final_path && php$phpversion artisan passport:install +cd $final_path && php$phpversion artisan migrate:refresh --seed && cd $YNH_CWD +cd $final_path && php$phpversion artisan firefly-iii:upgrade-database && cd $YNH_CWD +cd $final_path && php$phpversion artisan passport:install && cd $YNH_CWD #================================================= diff --git a/scripts/restore b/scripts/restore index d8aafe4..7055b3a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -13,8 +13,12 @@ if [ ! -e _common.sh ]; then fi source _common.sh +source ynh_add_extra_apt_repos__3 +source ynh_install_php__3 +source ynh_composer source /usr/share/yunohost/helpers + #================================================= # MANAGE SCRIPT FAILURE #================================================= @@ -116,12 +120,27 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # SPECIFIC UPGRADE #================================================= -init_composer $final_path -cd $final_path && sudo /usr/bin/php$phpversion artisan migrate --env=production --force -cd $final_path && sudo /usr/bin/php$phpversion artisan cache:clear -cd $final_path && sudo /usr/bin/php$phpversion artisan firefly:upgrade-database -cd $final_path && sudo /usr/bin/php$phpversion artisan firefly:verify -cd $final_path && sudo /usr/bin/php$phpversion artisan passport:install + +# Install via composer +ynh_install_composer --phpversion="$phpversion" + +#cd $final_path && sudo /usr/bin/php$phpversion artisan migrate --env=production --force +#cd $final_path && sudo /usr/bin/php$phpversion artisan cache:clear +#cd $final_path && sudo /usr/bin/php$phpversion artisan firefly:upgrade-database +#cd $final_path && sudo /usr/bin/php$phpversion artisan firefly:verify +#cd $final_path && sudo /usr/bin/php$phpversion artisan passport:install + +cd $final_path && php$phpversion artisan migrate:refresh --seed && cd $YNH_CWD +cd $final_path && php$phpversion artisan firefly-iii:upgrade-database && cd $YNH_CWD +cd $final_path && php$phpversion artisan passport:install && cd $YNH_CWD + +#================================================= +# SETUP APPLICATION PERMISSIONS +#================================================= + +# Set right permissions +chown -R $app:$app $final_path +chmod -R 775 ${final_path}/storage #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index f16bc97..916782b 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -81,6 +81,13 @@ ynh_abort_if_errors # Normalize the URL path syntax path_url=$(ynh_normalize_url_path --path_url=$path_url) +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +ynh_script_progression --message="Installing dependencies..." --time --weight=1 +ynh_install_php --phpversion="$phpversion" --package="$pkg_dependencies" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -99,25 +106,61 @@ rm -Rf "$final_path" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" + +#================================================= +# SPECIFIC SETUP +#================================================= + +# Install via composer ynh_install_composer --phpversion="$phpversion" -cd $final_path && php$phpversion artisan migrate:refresh --seed -cd $final_path && php$phpversion artisan firefly-iii:upgrade-database -cd $final_path && php$phpversion artisan passport:install +# create a user +email=$(ynh_user_get_info $admin 'mail') -rm -rf "$final_path/bootstrap/cache/*" +# setup application config +sudo cp ../conf/.env $final_path/.env -cd $final_path && php$phpversion artisan cache:clear -cd $final_path && php$phpversion artisan migrate --seed -cd $final_path && php$phpversion artisan firefly-iii:upgrade-database -cd $final_path && php$phpversion artisan passport:install -cd $final_path && php$phpversion artisan cache:clear +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_replace_string "random_key" "$random_key" "$final_path/.env" +ynh_replace_string "yunouser" "$db_name" "$final_path/.env" +ynh_replace_string "yunopass" "$db_pwd" "$final_path/.env" +ynh_replace_string "yunobase" "$db_name" "$final_path/.env" +ynh_replace_string "yunomail" "$email" "$final_path/.env" +ynh_replace_string "yunodomain" "$domain" "$final_path/.env" +ynh_replace_string "yunoappurl" "$domain$path_url" "$final_path/.env" + +#Run artisan stuff + +cd $final_path && php$phpversion artisan migrate:refresh --seed && cd $YNH_CWD +cd $final_path && php$phpversion artisan firefly-iii:upgrade-database && cd $YNH_CWD +cd $final_path && php$phpversion artisan passport:install && cd $YNH_CWD + +#rm -rf "$final_path/bootstrap/cache/*" + +#cd $final_path && php$phpversion artisan cache:clear +#cd $final_path && php$phpversion artisan migrate --seed +#cd $final_path && php$phpversion artisan firefly-iii:upgrade-database +#cd $final_path && php$phpversion artisan passport:install +#cd $final_path && php$phpversion artisan cache:clear + +# Verify the checksum and backup the file if it's different +ynh_backup_if_checksum_is_different --file="$final_path/.env" +# Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum --file="$final_path/.env" cp -a "$tmpdir/storage/upload/" "$final_path/storage/upload/" cp -a "$tmpdir/storage/export/" "$final_path/storage/export/" +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + # Set right permissions -chown -R $app:$app $final_path +chown -R $app: $final_path chmod -R 775 ${final_path}/storage #remove tmp dir @@ -131,13 +174,6 @@ ynh_script_progression --message="Upgrading nginx web server configuration..." - # Create a dedicated nginx config ynh_add_nginx_config -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 - -ynh_install_app_dependencies $pkg_dependencies - #================================================= # CREATE DEDICATED USER #================================================= @@ -172,50 +208,6 @@ ynh_script_progression --message="Upgrading logrotate configuration..." --time - # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# SPECIFIC UPGRADE -#================================================= -# Install via composer -ynh_install_composer --phpversion="$phpversion" - -# Get the admin email -email=$(ynh_user_get_info --username=$admin --key='mail') - -# setup application config -sudo cp ../conf/.env $final_path/.env -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_replace_string --match_string"random_key" --replace_string="$random_key" --file="$final_path/.env" -ynh_replace_string --match_string"yunouser" --replace_string="$db_name" --file="$final_path/.env" -ynh_replace_string --match_string"yunopass" --replace_string="$db_pwd" --file="$final_path/.env" -ynh_replace_string --match_string"yunobase" --replace_string="$db_name" --file="$final_path/.env" -ynh_replace_string --match_string"yunomail" --replace_string="$email" --file="$final_path/.env" -ynh_replace_string --match_string"yunodomain" --replace_string="$domain" --file="$final_path/.env" - -#init_composer $final_path - -cd $final_path && php$phpversion artisan migrate --env=production --force -cd $final_path && php$phpversion artisan cache:clear -cd $final_path && php$phpversion artisan firefly:upgrade-database -cd $final_path && php$phpversion artisan firefly:verify -cd $final_path && php$phpversion artisan passport:install - -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different --file="$final_path/.env" -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/.env" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set right permissions -chown -R $app: $final_path -chmod -R 775 ${final_path}/storage - #================================================= # SETUP SSOWAT #=================================================