1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wallabag2_ynh.git synced 2024-10-01 13:35:06 +02:00
wallabag2_ynh/scripts/install
JimboJoe b773089381 Update to upstream version 2.2.2 (#24)
Tests worked correctly, merging.
2017-04-11 17:00:21 +02:00

105 lines
3 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Load common variables and helpers
source ./_common.sh
# Retrieve app id
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$(ynh_normalize_url_path $YNH_APP_ARG_PATH)
admin=$YNH_APP_ARG_ADMIN
# Set app specific variables
dbname=$app
dbuser=$app
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| exit 1
# Check admin user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist"
ynh_app_setting_set "$app" admin_user "$admin"
# Check destination directory
DESTDIR="/var/www/${app}"
[[ -d "$DESTDIR" ]] && ynh_die \
"The destination directory '${DESTDIR}' already exists.\
You should safely delete it before installing this app."
# Install dependencies
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|| ynh_die "Unable to install dependencies"
# Create tmp directory and fetch app inside
TMPDIR=$(ynh_mkdir_tmp)
extract_wallabag "$TMPDIR"
# Generate random DES key & password
deskey=$(ynh_string_random 24)
dbpass=$(ynh_string_random)
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
ynh_app_setting_set "$app" deskey "$deskey"
# Initialize database
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# Copy and set Wallabag dist configuration
wb_conf="${TMPDIR}/app/config/parameters.yml"
cp ../conf/parameters.yml "$wb_conf"
sed -i "s@{DBNAME}@${dbname}@g" "$wb_conf"
sed -i "s@{DBUSER}@${dbuser}@g" "$wb_conf"
sed -i "s@{DBPASS}@${dbpass}@g" "$wb_conf"
sed -i "s@{DESKEY}@${deskey}@g" "$wb_conf"
# Install files and set permissions
sudo mv "$TMPDIR" "$DESTDIR"
cd $DESTDIR
sudo chown -R www-data: "$DESTDIR"
# Install dependencies and Wallabag
exec_console www-data "$DESTDIR" wallabag:install
# Add users to Wallabag
for username in $(ynh_user_list); do
user_email=$(sudo yunohost user info "$username" --output-as plain \
| ynh_get_plain_key mail)
user_pass=$(ynh_string_random)
exec_console www-data "$DESTDIR" fos:user:create \
"$username" "$user_email" "$user_pass"
done
# Set admin user
exec_console www-data "$DESTDIR" fos:user:promote --super "$admin"
# Copy and set nginx configuration
if [[ "$path" == "/" ]] ; then
nginx_conf=$PKGDIR/conf/nginx_root.conf
else
nginx_conf=$PKGDIR/conf/nginx_sub_dir.conf
fi
sed -i "s@{LOCATION}@${path:-/}@g" "$nginx_conf"
sed -i "s@{PATH}@${path}@g" "$nginx_conf"
sed -i "s@{DESTDIR}@${DESTDIR}@g" "$nginx_conf"
sed -i "s@{POOLNAME}@${app}@g" "$nginx_conf"
sudo cp "$nginx_conf" "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Copy and set php-fpm configuration
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sed -i "s@{POOLNAME}@${app}@g" $PKGDIR/conf/php-fpm.conf
sed -i "s@{DESTDIR}@${DESTDIR}/@g" $PKGDIR/conf/php-fpm.conf
sudo cp $PKGDIR/conf/php-fpm.conf "$phpfpm_conf"
# Set SSOwat rules
ynh_app_setting_set "$app" unprotected_uris "/"
# Reload services
sudo service php5-fpm restart
sudo service nginx reload