mirror of
https://github.com/YunoHost-Apps/nextcloud_ynh.git
synced 2024-09-03 19:55:57 +02:00
145 lines
4.6 KiB
Bash
Executable file
145 lines
4.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
set -u
|
|
|
|
# Load common variables and helpers
|
|
. ./_common.sh
|
|
|
|
# Retrieve arguments
|
|
app=${!#}
|
|
dbname=$app
|
|
dbuser=$app
|
|
|
|
# Source app helpers
|
|
. /usr/share/yunohost/helpers
|
|
|
|
# Retrieve app settings
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
path=$(ynh_app_setting_get $app path)
|
|
path=${path%/}
|
|
dbpass=$(ynh_app_setting_get $app mysqlpwd)
|
|
|
|
# Check destination directory
|
|
DESTDIR="/var/www/$app"
|
|
[[ ! -d $DESTDIR ]] && die \
|
|
"The destination directory '$DESTDIR' does not exist.\
|
|
The app is not correctly installed, you should remove it first."
|
|
|
|
# Check app's data directory
|
|
DATADIR="/home/yunohost.app/${app}/data"
|
|
[[ ! -d $DATADIR ]] && die \
|
|
"The data directory '$DATADIR' does not exist.\
|
|
The app is not correctly installed, you should remove it first."
|
|
|
|
# Upgrade dependencies
|
|
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|
|
|| die "Unable to upgrade dependencies"
|
|
|
|
# Copy and set nginx configuration
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
sed -i "s@#APP#@${app}@g" ../conf/nginx.conf
|
|
sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf
|
|
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf
|
|
sed -i "s@#DESTDIR#@${DESTDIR}@g" ../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@#USER#@${app}@g" ../conf/php-fpm.conf
|
|
sed -i "s@#GROUP#@${app}@g" ../conf/php-fpm.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"
|
|
sudo chown root: $phpfpm_conf
|
|
sudo chmod 644 $phpfpm_conf
|
|
|
|
# Set system group in hooks
|
|
sed -i "s@#GROUP#@${app}@g" ../hooks/post_user_create
|
|
|
|
# occ helper for the current installation
|
|
_exec_occ() {
|
|
exec_occ "$DESTDIR" "$app" $@
|
|
}
|
|
|
|
# Retrieve new ownCloud sources in a temporary directory
|
|
TMPDIR=$(ynh_mkdir_tmp)
|
|
extract_owncloud "$TMPDIR"
|
|
|
|
# Copy ownCloud configuration file
|
|
oc_conf="${DESTDIR}/config.json"
|
|
sed -i "s@#DOMAIN#@${domain}@g" ../conf/config.json
|
|
sed -i "s@#DATADIR#@${DATADIR}@g" ../conf/config.json
|
|
sudo cp ../conf/config.json "${TMPDIR}/config.json"
|
|
|
|
# Copy configuration for external storage plugin
|
|
sudo cp ../conf/mount.json "$DATADIR"
|
|
|
|
# Enable maintenance mode
|
|
_exec_occ maintenance:mode --on
|
|
|
|
# Copy config and 3rd party applications from current directory
|
|
sudo cp -a "${DESTDIR}/config/config.php" "${TMPDIR}/config/config.php"
|
|
for a in $(sudo ls "${DESTDIR}/apps"); do
|
|
[[ ! -d "${TMPDIR}/apps/$a" ]] \
|
|
&& sudo cp -a "${DESTDIR}/apps/$a" "${TMPDIR}/apps/$a"
|
|
done
|
|
|
|
# Rename existing app directory and move new one
|
|
sudo rm -rf "${DESTDIR}"
|
|
sudo mv "$TMPDIR" "$DESTDIR"
|
|
|
|
# Set app folders ownership
|
|
sudo chown -R $app: "$DESTDIR" "$DATADIR"
|
|
|
|
# Upgrade ownCloud (SUCCESS = 0, UP_TO_DATE = 3)
|
|
# TODO: Restore old directory in case of failure?
|
|
_exec_occ maintenance:mode --off
|
|
_exec_occ upgrade \
|
|
|| ([[ $? -eq 3 ]] || die "Unable to upgrade ownCloud")
|
|
|
|
# Enable plugins and set ownCloud configuration
|
|
_exec_occ app:enable user_ldap
|
|
_exec_occ config:import "$oc_conf"
|
|
sudo rm -f "$oc_conf"
|
|
|
|
# Enable External Storage and create local mount as needed
|
|
_exec_occ app:enable files_external
|
|
_exec_occ files_external:list --output=json \
|
|
| grep -q '"storage":"\\\\OC\\\\Files\\\\Storage\\\\Local"' \
|
|
|| _exec_occ files_external:create \
|
|
'Home' 'local' 'null::null' -c 'datadir=/home/$user'
|
|
|
|
# Add dynamic logout URL to the config
|
|
# TODO: if changes are made to this section, replace it with new one.
|
|
_exec_occ config:system:get logout_url >/dev/null 2>&1 \
|
|
|| sudo su -c "echo \"
|
|
//-YunoHost-
|
|
// set logout_url according to main domain
|
|
\\\$main_domain = exec('cat /etc/yunohost/current_host');
|
|
\\\$CONFIG['logout_url'] = 'https://'.\\\$main_domain.'/yunohost/sso/?action=logout';
|
|
//-YunoHost-
|
|
\" >> ${DESTDIR}/config/config.php" -- $app
|
|
|
|
# Iterate over users to extend their home folder permissions - for the external
|
|
# storage plugin usage - and create relevant ownCloud directories
|
|
for u in $(ynh_user_list); do
|
|
sudo mkdir -p "${DATADIR}/${u}"
|
|
sudo setfacl -m g:$app:rwx "/home/$u" || true
|
|
done
|
|
|
|
# Fix app ownerships & permissions
|
|
sudo find ${DESTDIR}/ -type f -print0 | sudo xargs -0 chmod 0644
|
|
sudo find ${DESTDIR}/ -type d -print0 | sudo xargs -0 chmod 0755
|
|
sudo find ${DATADIR}/ -type f -print0 | sudo xargs -0 chmod 0640
|
|
sudo find ${DATADIR}/ -type d -print0 | sudo xargs -0 chmod 0750
|
|
sudo chmod 640 "${DESTDIR}/config/config.php"
|
|
sudo chmod 755 /home/yunohost.app
|
|
|
|
# Set SSOwat rules
|
|
ynh_app_setting_set "$app" unprotected_uris "/remote.php"
|
|
ynh_app_setting_set "$app" skipped_uris "/.well-known"
|
|
|
|
# Reload services
|
|
sudo service php5-fpm restart || true
|
|
sudo service nginx reload || true
|