2017-12-08 00:35:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2019-04-03 03:27:49 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-12-08 00:35:52 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2022-07-31 19:15:34 +02:00
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key="mail")
|
|
|
|
admin_pass=$(ynh_string_random --length=24)
|
2022-12-19 17:53:44 +01:00
|
|
|
secrets_peertube=$(ynh_string_random --length=24)
|
2022-12-15 11:11:11 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=secrets_peertube --value=$secrets_peertube
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2023-12-27 18:10:54 +01:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_script_progression --message="Installing nodejs..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2023-03-21 23:33:23 +01:00
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2018-03-03 20:05:39 +01:00
|
|
|
#=================================================
|
2019-04-03 00:43:02 +02:00
|
|
|
# CREATE A POSTGRESQL DATABASE
|
2018-03-03 20:05:39 +01:00
|
|
|
#=================================================
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_script_progression --message="Initializing postgresql modules..."
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
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
|
2017-12-08 00:35:52 +01:00
|
|
|
|
|
|
|
#=================================================
|
2019-04-03 00:43:02 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-03-21 23:12:02 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2023-03-21 23:12:02 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2023-12-27 18:23:51 +01:00
|
|
|
#=================================================
|
|
|
|
# BUILD YARN DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
|
|
|
|
|
|
|
pushd "$install_dir"
|
|
|
|
ynh_use_nodejs
|
|
|
|
npm install -g npm
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean
|
|
|
|
popd
|
|
|
|
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2023-12-27 18:23:51 +01:00
|
|
|
ynh_script_progression --message="Adding system configurations..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2021-04-09 23:37:52 +02:00
|
|
|
# Create a dedicated NGINX config
|
2021-06-29 22:13:41 +02:00
|
|
|
ynh_add_nginx_config
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2023-09-13 18:43:40 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
2023-12-27 17:23:14 +01:00
|
|
|
yunohost service add $app --description="Federated video streaming platform" --log="/var/log/$app/$app.log" --needs_exposed_ports $port_rtmp
|
2023-09-13 18:43:40 +02:00
|
|
|
|
2021-04-10 19:38:56 +02:00
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
2023-12-27 18:23:51 +01:00
|
|
|
ynh_script_progression --message="Adding peertube configuration file..."
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2023-12-27 17:23:14 +01:00
|
|
|
ynh_add_config --template="production.yaml" --destination="$install_dir/config/production.yaml"
|
2023-03-21 23:12:02 +01:00
|
|
|
chmod 400 "$install_dir/config/production.yaml"
|
|
|
|
chown $app:$app "$install_dir/config/production.yaml"
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2023-12-27 17:26:40 +01:00
|
|
|
# Initialize local setting conf file
|
|
|
|
echo '{}' > "$install_dir/config/local-production.json"
|
2023-03-21 23:12:02 +01:00
|
|
|
chmod 600 "$install_dir/config/local-production.json"
|
|
|
|
chown $app:$app "$install_dir/config/local-production.json"
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2023-12-27 18:23:51 +01:00
|
|
|
#=================================================
|
|
|
|
# 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"
|
|
|
|
|
2021-03-30 22:58:26 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL LDAP PLUGIN
|
|
|
|
#=================================================
|
2023-09-13 18:43:40 +02:00
|
|
|
ynh_script_progression --message="Installing $app plugin and password..."
|
2021-03-30 22:58:26 +02:00
|
|
|
|
2023-03-21 23:12:02 +01:00
|
|
|
pushd "$install_dir"
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-auth-ldap
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-livechat
|
|
|
|
echo "$admin_pass" | ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run reset-password -- -u root
|
2021-03-30 22:58:26 +02:00
|
|
|
popd
|
|
|
|
|
2019-04-03 00:43:02 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|