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

232 lines
9.2 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-05-20 00:11:46 +02:00
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2016-06-04 23:56:19 +02:00
2016-12-14 16:02:43 +01:00
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
2018-05-22 20:01:55 +02:00
ynh_print_OFF; password_admin=$YNH_APP_ARG_PASSWORD; ynh_print_ON
2016-05-20 00:11:46 +02:00
2016-12-14 16:02:43 +01:00
app=$YNH_APP_INSTANCE_NAME
2016-05-20 00:11:46 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
2018-05-22 20:01:55 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2016-12-14 16:02:43 +01:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE A SQL BDD
#=================================================
2015-12-18 14:11:35 +01:00
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
2015-12-18 14:11:35 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2015-12-18 14:11:35 +01:00
ynh_app_setting_set $app final_path $final_path
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
2016-12-14 16:02:43 +01:00
# Delete the install directory.
2018-05-22 20:01:55 +02:00
ynh_secure_remove "$final_path/install"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_add_nginx_config
2015-12-18 14:11:35 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2015-12-18 14:11:35 +01:00
ynh_system_user_create $app # Créer un utilisateur système dédié à l'app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
#=================================================
# SPECIFIC SETUP
#=================================================
# FILL THE DATABASE
#=================================================
2015-12-18 14:11:35 +01:00
# Remplacement des variables dans le fichier sql
if [ $(echo $LANG | cut -c1-2) == "fr" ]
then
2018-05-22 20:01:55 +02:00
langue=french
folders="partagés"
roles=utilisateurs
else
2018-05-22 20:01:55 +02:00
langue=english
folders=shared
roles=users
fi
2018-05-22 20:01:55 +02:00
ynh_replace_string "__APP__" "$app" ../conf/populate.sql
ynh_replace_string "__FINALPATH__" "$final_path" ../conf/populate.sql
ynh_replace_string "__DOMAIN__" "$domain" ../conf/populate.sql
ynh_replace_string "__PATH__" "$path_url" ../conf/populate.sql
ynh_replace_string "__FOLDERS__" "$folders" ../conf/populate.sql
ynh_replace_string "__ROLES__" "$roles" ../conf/populate.sql
ynh_replace_string "__VERSION__" "$(sed -n 3p $final_path/changelog.txt)" ../conf/populate.sql
ynh_replace_string "__TIMEZONE__" "$(cat /etc/timezone)" ../conf/populate.sql
ynh_replace_string "__BCRYPT_MDP__" "$(php $final_path/mdphash.php $password_admin)" ../conf/populate.sql
ynh_replace_string "__LANG__" "$langue" ../conf/populate.sql
ynh_replace_string "__TIME__" "$(date +%s)" ../conf/populate.sql
2015-12-18 14:11:35 +01:00
# Enregistre les infos dans la config YunoHost
2016-12-14 16:02:43 +01:00
ynh_app_setting_set $app langue $langue
# Import du fichier SQL
2018-05-22 20:01:55 +02:00
ynh_mysql_connect_as $db_name $db_pwd $db_name < ../conf/populate.sql
#=================================================
# CREATE TP.CONFIG.PHP FILE
#=================================================
# The file tp.config.php is a dump of the admin part of the database.
tp_config_file="$final_path/includes/config/tp.config.php"
echo "<?php
global \$SETTINGS;
\$SETTINGS = array (" > $tp_config_file
while read settings
do
echo -n " '$(echo $settings | awk '{ print $1 }')'" >> $tp_config_file
echo " => '$(echo $settings | cut -d' ' -f2-)'," >> $tp_config_file
done <<< "$(ynh_mysql_execute_as_root "SELECT intitule, valeur FROM teampass_misc" $app)"
echo ");" >> $tp_config_file
#=================================================
# CONFIGURE TEAMPASS
#=================================================
# Remplacement des variables dans les fichier settings.php et sk.php
2018-05-22 20:01:55 +02:00
ynh_replace_string "__DBUSER__" "$db_name" ../conf/settings.php
ynh_replace_string "__DBPWD__" "$db_pwd" ../conf/settings.php
ynh_replace_string "__FINALPATH__" "$final_path" ../conf/settings.php
path_sk_file=/etc/$app/
mkdir $path_sk_file
ynh_replace_string "__SKPATH__" "$path_sk_file" ../conf/settings.php
#=================================================
# CREATE A SALTKEY
#=================================================
saltkey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{32\}\).*/\1/p')
2018-05-22 20:01:55 +02:00
ynh_replace_string "__SALTKEY__" "$saltkey" ../conf/sk.php
#=================================================
# COPY THE FILES
#=================================================
2018-05-22 20:01:55 +02:00
cp ../conf/sk.php $path_sk_file/sk.php
2018-11-21 16:19:57 +01:00
chown -R $app $path_sk_file
2018-05-22 20:01:55 +02:00
chmod 750 $path_sk_file
cp ../conf/settings.php $final_path/includes/config/settings.php
ynh_store_file_checksum "$final_path/includes/config/settings.php" # Enregistre la somme de contrôle du fichier de config
2018-05-22 20:01:55 +02:00
cp $final_path/includes/libraries/csrfp/libs/csrfp.config.sample.php $final_path/includes/libraries/csrfp/libs/csrfp.config.php # Créer le fichier de config de csrfp
ynh_replace_string "CSRFP_TOKEN\" => \"" "&$(head -n40 /dev/urandom | tr -c -d 'a-f0-9' | head -c50)" $final_path/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne un token, valide en hexadécimal
ynh_replace_string "jsUrl\" => \"" "&includes/libraries/csrfp/js/csrfprotector.js" $final_path/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne l'adresse de csrfprotector.js
#=================================================
# CREATE THE USERS
#=================================================
2018-05-22 20:01:55 +02:00
# Not used anymore, because the current version support ldap.
# But still I keep that here, just in case...
# Ajout des utilisateurs actuels dans la base yunohost
2018-05-22 20:01:55 +02:00
# teampass_users=$(ldapsearch -h localhost -b ou=users,dc=yunohost,dc=org -x objectClass=mailAccount uid | grep uid: | sed 's/uid: //' | xargs)
# id=1
# for teampassuser in $teampass_users
# do
# real_password=$(ynh_string_random) # Génère un mot de passe aléatoire
# password=$(php $final_path/mdphash.php $real_password)
# mail=$(ldapsearch -h localhost -b ou=users,dc=yunohost,dc=org -x uid=$teampassuser mail | grep mail: | sed 's/mail: //' | head -n1)
# Creation de l'utilisateur
2018-05-22 20:01:55 +02:00
# ynh_mysql_execute_as_root "INSERT INTO teampass_users (id, login, pw, groupes_visibles, derniers, key_tempo, last_pw_change, last_pw, admin, fonction_id, groupes_interdits, last_connexion, gestionnaire, email, favourites, latest_items, personal_folder, can_create_root_folder) VALUES (NULL, '$teampassuser', '$password', '1', '', '', '', '', '0', '1', '', '', '0', '$mail', '', '', '1', '1');" $app
# Creation du repertoire personnel
2018-05-22 20:01:55 +02:00
# id_user=$(ynh_mysql_execute_as_root "SELECT id from teampass_users where login='$teampassuser';" $app)
# ynh_mysql_execute_as_root "INSERT INTO teampass_nested_tree (id, parent_id, title, nleft, nright, nlevel, bloquer_creation, bloquer_modification, personal_folder, renewal_period) VALUES (NULL, 0, '$id_user', 0, 0, 1, 0, 0, 1, 0);" $app
#
# ((id++))
# done
#=================================================
2018-05-22 20:01:55 +02:00
# CREATE A CRON FILE FOR AN AUTOMATIC BACKUP
#=================================================
2018-05-22 20:01:55 +02:00
echo "0 0 * * 0 $app cd $final_path/backups && php script.backup.php" > /etc/cron.d/$app
# Add also a clean of old backup.
#=================================================
# GENERIC FINALISATION
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2015-12-18 14:11:35 +01:00
2016-12-14 16:02:43 +01:00
# Les fichiers appartiennent à root
2018-05-22 20:01:55 +02:00
chown -R root: $final_path
# Sauf certains dossiers includes, files et upload
chown -R $app $final_path/{includes,files,upload}
# Restreint l'accès au dossier de backup
2018-05-22 20:01:55 +02:00
chmod 750 $final_path/backups
#=================================================
# RELOAD NGINX
#=================================================
2015-12-18 14:11:35 +01:00
2018-07-13 17:37:28 +02:00
ynh_system_reload --service_name=nginx
2018-05-22 20:01:55 +02:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/teampass_ynh
!!! Be carreful when using this app, we have encountered many issues with the last upgrade. The next upgrade could be also difficult, and may need to reinstall the app and migrate manually."
2018-07-13 17:37:28 +02:00
ynh_send_readme_to_admin --app_message="$message" --recipients="root"