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

Merge pull request #18 from YunoHost-Apps/testing

Apply last example_ynh
This commit is contained in:
yalh76 2022-03-09 20:08:51 +01:00 committed by GitHub
commit 2617bebdb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 371 additions and 407 deletions

55
.github/ISSUE_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,55 @@
---
name: Bug report
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
**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 the app itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and 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.*
### Context
- 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`*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install the_app
```
- *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
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

16
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished and ready to be reviewed/tested
- [ ] The fix/enhancement were manually tested (if applicable)
## Automatic tests
Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)

View file

@ -1,13 +1,17 @@
# Chroot ssh directory for YunoHost
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
[![Integration level](https://dash.yunohost.org/integration/ssh_chroot_dir.svg)](https://dash.yunohost.org/appci/app/ssh_chroot_dir)
[![Install ssh chroot directory with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=ssh_chroot_dir)
> **This app can't be tested automatically. Because it's impossible to use modprobe in a lxc container, and there's no fstab to tweak.
So, the tests fail each time...
The level is fixed at 3 by manual tests.**
# ssh chroot directory for YunoHost
> *This package allow you to create a directory with a ssh chroot 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/ssh_chroot_dir.svg)](https://dash.yunohost.org/appci/app/ssh_chroot_dir) ![](https://ci-apps.yunohost.org/ci/badges/ssh_chroot_dir.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/ssh_chroot_dir.maintain.svg)
[![Install ssh chroot directory with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=ssh_chroot_dir)
*[Lire ce readme en français.](./README_fr.md)*
> *This package allows you to install ssh chroot directory 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
@ -18,40 +22,27 @@ In addition to the chroot, the user has a limited space available.
So, you can provide to a distant user a limited part of your hard disk to let him put his backup, without any risk for your own server.
**Shipped version:** 1.2
## Screenshots
**Shipped version:** 1.2~ynh4
## Demo
No demo available.
## Configuration
## Documentation and resources
## Documentation
* Official app website: https://github.com/maniackcrudelis/ssh_chroot
* Upstream app code repository: https://github.com/maniackcrudelis/ssh_chroot
* YunoHost documentation for this app: https://yunohost.org/app_ssh_chroot_dir
* Report a bug: https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/issues
* YunoHost documentation: There no other documentations, feel free to contribute.
## Developer info
## YunoHost specific features
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/tree/testing).
#### Multi-users support
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/tree/testing --debug
or
sudo yunohost app upgrade ssh_chroot_dir -u https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/tree/testing --debug
```
Only by installing this app for each user.
#### Supported architectures
* x86-64 - [![](https://ci-apps.yunohost.org/ci/logs/ssh_chroot_dir%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/ssh_chroot_dir/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/ssh_chroot_dir%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/ssh_chroot_dir/)
## Limitations
* No backup and restore script.
* Can't be tested by package check.
## Additionnal informations
## Links
* Report a bug: https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/issues
* ssh_chroot website: https://github.com/maniackcrudelis/ssh_chroot
* YunoHost website: https://yunohost.org/
**More info regarding app packaging:** https://yunohost.org/packaging_apps

View file

@ -1,59 +1,44 @@
# Chroot ssh directory pour YunoHost
# ssh chroot directory pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/ssh_chroot_dir.svg)](https://dash.yunohost.org/appci/app/ssh_chroot_dir)
[![Installer ssh chroot directory avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=ssh_chroot_dir)
> **Cette application ne peut pas être testée automatiquement. Parce qu'il est impossible d'utiliser modprobe dans un conteneur lxc, et qu'il n' y a pas de fstab à modifier.
Donc, les tests échouent à chaque fois...
Le niveau est fixé à 3 par des tests manuels.**
[![Niveau d'intégration](https://dash.yunohost.org/integration/ssh_chroot_dir.svg)](https://dash.yunohost.org/appci/app/ssh_chroot_dir) ![](https://ci-apps.yunohost.org/ci/badges/ssh_chroot_dir.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/ssh_chroot_dir.maintain.svg)
[![Installer ssh chroot directory avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=ssh_chroot_dir)
*[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet de créer un répertoire avoir un chroot ssh rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, merci de regarder [ici](https://yunohost.org/#/install_fr) pour savoir comment l'installer et en profiter.*
> *Ce package vous permet d'installer ssh chroot directory rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
## Résumé
## Vue d'ensemble
Cette application crée un répertoire pour un utilisateur, pour lui permettre de mettre ici ses sauvegardes (ou ce qu'il veut).
Ce répertoire est accessible par ssh ou sftp.
Le répertoire est hautement sécurisé par un chroot complet avec des commandes disponibles limitées. Ainsi, l'utilisateur ne peut pas sortir de son répertoire et ne peut utiliser aucune commandes qui ne soit pas autorisée.
En plus du chroot, l'utilisateur dispose d'un espace limité.
This app create a directory for an user, to allow him to put in here his backups (or whatever he want).
This directory is accessible by ssh or sftp.
The directory is highly secured by a complete chroot with limited commands available. So the user can't go out of his directory and can't use any other command which not allowed.
In addition to the chroot, the user has a limited space available.
Ainsi, vous pouvez fournir à un utilisateur distant une partie limitée de votre disque dur pour lui permettre de mettre sa sauvegarde, sans aucun risque pour votre propre serveur.
So, you can provide to a distant user a limited part of your hard disk to let him put his backup, without any risk for your own server.
**Version embarquée:** 1.2
## Captures d'écran
**Version incluse :** 1.2~ynh4
## Démo
Aucune démo pour cette application.
## Configuration
## Documentations et ressources
## Documentation
* Site officiel de l'app : https://github.com/maniackcrudelis/ssh_chroot
* Dépôt de code officiel de l'app : https://github.com/maniackcrudelis/ssh_chroot
* Documentation YunoHost pour cette app : https://yunohost.org/app_ssh_chroot_dir
* Signaler un bug : https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/issues
* Documentation YunoHost: Il n'y a pas d'autre documentation, n'hésitez pas à contribuer.
## Informations pour les développeurs
## Fonctionnalités spécifiques à YunoHost
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/tree/testing).
#### Support multi-utilisateurs
Pour essayer la branche testing, procédez comme suit.
```
sudo yunohost app install https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/tree/testing --debug
ou
sudo yunohost app upgrade ssh_chroot_dir -u https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/tree/testing --debug
```
Seulement en installant cette application pour chaque utilisateur.
#### Architectures supportées.
* x86-64 - [![](https://ci-apps.yunohost.org/ci/logs/ssh_chroot_dir%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/ssh_chroot_dir/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/ssh_chroot_dir%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/ssh_chroot_dir/)
## Limitations
* Pas de script de backup et restore.
* Ne peut pas être testé avec package check.
## Informations additionnelles
## Liens
* Reporter un bug: https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh/issues
* Site de ssh_chroot: https://github.com/maniackcrudelis/ssh_chroot
* Site de YunoHost: https://yunohost.org/
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps

View file

@ -11,7 +11,7 @@
setup_private=0
setup_public=0
upgrade=1
backup_restore=0
backup_restore=1
multi_instance=1
port_already_use=0
change_url=0

View file

@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

0
doc/.gitkeep Normal file
View file

6
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1,6 @@
This app create a directory for an user, to allow him to put in here his backups (or whatever he want).
This directory is accessible by ssh or sftp.
The directory is highly secured by a complete chroot with limited commands available. So the user can't go out of his directory and can't use any other command which not allowed.
In addition to the chroot, the user has a limited space available.
So, you can provide to a distant user a limited part of your hard disk to let him put his backup, without any risk for your own server.

0
doc/DISCLAIMER.md Normal file
View file

0
doc/screenshots/.gitkeep Normal file
View file

View file

@ -8,6 +8,11 @@
},
"version": "1.2~ynh4",
"url": "https://github.com/maniackcrudelis/ssh_chroot",
"upstream": {
"license": "GPL-3.0",
"website": "https://github.com/maniackcrudelis/ssh_chroot",
"code": "https://github.com/maniackcrudelis/ssh_chroot"
},
"license": "GPL-3.0",
"maintainer": {
"name": "",
@ -18,14 +23,16 @@
"email": "maniackc_dev@crudelis.fr"
}],
"requirements": {
"yunohost": ">= 3.8.1"
"yunohost": ">= 4.3.0"
},
"multi_instance": true,
"services": [],
"services": [
],
"arguments": {
"install" : [
{
"name": "ssh_user",
"type": "string",
"ask": {
"en": "Choose an new user for this directory",
"fr": "Choisissez un nouvel utilisateur pour ce dossier"
@ -39,19 +46,15 @@
{
"name": "password",
"type": "password",
"ask": {
"en": "Set a password for this user",
"fr": "Définissez un mot de passe pour cet utilisateur"
},
"help": {
"en": "OPTIONAL. It's better to use a public ssh key instead. See below.",
"fr": "OPTIONNEL. Il est préférable d'utiliser une clé publique. Voir ci-dessous."
},
"example": "Choose a password",
"optional": true
},
{
"name": "pub_key",
"type": "string",
"ask": {
"en": "Give the public ssh key",
"fr": "Donnez une clé publique ssh"
@ -64,6 +67,7 @@
},
{
"name": "size",
"type": "string",
"ask": {
"en": "Choose the maximum space allowed to this user",
"fr": "Choississez l'espace maximum à allouer à cet utilisateur"

View file

@ -1,27 +1,5 @@
#!/bin/bash
#=================================================
# BACKUP
#=================================================
HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain
human=$(numfmt --to=iec --from-unit=1K $1)
echo $human
}
CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
file_to_analyse=$1
backup_size=$(du --summarize "$file_to_analyse" | cut -f1)
free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d)
if [ $free_space -le $backup_size ]
then
ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse."
ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)"
ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
fi
}
#=================================================
# PACKAGE CHECK BYPASSING...
#=================================================
@ -35,106 +13,10 @@ IS_PACKAGE_CHECK () {
fi
}
#=================================================
# BOOLEAN CONVERTER
#=================================================
bool_to_01 () {
local var="$1"
[ "$var" = "true" ] && var=1
[ "$var" = "false" ] && var=0
echo "$var"
}
bool_to_true_false () {
local var="$1"
[ "$var" = "1" ] && var=true
[ "$var" = "0" ] && var=false
echo "$var"
}
#=================================================
# FUTUR OFFICIAL HELPERS
#=================================================
# 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 2>&1
# 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
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
@ -280,175 +162,6 @@ __PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/service
#=================================================
ynh_debian_release () {
lsb_release --codename --short
}
is_stretch () {
if [ "$(ynh_debian_release)" == "stretch" ]
then
return 0
else
return 1
fi
}
is_jessie () {
if [ "$(ynh_debian_release)" == "jessie" ]
then
return 0
else
return 1
fi
}
#=================================================
ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
# Create an html to serve as maintenance notice
echo "<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3">
<title>Your app $app is currently under maintenance!</title>
<style>
body {
width: 70em;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Your app $app is currently under maintenance!</h1>
<p>This app has been put under maintenance by your administrator at $(date)</p>
<p>Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.</p>
</body>
</html>" > "/var/www/html/maintenance.$app.html"
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
# Use another location, to not be in conflict with the original config file
location ${path_url}_maintenance/ {
alias /var/www/html/ ;
try_files maintenance.$app.html =503;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
# The current config file will redirect all requests to the root of the app.
# To keep the full path, we can use the following rewrite rule:
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
# The difference will be in the $1 at the end, which keep the following queries.
# But, if it works perfectly for a html request, there's an issue with any php files.
# This files are treated as simple files, and will be downloaded by the browser.
# Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was.
systemctl reload nginx
}
ynh_maintenance_mode_OFF () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
sleep 4
# Then remove the temporary files used for the maintenance.
rm "/var/www/html/maintenance.$app.html"
rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
}
#=================================================
# Download and check integrity of a file from app.src_file
#
# The file conf/app.src_file need to contains:
#
# FILE_URL=Address to download the file
# FILE_SUM=Control sum
# # (Optional) Program to check the integrity (sha256sum, md5sum...)
# # default: sha256
# FILE_SUM_PRG=sha256
# # (Optionnal) Name of the local archive (offline setup support)
# # default: Name of the downloaded file.
# FILENAME=example.deb
#
# usage: ynh_download_file --dest_dir="/destination/directory" [--source_id=myfile]
# | arg: -d, --dest_dir= - Directory where to download the file
# | arg: -s, --source_id= - Name of the source file 'app.src_file' if it isn't '$app'
ynh_download_file () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [d]=dest_dir= [s]=source_id= )
local dest_dir
local source_id
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
source_id=${source_id:-app} # If the argument is not given, source_id equals "$app"
# Load value from configuration file (see above for a small doc about this file
# format)
local src_file="$YNH_CWD/../conf/${source_id}.src_file"
# If the src_file doesn't exist, use the backup path instead, with a "settings" directory
if [ ! -e "$src_file" ]
then
src_file="$YNH_CWD/../settings/conf/${source_id}.src_file"
fi
local file_url=$(grep 'FILE_URL=' "$src_file" | cut -d= -f2-)
local file_sum=$(grep 'FILE_SUM=' "$src_file" | cut -d= -f2-)
local file_sumprg=$(grep 'FILE_SUM_PRG=' "$src_file" | cut -d= -f2-)
local filename=$(grep 'FILENAME=' "$src_file" | cut -d= -f2-)
# Default value
file_sumprg=${file_sumprg:-sha256sum}
if [ "$filename" = "" ] ; then
filename="$(basename "$file_url")"
fi
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${filename}"
if test -e "$local_src"
then # Use the local source file if it is present
cp $local_src $filename
else # If not, download the source
local out=`wget -nv -O $filename $file_url 2>&1` || ynh_print_err $out
fi
# Check the control sum
echo "${file_sum} ${filename}" | ${file_sumprg} -c --status \
|| ynh_die "Corrupt file"
# Create the destination directory, if it's not already.
mkdir -p "$dest_dir"
# Move the file to its destination
mv $filename $dest_dir
}
#=================================================
# Create a changelog for an app after an upgrade.
#
# The changelog is printed into the file ./changelog for the time of the upgrade.

54
scripts/backup Normal file
View file

@ -0,0 +1,54 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# 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 () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE DATA DIR
#=================================================
ynh_backup --src_path="/home/yunohost.app/ssh_chroot_directories/$ssh_user" --is_big
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -13,6 +13,9 @@ 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,25 +25,16 @@ ynh_abort_if_errors
ynh_script_progression --message="Retrieve arguments from the manifest" --weight=2
ssh_user=$YNH_APP_ARG_SSH_USER
# Default value is null
ynh_print_OFF; password=${YNH_APP_ARG_PASSWORD:-}; ynh_print_ON
pub_key=${YNH_APP_ARG_PUB_KEY:-}
size=$YNH_APP_ARG_SIZE
app=$YNH_APP_INSTANCE_NAME
#=================================================
# DISCLAIMER
#=================================================
if IS_PACKAGE_CHECK; then
ynh_print_warn "This app can't be tested by package check. Please see the readme for more information. https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh"
fi
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Check if the app can be installed" --weight=2
ynh_script_progression --message="Validating installation parameters..." --weight=2
# Correct user name
# An unix user name can contains only :alnum: and . - _
@ -50,7 +44,7 @@ ssh_user=${ssh_user//[^[:alnum:].\-_]/_}
ynh_system_user_exists $ssh_user && ynh_die "This user already exist"
final_path=/opt/yunohost/$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"
ynh_print_OFF
if test -z "$password" && test -z "$pub_key"
@ -62,21 +56,21 @@ ynh_print_ON
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Store settings from manifest"
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set $app ssh_user $ssh_user
ynh_app_setting_set $app size $size
ynh_app_setting_set --app=$app --key=ssh_user --value=$ssh_user
ynh_app_setting_set --app=$app --key=size --value=$size
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Download, check and unpack source" --weight=2
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
ynh_setup_source --dest_dir="$final_path"
#=================================================
# SPECIFIC SETUP

View file

@ -12,12 +12,12 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings"
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
ssh_user=$(ynh_app_setting_get $app ssh_user)
final_path=$(ynh_app_setting_get $app final_path)
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# SPECIFIC REMOVE
@ -54,8 +54,6 @@ if ! IS_PACKAGE_CHECK; then
$final_path/chroot_manager.sh deluser --name $ssh_user
fi
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE APP MAIN DIR
#=================================================
@ -64,6 +62,8 @@ ynh_script_progression --message="Remove app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# GENERIC FINALIZATION
#=================================================
# DISCLAIMER
#=================================================

132
scripts/restore Normal file
View file

@ -0,0 +1,132 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# 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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..."
ynh_restore_file --origin_path="/home/yunohost.app/ssh_chroot_directories/$ssh_user" --not_mandatory
#=================================================
# SPECIFIC RESTORATION
#=================================================
# SOURCE LIBRARIES
#=================================================
# Load functions ssh_chroot_xxx
source "$final_path/ssh_chroot/ssh_chroot.sh"
#=================================================
# INSTALL QUOTAS SYSTEM
#=================================================
ynh_script_progression --message="Install quotas system" --weight=3
# https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh
if ! IS_PACKAGE_CHECK; then
quotas_install
fi
#=================================================
# CONFIGURE FSTAB TO SUPPORT QUOTAS
#=================================================
ynh_script_progression --message="Configure fstab to support quotas" --weight=3
# https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh
# Set fstab
if ! IS_PACKAGE_CHECK
then
quotas_find_mount_point "$user_dir"
quotas_set_fstab "$quotas_mount_point"
# Activate quotas
quotas_activate "$quotas_mount_point"
fi
#=================================================
# UPDATE THE CHROOT DIRECTORY
#=================================================
ynh_script_progression --message="Update the chroot directory" --weight=3
user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user"
# https://github.com/maniackcrudelis/ssh_chroot/blob/master/ssh_chroot/ssh_chroot.sh
# Build the chroot
ssh_chroot_set_directory "$user_dir"
# Copy some binaries in the chroot
ssh_chroot_standard_binaries "$user_dir"
ssh_chroot_copy_binary rsync "$user_dir"
# Set permissions
if ! IS_PACKAGE_CHECK
then
ssh_chroot_set_permissions "$user_dir" $ssh_user
fi
#=================================================
# UPDATE THE LINK TO CHROOT_MANAGER
#=================================================
ln -sf $final_path/chroot_manager.sh /home/yunohost.app/ssh_chroot_directories/chroot_manager
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
#=================================================
# GENERIC FINALIZATION
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app"

View file

@ -9,29 +9,38 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings"
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
ssh_user=$(ynh_app_setting_get $app ssh_user)
final_path=$(ynh_app_setting_get $app final_path)
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# 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
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -40,9 +49,10 @@ upgrade_type=$(ynh_check_app_version_changed)
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Download, check and unpack source" --weight=2
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
ynh_setup_source --dest_dir="$final_path"
fi
#=================================================
@ -81,6 +91,9 @@ fi
ln -sf $final_path/chroot_manager.sh /home/yunohost.app/ssh_chroot_directories/chroot_manager
# Set permissions to app files
chown -R root: $final_path
#=================================================
# GENERIC FINALIZATION
#=================================================