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

300 lines
11 KiB
Text
Raw Normal View History

2017-12-08 00:35:52 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2022-01-07 04:42:28 +01:00
source ynh_redis
2019-06-03 22:37:54 +02:00
source ynh_send_readme_to_admin__2
2022-06-10 01:21:56 +02:00
source ynh_apps
2019-04-03 03:27:49 +02:00
source /usr/share/yunohost/helpers
2017-12-08 00:35:52 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2019-04-03 03:21:30 +02:00
ynh_clean_setup () {
ynh_clean_check_starting
}
2017-12-08 00:35:52 +01:00
# 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="/"
2017-12-08 00:35:52 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2022-06-10 01:21:56 +02:00
admin=$YNH_APP_ARG_ADMIN
2017-12-08 00:35:52 +01:00
app=$YNH_APP_INSTANCE_NAME
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)
2020-09-27 19:00:21 +02:00
# Define app's data directory
datadir="/home/yunohost.app/${app}/storage"
2017-12-08 00:35:52 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Validating installation parameters..."
2017-12-08 00:35:52 +01:00
final_path=/var/www/$app
2019-06-03 22:37:54 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-12-08 00:35:52 +01:00
# Register (book) web path
2019-06-03 22:37:54 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2017-12-08 00:35:52 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Storing installation settings..."
2017-12-08 00:35:52 +01:00
2019-06-03 22:37:54 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
2021-02-26 04:16:57 +01:00
ynh_app_setting_set --app=$app --key=admin --value=$admin
2017-12-08 00:35:52 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-01-09 22:38:50 +01:00
ynh_script_progression --message="Finding an available port..."
2017-12-08 00:35:52 +01:00
2020-02-23 19:42:08 +01:00
# Find an available port
2022-06-10 01:21:56 +02:00
port=$(ynh_find_port --port=8095)
2019-06-03 22:37:54 +02:00
ynh_app_setting_set --app=$app --key=port --value=$port
2017-12-08 00:35:52 +01:00
2021-01-13 20:59:06 +01:00
# PeerTube Live port
rtmp_port=1935
ynh_port_available --port=$rtmp_port || ynh_die --message="Port $rtmp_port is needs to be available for this app"
2021-01-13 20:59:06 +01:00
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
2017-12-08 00:35:52 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2020-06-01 03:40:44 +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"
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
2021-04-10 19:38:56 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
2022-06-10 01:21:56 +02:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2021-04-10 19:38:56 +02:00
#=================================================
2019-04-03 00:43:02 +02:00
# CREATE A POSTGRESQL DATABASE
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Creating a PostgreSQL database..."
2019-04-03 06:24:02 +02:00
db_name="peertube_${app}"
2022-01-07 04:42:28 +01:00
db_user=$(ynh_sanitize_dbid --db_name=$app)
2021-02-26 03:34:51 +01:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2022-01-07 04:42:28 +01:00
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
2017-12-08 00:35:52 +01:00
ynh_psql_test_if_first_run
2022-06-10 01:21:56 +02:00
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
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
2019-06-03 22:37:54 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2017-12-08 00:35:52 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2019-06-03 22:37:54 +02:00
ynh_setup_source --dest_dir="$final_path"
2021-04-17 18:31:58 +02:00
chmod 750 "$final_path"
2021-04-10 19:38:56 +02:00
chmod -R o-rwx "$final_path"
2021-06-18 01:09:44 +02:00
chown -R $app:www-data "$final_path"
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 01:57:25 +02:00
# SPECIFIC SETUP
#=================================================
2021-06-29 22:13:41 +02:00
# CREATE DATA DIRECTORY
2017-12-08 00:35:52 +01:00
#=================================================
2021-06-29 22:13:41 +02:00
ynh_script_progression --message="Creating a data directory..."
2017-12-08 00:35:52 +01:00
2022-02-08 01:41:44 +01:00
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
2021-06-29 22:13:41 +02:00
mkdir -p $datadir
2017-12-08 00:35:52 +01:00
2022-02-08 01:41:44 +01:00
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
2019-04-03 02:56:53 +02:00
#=================================================
# BUILD YARN DEPENDENCIES
#=================================================
2020-09-11 14:20:57 +02:00
ynh_script_progression --message="Building Yarn dependencies..."
2019-04-03 02:56:53 +02:00
touch "$final_path/.yarnrc.yml"
chmod 400 "$final_path/.yarnrc.yml"
chown $app:$app "$final_path/.yarnrc.yml"
2019-04-03 03:00:43 +02:00
pushd "$final_path"
2019-06-23 16:13:13 +02:00
ynh_use_nodejs
2022-09-11 19:07:56 +02:00
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH HOME="$final_path" yarn install --production --pure-lockfile --use-yarnrc="$final_path/.yarnrc.yml"
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH HOME="$final_path" yarn cache clean --use-yarnrc="$final_path/.yarnrc.yml"
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
ynh_add_config --template="../conf/production.yaml" --destination="$final_path/config/production.yaml"
chmod 400 "$final_path/config/production.yaml"
chown $app:$app "$final_path/config/production.yaml"
ynh_add_config --template="../conf/local-production.json" --destination="$final_path/config/local-production.json"
2021-04-25 12:26:33 +02:00
chmod 600 "$final_path/config/local-production.json"
2021-04-10 19:38:56 +02:00
chown $app:$app "$final_path/config/local-production.json"
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..."
pushd "$final_path"
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/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..."
pushd "$final_path"
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/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..."
pushd "$final_path"
echo $admin_pass | ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/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
2022-02-08 01:41:44 +01:00
yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $rtmp_port
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 01:57:25 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-02-26 03:34:51 +01:00
ynh_script_progression --message="Configuring permissions..."
2019-04-03 01:57:25 +02:00
# Make app public if necessary
2019-04-03 03:02:51 +02:00
if [ $is_public -eq 1 ]
2019-04-03 01:57:25 +02:00
then
2021-02-26 03:34:51 +01:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
2019-04-03 01:57:25 +02:00
fi
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true"
2019-04-03 03:02:07 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-09-11 14:20:57 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2019-04-03 01:57:25 +02:00
2019-06-03 22:37:54 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-04-03 03:00:43 +02:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2020-06-01 03:40:44 +02:00
ynh_script_progression --message="Sending a readme for the admin..."
2019-04-03 03:00:43 +02:00
2022-06-10 01:21:56 +02:00
ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients=$admin_mail --type='install'
2019-04-03 01:57:25 +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"