1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/baikal_ynh.git synced 2024-09-03 18:16:11 +02:00
baikal_ynh/scripts/install
Jérôme Lebleu 1252a08d63 [enh] Update to Baikal 0.4.4 and download upstream sources
Sources are removed from the repository and downloaded instead to
improve readability and updates. This also comes with a patch to add
LDAP authentication backend.
The `install` and `remove` scripts have also been almost rewrite to
make use of new YunoHost helpers and facilities coming with 2.3.x.
2016-05-02 23:01:28 +02:00

91 lines
2.6 KiB
Bash

#!/bin/bash
set -e
# Retrieve arguments
domain=$1
path=${2%/}
password=$3
app=${!#}
# Load common variables and helpers
source ./_common.sh
# Set app specific variables
dbname=$app
dbuser=$app
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| exit 1
# Check destination directory
DESTDIR="/var/www/${app}"
[[ -d "$DESTDIR" ]] && die \
"The destination directory '${DESTDIR}' already exists.\
You should safely delete it before installing this app."
# Create tmp directory and fetch app inside
TMPDIR=$(ynh_mkdir_tmp)
extract_baikal "$TMPDIR"
# Generate random DES key & password
deskey=$(ynh_string_random 24)
dbpass=$(ynh_string_random)
# Initialize database
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
< "${TMPDIR}/Core/Resources/Db/MySQL/db.sql"
# Create admin password hash
password_hash=$(echo -n admin:BaikalDAV:$password | md5sum | cut -d ' ' -f 1)
# Copy and set Baikal configuration
bk_conf="${TMPDIR}/Specific/config.php"
cp ../conf/config.php "$bk_conf"
sed -i "s@#TIMEZONE#@$(cat /etc/timezone)@g" "$bk_conf"
sed -i "s@#PASSWORDHASH#@${password_hash}@g" "$bk_conf"
bk_conf="${TMPDIR}/Specific/config.system.php"
cp ../conf/config.system.php "$bk_conf"
sed -i "s@#PATH#@${path}@g" "$bk_conf"
sed -i "s@#DBNAME#@${dbname}@g" "$bk_conf"
sed -i "s@#DBUSER#@${dbuser}@g" "$bk_conf"
sed -i "s@#DBPASS#@${dbpass}@g" "$bk_conf"
sed -i "s@#DESKEY#@${deskey}@g" "$bk_conf"
# Disable installation
touch "${TMPDIR}/Specific/INSTALL_DISABLED"
# Install files and set permissions
sudo mv "$TMPDIR" "$DESTDIR"
sudo chown -R www-data: "$DESTDIR"
# Copy and set nginx configuration
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@#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@#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
# Save app settings
ynh_app_setting_set "$app" password "$password"
ynh_app_setting_set "$app" encrypt_key "$deskey"
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
# Set SSOwat rules
ynh_app_setting_set "$app" skipped_uris "/"
ynh_app_setting_set "$app" protected_uris "/admin/"
# Reload services
#sudo service php5-fpm restart || true
sudo service nginx reload || true