1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/peertube_ynh.git synced 2024-09-03 19:56:29 +02:00
peertube_ynh/scripts/install

119 lines
4.6 KiB
Text
Raw Normal View History

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
#=================================================
2019-04-03 00:43:02 +02:00
# CREATE A POSTGRESQL DATABASE
#=================================================
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"
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
2017-12-08 00:35:52 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-09-11 14:20:57 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
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
2019-04-03 02:56:53 +02:00
#=================================================
# BUILD YARN DEPENDENCIES
#=================================================
2023-03-21 23:33:23 +01:00
ynh_script_progression --message="Building Yarn dependencies..."
2019-04-03 02:56:53 +02:00
2023-03-21 23:12:02 +01:00
pushd "$install_dir"
2019-06-23 16:13:13 +02:00
ynh_use_nodejs
2023-10-17 20:06:51 +02:00
npm install -g npm
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
2022-02-08 01:41:44 +01:00
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean
2019-04-03 03:00:43 +02:00
popd
2019-04-03 02:56:53 +02:00
2021-04-10 19:38:56 +02:00
#=================================================
# ADD A CONFIGURATION
#=================================================
2021-06-29 22:13:41 +02:00
ynh_script_progression --message="Adding a 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
# 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
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-06-03 22:37:54 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Starting a systemd service..."
2019-06-03 22:37:54 +02:00
2020-02-23 19:42:08 +01:00
# Start a systemd service
2023-12-27 16:34:42 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on localhost"
2019-06-03 22:37:54 +02:00
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"