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

Merge pull request #93 from YunoHost-Apps/testing

Testing
This commit is contained in:
yalh76 2019-06-04 19:40:57 +02:00 committed by GitHub
commit b7611125d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 480 additions and 407 deletions

View file

@ -1,14 +1,14 @@
# PeerTube app for YunoHost # PeerTube app for YunoHost
[![Integration level](https://dash.yunohost.org/integration/peertube.svg)](https://dash.yunohost.org/appci/app/peertube) [![Integration level](https://dash.yunohost.org/integration/peertube.svg)](https://dash.yunohost.org/appci/app/peertube)
[![Install peertube with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=peertube) [![Install PeerTube with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=peertube)
## Overview ## Overview
### What is Peertube ? ### What is PeerTube ?
PeerTube is a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser, using <a href="https://github.com/feross/webtorrent">WebTorrent</a>. PeerTube is a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser, using <a href="https://github.com/feross/webtorrent">WebTorrent</a>.
### Why Peertube ? ### Why PeerTube ?
We can't build a FOSS video streaming alternatives to YouTube, Dailymotion, Vimeo... with a centralized software. One organization alone cannot have enough money to pay bandwidth and video storage of its server. We can't build a FOSS video streaming alternatives to YouTube, Dailymotion, Vimeo... with a centralized software. One organization alone cannot have enough money to pay bandwidth and video storage of its server.
@ -22,7 +22,7 @@ Servers are run independently by different people and organizations. They can ap
By watching a video, you help the hosting provider to broadcast it by becoming a broadcaster of the video yourself. Each instance doesnt need much money to broadcast the videos of its users. By watching a video, you help the hosting provider to broadcast it by becoming a broadcaster of the video yourself. Each instance doesnt need much money to broadcast the videos of its users.
**Shipped version:** 1.2.1 **Shipped version:** 1.3.0
## Screenshots ## Screenshots
@ -39,7 +39,7 @@ Want to see in action?
### Guidelines ### Guidelines
1. Require **dedicated domain** like **peertube.domain.tld**. 1. Require **dedicated domain** like **peertube.domain.tld**.
1. **No LDAP** support (blocked until Peertube core upstream implements it) 1. **No LDAP** support (blocked until PeerTube core upstream implements it)
1. URL can not be changed once selected. Choose the domain wisely. 1. URL can not be changed once selected. Choose the domain wisely.
1. You need more then **1GB** of ram. If you don't have it, please create a **swap memory**. 1. You need more then **1GB** of ram. If you don't have it, please create a **swap memory**.
@ -47,7 +47,7 @@ Want to see in action?
$ mkswap /swapfile $ mkswap /swapfile
$ swapon /swapfile $ swapon /swapfile
$ echo "/swapfile swap swap defaults 0 0" >> /etc/fstab $ echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
1. This app is **multi-instance** (you can have more then one Peertube instance running on a YunoHost server) 1. This app is **multi-instance** (you can have more then one PeerTube instance running on a YunoHost server)
### Installing guide ### Installing guide
@ -76,9 +76,9 @@ Want to see in action?
#### Supported architectures #### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/peertube%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/peertube/) * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/peertube%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/peertube/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/peertube%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/peertube/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/peertube%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/peertube/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/peertube%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/peertube/) * Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/peertube%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/peertube/)
## Links ## Links

View file

@ -37,5 +37,5 @@
Level 9=0 Level 9=0
Level 10=0 Level 10=0
;;; Options ;;; Options
Email=anmol@datamol.org Email=anmol@datamol.org;yalh@yahoo.com
Notification=yes Notification=yes

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/Chocobozzz/PeerTube/releases/download/v1.2.1/peertube-v1.2.1.tar.xz SOURCE_URL=https://github.com/Chocobozzz/PeerTube/releases/download/v1.3.0/peertube-v1.3.0.tar.xz
SOURCE_SUM=77517c06133704e36b755bdae4f68838221e657ca70a1a40d5c8652655978ed5 SOURCE_SUM=651789564bb4238c00f826bbe1e5b1dca9c13b9aaf4a87b922e0b7af5ebb8b77
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.xz SOURCE_FORMAT=tar.xz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true

View file

@ -8,13 +8,22 @@ webserver:
hostname: '__domain__' hostname: '__domain__'
port: 443 port: 443
rates_limit:
login:
# 15 attempts in 5 min
window: 5 minutes
max: 15
ask_send_email:
# 3 attempts in 5 min
window: 5 minutes
max: 3
# Proxies to trust to get real client IP # Proxies to trust to get real client IP
# If you run PeerTube just behind a local proxy (nginx), keep 'loopback' # If you run PeerTube just behind a local proxy (nginx), keep 'loopback'
# If you run PeerTube behind a remote proxy, add the proxy IP address (or subnet) # If you run PeerTube behind a remote proxy, add the proxy IP address (or subnet)
trust_proxy: trust_proxy:
- 'loopback' - 'loopback'
# Your database name will be "peertube"+database.suffix # Your database name will be "peertube"+database.suffix
database: database:
hostname: 'localhost' hostname: 'localhost'
@ -43,13 +52,14 @@ smtp:
tls: false # If you use StartTLS: false tls: false # If you use StartTLS: false
disable_starttls: true disable_starttls: true
ca_file: null # Used for self signed certificates ca_file: null # Used for self signed certificates
from_address: 'admin@__domain__' from_address: 'webmaster@__domain__'
# From the project root directory # From the project root directory
storage: storage:
tmp: '/home/yunohost.app/__app__/storage/tmp/' # Used to download data (imports etc), store uploaded files before processing... tmp: '/home/yunohost.app/__app__/storage/tmp/' # Used to download data (imports etc), store uploaded files before processing...
avatars: '/home/yunohost.app/__app__/storage/avatars/' avatars: '/home/yunohost.app/__app__/storage/avatars/'
videos: '/home/yunohost.app/__app__/storage/videos/' videos: '/home/yunohost.app/__app__/storage/videos/'
streaming_playlists: '/home/yunohost.app/__app__/storage/streaming-playlists/'
redundancy: '/home/yunohost.app/__app__/storage/videos/' redundancy: '/home/yunohost.app/__app__/storage/videos/'
logs: '/home/yunohost.app/__app__/storage/logs/' logs: '/home/yunohost.app/__app__/storage/logs/'
previews: '/home/yunohost.app/__app__/storage/previews/' previews: '/home/yunohost.app/__app__/storage/previews/'
@ -76,23 +86,60 @@ trending:
# Cache remote videos on your server, to help other instances to broadcast the video # Cache remote videos on your server, to help other instances to broadcast the video
# You can define multiple caches using different sizes/strategies # You can define multiple caches using different sizes/strategies
# Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following
#redundancy: redundancy:
# videos: videos:
# check_interval: '6 hour' # How often you want to check new videos to cache check_interval: '6 hour' # How often you want to check new videos to cache
# strategies: strategies:
# - # -
# size: '10GB' # size: '10GB'
# # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances)
# min_lifetime: '48 hours'
# strategy: 'most-views' # Cache videos that have the most views # strategy: 'most-views' # Cache videos that have the most views
# - # -
# size: '10GB' # size: '10GB'
# # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances)
# min_lifetime: '48 hours'
# strategy: 'trending' # Cache trending videos # strategy: 'trending' # Cache trending videos
# - # -
# size: '1GB' # size: '10GB'
# # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances) # # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances)
# min_lifetime: '48 hours' # min_lifetime: '48 hours'
# strategy: 'recently-added' # Cache recently added videos # strategy: 'recently-added' # Cache recently added videos
# min_views: 10 # Having at least x views # min_views: 10 # Having at least x views
csp:
enabled: false
report_only: true # CSP directives are still being tested, so disable the report only mode at your own risk!
report_uri:
tracker:
# If you disable the tracker, you disable the P2P aspect of PeerTube
enabled: true
# Only handle requests on your videos.
# If you set this to false it means you have a public tracker.
# Then, it is possible that clients overload your instance with external torrents
private: true
# Reject peers that do a lot of announces (could improve privacy of TCP/UDP peers)
reject_too_many_announces: false
history:
videos:
# If you want to limit users videos history
# -1 means there is no limitations
# Other values could be '6 months' or '30 days' etc (PeerTube will periodically delete old entries from database)
max_age: -1
views:
videos:
# PeerTube creates a database entry every hour for each video to track views over a period of time
# This is used in particular by the Trending page
# PeerTube could remove old remote video views if you want to reduce your database size (video view counter will not be altered)
# -1 means no cleanup
# Other values could be '6 months' or '30 days' etc (PeerTube will periodically delete old entries from database)
remote:
max_age: -1
############################################################################### ###############################################################################
# #
# From this point, all the following keys can be overridden by the web interface # From this point, all the following keys can be overridden by the web interface
@ -111,7 +158,6 @@ cache:
captions: captions:
size: 500 # Max number of video captions/subtitles you want to cache size: 500 # Max number of video captions/subtitles you want to cache
admin: admin:
# Used to generate the root user at first startup # Used to generate the root user at first startup
# And to receive emails from the contact form # And to receive emails from the contact form
@ -142,6 +188,8 @@ transcoding:
enabled: true enabled: true
# Allow your users to upload .mkv, .mov, .avi, .flv videos # Allow your users to upload .mkv, .mov, .avi, .flv videos
allow_additional_extensions: true allow_additional_extensions: true
# If a user uploads an audio file, PeerTube will create a video by merging the preview file and the audio file
allow_audio_files: true
threads: 1 threads: 1
resolutions: # Only created if the original video has a higher resolution, uses more storage! resolutions: # Only created if the original video has a higher resolution, uses more storage!
240p: false 240p: false
@ -149,6 +197,15 @@ transcoding:
480p: false 480p: false
720p: false 720p: false
1080p: false 1080p: false
# /!\ EXPERIMENTAL /!\
# /!\ Requires ffmpeg >= 4
# Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
# * Resolution change is smoother
# * Faster playback in particular with long videos
# * More stable playback (less bugs/infinite loading)
# /!\ Multiplies videos storage by 2 /!\
hls:
enabled: false
import: import:
# Add ability for your users to import remote videos (from YouTube, torrent...) # Add ability for your users to import remote videos (from YouTube, torrent...)
@ -158,6 +215,12 @@ import:
torrent: # Magnet URI or torrent file (use classic TCP/UDP/WebSeed to download the file) torrent: # Magnet URI or torrent file (use classic TCP/UDP/WebSeed to download the file)
enabled: false enabled: false
auto_blacklist:
# New videos automatically blacklisted so moderators can review before publishing
videos:
of_users:
enabled: false
# Instance settings # Instance settings
instance: instance:
name: 'YunoHost PeerTube' name: 'YunoHost PeerTube'
@ -165,6 +228,10 @@ instance:
description: '' # Support markdown description: '' # Support markdown
terms: '' # Support markdown terms: '' # Support markdown
default_client_route: '/videos/trending' default_client_route: '/videos/trending'
# Whether or not the instance is dedicated to NSFW content
# Enabling it will allow other administrators to know that you are mainly federating sensitive content
# Moreover, the NSFW checkbox on video upload will be automatically checked by default
is_nsfw: false
# By default, "do_not_list" or "blur" or "display" NSFW videos # By default, "do_not_list" or "blur" or "display" NSFW videos
# Could be overridden per user with a setting # Could be overridden per user with a setting
default_nsfw_policy: 'do_not_list' default_nsfw_policy: 'do_not_list'
@ -189,3 +256,10 @@ services:
# If false, we use an image link card that will redirect on your PeerTube instance # If false, we use an image link card that will redirect on your PeerTube instance
# Test on https://cards-dev.twitter.com/validator to see if you are whitelisted # Test on https://cards-dev.twitter.com/validator to see if you are whitelisted
whitelisted: false whitelisted: false
followers:
instance:
# Allow or not other instances to follow yours
enabled: true
# Whether or not an administrator must manually validate a new follower
manual_approval: false

View file

@ -6,7 +6,7 @@
"en": "Video streaming platform using P2P directly in the web browser, connected to a federated network", "en": "Video streaming platform using P2P directly in the web browser, connected to a federated network",
"fr": "Plateforme de diffusion vidéo par P2P directement dans le navigateur, et connectée à un réseau fédéralisé" "fr": "Plateforme de diffusion vidéo par P2P directement dans le navigateur, et connectée à un réseau fédéralisé"
}, },
"version": "1.2.1~ynh1", "version": "1.3.0~ynh1",
"url": "https://github.com/Chocobozzz/PeerTube", "url": "https://github.com/Chocobozzz/PeerTube",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"maintainer": [ "maintainer": [
@ -19,7 +19,7 @@
} }
], ],
"requirements": { "requirements": {
"yunohost": ">= 3.4" "yunohost": ">= 3.5"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [

View file

@ -18,60 +18,3 @@ pkg_dependencies="postgresql postgresql-contrib openssl g++ redis-server redis-t
#================================================= #=================================================
# FUTURE OFFICIAL HELPERS # FUTURE OFFICIAL HELPERS
#================================================= #=================================================
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin app_message [recipients]
# | arg: app_message - The message to send to the administrator.
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
ynh_send_readme_to_admin() {
local app_message="${1:-...No specific information...}"
local recipients="${2:-root}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` has important message for you"
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$app_message
---
Automatic diagnosis data from YunoHost
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
# Send the email to the recipients
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
}

View file

@ -8,7 +8,6 @@
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,69 +23,69 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get "$app" final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get "$app" psql_db) db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
#=================================================
# STOP PEERTUBE FOR BACKUP
#=================================================
ynh_print_info "Stop $app service..."
ynh_systemd_action --service_name="$app" --action="stop"
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Backing up the main app directory..." ynh_print_info --message="Backing up the main app directory..."
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Backing up nginx web server configuration..." ynh_print_info --message="Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Backing up the PostgreSQL database..." ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db "$db_name" > db.sql ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
#================================================= #=================================================
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Backing up logrotate configuration..." ynh_print_info --message="Backing up logrotate configuration..."
ynh_backup "/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Backing up systemd configuration..." ynh_print_info --message="Backing up systemd configuration..."
ynh_backup "/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# START PEERTUBE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_print_info "Start $app service..." ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on localhost" ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -8,7 +8,7 @@
source _common.sh source _common.sh
source ynh_add_extra_apt_repos__3 source ynh_add_extra_apt_repos__3
source ynh_systemd_action source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -16,7 +16,6 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
read-p "key"
ynh_clean_check_starting ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -29,7 +28,7 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url="/" path_url="/"
admin_email=$YNH_APP_ARG_EMAIL admin_email=$YNH_APP_ARG_EMAIL
admin_pass=$(ynh_string_random 24) admin_pass=$(ynh_string_random --length=24)
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -37,42 +36,42 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_print_info "Validating installation parameters..." ynh_print_info --message="Validating installation parameters..."
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path # Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url" ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_print_info "Storing installation settings..." ynh_print_info --message="Storing installation settings..."
ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set "$app" admin_email "$admin_email" ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email
ynh_app_setting_set "$app" admin_pass "$admin_pass" ynh_app_setting_set --app=$app --key=admin_pass --value=$admin_pass
ynh_app_setting_set "$app" is_public "$is_public" ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
ynh_print_info "Configuring firewall..." ynh_print_info --message="Configuring firewall..."
# Find a free port # Find a free port
port=$(ynh_find_port 9000) port=$(ynh_find_port --port=9000)
ynh_app_setting_set "$app" port "$port" ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Installing dependencies..." ynh_print_info --message="Installing dependencies..."
# Install nodejs # Install nodejs
ynh_install_nodejs 8 ynh_install_nodejs --nodejs_version=8
# Install dependencies # Install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
@ -90,32 +89,32 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Creating a PostgreSQL database..." ynh_print_info --message="Creating a PostgreSQL database..."
db_name="peertube_${app}" db_name="peertube_${app}"
db_pwd=$(ynh_string_random 30) db_user=$app
ynh_app_setting_set "$app" psql_db "$db_name" db_pwd=$(ynh_string_random --length=30)
ynh_app_setting_set "$app" psqlpwd "$db_pwd" ynh_app_setting_set --app="$app" --key=psql_db --value="$db_name"
ynh_app_setting_set --app="$app" --key=psqlpwd --value="$db_pwd"
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user "$app" "$db_pwd" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
ynh_psql_execute_as_root "\connect $db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS pg_trgm;"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Setting up source files..." ynh_print_info --message="Setting up source files..."
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source --dest_dir="$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Configuring nginx web server..." ynh_print_info --message="Configuring nginx web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -123,17 +122,17 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Configuring system user..." ynh_print_info --message="Configuring system user..."
# Create a system user # Create a system user
ynh_system_user_create "$app" ynh_system_user_create --username=$app
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# CREATE THE DATA DIRECTORY # CREATE THE DATA DIRECTORY
#================================================= #=================================================
ynh_print_info "Create the data directory..." ynh_print_info --message="Create the data directory..."
# Define app's data directory # Define app's data directory
datadir="/home/yunohost.app/${app}/storage" datadir="/home/yunohost.app/${app}/storage"
@ -149,12 +148,12 @@ chown -R "$app":"$app" "$datadir"
#================================================= #=================================================
cp ../conf/production.yaml "$final_path/config/production.yaml" cp ../conf/production.yaml "$final_path/config/production.yaml"
ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml" ynh_replace_string --match_string="__domain__" --replace_string="$domain" --target_file="$final_path/config/production.yaml"
ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml" ynh_replace_string --match_string="__db_name__" --replace_string="$app" --target_file="$final_path/config/production.yaml"
ynh_replace_string "__app__" "$app" "$final_path/config/production.yaml" ynh_replace_string --match_string="__app__" --replace_string="$app" --target_file="$final_path/config/production.yaml"
ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.yaml" ynh_replace_string --match_string="__db_pwd__" --replace_string="$db_pwd" --target_file="$final_path/config/production.yaml"
ynh_replace_string "__email__" "$admin_email" "$final_path/config/production.yaml" ynh_replace_string --match_string="__email__" --replace_string="$admin_email" --target_file="$final_path/config/production.yaml"
ynh_replace_string "__PORT__" "$port" "$final_path/config/production.yaml" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config/production.yaml"
#Create the admin settings file #Create the admin settings file
touch "$final_path/config/local-production.json" touch "$final_path/config/local-production.json"
@ -164,7 +163,8 @@ touch "$final_path/config/local-production.json"
#================================================= #=================================================
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config/production.yaml" ynh_store_file_checksum --file="$final_path/config/production.yaml"
ynh_store_file_checksum --file="$final_path/config/local-production.json"
#================================================= #=================================================
# BUILD YARN DEPENDENCIES # BUILD YARN DEPENDENCIES
@ -178,7 +178,7 @@ popd
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -194,10 +194,10 @@ chown -R "$app":"$app" $final_path
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Configuring log rotation..." ynh_print_info --message="Configuring log rotation..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log" ynh_use_logrotate --logfile="/home/yunohost.app/${app}/storage/logs/peertube.log"
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
@ -206,31 +206,31 @@ ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log"
# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added
yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Configuring SSOwat..." ynh_print_info --message="Configuring SSOwat..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway. # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SERVICE
#=================================================
ynh_print_info "Start $app service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN # CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN
@ -254,10 +254,10 @@ The admin password is: $admin_pass
If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh" If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh"
ynh_send_readme_to_admin "$message" ynh_send_readme_to_admin --app_message="$message"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Installation of $app completed" ynh_print_info --message="Installation of $app completed"

View file

@ -7,19 +7,21 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get "$app" port) port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get "$app" psql_db) db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
final_path=$(ynh_app_setting_get "$app" final_path) db_user=$app
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -28,16 +30,16 @@ final_path=$(ynh_app_setting_get "$app" final_path)
#================================================= #=================================================
# Remove a service from the admin panel, added by `yunohost service add` # Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status $app >/dev/null 2>&1 if ynh_exec_warn_less yunohost service status $app >/dev/null 2>&1
then then
ynh_print_info "Removing $app service" ynh_print_info --message="Removing $app service..."
yunohost service remove "$app" yunohost service remove $app
fi fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_print_info "Stopping and removing the systemd service" ynh_print_info --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
@ -45,18 +47,15 @@ ynh_remove_systemd_config
#================================================= #=================================================
# REMOVE THE POSTGRESQL DATABASE # REMOVE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Removing the PostgreSQL database" ynh_print_info --message="Removing the PostgreSQL database..."
ynh_psql_execute_as_root "\connect $db_name
SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';"
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_name="$db_name" --db_user="$app" ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Removing dependencies" ynh_print_info --message="Removing dependencies..."
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
@ -65,15 +64,15 @@ ynh_remove_nodejs
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Removing app main directory" ynh_print_info --message="Removing app main directory..."
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing nginx web server configuration" ynh_print_info --message="Removing nginx web server configuration..."
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
@ -81,7 +80,7 @@ ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing logrotate configuration" ynh_print_info --message="Removing logrotate configuration..."
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
@ -92,7 +91,7 @@ ynh_remove_logrotate
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_print_info "Closing port $port" ynh_print_info --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
@ -105,10 +104,10 @@ fi
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Removing the dedicated system user" ynh_print_info --message="Removing the dedicated system user..."
# Delete a system user # Delete a system user
ynh_system_user_delete "$app" ynh_system_user_delete --username=$app
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN
@ -129,10 +128,10 @@ rm -R /home/yunohost.app/$app -f
If you facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh" If you facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh"
ynh_send_readme_to_admin "$message" ynh_send_readme_to_admin --app_message="$message"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Removal of $app completed" ynh_print_info --message="Removal of $app completed"

View file

@ -8,7 +8,6 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_add_extra_apt_repos__3 source ../settings/scripts/ynh_add_extra_apt_repos__3
source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,26 +23,27 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading settings..." ynh_print_info --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get "$app" final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get "$app" port) port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get "$app" psql_db) db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd) db_user=$app
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_print_info "Validating restoration parameters..." ynh_print_info --message="Validating restoration parameters..."
ynh_webpath_available "$domain" "$path_url" \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d "$final_path" \ test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
@ -51,22 +51,22 @@ test ! -d "$final_path" \
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restoring the app main directory..." ynh_print_info --message="Restoring the app main directory..."
ynh_restore_file "$final_path" ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Recreating the dedicated system user..." ynh_print_info --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create "$app" ynh_system_user_create --username=$app
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
@ -83,10 +83,10 @@ chown -R "$app":"$app" "/home/yunohost.app/${app}/storage"
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Reinstalling dependencies..." ynh_print_info --message="Reinstalling dependencies..."
# Install nodejs # Install nodejs
ynh_install_nodejs 8 ynh_install_nodejs --nodejs_version=8
# Install dependencies # Install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
@ -104,21 +104,19 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Restoring the PostgreSQL database..." ynh_print_info --message="Restoring the PostgreSQL database..."
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user "$app" "$db_pwd" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root \ ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
ynh_psql_execute_file_as_root ./db.sql "$db_name"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_print_info "Restoring the systemd configuration..." ynh_print_info --message="Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable "$app.service" systemctl enable $app.service
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
@ -126,30 +124,30 @@ systemctl enable "$app.service"
yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SERVICE
#=================================================
ynh_print_info "Start $app service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Restoration completed for $app" ynh_print_info --message="Restoration completed for $app"

View file

@ -8,54 +8,68 @@
source _common.sh source _common.sh
source ynh_add_extra_apt_repos__3 source ynh_add_extra_apt_repos__3
source ynh_systemd_action
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get "$app" is_public) is_public=$(ynh_app_setting_get --app=$app --key=is_public)
admin_email=$(ynh_app_setting_get "$app" admin_email) admin_email=$(ynh_app_setting_get --app=$app --key=admin_email)
final_path=$(ynh_app_setting_get "$app" final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get "$app" port) port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get "$app" psql_db) db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_print_info "Ensuring downward compatibility..." ynh_print_info --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value # Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set "$app" is_public 1 ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1 is_public=1
elif [ "$is_public" = "No" ]; then elif [ "$is_public" = "No" ]; then
ynh_app_setting_set "$app" is_public 0 ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0 is_public=0
fi fi
# Close a port # Close a port
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_print_info "Closing port $port" ynh_print_info --message="Closing port $port"
ynh_exec_warn_less yunohost firewall disallow TCP $port ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
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
# Remove repository # Remove repository
ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list ynh_secure_remove --file="/etc/apt/sources.list.d/jessie-backports.list"
ynh_secure_remove /etc/apt/sources.list.d/yarn.list ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list"
# Define app's data directory
datadir="/home/yunohost.app/${app}/storage"
# Create app folders
mkdir -p "$datadir"
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..." ynh_print_info --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -67,68 +81,48 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# STOP PEERTUBE FOR UPGRADE
#=================================================
ynh_print_info "Stop $app service..."
ynh_systemd_action --service_name="$app" --action="stop"
#===================================================
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
#===================================================
ynh_psql_execute_as_root "\connect $db_name
CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS pg_trgm;"
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Create a temporary directory
tmpdir="$(mktemp -d)"
# Backup the config file in the temp dir
cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
# Remove the app directory securely
ynh_secure_remove "$final_path"
# Define app's data directory
datadir="/home/yunohost.app/${app}/storage"
# Create app folders
mkdir -p "$datadir"
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src if [ "$upgrade_type" == "UPGRADE_APP" ]
ynh_setup_source "$final_path" then
ynh_print_info --message="Upgrading source files..."
#================================================= # Create a temporary directory
# MODIFY A CONFIG FILE tmpdir="$(mktemp -d)"
#=================================================
cp ../conf/production.yaml "$final_path/config/production.yaml" # Backup the config file in the temp dir
ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml" cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml" cp -a "$final_path/config/production.yaml" "$tmpdir/production.yaml"
ynh_replace_string "__app__" "$app" "$final_path/config/production.yaml"
ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.yaml"
ynh_replace_string "__email__" "$admin_email" "$final_path/config/production.yaml"
ynh_replace_string "__PORT__" "$port" "$final_path/config/production.yaml"
#Copy the admin saved settings from tmp directory to final path # Remove the app directory securely
cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json" ynh_secure_remove --file="$final_path"
# Remove the tmp directory securely # Download, check integrity, uncompress and patch the source from app.src
ynh_secure_remove "$tmpdir" ynh_setup_source --dest_dir="$final_path"
#Copy the admin saved settings from tmp directory to final path
cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json"
cp -a "$tmpdir/production.yaml" "$final_path/config/production.yaml"
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Upgrading nginx web server configuration..." ynh_print_info --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -136,10 +130,10 @@ ynh_add_nginx_config
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Upgrading dependencies..." ynh_print_info --message="Upgrading dependencies..."
# Install nodejs # Install nodejs
ynh_install_nodejs 8 ynh_install_nodejs --nodejs_version=8
# Install dependencies # Install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
@ -157,13 +151,32 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Making sure dedicated system user exists..." ynh_print_info --message="Making sure dedicated system user exists..."
# Create a system user # Create a system user
ynh_system_user_create "$app" ynh_system_user_create "$app"
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_backup_if_checksum_is_different --file="$final_path/config/local-production.json"
ynh_backup_if_checksum_is_different --file="$final_path/config/production.yaml"
cp ../conf/production.yaml "$final_path/config/production.yaml"
ynh_replace_string --match_string="__domain__" --replace_string="$domain" --target_file="$final_path/config/production.yaml"
ynh_replace_string --match_string="__db_name__" --replace_string="$app" --target_file="$final_path/config/production.yaml"
ynh_replace_string --match_string="__app__" --replace_string="$app" --target_file="$final_path/config/production.yaml"
ynh_replace_string --match_string="__db_pwd__" --replace_string="$db_pwd" --target_file="$final_path/config/production.yaml"
ynh_replace_string --match_string="__email__" --replace_string="$admin_email" --target_file="$final_path/config/production.yaml"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config/production.yaml"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/config/local-production.json"
ynh_store_file_checksum "$final_path/config/production.yaml"
#================================================= #=================================================
# BUILD YARN DEPENDENCIES # BUILD YARN DEPENDENCIES
#================================================= #=================================================
@ -172,14 +185,10 @@ pushd "$final_path"
yarn install --production --pure-lockfile yarn install --production --pure-lockfile
popd popd
ynh_backup_if_checksum_is_different "$final_path/config/production.yaml"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/config/production.yaml"
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Upgrading logrotate configuration..." ynh_print_info --message="Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
@ -187,9 +196,9 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Upgrading systemd configuration..." ynh_print_info --message="Upgrading systemd configuration..."
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -206,31 +215,31 @@ chown -R "$app":"$app" "$datadir"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Upgrading SSOwat configuration..." ynh_print_info --message="Upgrading SSOwat configuration..."
# Make app public if necessary # Make app public if necessary
if [ "$is_public" -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway # unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Start $app service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SERVICE
#=================================================
ynh_print_info "Start $app service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Upgrade of $app completed" ynh_print_info --message="Upgrade of $app completed"

View file

@ -0,0 +1,140 @@
#!/bin/bash
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
# | arg: -m --app_message= - The file with the content to send to the administrator.
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
ynh_send_readme_to_admin() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
local app_message
local recipients
local type
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
app_message="${app_message:-}"
recipients="${recipients:-root}"
type="${type:-install}"
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
# Subject base
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
# Adapt the subject according to the type of mail required.
if [ "$type" = "backup" ]; then
mail_subject="$mail_subject has just been backup."
elif [ "$type" = "change_url" ]; then
mail_subject="$mail_subject has just been moved to a new URL!"
elif [ "$type" = "remove" ]; then
mail_subject="$mail_subject has just been removed!"
elif [ "$type" = "restore" ]; then
mail_subject="$mail_subject has just been restored!"
elif [ "$type" = "upgrade" ]; then
mail_subject="$mail_subject has just been upgraded!"
else # install
mail_subject="$mail_subject has just been installed!"
fi
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$(if [ -n "$app_message" ]
then
cat "$app_message"
else
echo "...No specific information..."
fi)
---
Automatic diagnosis data from YunoHost
__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
# Store the message into a file for further modifications.
echo "$mail_message" > mail_to_send
# If a html email is required. Apply html tags to the message.
if [ "$admin_mail_html" -eq 1 ]
then
# Insert 'br' tags at each ending of lines.
ynh_replace_string "$" "<br>" mail_to_send
# Insert starting HTML tags
sed --in-place '1s@^@<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n@' mail_to_send
# Keep tabulations
ynh_replace_string " " "\&#160;\&#160;" mail_to_send
ynh_replace_string "\t" "\&#160;\&#160;" mail_to_send
# Insert url links tags
ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "<a href=\"\2\">\1</a>" mail_to_send
# Insert pre tags
ynh_replace_string "__PRE_TAG1__" "<pre>" mail_to_send
ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
# Insert finishing HTML tags
echo -e "\n</body>\n</html>" >> mail_to_send
# Otherwise, remove tags to keep a plain text.
else
# Remove URL tags
ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
ynh_replace_string "__URL_TAG2__" ": " mail_to_send
# Remove PRE tags
ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
fi
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
if [ "$admin_mail_html" -eq 1 ]
then
content_type="text/html"
else
content_type="text/plain"
fi
# Send the email to the recipients
cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
}

View file

@ -1,89 +0,0 @@
#!/bin/bash
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
#
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
# | arg: -n, --service_name= - Name of the service to reload. Default : $app
# | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20
ynh_systemd_action() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
local service_name
local action
local line_match
local length
local log_path
local timeout
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local service_name="${service_name:-$app}"
local action=${action:-start}
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
local length=${length:-20}
local timeout=${timeout:-300}
# Start to read the log
if [[ -n "${line_match:-}" ]]
then
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal
journalctl -u $service_name -f --since=-45 > "$templog" &
else
# Read the specified log file
tail -F -n0 "$log_path" > "$templog" &
fi
# Get the PID of the tail command
local pid_tail=$!
fi
echo "${action^} the service $service_name" >&2
systemctl $action $service_name \
|| ( journalctl --lines=$length -u $service_name >&2 \
; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
; false )
# Start the timeout and try to find line_match
if [[ -n "${line_match:-}" ]]
then
local i=0
for i in $(seq 1 $timeout)
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
journalctl --lines=$length -u $service_name >&2
test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
fi
echo ""
ynh_clean_check_starting
fi
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
#
# usage: ynh_clean_check_starting
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}