From 298d90be72330cc39843cda4dcf18a89f83a8ad8 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 1 Jan 2022 23:38:40 +0100 Subject: [PATCH] fix --- conf/cron | 1 + scripts/_common.sh | 2 +- scripts/install | 15 +++----- scripts/upgrade | 96 ++++------------------------------------------ 4 files changed, 15 insertions(+), 99 deletions(-) create mode 100644 conf/cron diff --git a/conf/cron b/conf/cron new file mode 100644 index 0000000..cf6c9fb --- /dev/null +++ b/conf/cron @@ -0,0 +1 @@ +* * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/artisan schedule:run > /dev/null diff --git a/scripts/_common.sh b/scripts/_common.sh index 60c2daf..9f6ae51 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -YNH_COMPOSER_VERSION="2.0.11" +YNH_COMPOSER_VERSION="2.2.3" YNH_PHP_VERSION="7.4" diff --git a/scripts/install b/scripts/install index d0c7ebe..8db2e96 100644 --- a/scripts/install +++ b/scripts/install @@ -26,7 +26,7 @@ admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE random_key=$(ynh_string_random --length=32) -email=$(ynh_user_get_info $admin 'mail') +email=$(ynh_user_get_info --username=$admin --key=mail) password=$(ynh_string_random --length=10) dav_support=$YNH_APP_ARG_DAV_SUPPORT signup=$YNH_APP_ARG_SIGNUP @@ -100,11 +100,6 @@ 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" -# git clone https://github.com/monicahq/monica.git $final_path -# pushd "$final_path" -# git checkout tags/$version -# popd - chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -155,7 +150,6 @@ else sign="Yes" fi - # Enable or disable two factor authentication support for users if [ $two_factor -eq 1 ] then @@ -166,7 +160,7 @@ else twof="No" fi -ynh_add_config --template="../conf/.env" --destination="$final_path/.env" +ynh_add_config --template="../conf/.env" --destination="$config" #================================================= # INSTALL COMPOSER DEPENDENCIES @@ -213,8 +207,9 @@ chown $app:$app "$final_path/.env" #================================================= ynh_script_progression --message="Installing the cron file..." -echo "* * * * * -u $app /usr/bin/php$phpversion $final_path/artisan schedule:run" > /tmp/cron$app -mv -f /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/upgrade b/scripts/upgrade index 8ca2d5f..1b5423a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,12 +22,14 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) random_key=$(ynh_app_setting_get --app=$app --key=random_key) email=$(ynh_user_get_info --username=$admin --key=mail) dav_support=$(ynh_app_setting_get --app=$app --key=dav_support) signup=$(ynh_app_setting_get --app=$app --key=signup) two_factor=$(ynh_app_setting_get --app=$app --key=two_factor) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) version=$(curl -s https://api.github.com/repos/monicahq/monica/releases/latest | grep 'tag_name' | cut -d\" -f4) #================================================= @@ -128,7 +130,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" @@ -159,7 +161,6 @@ ynh_script_progression --message="Upgrading PHP-FPM configuration..." # Create a dedicated PHP-FPM config ynh_add_fpm_config --usage=low --footprint=low -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE @@ -168,46 +169,7 @@ 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" -ynh_install_composer --commands="update" - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." - -config="$final_path/.env" -db_user=$db_name - -# Enable or disable DAV support for users -if [ $dav_support -eq 0 ] -then - dav_boolean="false" - dav="Yes" -else - dav_boolean="true" - dav="No" -fi -# Enable or disable signup for public users -if [ $signup -eq 1 ] -then - sign_boolean="false" - sign="No" -else - sign_boolean="true" - sign="Yes" -fi -# Enable or disable two factor authentication support for users -if [ $two_factor -eq 1 ] -then - twof_boolean="true" - twof="Yes" -else - twof_boolean="false" - twof="No" -fi - -ynh_add_config --template="../conf/.env" --destination="$config" +ynh_install_composer --install_args="--no-interaction --no-dev" #================================================= # DEPLOYMENT @@ -223,56 +185,14 @@ pushd "$final_path" ynh_exec_warn_less php$phpversion artisan monica:update --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) - if [ -z $(ynh_app_setting_get --app=$app --key=private_key) ]; then - private_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $final_path/storage/oauth-private.key) - public_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $final_path/storage/oauth-public.key) - ynh_app_setting_set --app=$app --key=private_key --value=$private_key - ynh_app_setting_set --app=$app --key=private_key --value=$public_key - fi - ynh_replace_string --match_string="_IDENTITY_" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="_KEY_" --replace_string="$mobile_key" --target_file="$config" -else - pushd "$final_path" - php$phpversion artisan passport:keys - 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- ) - mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) - private_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' storage/oauth-private.key) - public_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' storage/oauth-public.key) - ynh_replace_string --match_string="_IDENTITY_" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="_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_app_setting_set --app=$app --key=private_key --value=$private_key - ynh_app_setting_set --app=$app --key=private_key --value=$public_key - rm -f key.txt - php$phpversion artisan config:clear - popd -fi - -if ynh_version_gt "2.15.0" "${previous_version}" ; then - ynh_script_progression --message="Upgrading for 2.15.0..." - pushd "$final_path" - php$phpversion artisan monica:moveavatarstophotosdirectory - popd -fi - -update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} - -chmod 400 "$config" -chown $app:$app "$config" - #================================================= # INSTALL THE CRON FILE #================================================= -ynh_script_progression --message="Installing the cron file..." +ynh_script_progression --message="Setuping a cron..." -echo "* * * * * -u $app /usr/bin/php$phpversion $final_path/artisan schedule:run" > /tmp/cron$app -mv -f /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