🍽 Fork YunoHost — snapshot mangé par la machine à tsoins
Upstream: https://github.com/YunoHost/yunohost @ 3a5f8bac8301c450897b96cbd43a4c7d3ba750fb But (José) : transformer tout le code en bions + ploxions du xerboxion. La carte de digestion vit au labo : /yunohost-digest.json
This commit is contained in:
129
helpers/helpers.v1.d/multimedia
Normal file
129
helpers/helpers.v1.d/multimedia
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (c) 2024 YunoHost Contributors
|
||||
#
|
||||
# This file is part of YunoHost (see https://yunohost.org)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
readonly MEDIA_GROUP=multimedia
|
||||
readonly MEDIA_DIRECTORY=/home/yunohost.multimedia
|
||||
|
||||
# Initialize the multimedia directory system
|
||||
#
|
||||
# usage: ynh_multimedia_build_main_dir
|
||||
#
|
||||
# Requires YunoHost version 4.2 or higher.
|
||||
ynh_multimedia_build_main_dir() {
|
||||
|
||||
## Création du groupe multimedia
|
||||
groupadd -f $MEDIA_GROUP
|
||||
|
||||
## Création des dossiers génériques
|
||||
mkdir -p "$MEDIA_DIRECTORY"
|
||||
mkdir -p "$MEDIA_DIRECTORY/share"
|
||||
mkdir -p "$MEDIA_DIRECTORY/share/Music"
|
||||
mkdir -p "$MEDIA_DIRECTORY/share/Picture"
|
||||
mkdir -p "$MEDIA_DIRECTORY/share/Video"
|
||||
mkdir -p "$MEDIA_DIRECTORY/share/eBook"
|
||||
|
||||
# Disable logging to prevent leaking the user list (and anyway it's long and boring)
|
||||
local xtrace_enable=$(set +o | grep xtrace)
|
||||
set +o xtrace # set +x
|
||||
|
||||
## Création des dossiers utilisateurs
|
||||
for user in $(yunohost user list --output-as json | jq -r '.users | keys[]'); do
|
||||
mkdir -p "$MEDIA_DIRECTORY/$user"
|
||||
mkdir -p "$MEDIA_DIRECTORY/$user/Music"
|
||||
mkdir -p "$MEDIA_DIRECTORY/$user/Picture"
|
||||
mkdir -p "$MEDIA_DIRECTORY/$user/Video"
|
||||
mkdir -p "$MEDIA_DIRECTORY/$user/eBook"
|
||||
ln -sfn "$MEDIA_DIRECTORY/share" "$MEDIA_DIRECTORY/$user/Share"
|
||||
# Création du lien symbolique dans le home de l'utilisateur.
|
||||
#link will only be created if the home directory of the user exists and if it's located in '/home' folder
|
||||
local user_home="$(getent passwd $user | cut -d: -f6 | grep '^/home/')"
|
||||
if [[ -d "$user_home" ]]; then
|
||||
ln -sfn "$MEDIA_DIRECTORY/$user" "$user_home/Multimedia"
|
||||
fi
|
||||
# Propriétaires des dossiers utilisateurs.
|
||||
chown -R $user "$MEDIA_DIRECTORY/$user"
|
||||
done
|
||||
|
||||
# Re-enable logging
|
||||
eval "$xtrace_enable"
|
||||
|
||||
# Default yunohost hooks for post_user_create,delete will take care
|
||||
# of creating/deleting corresponding multimedia folders when users
|
||||
# are created/deleted in the future...
|
||||
|
||||
## Application des droits étendus sur le dossier multimedia.
|
||||
# Droit d'écriture pour le groupe et le groupe multimedia en acl et droit de lecture pour other:
|
||||
setfacl -RnL -m g:$MEDIA_GROUP:rwX,g::rwX,o:r-X "$MEDIA_DIRECTORY" || true
|
||||
# Application de la même règle que précédemment, mais par défaut pour les nouveaux fichiers.
|
||||
setfacl -RnL -m d:g:$MEDIA_GROUP:rwX,g::rwX,o:r-X "$MEDIA_DIRECTORY" || true
|
||||
# Réglage du masque par défaut. Qui garantie (en principe...) un droit maximal à rwx. Donc pas de restriction de droits par l'acl.
|
||||
setfacl -RL -m m::rwx "$MEDIA_DIRECTORY" || true
|
||||
}
|
||||
|
||||
# Add a directory in yunohost.multimedia
|
||||
#
|
||||
# usage: ynh_multimedia_addfolder --source_dir="source_dir" --dest_dir="dest_dir"
|
||||
#
|
||||
# | 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"
|
||||
#
|
||||
# This "directory" will be a symbolic link to a existing directory.
|
||||
#
|
||||
# Requires YunoHost version 4.2 or higher.
|
||||
ynh_multimedia_addfolder() {
|
||||
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=sd
|
||||
local -A args_array=([s]=source_dir= [d]=dest_dir=)
|
||||
local source_dir
|
||||
local dest_dir
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
# Ajout d'un lien symbolique vers le dossier à partager
|
||||
ln -sfn "$source_dir" "$MEDIA_DIRECTORY/$dest_dir"
|
||||
|
||||
## Application des droits étendus sur le dossier ajouté
|
||||
# Droit d'écriture pour le groupe et le groupe multimedia en acl et droit de lecture pour other:
|
||||
setfacl -RnL -m g:$MEDIA_GROUP:rwX,g::rwX,o:r-X "$source_dir"
|
||||
# Application de la même règle que précédemment, mais par défaut pour les nouveaux fichiers.
|
||||
setfacl -RnL -m d:g:$MEDIA_GROUP:rwX,g::rwX,o:r-X "$source_dir"
|
||||
# Réglage du masque par défaut. Qui garantie (en principe...) un droit maximal à rwx. Donc pas de restriction de droits par l'acl.
|
||||
setfacl -RL -m m::rwx "$source_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.
|
||||
#
|
||||
# Requires YunoHost version 4.2 or higher.
|
||||
ynh_multimedia_addaccess() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user