mirror of
https://github.com/YunoHost-Apps/baikal_ynh.git
synced 2024-09-03 18:16:11 +02:00
93 lines
2.7 KiB
Bash
93 lines
2.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
# Retrieve app id
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=${2%/}
|
|
password=$3
|
|
|
|
# Load common variables and helpers
|
|
. ./_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" ]] && ynh_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
|
|
sed -i "s@{POOLNAME}@${app}@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"
|
|
|
|
# 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
|