aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfirma164
1 files changed, 123 insertions, 41 deletions
diff --git a/firma b/firma
index 7a8a968..11fbe99 100755
--- a/firma
+++ b/firma
@@ -870,28 +870,115 @@ function NewList {
#-------------------------------------------------------------
local -i return_code=0
- local answer
+ local answer admin invalid
+ local last_char digits_only
- if [ ! -d "$LIST_PATH" ]; then
+ # UTF-8 is avoided in DETAILS
+ echo "Firma will ask you some questions before setup your list."
+ echo "Please dont use UTF-8 characters."
- echo "Creating folder $LIST_PATH..."
- if mkdir "$LIST_PATH"; then # || (echo "$(basename $0): error creating $LIST_PATH: installation aborted"; exit 1)
- echo "Creating list config file and will ask some questions."
+ read -rep " List keyring location: ("$LIST_PATH") " LIST_HOMEDIR
+ LIST_HOMEDIR=${LIST_HOMEDIR:-"$LIST_PATH"}
- # TODO: try to create $LIST_HOMEDIR
- read -rep " List keyring location: ("$LIST_PATH") " LIST_HOMEDIR
- LIST_HOMEDIR=${LIST_HOMEDIR:-"$LIST_PATH"}
+ if [ -d "$LIST_HOMEDIR" ]; then
+ echo "cannot create $LIST_NAME: List already exists at $LIST_HOMEDIR"
+ return 1
+ fi
+
+ echo "Creating folder $LIST_HOMEDIR..."
+ mkdir -p $LIST_HOMEDIR
+
+ if [ ! -d "$LIST_HOMEDIR" ]; then
+
+ while true; do
+ read -rep " List email address or 'quit' to exit: " LIST_ADDRESS
+ if [ "$LIST_ADDRESS" == "quit" ]; then
+ return 1
+ elif CheckValidEmail $LIST_ADDRESS; then
+ break
+ else
+ echo " Invalid email address: $LIST_ADRESS."
+ fi
+ done
+
+ while true; do
+ read -rep " List administrator(s) email address(es) (space delimited) or 'quit' to exit: " LIST_ADMIN
+ if [ "$LIST_ADDRESS" == "quit" ]; then
+ return 1
+ else
+ for admin in $LIST_ADMIN; do
+ if ! CheckValidEmail $admin; then
+ invalid="`echo $invalid $admin | sed -e 's/ / /'`"
+ fi
+ done
+ if [ ! -z "$invalid" ]; then
+ echo " Invalid email address: $invalid."
+ else
+ break
+ fi
+ fi
+ done
- # Dont use UTF-8 (look at DETAILS)
- read -rep " List email address: " LIST_ADDRESS
- read -rep " List administrator(s) email address(es) (space delimited): " LIST_ADMIN
read -rep " List description (optional): " DESCRIPTION
- read -resp " Passphrase to protect the list's secret key: " PASSPHRASE
- # TODO: automatically create a passphrase
- # TODO: key specs: size, expiry date...
- # TODO: CheckValidEmail $LIST_ADDRESS...
- # TODO: for admin in $LIST_ADMIN; do CheckValidEmail $admin...
+ while true; do
+ read -rep " Automatically create a passphrase for the list pubkey? (Y/n) " answer
+ answer="`echo $answer | tr '[:lower:]' '[:upper:]'`"
+ if [ -z "$answer" ] || [ "$answer" == "Y" ] || [ "$answer" == "YES" ]; then
+ PASSPHRASE="`RandomString 62`"
+ break
+ elif [ "$answer" == "N" ] || [ "$answer" == "NO" ]; then
+ read -resp " Passphrase to protect the list's secret key: " PASSPHRASE
+ break
+ else
+ echo " Please answer either yes or no."
+ fi
+ done
+
+ while true; do
+ echo " Please choose a key size:"
+ echo " 1 - 1024"
+ echo " 2 - 2048 (default)"
+ echo " 2 - 4096"
+ read -rep " Please choose a key size or 'quit' to exit: " answer
+ answer="`echo $answer | tr '[:lower:]' '[:upper:]'`"
+ if [ "$answer" == "QUIT" ]; then
+ return 1
+ elif [ "$answer" == "1" ] || [ "$answer" == "1024" ]; then
+ KEY_SIZE="1024"
+ break
+ elif [ -z "$answer" ] || [ "$answer" == "2" ] || [ "$answer" == "2048" ]; then
+ KEY_SIZE="2048"
+ break
+ elif [ "$answer" == "3" ] || [ "$answer" == "4096" ]; then
+ KEY_SIZE="4096"
+ else
+ echo " Invalid answer."
+ fi
+ done
+
+ echo " Choose a key validity:"
+ echo " 0 = key does not expire (default)"
+ echo " <n> = key expires in n days"
+ echo " <n>w = key expires in n weeks"
+ echo " <n>m = key expires in n months"
+ echo " <n>y = key expires in n years"
+
+ while true; do
+ read -rep " Please enter the key expiration time or 'quit' to exit: " KEY_EXPIRATION
+ KEY_EXPIRATION="`echo $KEY_EXPIRATION | tr '[:upper:]' '[:lower:]' `"
+ last_char="`echo "$KEY_EXPIRATION" | grep -o '[hdwmy]$'`"
+ digits_only="`echo "$SUBKEY_VALIDITY" | sed -e "s/$last_char.$//"`"
+ if [ -z "$KEY_EXPIRATION" ]; then
+ KEY_EXPIRATION="0"
+ elif [ "$KEY_EXPIRATION" == "quit" ]; then
+ return 1
+ elif [ -z "`echo $digits_only | sed -e 's/[0-9]//g'`" ] || [ ! -z "$last_char" ]; then
+ break
+ else
+ echo " Invalid key expiration time."
+ fi
+ done
echo "Creating your config..."
touch $LIST_CONFIG_FILE
@@ -899,7 +986,6 @@ function NewList {
chown $FIRMA_USER.$FIRMA_GROUP $LIST_CONFIG_FILE
if [ -f "$LIST_CONFIG_FILE" ]; then
DeclareGpgVars
- # removed: MAIL_AGENT=$MAIL_AGENT\nGPG_BINARY=$GPG_BINARY\n
echo -e "LIST_HOMEDIR='$LIST_HOMEDIR'\nLIST_ADDRESS='$LIST_ADDRESS'\nLIST_ADMIN='$LIST_ADMIN'\nPASSPHRASE='$PASSPHRASE'" > $LIST_CONFIG_FILE
echo "Now generating your keyring..."
@@ -908,44 +994,40 @@ function NewList {
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
- Subkey-Length: 1024
+ Subkey-Length: $KEY_SIZE
Name-Real: $DESCRIPTION
Name-Email: $LIST_ADDRESS
- Expire-Date: 0
+ Expire-Date: $KEY_EXPIRATION
Passphrase: $PASSPHRASE
%commit
EOF
- while true; do
- read -rep " Send list public key to list admins? (Y/n) " answer
- answer="`echo $answer | tr '[:lower:]' '[:upper:]'`"
- if [ "$answer" == "Y" ] || [ "$answer" == "YES" ]; then
- SendListPubkey $LIST_ADMIN
- break
- elif [ "$answer" == "N" ] || [ "$answer" == "NO" ]; then
- echo " Not sending public key from list to admins. Do it manually."
- break
- else
- echo " Please answer either yes or no."
- fi
- done
-
- chown -R $FIRMA_USER.$FIRMA_GROUP $LIST_HOMEDIR
+ while true; do
+ read -rep " Send list public key to list admins? (Y/n) " answer
+ answer="`echo $answer | tr '[:lower:]' '[:upper:]'`"
+ if [ -z "$answer" ] || [ "$answer" == "Y" ] || [ "$answer" == "YES" ]; then
+ SendListPubkey $LIST_ADMIN
+ break
+ elif [ "$answer" == "N" ] || [ "$answer" == "NO" ]; then
+ echo " Not sending public key from list to admins. Do it manually."
+ break
+ else
+ echo " Please answer either yes or no."
+ fi
+ done
- else
- echo "$(basename $0): cannot create $LIST_PATH: Installation aborted"
- return_code=1
- fi
+ chown -R $FIRMA_USER.$FIRMA_GROUP $LIST_HOMEDIR
- fi
else
- echo "$(basename $0): cannot create $LIST_NAME: List already exists"
+ echo "$(basename $0): cannot create $LIST_HOMEDIR: Installation aborted"
return_code=1
fi
+ fi
+
return $return_code
}
@@ -1573,7 +1655,7 @@ GLOBAL_VARS="
LIST_ADDRESS LIST_ADMIN LIST_HOMEDIR PASSPHRASE SUBJECT_PREFIX REMOVE_THESE_HEADERS REPLIES_SHOULD_GO_TO_LIST
FIRMA_CONFIG_FILE VERSION
ERROR_MESSAGE EXIT_CODE
- DESCRIPTION LIST_NAME LIST_PATH LIST_CONFIG_FILE
+ DESCRIPTION LIST_NAME LIST_PATH LIST_CONFIG_FILE KEY_EXPIRATION KEY_SIZE
GPG_FLAGS GPG GPG_LIST_KEYS GPG_DECRYPT GPG_ENCRYPT
STDIN
ORIG_MESSAGE