mirror of
https://github.com/YunoHost-Apps/monica_ynh.git
synced 2024-09-03 19:46:23 +02:00
145 lines
5.5 KiB
Bash
Executable file
145 lines
5.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir" --keep=".env"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
|
|
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Updating $app's configuration files..." --weight=1
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# UPDATE PHP DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Updating php dependencies..."
|
|
|
|
ynh_secure_remove --file="$install_dir/vendor"
|
|
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$install_dir"
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
ynh_backup_if_checksum_is_different --file="$install_dir/.env"
|
|
|
|
ynh_add_config --template=".env" --destination="$install_dir/.env"
|
|
|
|
#==================================================
|
|
# FIX PHP VERSION
|
|
#==================================================
|
|
ynh_script_progression --message="Fixing php version in package.json..." --weight=1
|
|
|
|
ynh_replace_string --target_file="$install_dir/package.json" --match_string="php artisan lang:generate -vvv" --replace_string="php$phpversion artisan lang:generate -vvv"
|
|
|
|
#=================================================
|
|
# DEPLOYMENT
|
|
#=================================================
|
|
ynh_script_progression --message="Deploying..."
|
|
|
|
pushd "$install_dir"
|
|
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 monica:update --force
|
|
popd
|
|
|
|
if [ -f $install_dir/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="$install_dir/.env"
|
|
ynh_replace_string --match_string="mobile_key" --replace_string="$mobile_key" --target_file="$install_dir/.env"
|
|
else
|
|
pushd "$install_dir"
|
|
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="$install_dir/.env"
|
|
ynh_replace_string --match_string="mobile_key" --replace_string="$mobile_key" --target_file="$install_dir/.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="$install_dir/key.txt"
|
|
popd
|
|
fi
|
|
pushd "$install_dir"
|
|
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 "$install_dir"
|
|
# 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="$install_dir/.env"
|
|
|
|
chmod 400 "$install_dir/.env"
|
|
chown $app:$app "$install_dir/.env"
|
|
|
|
#==================================================
|
|
# FIX PHP VERSION
|
|
#==================================================
|
|
ynh_script_progression --message="Fixing PHP version in package.json..." --weight=1
|
|
|
|
ynh_replace_string --target_file="$install_dir/package.json" --match_string="php artisan lang:generate -vvv" --replace_string="php$phpversion artisan lang:generate -vvv"
|
|
|
|
#=================================================
|
|
# INSTALL THE CRON FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Setuping a cron..." --weight=1
|
|
|
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
|
|
|
chown root: "/etc/cron.d/$app"
|
|
chmod 644 "/etc/cron.d/$app"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|