|
10 | 10 | apt update && apt -y dist-upgrade && apt -y autoremove
|
11 | 11 |
|
12 | 12 | # Install required packages
|
13 |
| -apt-get -y install git python3 python3-venv python3-pip certbot python3-certbot-nginx nginx tor libnginx-mod-http-geoip geoip-database unattended-upgrades gunicorn libssl-dev net-tools fail2ban ufw |
| 13 | +apt-get -y install git python3 python3-venv python3-pip certbot python3-certbot-nginx nginx tor libnginx-mod-http-geoip geoip-database unattended-upgrades gunicorn libssl-dev net-tools fail2ban ufw gnupg |
14 | 14 |
|
15 | 15 | # Function to display error message and exit
|
16 | 16 | error_exit() {
|
@@ -82,12 +82,40 @@ echo "
|
82 | 82 |
|
83 | 83 | 👇 Please paste your public PGP key and press Enter."
|
84 | 84 |
|
85 |
| -PGP_PUBLIC_KEY="" |
86 |
| -while IFS= read -r LINE < /dev/tty; do |
87 |
| - PGP_PUBLIC_KEY+="$LINE"$'\n' |
88 |
| - [[ $LINE == "-----END PGP PUBLIC KEY BLOCK-----" ]] && break |
| 85 | +# Loop until a valid PGP public key is provided |
| 86 | +while true; do |
| 87 | + PGP_PUBLIC_KEY="" |
| 88 | + while IFS= read -r LINE < /dev/tty; do |
| 89 | + PGP_PUBLIC_KEY+="$LINE"$'\n' |
| 90 | + [[ $LINE == "-----END PGP PUBLIC KEY BLOCK-----" ]] && break |
| 91 | + done |
| 92 | + |
| 93 | + # Save the provided PGP key to a temporary file |
| 94 | + TEMP_PGP_KEY_FILE=$(mktemp) |
| 95 | + echo "$PGP_PUBLIC_KEY" > "$TEMP_PGP_KEY_FILE" |
| 96 | + |
| 97 | + # Validate the PGP public key |
| 98 | + if gpg --import "$TEMP_PGP_KEY_FILE" &>/dev/null; then |
| 99 | + PGP_KEY_ID=$(gpg --list-keys --with-colons | grep pub | head -n 1 | cut -d':' -f5) |
| 100 | + if [[ -n "$PGP_KEY_ID" ]]; then |
| 101 | + echo "Valid PGP public key provided." |
| 102 | + break # Exit the loop if a valid key is provided |
| 103 | + else |
| 104 | + echo "No valid PGP public key ID found. Please provide a valid PGP public key." |
| 105 | + fi |
| 106 | + else |
| 107 | + echo "⛔️ Invalid PGP public key. Please provide a valid PGP public key." |
| 108 | + fi |
| 109 | + |
| 110 | + # Remove the temporary PGP key file after validation attempt |
| 111 | + rm "$TEMP_PGP_KEY_FILE" |
| 112 | + # Prompt to try again |
| 113 | + echo "Please try again." |
89 | 114 | done
|
90 | 115 |
|
| 116 | +# Remove the temporary PGP key file after successful validation |
| 117 | +rm "$TEMP_PGP_KEY_FILE" |
| 118 | + |
91 | 119 | echo "
|
92 | 120 | 👍 Public PGP key received.
|
93 | 121 | Continuing with installation process..."
|
|
0 commit comments