gestion/controle_don/envoi_instructions_don.sh

72 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Check_don
# Copyright 2022 Adrien Bourmault
# Licence AGPL v3
contains() {
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
}
get_nom()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 1
}
get_prenom()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 2
}
get_adresse()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 3
}
get_code_postal()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 4
}
get_ville()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 5
}
get_courriel()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 6
}
get_somme()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 7
}
get_mode()
{
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 8
}
################################################################################
FILE=$(mktemp /tmp/temporary.XXXXXXXX)
courriel="$(get_courriel $1)"
nom="$(get_prenom $1) $(get_nom $1)"
somme="$(get_somme $1)"
mode="$(get_mode $1)"
cat mail_instructions_don.txt >> "$FILE"
sed -i "s/COURRIEL_DONNEUR/$courriel/" "$FILE"
sed -i "s/NOM_DONNEUR/$nom/" "$FILE"
sed -i "s/NUMERO_DON/$1/" "$FILE"
sed -i "s/MONTANT_DON/$somme/" "$FILE"
sed -i "s/MODE_DON/$mode/" "$FILE"
# ENVOI
( cat "$FILE" ) | /usr/sbin/sendmail -i -- "$courriel" tresorier@a-lec.org
#cat "$FILE"
rm -f "$FILE"