From 33ee5239838c1ffd68a0fd2e36b2a98f468a2221 Mon Sep 17 00:00:00 2001 From: liberodark Date: Wed, 20 Feb 2019 12:08:50 +0100 Subject: [PATCH] up --- README.md | 23 ++++++- check_process | 42 ++++++++++++ conf/app.src | 7 ++ conf/nginx.conf | 13 ++++ manifest.json | 58 +++++++++++++++++ scripts/_common.sh | 112 ++++++++++++++++++++++++++++++++ scripts/backup | 33 ++++++++++ scripts/install | 156 +++++++++++++++++++++++++++++++++++++++++++++ scripts/remove | 82 ++++++++++++++++++++++++ scripts/restore | 52 +++++++++++++++ scripts/upgrade | 56 ++++++++++++++++ 11 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 check_process create mode 100644 conf/app.src create mode 100644 conf/nginx.conf create mode 100644 manifest.json create mode 100644 scripts/_common.sh create mode 100644 scripts/backup create mode 100644 scripts/install create mode 100644 scripts/remove create mode 100644 scripts/restore create mode 100644 scripts/upgrade diff --git a/README.md b/README.md index 4e10d8a..cdbb911 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# cockpit_ynh \ No newline at end of file +# Cockpit app for YunoHost +Cockpit Server + +- [Yunohost project](https://yunohost.org) +- [Cockpit website](https://cockpit-project.org/) + +![](https://ia800109.us.archive.org/21/items/github.com-cockpit-project-cockpit_-_2018-02-23_15-25-16/cover.jpg) + + +[![Install Cockpit with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=cockpit) + +### Installing guide + + 1. App can be installed by YunoHost **admin web-interface** or by **running following command**: + + $ sudo yunohost app install https://github.com/YunoHost-Apps/cockpit_ynh + + +### Upgrade this package: + + $ sudo yunohost app upgrade cockpit -u https://github.com/YunoHost-Apps/cockpit_ynh + diff --git a/check_process b/check_process new file mode 100644 index 0000000..0cbeae3 --- /dev/null +++ b/check_process @@ -0,0 +1,42 @@ +# See here for more informations +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/" (PATH) + is_public=1 (PUBLIC|public=1|private=0) +# password="pass" +# nextclouddomain="domain.tld" + port="9980" (PORT) + ; Checks + pkg_linter=1 + setup_sub_dir=0 + setup_root=1 + setup_nourl=0 + setup_private=0 + setup_public=1 + upgrade=1 + backup_restore=1 + multi_instance=1 + incorrect_path=1 + port_already_use=0 + change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto +# Level 4: + Level 4=1 (This app supports the Nextcloud LDAP auth) +# Level 5: + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email= +Notification=none diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..506f768 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,7 @@ +SOURCE_URL=https://github.com/MediaBrowser/Emby.Releases/releases/download/4.0.2.0/emby-server-deb_4.0.2.0_amd64.deb +SOURCE_SUM=8048da68873d2da8c67c1abf73b5383dc82cef49e9182e9872f11e5127b3b987cf33e995d0956b0cb33d113ae37fef3b2357974b98e9a290fdf618f5a04f42b8 +SOURCE_SUM_PRG=sha512sum +SOURCE_FORMAT=deb +SOURCE_IN_SUBDIR=false +SOURCE_EXTRACT=false +SOURCE_FILENAME=emby-server-deb.deb diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..4193bce --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,13 @@ +location ^~ __PATH__/ { + proxy_pass http://127.0.0.1:__PORT__; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; +} \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..f6de0fd --- /dev/null +++ b/manifest.json @@ -0,0 +1,58 @@ +{ + "name": "EmbyServer", + "id": "embyserver", + "packaging_format": 1, + "description": { + "en": "EmbyServer package for YunoHost.", + "fr": "EmbyServer pour YunoHost." + }, + "version": "4.0.2.0", + "url": "https://emby.media/", + "license": "free", + "maintainer": { + "name": "liberodark", + "email": "liberodark@gmail.com" + }, + "requirements": { + "yunohost": ">= 2.7.2" + }, + "multi_instance": false, + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], + "arguments": { + "install": [{ + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for EmbyServer", + "fr": "Choisissez un nom de domaine pour EmbyServer" + }, + "example": "example.com" + }, + + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for EmbyServer /emby is accepted", + "fr": "Choisissez un chemin pour EmbyServer /emby est accepté" + }, + "example": "/emby", + "default": "/emby" + }, + + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public site ?", + "fr": "Est-ce un site public ?" + }, + "default": "true" + } + ] + } +} diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..0f53f77 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# ============================================================================= +# YUNOHOST 2.7 FORTHCOMING HELPERS +# ============================================================================= + +# Create a dedicated nginx config +# +# usage: ynh_add_nginx_config +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalnginxconf" + sudo cp ../conf/nginx.conf "$finalnginxconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${path_url:-}"; then + ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" + fi + if test -n "${domain:-}"; then + ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" + fi + if test -n "${port:-}"; then + ynh_replace_string "__PORT__" "$port" "$finalnginxconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__NAME__" "$app" "$finalnginxconf" + fi + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" + fi + ynh_store_file_checksum "$finalnginxconf" + + sudo systemctl reload nginx +} + +# Remove the dedicated nginx config +# +# usage: ynh_remove_nginx_config +ynh_remove_nginx_config () { + ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo systemctl reload nginx +} + +# Create a dedicated php-fpm config +# +# usage: ynh_add_fpm_config +ynh_add_fpm_config () { + finalphpconf="/etc/php5/fpm/pool.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalphpconf" + sudo cp ../conf/php-fpm.conf "$finalphpconf" + ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" + ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" + ynh_replace_string "__USER__" "$app" "$finalphpconf" + sudo chown root: "$finalphpconf" + ynh_store_file_checksum "$finalphpconf" + + if [ -e "../conf/php-fpm.ini" ] + then + finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" + ynh_backup_if_checksum_is_different "$finalphpini" + sudo cp ../conf/php-fpm.ini "$finalphpini" + sudo chown root: "$finalphpini" + ynh_store_file_checksum "$finalphpini" + fi + + sudo systemctl reload php5-fpm +} + +# Remove the dedicated php-fpm config +# +# usage: ynh_remove_fpm_config +ynh_remove_fpm_config () { + ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" + ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 + sudo systemctl reload php5-fpm +} + +# Create a dedicated systemd config +# +# usage: ynh_add_systemd_config +ynh_add_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + ynh_backup_if_checksum_is_different "$finalsystemdconf" + sudo cp ../conf/systemd.service "$finalsystemdconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__APP__" "$app" "$finalsystemdconf" + fi + ynh_store_file_checksum "$finalsystemdconf" + + sudo chown root: "$finalsystemdconf" + sudo systemctl enable $app + sudo systemctl daemon-reload +} + +# Remove the dedicated systemd config +# +# usage: ynh_remove_systemd_config +ynh_remove_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + if [ -e "$finalsystemdconf" ]; then + sudo systemctl stop $app + sudo systemctl disable $app + ynh_secure_remove "$finalsystemdconf" + fi +} diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..af8ccd9 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,33 @@ +#!/bin/bash + +# Exit on command errors and treat unset variables as an error +set -eu + +# See comments in install script +app=$YNH_APP_INSTANCE_NAME + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Backup sources & data +# Note: the last argument is where to save this path, see the restore script. +ynh_backup "/var/www/${app}" "sources" + +### MySQL (remove if not used) ### +# If a MySQL database is used: +# # Dump the database +# dbname=$app +# dbuser=$app +# dbpass=$(ynh_app_setting_get "$app" mysqlpwd) +# mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql +### MySQL end ### + +# Copy NGINX configuration +domain=$(ynh_app_setting_get "$app" domain) +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" + +### PHP (remove if not used) ### +# If a dedicated php-fpm process is used: +# # Copy PHP-FPM pool configuration +# ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf" +### PHP end ### diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..3cc412e --- /dev/null +++ b/scripts/install @@ -0,0 +1,156 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + ### Remove this function if there's nothing to clean before calling the remove script. + true +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +is_public=$YNH_APP_ARG_IS_PUBLIC + +### If it's 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 instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +### The app instance name is available as $YNH_APP_INSTANCE_NAME +### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +### - ynhexample__{N} for the subsequent installations, with N=3,4, ... +### The app instance name is probably what interests you most, since this is +### guaranteed to be unique. This is a good unique identifier to define installation path, +### db names, ... +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= + +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" +final_path=/opt/yunohost/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url +ynh_app_setting_set $app is_public $is_public + +#================================================= +# FIND AND OPEN A PORT +#================================================= + +### Use these lines if you have to open a port for the application +### `ynh_find_port` will find the first available port starting from the given port. +### If you're not using these lines: +### - Remove the section "CLOSE A PORT" in the remove script + +# Find a free port +port=$(ynh_find_port 8096) +# Open this port +yunohost firewall allow --no-upnp TCP $port 2>&1 +ynh_app_setting_set $app port $port + +#================================================= +# 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" + +#============================================== +# INSTALL EMBY +#============================================== + +dpkg --install $final_path/emby-server-deb* + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create $app + +#================================================= +# MODIFY A CONFIG FILE +#================================================= +#cp -a ../conf/onlyoffice-documentserver.conf /etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver.conf +#ynh_replace_string "__NEXTCLOUDDOMAIN__" "$nextcloud_domain" "/etc/loolwsd/loolwsd.xml" +#ynh_replace_string "__PASSWORD__" "$password" "/etc/loolwsd/loolwsd.xml" + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +### `ynh_store_file_checksum` is used to store the checksum of a file. +### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, +### you can make a backup of this file before modifying it again if the admin had modified it. + +# Calculate and store the config file checksum into the app settings +#ynh_store_file_checksum "/etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver.conf" + + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +### For security reason, any app should set the permissions to root: before anything else. +### Then, if write authorization is needed, any access should be given only to directories +### that really need such authorization. + +# Set permissions to app files +#chown -R root: /etc/loolwsd + + +#================================================= +# SETUP SSOWAT +#================================================= + +# If app is public, add url to SSOWat conf as skipped_uris +if [ $is_public -eq 1 ]; then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +# Reload services +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..19721ec --- /dev/null +++ b/scripts/remove @@ -0,0 +1,82 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +port=$(ynh_app_setting_get $app port) +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# STANDARD REMOVE +#================================================= + +ynh_package_remove emby-server + +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +#ynh_remove_app_dependencies + +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + echo "Close port $port" >&2 + yunohost firewall disallow TCP $port 2>&1 +fi + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= + +# Remove a cron file +ynh_secure_remove "/etc/cron.d/$app" + +# Remove a directory securely +ynh_secure_remove "/etc/apt/sources.list.d/onlyoffice.list" + + +# Remove the log files +ynh_secure_remove "/var/log/$app/" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete $app diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..93169e9 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,52 @@ +#!/bin/bash + +# Note: each files and directories you've saved using the ynh_backup helper +# will be located in the current directory, regarding the last argument. + +# Exit on command errors and treat unset variables as an error +set -eu + +# See comments in install script +app=$YNH_APP_INSTANCE_NAME + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Retrieve old app settings +domain=$(ynh_app_setting_get "$app" domain) +path_url=$(ynh_app_setting_get "$app" path_url) + +# Check domain/path availability +sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path_url}" + +# Restore sources & data +src_path="/var/www/${app}" +sudo cp -a ./sources "$src_path" + +# Restore permissions to app files +# you may need to make some file and/or directory writeable by www-data (nginx user) +sudo chown -R root: "$src_path" + +### MySQL (remove if not used) ### +# If a MySQL database is used: +# # Create and restore the database +# dbname=$app +# dbuser=$app +# dbpass=$(ynh_app_setting_get "$app" mysqlpwd) +# ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" +# ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql +### MySQL end ### + +# Restore NGINX configuration +sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" + +### PHP (remove if not used) ### +# If a dedicated php-fpm process is used: +# # Copy PHP-FPM pool configuration and reload the service +# sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf" +# sudo service php5-fpm reload +### PHP end ### + +# Restart webserver +sudo service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..3ad3f7a --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,56 @@ +#!/bin/bash + +# Exit on command errors and treat unset variables as an error +set -eu + +# See comments in install script +app=$YNH_APP_INSTANCE_NAME +final_path=/opt/yunohost/$app + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Stop emby-server service +systemctl stop emby-server + +#================================================= +# 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" + +#============================================== +# INSTALL PLEX +#============================================== + +dpkg --install $final_path/emby-server-deb* + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +#ynh_add_nginx_config + + +#================================================= +# UPGRADE CONFIG +#================================================= +#cp -a ../conf/loolwsd.xml /etc/loolwsd +#ynh_replace_string "__NEXTCLOUDDOMAIN__" "$nextcloud_domain" "/etc/loolwsd/loolwsd.xml" +#ynh_replace_string "__PASSWORD__" "$password" "/etc/loolwsd/loolwsd.xml" +#systemctl restart loolwsd + + + +# If app is public, add url to SSOWat conf as skipped_uris +#if [[ $is_public -eq 1 ]]; then + # See install script +# ynh_app_setting_set "$app" unprotected_uris "/" +#fi + +# Start emby-server service +systemctl start emby-server +