Skip to content

Commit

Permalink
Add 'no input check' to multiple functions
Browse files Browse the repository at this point in the history
Functions are:
1. _input_db_name
2. _input_db_pass
3. _input_db_username
4. _input_drupal_dir
5. _input_drupal_pass
6. _input_drupal_site_name
7. _input_drupal_username
  • Loading branch information
shreyas-a-s committed Jan 10, 2024
1 parent 190723b commit b17d5ed
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 93 deletions.
35 changes: 22 additions & 13 deletions functions/_input_db_name.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#!/usr/bin/env bash

function _input_db_name {
if command -v whiptail > /dev/null; then # Whiptail is installed
psqldb=$(whiptail --title "USER INPUT" --inputbox \
"\nEnter the name for a new database for our website:\
\n\n (Press ENTER to continue)" \
12 47 \
"$psqldb" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then # Whiptail is installed
psqldb=$(whiptail --title "USER INPUT" --inputbox \
"\nEnter the name for a new database for our website:\
\n\n (Press ENTER to continue)" \
12 47 \
"$psqldb" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else # Whiptail is not installed
read -r -p "Enter the name for a new database for our website: " psqldb
fi
else # Whiptail is not installed
read -r -p "Enter the name for a new database for our website: " psqldb
fi

# Check if input is empty
if [ -n "$psqldb" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done

# Replaces 'spaces' with 'hyphens'
psqldb=$(echo "$psqldb" | tr ' ' '-')
Expand Down
32 changes: 20 additions & 12 deletions functions/_input_db_pass.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#!/usr/bin/env bash

function _input_db_pass {
if command -v whiptail > /dev/null; then
PGPASSWORD=$(whiptail --title "USER INPUT" --passwordbox \
"\nEnter a password for the new user:\n\n (Press ENTER to continue)" \
11 38 \
"$PGPASSWORD" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then
PGPASSWORD=$(whiptail --title "USER INPUT" --passwordbox \
"\nEnter a password for the new user:\n\n (Press ENTER to continue)" \
11 38 \
"$PGPASSWORD" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else
read -r -p "Enter a password for the new user: " PGPASSWORD
fi
else
read -r -p "Enter a password for the new user: " PGPASSWORD
fi

# Check if input is empty
if [ -n "$PGPASSWORD" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done
# Hide PGPASSWORD by replacing characters with *
HIDDEN_PGPASSWORD=$(for _ in $(seq "$(printf "%s" "$PGPASSWORD" | wc -m)"); do printf "*"; done)

Expand Down
32 changes: 20 additions & 12 deletions functions/_input_db_username.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#!/usr/bin/env bash

function _input_db_username {
if command -v whiptail > /dev/null; then
psqluser=$(whiptail --title "USER INPUT" --inputbox \
"\nEnter username for a new database user:\n\n (Press ENTER to continue)" \
11 44 \
"$psqluser" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then
psqluser=$(whiptail --title "USER INPUT" --inputbox \
"\nEnter username for a new database user:\n\n (Press ENTER to continue)" \
11 44 \
"$psqluser" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else
read -r -p "Enter a new username (role) for postgres: " psqluser
fi
else
read -r -p "Enter a new username (role) for postgres: " psqluser
fi

# Check if input is empty
if [ -n "$psqluser" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done
# Replaces 'spaces' with 'hyphens'
psqluser=$(echo "$psqluser" | tr ' ' '-')

Expand Down
38 changes: 24 additions & 14 deletions functions/_input_drupal_dir.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#!/usr/bin/env bash

function _input_drupal_dir {
if command -v whiptail > /dev/null; then
drupalsitedir=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \
"\nEnter the name of the directory to which\n drupal website needs to be installed:\
\n (Press ENTER to continue)" \
12 45 \
"$drupalsitedir" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then
drupalsitedir=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \
"\nEnter the name of the directory to which\n drupal website needs to be installed:\
\n (Press ENTER to continue)" \
12 45 \
"$drupalsitedir" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else
printf "Enter the name of the directory to which drupal website needs to be installed: "
read -r drupalsitedir
fi
else
printf "Enter the name of the directory to which drupal website needs to be installed: "
read -r drupalsitedir
fi

# Check if input is empty
if [ -n "$drupalsitedir" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done

drupalsitedir=$(echo "$drupalsitedir" | tr ' ' '-') # Replaces 'spaces' with 'hyphens'
export drupalsitedir
}
Expand Down
37 changes: 23 additions & 14 deletions functions/_input_drupal_pass.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#!/usr/bin/env bash

function _input_drupal_pass {
if command -v whiptail > /dev/null; then
drupal_pass=$(whiptail --title "DRUPAL WEBSITE DETAILS" --passwordbox \
"\nEnter a password for the new drupal user:\
\n (Press ENTER to continue)" \
11 45 \
"$drupal_pass" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then
drupal_pass=$(whiptail --title "DRUPAL WEBSITE DETAILS" --passwordbox \
"\nEnter a password for the new drupal user:\
\n (Press ENTER to continue)" \
11 45 \
"$drupal_pass" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else
printf "\nEnter a password for the new drupal user: "
read -r drupal_pass
fi
else
printf "\nEnter a password for the new drupal user: "
read -r drupal_pass
fi

# Check if input is empty
if [ -n "$drupal_pass" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done

# Hide drupal_pass by replacing characters with *
hidden_drupal_pass=$(for _ in $(seq "$(printf "%s" "$drupal_pass" | wc -m)"); do printf "*"; done)
Expand Down
38 changes: 24 additions & 14 deletions functions/_input_drupal_site_name.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#!/usr/bin/env bash

function _input_drupal_site_name {
if command -v whiptail > /dev/null; then
drupal_site_name=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \
"\nEnter a Name for your Drupal website:\n (Example: My Beautiful Website)\
\n (Press ENTER to continue)" \
12 41 \
"$drupal_site_name" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then
drupal_site_name=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \
"\nEnter a Name for your Drupal website:\n (Example: My Beautiful Website)\
\n (Press ENTER to continue)" \
12 41 \
"$drupal_site_name" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else
printf "\nEnter a Name for your Drupal website(eg: My Beautiful Website) : "
read -r drupal_site_name
fi
else
printf "\nEnter a Name for your Drupal website(eg: My Beautiful Website) : "
read -r drupal_site_name
fi

# Check if input is empty
if [ -n "$drupal_site_name" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done

export drupal_site_name # Export drupal site name to be used by child scripts
}

Expand Down
38 changes: 24 additions & 14 deletions functions/_input_drupal_username.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#!/usr/bin/env bash

function _input_drupal_username {
if command -v whiptail > /dev/null; then
drupal_user=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \
"\nEnter the username to be used for drupal:\
\n (Press ENTER to continue)" \
11 45 \
"$drupal_user" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
while true; do
if command -v whiptail > /dev/null; then
drupal_user=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \
"\nEnter the username to be used for drupal:\
\n (Press ENTER to continue)" \
11 45 \
"$drupal_user" \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 1 ]; then
exit 1
fi
else
printf "\nEnter the username to be used for drupal: "
read -r drupal_user
fi
else
printf "\nEnter the username to be used for drupal: "
read -r drupal_user
fi

# Check if input is empty
if [ -n "$drupal_user" ]; then
break
else
whiptail --msgbox " Please enter a value" 7 30
fi
done

drupal_user=$(echo "$drupal_user" | tr ' ' '-') # Repace 'spaces' with 'hyphens'
export drupal_user # Export drupal username to be used by child scripts
}
Expand Down

0 comments on commit b17d5ed

Please sign in to comment.