@ECHO OFF
REM LGNTC.BAT
REM Helper for LGNTSTA.BAT. Output survives LOGOUT/LOGIN on local C:.
REM LOGIN/MAP/LOGOUT are copied to C:\LGNTTMP by LGNTSTA.
REM
REM Important: LOGIN can change the current drive/search path. Therefore all
REM tool calls and all redirected output files use absolute C:\LGNTTMP paths.

C:
CD \LGNTTMP

ECHO LGNTC helper started. > C:\LGNTTMP\HELPER.TXT
ECHO This helper intentionally changes login state. >> C:\LGNTTMP\HELPER.TXT
ECHO It was started by DLYSTRT after LGNTSTA Part 1 returned. >> C:\LGNTTMP\HELPER.TXT
ECHO. >> C:\LGNTTMP\HELPER.TXT

ECHO === D01 LOGOUT from initial supervisor session === >> C:\LGNTTMP\HELPER.TXT
C:\LGNTTMP\LOGOUT > C:\LGNTTMP\D01_LOG.OUT

ECHO === D02 LOGIN NOPASSUSER using local Novell LOGIN === >> C:\LGNTTMP\HELPER.TXT
C:\LGNTTMP\LOGIN NOPASSUSER > C:\LGNTTMP\D02_LGIN.OUT

ECHO === D03 MAP after NOPASSUSER login using local Novell MAP === >> C:\LGNTTMP\HELPER.TXT
C:\LGNTTMP\MAP > C:\LGNTTMP\D03_MAP.OUT

ECHO === D04 LOGOUT NOPASSUSER === >> C:\LGNTTMP\HELPER.TXT
C:\LGNTTMP\LOGOUT > C:\LGNTTMP\D04_LGOT.OUT

REM Novell LOGIN /? may print usage directly to the console instead of stdout.
REM Store the observed simple syntax as baseline for later implementation tests.
ECHO Usage: LOGIN [server/]user > C:\LGNTTMP\D99_HELP.OUT

IF "%LGNTPWD%"=="" GOTO MANUAL

ECHO === D05 LOGIN SUPERVISOR using maintainer F:\LOGIN\LOGIN /PWD option === >> C:\LGNTTMP\HELPER.TXT
F:
CD \
IF EXIST \LOGIN\LOGIN.EXE GOTO HAVELOGINF
ECHO F:\LOGIN\LOGIN.EXE not found before supervisor relogin. >> C:\LGNTTMP\HELPER.TXT
ECHO.
ECHO F:\LOGIN\LOGIN.EXE nicht gefunden.
ECHO Bitte manuell als SUPERVISOR einloggen und danach ausfuehren:
ECHO   F:
ECHO   CD \
ECHO   LGNTSTA PART2
GOTO END

:HAVELOGINF
F:
CD \
F:\LOGIN\LOGIN SUPERVISOR /PWD:%LGNTPWD% > C:\LGNTTMP\D05_LGSUP.OUT

ECHO === Check F: before queuing LGNTSTA PART2 === >> C:\LGNTTMP\HELPER.TXT
F:
CD \
IF EXIST \LGNTSTA.BAT GOTO QUEUEP2
ECHO F: not restored or \LGNTSTA.BAT missing after supervisor login. >> C:\LGNTTMP\HELPER.TXT
ECHO.
ECHO F: wurde nicht wiederhergestellt oder \LGNTSTA.BAT fehlt.
ECHO Bitte manuell pruefen und dann ausfuehren:
ECHO   F:
ECHO   CD \
ECHO   LGNTSTA PART2
GOTO END

:QUEUEP2
ECHO F: is available. Queueing delayed LGNTSTA PART2 only. >> C:\LGNTTMP\HELPER.TXT
C:
CD \LGNTTMP
DLYSTRT /T:2 F:\LGNTSTA.BAT PART2 > C:\LGNTTMP\D06_P2.OUT
ECHO LGNTC queued F:\LGNTSTA.BAT PART2. LGNTZIP is intentionally not automatic. >> C:\LGNTTMP\HELPER.TXT
ECHO.
ECHO LGNTC fertig. PART2 wird per DLYSTRT gestartet.
ECHO LGNTZIP danach bei Bedarf manuell ausfuehren.
GOTO END

:MANUAL
ECHO LGNTPWD is not set; automatic SUPERVISOR login skipped. >> C:\LGNTTMP\HELPER.TXT
ECHO.
ECHO LGNTC fertig. Jetzt manuell wieder als SUPERVISOR einloggen:
ECHO   F:\LOGIN\LOGIN SUPERVISOR
ECHO Danach ausfuehren:
ECHO   F:\LGNTSTA PART2
ECHO LGNTZIP danach bei Bedarf manuell ausfuehren.
ECHO.

:END
