Skip to content

Commit

Permalink
Adds APP_KEY generation in start.sh.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bradez committed Mar 7, 2024
1 parent 03ea802 commit de1c467
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ if "%AUTH_TOKEN%"=="" (
)
goto :EOF

:: Function to check if the $APP_KEY is set and generate a new one if not
:check_and_generate_app_key
:: Check if $APP_KEY is already set
set "APP_KEY="
for /f "tokens=2 delims==" %%i in ('findstr /r /c:"APP_KEY=" configs\core\.env') do (
set "APP_KEY=%%i"
)
:: If not set, generate a new key automatically
if "%APP_KEY%"=="" (
echo No application key set. A new key will be generated automatically.

for /f "delims=" %%i in ('powershell -Command "$RandomBytes = New-Object byte[] 32; [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($RandomBytes); $Base64String = [Convert]::ToBase64String($RandomBytes); Write-Output $Base64String"') do (
set APP_KEY=%%i
)

powershell -Command "(Get-Content 'configs\core\.env') | ForEach-Object {$_ -replace '\bAPP_KEY=.*', 'APP_KEY=base64:!APP_KEY!'} | Set-Content 'configs\core\.env'"
)
goto :EOF

:: Function to generate a daemon password and set it in the .env file
:generate_daemon_password
:: Generate a new daemon password
Expand Down Expand Up @@ -175,6 +194,7 @@ git submodule update --init
call :check_has_app_url
call :check_has_basic_token
call :check_has_daemon_password
call :check_and_generate_app_key

:: Build the daemon container
docker compose build daemon
Expand Down
15 changes: 15 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ check_has_basic_token() {
fi
}

check_and_generate_app_key() {
APP_KEY=$(awk '$1 ~ /^APP_KEY/' configs/core/.env | cut -d "=" -f 2)
if [ -z "$APP_KEY" ]; then
echo "No application key set. A new key will be generated automatically."

if [ "$PLATFORM_OS" = "macOS" ]; then
APP_KEY=$(dd if=/dev/urandom bs=32 count=1 status=none | base64)
sed -i '' -e "s/^APP_KEY=/APP_KEY=base64:$APP_KEY/g" configs/daemon/.env
else
sed -i "s/^APP_KEY=/APP_KEY=base64:$APP_KEY/g" configs/daemon/.env
fi
fi
}

generate_daemon_password() {
# Generate a new key pass for the daemon and set to .env file
WALLET_PASSWORD=$(openssl rand -hex 32)
Expand Down Expand Up @@ -158,6 +172,7 @@ git submodule update --init
check_has_app_url
check_has_basic_token
check_has_daemon_password
check_and_generate_app_key

docker compose build daemon
get_daemon_address
Expand Down

0 comments on commit de1c467

Please sign in to comment.