#!/bin/bash # Exit on command errors and treat unset variables as an error set -eu source .fonctions # Loads the generic functions usually used in the script source /usr/share/yunohost/helpers # Source app helpers CLEAN_SETUP () { # Clean installation residues that are not supported by the remove script. # Clean hosts sudo sed -i '/#SPIP/d' /etc/hosts } TRAP_ON # Active trap to stop the script if an error is detected. domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH admin_spip=$YNH_APP_ARG_ADMIN language=$YNH_APP_ARG_LANGUAGE is_public=$YNH_APP_ARG_IS_PUBLIC ldap=$YNH_APP_ARG_LDAP app=$YNH_APP_INSTANCE_NAME CHECK_VAR "$app" "app name not set" CHECK_USER "$admin_spip" CHECK_PATH CHECK_DOMAINPATH CHECK_FINALPATH ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path ynh_app_setting_set $app admin $admin_spip ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app language $language ynh_app_setting_set $app ldap $ldap GENERATE_DB $app # Create a database and a dedicated user in the app name # Creates the destination directory and stores its location. sudo mkdir "$final_path" ynh_app_setting_set $app final_path $final_path # Get source SETUP_SOURCE # Set permissions spip directory sudo chown -R www-data: $final_path echo -e "127.0.0.1 $domain #SPIP" | sudo tee -a /etc/hosts # Copy nginx configuration sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # 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 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 POOL_FPM sudo cp ../conf/connect.php $final_path/config/connect.php sudo cp ../conf/mes_options.php $final_path/config/mes_options.php #Allow plugins installation directly from SPIP sudo mkdir $final_path/plugins/ sudo mkdir $final_path/plugins/auto/ sudo chown www-data:www-data -R $final_path/plugins/ # Change SPIP configuration file variables 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 db_md5=$(echo $db_pwd | md5sum | awk '{print $1}') db_sha=$(echo $db_pwd | openssl dgst -sha1 -hmac "key" | awk -F'= ' {'print $2'}) language="$(echo $language | head -c 2)" # Change spip_auteurs table informations sudo sed -i "s@__ADMIN_SPIP__@$admin_spip@g" ../conf/sql/spip.sql sudo sed -i "s@__PATH__@$path@g" ../conf/sql/spip.sql sudo sed -i "s@__DB_USER__@$db_user@g" ../conf/sql/spip.sql sudo sed -i "s@__DB_PWD__@$db_md5@g" ../conf/sql/spip.sql sudo sed -i "s@__DOMAIN__@$domain@g" ../conf/sql/spip.sql sudo sed -i "s@__DB_SHA__@$db_sha@g" ../conf/sql/spip.sql sudo sed -i "s@__LANG_SPIP__@$language@g" ../conf/sql/spip.sql for i in 1 2 3 4 5 6 7 8 do 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') if [ "$j" = "" ]; then # For obscure reasons, the loop is too fast at execution sleep 1 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') 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 # Load the tables structure into the database. mysql --debug-check -u $db_user -p$db_pwd $db_user < ../conf/sql/spip.sql # Use LDAP for SPIP if [ "${ldap}" = "Yes" ]; 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 # Reload SSOwat configuration sudo yunohost app ssowatconf # Reload Nginx and regenerate SSOwat conf sudo systemctl reload php5-fpm sudo systemctl reload nginx # clean hosts sudo sed -i '/#SPIP/d' /etc/hosts