diff --git a/conf/cron b/conf/cron new file mode 100644 index 0000000..6b49ccb --- /dev/null +++ b/conf/cron @@ -0,0 +1 @@ +* * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/artisan schedule:run \ No newline at end of file diff --git a/scripts/install b/scripts/install index deab0f4..e3575d1 100755 --- a/scripts/install +++ b/scripts/install @@ -28,6 +28,7 @@ language=$YNH_APP_ARG_LANGUAGE password=$YNH_APP_ARG_PASSWORD random_key=$(ynh_string_random --length=32) email=$(ynh_user_get_info --username=$admin --key="mail") +phpversion=$YNH_PHP_VERSION app=$YNH_APP_INSTANCE_NAME @@ -119,7 +120,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= ynh_script_progression --message="Installing composer dependencies..." -ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" --install_args="--ignore-platform-req=ext-redis" +ynh_exec_warn_less ynh_install_composer --install_args="--ignore-platform-req=ext-redis" chmod 750 "$final_path" chmod -R o-rwx "$final_path" @@ -130,43 +131,39 @@ chown -R $app:www-data "$final_path" #================================================= ynh_script_progression --message="Adding a configuration file..." +mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) +mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) + +ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id +ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key + ynh_add_config --template="../conf/.env" --destination="$final_path/.env" +chmod 400 "$final_path/.env" +chown $app:$app "$final_path/.env" #================================================= # DEPLOY #================================================= ynh_script_progression --message="Deploying..." -update-alternatives --set php /usr/bin/php$phpversion - pushd "$final_path" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH yarn install ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH yarn run production ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan setup:production --force --email=$email --password="$password" ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan passport:client --password -n > key.txt - mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) - mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) - ynh_replace_string --match_string="MOBILE_ID" --replace_string="$mobile_id" --target_file="$final_path/.env" - ynh_replace_string --match_string="MOBILE_KEY" --replace_string="$mobile_key" --target_file="$final_path/.env" - ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id - ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key ynh_secure_remove --file="$final_path/key.txt" ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan config:cache popd -chmod 400 "$final_path/.env" -chown $app:$app "$final_path/.env" - -update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} - #================================================= # INSTALL THE CRON FILE #================================================= ynh_script_progression --message="Installing the cron file..." -echo "* * * * * -u $app /usr/bin/php$phpversion $final_path/artisan schedule:run" > /tmp/cron$app -mv /tmp/cron$app /etc/cron.d/$app +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index 9d14886..762818c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -70,9 +70,8 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" -config="$final_path/.env" -chmod 400 "$config" -chown $app:$app "$config" +chmod 400 "$final_path/.env" +chown $app:$app "$final_path/.env" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index 3116acc..e14f693 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -31,18 +31,9 @@ email=$(ynh_user_get_info --username=$admin --key=mail) #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# CHECK VERSION NUMBER -#================================================= - -abort_if_up_to_date -# previous function is what defines 'version', more precisely the 'previous version' -previous_version="${version}" - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -88,7 +79,7 @@ then ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/.env" fi chmod 750 "$final_path" @@ -128,74 +119,25 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= ynh_script_progression --message="Updating php dependencies..." -ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="update" --install_args="--ignore-platform-req=ext-redis" +ynh_exec_warn_less ynh_composer_exec --install_args="--no-interaction --no-dev --ignore-platform-req=ext-redis" chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." - -config="$final_path/.env" -ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/.env "$config" - -ynh_add_config --template="../conf/.env" --destination="$config" - #================================================= # DEPLOYMENT #================================================= ynh_script_progression --message="Deploying..." -update-alternatives --set php /usr/bin/php$phpversion - pushd "$final_path" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH yarn install ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH yarn run production - ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan setup:production --force -popd - -if [ -f $final_path/storage/oauth-private.key ]; then - mobile_id=$(ynh_app_setting_get --app=$app --key=mobile_id) - mobile_key=$(ynh_app_setting_get --app=$app --key=mobile_key) - ynh_replace_string --match_string="MOBILE_ID" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="MOBILE_KEY" --replace_string="$mobile_key" --target_file="$config" -else - pushd "$final_path" - ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan passport:keys - ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan passport:client --password -n > key.txt - mobile_id=$( tail -2 key.txt | head -1 | cut -c 12- ) - mobile_key=$( tail -1 key.txt | cut -c 16- ) - ynh_replace_string --match_string="MOBILE_ID" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="MOBILE_KEY" --replace_string="$mobile_key" --target_file="$config" - ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id - ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key - ynh_secure_remove --file="$final_path/key.txt" - popd -fi -pushd "$final_path" + ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan monica:update --force ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan config:cache popd -if ynh_version_gt "2.15.0" "${previous_version}" ; then - ynh_script_progression --message="Upgrading for 2.15.0..." - pushd "$final_path" - ynh_exec_warn_less ynh_exec_as $app php$phpversion artisan monica:moveavatarstophotosdirectory - popd -fi - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config" - -chmod 400 "$config" -chown $app:$app "$config" - -update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/ynh_package_version b/scripts/ynh_package_version deleted file mode 100644 index f6b5fd1..0000000 --- a/scripts/ynh_package_version +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -read_json () { - sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" -} - -read_manifest () { - if [ -f '../manifest.json' ] ; then - read_json '../manifest.json' "$1" - else - read_json '../settings/manifest.json' "$1" - fi -} - -abort_if_up_to_date () { - version=$(read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" 'version' 2> /dev/null || echo '20160501-7') - last_version=$(read_manifest 'version') - if [ "${version}" = "${last_version}" ]; then - ynh_print_info "Up-to-date, nothing to do" - ynh_die "" 0 - fi -} - -ynh_version_gt () -{ - dpkg --compare-versions "$1" gt "$2" -}