mirror of
https://github.com/YunoHost-Apps/piwigo_ynh.git
synced 2024-09-03 20:06:03 +02:00
Simplify the mess about seting up sources, install dir, data dir, plugin dirs ...
This commit is contained in:
parent
cdc6f8e6c0
commit
fb61948453
4 changed files with 37 additions and 121 deletions
|
@ -78,7 +78,6 @@ ram.runtime = "50M"
|
||||||
[resources.install_dir]
|
[resources.install_dir]
|
||||||
|
|
||||||
[resources.data_dir]
|
[resources.data_dir]
|
||||||
subdirs = [ "_data", "upload", "galleries" ]
|
|
||||||
|
|
||||||
[resources.permissions]
|
[resources.permissions]
|
||||||
main.url = "/"
|
main.url = "/"
|
||||||
|
|
|
@ -1,50 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# COMMON VARIABLES
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# PERSONAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# EXPERIMENTAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Check available space before creating a temp directory.
|
|
||||||
#
|
|
||||||
# usage: ynh_smart_mktemp --min_size="Min size"
|
|
||||||
#
|
|
||||||
# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb
|
|
||||||
ynh_smart_mktemp () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [s]=min_size= )
|
|
||||||
local min_size
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
min_size="${min_size:-300}"
|
|
||||||
# Transform the minimum size from megabytes to kilobytes
|
|
||||||
min_size=$(( $min_size * 1024 ))
|
|
||||||
|
|
||||||
# Check if there's enough free space in a directory
|
|
||||||
is_there_enough_space () {
|
|
||||||
local free_space=$(df --output=avail "$1" | sed 1d)
|
|
||||||
test $free_space -ge $min_size
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_there_enough_space /tmp; then
|
|
||||||
local tmpdir=/tmp
|
|
||||||
elif is_there_enough_space /var; then
|
|
||||||
local tmpdir=/var
|
|
||||||
elif is_there_enough_space /; then
|
|
||||||
local tmpdir=/
|
|
||||||
elif is_there_enough_space /home; then
|
|
||||||
local tmpdir=/home
|
|
||||||
else
|
|
||||||
ynh_die "Insufficient free space to continue..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$(mktemp --directory --tmpdir="$tmpdir")"
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
@ -14,27 +8,29 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Setting up source files..." --weight=5
|
ynh_script_progression --message="Setting up source files..." --weight=5
|
||||||
|
|
||||||
# Create tmp directory and fetch app inside
|
ynh_setup_source --dest_dir="$install_dir"
|
||||||
tmpdir="$(ynh_smart_mktemp --min_size=300)"
|
ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin
|
||||||
ynh_setup_source --dest_dir="$tmpdir"
|
ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin
|
||||||
|
|
||||||
# Fetch needed plugins
|
|
||||||
mkdir -p $tmpdir/plugins/Ldap_Login
|
|
||||||
ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin
|
|
||||||
ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin
|
|
||||||
|
|
||||||
# sets extended pattern matching options in the bash shell
|
|
||||||
shopt -s extglob
|
|
||||||
|
|
||||||
# Install files and set permissions
|
|
||||||
cp -a $tmpdir/!(upload|_data|galleries) $install_dir
|
|
||||||
|
|
||||||
chmod 750 "$install_dir"
|
chmod 750 "$install_dir"
|
||||||
chmod -R o-rwx "$install_dir"
|
chmod -R o-rwx "$install_dir"
|
||||||
chown -R $app:www-data "$install_dir"
|
chown -R $app:www-data "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PHP-FPM CONFIGURATION
|
# CONFIGURE DATA DIRECTORY
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Initializing data directory..." --weight=1
|
||||||
|
|
||||||
|
mv $install_dir/_data $data_dir/_data
|
||||||
|
mv $install_dir/upload $data_dir/upload
|
||||||
|
mv $install_dir/galleries $data_dir/galleries
|
||||||
|
|
||||||
|
chmod 750 "$data_dir"
|
||||||
|
chmod -R o-rwx "$data_dir"
|
||||||
|
chown -R $app:www-data "$data_dir"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SYSTEM CONFIGURATIONS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
||||||
|
|
||||||
|
@ -42,27 +38,6 @@ ynh_add_fpm_config
|
||||||
|
|
||||||
ynh_add_nginx_config
|
ynh_add_nginx_config
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC SETUP
|
|
||||||
#=================================================
|
|
||||||
# CREATE DATA DIRECTORY
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Creating a data directory..." --weight=1
|
|
||||||
|
|
||||||
ln -sd $data_dir/_data $install_dir/_data
|
|
||||||
ln -sd $data_dir/upload $install_dir/upload
|
|
||||||
ln -sd $data_dir/galleries $install_dir/galleries
|
|
||||||
|
|
||||||
cp -Rp $tmpdir/_data/. $install_dir/_data
|
|
||||||
cp -Rp $tmpdir/upload/. $install_dir/upload
|
|
||||||
cp -Rp $tmpdir/galleries/. $install_dir/galleries
|
|
||||||
|
|
||||||
ynh_secure_remove --file="$tmpdir"
|
|
||||||
|
|
||||||
chmod 750 "$data_dir"
|
|
||||||
chmod -R o-rwx "$data_dir"
|
|
||||||
chown -R $app:www-data "$data_dir"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP APPLICATION WITH CURL
|
# SETUP APPLICATION WITH CURL
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -10,7 +10,6 @@ else
|
||||||
language="en_UK"
|
language="en_UK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK VERSION
|
# CHECK VERSION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -21,42 +20,33 @@ upgrade_type=$(ynh_check_app_version_changed)
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# sets extended pattern matching options in the bash shell
|
# Get rid of legacy symlinks
|
||||||
shopt -s extglob
|
[ -L "$install_dir/_data" ] && ynh_secure_remove "$install_dir/_data" || true
|
||||||
|
[ -L "$install_dir/galleries" ] && ynh_secure_remove "$install_dir/galleries" || true
|
||||||
|
[ -L "$install_dir/upload" ] && ynh_secure_remove "$install_dir/upload" || true
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
then
|
then
|
||||||
ynh_script_progression --message="Upgrading source files..." --weight=3
|
ynh_script_progression --message="Upgrading source files..." --weight=3
|
||||||
|
|
||||||
# Create tmp directory and fetch app inside
|
ynh_setup_source --dest_dir="$install_dir"
|
||||||
tmpdir="$(ynh_smart_mktemp --min_size=300)"
|
ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin
|
||||||
ynh_setup_source --dest_dir="$tmpdir"
|
ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin
|
||||||
|
|
||||||
# Fetch needed plugins
|
# We don't want to keep those in the install dir, they already are in $data_dir
|
||||||
mkdir -p $tmpdir/plugins/Ldap_Login
|
if [ -d "$install_dir/_data" ] && [ ! -L "$install_dir/_data" ]
|
||||||
ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin
|
then
|
||||||
ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin
|
ynh_secure_remove "$install_dir/_data"
|
||||||
|
fi
|
||||||
# Install files and set permissions
|
if [ -d "$install_dir/galleries" ] && [ ! -L "$install_dir/galleries" ]
|
||||||
cp -a $tmpdir/!(upload|_data|galleries) $install_dir
|
then
|
||||||
|
ynh_secure_remove "$install_dir/galleries"
|
||||||
# Backward compatibility:
|
fi
|
||||||
# If the _data subdirectory wasn't already moved to /home/yunohost.app/$app,
|
if [ -d "$install_dir/upload" ] && [ ! -L "$install_dir/upload" ]
|
||||||
# then move it there
|
then
|
||||||
if [ ! -h $install_dir/_data ] ; then
|
ynh_secure_remove "$install_dir/upload"
|
||||||
mv $install_dir/_data $data_dir
|
|
||||||
ln -sd $data_dir/_data $install_dir/_data
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Backward compatibility:
|
|
||||||
# If the galleries subdirectory wasn't already moved to /home/yunohost.app/$app,
|
|
||||||
# then move it there
|
|
||||||
if [ ! -h $install_dir/galleries ] ; then
|
|
||||||
mv $install_dir/galleries $data_dir
|
|
||||||
ln -sd $data_dir/galleries $install_dir/galleries
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_secure_remove --file="$tmpdir"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod 750 "$data_dir"
|
chmod 750 "$data_dir"
|
||||||
|
|
Loading…
Reference in a new issue