mirror of
https://github.com/YunoHost-Apps/ghost_ynh.git
synced 2024-09-03 19:16:02 +02:00
168 lines
5.8 KiB
Bash
168 lines
5.8 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
# If db_name doesn't exist, create it
|
|
if [ -z "$db_name" ]; then
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
fi
|
|
|
|
# Make sure the .config directory belongs to $app:$app
|
|
if [[ ! -d "$install_dir/.config" ]]; then
|
|
mkdir $install_dir/.config
|
|
chown $app:$app $install_dir/.config
|
|
elif [[ $(stat -c "%U:%G" $install_dir/.config) != "$app:$app" ]]; then
|
|
chown -R $app:$app $install_dir/.config
|
|
fi
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action=stop --log_path="systemd" --line_match="Ghost has shut down" --timeout=60
|
|
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Updating NodeJS..." --weight=1
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
|
|
|
|
#=================================================
|
|
# UPGRADE
|
|
#=================================================
|
|
|
|
# Up to v5.26.4~ynh1, we were downloading the source code and building the app by ourselves
|
|
# that was a mess to maintain, let's move away from that
|
|
if ynh_compare_current_package_version --comparison le --version 5.26.4~ynh1
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading from older packaging of $app..."
|
|
|
|
# Create a temporary directory
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
# Backup the content folder to the temp dir
|
|
if [ -f "$install_dir/config.production.json" ]
|
|
then
|
|
# Old versions of Ghost stored it here
|
|
cp -ar "$install_dir/content" "$tmpdir/content"
|
|
else
|
|
# New versions of Ghost store it here
|
|
cp -ar "$install_dir/ghost/core/content" "$tmpdir/content"
|
|
fi
|
|
|
|
# Remove the app directory securely
|
|
ynh_secure_remove --file=$install_dir
|
|
|
|
# Recreate it
|
|
mkdir -p $install_dir
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
pushd $install_dir
|
|
ynh_use_nodejs
|
|
ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install npm@latest
|
|
ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ghost-cli@latest
|
|
ynh_exec_as $app $ynh_node_load_PATH $install_dir/node_modules/ghost-cli/bin/ghost install $(ynh_app_upstream_version) \
|
|
--no-prompt --no-setup-systemd --no-start \
|
|
--dir ghost --no-setup-linux-user \
|
|
--no-setup-nginx --no-setup-ssl --url https://$domain$path --port $port \
|
|
--db mysql --dbhost 127.0.0.1 --dbuser $db_user --dbpass $db_pwd --dbname $db_name \
|
|
--mail SMTP --mailhost 127.0.0.1 --mailport 465
|
|
popd
|
|
|
|
# Copy content folder back to the install_dir
|
|
cp -ar "$tmpdir/content" "${install_dir}/ghost/content"
|
|
|
|
# Remove the tmp directory securely
|
|
ynh_secure_remove --file="$tmpdir"
|
|
|
|
else
|
|
|
|
# Upgrade Ghost CLI
|
|
pushd $install_dir
|
|
ynh_use_nodejs
|
|
ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install npm@latest
|
|
ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ghost-cli@latest
|
|
popd
|
|
|
|
pushd $install_dir/ghost
|
|
# Make sure the app does not expect to manage its own process
|
|
ynh_exec_as $app $ynh_node_load_PATH $install_dir/node_modules/ghost-cli/bin/ghost config --process local
|
|
# Upgrade Ghost itself
|
|
ynh_exec_as $app $ynh_node_load_PATH $install_dir/node_modules/ghost-cli/bin/ghost update $(ynh_app_upstream_version) \
|
|
--no-prompt --no-auto-rollback --no-restart --force
|
|
popd
|
|
|
|
fi
|
|
|
|
# Make sure the configuration is correct
|
|
pushd $install_dir/ghost
|
|
ynh_exec_as $app $ynh_node_load_PATH $install_dir/node_modules/ghost-cli/bin/ghost config \
|
|
--port $port --process local \
|
|
--url https://$domain$path \
|
|
--mail SMTP --mailuser noreply@$domain --mailpass $mail_pwd --mailhost 127.0.0.1 --mailport 25
|
|
popd
|
|
|
|
config_file=$install_dir/ghost/config.production.json
|
|
cat <<< $(jq -r '.database.connection.host = "127.0.0.1"' $config_file) > $config_file
|
|
cat <<< $(jq -r '.mail.options.host = "127.0.0.1"' $config_file) > $config_file
|
|
cat <<< $(jq -r '.mail.options.ignoreTLS = true' $config_file) > $config_file
|
|
|
|
if [ ! -s "$config_file" ]; then
|
|
ynh_die --message="Something went wrong while setting up the configuration file: it ended up empty."
|
|
fi
|
|
|
|
# Cleanup cache
|
|
ynh_secure_remove --file="$install_dir/.cache/yarn"
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --logfile="$install_dir/ghost/content/logs" --non-append
|
|
|
|
yunohost service add $app --description="$app daemon for Ghost" --log="$install_dir/ghost/contents/logs"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action=start --log_path="systemd" --line_match="Ghost booted" --timeout=60
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|