2017-12-08 00:35:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2019-06-03 22:37:54 +02:00
|
|
|
source ynh_send_readme_to_admin__2
|
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
|
2017-12-11 05:28:25 +01:00
|
|
|
path_url="/"
|
2017-12-08 00:35:52 +01:00
|
|
|
admin_email=$YNH_APP_ARG_EMAIL
|
2019-06-03 22:37:54 +02:00
|
|
|
admin_pass=$(ynh_string_random --length=24)
|
2017-12-08 00:35:52 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
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
|
|
|
|
2017-12-11 05:28:25 +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
|
|
|
|
ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email
|
|
|
|
ynh_app_setting_set --app=$app --key=admin_pass --value=$admin_pass
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
2020-09-27 19:00:21 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
2017-12-08 00:35:52 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2020-02-23 19:42:08 +01:00
|
|
|
# Find an available port
|
2019-06-03 22:37:54 +02:00
|
|
|
port=$(ynh_find_port --port=9000)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$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
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install nodejs
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_install_nodejs --nodejs_version=$YNH_NODEJS_VERSION
|
2018-04-04 07:57:35 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
# Install ffmpeg from backports for Debian Jessie and from main for others
|
2018-05-31 00:33:14 +02:00
|
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
2019-04-03 02:43:43 +02:00
|
|
|
ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg"
|
|
|
|
else
|
|
|
|
ynh_add_app_dependencies --package="ffmpeg"
|
2018-05-31 00:33:14 +02:00
|
|
|
fi
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# 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"
|
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
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
2018-03-03 20:05:39 +01:00
|
|
|
|
2019-04-03 06:24:02 +02:00
|
|
|
db_name="peertube_${app}"
|
2019-06-03 22:37:54 +02:00
|
|
|
db_user=$app
|
|
|
|
db_pwd=$(ynh_string_random --length=30)
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=psql_db --value=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=psqlpwd --value=$db_pwd
|
2017-12-08 00:35:52 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2019-06-03 22:37:54 +02:00
|
|
|
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
|
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"
|
2018-05-21 12:10:41 +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
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2020-09-27 19:00:21 +02:00
|
|
|
ynh_add_nginx_config "datadir"
|
2017-12-08 00:35:52 +01:00
|
|
|
|
|
|
|
#=================================================
|
2019-04-03 01:57:25 +02:00
|
|
|
# CREATE DEDICATED USER
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2019-04-03 01:57:25 +02:00
|
|
|
# Create a system user
|
2019-10-24 20:13:53 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
2019-04-03 01:57:25 +02:00
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# CREATE THE DATA DIRECTORY
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Creating the data directory..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2019-04-03 01:57:25 +02:00
|
|
|
# Create app folders
|
|
|
|
mkdir -p "$datadir"
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2019-04-03 02:49:10 +02:00
|
|
|
# Give permission to the datadir
|
|
|
|
chown -R "$app":"$app" "$datadir"
|
|
|
|
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
2019-04-03 01:57:25 +02:00
|
|
|
# MODIFY A CONFIG FILE
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Modifying a config file..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
config="$final_path/config/production.yaml"
|
|
|
|
cp ../conf/production.yaml "$config"
|
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$app" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_email" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
|
2020-09-27 19:00:21 +02:00
|
|
|
ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="$config"
|
2018-05-31 00:33:14 +02:00
|
|
|
|
2019-10-13 14:52:23 +02:00
|
|
|
#Create the admin settings file
|
2020-06-01 03:40:44 +02:00
|
|
|
local_config="$final_path/config/local-production.json"
|
|
|
|
cp ../conf/local-production.json "$local_config"
|
2019-06-06 23:16:31 +02:00
|
|
|
|
2018-06-25 12:12:05 +02:00
|
|
|
#=================================================
|
2019-04-03 01:57:25 +02:00
|
|
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
2018-06-25 12:12:05 +02:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Storing the config file checksum..."
|
2018-06-25 12:12:05 +02:00
|
|
|
|
2019-04-03 01:57:25 +02:00
|
|
|
# Calculate and store the config file checksum into the app settings
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_store_file_checksum --file="$config"
|
|
|
|
ynh_store_file_checksum --file="$local_config"
|
2018-06-25 12:12:05 +02:00
|
|
|
|
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
|
|
|
|
2019-06-19 00:43:32 +02:00
|
|
|
chown -R "$app":"$app" $final_path
|
|
|
|
|
2019-04-03 03:00:43 +02:00
|
|
|
pushd "$final_path"
|
2019-06-23 16:13:13 +02:00
|
|
|
ynh_use_nodejs
|
2020-06-01 03:40:44 +02:00
|
|
|
sudo -u $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
2019-04-03 03:00:43 +02:00
|
|
|
popd
|
2019-04-03 02:56:53 +02:00
|
|
|
|
2017-12-08 00:35:52 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2017-12-08 00:35:52 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_add_systemd_config --others_var="ynh_node_load_PATH"
|
2017-12-08 00:35:52 +01:00
|
|
|
|
2019-04-03 01:57:25 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
2019-04-03 01:57:25 +02:00
|
|
|
|
|
|
|
# Set permissions to app files
|
2020-06-01 03:40:44 +02:00
|
|
|
chown -R $app:$app $final_path
|
2019-04-03 01:57:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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)
|
2020-09-27 19:00:21 +02:00
|
|
|
ynh_use_logrotate --logfile="$datadir/logs/peertube.log"
|
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
|
|
|
|
2020-09-27 19:00:21 +02:00
|
|
|
yunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log"
|
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
|
2019-06-23 16:13:13 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
|
2019-06-03 22:37:54 +02:00
|
|
|
|
2019-04-03 01:57:25 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
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
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2019-04-03 01:57:25 +02:00
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# we need to wait for the service to init peertube's database
|
|
|
|
pushd "$final_path"
|
2019-06-23 16:13:13 +02:00
|
|
|
echo $admin_pass | NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production npm run reset-password -- -u root
|
2019-04-03 03:00:43 +02:00
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2019-06-19 00:43:32 +02:00
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/message"
|
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message"
|
|
|
|
ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message"
|
|
|
|
ynh_replace_string --match_string="__ADMIN_PASS__" --replace_string="$admin_pass" --target_file="../conf/message"
|
2019-04-03 03:00:43 +02:00
|
|
|
|
2019-06-19 00:43:32 +02:00
|
|
|
ynh_send_readme_to_admin --app_message="../conf/message" --recipients=$admin_email --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"
|