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

183 lines
6.9 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)
2023-03-27 23:11:08 +02:00
db_name=$(peertube_$app)
2022-07-31 19:15:34 +02:00
2020-09-27 19:00:21 +02:00
# Define app's data directory
2023-03-21 23:12:02 +01:00
#REMOVEME? data_dir="/home/yunohost.app/${app}/storage"
2020-09-27 19:00:21 +02:00
2017-12-08 00:35:52 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2023-03-21 23:33:23 +01:00
ynh_script_progression --message="Storing installation settings..."
2017-12-08 00:35:52 +01:00
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
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2023-03-27 23:08:37 +02:00
ynh_script_progression --message="Installing dependencies..."
2017-12-08 00:35:52 +01:00
2022-07-31 19:15:34 +02:00
ynh_exec_warn_less ynh_install_apps --apps="$app_dependencies"
2021-04-10 19:38:56 +02: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-03-21 23:33:23 +01:00
ynh_script_progression --message="Creating a PostgreSQL database..."
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
2021-12-24 09:22:23 +01:00
#=================================================
# CONFIGURE REDIS
#=================================================
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
#=================================================
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
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
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-03-21 23:12:02 +01:00
ynh_add_config --template="../conf/production.yaml" --destination="$install_dir/config/production.yaml"
2021-04-10 19:38:56 +02:00
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-03-21 23:12:02 +01:00
ynh_add_config --template="../conf/local-production.json" --destination="$install_dir/config/local-production.json"
2021-04-10 19:38:56 +02:00
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-04-11 20:43:53 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
2021-05-13 22:41:53 +02:00
ynh_add_systemd_config
2021-04-11 20:43:53 +02:00
2021-03-30 22:58:26 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
2022-02-08 01:41:44 +01:00
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
2021-03-30 22:58:26 +02:00
# Start a systemd service
2022-07-31 19:15:34 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="HTTP server listening on localhost" --timeout=300 --length=200
2021-03-30 22:58:26 +02:00
#=================================================
# INSTALL LDAP PLUGIN
#=================================================
ynh_script_progression --message="Installing LDAP plugin..."
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
popd
#=================================================
# INSTALL PEERTUBE LIVECHAT PLUGIN
#=================================================
ynh_script_progression --message="Installing PeerTube livechat plugin..."
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-livechat
2021-03-30 22:58:26 +02:00
popd
#=================================================
# CHANGE PEERTUBE ADMIN PASSWORD
#=================================================
ynh_script_progression --message="Changing PeerTube admin password..."
2023-03-21 23:12:02 +01:00
pushd "$install_dir"
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
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
2021-06-29 22:13:41 +02:00
# Stop a systemd service
2022-07-31 19:15:34 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
2021-03-30 22:58:26 +02:00
2019-04-03 01:57:25 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Configuring log rotation..."
2019-04-03 01:57:25 +02:00
# Use logrotate to manage application logfile(s)
2022-02-08 01:41:44 +01:00
ynh_use_logrotate
2019-04-03 01:57:25 +02:00
2019-04-03 03:06:16 +02:00
#=================================================
2020-02-23 19:42:08 +01:00
# INTEGRATE SERVICE IN YUNOHOST
2019-04-03 03:06:16 +02:00
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2019-04-03 03:06:16 +02:00
2023-03-21 23:33:23 +01:00
yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $port_rtmp
2019-04-03 03:06:16 +02:00
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
2022-07-31 19:15:34 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --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"