1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jupyterlab_ynh.git synced 2024-09-03 19:26:35 +02:00
jupyterlab_ynh/scripts/upgrade

205 lines
7.4 KiB
Text
Raw Normal View History

2019-01-20 12:36:14 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-08-14 00:07:10 +02:00
source _common.sh
2019-01-20 12:36:14 +01:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=3
2019-01-20 12:36:14 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-08-14 00:07:10 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
port_hub=$(ynh_app_setting_get --app=$app --key=port_hub)
port_http_proxy=$(ynh_app_setting_get --app=$app --key=port_http_proxy)
enable_terminal=$(ynh_app_setting_get --app=$app --key=enable_terminal)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2019-08-14 00:07:10 +02:00
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/opt/$app
mkdir -p $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
2019-01-20 12:36:14 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=48
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
2019-01-20 12:36:14 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
2019-08-14 00:07:10 +02:00
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Stopping a systemd service..."
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
ynh_systemd_action --service_name=$app --action="stop"
2019-01-20 12:36:14 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..."
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
# Create a dedicated nginx config
2019-01-20 12:36:14 +01:00
ynh_add_nginx_config
#=================================================
2019-08-14 00:07:10 +02:00
# UPGRADE DEPENDENCIES
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=83
2019-08-14 00:07:10 +02:00
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=8
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
npm install -g configurable-http-proxy
pip3 install pipenv
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=160
2019-08-14 00:07:10 +02:00
# Download, check integrity, uncompress and patch the source from app.src
source ./upgrade.d/upgrade.sh
mkdir -p $final_path
pushd $final_path
2019-09-27 20:55:18 +02:00
PIPENV_VENV_IN_PROJECT="enabled" PIPENV_SKIP_LOCK=true ynh_exec_warn_less pipenv install jupyterlab==$jupyterlab_version jupyterhub notebook jupyterhub-ldapauthenticator --three
2019-08-14 00:07:10 +02:00
ynh_exec_warn_less pipenv run jupyterhub upgrade-db
popd
fi
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
# SPECIFIC UPGRADE
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
# STORE THE CONFIG FILE CHECKSUM
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
ynh_backup_if_checksum_is_different --file="$final_path/config/jupyterhub_config.py"
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
cp -f ../conf/jupyterhub_config.py $final_path/config/jupyterhub_config.py
ynh_replace_string --match_string="__URL__" --replace_string="https://$domain" --target_file="$final_path/config/jupyterhub_config.py"
ynh_replace_string --match_string="__PATH__" --replace_string="${path_url%/}" --target_file="$final_path/config/jupyterhub_config.py"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config/jupyterhub_config.py"
ynh_replace_string --match_string="__PORT_HUB__" --replace_string="$port_hub" --target_file="$final_path/config/jupyterhub_config.py"
ynh_replace_string --match_string="__PORT_HTTP_PROXY__" --replace_string="$port_http_proxy" --target_file="$final_path/config/jupyterhub_config.py"
ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$final_path/config/jupyterhub_config.py"
ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$final_path/config/jupyterhub_config.py"
2019-01-26 16:40:36 +01:00
2019-08-14 00:07:10 +02:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/config/jupyterhub_config.py"
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
ynh_backup_if_checksum_is_different --file="$final_path/config/jupyter_notebook_config.py"
cp -f ../conf/jupyter_notebook_config.py $final_path/config/jupyter_notebook_config.py
ynh_replace_string --match_string="__ENABLE_TERMINAL__" --replace_string="$enable_terminal" --target_file="$final_path/config/jupyter_notebook_config.py"
ynh_store_file_checksum --file="$final_path/config/jupyter_notebook_config.py"
2019-01-20 12:36:14 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Upgrading systemd configuration..."
2019-01-20 12:36:14 +01:00
# Create a dedicated systemd config
2019-08-14 00:07:10 +02:00
ynh_replace_string --match_string="__NODE_PATH__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
ynh_add_systemd_config
2019-01-20 12:36:14 +01:00
#=================================================
# GENERIC FINALIZATION
2019-08-14 00:07:10 +02:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
chown -R $admin: $final_path/.venv/share
2019-01-20 12:36:14 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Upgrading SSOwat configuration..."
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
2019-01-20 12:36:14 +01:00
fi
#=================================================
2019-08-14 00:07:10 +02:00
# START SYSTEMD SERVICE
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Starting a systemd service..."
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
ynh_systemd_action --service_name=$app --action="start" --line_match="JupyterHub is now running at" --log_path="systemd"
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
# RELOAD NGINX
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Reloading nginx web server..."
2019-01-20 12:36:14 +01:00
2019-08-14 00:07:10 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-14 00:07:10 +02:00
# END OF SCRIPT
2019-01-20 12:36:14 +01:00
#=================================================
2019-08-18 00:02:04 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last