2016-09-18 11:03:26 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
|
|
# Save app settings
|
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
|
|
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
|
|
2016-12-30 17:46:49 +01:00
|
|
|
|
# Download sources
|
|
|
|
|
sudo wget -q https://github.com/Blount/LBCAlerte/archive/3.3.zip -O LBCAlerte.zip
|
|
|
|
|
|
|
|
|
|
# Uncompress
|
|
|
|
|
sudo unzip -qq LBCAlerte.zip -d ..
|
|
|
|
|
|
2016-09-18 11:03:26 +02:00
|
|
|
|
# Copy source files
|
|
|
|
|
src_path=/var/www/$app
|
|
|
|
|
sudo mkdir -p $src_path/var
|
2016-12-30 17:46:49 +01:00
|
|
|
|
sudo cp -a ../LBCAlerte*/. $src_path
|
2016-09-18 11:03:26 +02:00
|
|
|
|
|
|
|
|
|
# Set permissions to app files
|
2016-11-26 19:19:16 +01:00
|
|
|
|
sudo chown -R www-data: $src_path
|
2016-09-18 11:03:26 +02:00
|
|
|
|
|
|
|
|
|
# Generate MySQL password and create database
|
|
|
|
|
dbuser=$app
|
|
|
|
|
dbname=$app
|
|
|
|
|
dbpass=$(ynh_string_random 12)
|
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
|
|
|
|
|
|
# Load initial SQL into the new database
|
|
|
|
|
#ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < "../sources/sql/mysql.init.sql"
|
|
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
|
nginx_conf=../conf/nginx.conf
|
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
|
|
|
|
sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
|
|
|
|
|
# If a dedicated php-fpm process is used:
|
|
|
|
|
# Don't forget to modify ../conf/nginx.conf accordingly or your app will not work!
|
|
|
|
|
# sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
|
|
|
|
|
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
|
|
# Set permissions and reload nginx (needed at this stage for the PHP piwigo installation process)
|
|
|
|
|
sudo service nginx reload
|
2016-12-30 17:34:11 +01:00
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2016-09-18 11:03:26 +02:00
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Configure LBCAlerte via curl
|
|
|
|
|
sleep 2
|
|
|
|
|
curl --resolve $domain:443:127.0.0.1 -kL -X POST https://$domain$path/index.php?mod=install --data "password=$password&confirmPassword=$password&type=db&db[host]=localhost&db[user]=$dbuser&db[password]=$dbpass&db[dbname]=$dbname" > /tmp/LBCAlerte-install.log 2>&1
|
|
|
|
|
|
|
|
|
|
#protect URIs if private
|
|
|
|
|
if [ $is_public -eq 0 ];
|
|
|
|
|
then
|
2016-12-30 17:34:11 +01:00
|
|
|
|
ynh_app_setting_delete "$app" unprotected_uris
|
|
|
|
|
ynh_app_setting_set "$app" protected_uris "/"
|
2016-09-18 11:03:26 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Add cron job
|
|
|
|
|
cron_path="/etc/cron.d/$app"
|
|
|
|
|
sed -i "s@#DESTDIR#@${src_path}@g" ../conf/LBCAlerte.cron
|
|
|
|
|
sudo cp ../conf/LBCAlerte.cron "$cron_path"
|
|
|
|
|
sudo chmod 644 "$cron_path"
|