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

[enh] Make use of ynh_die and YNH_APP_INSTANCE_NAME env var

This commit is contained in:
Jérôme Lebleu 2016-05-15 17:26:39 +02:00
parent b3919af317
commit 9ecfb49896
5 changed files with 48 additions and 54 deletions

View file

@ -18,13 +18,6 @@ PKGDIR=$(cd ../; pwd)
# Common helpers
#
# Print a message to stderr and exit
# usage: print MSG [RETCODE]
die() {
printf "%s" "$1" 1>&2
exit "${2:-1}"
}
# Download and extract Roundcube sources to the given directory
# usage: extract_roundcube_to DESTDIR
extract_roundcube() {
@ -33,17 +26,17 @@ extract_roundcube() {
# retrieve and extract Roundcube tarball
rc_tarball="${DESTDIR}/roundcube.tar.gz"
wget -q -O "$rc_tarball" "$ROUNDCUBE_SOURCE_URL" \
|| die "Unable to download Roundcube tarball"
|| ynh_die "Unable to download Roundcube tarball"
echo "$ROUNDCUBE_SOURCE_SHA256 $rc_tarball" | sha256sum -c >/dev/null \
|| die "Invalid checksum of downloaded tarball"
|| ynh_die "Invalid checksum of downloaded tarball"
tar xf "$rc_tarball" -C "$DESTDIR" --strip-components 1 \
|| die "Unable to extract Roundcube tarball"
|| ynh_die "Unable to extract Roundcube tarball"
rm "$rc_tarball"
# apply patches
(cd "$DESTDIR" \
&& for p in ${PKGDIR}/patches/*.patch; do patch -p1 < $p; done) \
|| die "Unable to apply patches to Roundcube"
|| ynh_die "Unable to apply patches to Roundcube"
# copy composer.json-dist for Roundcube with complete dependencies
cp "${PKGDIR}/sources/composer.json-dist" "${DESTDIR}/composer.json-dist"
@ -85,7 +78,7 @@ init_composer() {
curl -sS https://getcomposer.org/installer \
| exec_as "$AS_USER" COMPOSER_HOME="${DESTDIR}/.composer" \
php -- --quiet --install-dir="$DESTDIR" \
|| die "Unable to install Composer"
|| ynh_die "Unable to install Composer"
# install composer.json
exec_as "$AS_USER" \
@ -93,5 +86,5 @@ init_composer() {
# update dependencies to create composer.lock
exec_composer "$AS_USER" "$DESTDIR" install --no-dev \
|| die "Unable to update Roundcube core dependencies"
|| ynh_die "Unable to update Roundcube core dependencies"
}

View file

@ -1,8 +1,10 @@
#!/bin/bash
# Retrieve arguments
backup_dir=$1
app=$2
# Exit on command errors and treat unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Set app specific variables
dbname=$app
@ -12,9 +14,9 @@ dbuser=$app
. /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
dbpass=$(ynh_app_setting_get $app mysqlpwd)
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
# Copy the app files
DESTDIR="/var/www/$app"

View file

@ -1,12 +1,14 @@
#!/bin/bash
set -e
set -u
# Exit on command errors and treat unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$1
path=${2%/}
app=${!#}
# Load common variables
. ./_common.sh
@ -18,13 +20,13 @@ dbuser=$app
# Source app helpers
. /usr/share/yunohost/helpers
# TODO: Check domain/path availability with app helper
sudo yunohost app checkurl $domain$path -a $app \
|| die "The path ${domain}${path} is not available for app installation."
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| exit 1
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && die \
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before installing this app."
@ -68,7 +70,7 @@ installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
# Update Roundcube configuration
sudo sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \
"${DESTDIR}/config/config.inc.php"
"${DESTDIR}/config/config.inc.php"
## Install rcmcarddav TODO: if baikal is detected
#sudo yunohost app list -f baikal --json | grep '"installed": true'

View file

@ -1,15 +1,10 @@
#!/bin/bash
# Retrieve arguments
backup_dir=$1
app=$2
# Exit on command errors and treat unset variables as an error
set -eu
# TODO: Put a simple die function in app helpers, redeclare it since
# _common.sh cannot be easily sourced
die() {
printf "%s" "$1" 1>&2
exit "${2:-1}"
}
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Set app specific variables
dbname=$app
@ -19,27 +14,27 @@ dbuser=$app
. /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
dbpass=$(ynh_app_setting_get $app mysqlpwd)
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
# TODO: Check domain/path availability with app helper
sudo yunohost app checkurl $domain$path -a $app \
|| die "The path ${domain}${path} is not available for app installation."
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| exit 1
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && die \
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before restoring this app."
# Check configuration files
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
[[ -f $nginx_conf ]] && die \
[[ -f $nginx_conf ]] && ynh_die \
"The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app."
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
[[ -f $phpfpm_conf ]] && die \
[[ -f $phpfpm_conf ]] && ynh_die \
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
You should safely delete it before restoring this app."

View file

@ -1,13 +1,15 @@
#!/bin/bash
set -e
set -u
# Exit on command errors and treat unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Load common variables and helpers
. ./_common.sh
# Set app specific variables
app=${!#}
dbname=$app
dbuser=$app
@ -15,14 +17,14 @@ dbuser=$app
. /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
path=${path%/}
dbpass=$(ynh_app_setting_get $app mysqlpwd)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
# Check destination directory
DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && die \
[[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first."
@ -32,7 +34,7 @@ extract_roundcube "$TMPDIR"
# Install the new Roundcube version
sudo php "${TMPDIR}/bin/installto.sh" "$DESTDIR" --force --accept \
|| die "Unable to update Roundcube installation"
|| ynh_die "Unable to update Roundcube installation"
rm -rf "$TMPDIR"
# Generate a new random DES key
@ -72,7 +74,7 @@ installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
# Update Roundcube configuration
sudo sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \
"$rc_conf"
"$rc_conf"
## Install rcmcarddav if baikal is detected
#sudo yunohost app list -f baikal --json | grep '"installed": true'