@echo off
if "%RMMuser%" == "" set RMMuser=admin
if "%RMMpassword%" == "" set RMMpassword=password

if Not "%DeployPath%" == "" pushd %DeployPath%\win32\kiratool

if "%1" == "" (
    echo --------RMM2 Version Information-------------------
    call :KTCMD ver
    call :KTCMD fw
    call :KTCMD info
    echo --------RMM2 Network Configuration-------------------
    call :KTCMD cfg get network.pref_hostname
    call :KTCMD ip
    call :KTCMD mac
    call :KTCMD netmask
    call :KTCMD gw
    call :KTCMD ipsrc
) else if "%1" == "set" (
    if "%2" == "" (
        echo "Usage: %0 set ip_address"
    ) else (
        call :KTCMD ip set  %2
        call :KTCMD ipsrc set static
    )
) else if "%1" == "get" (
    if "%2" == "" (
        echo "Usage: %0 get <filename to store results>"
    ) else (
        call :KTCMD cfg backup  %2
    )
) else if "%1" == "apply" (
    if "%2" == "" (
        echo "Usage: %0 apply <existing backup filename>"
    ) else (
        call :KTCMD cfg restore  %2
    )
) else (
    echo "Usage: %0                      - reports RMM2 configuration info."
    echo "       %0 [set ip_address]     - sets a static IP address for the RMM2"
    echo "       %0 [get <filename to store results>]   - creates a backup file."
    echo "       %0 [apply <existing backup filename>]  - restores a backup file."
)
if Not "%DeployPath%" == "" popd
goto :EOF

:KTCMD
kiratool -u %RMMuser% -p %RMMpassword% %*
set ERR=%ERRORLEVEL%
if Not "%ERR%" == "0" (
    echo We got an error: %ERR%
)
goto :EOF

REM To confirm whether a .bin file is a valid RMM2 firmware image (but not upgrade) ...
REM kiratool.exe -u %RMMusername% -p %RMMpassword% fw validate fw-kira-kimasmig4-asmidc-intel_040202-5990.bin

REM To upgrade the RMM2 firmware use:  (this also confirms that the image is valid)
REM kiratool.exe -u %RMMusername% -p %RMMpassword% fw upgrade fw-kira-kimasmig4-asmidc-intel_040202-5990.bin
