1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00

Apply last example_ynh

This commit is contained in:
yalh76 2020-06-23 02:40:39 +02:00
parent a4aafe2b7d
commit c4f795ff80
14 changed files with 650 additions and 383 deletions

View file

@ -1,10 +1,10 @@
# Calibre-web for YunoHost
[![Integration level](https://dash.yunohost.org/integration/calibreweb.svg)](https://ci-apps.yunohost.org/jenkins/job/calibreweb%20%28Community%29/lastBuild/consoleFull)
[![Install calibreweb with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=calibreweb)
> *This package allow you to install calibreweb 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.*
[![Integration level](https://dash.yunohost.org/integration/calibreweb.svg)](https://dash.yunohost.org/appci/app/calibreweb) ![](https://ci-apps.yunohost.org/ci/badges/calibreweb.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/calibreweb.maintain.svg)
[![Install Calibre-web with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=calibreweb)
> *This package allows you to install Calibre-web quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview
This is an implementation of [Calibre-web](https://github.com/janeczku/calibre-web) for Yunohost.
@ -47,7 +47,12 @@ yunohost app setting calibreweb do_not_backup_data -v 1
By default, removing the app will **never** delete the library.
## Known Limitations
#### Supported architectures
* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/calibreweb%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/calibreweb/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/calibreweb%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/calibreweb/)
## Limitations
* Authorization access to library to be done manually after install if Calibre library was already existing, for example :
```
@ -68,20 +73,20 @@ chmod o+rw path/to/library
---
Developers info
Developer info
----------------
Please do your pull request to the [testing branch](https://github.com/Yunohost-Apps/calibreweb_ynh/tree/Testing).
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/calibreweb_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/Yunohost-Apps/calibreweb_ynh/tree/Testing --debug
sudo yunohost app install https://github.com/YunoHost-Apps/calibreweb_ynh/tree/testing --debug
or
sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibreweb_ynh/tree/Testing --debug
sudo yunohost app upgrade calibreweb -u https://github.com/YunoHost-Apps/calibreweb_ynh/tree/testing --debug
```
## Todo
- [X] Multiinstance
- [X] Better Multimedia integration : Integrate in Yunohost.multimedia
- [X] rework LDAP integration to create user automatically
@ -97,7 +102,5 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre
- [ ] Add action to deactivate LDAP et retrieve admin password
- [ ] Use internal updater to update version?
## LICENSE
Package and software are GPL 3.0

View file

@ -1,9 +1,12 @@
location __PATH__ {
client_max_body_size 200M;
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
client_max_body_size 200M;
proxy_pass http://localhost:__PORT__;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;

View file

@ -7,7 +7,7 @@ Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
ExecStart=/bin/sh -c '/usr/bin/python3 __FINALPATH__/cps.py'
ExecStart=/bin/sh -c '/opt/pyenv/versions/__PYTHON_VERSION__/bin/python __FINALPATH__/cps.py'
[Install]
WantedBy=multi-user.target

46
issue_template.md Normal file
View file

@ -0,0 +1,46 @@
---
name: Bug report
about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all.
---
**How to post a meaningful bug report**
1. *Read this whole template first.*
2. *Determine if you are on the right place:*
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!*
- *Otherwise, the issue may be due to Calibre-web itself. Refer to its documentation or repository for help.*
- *If you have a doubt, post here, we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
**Describe the bug**
*A clear and concise description of what the bug is.*
**Versions**
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes*
- If yes, please explain:
- Using, or trying to install package version/branch:
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
**To Reproduce**
*Steps to reproduce the behavior.*
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install calibreweb
```
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
- *If the error occurs in your browser, explain what you did:*
1. *Go to '...'*
2. *Click on '....'*
3. *Scroll down to '....'*
4. *See error*
**Expected behavior**
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
**Logs**
*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.*
*If applicable and useful, add screenshots to help explain your problem.*

18
pull_request_template.md Normal file
View file

@ -0,0 +1,18 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished.
- [ ] Tested with Package_check.
- [ ] Fix or enhancement tested.
- [ ] Upgrade from last version tested.
- [ ] Can be reviewed and tested.
## Package_check results
---
*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results*
[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/calibreweb_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/calibreweb_ynh%20PR-NUM-%20(USERNAME)/)

View file

@ -1,7 +1,10 @@
#!/bin/bash
PKG_DEPENDENCIES="sqlite3 libldap2-dev libsasl2-dev python3-dev imagemagick python3-lxml libjpeg-dev"
pkg_dependencies="sqlite3 libldap2-dev libsasl2-dev python3-dev imagemagick python3-lxml libjpeg-dev"
#PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick"
python_version=3.5
DOSSIER_MEDIA=/home/yunohost.multimedia
LOG_FILE=/var/log/$app/$app.log
@ -12,87 +15,10 @@ ACCESS_LOG_FILE=/var/log/$app/$app-access.log
# TO BE DELETED WHEN RELEASED
#=================================================
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
#=================================================
#YNH_MULTIMEDIA
# FUTURE OFFICIAL HELPERS
#=================================================
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
# Install or update the main directory yunohost.multimedia
#
# usage: ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir () {
local ynh_media_release="v1.2"
local checksum="806a827ba1902d6911095602a9221181"
# Download yunohost.multimedia scripts
wget -nv https://github.com/Yunohost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
# Check the control sum
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|| ynh_die "Corrupt source"
# Check if the package acl is installed. Or install it.
ynh_package_is_installed 'acl' \
|| ynh_package_install acl
# Extract
mkdir yunohost.multimedia-master
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
./yunohost.multimedia-master/script/ynh_media_build.sh
}
# Add a directory in yunohost.multimedia
# This "directory" will be a symbolic link to a existing directory.
#
# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
ynh_multimedia_addfolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
}
# Move a directory in yunohost.multimedia, and replace by a symbolic link
#
# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# It will be moved to "Destination directory"
# A symbolic link will replace it.
# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
ynh_multimedia_movefolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
}
# Allow an user to have an write authorisation in multimedia directories
#
# usage: ynh_multimedia_addaccess user_name
#
# | arg: -u, --user_name= - The name of the user which gain this access.
ynh_multimedia_addaccess () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [u]=user_name=)
local user_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
groupadd -f multimedia
usermod -a -G multimedia $user_name
}

View file

@ -6,13 +6,17 @@
# IMPORT GENERIC HELPERS
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -22,10 +26,11 @@ ynh_abort_if_errors
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
path_url=$(ynh_app_setting_get $app path)
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
path_url=$(ynh_app_setting_get --app=$app --key=path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
#Get settings from database in case it has been changed in the app
calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1")
@ -33,24 +38,15 @@ calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM setting
calibre_dir=${calibre_dir%/}
ynh_app_setting_set $app calibre_dir $calibre_dir
source ../settings/scripts/_common.sh
#=================================================
# STANDARD BACKUP STEPS
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
#Deactivate as per package linter
#ynh_systemd_action --service_name=$app --action="stop"
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Backing up the main app directory..." --weight=1
#This will backup the app.db file at the same time
ynh_backup --src_path="$final_path"
@ -58,42 +54,29 @@ ynh_backup --src_path="$final_path"
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_script_progression --message="Backing up logrotate configuration..." --weight=1
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_script_progression --message="Backing up systemd configuration..." --weight=1
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Backing up data directory..."
ynh_print_info "Data directory will be backup up only if BACKUP_CORE_ONLY is unset"
ynh_backup --src_path="$calibre_dir" --is_big
#=================================================
# START SYSTEMD SERVICE
#=================================================
#deactivate as per package_linter
#ynh_script_progression --message="Starting a systemd service..." --weight=5
#ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
@ -15,18 +15,21 @@ source /usr/share/yunohost/helpers
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get $app port)
source _common.sh
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -91,7 +94,7 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path"
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
@ -107,10 +110,10 @@ fi
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path"
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================

View file

@ -6,14 +6,25 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_install_python
source ynh_multimedia_3
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
@ -27,15 +38,7 @@ if [ $is_public -eq 1 ]; then
public_library=1
fi
source _common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@ -43,72 +46,61 @@ ynh_abort_if_errors
ynh_script_progression --message="Validating installation parameters..." --weight=5
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# 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
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=5
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=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..."
# Find a free port
port=$(ynh_find_port 8083)
# Open this port
ynh_script_progression --message="Opening port $port..." --weight=5
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
# Find an available port
port=$(ynh_find_port --port=8083)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Downloading sources to $final_path..." --weight=10
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"
# Optional: Expose this port publicly
# (N.B. : you only need to do this if the app actually needs to expose the port publicly.
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# Open the port
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing package dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES
#use latest version of pip as per documentation in https://github.com/pypa/get-pip
#cannot use helper as maintaining the checksum would be a pain in the a***
curl https://bootstrap.pypa.io/get-pip.py | python3
ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Installing pip requirements..." --weight=50
pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=10
ynh_script_progression --message="Installing pip additionnal requirements..." --weight=60
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --weight=5
#Cannot use empty string for X-script-name, causes an issue in the python prg
ynh_script_progression --message="Setting up system configuration..." --weight=5
if [ $path_url = "/" ] ; then
ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf
fi
@ -119,23 +111,40 @@ ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create $app
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC SETUP
#=================================================
# BUILD CALIBRE-WEB
#=================================================
ynh_script_progression --message="Building Calibre-web..." --weight=110
chown -R $app: $final_path
ynh_install_python --python_version=$python_version
pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt
/opt/pyenv/versions/$python_version/bin/pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_add_systemd_config --others_var="python_version"
#=================================================
# CREATE FILES AND DIRECTORIES
# CREATE MULTIMEDIA DIRECTORIES
#=================================================
ynh_script_progression --message="Creating files and directory..." --weight=5
ynh_script_progression --message="Creating multimedia directories..." --weight=5
# Logic is as follow : if app is set to be publicly accessible, we will assume that the library should be set in "Share" multimedia directory
# If app is set to be private but access is requested for all user, we will assume the same
# If app is set to be private but access is limited to the admin user, we will set it inside his own multimedia directory.
@ -159,26 +168,17 @@ if [ ! -e "$calibre_dir"/metadata.db ]; then
chown $app:$app $calibre_dir/*
fi
ynh_app_setting_set $app calibre_dir $calibre_dir
ynh_app_setting_set --app=$app --key=calibre_dir --value=$calibre_dir
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
chown -R $app:$app /var/log/$app
#=================================================
# SPECIFIC SETUP
#=================================================
# SET SQLITE DATABASE SETTINGS
#=================================================
ynh_script_progression --message="Setting up database and settings..." --weight=5
# we need to start and stop the service so that initial app.db file is created and that we can set default data
# If port 8083 is already in use (ex for second instance), then service start will fail, which is expected : so we do not want
# to set $port on the line match. "server on" will be displayed in case the port is already in use and should be ok to spot the fact that the database is initialized.
ynh_systemd_action --service_name=$app --action="start" --line_match="server on " --log_path="$final_path/calibre-web.log" -t 30
#sleep required on low spec like raspberryPi
sleep 2s
@ -194,32 +194,52 @@ eval sqlite3 $final_path/app.db "$conf"
conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
#disabled - do not work when calibreweb is not owner
#chown -R root: $final_path
#chown $app: $final_path/app.db
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
ynh_script_progression --message="Storing the config file checksum..."
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "${final_path}/app.db"
ynh_store_file_checksum --file="${final_path}/app.db"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions to app files
chown -R $app: $final_path
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
chown -R $app:$app /var/log/$app
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --line_match="server on :$port" -t 30
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..."
# Make app public if necessary
if [ $is_public -eq 1 ]
@ -232,15 +252,15 @@ if [ $public_library -eq 0 ]; then
yunohost app addaccess $app -u $admin
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx and start $app..." --weight=5
ynh_script_progression --message="Reloading nginx web server..." --weight=5
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name=$app --action="start" --line_match="server on :$port" -t 30
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
@ -15,67 +15,63 @@ source /usr/share/yunohost/helpers
ynh_script_progression --message="Loading installation settings..." --weight=3
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)
calibre_dir=$(ynh_app_setting_get $app calibre_dir)
source _common.sh
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
calibre_dir=$(ynh_app_setting_get --app=$app --key=calibre_dir)
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service..." --weight=1
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
fi
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2
# Remove the dedicated systemd config
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2
ynh_remove_systemd_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing Dependencies..." --weight=5
# Remove metapackage and its dependencies
ynh_script_progression --message="Removing Dependencies..." --weight=5
ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing $final_path..." --weight=1
# Remove the app directory securely
ynh_script_progression --message="Removing $final_path..." --weight=1
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing nginx web server configuration..." --weight=1
# Remove the dedicated nginx config
ynh_script_progression --message="Removing nginx web server configuration..." --weight=1
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
ynh_remove_logrotate
#=================================================
@ -85,20 +81,27 @@ ynh_remove_logrotate
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..." --weight=10
yunohost firewall disallow TCP $port 2>&1
ynh_exec_warn_less yunohost firewall disallow TCP $port 2>&1
fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
# Remove the log files
ynh_script_progression --message="Removing log file..." --weight=1
ynh_secure_remove "/var/log/$app/"
ynh_secure_remove --file="/var/log/$app/"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
@ -106,3 +109,9 @@ ynh_system_user_delete --username=$app
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_print_warn "!!!The library folder $calibre_dir was not deleted. Delete it manually if required!!!"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed"

View file

@ -6,12 +6,18 @@
# IMPORT GENERIC HELPERS
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_python
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -21,22 +27,22 @@ ynh_abort_if_errors
ynh_script_progression --message="Loading settings..." --weight=1
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)
calibre_dir=$(ynh_app_setting_get $app calibre_dir)
is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get $app port)
source ../settings/scripts/_common.sh
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
calibre_dir=$(ynh_app_setting_get --app=$app --key=calibre_dir)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
@ -44,24 +50,8 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring nginx configuration..." --weight=1
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# REOPEN PORT
#=================================================
ynh_script_progression --message="reopening port $port..." --weight=5
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
@ -70,9 +60,18 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# RESTORE USER RIGHTS
#=================================================
ynh_script_progression --message="Restoring user rights..."
# Restore permissions on app files
chown -R $app: $final_path
@ -82,43 +81,19 @@ chown -R $app: $final_path
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=15
# Define and install dependencies
ynh_script_progression --message="Reinstalling dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES
#use latest version of pip as per documentation in https://github.com/pypa/get-pip
#cannot use helper as maintaining the checksum would be a pain in the a***
curl https://bootstrap.pypa.io/get-pip.py | python3
#pip package not required as already in app directory
#pip install --target $final_path/vendor -r $final_path/requirements.txt
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE SYSTEMD
# BUILD CALIBRE-WEB
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_script_progression --message="Building Calibre-web..." --weight=110
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
chown -R $app: $final_path
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# RESTORE THE LOG FILE DIRECTORY
#=================================================
mkdir -p /var/log/$app
chown -R $app:$app /var/log/$app
ynh_install_python --python_version=$python_version
#=================================================
# RESTORE THE DATA DIRECTORY
@ -146,6 +121,42 @@ fi
# Remove the option backup_core_only if it's in the settings.yml file
ynh_app_setting_delete $app backup_core_only
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#=================================================
# RESTORE THE LOG FILE DIRECTORY
#=================================================
mkdir -p /var/log/$app
chown -R $app:$app /var/log/$app
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# SETUP SSOWAT
#=================================================
@ -163,22 +174,16 @@ fi
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SYSTEMD SERVICE
# WARNING FOR READ ACCESS
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
ynh_print_warn "Please, give required access to $app user to the $calibre_dir folder."
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
#=================================================
# WARNING FOR READ ACCESS
#=================================================
ynh_print_warn "Please, give required access to $app user to the $calibre_dir folder."

View file

@ -1,15 +1,14 @@
#!/bin/bash
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_install_python
source ynh_multimedia_3
source /usr/share/yunohost/helpers
#=================================================
@ -18,27 +17,27 @@ source /usr/share/yunohost/helpers
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
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)
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
language=$(ynh_app_setting_get --app=$app --key=language)
#Get settings from database in case it has been changed in the app and save it in settings so that it can be used back afterward
calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1")
calibre_dir=${calibre_dir%/}
ynh_app_setting_set $app calibre_dir $calibre_dir
ynh_app_setting_set --app=$app --key=calibre_dir --value=$calibre_dir
upload=$(sqlite3 $final_path/app.db "SELECT config_uploading FROM settings WHERE ID=1")
ynh_app_setting_set $app upload $upload
source _common.sh
ynh_app_setting_set --app=$app --key=upload --value=$upload
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
@ -56,6 +55,18 @@ else #on est encore en 0.6.0
current_upstream_app_version='0.6.0'
fi
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Remove not needed open port
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..." --weight=10
ynh_exec_warn_less yunohost firewall disallow TCP $port 2>&1
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
@ -64,29 +75,29 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# 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 the app in case database is updated
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
path_url=$(ynh_normalize_url_path --path_url=$path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -109,6 +120,7 @@ fi
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files from $current_upstream_app_version to $new_upstream_package_version..." --weight=10
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
@ -116,8 +128,8 @@ fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=5
if [ $path_url = "/" ] ; then
ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf
fi
@ -127,50 +139,51 @@ ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=15
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Installing package dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES
ynh_install_app_dependencies $pkg_dependencies
#use latest version of pip as per documentation in https://github.com/pypa/get-pip
#cannot use helper as maintaining the checksum would be a pain in the a***
curl https://bootstrap.pypa.io/get-pip.py | python3
ynh_script_progression --message="Installing pip requirements ..." --weight=30
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt
ynh_script_progression --message="Installing pip additionnal requirements..." --weight=40
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
ynh_system_user_create $app
# Set permissions on app files (required to be able to update database)
chown -R $app: $final_path
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC UPGRADE
#=================================================
#build multimedia directory
# BUILD CALIBRE-WEB
#=================================================
ynh_script_progression --message="Create Multimedia dir..." --weight=1
ynh_script_progression --message="Building Calibre-web..." --weight=110
chown -R $app: $final_path
ynh_install_python --python_version=$python_version
pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt
/opt/pyenv/versions/$python_version/bin/pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
popd
#=================================================
# CREATE MULTIMEDIA DIRECTORIES
#=================================================
ynh_script_progression --message="Creating multimedia directories..." --weight=1
#Create multimedia directory but we do not change the calibre_dir : It's the user to make this choice.
ynh_multimedia_build_main_dir
ynh_multimedia_addaccess $app
#=================================================
#Update database structure
# UPDATE DATABASE
#=================================================
ynh_script_progression --message="Update database..." --weight=1
### 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.
ynh_backup_if_checksum_is_different "$final_path/app.db"
ynh_backup_if_checksum_is_different --file="$final_path/app.db"
#set database settings as per conf file : restart server so that app.db is regenerated, then add new ldap & log settings
if [ "$current_upstream_app_version" == '0.6.6' ]; then
@ -188,37 +201,52 @@ conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settin
eval sqlite3 $final_path/app.db "$conf"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/app.db"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
ynh_use_logrotate --non-append
ynh_store_file_checksum --file="$final_path/app.db"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_add_systemd_config
ynh_add_systemd_config --others_var="python_version"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions on app files
chown -R $app: $final_path
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..."
# Make app public if necessary
if [ $is_public -eq 1 ]
@ -242,12 +270,6 @@ fi
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#=================================================
# END OF SCRIPT

151
scripts/ynh_install_python Normal file
View file

@ -0,0 +1,151 @@
#!/bin/bash
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
pyenv_install_dir="/opt/pyenv"
# PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable.
export PYENV_ROOT="$pyenv_install_dir"
# Required dependencies
pyenv_dependencies="build-essential libssl1.0-dev|libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git"
# Install python version management
#
# [internal]
#
# usage: ynh_install_pyenv
ynh_install_pyenv () {
echo "Installation of pyenv - python version management" >&2
# Build an app.src for pyenv
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/pyenv/pyenv/archive/v1.2.19.tar.gz
SOURCE_SUM=e93466735ac9c34d68b7d5d71f32c16a2b4b1a6a1adffb85acc4126a3398b9d0" > "../conf/pyenv.src"
# Download and extract pyenv
ynh_setup_source "$pyenv_install_dir" pyenv
# Build an app.src for pyenv-virtualenv
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/pyenv/pyenv-virtualenv/archive/v1.1.5.tar.gz
SOURCE_SUM=27ae3de027a6f6dccdca4085225512e559c6b94b31625bd2b357a18890a1e618" > "../conf/pyenv-virtualenv.src"
# Download and extract pyenv-virtualenv
ynh_setup_source "$pyenv_install_dir/plugins/pyenv-virtualenv" pyenv-virtualenv
(cd $pyenv_install_dir
./src/configure && make -C src)
# Create shims directory if needed
if [ ! -d $pyenv_install_dir/shims ] ; then
mkdir $pyenv_install_dir/shims
fi
}
# Install a specific version of python
#
# ynh_install_python will install the version of python provided as argument by using pyenv.
#
# pyenv (python version management) stores the target python version in a .python_version file created in the target folder (using pyenv local <version>)
# It then uses that information for every python user that uses pyenv provided python command
#
# This helper creates a /etc/profile.d/pyenv.sh that configures PATH environment for pyenv
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
#
# Don't forget to execute python-dependent command in a login environment
# (e.g. sudo --login option)
# When not possible (e.g. in systemd service definition), please use direct path
# to pyenv shims (e.g. $PYENV_ROOT/shims/bundle)
#
# usage: ynh_install_python python_version user
# | arg: -v, --python_version= - Version of python to install.
# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0).
# The crontab will handle the update of minor versions when needed.
ynh_install_python () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [v]=python_version= )
# Use pyenv, https://github.com/pyenv/pyenv to manage the python versions
local python_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Create $pyenv_install_dir
mkdir -p "$pyenv_install_dir/plugins/pyenv-virtualenv"
# Load pyenv path in PATH
CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing python binary, to avoid to block pyenv
#test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv
# If pyenv is not previously setup, install it
if ! type pyenv > /dev/null 2>&1
then
ynh_install_pyenv
elif dpkg --compare-versions "$($pyenv_install_dir/bin/pyenv --version | cut -d" " -f2)" lt "1.2.19"
then
ynh_install_pyenv
elif dpkg --compare-versions "$($pyenv_install_dir/plugins/pyenv-virtualenv/bin/pyenv-virtualenv --version | cut -d" " -f2)" lt "1.1.5"
then
ynh_install_pyenv
fi
# Restore /usr/local/bin in PATH (if needed)
PATH=$CLEAR_PATH
# And replace the old python binary
# test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python
# Install required dependencies
ynh_add_app_dependencies --package="$pyenv_dependencies"
# Install the requested version of python
pyenv install --skip-existing $python_version
# Store the ID of this app and the version of python requested for it
echo "$YNH_APP_ID:$python_version" | tee --append "$pyenv_install_dir/ynh_app_version"
# Store python_version into the config of this app
ynh_app_setting_set --app=$app --key=python_version --value=$python_version
# Set environment for python users
echo "#pyenv
export PYENV_ROOT=$pyenv_install_dir
export PATH=\"$pyenv_install_dir/bin:$PATH\"
eval \"\$(pyenv init -)\"
#pyenv" > /etc/profile.d/pyenv.sh
# Load the right environment for the Installation
eval "$(pyenv init -)"
(cd $final_path
pyenv local $python_version)
}
# Remove the version of python used by the app.
#
# This helper will check if another app uses the same version of python,
# if not, this version of python will be removed.
# If no other app uses python, pyenv will be also removed.
#
# usage: ynh_remove_python
ynh_remove_python () {
python_version=$(ynh_app_setting_get --app=$app --key=python_version)
# Remove the line for this app
sed --in-place "/$YNH_APP_ID:$python_version/d" "$pyenv_install_dir/ynh_app_version"
# If no other app uses this version of python, remove it.
if ! grep --quiet "$python_version" "$pyenv_install_dir/ynh_app_version"
then
$pyenv_install_dir/bin/pyenv uninstall --force $python_version
fi
# Remove pyenv environment configuration
rm /etc/profile.d/pyenv.sh
# If no other app uses pyenv, remove pyenv and dedicated group
if [ ! -s "$pyenv_install_dir/ynh_app_version" ]
then
ynh_secure_remove --file="$pyenv_install_dir"
fi
}

78
scripts/ynh_multimedia_3 Normal file
View file

@ -0,0 +1,78 @@
#!/bin/bash
# Install or update the main directory yunohost.multimedia
#
# usage: ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir () {
local ynh_media_release="v1.2"
local checksum="806a827ba1902d6911095602a9221181"
# Download yunohost.multimedia scripts
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
# Check the control sum
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|| ynh_die "Corrupt source"
# Check if the package acl is installed. Or install it.
ynh_package_is_installed 'acl' \
|| ynh_package_install acl
# Extract
mkdir yunohost.multimedia-master
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
./yunohost.multimedia-master/script/ynh_media_build.sh
}
# Add a directory in yunohost.multimedia
# This "directory" will be a symbolic link to a existing directory.
#
# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
ynh_multimedia_addfolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
}
# Move a directory in yunohost.multimedia, and replace by a symbolic link
#
# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# It will be moved to "Destination directory"
# A symbolic link will replace it.
# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
ynh_multimedia_movefolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
}
# Allow an user to have an write authorisation in multimedia directories
#
# usage: ynh_multimedia_addaccess user_name
#
# | arg: -u, --user_name= - The name of the user which gain this access.
ynh_multimedia_addaccess () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [u]=user_name=)
local user_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
groupadd -f multimedia
usermod -a -G multimedia $user_name
}