Skip to content

Commit dd390ff

Browse files
authored
Merge pull request #7 from ichbinder/addYesOption
Add yes option -y by @ichbinder.
2 parents b7d42bd + 1dfcb75 commit dd390ff

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

nginx_proxy_manager_cli.sh

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Github [ https://github.com/Erreur32/nginx-proxy-manager-Bash-API ]
55
# By Erreur32 - July 2024
66

7-
VERSION="2.5.8"
7+
VERSION="2.5.9"
88

99
#
1010
# This script allows you to manage Nginx Proxy Manager via the API. It provides
@@ -56,6 +56,7 @@ VERSION="2.5.8"
5656
# -w ALLOW_WEBSOCKET_UPGRADE Allow WebSocket upgrade (true/false, default: true)
5757
# -l CUSTOM_LOCATIONS Custom locations (JSON array of location objects)"
5858
# -a ADVANCED_CONFIG Advanced configuration (block of configuration settings)
59+
# -y Automatic yes to prompts
5960
#
6061
# 📦 Backup and Restore:
6162
# --backup Backup all configurations to a file
@@ -179,6 +180,7 @@ SHOW_DEFAULT=false
179180
ENABLE_ACL=false
180181
DISABLE_ACL=false
181182
ACCESS_LIST=false
183+
AUTO_YES=false # Added: Flag for automatic confirmation (y)
182184
# Colors Custom
183185
COLOR_GREEN="\033[32m"
184186
COLOR_RED="\033[41;1m"
@@ -509,7 +511,7 @@ validate_token() {
509511
#################################
510512
# Main menu logic
511513
#################################
512-
while getopts "d:i:p:f:c:b:w:a:l:-:" opt; do
514+
while getopts "d:i:p:f:c:b:w:a:l:y-:" opt; do
513515
case $opt in
514516
d) DOMAIN_NAMES="$OPTARG" ;;
515517
i) FORWARD_HOST="$OPTARG" ;;
@@ -520,12 +522,13 @@ while getopts "d:i:p:f:c:b:w:a:l:-:" opt; do
520522
w) ALLOW_WEBSOCKET_UPGRADE="$OPTARG" ;;
521523
a) ADVANCED_CONFIG="$OPTARG" ;;
522524
l) CUSTOM_LOCATIONS="$OPTARG" ;;
525+
y) AUTO_YES=true ;; # Neu: -y Flag für automatische "yes" Bestätigung
523526
-)
524527
case "${OPTARG}" in
525528
show-default) SHOW_DEFAULT=true ;;
526529
backup) BACKUP=true ;;
527530
backup-host)
528-
validate_token
531+
validate_token
529532
BACKUP_HOST=true
530533
HOST_ID="${!OPTIND}"; shift
531534
;;
@@ -544,42 +547,42 @@ while getopts "d:i:p:f:c:b:w:a:l:-:" opt; do
544547
ssl-regenerate) validate_token; SSL_REGENERATE=true ;;
545548
ssl-restore) validate_token; SSL_RESTORE=true ;;
546549
create-user)
547-
validate_token
550+
validate_token
548551
CREATE_USER=true
549552
USERNAME="${!OPTIND}"; shift
550553
PASSWORD="${!OPTIND}"; shift
551554
EMAIL="${!OPTIND}"; shift
552555
;;
553556
delete-user)
554-
validate_token
557+
validate_token
555558
DELETE_USER=true
556559
USERNAME="${!OPTIND}"; shift
557560
;;
558561
host-delete)
559-
validate_token
562+
validate_token
560563
DELETE_HOST=true
561564
HOST_ID="${!OPTIND}"; shift
562565
;;
563566
host-show)
564-
validate_token
567+
validate_token
565568
HOST_SHOW=true
566569
HOST_ID="${!OPTIND}"; shift
567570
;;
568571
host-list) validate_token; LIST_HOSTS=true ;;
569572
host-list-full) validate_token; LIST_HOSTS_FULL=true ;;
570573
host-list-users) validate_token; LIST_USERS=true ;;
571574
host-search)
572-
validate_token
575+
validate_token
573576
SEARCH_HOST=true
574577
SEARCH_HOSTNAME="${!OPTIND}"; shift
575578
;;
576579
host-enable)
577-
validate_token
580+
validate_token
578581
ENABLE_HOST=true
579582
HOST_ID="${!OPTIND}"; shift
580583
;;
581584
host-disable)
582-
validate_token
585+
validate_token
583586
DISABLE_HOST=true
584587
HOST_ID="${!OPTIND}"; shift
585588
;;
@@ -602,7 +605,7 @@ while getopts "d:i:p:f:c:b:w:a:l:-:" opt; do
602605
check-token) CHECK_TOKEN=true
603606
;;
604607
generate-cert)
605-
validate_token
608+
validate_token
606609
GENERATE_CERT=true
607610
DOMAIN="${!OPTIND}"; shift
608611
EMAIL="${!OPTIND}"; shift
@@ -630,7 +633,7 @@ while getopts "d:i:p:f:c:b:w:a:l:-:" opt; do
630633
;;
631634
force-cert-creation)
632635
validate_token
633-
FORCE_CERT_CREATION=true ;;
636+
FORCE_CERT_CREATION=true ;;
634637
list-ssl-certificates)
635638
validate_token
636639
LIST_SSL_CERTIFICATES=true
@@ -886,7 +889,12 @@ check_existing_proxy_host() {
886889

887890
if [ -n "$EXISTING_HOST" ]; then
888891
echo -e "\n 🔔 Proxy host for $DOMAIN_NAMES already exists."
889-
read -p " 👉 Do you want to update it? (y/n): " -r
892+
if [ "$AUTO_YES" = true ]; then
893+
REPLY="y"
894+
echo -e "🔔 Option -y detected. Skipping confirmation prompt and proceeding with update..."
895+
else
896+
read -p " 👉 Do you want to update it? (y/n): " -r
897+
fi
890898
if [[ $REPLY =~ ^[Yy]$ ]]; then
891899
HOST_ID=$(echo "$EXISTING_HOST" | jq -r '.id')
892900
update_proxy_host "$HOST_ID"
@@ -1488,7 +1496,12 @@ delete_certificate() {
14881496
echo -e " ✅ Certificate found for $DOMAIN (Provider: $PROVIDER, Expires on: $EXPIRES_ON)."
14891497

14901498
# Ask for confirmation before deleting the certificate
1491-
read -p "⚠️ Are you sure you want to delete the certificate for $DOMAIN? (y/n): " CONFIRM
1499+
if [ "$AUTO_YES" = true ]; then
1500+
echo -e "🔔 The -y option was provided. Skipping confirmation prompt and proceeding with certificate creation..."
1501+
CONFIRM="y"
1502+
else
1503+
read -p "⚠️ Are you sure you want to delete the certificate for $DOMAIN? (y/n): " CONFIRM
1504+
fi
14921505
if [[ "$CONFIRM" != "y" ]]; then
14931506
echo -e " ❌ Certificate deletion aborted."
14941507
exit 0
@@ -1522,7 +1535,7 @@ generate_certificate() {
15221535
echo -e "\n 👀 Checking if Let's Encrypt certificate for domain: $DOMAIN exists..."
15231536

15241537
RESPONSE=$(curl -s -X GET "$BASE_URL/nginx/certificates" \
1525-
-H "Authorization: Bearer $(cat $TOKEN_FILE)")
1538+
-H "Authorization: Bearer $(cat $TOKEN_FILE)")
15261539

15271540
EXISTING_CERT=$(echo "$RESPONSE" | jq -r --arg DOMAIN "$DOMAIN" '.[] | select(.domain_names[] == $DOMAIN)')
15281541

@@ -1533,7 +1546,13 @@ generate_certificate() {
15331546
fi
15341547

15351548
# Ask for confirmation before creating a new certificate
1536-
read -p "⚠️ No existing certificate found for $DOMAIN. Do you want to create a new Let's Encrypt certificate? (y/n): " CONFIRM
1549+
if [ "$AUTO_YES" = true ]; then
1550+
echo -e "🔔 The -y option was provided. Skipping confirmation prompt and proceeding with certificate creation..."
1551+
CONFIRM="y"
1552+
else
1553+
read -p "⚠️ No existing certificate found for $DOMAIN. Do you want to create a new Let's Encrypt certificate? (y/n): " CONFIRM
1554+
fi
1555+
15371556
if [[ "$CONFIRM" != "y" ]]; then
15381557
echo -e " ❌ Certificate creation aborted."
15391558
exit 0
@@ -1552,10 +1571,10 @@ generate_certificate() {
15521571

15531572
echo -e "\n 🔔 Please WAIT until validation !!(or not)!! \n Data being sent: $DATA" # Log the data being sent
15541573

1555-
HTTP_RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X POST "$BASE_URL/nginx/certificates" \
1556-
-H "Authorization: Bearer $(cat $TOKEN_FILE)" \
1557-
-H "Content-Type: application/json; charset=UTF-8" \
1558-
--data-raw "$DATA")
1574+
HTTP_RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X POST "$BASE_URL/users" \
1575+
-H "Authorization: Bearer $(cat $TOKEN_FILE)" \
1576+
-H "Content-Type: application/json; charset=UTF-8" \
1577+
--data-raw "$DATA")
15591578

15601579
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
15611580
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
@@ -1617,7 +1636,12 @@ enable_ssl() {
16171636
EXPIRES_ON=$(echo "$EXISTING_CERT" | jq -r '.expires_on')
16181637
echo -e " 🔔 Certificate for $DOMAIN_NAMES already exists and is valid until $EXPIRES_ON.\n"
16191638
else
1620-
read -p "⚠️ No certificate found for $DOMAIN_NAMES. Do you want to create a new Let's Encrypt certificate? (y/n): " CONFIRM_CREATE
1639+
if [ "$AUTO_YES" = true ]; then
1640+
echo -e "🔔 The -y option was provided. Skipping confirmation prompt and proceeding with certificate creation..."
1641+
CONFIRM_CREATE="y"
1642+
else
1643+
read -p "⚠️ No certificate found for $DOMAIN_NAMES. Do you want to create a new Let's Encrypt certificate? (y/n): " CONFIRM_CREATE
1644+
fi
16211645
if [[ "$CONFIRM_CREATE" == "y" ]]; then
16221646
# Prompt for email if not set
16231647
read -p "Please enter your email for Let's Encrypt: " EMAIL
@@ -2195,7 +2219,12 @@ restore_host() {
21952219
# Verify if the proxy host exists
21962220
if [ -n "$HOST_ID_RESPONSE" ] && [ "$(echo "$HOST_ID_RESPONSE" | jq -r '.id')" = "$HOST_ID" ]; then
21972221
echo -e " 🔔 Proxy host for ID $HOST_ID already exists.\n ${COLOR_ORANGE}"
2198-
read -p " 👉 Do you want to delete the existing proxy host and restore from the backup? (y/n): " -r confirm
2222+
if [ "$AUTO_YES" = true ]; then
2223+
echo -e "🔔 The -y parameter is active. Skipping confirmation prompt..."
2224+
confirm="y"
2225+
else
2226+
read -p " 👉 Do you want to delete the existing proxy host and restore from the backup? (y/n): " -r confirm
2227+
fi
21992228
echo -e "${CoR}"
22002229
if [[ $confirm =~ ^[Yy]$ ]]; then
22012230
echo -e "${CoR}"

0 commit comments

Comments
 (0)