Skip to content

Commit

Permalink
refactor: fix lint errors for all shell/bash scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 16, 2024
1 parent 1e74489 commit a8d35bc
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests/test_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
########################################

# TODO read personal access token
# read -p
# read -erp
# GITHUB_TOKEN=input
# Feed to act using -s flag: -s GITHUB_TOKEN=input_personal_access_token

Expand Down
6 changes: 3 additions & 3 deletions nginx/container-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ done

# Check if the timeout was reached
if [ $timeout -eq 0 ]; then
echo "NGINX did not start within the timeout."
exit 1
echo "NGINX did not start within the timeout."
exit 1
fi

# Check if FMTM_DOMAIN is set
Expand Down Expand Up @@ -63,7 +63,7 @@ if [ -n "${FMTM_S3_DOMAIN}" ]; then
fi

# Run certbot with the constructed arguments
echo "Running command: certbot --non-interactive certonly ${certbot_args[@]}"
echo "Running command: certbot --non-interactive certonly ${certbot_args[*]}"
certbot --non-interactive certonly "${certbot_args[@]}"
echo "Certificate generated under: /etc/letsencrypt/live/${FMTM_DOMAIN}/"

Expand Down
136 changes: 47 additions & 89 deletions scripts/gen-env.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

DOTENV_PATH=.env
DOTENV_NAME=.env
IS_TEST=false
BRANCH_NAME=

Expand Down Expand Up @@ -41,7 +41,7 @@ install_envsubst_if_missing() {
else
echo "Downloading a8m/envsubst"
echo
curl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-`uname -s`-`uname -m` -o envsubst
curl -L "https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-$(uname -s)-$(uname -m)" -o envsubst
chmod +x envsubst
fi
}
Expand All @@ -51,12 +51,10 @@ check_if_test() {

echo "Is this a test deployment?"
echo
while true
do
read -e -p "Enter 'y' if yes, anything else to continue: " test
while true; do
read -erp "Enter 'y' if yes, anything else to continue: " test

if [[ "$test" = "y" || "$test" = "yes" ]]
then
if [[ "$test" = "y" || "$test" = "yes" ]]; then
IS_TEST=true
export DEBUG=True
export LOG_LEVEL="DEBUG"
Expand All @@ -72,48 +70,18 @@ check_if_test() {
}

check_existing_dotenv() {
if [ -f "${DOTENV_PATH}" ]
then
echo "WARNING: ${DOTENV_PATH} file already exists."
echo "This script will overwrite the content of this file."
echo
echo "Do you want to overwrite "${DOTENV_PATH}"? y/n"
until [ "$overwrite" = "y" -o "$overwrite" = "n" ]
do
read -e -p "Enter 'y' to overwrite, anything else to continue: " overwrite

if [ "$overwrite" = "y" ]
then
return 1
elif [ "$overwrite" = "n" ]
then
echo "Continuing with existing .env file."
return 0
else
echo "Invalid input!"
fi
done
fi

return 1
}

check_existing_dotenv() {
if [ -f "${DOTENV_PATH}" ]
then
echo "WARNING: ${DOTENV_PATH} file already exists."
if [ -f "${DOTENV_NAME}" ]; then
echo "WARNING: ${DOTENV_NAME} file already exists."
echo "This script will overwrite the content of this file."
echo
echo "Do you want to overwrite file '"${DOTENV_PATH}"'? y/n"
printf "Do you want to overwrite file \'%s\'? y/n" "${DOTENV_NAME}"
echo
while true
do
read -e -p "Enter 'y' to overwrite, anything else to continue: " overwrite
while true; do
read -erp "Enter 'y' to overwrite, anything else to continue: " overwrite

if [[ "$overwrite" = "y" || "$overwrite" = "yes" ]]
then
if [[ "$overwrite" = "y" || "$overwrite" = "yes" ]]; then
return 1
else
else
echo "Continuing with existing .env file."
return 0
fi
Expand All @@ -126,8 +94,7 @@ check_existing_dotenv() {
set_deploy_env() {
pretty_echo "Deployment Environment"

while true
do
while true; do
echo "Which environment do you wish to run? (dev/staging/prod)"
echo
echo "Both dev & staging include ODK Central and S3 buckets."
Expand All @@ -136,7 +103,7 @@ set_deploy_env() {
echo "- ODK Central"
echo "- S3 Buckets"
echo
read -e -p "Enter the environment (dev/staging/prod): " environment
read -erp "Enter the environment (dev/staging/prod): " environment

case "$environment" in
dev)
Expand All @@ -154,15 +121,15 @@ set_deploy_env() {
*)
echo "Invalid environment name. Please enter dev, staging, or prod."
;;
esac
esac
done
}

set_external_odk() {
pretty_echo "External ODK Central Host"

echo "Please enter the ODKCentral URL."
read -e -p "ODKCentral URL: " ODK_CENTRAL_URL
read -erp "ODKCentral URL: " ODK_CENTRAL_URL
echo
export ODK_CENTRAL_URL=${ODK_CENTRAL_URL}

Expand All @@ -183,7 +150,7 @@ set_odk_user_creds() {
pretty_echo "ODK User Credentials"

echo "Please enter the ODKCentral Email."
read -e -p "ODKCentral Email: " ODK_CENTRAL_USER
read -erp "ODKCentral Email: " ODK_CENTRAL_USER
echo
export ODK_CENTRAL_USER=${ODK_CENTRAL_USER}

Expand All @@ -192,7 +159,7 @@ set_odk_user_creds() {
echo
echo "Note: this must be >10 characters long."
echo
read -e -p "ODKCentral Password: " ODK_CENTRAL_PASSWD
read -erp "ODKCentral Password: " ODK_CENTRAL_PASSWD
echo

# Check the length of the entered password
Expand All @@ -211,38 +178,35 @@ check_external_database() {
pretty_echo "External Database"

echo "Do you want to use an external database instead of local?"
while true
do
read -e -p "Enter y for external, anything else to continue: " externaldb
while true; do
read -erp "Enter y for external, anything else to continue: " externaldb

if [ "$externaldb" = "y" ]
then
if [ "$externaldb" = "y" ]; then
EXTERNAL_DB="True"
echo "Using external database."
fi
break
done

if [ "$EXTERNAL_DB" = "True" ]
then
if [ "$EXTERNAL_DB" = "True" ]; then
echo
echo "Please enter the database host."
read -e -p "FMTM DB Host: " FMTM_DB_HOST
read -erp "FMTM DB Host: " FMTM_DB_HOST
echo
export FMTM_DB_HOST=${FMTM_DB_HOST}

echo "Please enter the database name."
read -e -p "FMTM DB Name: " FMTM_DB_NAME
read -erp "FMTM DB Name: " FMTM_DB_NAME
echo
export FMTM_DB_NAME=${FMTM_DB_NAME}

echo "Please enter the database user."
read -e -p "FMTM DB User: " FMTM_DB_USER
read -erp "FMTM DB User: " FMTM_DB_USER
echo
export FMTM_DB_USER=${FMTM_DB_USER}

echo "Please enter the database password."
read -e -p "FMTM DB Password: " FMTM_DB_PASSWORD
read -erp "FMTM DB Password: " FMTM_DB_PASSWORD
echo
export FMTM_DB_PASSWORD=${FMTM_DB_PASSWORD}

Expand All @@ -255,17 +219,17 @@ set_external_s3() {
pretty_echo "S3 Credentials"

echo "Please enter the S3 host endpoint."
read -e -p "S3 Endpoint: " S3_ENDPOINT
read -erp "S3 Endpoint: " S3_ENDPOINT
echo
export S3_ENDPOINT=${S3_ENDPOINT}

echo "Please enter the access key."
read -e -p "S3 Access Key: " S3_ACCESS_KEY
read -erp "S3 Access Key: " S3_ACCESS_KEY
echo
export S3_ACCESS_KEY=${S3_ACCESS_KEY}

echo "Please enter the secret key."
read -e -p "S3 Secret Key: " S3_SECRET_KEY
read -erp "S3 Secret Key: " S3_SECRET_KEY
echo
export S3_SECRET_KEY=${S3_SECRET_KEY}

Expand All @@ -275,7 +239,7 @@ set_external_s3() {
echo "The bucket should be public."
echo
echo "Please enter the bucket name."
read -e -p "S3 Bucket Name: " S3_BUCKET_NAME
read -erp "S3 Bucket Name: " S3_BUCKET_NAME
echo
export S3_BUCKET_NAME=${S3_BUCKET_NAME}
fi
Expand All @@ -293,12 +257,10 @@ set_domains() {
pretty_echo "FMTM Domain Name"

echo "To run FMTM you must own a domain name."
while true
do
read -e -p "Enter a valid domain name you wish to run FMTM from: " fmtm_domain
while true; do
read -erp "Enter a valid domain name you wish to run FMTM from: " fmtm_domain

if [ "$fmtm_domain" = "" ]
then
if [ "$fmtm_domain" = "" ]; then
echo "Invalid input!"
else
export FMTM_DOMAIN="${fmtm_domain}"
Expand All @@ -317,26 +279,23 @@ set_domains() {
echo "$fmtm_domain --> $current_ip"
echo "api.$fmtm_domain --> $current_ip"

if [ "$BRANCH_NAME" != "main" ]
then
if [ "$BRANCH_NAME" != "main" ]; then
echo "s3.$fmtm_domain --> $current_ip"
echo "odk.$fmtm_domain --> $current_ip"
fi

echo
read -e -p "Once these DNS entries are set and valid, press ENTER to continue." valid
read -erp "Once these DNS entries are set and valid, press ENTER to continue."

pretty_echo "Certificates"
echo "FMTM will automatically generate SSL (HTTPS) certificates for your domain name."
while true
do
while true; do
echo "Enter an email address you wish to use for certificate generation."
read -e -p "This will be used by LetsEncrypt, but for no other purpose: " cert_email
read -erp "This will be used by LetsEncrypt, but for no other purpose: " cert_email

if [ "$cert_email" = "" ]
then
if [ "$cert_email" = "" ]; then
echo "Invalid input!"
else
else
export CERT_EMAIL="${cert_email}"
break
fi
Expand All @@ -359,9 +318,9 @@ set_osm_credentials() {

echo "Please enter your OSM authentication details"
echo
read -e -p "Client ID: " OSM_CLIENT_ID
read -erp "Client ID: " OSM_CLIENT_ID
echo
read -e -p "Client Secret: " OSM_CLIENT_SECRET
read -erp "Client Secret: " OSM_CLIENT_SECRET

export OSM_CLIENT_ID=${OSM_CLIENT_ID}
export OSM_CLIENT_SECRET=${OSM_CLIENT_SECRET}
Expand All @@ -373,7 +332,7 @@ check_change_port() {
pretty_echo "Set Default Port"
echo "The default port for local development is 7050."
echo
read -e -p "Enter a different port if required, or nothing for default: " fmtm_port
read -erp "Enter a different port if required, or nothing for default: " fmtm_port

if [ -n "$fmtm_port" ]; then
echo "Using $fmtm_port"
Expand All @@ -389,15 +348,15 @@ generate_dotenv() {
if [ -f ./.env.example ]; then
echo ".env.example already exists. Continuing."

echo "substituting variables from .env.example --> ${DOTENV_PATH}"
./envsubst < .env.example > ${DOTENV_PATH}
echo "substituting variables from .env.example --> ${DOTENV_NAME}"
./envsubst < .env.example > ${DOTENV_NAME}
else
echo "Downloading .env.example from repo."
echo
curl -LO "https://raw.githubusercontent.com/hotosm/fmtm/${BRANCH_NAME:-development}/.env.example"

echo "substituting variables from .env.example --> ${DOTENV_PATH}"
./envsubst < .env.example > ${DOTENV_PATH}
echo "substituting variables from .env.example --> ${DOTENV_NAME}"
./envsubst < .env.example > ${DOTENV_NAME}

echo "Deleting .env.example"
rm .env.example
Expand All @@ -413,8 +372,7 @@ prompt_user_gen_dotenv() {
if [ $IS_TEST != true ]; then
set_deploy_env

if [ "$BRANCH_NAME" == "main" ]
then
if [ "$BRANCH_NAME" == "main" ]; then
set_external_odk
check_external_database
set_external_s3
Expand Down
2 changes: 1 addition & 1 deletion scripts/renew-certs-manual.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cleanup_and_exit() {
trap cleanup_and_exit INT

# Prompt the user for input and set the BRANCH_NAME variable
read -p "Enter the environment (dev/staging/prod): " ENVIRONMENT
read -erp "Enter the environment (dev/staging/prod): " ENVIRONMENT

case "$ENVIRONMENT" in
dev)
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ EOF
add_vars_to_bashrc() {
# DOCKER_HOST must be added to the top of bashrc, as running non-interactively
# Most distros exit .bashrc execution is non-interactive

heading_echo "Adding rootless DOCKER_HOST to bashrc"

user_id=$(id -u)
Expand Down Expand Up @@ -221,6 +221,6 @@ install_docker() {
add_vars_to_bashrc
}

check_user_not_root
check_user_not_root "$@"
trap cleanup_and_exit INT
install_docker
1 change: 0 additions & 1 deletion scripts/setup/podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ check_os() {
source /etc/os-release
case "$ID" in
debian)
IS_DEBIAN=true
echo "Current OS is ${PRETTY_NAME}."
;;
ubuntu)
Expand Down
Loading

0 comments on commit a8d35bc

Please sign in to comment.