From df8a67713a1893f14c0372f01c5b9af48de5a6f9 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Thu, 12 Nov 2020 17:54:51 +0100 Subject: getopt version dans les bacs --- install.sh | 320 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 170 insertions(+), 150 deletions(-) (limited to 'install.sh') diff --git a/install.sh b/install.sh index 508f4bb..cb3b7d4 100755 --- a/install.sh +++ b/install.sh @@ -2,173 +2,193 @@ THIS_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" emailre=".\+@.\+\\..\+" GPIGEON_SCRIPT=$THIS_SCRIPT_DIR/cgi-bin/gpigeon.cgi +GPG_DATA_DIR='/usr/share/www-data' +SCRIPT_USER='www-data' +SCRIPT_GROUP=$SCRIPT_USER +GPIGEON_ROOT_DIR='/var/www/gpigeon' + command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2" printf "Welcome to the gpigeon.cgi installer. We will first install the dependencies.\n" -apt install perl gcc make cpanminus libnet-ssleay-perl -cpanm Digest::SHA Email::Valid String::Random HTML::Entities CGI CGI::Carp -Net::SMTP Net::SMTPS GPG || ( printf "\nInstallation of dependencies failed\n" && exit 1 ) +#apt install perl gcc make cpanminus libnet-ssleay-perl || exit 1 +#cpanm Digest::SHA Email::Valid String::Random HTML::Entities CGI CGI::Carp Net::SMTP Net::SMTPS GPG || ( printf "\nInstallation of dependencies failed\n" && exit 1 ) -while [[ -z $_APP_PASSWORD ]]; do - printf "Choose a password for the gpigeon web application: \n" - read -r -s _APP_PASSWORD -done -while [[ $_APP_PASSWORD_VERIFICATION != $_APP_PASSWORD ]]; do - printf "\nRepeat password: " - read -r -s _APP_PASSWORD_VERIFICATION -done -# prevent obscure errors with q{} from perl -_APP_PASSWORD="$(echo $_APP_PASSWORD | sed s/{/\\\\{/g | sed s/}/\\\\}/g)" -HASHED_PASSWORD=`perl -e "use Digest::SHA qw(sha256_hex);print sha256_hex(q{$_APP_PASSWORD});"` -printf "\nPassword matches. The SHA256 hash of it is: \033[32m$HASHED_PASSWORD\033[0m\n" -printf "\nWhat is your email address: " -read -r _YOUR_EMAIL -while ! echo "$_YOUR_EMAIL" | grep "$emailre" >/dev/null; do - printf "\nYour email address is not a valid one. Type it again: " - read -r _YOUR_EMAIL -done -printf "\033[32m$_YOUR_EMAIL\033[0m seems a valid e-mail address." +interact() { -while [[ -z $_YOUR_EMAIL_PASSWORD ]]; do - printf "\nPassword for your email account: " - read -r -s _YOUR_EMAIL_PASSWORD -done + if [ $INSTALLING eq 1 ]; then + echo "already installing !" + exit 1 + fi -while [[ -z $_YOUR_EMAIL_PASSWORD_VERIFICATION != $_YOUR_EMAIL_PASSWORD ]]; do - printf "\nAgain for confirmation: " - read -r -s _YOUR_EMAIL_PASSWORD_VERIFICATION -done + printf "Choose a password for the gpigeon web application: \n" + read -r -s _APP_PASSWORD -_YOUR_EMAIL_PASSWORD_VERIFICATION=$(printf '%s\n' "$_YOUR_EMAIL_PASSWORD" | sed -e 's/[]\/$*.^[]/\\&/g'); + while [[ $_APP_PASSWORD_VERIFICATION != $_APP_PASSWORD ]]; do + printf "\nRepeat password: " + read -r -s _APP_PASSWORD_VERIFICATION + done + # prevent obscure errors with q{} from perl + _APP_PASSWORD="$(echo $_APP_PASSWORD | sed s/{/\\\\{/g | sed s/}/\\\\}/g)" + HASHED_PASSWORD=`perl -e "use Digest::SHA qw(sha256_hex);print sha256_hex(q{$_APP_PASSWORD});"` + printf "\nPassword matches. The SHA256 hash of it is: \033[32m$HASHED_PASSWORD\033[0m\n" -domain="$(echo "$_YOUR_EMAIL" | sed "s/.*@//")" -serverinfo="$(grep "^$domain" "domains.csv" 2>/dev/null)" -if [ -z "$serverinfo" ]; then - printf "\nAh. Your email domain isn't listed in the domains.csv file. Don't - worry, you can find info relating to that easily on the domain website / - the Internet, and type it in here." - while ! echo "$smtp" | grep -Eo "[.[:alnum:]]"; do - printf "\nWhat is the SMTP server address of your domain (generally it - is like this: smtp.domain.net)? " - read -r smtp + printf "\nWhat is your email address: " + read -r _YOUR_EMAIL + while ! echo "$_YOUR_EMAIL" | grep "$emailre" >/dev/null; do + printf "\nYour email address is not a valid one. Type it again: " + read -r _YOUR_EMAIL done + printf "\033[32m$_YOUR_EMAIL\033[0m seems a valid e-mail address." - while ! echo "$sport" | grep -Eo "[0-9]{1,5}"; do - printf "\nWhat is the SMTP server port (it is 465 or 587 in most - cases) ? " - read -r sport + while [[ -z $_YOUR_EMAIL_PASSWORD ]]; do + printf "\nPassword for your email account: " + read -r -s _YOUR_EMAIL_PASSWORD done -else - print "Yay! Your email domain seems to be listed in domains.csv, so you don't - have to manually type the smtp server address and port manually." - IFS=, read service imap iport smtp sport </dev/null)" + if [ -z "$serverinfo" ]; then + printf "\nAh. Your email domain isn't listed in the domains.csv file. Don't + worry, you can find info relating to that easily on the domain website / + the Internet, and type it in here." + while ! echo "$smtp" | grep -Eo "[.[:alnum:]]"; do + printf "\nWhat is the SMTP server address of your domain (typically like this: smtp.domain.net)? " + read -r smtp + done + + while ! echo "$sport" | grep -Eo "[0-9]{1,5}"; do + printf "\nWhat is the SMTP server port (typically 465 or 587) ? " + read -r sport + done + else + print "Yay! Your email domain seems to be listed in domains.csv, so you don't + have to manually type the smtp server address and port manually." + IFS=, read service imap iport smtp sport <