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

78 lines
2.4 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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}"
# Download sources
sudo wget -q https://github.com/Blount/Cheky/archive/3.8.1.zip -O Cheky.zip
# Uncompress
sudo unzip -qq Cheky.zip -d ..
# Copy source files
src_path=/var/www/$app
sudo mkdir -p $src_path/var
sudo cp -a ../Cheky*/. $src_path
# Set permissions to app files
sudo chown -R www-data: $src_path
# 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
ynh_app_setting_set "$app" unprotected_uris "/"
sudo yunohost app ssowatconf
# Configure Cheky 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/Cheky-install.log 2>&1
#protect URIs if private
if [ $is_public -eq 0 ];
then
ynh_app_setting_delete "$app" unprotected_uris
ynh_app_setting_set "$app" protected_uris "/"
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"