Skip to content

Commit

Permalink
try to update file different way
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crawford <[email protected]>
  • Loading branch information
stephen-crawford committed Sep 25, 2023
1 parent f69050a commit b216245
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions tools/install_demo_configuration.bat
Original file line number Diff line number Diff line change
Expand Up @@ -363,33 +363,17 @@ if errorlevel 1 (
echo Clear the ADMIN_PASSWORD variable
set "ADMIN_PASSWORD="

set "OUTPUT_FILE=temp_file"

del "%OUTPUT_FILE%" 2>nul

for /f "usebackq delims=" %%a in ("%INTERNAL_USERS_FILE%") do (
set "line=%%a"
if "!line:~0,2!"==" " (
rem Check if the line contains the specific pattern
if "!line:~2!"=="hash: \"$2a$12$VcCDgh2NDk07JGN0rjGbM.Ad41qVR/YFJcgHp0UGns5JDymv..TOG\"" (
echo "line found"
)
)
)
set default_line=" hash: ""$2a$12$VcCDgh2NDk07JGN0rjGbM.Ad41qVR/YFJcgHp0UGns5JDymv..TOG"""

for /f "usebackq delims=" %%a in ("%INTERNAL_USERS_FILE%") do (
set "line=%%a"
rem Check for two leading spaces before the pattern
if "!line:~0,2!"==" " (
rem Check if the line contains the specific pattern
if "!line:~2!"=="hash: \"$2a$12$VcCDgh2NDk07JGN0rjGbM.Ad41qVR/YFJcgHp0UGns5JDymv..TOG\"" (
set "line= hash: \"%HASHED_ADMIN_PASSWORD%\""
)
)
echo !line!>>"%OUTPUT_FILE%"
)
set "search=%default_line%"
set "replace=" hash: ""%HASHED_ADMIN_PASSWORD%"""

move /y "%OUTPUT_FILE%" "%INTERNAL_USERS_FILE%"

for /f "delims=" %%i in ('type "%INTERNAL_USERS_FILE%" ^& break ^> "%INTERNAL_USERS_FILE%" ') do (
set "line=%%i"
>>"%INTERNAL_USERS_FILE%" echo(!line:%search%=%replace%!
endlocal
)

echo AFTER CHANGE:
type "%INTERNAL_USERS_FILE%"
Expand Down

0 comments on commit b216245

Please sign in to comment.