Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VH 1303 - Updated the script to generate a .env file based on user input #615

Conversation

DokurOmkar
Copy link
Contributor

@DokurOmkar DokurOmkar commented Jun 6, 2024

PR Details

Description

In this PR, initialization script is updated to generate a .env file based on user input.

Related Issue

VH-1303

Motivation and Context

How Has This Been Tested?

This update has been tested by running the script locally to check that user input is taken and .env file created.

Types of changes

  • Defect fix (non-breaking change that fixes an issue)
  • [] New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that cause existing functionality to change)

Checklist:

  • I have added any new packages to the sonar-scanner.properties file
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
    V2XHUB Contributing Guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@@ -1,4 +1,82 @@
#!/bin/bash

# Default values for the variables
PORT_DRAYAGE_ENABLED_DEFAULT="TRUE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to false by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to False

@@ -9,15 +87,15 @@ sudo apt update -y && sudo apt upgrade -y
sudo apt-get install chromium-browser -y

# Make passwords for mysql
mkdir -p secrets && cd secrets
mkdir -p secrets && cd secrets || return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary. Is this something from shell check. Can you add justification for adding return statement here, maybe even link rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, shell has thrown a warning here "^-- SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails."

Added a comment next to return saying "# return in case cd fails"


# Creates password files where user inputs password
FILE1=mysql_root_password.txt
FILE2=mysql_password.txt
if test -f "$FILE1"; then
echo "$FILE1 exists."
else
read -p "enter password for the mysql_root_password: " sql_root_pass
read -r -p "enter password for the mysql_root_password: " sql_root_pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this again as shell check thrown an error:

^-- SC2162 (info): read without -r will mangle backslashes.

For this reason it is "read -r -p"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment the rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the Rule as a comment

echo "$sql_pass" > sql_pass.txt
# Remove endline characters from password files
tr -d '\n' <sql_pass.txt> mysql_password.txt && rm sql_pass.txt
fi
# TODO VH-1303 Allow for version and configuration selection in initialization script
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!


# Create V2X Hub user
cd $mysqlDir
cd "$mysqlDir" || return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment next to return saying "# return in case cd fails"

SENSOR_JSON_FILE_PATH=${SENSOR_JSON_FILE_PATH:-$SENSOR_JSON_FILE_PATH_DEFAULT}
fi

# Write to .env file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If .env file already exists we may want to warn user that we are overwriting of even ask for permission to overwrite

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the script to ask for permission to overwrite the existing .env file

Copy link
Contributor

@paulbourelly999 paulbourelly999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments but otherwise this looks great! Thanks

@@ -9,15 +93,15 @@ sudo apt update -y && sudo apt upgrade -y
sudo apt-get install chromium-browser -y

# Make passwords for mysql
mkdir -p secrets && cd secrets
mkdir -p secrets && cd secrets || return # return in case cd fails
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link the rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the Rule as a comment

Copy link

sonarcloud bot commented Jun 7, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

# Check if Port Drayage functionality is enabled
if [[ $PORT_DRAYAGE_ENABLED == "TRUE" ]]; then
sudo docker compose up -d
elif [[ $PORT_DRAYAGE_ENABLED == "FALSE" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the time, users or at least I will not want port drayage enabled. Won't this only bring up the php container?

@paulbourelly999 paulbourelly999 merged commit 165cb55 into develop Jun 7, 2024
2 of 3 checks passed
@paulbourelly999 paulbourelly999 deleted the vh-1303_update_initialization_script_to_create_env_file_based_on_user_input branch June 7, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants