2015-05-30 19:37:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-05-20 00:11:46 +02:00
|
|
|
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
|
|
|
|
# Retrieve arguments
|
|
|
|
if [ $ynh_version = "2.4" ]
|
|
|
|
then
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
password_admin=$YNH_APP_ARG_PASSWORD
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
# Source app helpers
|
2016-06-04 23:17:28 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-05-20 00:11:46 +02:00
|
|
|
else
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
|
|
|
password_admin=$3
|
|
|
|
app=teampass
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Delete files and db if exit with an error
|
|
|
|
EXIT_PROPERLY () {
|
|
|
|
trap '' ERR
|
|
|
|
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
|
|
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!"
|
|
|
|
|
|
|
|
if [ $ynh_version = "2.2" ]; then
|
|
|
|
/bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique.
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
TRAP_ON () { # Activate signal capture
|
|
|
|
trap EXIT_PROPERLY ERR # Capturing exit signals on error
|
|
|
|
}
|
|
|
|
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
|
|
|
|
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
|
|
|
|
# Mais pas la fonction TRAP_OFF...
|
|
|
|
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
|
|
|
|
trap '' ERR # Ignoring exit signals
|
|
|
|
}
|
|
|
|
TRAP_ON
|
2015-05-30 19:37:21 +02:00
|
|
|
|
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
# Vérifie la présence du / en début de path
|
|
|
|
if [ $(echo $path | cut -c1) != "/" ]; then
|
|
|
|
path="/$path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Vérifie la disponibilité du path et du domaine.
|
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
# Vérifie que le mot de passe n'est pas vide.
|
|
|
|
if [[ -z $password_admin ]]; then
|
|
|
|
echo "Mot de passe incorrect"
|
2016-06-04 23:33:21 +02:00
|
|
|
touch /force_stop 2> /dev/null
|
2015-12-18 14:11:35 +01:00
|
|
|
fi
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
# Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
|
|
final_path=/var/www/$app
|
|
|
|
if [ -e "$final_path" ]
|
|
|
|
then
|
|
|
|
echo "This path already contains a folder"
|
2016-06-04 23:33:21 +02:00
|
|
|
touch /force_stop 2> /dev/null
|
2015-12-18 14:11:35 +01:00
|
|
|
fi
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
|
|
|
sudo yunohost app setting $app domain -v $domain
|
|
|
|
sudo yunohost app setting $app path -v $path
|
|
|
|
|
|
|
|
|
|
|
|
# Génère un mot de passe aléatoire.
|
2016-05-20 00:11:46 +02:00
|
|
|
db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
|
2015-12-18 14:11:35 +01:00
|
|
|
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
|
|
|
db_user=$app
|
|
|
|
# Initialise la base de donnée et stocke le mot de passe mysql.
|
2016-05-20 00:11:46 +02:00
|
|
|
if [ $ynh_version = "2.4" ]; then
|
|
|
|
ynh_mysql_create_db $db_user $db_user $db_pwd
|
|
|
|
else
|
|
|
|
sudo yunohost app initdb $db_user -p $db_pwd
|
|
|
|
fi
|
2015-12-06 12:49:32 +01:00
|
|
|
sudo yunohost app setting $app mysqlpwd -v $db_pwd
|
2015-05-30 19:37:21 +02:00
|
|
|
|
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
# Crée le repertoire de destination et stocke son emplacement.
|
|
|
|
sudo mkdir "$final_path"
|
|
|
|
sudo yunohost app setting $app final_path -v $final_path
|
|
|
|
|
|
|
|
# Décompresse la source
|
|
|
|
tar -x -f ../sources/teampass.tar.gz
|
|
|
|
# Copie les fichiers sources
|
|
|
|
sudo cp -a teampass/. "$final_path"
|
|
|
|
# Copie les fichiers additionnels ou modifiés.
|
|
|
|
sudo cp -a ../sources/ajouts/. "$final_path"
|
|
|
|
# Et copie le fichier de config nginx
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2015-12-20 21:03:34 +01:00
|
|
|
# Delete the install directory.
|
|
|
|
sudo rm -r $final_path/install
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
|
|
|
|
# Modifie les variables dans le fichier de configuration nginx
|
|
|
|
sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
2015-12-20 21:03:34 +01:00
|
|
|
sudo sed -i "s@__WWWPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
2015-12-18 14:11:35 +01:00
|
|
|
sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
# Créer le fichier de configuration du pool php-fpm et le configure.
|
2015-12-06 12:49:32 +01:00
|
|
|
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
|
|
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
|
|
|
|
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
|
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
|
|
sudo chown root: $finalphpconf
|
|
|
|
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
|
|
|
|
sudo cp ../conf/php-fpm.ini $finalphpini
|
|
|
|
sudo chown root: $finalphpini
|
|
|
|
sudo service php5-fpm reload
|
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
|
2015-12-20 21:03:34 +01:00
|
|
|
# Installation de php5-cli
|
|
|
|
# sudo apt-get update
|
|
|
|
# sudo apt-get -y install php5-cli
|
2015-12-18 14:11:35 +01:00
|
|
|
|
|
|
|
# Copie du script contenant la fonction bCrypt
|
|
|
|
sudo cp ../conf/mdphash.php $final_path
|
|
|
|
|
2015-12-06 12:49:32 +01:00
|
|
|
# Remplacement des variables dans le fichier sql
|
|
|
|
if [ $(echo $LANG | cut -c1-2) == "fr" ]
|
|
|
|
then
|
|
|
|
langue=french
|
|
|
|
folders=partagés
|
|
|
|
roles=utilisateurs
|
|
|
|
else
|
|
|
|
langue=english
|
|
|
|
folders=shared
|
|
|
|
roles=users
|
|
|
|
fi
|
|
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/populate.sql
|
|
|
|
sed -i "s@__DOMAIN__@$domain@g" ../conf/populate.sql
|
|
|
|
sed -i "s@__PATH__@$path@g" ../conf/populate.sql
|
|
|
|
sed -i "s@__FOLDERS__@$folders@g" ../conf/populate.sql
|
|
|
|
sed -i "s@__ROLES__@$roles@g" ../conf/populate.sql
|
2015-12-06 20:27:02 +01:00
|
|
|
sed -i "s@__VERSION__@$(sed -n 2p $final_path/changelog.md)@g" ../conf/populate.sql
|
2015-12-06 12:49:32 +01:00
|
|
|
sed -i "s@__TIMEZONE__@$(cat /etc/timezone)@g" ../conf/populate.sql
|
|
|
|
sed -i "s@__BCRYPT_MDP__@$(php ../conf/mdphash.php $password_admin)@g" ../conf/populate.sql
|
|
|
|
sed -i "s@__LANG__@$langue@g" ../conf/populate.sql
|
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
# Enregistre les infos dans la config YunoHost
|
2015-12-06 12:49:32 +01:00
|
|
|
sudo yunohost app setting $app langue -v $langue
|
|
|
|
|
|
|
|
# Import du fichier SQL
|
|
|
|
mysql -u $db_user -p$db_pwd $db_user < ../conf/populate.sql
|
|
|
|
|
|
|
|
# Remplacement des variables dans les fichier settings.php et sk.php
|
|
|
|
sed -i "s@__DBUSER__@$db_user@g" ../conf/settings.php
|
|
|
|
sed -i "s@__DBPWD__@$db_pwd@g" ../conf/settings.php
|
|
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/settings.php
|
|
|
|
path_sk_file=/etc/teampass/
|
|
|
|
sudo mkdir $path_sk_file
|
|
|
|
sed -i "s@__SKPATH__@$path_sk_file@g" ../conf/settings.php
|
|
|
|
|
|
|
|
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')
|
|
|
|
sed -i "s@__SALTKEY__@$saltkey@g" ../conf/sk.php
|
|
|
|
|
|
|
|
# Et copie des fichiers à leurs emplacements.
|
|
|
|
sudo cp ../conf/sk.php $path_sk_file/sk.php
|
2015-12-20 21:03:34 +01:00
|
|
|
sudo chown -R root:www-data $path_sk_file
|
|
|
|
sudo chmod 750 $path_sk_file
|
2015-12-06 12:49:32 +01:00
|
|
|
sudo cp ../conf/settings.php $final_path/includes/settings.php
|
2016-05-13 22:08:10 +02:00
|
|
|
sudo cp $final_path/includes/libraries/csrfp/libs/csrfp.config.sample.php $final_path/includes/libraries/csrfp/libs/csrfp.config.php
|
|
|
|
|
2015-12-06 12:49:32 +01:00
|
|
|
|
|
|
|
# Ajout des utilisateurs actuels dans la base yunohost
|
|
|
|
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
|
|
|
|
password=$(php ../conf/mdphash.php $teampassuser)
|
|
|
|
mail=$(sudo 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
|
|
|
|
mysql -u $db_user -p$db_pwd $db_user -e "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');"
|
|
|
|
# Creation du repertoire personnel
|
|
|
|
id_user=$(mysql -u $db_user -p$db_pwd $db_user -se "SELECT id from teampass_users where login='$teampassuser';")
|
|
|
|
mysql -u $db_user -p$db_pwd $db_user -e "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);"
|
|
|
|
|
|
|
|
((id++))
|
|
|
|
done
|
|
|
|
|
2015-12-18 14:11:35 +01:00
|
|
|
|
|
|
|
# Configure les droits d'accès au fichiers
|
|
|
|
# -rw-r----- sur les fichiers
|
|
|
|
sudo find $final_path -type f -print0 | xargs -0 sudo chmod 640
|
|
|
|
# drwxr-x--- sur les dossiers
|
|
|
|
sudo find $final_path -type d -print0 | xargs -0 sudo chmod 750
|
|
|
|
# Les dossiers files et upload ont besoin d'un droit d'écriture.
|
|
|
|
sudo chmod 770 -R $final_path/files $final_path/upload
|
|
|
|
# Le script de conversion csv xml doit être exécutable, au moins par root.
|
|
|
|
sudo chmod 740 $final_path/CsvToXml_For_Teampass.sh
|
|
|
|
# Les fichiers appartiennent à root et sont lisibles par www-data
|
|
|
|
sudo chown -R root:www-data $final_path
|
|
|
|
|
|
|
|
# Recharge la configuration Nginx
|
2015-05-30 19:37:21 +02:00
|
|
|
sudo service nginx reload
|
2015-12-18 14:11:35 +01:00
|
|
|
# Régénère la configuration de SSOwat
|
2015-05-30 19:37:21 +02:00
|
|
|
sudo yunohost app ssowatconf
|