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

88 lines
3.2 KiB
Text
Raw Normal View History

2015-08-20 12:20:05 +02:00
#!/bin/bash
# DotClear 2 installation script for YunoHost
# First arguments
app=dotclear2
2015-08-19 17:41:15 +02:00
domain=$1
path=$2
2015-08-20 12:20:05 +02:00
# Check domain/path availability asap
sudo yunohost app checkurl $domain$path -a $app
2015-08-19 17:41:15 +02:00
if [[ ! $? -eq 0 ]]; then
exit 1
fi
2015-08-20 12:20:05 +02:00
# Other arguments
admin=$3
password=$4
is_public=$5
directory=/var/www/$app/
php_config="$directory/inc/config.php"
db_password="$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')"
master_key=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
firstname=`sudo yunohost user info $admin | grep firstname | cut -d' ' -f2 | tr -d '\n'`
lastname=`sudo yunohost user info $admin | grep lastname | cut -d' ' -f2 | tr -d '\n'`
email=`sudo yunohost user info $admin | grep mail | cut -d' ' -f2 | tr -d '\n'`
TZ=`cat /etc/timezone|tr -d '\n'`
2015-08-19 17:41:15 +02:00
2015-08-20 12:20:05 +02:00
# Save app settings
sudo yunohost app setting $app admin -v "$admin"
sudo yunohost app setting $app is_public -v "$is_public"
2015-08-19 17:41:15 +02:00
2015-08-20 12:20:05 +02:00
# Make sure we got the tools we need for this install
sudo apt install -y curl wget sed
2015-08-19 17:41:15 +02:00
# Initialize database and store mysql password for upgrade
2015-08-20 12:20:05 +02:00
sudo yunohost app initdb $app -p $db_password
sudo yunohost app setting $app mysqlpwd -v $db_password
2015-08-19 17:41:15 +02:00
# Get sources
2015-08-20 12:20:05 +02:00
sudo mkdir -p $directory
cd $directory
sudo wget dotclear.tgz http://download.dotclear.org/latest.tar.gz -O $app.tgz
sudo tar xf $app.tgz
mv dotclear $app
sudo rm -f $app.tgz
sudo chown www-data:www-data -R $app
2015-08-19 17:41:15 +02:00
# Config as if we called in admin/install/wizard.php
2015-08-20 12:20:05 +02:00
sudo mv $php_config.in $php_config
sudo sed -i -e "s;'DC_DBDRIVER','';'DC_DBDRIVER','mysqli';" \
-e "s;'DC_DBHOST','';'DC_DBHOST','localhost';" \
-e "s;'DC_DBUSER','';'DC_DBUSER','$app';" \
-e "s;'DC_DBPASSWORD','';'DC_DBPASSWORD','$db_password';" \
-e "s;'DC_DBNAME','';'DC_DBNAME','$app';" \
-e "s;'DC_MASTER_KEY','';'DC_MASTER_KEY','$master_key';" \
-e "s;'DC_ADMIN_URL','';'DC_ADMIN_URL','https://$domain$path/admin/index.php';" \
-e "s;'DC_ADMIN_MAILFROM','';'DC_ADMIN_MAILFROM','$email';" $php_config
2015-08-19 17:41:15 +02:00
# Modify Nginx configuration file and copy it to Nginx conf directory
2015-08-20 12:20:05 +02:00
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# If app is public, add url to SSOWat conf as skipped_uris
if [ "$is_public" = "Yes" ];
then
# unprotected_uris allows SSO credentials to be passed anyway.
sudo yunohost app setting $app unprotected_uris -v "/"
fi
2015-08-19 17:41:15 +02:00
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app ssowatconf
# Setting first user details and filling database calling admin/install/index.php
2015-08-20 12:20:05 +02:00
success=`curl -F "u_email=$EMAIL" -F "u_firstname=$FIRSTNAME" -F "u_name=$NAME" -F "u_login=$LOGIN" -F "u_pwd=$PWD" -F "u_pwd2=$PWD" -F "u_date=$TZ" $domain$path/admin/install/index.php`
2015-08-19 17:41:15 +02:00
# Success or not success
2015-08-20 12:20:05 +02:00
if [ `echo $success | grep -c success` -ge 0 ]
2015-08-19 17:41:15 +02:00
then
2015-08-20 12:20:05 +02:00
echo Installation OK, $app should be available here $domain$path/
2015-08-19 17:41:15 +02:00
exit 0
else
echo Using curl to finish setup failed, open $domain$path/admin/install/index.php and do it yourself
exit 1
fi