2025-07-18 ...before ...pwdgen20250605.sh

#!/bin/bash

pwdnamesfile="./pwdnames20250605.txt"
date=$(date)

if [ "$1" == "--new" ]
then
    passwordnewkey=$(pwgen -c -y -s 32 1)
    echo "$passwordnewkey" > pwdkey$date.pwd.txt
    echo "$passwordnewkey" | xclip -selection clipboard -i
    gpg --gen-key
    keyuid=$(gpg -K | tail -n 4 | head -n 1 | sed 's/[^A-F0-9]*\(.*\).*/\1/g')
    echo $keyuid > "keyuidfile$date.uid.txt"
    gpg --output "passwords$date.pub.txt.asc" -a --export "$keyuid"
    gpg --output "passwords$date.private.txt.asc" -a --export-secret-key "$keyuid"
    n=$(wc -l $pwdnamesfile | sed 's/\([0-9]*\).*/\1/g')
    i=1
    while [ $i -le $n ]
    do
        nm=$(cat $pwdnamesfile | head -n $i | tail -n 1)
        echo "$(pwgen -c -y -s 32 1)" >> "password$date.klartext.txt"
        i=$(($i+1))
    done
    gpg -a --encrypt --recipient $keyuid "password$date.klartext.txt"
    #rm "password$date.klartext.txt"
fi
elif [[ "$1" == "--password" && -n "$2" ]]
then
    n=$(wc -l $pwdnamesfile | sed 's/\([0-9]*\).*/\1/g')
    cat pwdkey$date.pwd.txt | xclip -selection clipboard -i
    gpg --decrypt "password$date.klartext.txt.asc" >> "password$date.decrypted.txt"
    n=$(wc -l $pwdnamesfile | sed 's/\([0-9]*\).*/\1/g')
    i=1
    while [ $i -le $n ]
    do
        nm=$(cat $pwdnamesfile | head -n $i | tail -n 1)
        echo "$i: $nm"
        i=$(($i+1))
    done
    read -p "Bitte geben sie die zeile fuer das password an:" $pwdnum
    cat "password$date.decrypted.txt" | head -n $pwdnum | tail -n 1 | xclip -selection clipboard -i
    #rm "password$date.decrypted.txt"
fi