1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/spip_ynh.git synced 2024-09-03 20:25:59 +02:00
spip_ynh/scripts/install

134 lines
4.1 KiB
Text
Raw Normal View History

2015-04-28 17:54:25 +02:00
#!/bin/bash
2017-02-21 04:04:26 +01:00
# Exit on command errors and treat unset variables as an error
set -eu
2017-03-08 00:26:58 +01:00
source .fonctions # Loads the generic functions usually used in the script
source /usr/share/yunohost/helpers # Source app helpers
2016-09-20 01:51:28 +02:00
CLEAN_SETUP () {
2017-03-08 00:26:58 +01:00
# Clean installation residues that are not supported by the remove script.
2017-02-21 04:02:03 +01:00
# Clean hosts
sudo sed -i '/#SPIP/d' /etc/hosts
2016-09-20 01:51:28 +02:00
}
2017-03-08 00:26:58 +01:00
TRAP_ON # Active trap to stop the script if an error is detected.
2016-08-30 00:22:47 +02:00
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
2017-02-21 16:54:39 +01:00
admin_spip=$YNH_APP_ARG_ADMIN
2016-08-30 00:22:47 +02:00
language=$YNH_APP_ARG_LANGUAGE
2016-09-20 01:51:28 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2017-03-05 19:42:06 +01:00
ldap=$YNH_APP_ARG_LDAP
2016-09-20 01:51:28 +02:00
app=$YNH_APP_INSTANCE_NAME
CHECK_VAR "$app" "app name not set"
CHECK_USER "$admin_spip"
2015-04-28 17:54:25 +02:00
2016-09-20 01:51:28 +02:00
CHECK_PATH
2015-04-28 17:05:35 +02:00
2016-09-20 01:51:28 +02:00
CHECK_DOMAINPATH
2015-04-28 17:05:35 +02:00
2016-09-20 01:51:28 +02:00
CHECK_FINALPATH
2015-04-28 17:05:35 +02:00
2017-02-21 04:02:03 +01:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path
2017-02-21 16:54:39 +01:00
ynh_app_setting_set $app admin $admin_spip
2017-02-21 04:02:03 +01:00
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app language $language
2017-03-05 19:42:06 +01:00
ynh_app_setting_set $app ldap $ldap
2015-04-28 17:05:35 +02:00
2017-03-08 00:26:58 +01:00
GENERATE_DB $app # Create a database and a dedicated user in the app name
2015-04-28 17:05:35 +02:00
2017-03-08 00:26:58 +01:00
# Creates the destination directory and stores its location.
sudo mkdir "$final_path"
2017-02-21 15:34:35 +01:00
ynh_app_setting_set $app final_path $final_path
# Get source
SETUP_SOURCE
2015-04-28 17:05:35 +02:00
2017-03-08 00:26:58 +01:00
# Set permissions spip directory
2015-04-28 17:05:35 +02:00
sudo chown -R www-data: $final_path
2017-02-21 18:00:37 +01:00
echo -e "127.0.0.1 $domain #SPIP" | sudo tee -a /etc/hosts
2017-03-08 00:26:58 +01:00
# Copy nginx configuration
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2017-03-08 00:26:58 +01:00
# Modif the variables in the nginx configuration file
sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
2015-04-28 17:05:35 +02:00
2017-02-23 23:52:18 +01:00
if [ "$is_public" = "Yes" ];
then
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Create the php-fpm pool config
2016-09-20 01:51:28 +02:00
POOL_FPM
2015-04-28 18:46:07 +02:00
2017-02-22 00:38:20 +01:00
sudo cp ../conf/connect.php $final_path/config/connect.php
2017-03-05 19:42:06 +01:00
sudo cp ../conf/mes_options.php $final_path/config/mes_options.php
2017-03-08 00:26:58 +01:00
# Change SPIP configuration file variables
2017-03-05 19:42:06 +01:00
sudo sed -i "s@__DB_USER__@$db_user@g" $final_path/config/connect.php
sudo sed -i "s@__DB_PWD__@$db_pwd@g" $final_path/config/connect.php
2017-02-22 01:59:00 +01:00
db_md5=$(echo $db_pwd | md5sum | awk '{print $1}')
db_sha=$(echo $db_pwd | openssl dgst -sha1 -hmac "key" | awk -F'= ' {'print $2'})
2017-02-23 03:08:41 +01:00
language="$(echo $language | head -c 2)"
2017-03-08 00:26:58 +01:00
# Change spip_auteurs table informations
2017-02-22 01:15:59 +01:00
sudo sed -i "s@__ADMIN_SPIP__@$admin_spip@g" ../conf/sql/spip.sql
2017-02-23 15:04:08 +01:00
sudo sed -i "s@__PATH__@$path@g" ../conf/sql/spip.sql
2017-02-22 01:15:59 +01:00
sudo sed -i "s@__DB_USER__@$db_user@g" ../conf/sql/spip.sql
2017-02-22 16:25:39 +01:00
sudo sed -i "s@__DB_PWD__@$db_md5@g" ../conf/sql/spip.sql
2017-02-22 01:59:00 +01:00
sudo sed -i "s@__DOMAIN__@$domain@g" ../conf/sql/spip.sql
2017-02-22 16:25:39 +01:00
sudo sed -i "s@__DB_SHA__@$db_sha@g" ../conf/sql/spip.sql
2017-02-23 03:08:41 +01:00
sudo sed -i "s@__LANG_SPIP__@$language@g" ../conf/sql/spip.sql
2017-02-22 01:59:00 +01:00
for i in 1 2 3 4 5 6 7 8
do
2017-02-22 16:05:03 +01:00
j=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
2017-02-22 01:59:00 +01:00
if [ "$j" = "" ];
then
# For obscure reasons, the loop is too fast at execution
sleep 1
2017-02-22 16:05:03 +01:00
j=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
2017-02-22 01:59:00 +01:00
fi
sudo sed -i "s/__ALEA_ACTUEL__/$j/g" ../conf/sql/spip.sql
sudo sed -i "s/__ALEA_FUTUR__/$j/g" ../conf/sql/spip.sql
done
2017-02-22 01:15:59 +01:00
2017-03-08 00:26:58 +01:00
# Load the tables structure into the database.
2017-02-22 01:15:59 +01:00
mysql --debug-check -u $db_user -p$db_pwd $db_user < ../conf/sql/spip.sql
2017-03-08 00:26:58 +01:00
# Use LDAP for SPIP
2017-03-26 15:36:46 +02:00
if [ "${ldap}" = "Yes" ];
2017-03-05 19:42:06 +01:00
then
sudo cp ../conf/ldap.php $final_path/config/ldap.php
sudo sed -i "s/__LDAP__/ldap/g" $final_path/config/connect.php
sudo mysql -e "INSERT INTO spip_meta (nom, valeur, impt) VALUES ('ldap_statut_import', '1comite', 'oui');" -u $db_user -p$db_pwd $db_user
else
sudo sed -i "s@__LDAP__@@g" $final_path/config/connect.php
fi
# Setup SSOwat
ynh_app_setting_set "$app" is_public "$is_public"
if [ "$is_public" = "Yes" ];
then
ynh_app_setting_set "$app" unprotected_uris "/"
fi
2017-02-21 17:22:15 +01:00
2017-03-08 00:26:58 +01:00
# Reload SSOwat configuration
2017-02-21 18:00:37 +01:00
sudo yunohost app ssowatconf
2015-04-28 17:05:35 +02:00
# Reload Nginx and regenerate SSOwat conf
2017-03-26 16:26:55 +02:00
sudo systemctl reload php5-fpm
sudo systemctl reload nginx
2017-02-21 04:02:03 +01:00
2017-03-08 00:26:58 +01:00
# clean hosts
2017-02-21 04:02:03 +01:00
sudo sed -i '/#SPIP/d' /etc/hosts