1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/airsonic_ynh.git synced 2024-09-03 18:06:14 +02:00

First commit

Hello there!
This commit is contained in:
Gofannon 2019-02-06 19:37:46 +01:00
commit 88b7054a91
18 changed files with 1168 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*~
*.sw[op]

4
LICENSE Normal file
View file

@ -0,0 +1,4 @@
File containing the license of your package.
More information here:
https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13---indiquer-la-licence-associ%C3%A9e-au-paquet---brouillon--auto--working-

82
README.md Normal file
View file

@ -0,0 +1,82 @@
# Usage of this package (REMOVE THIS SECTION BEFORE RELEASE)
- Copy this app before working on it.
- Edit `conf/nginx.conf` file to match application prerequisites.
- Edit `manifest.json` with application specific information.
- Edit the `install`, `upgrade`, `remove`, `backup`, and `restore` scripts.
- Add a `LICENSE` file for the package.
- Edit `README.md`.
# Example app for YunoHost
[![Integration level](https://dash.yunohost.org/integration/REPLACEBYYOURAPP.svg)](https://ci-apps.yunohost.org/jenkins/job/REPLACEBYYOURAPP%20%28Community%29/lastBuild/consoleFull)
[![Install REPLACEBYYOURAPP with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=REPLACEBYYOURAPP)
> *This package allow you to install REPLACEBYYOURAPP quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview
Quick description of this app.
**Shipped version:** 1.0
## Screenshots
![](Link to an screenshot for this app)
## Demo
* [Official demo](Link to a demo site for this app)
## Configuration
How to configure this app: by an admin panel, a plain file with SSH, or any other way.
## Documentation
* Official documentation: Link to the official documentation of this app
* YunoHost documentation: If specific documentation is needed, feel free to contribute.
## YunoHost specific features
#### Multi-users support
Are LDAP and HTTP auth supported?
Can the app be used by multiple users?
#### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/REPLACEBYYOURAPP%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/REPLACEBYYOURAPP%20(Community)/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/jenkins/job/REPLACEBYYOURAPP%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/REPLACEBYYOURAPP%20(Community)%20(%7EARM%7E)/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/jenkins/job/REPLACEBYYOURAPP%20(Community)/badge/icon)](https://ci-stretch.nohost.me/jenkins/job/REPLACEBYYOURAPP%20(Community)/)
## Limitations
* Any known limitations.
## Additional information
* Other information you would add about this application
**More information on the documentation page:**
https://yunohost.org/packaging_apps
## Links
* Report a bug: https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/issues
* App website: Link to the official website of this app
* YunoHost website: https://yunohost.org/
---
Developers info
----------------
**Only if you want to use a testing branch for coding, instead of merging directly into master.**
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing --debug
or
sudo yunohost app upgrade REPLACEBYYOURAPP -u https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing --debug
```

44
check_process Normal file
View file

@ -0,0 +1,44 @@
# 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" (PATH)
admin="john" (USER)
language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="pass"
port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
;upgrade=1 from_commit=XXX
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: If the app supports LDAP and SSOwat, turn level 4 to '1' and add a link to an issue or a part of your code to show it.
# If the app does not use LDAP nor SSOwat, and can't use them, turn level 4 to 'na' and explain as well.
Level 4=0
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

17
conf/airsonic.properties Normal file
View file

@ -0,0 +1,17 @@
# Airsonic preferences - custom for Yunohost
# Full settings list here "https://airsonic.github.io/docs/configure/airsonic-properties/"
# Example config from doc
#LdapEnabled=false
#LdapUrl=ldap://host.domain.com:389/cn=Users,dc=domain,dc=com
#LdapSearchFilter=(sAMAccountName={0})
#LdapManagerDn=
#LdapAutoShadowing=false
LdapEnabled=true
LdapUrl=ldap://localhost:389/ou=users,dc=yunohost,dc=org
LdapSearchFilter=(&(uid=%{0})(objectClass=posixAccount))
#LdapSearchFilter=(&(uid=%{user})(objectClass=posixAccount)) DOKUWIKI
#LdapManagerDn=
# Automatically create users comming from Yunohost in Airsonic
LdapAutoShadowing=true

18
conf/app.src Normal file
View file

@ -0,0 +1,18 @@
SOURCE_URL=https://github.com/airsonic/airsonic/releases/download/v10.1.2/airsonic.war
SOURCE_SUM=738c0614a113f692d75f62d9a74efab1580e3ba8c683feb8d6bfded80240f342
# (Optional) Program to check the integrity (sha256sum, md5sum...)
# default: sha256
SOURCE_SUM_PRG=sha256sum
# (Optional) Archive format
# default: tar.gz
SOURCE_FORMAT=false
# (Optional) Put false if sources are directly in the archive root
# default: true
SOURCE_IN_SUBDIR=false
# (Optionnal) Name of the local archive (offline setup support)
# default: ${src_id}.${src_format}
SOURCE_FILENAME=airsonic.war
# (Optional) If it set as false don't extract the source.
# (Useful to get a debian package or a python wheel.)
# default: true
SOURCE_EXTRACT=false

26
conf/nginx.conf Normal file
View file

@ -0,0 +1,26 @@
# source of config file : https://airsonic.github.io/docs/proxy/nginx/
# adapted for yunohost
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header Host $http_host;
proxy_max_temp_file_size 0;
proxy_pass http://127.0.0.1:__PORT__;
proxy_redirect http:// https://;
# Include SSOWAT user panel.
# include conf.d/yunohost_panel.conf.inc;
# add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' www.gstatic.com; img-src 'self' *.akamaized.net; style-src 'self' 'unsafe-inline' fonts.googleapis.com; font-src 'self' fonts.gstatic.com; frame-src 'self'; object-src 'none'";
}
### Yunohost example from the doc
#location YNH_EXAMPLE_PATH/ {
# rewrite ^YNH_EXAMPLE_PATH$ YNH_EXAMPLE_PATH/ permanent;
# proxy_pass http://YNH_EXEMPLE_DOMAIN:YNH_EXAMPLE_PORT/;
# proxy_set_header Host $host;
# proxy_buffering off;
#}

36
conf/systemd-sysconfig Normal file
View file

@ -0,0 +1,36 @@
# source file https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic-systemd-env
# install documentation : https://airsonic.github.io/docs/install/war-standalone/
# Set the location of the standalone war to use
JAVA_JAR=__FINALPATH__/airsonic.war
# Set any java opts separated by spaces
#JAVA_OPTS=-Xmx700m
# Set a different location for airsonic home.
# If this path is /var/libresonic or even contains "libresonic",
# the data from a previous libresonic can be used as is (i.e. without
# renaming libresonic.properties,db/libresonic*,etc
AIRSONIC_HOME=__FINALPATH__
# Change the port to listen on
PORT=__PORT__
# Change the path that is listened on
CONTEXT_PATH=__PATH__
# Add any java args. These are different than JAVA_OPTS in that
# they are passed directly to the program. The default is empty:
#JAVA_ARGS=
# Note that there are several settings for spring boot, not explicitly listed
# here, but can be used in either JAVA_OPTS or JAVA_ARGS. The full list
# can be found here:
# https://docs.spring.io/spring-boot/docs/1.4.5.RELEASE/reference/htmlsingle/#common-application-properties
# For example to set debug across the board:
#JAVA_ARGS=--debug
# Or to change the ip address that is listened on:
#JAVA_ARGS=--server.address=127.0.0.1

31
conf/systemd.service Normal file
View file

@ -0,0 +1,31 @@
# source file https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic.service
# install documentation : https://airsonic.github.io/docs/install/war-standalone/
[Unit]
Description=__APP__ Media Server
After=remote-fs.target network.target
AssertPathExists=__FINALPATH__
[Service]
Type=simple
Environment="JAVA_JAR=/var/airsonic/airsonic.war"
Environment="JAVA_OPTS=-Xmx700m"
Environment="AIRSONIC_HOME=/var/airsonic"
Environment="PORT=8080"
Environment="CONTEXT_PATH=/airsonic"
Environment="JAVA_ARGS="
EnvironmentFile=-/etc/default/airsonic
ExecStart=/usr/bin/java \
$JAVA_OPTS \
-Dairsonic.home=${AIRSONIC_HOME} \
-Dserver.context-path=${CONTEXT_PATH} \
-Dserver.port=${PORT} \
-jar ${JAVA_JAR} $JAVA_ARGS
User=__APP__
Group=__APP__
# Force systemd to wait XX sec for the process to start before killing it
# TimeoutStopSec= 180
[Install]
WantedBy=multi-user.target

75
manifest.json Normal file
View file

@ -0,0 +1,75 @@
{
"name": "Airsonic",
"id": "airsonic",
"packaging_format": 1,
"description": {
"en": "Airsonic is an open source, web-based media server.",
"fr": "Airsonic est un server multimedia open-source."
},
"version": "10.1.2~ynh1",
"url": "http://airsonic.github.io",
"license": "GPL-3.0-or-later",
"maintainer": {
"name": "Gofannon",
"email": "gofannon@riseup.net"
},
"previous_maintainers": [
{
"name": "XXX",
"email": "XXX",
"url": "XXX"
}
],
"requirements": {
"yunohost": ">= 3.0"
},
"multi_instance": true,
"services": [
"nginx"
],
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain name for Airsonic",
"fr": "Choisissez un nom de domaine pour Airsonic"
},
"example": "example.com"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Airsonic",
"fr": "Choisissez un chemin pour Airsonic"
},
"example": "/airsonic",
"default": "/airsonic"
},
{
"name": "admin",
"type": "user",
"ask": {
"en": "Choose an admin user",
"fr": "Choisissez ladministrateur"
},
"help": {
"en": "This user will have full control on this application and will be able to configure it.",
"fr": "Cet utilisateur aura le controle total de l'application et pourra la configurer."
},
"example": "johndoe"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public application?",
"fr": "Est-ce une application publique ?"
},
"default": true
}
]
}
}

13
scripts/_common.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/bash
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}

77
scripts/backup Normal file
View file

@ -0,0 +1,77 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_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
#=================================================
# 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 db_name)
# Custom values out of the manifest
service_config=$(ynh_app_setting_get $app service_config)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
#ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"
# Restore the systemd service configuration
ynh_restore_file "$service_config"
#=================================================
# BACKUP A CRON FILE
#=================================================
#ynh_backup "/etc/cron.d/$app"

293
scripts/install Normal file
View file

@ -0,0 +1,293 @@
#!/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
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
#language=$YNH_APP_ARG_LANGUAGE
#password=$YNH_APP_ARG_PASSWORD
### 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=/var/$app # Without looking at the comment, I would have installed the app in this folder
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 admin $admin
ynh_app_setting_set $app is_public $is_public
#ynh_app_setting_set $app language $language
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
# FIXME Do NOT allow access from internet direcly. Users will have to go through
# Nginx that acts as a reverse proxy for Airsonic
#yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies openjdk-8-jre ffmpeg
# FIXME Should run "sudo update-alternatives --config java"
# See https://airsonic.github.io/docs/install/prerequisites/
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
### Use these lines if you need a database for the application.
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
### The password will be stored as 'mysqlpwd' into the app settings,
### and will be available as $db_pwd
### If you're not using these lines:
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
#db_name=$(ynh_sanitize_dbid $app)
#ynh_app_setting_set $app db_name $db_name
#ynh_mysql_setup_db $db_name $db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
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"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# ENABLE "TRANSCODE"
#=================================================
### For details, see https://airsonic.github.io/docs/transcode/
mkdir $final_path/transcode
if [ -x /usr/bin/ffmpeg ]; then # Check if 'ffmpeg' is installed and executable
ln -s /usr/bin/ffmpeg $final_path/transcode
fi
# FIXME Not sure if 'lame' is needed ?
if [ -x /usr/bin/lame ]; then # Check if 'lame' is installed and executable
ln -s /usr/bin/lame $final_path/transcode
fi
# Ensure links belong to the $app user
chown $app: $final_path/transcode
#=================================================
# SETUP SYSTEMD
#=================================================
### `ynh_systemd_config` is used to configure a systemd script for an app.
### It can be used for apps that use sysvinit (with adaptation) or systemd.
### Have a look at the app to be sure this app needs a systemd script.
### `ynh_systemd_config` will use the file conf/systemd.service
# Create a dedicated systemd config
ynh_add_systemd_config
# Path of the systemd service configuration
service_config='/etc/default/airsonic'
# Store the path in Yunohost app settings
# Will be used in 'restore' and maybe 'upgrade'
# Avoid to hardcore the value in the scripts
ynh_app_setting_set $app service_config $service_config
# Copy config. template to right location
cp ../conf/systemd-sysconfig $service_config
# Configure the service
# TODO Config could be done in systemd template directly but documentation says
# to avoid it. Stick with this config file for now
ynh_replace_string "__FINALPATH__" "$final_path" "$service_config"
ynh_replace_string "__PORT__" "$port" "$service_config"
ynh_replace_string "__PATH__" "$path_url" "$service_config"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum $service_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
# INTEGRATE APPLICATION WITH YUNOHOST
#=================================================
# preload Airsonic configuration with LDAP settings
# FIXME It does not work at the moment
# Maybe the settings are wrong or this is an issue with the app itself.
# Airsonic logs are not verbose enough even in TRACE mode
# See https://airsonic.github.io/docs/logging/
#cp ../conf/airsonic.properties $final_path/airsonic.properties
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
# Don't store this file checksum as it will be modified by user and it cannot
# be overwritten easily during upgrade
#ynh_store_file_checksum $final_path/airsonic.properties
#=================================================
# 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 $app: $final_path
#=================================================
# SETUP LOGROTATE
#=================================================
### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
### Use this helper only if there is effectively a log file for this app.
### If you're not using this helper:
### - Remove the section "BACKUP LOGROTATE" in the backup script
### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
### - And the section "SETUP LOGROTATE" in the upgrade script
# Use logrotate to manage application logfile(s)
ynh_use_logrotate $final_path/airsonic.log
# See https://airsonic.github.io/docs/logging/#main-log-file
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
### `yunohost service add` is a CLI yunohost command to add a service in the admin panel.
### You'll find the service in the 'services' section of YunoHost admin panel.
### This CLI command would be useless if the app does not have any services (systemd or sysvinit)
### If you're not using these lines:
### - You can remove these files in conf/.
### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script
### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script
yunohost service add $app --description "Airsonic daemon" --log "$final_path/airsonic.log"
#=================================================
# SETUP SSOWAT
#=================================================
# 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
#=================================================
# MANAGE SERVICES
#=================================================
# Run the app
systemctl start $app.service
# Hack for 'package_check' to give enough time to the app to be deployed so the nginx reload does not break the run of the
# Wait 150 seconds to let time to java for deploying the app and avoid "HTTP 502
# errors" on nginx while Airsonic is starting. It also crashes 'package_check'
# because of this
#sleep 150
# On a small dedicated server in the app log:
# INFO --- org.airsonic.player.Application : Started Application in 118.214 seconds (JVM running for 121.451)
systemctl reload nginx

114
scripts/remove Normal file
View file

@ -0,0 +1,114 @@
#!/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)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status | grep -q $app
then
echo "Remove $app service"
yunohost service remove $app
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
# Remove a database if it exists, along with the associated user
#ynh_mysql_remove_db $db_user $db_name
#=================================================
# 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
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# 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/$app/"
# Remove the log files
#ynh_secure_remove "/var/log/$app/"
# Remove the systemd configuration file
ynh_secure_remove $service_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app

157
scripts/restore Normal file
View file

@ -0,0 +1,157 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_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
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
#db_name=$(ynh_app_setting_get $app db_name)
# Custom values out of the manifest
service_config=$(ynh_app_setting_get $app service_config)
#=================================================
# 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 "
#FIXME No need for this step in restore ??
# See https://github.com/YunoHost-Apps/webmin_ynh/commit/589f730a32f33fd9244bb32804dba7651b03abe4#diff-ad962c6fd65b725b71aa46c8a715127f
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
# FIXME Do NOT allow access from internet direcly. Users will have to go through
# Nginx that acts as a reverse proxy for Airsonic
#yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# 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"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
#db_pwd=$(ynh_app_setting_get $app mysqlpwd)
#ynh_mysql_setup_db $db_name $db_name $db_pwd
#ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R app: $final_path
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies openjdk-8-jre ffmpeg
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --description "Airsonic daemon" --log "$final_path/airsonic.log"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
# Restore the systemd service configuration
ynh_restore_file "$service_config"
#=================================================
# RESTORE THE CRON FILE
#=================================================
#ynh_restore_file "/etc/cron.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD SERVICES
#=================================================
systemctl reload nginx
# Run the app
systemctl start $app.service

175
scripts/upgrade Normal file
View file

@ -0,0 +1,175 @@
#!/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)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
#language=$(ynh_app_setting_get $app language)
#db_name=$(ynh_app_setting_get $app db_name)
# Custom values out of the manifest
service_config=$(ynh_app_setting_get $app service_config)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
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
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_install_app_dependencies openjdk-8-jre ffmpeg
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# INTEGRATE APPLICATION WITH YUNOHOST
#=================================================
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
# Path of the systemd service configuration
ynh_backup_if_checksum_is_different "$final_path/airsonic.properties"
# preload Airsonic configuration with LDAP settings
# FIXME It does not work at the moment
# Maybe the settings are wrong or this is an issue with the app itself.
# Airsonic logs are not verbose enough even in TRACE mode
# See https://airsonic.github.io/docs/logging/
#cp ../conf/airsonic.properties $final_path/airsonic.properties
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/airsonic.properties"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
#ynh_use_logrotate --non-append => TODO why no $file? why "--non-append"?
ynh_use_logrotate --non-append $final_path/airsonic.log
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
# Backup existing systemd service configuration
ynh_backup_if_checksum_is_different "$service_config"
# Copy config. template to right location
cp ../conf/systemd-sysconfig $service_config
# Configure the service
# TODO Config could be done in systemd template directly but documentation says
# to avoid it. Stick with this config file for now
ynh_replace_string "__FINALPATH__" "$final_path" "$service_config"
ynh_replace_string "__PORT__" "$port" "$service_config"
ynh_replace_string "__PATH__" "$path_url" "$service_config"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$service_config"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R $app: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
# 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
# Run the app
systemctl start $app.service

2
sources/extra_files/app/.gitignore vendored Executable file
View file

@ -0,0 +1,2 @@
*~
*.sw[op]

2
sources/patches/.gitignore vendored Executable file
View file

@ -0,0 +1,2 @@
*~
*.sw[op]