Merge pull request #22 from YunoHost-Apps/testing

Merge testing into master
This commit is contained in:
anmol26s 2018-06-05 20:23:48 +05:30 committed by GitHub
commit fbeccaf5c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 909 additions and 8116 deletions

View file

@ -1,26 +1,12 @@
# PeerTube app for YunoHost # PeerTube app for YunoHost
[![Install Peertube with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=Peertube)<br><br> [![Install Peertube with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=Peertube)<br><br>
=======
## Installation(Read it) **Shipped Version:** 1.0.0-beta.7
1. Require dedicated domain like **peertube.domain.tld**.
2. No LDAP support
3. No Multi-instance
4. No change-url possible.
5. Peertube is under development stage,don't use it for production
6. **Install the app by following command:**
$ yunohost app install https://github.com/YunoHost-Apps/peertube_ynh <h4>
7. **root** is the admin username and the admin email is the email address given at the time of installation. PeerTube is a decentralized video streaming platform using P2P (BitTorrent) directly in the web browser, using <a href="https://github.com/feross/webtorrent">WebTorrent</a>.
8. **After installation change the password by this command:**
$ cd /var/www/peertube && NODE_ENV=production npm run reset-password -- -u root
<h1 align="center">
PeerTube
</h1>
<h4 align="center">
Decentralized video streaming platform using P2P (BitTorrent) directly in the web browser with <a href="https://github.com/feross/webtorrent">WebTorrent</a>.
</h4> </h4>
**PeerTube is sponsored by [Framasoft](https://framatube.org/#en), a non-profit that promotes, spreads and develops free-libre software. If you want to support this project, please [consider donating them](https://soutenir.framasoft.org/en/).** **PeerTube is sponsored by [Framasoft](https://framatube.org/#en), a non-profit that promotes, spreads and develops free-libre software. If you want to support this project, please [consider donating them](https://soutenir.framasoft.org/en/).**
@ -29,32 +15,60 @@ Decentralized video streaming platform using P2P (BitTorrent) directly in the we
Want to see in action? Want to see in action?
* [Demo server](http://peertube.cpy.re) * [Demo](http://peertube.cpy.re)
* [Video](https://peertube.cpy.re/videos/watch/f78a97f8-a142-4ce1-a5bd-154bf9386504) to see how the "decentralization feature" looks like * [Video](https://peertube.cpy.re/videos/watch/f78a97f8-a142-4ce1-a5bd-154bf9386504) to see how the "decentralization feature" looks like
* [Video](https://peertube.valvin.fr/videos/watch/e510b421-92f3-4153-aaf9-baf5166f43e8) showcasing A2HS
## Why
## Installation
### Guidelines
1. Require dedicated domain like **peertube.domain.tld**.
1. No LDAP support (blocked until upstream implements it)
1. URL can not be changed once selected.
1. Take notice that this YunoHost package *claims* the following features:
- [x] Install
- [x] Remove
- [X] Upgrade
- [X] Backup
- [X] Restore
- [X] Multi-instance
### Install
1. **App can be installed by YunoHost admin interface or by the following command:**
$ sudo yunohost app install https://github.com/YunoHost-Apps/peertube_ynh
1. **root** is the admin username.
1. **root Password** will be sent to the email address given at the time of the installation.
1. **TLS** and **starttls** are disabled for the outgoing mails. If you intent to use email address not hosted on your local server,it's advised to have a proper SMTP configured with tls and starttls settings by editing **/var/www/peertube/config/porduction.yml**.
### Updation
1. **App can be updated by YunoHost admin interface or by the following command:**
$ sudo yunohost app upgrade -u https://github.com/YunoHost-Apps/peertube_ynh peertube
1. App will backup the **home directory** for Peertube before updating which can take a lot of space on the system. It's advised to check the home folder's free space by
$ df -h "/home" | awk 'NR==2 { print $4 }'
and comapre it with space occupied by the Peertube home directory before updating.
$ du -hcs /home/yunohost.app/peertube | awk 'NR==2 { print $1 }'
## Why
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.
So we need to have a decentralized network (as [Hubzilla](https://project.hubzilla.org/page/hubzilla/hubzilla-project)([Hubzilla YunoHost](https://github.com/YunoHost-Apps/hubzilla_ynh)),[Friendica](http://friendi.ca/)([Friendica YunoHost](https://github.com/YunoHost-Apps/friendica_ynh)),[Mastodon](https://github.com/tootsuite/mastodon)([Mastodon YunoHost](https://github.com/YunoHost-Apps/mastodon_ynh)),[Diaspora](https://github.com/diaspora/diaspora)([Diaspora YunoHost](https://github.com/YunoHost-Apps/diaspora_ynh))). So we need to have a decentralized network (as [Hubzilla](https://project.hubzilla.org/page/hubzilla/hubzilla-project) ([Hubzilla YunoHost](https://github.com/YunoHost-Apps/hubzilla_ynh)), [Friendica](http://friendi.ca/) ([Friendica YunoHost](https://github.com/YunoHost-Apps/friendica_ynh)), [Mastodon](https://github.com/tootsuite/mastodon) ([Mastodon YunoHost](https://github.com/YunoHost-Apps/mastodon_ynh)), [Diaspora](https://github.com/diaspora/diaspora) ([Diaspora YunoHost](https://github.com/YunoHost-Apps/diaspora_ynh)),[Funkwhale](https://funkwhale.audio) ([Funkwhale YunoHost](https://github.com/YunoHost-Apps/funkwhale_ynh))).
But it's not enough because one video could become famous and overload the server. But it's not enough because one video could become famous and overload the server.
It's the reason why we need to use a P2P protocol to limit the server load. It's the reason why we need to use a P2P protocol to limit the server load.
Thanks to [WebTorrent](https://github.com/feross/webtorrent), we can make P2P (thus bittorrent) inside the web browser right now. Thanks to [WebTorrent](https://github.com/feross/webtorrent), we can make P2P (thus bittorrent) inside the web browser right now.
### Dependencies ### Dependencies
* **NodeJS >= 6.x** * NodeJS, PostgreSQL.
* **npm >= 3.x** * On Debian Jessie,backport is added for the ffmpeg package.
* yarn
* OpenSSL (cli)
* PostgreSQL
* FFmpeg
## LICENSE
## Features PeerTube is licensed under the GNU Affero General Public License v3.0.
- [X] Install
- [X] Remove
- [ ] Upgrade
- [ ] Backup
- [ ] Restore

View file

@ -16,9 +16,9 @@
setup_nourl=0 setup_nourl=0
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=0 upgrade=1
backup_restore=0 backup_restore=1
multi_instance=0 multi_instance=1
incorrect_path=0 incorrect_path=0
port_already_use=1 port_already_use=1
change_url=0 change_url=0
@ -26,8 +26,8 @@
Level 1=auto Level 1=auto
Level 2=auto Level 2=auto
Level 3=auto Level 3=auto
# Level 4: # Level 4: not supported by upstream
Level 4=0 Level 4=1
# Level 5: # Level 5:
Level 5=auto Level 5=auto
Level 6=auto Level 6=auto
@ -36,5 +36,5 @@
Level 9=0 Level 9=0
Level 10=0 Level 10=0
;;; Options ;;; Options
Email= Email=anmol@datamol.org
Notification=none Notification=yes

View file

@ -1,6 +1,6 @@
SOURCE_URL=https://github.com/Chocobozzz/PeerTube/archive/develop.zip SOURCE_URL=https://github.com/Chocobozzz/PeerTube/releases/download/v1.0.0-beta.7/peertube-v1.0.0-beta.7.tar.xz
SOURCE_SUM=f7266fc1cb2a127902707ccc0978b4ae5f7a08c1e089feb479a78e3410872ec0 SOURCE_SUM=f4764d122d10e31cad9ee0b0dda4cd150c99278ff070c3d6b650247d4fdc9fe4
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip SOURCE_FORMAT=tar.xz
SOURCE_IN_SUBDIR= SOURCE_IN_SUBDIR=true
SOURCE_FILENAME= SOURCE_FILENAME=

1
conf/backports.list Normal file
View file

@ -0,0 +1 @@
deb http://httpredir.debian.org/debian jessie-backports main

View file

@ -1,18 +1,37 @@
location / { location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
add_header Cache-Control "public, max-age=31536000, immutable";
alias __FINALPATH__/client/dist/$1;
}
location ~ ^/static/(thumbnails|avatars)/(.*)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
alias /home/yunohost.app/__NAME__/storage/$1/$2;
}
location / {
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
} }
proxy_pass http://localhost:9000; proxy_pass http://localhost:__PORT__;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# For the video upload # Hard limit, PeerTube does not support videos > 4GB
client_max_body_size 2G; client_max_body_size 4G;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
} }
# Bypass PeerTube webseed route for better performances # Bypass PeerTube webseed route for better performances
location /static/webseed { location /static/webseed {
# Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
limit_rate 800k;
if ($request_method = 'OPTIONS') { if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
@ -27,9 +46,12 @@ location / {
add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
# Don't spam access log file with byte range requests
access_log off;
} }
alias __FINALPATH__/videos; alias /home/yunohost.app/__NAME__/storage/videos;
} }
# Websocket tracker # Websocket tracker
@ -42,5 +64,5 @@ location / {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_pass http://localhost:9000; proxy_pass http://localhost:__PORT__;
} }

View file

@ -1,29 +1,69 @@
listen: listen:
port: 9000 hostname: 'localhost'
port: __PORT__
# Correspond to your reverse proxy "listen" configuration # Correspond to your reverse proxy "listen" configuration
webserver: webserver:
https: true https: true
hostname: '__domain__' hostname: '__domain__'
port: 443 port: 443
# Proxies to trust to get real client IP
# 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)
trust_proxy:
- 'loopback'
# Your database name will be "peertube"+database.suffix # Your database name will be "peertube"+database.suffix
database: database:
hostname: 'localhost' hostname: 'localhost'
port: 5432 port: 5432
suffix: '_prod' suffix: '___db_name__'
username: 'peertube' username: '__db_name__'
password: '__db_pwd__' password: '__db_pwd__'
# Your object store
redis:
hostname: 'localhost'
port: 6379
auth: null
# SMTP server to send emails
smtp:
hostname: 'localhost'
port: 25
username: null
password: null
tls: false
disable_starttls: true
ca_file: null # Used for self signed certificates
from_address: 'admin@__domain__'
# From the project root directory # From the project root directory
storage: storage:
certs: 'certs/' avatars: '/home/yunohost.app/__app__/storage/avatars/'
videos: 'videos/' videos: '/home/yunohost.app/__app__/storage/videos/'
logs: 'logs/' logs: '/home/yunohost.app/__app__/storage/logs/'
previews: 'previews/' previews: '/home/yunohost.app/__app__/storage/previews/'
thumbnails: 'thumbnails/' thumbnails: '/home/yunohost.app/__app__/storage/thumbnails/'
torrents: 'torrents/' torrents: '/home/yunohost.app/__app__/storage/torrents/'
cache: 'cache/' cache: '/home/yunohost.app/__app__/storage/cache/'
log:
level: 'info' # debug/info/warning/error
###############################################################################
#
# From this point, all the following keys can be overriden by the web interface
# (local-production.json file). If you need to change some values, prefer to
# use the web interface because the configuration will be automatically
# reloaded without any need to restart PeerTube.
#
# /!\ If you already have a local-production.json file, the modification of the
# following keys will have no effect /!\.
#
###############################################################################
cache: cache:
previews: previews:
@ -35,6 +75,10 @@ admin:
signup: signup:
enabled: false enabled: false
limit: 10 # When the limit is reached, registrations are disabled. -1 == unlimited limit: 10 # When the limit is reached, registrations are disabled. -1 == unlimited
filters:
cidr: # You can specify CIDR ranges to whitelist (empty = no filtering) or blacklist
whitelist: []
blacklist: []
user: user:
# Default value of maximum video BYTES the user can upload (does not take into account transcoded files). # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).
@ -45,10 +89,37 @@ user:
# Uses a lot of CPU! # Uses a lot of CPU!
transcoding: transcoding:
enabled: false enabled: false
threads: 2 threads: 1
resolutions: # Only created if the original video has a higher resolution resolutions: # Only created if the original video has a higher resolution
240p: true 240p: false
360p: true 360p: false
480p: true 480p: false
720p: true 720p: false
1080p: true 1080p: false
# Instance settings
instance:
name: 'PeerTube'
short_description: 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.'
description: '' # Support markdown
terms: '' # Support markdown
default_client_route: '/videos/trending'
# By default, "do_not_list" or "blur" or "display" NSFW videos
# Could be overridden per user with a setting
default_nsfw_policy: 'do_not_list'
customizations:
javascript: '' # Directly your JavaScript code (without <script> tags). Will be eval at runtime
css: '' # Directly your CSS code (without <style> tags). Will be injected at runtime
# Robot.txt rules. To disallow robots to crawl your instance and disallow indexation of your site, add '/' to "Disallow:'
robots: |
User-agent: *
Disallow: ''
services:
# Cards configuration to format video in Twitter
twitter:
username: '' # The Twitter @username the card should be attributed to
# If true, a video player will be embedded in the Twitter feed on PeerTube video share
# 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
whitelisted: false

View file

@ -4,13 +4,14 @@ Description=PeerTube daemon
[Service] [Service]
Type=simple Type=simple
Environment=NODE_ENV=production Environment=NODE_ENV=production
Environment=NODE_CONFIG_DIR=__FINALPATH__/config
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
ExecStart=/usr/bin/npm start ExecStart=/bin/sh -c 'PATH=/opt/node_n/bin:$PATH exec npm start'
WorkingDirectory=__FINALPATH__/ WorkingDirectory=__FINALPATH__/
StandardOutput=syslog StandardOutput=syslog
StandardError=syslog StandardError=syslog
SyslogIdentifier=peertube SyslogIdentifier=__APP__
Restart=always Restart=always
[Install] [Install]

File diff suppressed because it is too large Load diff

View file

@ -3,23 +3,21 @@
"id": "peertube", "id": "peertube",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
"en": "Peertube is a p2p video sharing app which works in browser too" "en": "Video streaming platform using P2P directly in the web browser, connected to a federated network"
}, },
"version": "1.0", "version": "1.0.0-beta.7",
"url": "https://github.com/Chocobozzz/PeerTube", "url": "https://github.com/Chocobozzz/PeerTube",
"license": "AGPL", "license": "AGPL-3.0-only",
"maintainer": { "maintainer": {
"name": "Anmol Sharma", "name": "Anmol Sharma",
"email": "anmol@datamol.org" "email": "anmol@datamol.org"
}, },
"requirements": { "requirements": {
"yunohost": ">= 2.7.2" "yunohost": ">= 2.7.9"
}, },
"multi_instance": false, "multi_instance": true,
"services": [ "services": [
"nginx", "nginx"
"nodejs",
"postgresql"
], ],
"arguments": { "arguments": {
"install" : [ "install" : [
@ -34,7 +32,7 @@
{ {
"name": "email", "name": "email",
"ask": { "ask": {
"en": "Choose an admin(root) email(Can be other then LDAP emails and can't be changed after installation)" "en": "Choose an admin email (can be changed after installation)"
}, },
"example": "johndoe@example.com" "example": "johndoe@example.com"
}, },

View file

@ -11,3 +11,60 @@ ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name ynh_app_setting_delete $app $checksum_setting_name
} }
# 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\` was just installed!"
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"
}

88
scripts/backup Normal file
View file

@ -0,0 +1,88 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
cp ../settings/scripts/psql.sh ./psql.sh
chmod a+rx _common.sh psql.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
source psql.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get "$app" final_path)
domain=$(ynh_app_setting_get "$app" domain)
db_name=$(ynh_app_setting_get "$app" psql_db)
# Stop Peertube for backup
systemctl stop "$app"
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
# Copy the data directory
datadir="/home/yunohost.app/${app}/storage"
ynh_backup "$datadir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PostgreSQL DATABASE
#=================================================
ynh_psql_dump_db "$db_name" > db.sql
ynh_backup "db.sql"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx
systemctl enable "$app"
systemctl start "$app"
# App needs time to start
sleep 30

View file

@ -7,9 +7,8 @@
#================================================= #=================================================
source _common.sh source _common.sh
source psql.sh
source nodejs.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source psql.sh
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
@ -25,8 +24,10 @@ 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)
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
# This is a multi-instance app, meaning it can be installed several times independently # This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID # The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) # The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
@ -47,17 +48,18 @@ final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Check web path availability # Check web path availability
ynh_webpath_available $domain $path_url ynh_webpath_available "$domain" "$path_url"
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register "$app" "$domain" "$path_url"
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_app_setting_set $app domain $domain ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set $app admin_email $admin_email ynh_app_setting_set "$app" admin_email "$admin_email"
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set "$app" admin_pass "$admin_pass"
ynh_app_setting_set "$app" is_public "$is_public"
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -67,82 +69,108 @@ ynh_app_setting_set $app is_public $is_public
# Find a free port # Find a free port
port=$(ynh_find_port 9000) port=$(ynh_find_port 9000)
# Open this port # Open this port
yunohost firewall allow Both $port 2>&1 yunohost firewall allow Both "$port" 2>&1
ynh_app_setting_set $app port $port ynh_app_setting_set "$app" port "$port"
#=================================================
# CREATE THE DATA DIRECTORY
#=================================================
# Define app's data directory
datadir="/home/yunohost.app/${app}/storage"
# Create app folders
mkdir -p "$datadir"
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_install_app_dependencies postgresql-9.4 yarn ffmpeg # install nodejs
ynh_install_nodejs 8 ynh_install_nodejs 8
# install yarn
wget -nv https://github.com/yarnpkg/yarn/releases/download/v1.6.0/yarn_1.6.0_all.deb
echo "96866d835da94a1f01a616f3d637c9100e826f65cb38a65e5d96ccf01ff6d692 yarn_1.6.0_all.deb" | sha256sum -c || ynh_die
dpkg -i yarn_1.6.0_all.deb
# add backports for Debian Jessie (required to install ffmpeg)
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list
ynh_package_update
fi
# install postgresql, ffmpeg, redis
ynh_install_app_dependencies postgresql ffmpeg redis-server redis-tools mailutils
#=================================================
# DATABASE SETUP
#=================================================
# Create postgresql database # Create postgresql database
db_name="peertube_prod" db_name="peertube_${app}"
db_pwd=$(ynh_string_random 30) db_pwd=$(ynh_string_random 30)
ynh_app_setting_set $app psql_db $db_name ynh_app_setting_set "$app" psql_db "$db_name"
ynh_app_setting_set $app psqlpwd $db_pwd ynh_app_setting_set "$app" psqlpwd "$db_pwd"
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user $app $db_pwd ynh_psql_create_user "$app" "$db_pwd"
ynh_psql_execute_as_root \ ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
cp -f ../conf/yarn.lock $final_path/client/yarn.lock
cp ../conf/production.yaml $final_path/config/.
(cd $final_path && yarn install)
(cd $final_path && npm run build)
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
# Create a system user # Create a system user
ynh_system_user_create $app ynh_system_user_create "$app"
#================================================= #=================================================
# SPECIFIC SETUP # DOWNLOAD, CHECK AND UNPACK PEERTUBE SOURCE
#=================================================
# ...
#================================================= #=================================================
ynh_app_setting_set "$app" final_path "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#================================================= #=================================================
# SETUP APPLICATION WITH CURL # BUILD YARN DEPENDENCIES
#================================================= #=================================================
cp ../conf/production.yaml "$final_path/config/production.yaml"
touch "$final_path/config/local-production.json"
(
cd "$final_path"
yarn install --production --pure-lockfile --silent --cache-folder /var/cache/yarn/
)
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
mkdir -p "/etc/nginx/conf.d/${domain}.d"
ynh_add_nginx_config
# Set right permissions for curl install # Set right permissions for curl install
chown -R $app:$app $final_path chown -R "$app":"$app" "$datadir"
# Reload Nginx # Reload Nginx
systemctl reload nginx systemctl reload nginx
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml" ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml"
ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml" ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml"
ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.yaml" ynh_replace_string "__app__" "$app" "$final_path/config/production.yaml"
ynh_replace_string "__email__" "$admin_email" "$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"
#================================================= #=================================================
@ -160,34 +188,63 @@ ynh_store_file_checksum "$final_path/config/production.yaml"
#================================================= #=================================================
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
if [ $is_public -eq 0 ] if [ "$is_public" -eq 0 ]
then # Remove the public access then # Remove the public access
ynh_app_setting_delete $app skipped_uris ynh_app_setting_delete "$app" skipped_uris
fi fi
# 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" unprotected_uris "/"
fi fi
# Give permisiion to the final_path
chown -R "$app":"$app" "$final_path" "$datadir"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
sudo systemctl start peertube systemctl enable "$app"
systemctl start "$app"
#=================================================
# CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN
#=================================================
# we need to wait for the service to init peertube's database
(
cd "$final_path"
sleep 30
echo $admin_pass | NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production PATH="/opt/node_n/bin:$PATH" npm run reset-password -- -u root
)
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
systemctl reload nginx systemctl reload nginx
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
message="PeerTube was successfully installed :)
Please open 'https://$domain$path_url'
Here is the admin password: '$admin_pass'
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/peertube_ynh"
ynh_send_readme_to_admin "$message"

View file

@ -1,9 +1,50 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
#
# POSTGRES HELPERS # POSTGRES HELPERS
#
# Point of contact : Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
#================================================= #=================================================
# Create a master password and set up global settings
# Please always call this script in install and restore scripts
#
# usage: ynh_psql_test_if_first_run
ynh_psql_test_if_first_run() {
if [ -f /etc/yunohost/psql ];
then
echo "PostgreSQL is already installed, no need to create master password"
else
pgsql=$(ynh_string_random)
pg_hba=""
echo "$pgsql" >> /etc/yunohost/psql
if [ -e /etc/postgresql/9.4/ ]
then
pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
elif [ -e /etc/postgresql/9.6/ ]
then
pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
else
ynh_die "postgresql shoud be 9.4 or 9.6"
fi
systemctl start postgresql
sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$pgsql'" postgres
# force all user to connect to local database using passwords
# https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF
# Note: we can't use peer since YunoHost create users with nologin
# See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user
sed -i '/local\s*all\s*all\s*peer/i \
local all all password' "$pg_hba"
systemctl enable postgresql
systemctl reload postgresql
fi
}
# Open a connection as a user # Open a connection as a user
# #
# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" # example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"
@ -14,7 +55,10 @@
# | arg: pwd - the user password # | arg: pwd - the user password
# | arg: db - the database to connect to # | arg: db - the database to connect to
ynh_psql_connect_as() { ynh_psql_connect_as() {
ynh_die "ynh_psql_connect_as is not yet implemented" user="$1"
pwd="$2"
db="$3"
sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$pwd" psql "$db"
} }
# # Execute a command as root user # # Execute a command as root user
@ -23,8 +67,8 @@ ynh_psql_connect_as() {
# | arg: sql - the SQL command to execute # | arg: sql - the SQL command to execute
# | arg: db - the database to connect to # | arg: db - the database to connect to
ynh_psql_execute_as_root () { ynh_psql_execute_as_root () {
sudo su -c "psql" - postgres <<< ${1} sql="$1"
#TODO support db argument ? sudo --login --user=postgres psql <<< "$sql"
} }
# Execute a command from a file as root user # Execute a command from a file as root user
@ -33,33 +77,54 @@ ynh_psql_execute_as_root () {
# | arg: file - the file containing SQL commands # | arg: file - the file containing SQL commands
# | arg: db - the database to connect to # | arg: db - the database to connect to
ynh_psql_execute_file_as_root() { ynh_psql_execute_file_as_root() {
ynh_die "ynh_psql_execute_file_as_root is not yet implemented" file="$1"
db="$2"
sudo --login --user=postgres psql "$db" < "$file"
} }
# Create a database and grant optionnaly privilegies to a user # Create a database, an user and its password. Then store the password in the app's config
#
# After executing this helper, the password of the created database will be available in $db_pwd
# It will also be stored as "psqlpwd" into the app settings.
#
# usage: ynh_psql_setup_db user name [pwd]
# | arg: user - Owner of the database
# | arg: name - Name of the database
# | arg: pwd - Password of the database. If not given, a password will be generated
ynh_psql_setup_db () {
db_user="$1"
db_name="$2"
new_db_pwd=$(ynh_string_random) # Generate a random password
# If $3 is not given, use new_db_pwd instead for db_pwd.
db_pwd="${3:-$new_db_pwd}"
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config
}
# Create a database and grant privilegies to a user
# #
# usage: ynh_psql_create_db db [user [pwd]] # usage: ynh_psql_create_db db [user [pwd]]
# | arg: db - the database name to create # | arg: db - the database name to create
# | arg: user - the user to grant privilegies # | arg: user - the user to grant privilegies
# | arg: pwd - the password to identify user by # | arg: pwd - the user password
ynh_psql_create_db() { ynh_psql_create_db() {
db=$1 db="$1"
# grant all privilegies to user user="$2"
if [[ $# -gt 1 ]]; then pwd="$3"
ynh_psql_create_user ${2} "${3}" ynh_psql_create_user "$user" "$pwd"
sudo su -c "createdb -O ${2} $db" - postgres sudo --login --user=postgres createdb --owner="$user" "$db"
else
sudo su -c "createdb $db" - postgres
fi
} }
# Drop a database # Drop a database
# #
# usage: ynh_psql_drop_db db # usage: ynh_psql_drop_db db
# | arg: db - the database name to drop # | arg: db - the database name to drop
ynh_psql_drop_db() { # | arg: user - the user to drop
sudo su -c "dropdb ${1}" - postgres ynh_psql_remove_db() {
db="$1"
user="$2"
sudo --login --user=postgres dropdb "$db"
ynh_psql_drop_user "$user"
} }
# Dump a database # Dump a database
@ -70,7 +135,8 @@ ynh_psql_drop_db() {
# | arg: db - the database name to dump # | arg: db - the database name to dump
# | ret: the psqldump output # | ret: the psqldump output
ynh_psql_dump_db() { ynh_psql_dump_db() {
ynh_die "ynh_psql_dump_db is not yet implemented" db="$1"
sudo --login --user=postgres pg_dump "$db"
} }
@ -78,10 +144,10 @@ ynh_psql_dump_db() {
# #
# usage: ynh_psql_create_user user pwd [host] # usage: ynh_psql_create_user user pwd [host]
# | arg: user - the user name to create # | arg: user - the user name to create
# | arg: pwd - the password to identify user by
ynh_psql_create_user() { ynh_psql_create_user() {
ynh_psql_execute_as_root \ user="$1"
"CREATE USER ${1} WITH PASSWORD '${2}';" pwd="$2"
sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres
} }
# Drop a user # Drop a user
@ -89,22 +155,6 @@ ynh_psql_create_user() {
# usage: ynh_psql_drop_user user # usage: ynh_psql_drop_user user
# | arg: user - the user name to drop # | arg: user - the user name to drop
ynh_psql_drop_user() { ynh_psql_drop_user() {
sudo su -c "dropuser ${1}" - postgres user="$1"
} sudo --login --user=postgres dropuser "$user"
}
ynh_psql_test_if_first_run() {
if [ -f /etc/yunohost/psql ];
then
echo "PostgreSQL is already installed, no need to create master password"
else
local pgsql=$(ynh_string_random)
echo "$pgsql" >> /etc/yunohost/psql
systemctl start postgresql
sudo -u postgres psql -c"ALTER user postgres WITH PASSWORD '${pgsql}'"
# we can't use peer since YunoHost create users with nologin
sed -i '/local\s*all\s*all\s*peer/i \
local all all password' /etc/postgresql/9.4/main/pg_hba.conf
systemctl enable postgresql
systemctl reload postgresql
fi
}

View file

@ -7,9 +7,8 @@
#================================================= #=================================================
source _common.sh source _common.sh
source psql.sh
source nodejs.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source psql.sh
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
@ -17,10 +16,10 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get "$app" domain)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get "$app" port)
db_name=$(ynh_app_setting_get $app psql_db) db_name=$(ynh_app_setting_get "$app" psql_db)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get "$app" final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -35,33 +34,38 @@ ynh_remove_systemd_config
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE FROM ADMIN PANEL
#================================================= #=================================================
if yunohost service status | grep -q $app if yunohost service status | grep -q "$app"
then then
echo "Remove $app service" echo "Remove $app service"
yunohost service remove $app yunohost service remove "$app"
fi fi
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
ynh_remove_nodejs ynh_remove_nodejs
# Remove yarn
sudo apt-get remove --purge -y yarn
# Delete backport from source.list
ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list
#================================================= #=================================================
# REMOVE THE MYSQL DATABASE # REMOVE THE MYSQL DATABASE
#================================================= #=================================================
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_psql_drop_db $db_name ynh_psql_remove_db "$db_name" "$app"
ynh_psql_drop_user $app
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove "$final_path"
ynh_secure_remove /home/yunohost.app/"$app"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
@ -77,6 +81,7 @@ ynh_remove_nginx_config
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
ynh_secure_remove /var/log/"$app" ynh_secure_remove /var/log/"$app"
#================================================= #=================================================
# CLOSE A PORT # CLOSE A PORT
#================================================= #=================================================
@ -84,7 +89,7 @@ ynh_secure_remove /var/log/"$app"
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
echo "Close port $port" echo "Close port $port"
yunohost firewall disallow TCP $port 2>&1 yunohost firewall disallow Both "$port" 2>&1
fi fi
#================================================= #=================================================
@ -98,4 +103,4 @@ fi
#================================================= #=================================================
# Delete a system user # Delete a system user
ynh_system_user_delete $app ynh_system_user_delete "$app"

155
scripts/restore Normal file
View file

@ -0,0 +1,155 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
cp ../settings/scripts/psql.sh ./psql.sh
chmod a+rx _common.sh psql.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
source psql.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url="/"
final_path=$(ynh_app_setting_get "$app" final_path)
port=$(ynh_app_setting_get "$app" port)
db_name=$(ynh_app_setting_get "$app" psql_db)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available "$domain" "$path_url" \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d "$final_path" \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
datadir="/home/yunohost.app/${app}/storage"
ynh_restore_file "$datadir"
# Open this port
yunohost firewall allow Both "$port" 2>&1
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create "$app"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Set right permissions
datadir="/home/yunohost.app/${app}/storage"
chown -R "$app":"$app" "$datadir"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# install yarn
# install nodejs
ynh_install_nodejs 8
wget -nv https://github.com/yarnpkg/yarn/releases/download/v1.6.0/yarn_1.6.0_all.deb
echo "96866d835da94a1f01a616f3d637c9100e826f65cb38a65e5d96ccf01ff6d692 yarn_1.6.0_all.deb" | sha256sum -c || ynh_die
dpkg -i yarn_1.6.0_all.deb
# add backports for Debian Jessie (required to install ffmpeg)
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list
ynh_package_update
fi
# Define and install dependencies
ynh_install_app_dependencies postgresql ffmpeg redis-server redis-tools mailutils
#=================================================
# RESTORE THE PostgreSQL DATABASE
#=================================================
ynh_psql_test_if_first_run
ynh_psql_create_user "$app" "$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_file_as_root ./db.sql "$db_name"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable "$app.service"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
(
cd "$final_path"
yarn install --production --pure-lockfile --silent --cache-folder /var/cache/yarn/
)
# Set right permissions for curl install
chown -R "$app":"$app" "$datadir"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PeerTube
#=================================================
systemctl reload nginx
systemctl enable "$app"
systemctl start "$app"
# App needs time to start
sleep 30

201
scripts/upgrade Normal file
View file

@ -0,0 +1,201 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
source psql.sh
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url="/"
is_public=$(ynh_app_setting_get "$app" is_public)
admin_email=$(ynh_app_setting_get "$app" admin_email)
final_path=$(ynh_app_setting_get "$app" final_path)
port=$(ynh_app_setting_get "$app" port)
db_name=$(ynh_app_setting_get "$app" psql_db)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set "$app" is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set "$app" is_public 0
is_public=0
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Stop Peertube for upgrade
systemctl stop "$app"
#=================================================
# 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"
# Open this port
yunohost firewall allow Both "$port" 2>&1
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create "$app"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
# install nodejs
ynh_install_nodejs 8
# install yarn
wget -nv https://github.com/yarnpkg/yarn/releases/download/v1.6.0/yarn_1.6.0_all.deb
echo "96866d835da94a1f01a616f3d637c9100e826f65cb38a65e5d96ccf01ff6d692 yarn_1.6.0_all.deb" | sha256sum -c || ynh_die
dpkg -i yarn_1.6.0_all.deb
# add backports for Debian Jessie (required to install ffmpeg)
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list
ynh_package_update
fi
# install postgresql, ffmpeg, redis
ynh_install_app_dependencies postgresql ffmpeg redis-server redis-tools mailutils
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path "$path_url")
#=================================================
# DOWNLOAD, CHECK AND UNPACK PEERTUBE SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
cp ../conf/production.yaml "$final_path/config/production.yaml"
#Copy the admin saved settings from tmp directory to final path
cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json"
# Remove the tmp directory securely
ynh_secure_remove "$tmpdir"
(
cd "$final_path"
yarn install --production --pure-lockfile --silent --cache-folder /var/cache/yarn/
)
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
chown -R root:root "$final_path"
chown -R "$app" "$datadir"
# Reload Nginx
systemctl reload nginx
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml"
ynh_replace_string "__db_name__" "$app" "$final_path/config/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"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config/production.yaml"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
# Set right permissions
chown -R "$app":"$app" "$final_path" "$datadir"
#=================================================
# SETUP SSOWAT
#=================================================
if [ "$is_public" -eq 0 ]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [ "$is_public" -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set "$app" unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx
systemctl enable "$app"
systemctl start "$app"
# App needs time to start
sleep 30