mirror of
https://github.com/YunoHost-Apps/peertube_ynh.git
synced 2024-09-03 19:56:29 +02:00
284 lines
10 KiB
Bash
284 lines
10 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_send_readme_to_admin__2
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url="/"
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
admin_email=$(ynh_user_get_info --username=$admin --key="mail")
|
|
admin_pass=$(ynh_string_random --length=24)
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Define app's data directory
|
|
datadir="/home/yunohost.app/${app}/storage"
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# FIND AND OPEN A PORT
|
|
#=================================================
|
|
ynh_script_progression --message="Finding an available port..."
|
|
|
|
# Find an available port
|
|
port=$(ynh_find_port --port=9000)
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
# PeerTube Live port
|
|
rtmp_port=1935
|
|
ynh_port_available --port=$rtmp_port || ynh_die "Port $rtmp_port is needs to be available for this app"
|
|
ynh_app_setting_set --app=$app --key=rtmp_port --value=$rtmp_port
|
|
|
|
# Open the port
|
|
ynh_script_progression --message="Configuring firewall..."
|
|
ynh_exec_warn_less yunohost firewall allow TCP $rtmp_port
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
# Install nodejs
|
|
ynh_install_nodejs --nodejs_version=$YNH_NODEJS_VERSION
|
|
|
|
# Install dependencies
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
# Install ffmpeg from backports for Debian Jessie and from main for others
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
|
ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg"
|
|
else
|
|
ynh_add_app_dependencies --package="ffmpeg"
|
|
fi
|
|
|
|
# Install Yarn
|
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
|
|
|
db_name="peertube_${app}"
|
|
db_user=$app
|
|
db_pwd=$(ynh_string_random --length=30)
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
|
ynh_psql_test_if_first_run
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config "datadir"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
# Create a system user
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# CREATE THE DATA DIRECTORY
|
|
#=================================================
|
|
ynh_script_progression --message="Creating the data directory..."
|
|
|
|
# Create app folders
|
|
mkdir -p "$datadir"
|
|
|
|
# Give permission to the datadir
|
|
chown -R "$app":"$app" "$datadir"
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Modifying a config file..."
|
|
|
|
ynh_add_config --template="../conf/production.yaml" --destination="$final_path/config/production.yaml"
|
|
|
|
ynh_add_config --template="../conf/local-production.json" --destination="$final_path/config/local-production.json"
|
|
|
|
#=================================================
|
|
# BUILD YARN DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
|
|
|
chown -R "$app":"$app" $final_path
|
|
|
|
pushd "$final_path"
|
|
ynh_use_nodejs
|
|
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
|
popd
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config --others_var="ynh_node_load_PATH"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on localhost"
|
|
|
|
#=================================================
|
|
# INSTALL LDAP PLUGIN
|
|
#=================================================
|
|
ynh_script_progression --message="Installing LDAP plugin..."
|
|
|
|
pushd "$final_path"
|
|
NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production npm run plugin:install -- --npm-name peertube-plugin-auth-ldap
|
|
popd
|
|
|
|
#=================================================
|
|
# CHANGE PEERTUBE ADMIN PASSWORD
|
|
#=================================================
|
|
ynh_script_progression --message="Changing PeerTube admin password..."
|
|
|
|
pushd "$final_path"
|
|
echo $admin_pass | NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production npm run reset-password -- -u root
|
|
popd
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
ynh_script_progression --message="Securing files and directories..."
|
|
|
|
# Set permissions to app files
|
|
chown -R $app:$app $final_path
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..."
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate --logfile="$datadir/logs/peertube.log"
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log" --needs_exposed_ports $rtmp_port
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on localhost"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
# Make app public if necessary
|
|
if [ $is_public -eq 1 ]
|
|
then
|
|
# Everyone can access the app.
|
|
# The "main" permission is automatically created before the install script.
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
fi
|
|
|
|
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# SEND A README FOR THE ADMIN
|
|
#=================================================
|
|
ynh_script_progression --message="Sending a readme for the admin..."
|
|
|
|
ynh_add_config --template="../conf/message_install" --destination="../conf/msg_install"
|
|
ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients=$admin_email --type='install'
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|