1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monica_ynh.git synced 2024-09-03 19:46:23 +02:00
This commit is contained in:
ericgaspar 2022-01-01 23:38:40 +01:00
parent f3a47e938c
commit 298d90be72
4 changed files with 15 additions and 99 deletions

1
conf/cron Normal file
View file

@ -0,0 +1 @@
* * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/artisan schedule:run > /dev/null

View file

@ -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"

View file

@ -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

View file

@ -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