1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/agendav_ynh.git synced 2024-09-03 20:36:12 +02:00

[enh] Update the upgrade script regarding changes

This commit is contained in:
Jérôme Lebleu 2016-07-15 15:14:59 +02:00
parent 1f2d0b6453
commit 82e8288105
2 changed files with 59 additions and 42 deletions

View file

@ -12,11 +12,11 @@ AJAX interface to allow users to manage their own calendars and shared ones.
## TODO ## TODO
* Update the `upgrade`, `backup` and `restore` scripts * Update the `backup` and `restore` scripts
* Test the upgrade from the 1.x to the 2.x * Test the upgrade from the 1.x to the 2.x
## Links ## Links
* Report a bug: https://dev.yunohost.org/projects/apps/issues * Report a bug: https://dev.yunohost.org/projects/apps/issues
* Nextcloud website: http://agendav.org/ * AgenDAV website: http://agendav.org/
* YunoHost website: https://yunohost.org/ * YunoHost website: https://yunohost.org/

View file

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
set -e set -eu
# Source app helpers # Source common variables and helpers
. /usr/share/yunohost/helpers source ./_common.sh
# Set app specific variables # Set app specific variables
app="agendav" app="agendav"
@ -16,6 +16,18 @@ path=$(ynh_app_setting_get "$app" path)
path=${path%/} path=${path%/}
dbpass=$(ynh_app_setting_get "$app" mysqlpwd) dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
encryptkey=$(ynh_app_setting_get "$app" encryptkey) encryptkey=$(ynh_app_setting_get "$app" encryptkey)
language=$(ynh_app_setting_get "$app" language)
# Set and store language
if [[ -z "$language" ]]; then
# retrieve language the old way
lang=${LANG/.*/}
[[ ${LANGUAGES[$lang]+_} ]] || lang="en"
# retrieve and store the relevant language
language=${LANGUAGES[$lang]}
ynh_app_setting_set "$app" language "$language"
fi
# Check destination directory # Check destination directory
DESTDIR="/var/www/$app" DESTDIR="/var/www/$app"
@ -26,12 +38,10 @@ DESTDIR="/var/www/$app"
# Check whether Baïkal or Radicale is installed # Check whether Baïkal or Radicale is installed
if sudo yunohost app list --installed -f baikal | grep -q id ; then if sudo yunohost app list --installed -f baikal | grep -q id ; then
caldav_app="baikal" caldav_app="baikal"
caldav_principal_path="/cal.php/%u/" caldav_baseurl="/cal.php/"
caldav_calendar_path="/cal.php/calendars/%s/"
elif sudo yunohost app list --installed -f radicale | grep -q id ; then elif sudo yunohost app list --installed -f radicale | grep -q id ; then
caldav_app="radicale" caldav_app="radicale"
caldav_principal_path="/%u/" caldav_baseurl="/"
caldav_calendar_path="/%s/"
else else
ynh_die "You must install Baïkal or Radicale before" ynh_die "You must install Baïkal or Radicale before"
fi fi
@ -40,52 +50,59 @@ fi
ynh_package_is_installed "php5-cli" \ ynh_package_is_installed "php5-cli" \
|| ynh_package_install "php5-cli" || ynh_package_install "php5-cli"
# Clean up existing files and copy new files to the right place # Create tmp directory and fetch app inside
sudo rm -rf "$DESTDIR" TMPDIR=$(ynh_mkdir_tmp)
sudo cp -r ../sources "$DESTDIR" extract_agendav "$TMPDIR"
# Create log directory
LOGDIR=/var/log/agendav
sudo install -m 750 -o www-data -d "$LOGDIR"
# Copy and set AgenDAV configuration
conf_path="${TMPDIR}/web/config/settings.php"
cp ../conf/settings.php "$conf_path"
sed -i "s/{DBUSER}/${dbuser}/g" "$conf_path"
sed -i "s/{DBPASS}/${dbpass}/g" "$conf_path"
sed -i "s/{DBNAME}/${dbname}/g" "$conf_path"
sed -i "s/{ENCRYPTKEY}/${encryptkey}/g" "$conf_path"
sed -i "s@{LOGDIR}@${LOGDIR}@g" "$conf_path"
sed -i "s@{TIMEZONE}@$(cat /etc/timezone)@g" "$conf_path"
sed -i "s@{LANGUAGE}@${language}@g" "$conf_path"
# CalDAV config # CalDAV config
caldav_domain=$(ynh_app_setting_get "$caldav_app" domain) caldav_domain=$(ynh_app_setting_get "$caldav_app" domain)
caldav_path=$(ynh_app_setting_get "$caldav_app" path) caldav_path=$(ynh_app_setting_get "$caldav_app" path)
caldav_url="https://${caldav_domain}${caldav_path%/}" caldav_url="https://${caldav_domain}${caldav_path%/}"
sed -i "s@{PRINCIPAL_URL}@${caldav_url}${caldav_principal_path}@g" \ sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path"
../conf/caldav.php sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path"
sed -i "s@{CALENDAR_URL}@${caldav_url}${caldav_calendar_path}@g" \
../conf/caldav.php
# Database config # Replace files and set permissions
sed -i "s/{DBUSER}/${dbuser}/g" ../conf/database.php sudo rm -rf "$DESTDIR"
sed -i "s/{DBPASS}/${dbpass}/g" ../conf/database.php sudo mv "$TMPDIR" "$DESTDIR"
sed -i "s/{DBNAME}/${dbname}/g" ../conf/database.php
# Main config
LOGDIR=/var/log/agendav
lang=${LANG/.*/}
sed -i "s@{DOMAIN}@${domain}@g" ../conf/config.php
sed -i "s@{PATH}@${path}@g" ../conf/config.php
sed -i "s@{LOGDIR}@${LOGDIR}@g" ../conf/config.php
sed -i "s/{ENCRYPTKEY}/${encryptkey}/g" ../conf/config.php
sed -i "s@{COOKIE_PREFIX}@${path#/}@g" ../conf/config.php
sed -i "s@{COOKIE_DOMAIN}@${domain}@g" ../conf/config.php
sed -i "s@{LANG}@${lang:-en_EN}@g" ../conf/config.php
sed -i "s@{TIMEZONE}@$(cat /etc/timezone)@g" ../conf/config.php
# Copy config files and set permissions
sudo cp ../conf/{config,database,caldav}.php "${DESTDIR}/web/config/"
(cd "$DESTDIR/web/application" && sudo ln -s ../config config)
sudo chown -hR root: "$DESTDIR" sudo chown -hR root: "$DESTDIR"
sudo chown -hR www-data: "${DESTDIR}/web"
sudo chmod -R 750 "${DESTDIR}/web/var"
# Create log directory # Run database migrations
sudo install -m 750 -o www-data -d "$LOGDIR" (cd "$DESTDIR" && sudo sudo -u www-data \
php agendavcli migrations:migrate --no-interaction) \
# Execute database shema update || ynh_die "Unable to run AgenDAV database migration"
sudo /var/www/agendav/bin/agendavcli dbupdate
# Copy and set nginx configuration # Copy and set nginx configuration
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf
sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf
sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf
# comment redirection in case of an installation at root
[[ -n "$path" ]] || sed -i '$s/^/#/' ../conf/nginx.conf
sudo cp ../conf/nginx.conf "$nginx_conf" sudo cp ../conf/nginx.conf "$nginx_conf"
# Copy and set php-fpm configuration
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf
sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
# Reload services # Reload services
sudo service nginx reload || true sudo service php5-fpm restart || true
sudo service nginx reload || true