mirror of
https://github.com/YunoHost-Apps/outline_ynh.git
synced 2024-09-03 19:56:12 +02:00
157 lines
6.3 KiB
Bash
Executable file
157 lines
6.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
utils_secret=$(ynh_hex_32_random)
|
|
secret_key=$(ynh_hex_32_random)
|
|
|
|
#=================================================
|
|
# INSTALL DEX APP FOR OAUTH2 / OIDC
|
|
#=================================================
|
|
ynh_script_progression "Installing Dex..."
|
|
|
|
oidc_secret=$(ynh_hex_32_random)
|
|
oidc_name="Outline"
|
|
oidc_callback="$domain/auth/oidc.callback"
|
|
|
|
if yunohost app list | grep -q "$YNH_APP_ARG_DEX_DOMAIN$YNH_APP_ARG_DEX_PATH"; then
|
|
ynh_die "The domain provided for Dex is already used by another app. Please chose another one !"
|
|
fi
|
|
|
|
yunohost app install https://github.com/YunoHost-Apps/dex_ynh/tree/ccc5b82dc9762b42abe82dfa0582e6e4bb6175c5 --force --args "domain=$dex_domain&path=$dex_path&oidc_name=$oidc_name&oidc_secret=$oidc_secret&oidc_callback=$oidc_callback" 2>&1 | tee dexlog.txt
|
|
dex_app=$(gawk 'match($0, /Installation of (.+) completed/, app) {print app[1]}' dexlog.txt)
|
|
rm dexlog.txt
|
|
|
|
# Create Dex URIs
|
|
if [ $dex_path = "/" ]
|
|
then
|
|
dex_auth_uri="https://$dex_domain/auth"
|
|
dex_token_uri="https://$dex_domain/token"
|
|
dex_user_uri="https://$dex_domain/userinfo"
|
|
else
|
|
dex_auth_uri="https://$dex_domain$dex_path/auth"
|
|
dex_token_uri="https://$dex_domain$dex_path/token"
|
|
dex_user_uri="https://$dex_domain$dex_path/userinfo"
|
|
|
|
fi
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression "Storing installation settings..."
|
|
|
|
ynh_app_setting_set --key=utils_secret --value=$utils_secret
|
|
ynh_app_setting_set --key=secret_key --value=$secret_key
|
|
ynh_app_setting_set --key=dex_app --value=$dex_app
|
|
ynh_app_setting_set --key=oidc_name --value=$oidc_name
|
|
ynh_app_setting_set --key=oidc_secret --value=$oidc_secret
|
|
ynh_app_setting_set --key=oidc_callback --value=$oidc_callback
|
|
ynh_app_setting_set --key=dex_auth_uri --value=$dex_auth_uri
|
|
ynh_app_setting_set --key=dex_token_uri --value=$dex_token_uri
|
|
ynh_app_setting_set --key=dex_user_uri --value=$dex_user_uri
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression "Installing dependencies..."
|
|
|
|
# Install nodejs
|
|
ynh_nodejs_install 2>&1
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression "Creating a PostgreSQL database..."
|
|
|
|
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS unaccent;"
|
|
|
|
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression "Setting up source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$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 | 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"
|
|
#=================================================
|
|
# SETUP LOCAL STORAGE
|
|
#=================================================
|
|
|
|
mkdir "/var/lib/$app"
|
|
chown -R $app:www-data "/var/lib/$app"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Configuring NGINX web server..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_config_add_nginx
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_config_add_systemd
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_config_add_logrotate
|
|
|
|
cron_path="/etc/cron.d/$app"
|
|
ynh_config_add --template="outline.cron" --destination="$cron_path"
|
|
#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 root: "$cron_path"
|
|
#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 644 "$cron_path"
|
|
|
|
yunohost service add $app --description="Outline server" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# BUILD YARN DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression "Building $app. This can be very long, be patient !"
|
|
|
|
pushd "$install_dir"
|
|
|
|
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --frozen-lockfile --network-timeout 1000000000 2>&1
|
|
ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_OPTIONS="--max-old-space-size=3200" yarn build 2>&1
|
|
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn cache clean 2>&1
|
|
popd
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Adding $app's configuration..."
|
|
|
|
ynh_config_add --template=".env" --destination="$install_dir/.env"
|
|
|
|
#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/.env"
|
|
#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/.env"
|
|
|
|
#=================================================
|
|
# RUN DB MIGRATION
|
|
#=================================================
|
|
ynh_script_progression "Running DB initial migration..."
|
|
|
|
pushd "$install_dir"
|
|
|
|
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn db:migrate
|
|
popd
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Starting $app's systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemctl --service=$app --action="start" --log_path="systemd"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Installation of $app completed"
|