From 1d689fcfc6e209514854b8f8b9eb5e5af86c2ddc Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 20 May 2016 00:11:46 +0200 Subject: [PATCH] trap et maj ynh 2.4 --- README.md | 5 ++++ manifest.json | 9 +++++++ manifest2.2.json | 50 +++++++++++++++++++++++++++++++++++++++ scripts/backup | 7 +++++- scripts/install | 61 +++++++++++++++++++++++++++++++++++++++--------- scripts/remove | 61 +++++++++++++++++++++++++++++++++++++----------- scripts/restore | 7 +++++- scripts/upgrade | 7 +++++- scripts/upgrade~ | 58 --------------------------------------------- 9 files changed, 180 insertions(+), 85 deletions(-) create mode 100644 manifest2.2.json delete mode 100644 scripts/upgrade~ diff --git a/README.md b/README.md index ac9db6b..e2a79bb 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,8 @@ Teampass peut-être configuré uniquement via le compte administrateur. Pour cel Pour utiliser la fonction de sauvegarde automatique, il est nécessaire de mettre en place un cron contenant ceci dans /etc/cron.d/teampass: ```0 0 * * * www-data cd /var/www/teampass/backups && php script.backup.php``` + +Mise à jour du package: +sudo yunohost app upgrade -u https://github.com/Ackak/teampass_ynh + +Multi-utilisateur: Oui, avec support ldap. diff --git a/manifest.json b/manifest.json index 3cde640..0df48c7 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,10 @@ { "name": "Teampass", "id": "teampass", + "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4" + }, "description": { "en": "Passwords Manager", "fr": "Gestionnaire de mots de passes." @@ -13,6 +17,11 @@ "email": "ackak_ynh@ackak.net maniackc_dev@crudelis.fr matlink@matlink.fr" }, "multi_instance": "false", + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], "arguments": { "install" : [ { diff --git a/manifest2.2.json b/manifest2.2.json new file mode 100644 index 0000000..dea5a1a --- /dev/null +++ b/manifest2.2.json @@ -0,0 +1,50 @@ +{ + "name": "Teampass", + "id": "teampass", + "packaging_format": 1, + "description": { + "en": "Passwords Manager", + "fr": "Gestionnaire de mots de passes." + }, + "version": "2.1.24.4", + "url": "http://www.teampass.net", + "licence": "free", + "maintainer": { + "name": "Ackak, Maniack Crudelis et matlink", + "email": "ackak_ynh@ackak.net maniackc_dev@crudelis.fr matlink@matlink.fr" + }, + "multi_instance": "false", + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for Teampass", + "fr": "Choisissez un domaine pour Teampass" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for Teampass", + "fr": "Choisissez un chemin pour Teampass" + }, + "example": "/teampass", + "default": "/teampass" + }, + { + "name": "password", + "ask": { + "en": "Choose a password for the admin", + "fr": "Choisissez un mot de passe pour l'administrateur" + } + } + ] + } +} diff --git a/scripts/backup b/scripts/backup index b8469b0..73ab576 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=app_name +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=teampass +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) diff --git a/scripts/install b/scripts/install index c521c45..96fa412 100644 --- a/scripts/install +++ b/scripts/install @@ -1,10 +1,46 @@ #!/bin/bash -# Renseigne les variables à partir des arguments. -domain=$1 -path=$2 -password_admin=$3 -app=teampass +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 + . /usr/share/yunohost/helpers +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 # Vérifie la présence du / en début de path @@ -15,13 +51,13 @@ fi # Vérifie la disponibilité du path et du domaine. sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then - exit 1 + touch /force_stop fi # Vérifie que le mot de passe n'est pas vide. if [[ -z $password_admin ]]; then echo "Mot de passe incorrect" - exit 1 + touch /force_stop fi # Vérifie que le dossier de destination n'est pas déjà utilisé. @@ -29,7 +65,7 @@ final_path=/var/www/$app if [ -e "$final_path" ] then echo "This path already contains a folder" - exit 1 + touch /force_stop fi @@ -39,11 +75,15 @@ sudo yunohost app setting $app path -v $path # Génère un mot de passe aléatoire. -db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') +db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20) # 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. -sudo yunohost app initdb $db_user -p $db_pwd +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 sudo yunohost app setting $app mysqlpwd -v $db_pwd @@ -133,7 +173,6 @@ sudo cp ../conf/settings.php $final_path/includes/settings.php sudo cp $final_path/includes/libraries/csrfp/libs/csrfp.config.sample.php $final_path/includes/libraries/csrfp/libs/csrfp.config.php - # 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 diff --git a/scripts/remove b/scripts/remove index d741fd3..9402ed4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,33 +1,68 @@ #!/bin/bash -app=teampass - # Récupère les infos de l'application. -root_pwd=$(sudo cat /etc/yunohost/mysql) +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + app=teampass + MYSQL_ROOT_PWD_FILE="/etc/yunohost/mysql" +fi domain=$(sudo yunohost app setting $app domain) +# Suppression de la base de donnée et de l'utilisateur associé. # Utilise '$app' comme nom d'utilisateur et de base de donnée db_user=$app -mysql -u root -p$root_pwd -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;" +if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then + echo "Delete db" + if [ $ynh_version = "2.4" ]; then + ynh_mysql_drop_db $db_user + ynh_mysql_drop_user $db_user + else + mysql -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;" + fi +fi # Suppression du dossier de l'application -sudo rm -rf /var/www/$app +if [ -e "/var/www/$app" ]; then # Delete final_path + echo "Delete app dir" + sudo rm -r "/var/www/$app" +fi #Remove the sk.php -sudo rm -rf /etc/teampass/ +if [ -e "/etc/teampass/" ]; then + echo "Delete sk.php" + sudo rm -r "/etc/teampass/" +fi # Suppression de la configuration nginx -sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config + echo "Delete nginx config" + sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo service nginx reload +fi # Suppression des log -sudo rm -r /var/log/$app/ +if [ -e "/var/log/$app/" ]; then + echo "Delete log" + sudo rm -r "/var/log/$app/" +fi # Suppression de la configuration du pool php-fpm -sudo rm -f /etc/php5/fpm/pool.d/$app.conf -sudo rm -f /etc/php5/fpm/conf.d/20-$app.ini - -# Recharge la configuration Nginx et php5-fpm -sudo service nginx reload +if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config + echo "Delete fpm config" + sudo rm "/etc/php5/fpm/pool.d/$app.conf" +fi +if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config + echo "Delete php config" + sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" +fi sudo service php5-fpm reload + # Régénère la configuration de SSOwat sudo yunohost app ssowatconf + +echo -e "\e[0m" # Restore normal color diff --git a/scripts/restore b/scripts/restore index 55b7eae..7f086d6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=app_name +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=teampass +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) diff --git a/scripts/upgrade b/scripts/upgrade index 1ff8f9d..e1d6d12 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=teampass +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=teampass +fi domain=$(sudo yunohost app setting $app domain) path=$(sudo yunohost app setting $app path) final_path=$(sudo yunohost app setting $app final_path) diff --git a/scripts/upgrade~ b/scripts/upgrade~ deleted file mode 100644 index 096b708..0000000 --- a/scripts/upgrade~ +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Récupère les infos de l'application. -app=teampass -domain=$(sudo yunohost app setting $app domain) -path=$(sudo yunohost app setting $app path) -final_path=$(sudo yunohost app setting $app 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 - -# Delete the install directory. -sudo rm -r $final_path/install - -# Modifie les variables dans le fichier de configuration nginx -sudo sed -i "s@__PATH__@$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 -sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf - -# Créer le fichier de configuration du pool php-fpm et le configure. -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 - -# sudo chown www-data: -R $final_path -# sudo chmod 770 -R $final_path -# sudo find $final_path -type f -print0 | xargs -0 sudo chmod 740 # Applique les permissions sur les fichiers seulement (rwxr-----) -# sudo chmod 770 -R $final_path/files $final_path/upload -# sudo chmod a+x $final_path/CsvToXml_For_Teampass.sh - -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 -sudo service nginx reload -# Régénère la configuration de SSOwat -sudo yunohost app ssowatconf \ No newline at end of file