1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nextcloud_ynh.git synced 2024-09-03 19:55:57 +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-14 21:59:14 +02:00
parent 2994c1e80c
commit d37d87fdeb
6 changed files with 42 additions and 52 deletions

View file

@ -23,13 +23,6 @@ PKGDIR=$(cd ../; pwd)
# Common helpers # Common helpers
# #
# Print a message to stderr and exit
# usage: die msg [retcode]
die() {
printf "%s" "$1" 1>&2
exit "${2:-1}"
}
# Download and extract ownCloud sources to the given directory # Download and extract ownCloud sources to the given directory
# usage: extract_owncloud DESTDIR [AS_USER] # usage: extract_owncloud DESTDIR [AS_USER]
extract_owncloud() { extract_owncloud() {
@ -40,18 +33,18 @@ extract_owncloud() {
oc_tarball="/tmp/owncloud.tar.bz2" oc_tarball="/tmp/owncloud.tar.bz2"
rm -f "$oc_tarball" rm -f "$oc_tarball"
wget -q -O "$oc_tarball" "$OWNCLOUD_SOURCE_URL" \ wget -q -O "$oc_tarball" "$OWNCLOUD_SOURCE_URL" \
|| die "Unable to download ownCloud tarball" || ynh_die "Unable to download ownCloud tarball"
echo "$OWNCLOUD_SOUCE_SHA256 $oc_tarball" | sha256sum -c >/dev/null \ echo "$OWNCLOUD_SOUCE_SHA256 $oc_tarball" | sha256sum -c >/dev/null \
|| die "Invalid checksum of downloaded tarball" || ynh_die "Invalid checksum of downloaded tarball"
exec_as "$AS_USER" tar xjf "$oc_tarball" -C "$DESTDIR" --strip-components 1 \ exec_as "$AS_USER" tar xjf "$oc_tarball" -C "$DESTDIR" --strip-components 1 \
|| die "Unable to extract ownCloud tarball" || ynh_die "Unable to extract ownCloud tarball"
rm -f "$oc_tarball" rm -f "$oc_tarball"
# apply patches # apply patches
(cd "$DESTDIR" \ (cd "$DESTDIR" \
&& for p in ${PKGDIR}/patches/*.patch; do \ && for p in ${PKGDIR}/patches/*.patch; do \
exec_as "$AS_USER" patch -p1 < $p; done) \ exec_as "$AS_USER" patch -p1 < $p; done) \
|| die "Unable to apply patches to ownCloud" || ynh_die "Unable to apply patches to ownCloud"
} }
# Execute a command as another user # Execute a command as another user

View file

@ -1,10 +1,9 @@
#!/bin/bash #!/bin/bash
set -e set -eu
# Retrieve arguments # Get multi-instances specific variables
backup_dir=$1 app=$YNH_APP_INSTANCE_NAME
app=${!#}
# Set app specific variables # Set app specific variables
dbname=$app dbname=$app
@ -14,9 +13,9 @@ dbuser=$app
. /usr/share/yunohost/helpers . /usr/share/yunohost/helpers
# Retrieve app settings # Retrieve app settings
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get $app path) path=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get $app mysqlpwd) dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
# Copy the app source files # Copy the app source files
DESTDIR="/var/www/$app" DESTDIR="/var/www/$app"

View file

@ -1,13 +1,14 @@
#!/bin/bash #!/bin/bash
set -e set -eu
set -u
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments # Retrieve arguments
domain=$1 domain=$1
path=${2%/} path=${2%/}
admin=$3 admin=$3
app=${!#}
# Load common variables # Load common variables
. ./_common.sh . ./_common.sh
@ -21,16 +22,16 @@ dbuser=$app
# TODO: Check domain/path availability with app helper # TODO: Check domain/path availability with app helper
sudo yunohost app checkurl $domain$path -a $app \ sudo yunohost app checkurl $domain$path -a $app \
|| die "The path ${domain}${path} is not available for app installation." || ynh_die "The path ${domain}${path} is not available for app installation."
# Check user parameter # Check user parameter
ynh_user_exists "$admin" \ ynh_user_exists "$admin" \
|| die "The chosen admin user does not exist." || ynh_die "The chosen admin user does not exist."
ynh_app_setting_set $app admin_user $admin ynh_app_setting_set $app admin_user $admin
# Check destination directory # Check destination directory
DESTDIR="/var/www/$app" DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && die \ [[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\ "The destination directory '$DESTDIR' already exists.\
You should safely delete it before installing this app." You should safely delete it before installing this app."
@ -39,7 +40,7 @@ DATADIR="/home/yunohost.app/${app}/data"
# Install dependencies # Install dependencies
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \ ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|| die "Unable to install dependencies" || ynh_die "Unable to install dependencies"
# Generate random password # Generate random password
dbpass=$(ynh_string_random) dbpass=$(ynh_string_random)
@ -51,7 +52,7 @@ ynh_mysql_create_db $dbname $dbuser $dbpass
# Create a system account for ownCloud # Create a system account for ownCloud
sudo useradd -c "$app system account" \ sudo useradd -c "$app system account" \
-d /var/lib/$app --system --user-group $app \ -d /var/lib/$app --system --user-group $app \
|| die "Unable to create $app system account" || ynh_die "Unable to create $app system account"
# Set system group in hooks # Set system group in hooks
sed -i "s@#GROUP#@${app}@g" ../hooks/post_user_create sed -i "s@#GROUP#@${app}@g" ../hooks/post_user_create
@ -103,7 +104,7 @@ _exec_occ maintenance:install \
--database-user "$dbuser" --database-pass "$dbpass" \ --database-user "$dbuser" --database-pass "$dbpass" \
--admin-user "admin" --admin-pass "$(ynh_string_random 6)" \ --admin-user "admin" --admin-pass "$(ynh_string_random 6)" \
--data-dir "$DATADIR" \ --data-dir "$DATADIR" \
|| die "Unable to install ownCloud" || ynh_die "Unable to install ownCloud"
# Enable plugins and set ownCloud configuration # Enable plugins and set ownCloud configuration
_exec_occ app:enable user_ldap _exec_occ app:enable user_ldap
@ -113,7 +114,7 @@ sudo rm -f "$oc_conf"
# Check LDAP configuratio to see if everything worked well # Check LDAP configuratio to see if everything worked well
_exec_occ ldap:test-config \'\' \ _exec_occ ldap:test-config \'\' \
|| die "An error occured during LDAP configuration" || ynh_die "An error occured during LDAP configuration"
# Enable External Storage and create local mount # Enable External Storage and create local mount
_exec_occ app:enable files_external _exec_occ app:enable files_external

View file

@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Set app specific variables # Set app specific variables
app=${!#}
dbname=$app dbname=$app
dbuser=$app dbuser=$app

View file

@ -1,15 +1,9 @@
#!/bin/bash #!/bin/bash
# Retrieve arguments set -eu
backup_dir=$1
app=${!#}
# TODO: Put a simple die function in app helpers, redeclare it since # Get multi-instances specific variables
# _common.sh cannot be easily sourced app=$YNH_APP_INSTANCE_NAME
die() {
printf "%s" "$1" 1>&2
exit "${2:-1}"
}
# Set app specific variables # Set app specific variables
dbname=$app dbname=$app
@ -25,11 +19,11 @@ dbpass=$(ynh_app_setting_get $app mysqlpwd)
# TODO: Check domain/path availability with app helper # TODO: Check domain/path availability with app helper
sudo yunohost app checkurl $domain$path -a $app \ sudo yunohost app checkurl $domain$path -a $app \
|| die "The path ${domain}${path} is not available for app installation." || ynh_die "The path ${domain}${path} is not available for app installation."
# Check destination directory # Check destination directory
DESTDIR="/var/www/$app" DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && die \ [[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\ "The destination directory '$DESTDIR' already exists.\
You should safely delete it before restoring this app." You should safely delete it before restoring this app."
@ -38,22 +32,22 @@ DATADIR="/home/yunohost.app/${app}/data"
# Check configuration files # Check configuration files
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" 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}'. "The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app." You should safely delete it before restoring this app."
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" 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}'. "The PHP FPM configuration already exists at '${phpfpm_conf}'.
You should safely delete it before restoring this app." You should safely delete it before restoring this app."
# Install dependencies # Install dependencies
ynh_package_install_from_equivs ./owncloud-deps.control \ ynh_package_install_from_equivs ./owncloud-deps.control \
|| die "Unable to install dependencies" || ynh_die "Unable to install dependencies"
# Create a system account for ownCloud # Create a system account for ownCloud
sudo useradd -c "$app system account" \ sudo useradd -c "$app system account" \
-d /var/lib/$app --system --user-group $app \ -d /var/lib/$app --system --user-group $app \
|| die "Unable to create $app system account" || ynh_die "Unable to create $app system account"
# Restore the app files # Restore the app files
sudo cp -a ./www "$DESTDIR" sudo cp -a ./www "$DESTDIR"

View file

@ -1,13 +1,14 @@
#!/bin/bash #!/bin/bash
set -e set -eu
set -u
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Load common variables and helpers # Load common variables and helpers
. ./_common.sh . ./_common.sh
# Retrieve arguments # Set app specific variables
app=${!#}
dbname=$app dbname=$app
dbuser=$app dbuser=$app
@ -22,19 +23,19 @@ dbpass=$(ynh_app_setting_get $app mysqlpwd)
# Check destination directory # Check destination directory
DESTDIR="/var/www/$app" DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && die \ [[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\ "The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first." The app is not correctly installed, you should remove it first."
# Check app's data directory # Check app's data directory
DATADIR="/home/yunohost.app/${app}/data" DATADIR="/home/yunohost.app/${app}/data"
[[ ! -d $DATADIR ]] && die \ [[ ! -d $DATADIR ]] && ynh_die \
"The data directory '$DATADIR' does not exist.\ "The data directory '$DATADIR' does not exist.\
The app is not correctly installed, you should remove it first." The app is not correctly installed, you should remove it first."
# Upgrade dependencies # Upgrade dependencies
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \ ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|| die "Unable to upgrade dependencies" || ynh_die "Unable to upgrade dependencies"
# 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"
@ -96,7 +97,7 @@ sudo chown -R $app: "$DESTDIR" "$DATADIR"
# TODO: Restore old directory in case of failure? # TODO: Restore old directory in case of failure?
_exec_occ maintenance:mode --off _exec_occ maintenance:mode --off
_exec_occ upgrade \ _exec_occ upgrade \
|| ([[ $? -eq 3 ]] || die "Unable to upgrade ownCloud") || ([[ $? -eq 3 ]] || ynh_die "Unable to upgrade ownCloud")
# Enable plugins and set ownCloud configuration # Enable plugins and set ownCloud configuration
_exec_occ app:enable user_ldap _exec_occ app:enable user_ldap