1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cheky_ynh.git synced 2024-09-03 18:16:00 +02:00
cheky_ynh/scripts/install

79 lines
2.4 KiB
Text
Raw Normal View History

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/Cheky/archive/3.8.1.zip -O Cheky.zip
2016-12-30 17:46:49 +01:00
# Uncompress
sudo unzip -qq Cheky.zip -d ..
2016-12-30 17:46:49 +01:00
2016-09-18 11:03:26 +02:00
# Copy source files
src_path=/var/www/$app
sudo mkdir -p $src_path/var
sudo cp -a ../Cheky*/. $src_path
2016-09-18 11:03:26 +02:00
# Set permissions to app files
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 Cheky via curl
2016-09-18 11:03:26 +02:00
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/Cheky-install.log 2>&1
2016-09-18 11:03:26 +02:00
#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/Cheky.cron
sudo cp ../conf/Cheky.cron "$cron_path"
sudo chmod 644 "$cron_path"