2021-01-09 12:31:07 +01:00
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2023-03-10 07:59:41 +01:00
password=$YNH_APP_ARG_PASSWORD
2024-08-30 22:56:31 +02:00
ynh_app_setting_set --key=password --value="$password"
2021-01-09 12:31:07 +01:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Configuring firewall..."
2021-01-13 21:58:03 +01:00
2021-05-26 19:08:05 +02:00
# Reserve UDP Port range 49152:65535
2024-08-30 22:56:31 +02:00
ynh_hide_warnings yunohost firewall allow UDP -4 49152:65535
2021-01-09 12:31:07 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Setting up source files..."
2021-01-09 12:31:07 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2023-03-10 07:59:41 +01:00
ynh_setup_source --dest_dir="$install_dir/build"
ynh_setup_source --dest_dir="$install_dir/build_ldap" --source_id="ldap"
mkdir -p "$install_dir/live/data"
mkdir -p "$install_dir/live_ldap/data"
2023-03-19 22:27:19 +01:00
2023-03-10 07:59:41 +01:00
cp -r "$install_dir/build/static/" "$install_dir/live/"
2024-08-30 22:56:31 +02:00
ynh_replace --match="<div class=\"galene-header\">Galène</div>" --replace="<div class=\"galene-header\" onclick=\"location.href=window.location.origin\" style=\"cursor:pointer\">Galène</div>" --file="$install_dir/live/static/galene.html"
2021-06-02 09:36:30 +02:00
2024-08-30 22:56:31 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir"
2022-10-14 09:13:16 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# BUILD APP
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Building app..."
2022-10-14 09:13:16 +02:00
2024-08-30 22:56:31 +02:00
ynh_go_install
2023-03-19 22:27:19 +01:00
pushd $install_dir/build/galene-password-generator/
2024-08-30 22:56:31 +02:00
ynh_hide_warnings ynh_exec_as_app CGO_ENABLED=0 go build -o $install_dir/
2023-03-19 22:27:19 +01:00
popd
2023-03-10 07:59:41 +01:00
pushd $install_dir/build/
2024-08-30 22:56:31 +02:00
ynh_hide_warnings ynh_exec_as_app CGO_ENABLED=0 go build -ldflags='-s -w' -o $install_dir/live/
2022-10-14 09:13:16 +02:00
popd
2023-03-19 22:27:19 +01:00
2023-03-10 07:59:41 +01:00
pushd $install_dir/build_ldap/
2024-08-30 22:56:31 +02:00
ynh_hide_warnings ynh_exec_as_app CGO_ENABLED=0 go build -ldflags='-s -w' -o $install_dir/live_ldap/
2022-10-14 09:13:16 +02:00
popd
2023-03-19 22:27:19 +01:00
2024-08-30 22:56:31 +02:00
ynh_go_remove
ynh_safe_rm "$install_dir/build/"
ynh_safe_rm "$install_dir/build_ldap/"
ynh_safe_rm "$install_dir/.cache/"
ynh_safe_rm "$install_dir/go/"
ynh_safe_rm "$install_dir/.go-version"
2022-10-14 09:13:16 +02:00
2023-03-19 22:27:19 +01:00
chmod +x "$install_dir/galene-password-generator"
2021-01-09 12:31:07 +01:00
#=================================================
2022-10-14 09:13:16 +02:00
# ADD A CONFIGURATION
2021-01-09 12:31:07 +01:00
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Adding $app's configuration..."
2021-01-09 12:31:07 +01:00
2023-03-19 22:27:19 +01:00
password_hash=$(echo $($install_dir/galene-password-generator $password))
2024-08-30 22:56:31 +02:00
ynh_app_setting_set --key=password_hash --value="$password_hash"
2023-03-19 22:27:19 +01:00
2022-10-14 09:13:16 +02:00
# Configure Galène
2024-08-30 22:56:31 +02:00
ynh_config_add --template="config.json" --destination="$install_dir/live/data/config.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/live/data/config.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/live/data/config.json"
2021-01-09 12:31:07 +01:00
2022-10-14 09:13:16 +02:00
# Configure Galène LDAP
key=$(jose jwk gen -i '{"kty":"oct","alg":"HS256"}')
2024-08-30 22:56:31 +02:00
ynh_app_setting_set --key=key --value="$key"
ynh_config_add --template="galene-ldap.json" --destination="$install_dir/live_ldap/data/galene-ldap.json"
2023-03-10 07:59:41 +01:00
chmod 400 "$install_dir/live_ldap/data/galene-ldap.json"
chown $app:$app "$install_dir/live_ldap/data/galene-ldap.json"
2021-01-09 12:31:07 +01:00
2021-09-06 10:34:58 +02:00
# Create a group name config
2024-08-30 22:56:31 +02:00
ynh_config_add --template="groupname.json" --destination="$data_dir/groups/$group_name.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$data_dir/groups/$group_name.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$data_dir/groups/$group_name.json"
2022-10-14 09:13:16 +02:00
# Create a group name authenticated on LDAP
2024-08-30 22:56:31 +02:00
ynh_config_add --template="groupname-ldap.json" --destination="$data_dir/groups/YunoHost_Users.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$data_dir/groups/YunoHost_Users.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$data_dir/groups/YunoHost_Users.json"
2021-02-25 10:12:39 +01:00
2021-11-23 22:19:40 +01:00
#=================================================
2024-05-26 21:48:21 +02:00
# SYSTEM CONFIGURATION
2021-11-23 22:19:40 +01:00
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Adding system configurations related to $app..."
2022-10-14 09:13:16 +02:00
public_ip4="$(curl -s ip.yunohost.org)" || true
2021-11-23 22:19:40 +01:00
2024-05-26 21:48:21 +02:00
# Create a dedicated NGINX config
2024-08-30 22:56:31 +02:00
ynh_config_add_nginx
2024-05-26 21:48:21 +02:00
2022-10-14 09:13:16 +02:00
# Create a dedicated systemd config
2024-08-30 22:56:31 +02:00
ynh_config_add_systemd
ynh_config_add_systemd --service=${app}_ldap --template="ldap.service"
2021-11-23 22:19:40 +01:00
2023-03-10 07:59:41 +01:00
yunohost service add $app --description="Videoconferencing server" --needs_exposed_ports="$port_turn"
2022-10-14 09:13:16 +02:00
yunohost service add ${app}_ldap --description="LDAP integration for the videoconferencing server"
2021-01-09 12:31:07 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Starting $app's systemd service..."
2021-01-09 12:31:07 +01:00
# Start a systemd service
2024-08-30 22:56:31 +02:00
ynh_systemctl --service=$app --action="start" --log_path="systemd"
ynh_systemctl --service=${app}_ldap --action="start" --log_path="systemd"
2021-01-09 12:31:07 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2024-08-30 22:56:31 +02:00
ynh_script_progression "Installation of $app completed"