Ну, копая чуть-чуть глубже, мне удалось собрать воедино разные кусочки, чтобы сформировать работающий скрипт. Это далеко не самый красивый зверь, но учитывая, что он был буквально моим первым - я счастлив :) Я поделюсь этим здесь целиком на случай, если кому-то еще это понадобится.
#!/bin/bash
## USERMAIL is a mail address to be added to the blocklist
COUNTER=0
while [ $COUNTER -lt 1 ]; do
clear ## clears the screen
echo -e "\nPlease enter user's email address to add to Sender Access blocklist (to minimize errors, please copy the email address):"
echo ""
read -p 'Email:' USERMAIL ## this is where user provides an email
if
grep $USERMAIL /etc/postfix/sender_access_regexp;
then echo -e "\nUser already exists on this list." ## this checks if there is such an address on the list already
else
echo /^.*$USERMAIL$/ REJECT >> /etc/postfix/sender_access_regexp ## the bits and pieces surrounding $USERMAIL are all part of regex
echo -e "\nUser $USERMAIL added to blocklist."
echo ""
fi
echo""
read -p "Would you like to add another addres to Sender Access blocklist? (y/n)" -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then let COUNTER=COUNTER+0
echo ""
else let COUNTER=COUNTER+1
echo ""
fi
done
postmap /etc/postfix/sender_access_regexp
postfix reload
echo ""
read -n 1 -s -r -p "All done, press any key to continue"
echo ""
Вот и все. Все эти echo ""
есть, потому что я не знал, как добавить пустую строку: shrug:
P.S. вы можете получить permission denied
, если владелец /etc/postifx/sender_access_regexp
и ваш скрипт не тот же пользователь.
P.P.S. все предложения по сглаживанию этого скрипта все еще приветствуются!