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

[PLA-2094] Changes start script to add notification email #55

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configs/core/.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ASSET_URL="${APP_URL}"
BCRYPT_ROUNDS=12
CORS_PATHS="graphql,graphql/beam,graphql/fuel-tanks,graphql/marketplace"

UPGRADE_NOTIFICATION_EMAIL=
NETWORK=canary-matrixchain
DECODER_CONTAINER=decoder:8090
DAEMON_ACCOUNT=
Expand Down
4 changes: 2 additions & 2 deletions configs/core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": "^8.3",
"php": "^8.3|^8.4",
"enjin/platform-core": "^2.0",
"enjin/platform-beam": "^2.0",
"enjin/platform-fuel-tanks": "^2.0",
Expand All @@ -29,7 +29,7 @@
"guzzlehttp/guzzle": "^7.0",
"laravel/framework": "^11.0",
"laravel/horizon": "^5.0",
"laravel/reverb": "@beta",
"laravel/reverb": "^1.0",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.0",
"fakerphp/faker": "^1.0"
Expand Down
36 changes: 36 additions & 0 deletions start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ if "%APP_URL%"=="" (
)
goto :EOF

:: Function to read the email address from the user
:read_email
:: Read the email address from the user
echo Please input the email address: (e.g. user@example.com)
set /p NOTIFICATION_EMAIL=
:: Check if the email address is empty
if "%NOTIFICATION_EMAIL%"=="" (
goto :EOF
)
:: Check if the email address is valid
if not "%NOTIFICATION_EMAIL%"=="%NOTIFICATION_EMAIL: =%" (
echo The email address you provided is not valid. Please try again.
call :read_email
)
goto :EOF

:: Function to check if user already has UPGRADE_NOTIFICATION_EMAIL set
:check_has_upgrade_notification_email
:: Check if user already has UPGRADE_NOTIFICATION_EMAIL set
set "NOTIFICATION_EMAIL="
for /f "tokens=2 delims==" %%i in ('findstr /r /c:"UPGRADE_NOTIFICATION_EMAIL=" configs\core\.env') do (
set "NOTIFICATION_EMAIL=%%i"
)
:: If not set, prompt the user
if "%NOTIFICATION_EMAIL%"=="" (
echo If you want to receive notifications with major updates or security notices, please provide an email address, otherwise leave it blank
call :read_email
:: Check if the email address is empty
if "%NOTIFICATION_EMAIL%"=="" (
goto :EOF
)
powershell -Command "(Get-Content 'configs\core\.env') | ForEach-Object {$_ -replace '\bUPGRADE_NOTIFICATION_EMAIL=.*', 'UPGRADE_NOTIFICATION_EMAIL=!NOTIFICATION_EMAIL!'} | Set-Content 'configs\core\.env'"
)
goto :EOF

:: Function to generate a new basic auth token and set it in the .env file
:generate_basic_token
:: Generate a new basic auth token
Expand Down Expand Up @@ -191,6 +226,7 @@ call :check_has_app_url
call :check_has_basic_token
call :check_has_daemon_password
call :check_and_generate_app_key
call :check_has_upgrade_notification_email
call :get_daemon_address

:: Prompt the user to start platform services
Expand Down
38 changes: 38 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ generate_basic_token() {
fi
}

read_email() {
# Read the email address from the user
echo "Please input the email address: (e.g. user@example.com)"
read NOTIFICATION_EMAIL

# Check if the email address is empty
if [ -z "$NOTIFICATION_EMAIL" ]; then
return
fi

# Check if the email address is valid
if ! [[ $NOTIFICATION_EMAIL =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
echo "The email address you provided is not valid. Please try again."
read_email
fi
}

check_has_upgrade_notification_email() {
# Check if user already has UPGRADE_NOTIFICATION_EMAIL set
NOTIFICATION_EMAIL=$(awk '$1 ~ /^UPGRADE_NOTIFICATION_EMAIL/' configs/core/.env | cut -d "=" -f 2)
if [ -z "$NOTIFICATION_EMAIL" ]; then
echo "If you want to receive notifications with major updates or security notices, please provide an email address, otherwise leave it blank"
read_email

# Check if the email address is empty
if [ -z "$NOTIFICATION_EMAIL" ]; then
return
fi

if [ "$PLATFORM_OS" = "macOS" ]; then
sed -i '' -e "s/^UPGRADE_NOTIFICATION_EMAIL=/UPGRADE_NOTIFICATION_EMAIL=$NOTIFICATION_EMAIL/g" configs/core/.env
else
sed -i "s/^UPGRADE_NOTIFICATION_EMAIL=/UPGRADE_NOTIFICATION_EMAIL=\"$NOTIFICATION_EMAIL\"/g" configs/core/.env
fi
fi
}

check_has_basic_token() {
# Check if user already has BASIC_AUTH_TOKEN set
AUTH_TOKEN=$(awk '$1 ~ /^BASIC_AUTH_TOKEN/' configs/core/.env | cut -d "=" -f 2)
Expand Down Expand Up @@ -176,6 +213,7 @@ check_has_app_url
check_has_basic_token
check_has_daemon_password
check_and_generate_app_key
check_has_upgrade_notification_email
get_daemon_address

echo "Do you want to start all platform services? (y/n)"
Expand Down
Loading