#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source ynh_install_go source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME 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) password=$(ynh_app_setting_get --app=$app --key=password) final_path=$(ynh_app_setting_get --app=$app --key=final_path) group_name=$(ynh_app_setting_get --app=$app --key=group_name) group_description=$(ynh_app_setting_get --app=$app --key=group_description) port=$(ynh_app_setting_get --app=$app --key=port) ldap_port=$(ynh_app_setting_get --app=$app --key=ldap_port) key=$(ynh_app_setting_get --app=$app --key=key) turn_port=$(ynh_app_setting_get --app=$app --key=turn_port) datadir=$(ynh_app_setting_get --app=$app --key=datadir) if ynh_compare_current_package_version --comparison le --version 0.3.5~ynh3 then ynh_die --message="Please, you need to remove the app and reinstall it" fi #================================================= # CHECK VERSION #================================================= ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_systemd_action --service_name=${app}_ldap --action="stop" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If open, close direct access to $port in firewall if yunohost firewall list | grep -q "\- $port$" then ynh_exec_warn_less yunohost firewall disallow TCP $port fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then final_path=/var/www/$app mkdir -p $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # If ldap_port doesn't exist, create it if [ -z "$ldap_port" ]; then ldap_port=$(ynh_find_port --port=$(($port + 1))) ynh_app_setting_set --app=$app --key=port --value=$ldap_port fi # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all ynh_app_setting_delete --app=$app --key=is_public fi # We remove the old admin/password file if present if [ -f "$final_path/data/passwd" ] ; then ynh_secure_remove --file="$final_path/data/passwd" fi # For version 0.6~ynh1 and before if [[ ! -d "$final_path/live" ]] then tempdir="$(mktemp -d)" mv $final_path $tempdir mkdir -p "$final_path/live" mv $tempdir/$app/galene "$final_path/live/" mv $tempdir/$app/data/ "$final_path/live/" mv $tempdir/$app/static/ "$final_path/live/" ynh_secure_remove --file="$tempdir" fi #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." --weight=2 ynh_setup_source --dest_dir="$final_path/build" ynh_setup_source --dest_dir="$final_path/build_ldap" --source_id="ldap" mkdir -p "$final_path/live/data" mkdir -p "$final_path/live_ldap/data" ynh_secure_remove --file="$final_path/live/static/" cp -r "$final_path/build/static/" "$final_path/live/" ynh_replace_string --match_string="
Galène
" --replace_string="
Galène
" --target_file="$final_path/live/static/galene.html" chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE #================================================= # BUILD APP #================================================= ynh_script_progression --message="Building app..." --weight=1 if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_exec_warn_less ynh_install_go --go_version=$go_version ynh_use_go pushd $final_path/build/ ynh_exec_as $app CGO_ENABLED=0 $ynh_go build -ldflags='-s -w' -o $final_path/live/ popd pushd $final_path/build_ldap/ ynh_exec_as $app CGO_ENABLED=0 $ynh_go build -ldflags='-s -w' -o $final_path/live_ldap/ popd ynh_remove_go ynh_secure_remove --file="$final_path/build/" ynh_secure_remove --file="$final_path/build_ldap/" ynh_secure_remove --file="$final_path/.cache/" ynh_secure_remove --file="$final_path/go/" ynh_secure_remove --file="$final_path/.go-version" fi #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=2 # Configure Galène ynh_add_config --template="../conf/config.json" --destination="$final_path/live/data/config.json" chmod 400 "$final_path/live/data/config.json" chown $app:$app "$final_path/live/data/config.json" # Configure Galène LDAP # If key doesn't exist, create it if [ -z "$key" ]; then key=$(jose jwk gen -i '{"kty":"oct","alg":"HS256"}') ynh_app_setting_set --app=$app --key=key --value=$key fi ynh_add_config --template="../conf/galene-ldap.json" --destination="$final_path/live_ldap/data/galene-ldap.json" chmod 400 "$final_path/live_ldap/data/galene-ldap.json" chown $app:$app "$final_path/live_ldap/data/galene-ldap.json" # Create a group name config ynh_add_config --template="../conf/groupname.json" --destination="$datadir/groups/$group_name.json" chmod 400 "$datadir/groups/$group_name.json" chown $app:$app "$datadir/groups/$group_name.json" # Create a group name authenticated on LDAP ynh_add_config --template="../conf/groupname-ldap.json" --destination="$datadir/groups/YunoHost_Users.json" chmod 400 "$datadir/groups/YunoHost_Users.json" chown $app:$app "$datadir/groups/YunoHost_Users.json" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 public_ip4="$(curl -s ip.yunohost.org)" || true # Create a dedicated systemd config ynh_add_systemd_config ynh_add_systemd_config --service=${app}_ldap --template="ldap.service" #================================================= # GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="Videoconferencing server" --needs_exposed_ports="$turn_port" yunohost service add ${app}_ldap --description="LDAP integration for the videoconferencing server" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" ynh_systemd_action --service_name=${app}_ldap --action="start" --log_path="systemd" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=2 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last