2016-03-28 22:14:19 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
2016-05-15 17:26:39 +02:00
|
|
|
set -eu
|
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
if [ ! -e _common.sh ]; then
|
2017-06-17 23:26:47 +02:00
|
|
|
# Get file fonction if not been to the current directory
|
|
|
|
sudo cp ../settings/scripts/_common.sh ./_common.sh
|
|
|
|
sudo chmod a+rx _common.sh
|
2017-06-02 17:15:57 +02:00
|
|
|
fi
|
|
|
|
# Loads the generic functions usually used in the script
|
|
|
|
source _common.sh
|
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Retrieve app settings
|
2016-05-15 17:26:39 +02:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
2016-05-01 16:41:29 +02:00
|
|
|
path=${path%/}
|
2016-05-15 17:26:39 +02:00
|
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
2016-05-15 23:51:33 +02:00
|
|
|
with_carddav=$(ynh_app_setting_get "$app" with_carddav)
|
2017-07-03 15:05:22 +02:00
|
|
|
with_enigma=$(ynh_app_setting_get "$app" with_enigma)
|
2017-06-02 17:15:57 +02:00
|
|
|
dbname=$app
|
|
|
|
dbuser=$app
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
ynh_backup_before_upgrade # Backup the current version of the app
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_backup_fail_upgrade # restore it if the upgrade fails
|
|
|
|
}
|
|
|
|
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
|
|
|
|
# Init final_path, if ever it got deleted somehow
|
|
|
|
final_path=/var/www/$app
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2016-05-17 13:15:38 +02:00
|
|
|
# FIXME: jessie-backports is needed for php-net-ldap3
|
|
|
|
grep -q -R 'jessie-backports' /etc/apt/sources.list{,.d} || {
|
|
|
|
echo "deb http://httpredir.debian.org/debian jessie-backports main" \
|
|
|
|
| sudo tee -a /etc/apt/sources.list.d/backports.list >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install dependencies
|
2017-07-12 12:48:38 +02:00
|
|
|
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
2016-05-17 13:15:38 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
# Create system user dedicace for this app
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
# Create final_path directory and install app inside
|
|
|
|
sudo mkdir -p $final_path
|
2017-07-11 13:58:14 +02:00
|
|
|
ynh_setup_source "${final_path}"
|
2017-06-02 17:15:57 +02:00
|
|
|
# Change owner by admin for execute composer
|
|
|
|
sudo chown -R admin: "${final_path}"
|
2017-06-19 02:10:09 +02:00
|
|
|
# init_composer "${final_path}" admin
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Install the new Roundcube version
|
2017-06-02 17:56:04 +02:00
|
|
|
sudo php "${final_path}/bin/installto.sh" "$final_path" --force --accept
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Generate a new random DES key
|
|
|
|
deskey=$(ynh_string_random 24)
|
|
|
|
|
|
|
|
# Copy and set Roundcube configuration
|
2017-06-02 17:15:57 +02:00
|
|
|
rc_conf="${final_path}/config/config.inc.php"
|
|
|
|
cp ../conf/config.inc.php "$rc_conf"
|
|
|
|
ynh_substitute_char "#DESKEY#" "$deskey" "$rc_conf"
|
|
|
|
ynh_substitute_char "#DBUSER#" "$dbuser" "$rc_conf"
|
|
|
|
ynh_substitute_char "#DBPASS#" "$dbpass" "$rc_conf"
|
|
|
|
ynh_substitute_char "#DBNAME#" "$dbname" "$rc_conf"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
# Install files and set permissions
|
|
|
|
sudo mkdir -p "${final_path}/logs" "${final_path}/temp"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Check if dependencies need to be updated with composer
|
2017-06-18 17:09:53 +02:00
|
|
|
if [[ -f ${final_path}/composer.json ]]; then
|
2017-06-02 17:15:57 +02:00
|
|
|
exec_composer admin "${final_path}" update --no-dev --prefer-dist
|
2016-03-28 22:14:19 +02:00
|
|
|
else
|
2017-06-02 17:15:57 +02:00
|
|
|
init_composer "${final_path}" admin
|
2016-03-28 22:14:19 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Update or install additional plugins
|
2017-06-18 19:07:19 +02:00
|
|
|
exec_composer admin "${final_path}" update --no-dev --prefer-dist \
|
2017-06-30 15:00:32 +02:00
|
|
|
"johndoh/contextmenu dev-master" \
|
|
|
|
"sblaisot/automatic_addressbook dev-master"
|
2016-03-30 14:38:37 +02:00
|
|
|
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
|
|
|
|
|
2016-05-15 23:51:33 +02:00
|
|
|
# Guess with_carddav value if empty
|
|
|
|
if [[ -z "${with_carddav:-}" ]]; then
|
2017-06-02 17:15:57 +02:00
|
|
|
[[ -f "${final_path}/plugins/carddav/config.inc.php" ]] \
|
2016-05-15 23:51:33 +02:00
|
|
|
&& with_carddav=1 \
|
|
|
|
|| with_carddav=0
|
|
|
|
ynh_app_setting_set "$app" with_carddav "$with_carddav"
|
|
|
|
fi
|
|
|
|
|
2017-06-19 00:16:34 +02:00
|
|
|
# Update or install CardDAV plugin
|
2016-05-15 23:51:33 +02:00
|
|
|
if [[ $with_carddav -eq 1 ]]; then
|
2017-06-19 00:16:34 +02:00
|
|
|
install_carddav "${final_path}" admin \
|
2016-05-15 23:51:33 +02:00
|
|
|
&& installed_plugins+=" 'carddav'," \
|
|
|
|
|| echo "Unable to install CardDAV plugin" >&2
|
|
|
|
fi
|
|
|
|
|
2017-07-03 15:05:22 +02:00
|
|
|
# Guess with_enigma value if empty
|
|
|
|
if [[ -z "${with_enigma:-}" ]]; then
|
|
|
|
[[ -f "${final_path}/plugins/enigma/config.inc.php" ]] \
|
|
|
|
&& with_enigma=1 \
|
|
|
|
|| with_enigma=0
|
|
|
|
ynh_app_setting_set "$app" with_enigma "$with_enigma"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install Enigma plugin
|
|
|
|
if [[ $with_enigma -eq 1 ]]; then
|
|
|
|
sudo cp -a "$final_path/plugins/enigma/config.inc.php.dist" "$final_path/plugins/enigma/config.inc.php" \
|
|
|
|
&& installed_plugins+=" 'enigma'," \
|
|
|
|
|| echo "Unable to install Enigma plugin" >&2
|
|
|
|
fi
|
|
|
|
|
2016-03-30 14:38:37 +02:00
|
|
|
# Update Roundcube configuration
|
2016-04-27 14:38:35 +02:00
|
|
|
sudo sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \
|
2016-05-15 17:26:39 +02:00
|
|
|
"$rc_conf"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-07-03 13:12:59 +02:00
|
|
|
# Update javascript dependencies
|
|
|
|
pushd ${final_path}
|
|
|
|
sudo /usr/bin/php -q ./bin/install-jsdeps.sh
|
|
|
|
popd
|
|
|
|
|
2017-06-18 17:09:53 +02:00
|
|
|
# Owner user app
|
2017-07-11 15:30:30 +02:00
|
|
|
sudo chown -R root: "${final_path}"
|
|
|
|
sudo chown -R $app: "${final_path}/temp/" "${final_path}/logs/"
|
2017-06-18 17:09:53 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
ynh_nginx_config
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
# Create the php-fpm pool config
|
|
|
|
ynh_fpm_config
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Reload services
|
2017-06-02 17:15:57 +02:00
|
|
|
sudo systemctl reload nginx
|