2016-03-28 22:14:19 +02:00
|
|
|
#
|
|
|
|
# Common variables
|
|
|
|
#
|
|
|
|
|
|
|
|
# Roundcube version
|
2016-05-22 22:31:32 +02:00
|
|
|
VERSION=1.2.0
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2016-05-17 13:15:38 +02:00
|
|
|
# Package name for Roundcube dependencies
|
|
|
|
DEPS_PKG_NAME="roundcube-deps"
|
|
|
|
|
2016-03-28 22:14:19 +02:00
|
|
|
# Roundcube complete tarball checksum
|
2016-05-22 22:31:32 +02:00
|
|
|
ROUNDCUBE_SOURCE_SHA256="e3b89c2772c2c5990da9bca640bc342f486edf356016cf717e6a1083c822b523"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2016-05-01 12:31:42 +02:00
|
|
|
# Remote URL to fetch Roundcube source tarball
|
|
|
|
ROUNDCUBE_SOURCE_URL="https://github.com/roundcube/roundcubemail/releases/download/${VERSION}/roundcubemail-${VERSION}.tar.gz"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# App package root directory should be the parent folder
|
|
|
|
PKGDIR=$(cd ../; pwd)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Common helpers
|
|
|
|
#
|
|
|
|
|
|
|
|
# Download and extract Roundcube sources to the given directory
|
|
|
|
# usage: extract_roundcube_to DESTDIR
|
|
|
|
extract_roundcube() {
|
|
|
|
local DESTDIR=$1
|
|
|
|
|
|
|
|
# retrieve and extract Roundcube tarball
|
|
|
|
rc_tarball="${DESTDIR}/roundcube.tar.gz"
|
2016-05-01 12:11:44 +02:00
|
|
|
wget -q -O "$rc_tarball" "$ROUNDCUBE_SOURCE_URL" \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Unable to download Roundcube tarball"
|
2016-05-01 12:31:42 +02:00
|
|
|
echo "$ROUNDCUBE_SOURCE_SHA256 $rc_tarball" | sha256sum -c >/dev/null \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Invalid checksum of downloaded tarball"
|
2016-03-28 22:14:19 +02:00
|
|
|
tar xf "$rc_tarball" -C "$DESTDIR" --strip-components 1 \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Unable to extract Roundcube tarball"
|
2016-03-28 22:14:19 +02:00
|
|
|
rm "$rc_tarball"
|
|
|
|
|
|
|
|
# apply patches
|
|
|
|
(cd "$DESTDIR" \
|
|
|
|
&& for p in ${PKGDIR}/patches/*.patch; do patch -p1 < $p; done) \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Unable to apply patches to Roundcube"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# copy composer.json-dist for Roundcube with complete dependencies
|
|
|
|
cp "${PKGDIR}/sources/composer.json-dist" "${DESTDIR}/composer.json-dist"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute a command as another user
|
|
|
|
# usage: exec_as USER COMMAND [ARG ...]
|
|
|
|
exec_as() {
|
|
|
|
local USER=$1
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
if [[ $USER = $(whoami) ]]; then
|
|
|
|
eval $@
|
|
|
|
else
|
|
|
|
# use sudo twice to be root and be allowed to use another user
|
|
|
|
sudo sudo -u "$USER" $@
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute a composer command from a given directory
|
|
|
|
# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...]
|
|
|
|
exec_composer() {
|
|
|
|
local AS_USER=$1
|
|
|
|
local WORKDIR=$2
|
|
|
|
shift 2
|
|
|
|
|
|
|
|
exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \
|
|
|
|
php "${WORKDIR}/composer.phar" $@ \
|
|
|
|
-d "${WORKDIR}" --quiet --no-interaction
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install and initialize Composer in the given directory
|
|
|
|
# usage: init_composer DESTDIR [AS_USER]
|
|
|
|
init_composer() {
|
|
|
|
local DESTDIR=$1
|
|
|
|
local AS_USER=${2:-admin}
|
|
|
|
|
|
|
|
# install composer
|
|
|
|
curl -sS https://getcomposer.org/installer \
|
2016-03-30 16:01:05 +02:00
|
|
|
| exec_as "$AS_USER" COMPOSER_HOME="${DESTDIR}/.composer" \
|
|
|
|
php -- --quiet --install-dir="$DESTDIR" \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Unable to install Composer"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# install composer.json
|
|
|
|
exec_as "$AS_USER" \
|
|
|
|
cp "${DESTDIR}/composer.json-dist" "${DESTDIR}/composer.json"
|
|
|
|
|
|
|
|
# update dependencies to create composer.lock
|
2016-03-30 14:19:41 +02:00
|
|
|
exec_composer "$AS_USER" "$DESTDIR" install --no-dev \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Unable to update Roundcube core dependencies"
|
2016-03-28 22:14:19 +02:00
|
|
|
}
|
2016-05-15 23:51:33 +02:00
|
|
|
|
|
|
|
# Install and configure CardDAV plugin for Roundcube
|
|
|
|
# usage: install_carddav DESTDIR [AS_USER]
|
|
|
|
install_carddav() {
|
|
|
|
local DESTDIR=$1
|
|
|
|
local AS_USER=${2:-www-data}
|
|
|
|
|
|
|
|
local carddav_config="${DESTDIR}/plugins/carddav/config.inc.php"
|
|
|
|
local carddav_tmp_config="${PKGDIR}/conf/carddav.config.inc.php"
|
|
|
|
|
|
|
|
exec_composer "$AS_USER" "$DESTDIR" require \
|
|
|
|
"roundcube/carddav dev-master"
|
|
|
|
|
|
|
|
# Look for installed and supported CardDAV servers
|
|
|
|
for carddav_app in "owncloud" "baikal"; do
|
2016-05-17 13:43:22 +02:00
|
|
|
local app_id=$(sudo yunohost app list --installed --output-as plain \
|
|
|
|
-f "$carddav_app" | ynh_get_plain_key '#id' | head -1)
|
|
|
|
[[ -z "$app_id" ]] || {
|
|
|
|
# Retrieve app settings and enable relevant preset
|
|
|
|
carddav_domain=$(ynh_app_setting_get "$app_id" domain)
|
|
|
|
carddav_path=$(ynh_app_setting_get "$app_id" path)
|
|
|
|
carddav_url="https://${carddav_domain}${carddav_path%/}"
|
|
|
|
sed -i "s#{${carddav_app}_url}#${carddav_url}#g" "$carddav_tmp_config"
|
|
|
|
sed -i \
|
2016-05-15 23:51:33 +02:00
|
|
|
"/\/\/\/\/ PRESET FOR: ${carddav_app}/\
|
|
|
|
,/\/\/\/\/ END: ${carddav_app}/s/^\/\///" "$carddav_tmp_config"
|
2016-05-17 13:43:22 +02:00
|
|
|
}
|
2016-05-15 23:51:33 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# Copy plugin the configuration file
|
|
|
|
sudo cp "$carddav_tmp_config" "$carddav_config"
|
|
|
|
sudo chown "${AS_USER}:" "$carddav_config"
|
|
|
|
}
|