first commit

parents
@echo off
rem ---------------------------------------------------------------------------
rem Script for configuring and starting a given application
rem
rem $Id: *.bat 0000001 2014-05-23 14:48:00Z gbe $
rem ---------------------------------------------------------------------------
rem ===========================================================================
rem CONFIG IDENTIFIER
rem ===========================================================================
set CURRENT_CONF=-gbe64
set CURRENT_DIR=%CD%
set FORCE_CALL=0
set FORCE_CALL_STOP=0
set FORCE_CALL_RESTART=0
rem echo "Relative Path %0"
rem echo "Drive and Path -> %~dp0"
rem echo "Full Path -> %~f0"
set CONFIG_DIR=%~dp0
rem https://www.dostips.com/DtTipsStringManipulation.php
set CONFIG_DIR=%CONFIG_DIR:~0,-1%
rem ===========================================================================
rem SHIFT PARAMS
rem ===========================================================================
rem It adds params
rem
rem ---------------------------------------------------------------------------
set CMD_LINE_ARGS=
if "%VERBOSE%"=="Y" (echo shiftParams %0)
rem Get remaining unshifted command line arguments and save them in the
:setArgs
if ""%2""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %2
shift
goto setArgs
:doneSetArgs
rem ===========================================================================
rem Checking of the kind of execution aimed
rem ===========================================================================
IF "%1"=="configOthers" GOTO configOthers
IF "%1"=="config" GOTO config
IF "%1"=="start" GOTO start
IF "%1"=="stop" GOTO stop
IF "%1"=="restart" GOTO restart
IF "%1"=="plainConfig" GOTO plainConfig
IF "%1"=="plainStart" GOTO plainStart
IF "%1"=="plainStartCall" GOTO plainStart
IF "%1"=="plainStop" GOTO plainStop
IF "%1"=="plainStopCall" GOTO plainStop
IF "%1"=="plainRestart" GOTO plainRestart
IF "%1"=="plainRestartCall" GOTO plainRestart
IF "%1"=="help" GOTO help
IF "%1"=="shiftParams" GOTO shiftParams
goto default
:plainConfig
rem ===========================================================================
rem PLAINCONFIG SECTION
rem ===========================================================================
rem This configure the particular settings for this application, i.e. the path
rem environment variables, etc.
rem
rem ---------------------------------------------------------------------------
echo plainConfig %0
rem -----------------------------------constants-------------------------------
set EXECUTABLE=
set EXECUTABLE_HOME=
set ADD_CMD_LINE_ARGS=
set ADD_CMD_LINE_ARGS_END=
set EXECUTABLE_STOP=
set STOP_EXECUTABLE_HOME=
set ADD_STOP_CMD_LINE_ARGS=
set ADD_STOP_CMD_LINE_ARGS_END=
set EXECUTABLE_RESTART=
set RESTART_EXECUTABLE_HOME=
set ADD_RESTART_CMD_LINE_ARGS=
set ADD_RESTART_CMD_LINE_ARGS_END=
for %%* in (.) do set CURRENT_DIR_NAME=%%~nx*
set CREDENTIALS_HOME=%CURRENT_DIR%\..\credentials\%CURRENT_DIR_NAME%
rem this sets home variable used by cygwin git and other tools such as packer, etc
set HOME=%CREDENTIALS_HOME%\home
mkdir %HOME% >nul 2>&1
rem inside CREDENTIALS_HOME we look for .env files
FOR /R %CREDENTIALS_HOME% %%G IN (*.env) DO (
echo file: "%%G"
FOR /F %%F IN (%%G) DO (
echo SET %%F
SET %%F > nul 2>&1
)
)
if "%VERBOSE%"=="Y" (
echo The Current Dir is equal to %CURRENT_DIR%
echo The Current Conf is equal to %CURRENT_CONF%
echo The Config Dir is equal to %CONFIG_DIR%
echo The CURRENT_DIR_NAME is equal to %CURRENT_DIR_NAME%
echo The CREDENTIALS_HOME is equal to %CREDENTIALS_HOME%
echo The HOME is equal to %HOME%
)
goto end
:default
rem ===========================================================================
rem DEFAULT SECTION
rem ===========================================================================
rem If not config, start, stop, restart, or help run we are supposed to run
rem all the other config in this folder, then config run the config and
rem finnally run (launch) the application that depends on this batch
rem
rem this consist on:
rem
rem - first I will enumerate the configuration files that are going to be launch
rem - then launch those applications
rem - finally the aplication specific configuration
rem - finally launch aplication
rem
rem ---------------------------------------------------------------------------
echo default %0
set CMD_LINE_ARGS=%1 %CMD_LINE_ARGS%
goto start
goto end
:configOthers
rem ===========================================================================
rem CONFIGOTHERS SECTION
rem ===========================================================================
rem This launch the config sections of others gbe-*.bats in this folder using
rem the config parameter
rem
rem ---------------------------------------------------------------------------
if "%VERBOSE%"=="Y" (echo configOthers %0)
rem returns alphabetically sorted list
FOR %%G IN (%CONFIG_DIR%\*%CURRENT_CONF%.bat) DO (
if NOT "%%G"=="%CURRENT_DIR%\%0" (
echo calling plainConfig in %%G
if "%VERBOSE%"=="Y" (
call %%G plainConfig
) else (
call %%G plainConfig >nul 2>&1
)
)
)
rem ----finally I load the plainConfig of this launcher to give priority-------
echo calling plainConfig in %0
call %0 plainConfig
goto end
:config
rem ===========================================================================
rem CONFIG SECTION
rem ===========================================================================
rem This configure the particular settings for this application, i.e. the path
rem environment variables, etc.
rem
rem ---------------------------------------------------------------------------
echo config %0
call %0 configOthers
goto end
:start
rem ===========================================================================
rem START SECTION
rem ===========================================================================
rem It loads the others configuration, the configuration of this bat, and launch
rem the application
rem
rem ---------------------------------------------------------------------------
echo start %0
call %0 configOthers
call %0 plainStart %CMD_LINE_ARGS%
goto end
:plainStart
rem ===========================================================================
rem PLAINSTART SECTION
rem ===========================================================================
rem It runs the application
rem
rem ---------------------------------------------------------------------------
echo plainStart %0
IF "%EXECUTABLE%"=="" GOTO end
IF NOT "%EXECUTABLE_HOME%" == "" (
echo changing cd to %EXECUTABLE_HOME%
cd "%EXECUTABLE_HOME%"
)
IF NOT "%FORCE_CALL%" == "0" GOTO plainStartCall
IF "%1"=="plainStartCall" GOTO plainStartCall
start "" /B "%EXECUTABLE%" %ADD_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_CMD_LINE_ARGS_END%
GOTO endStart
:plainStartCall
call "%EXECUTABLE%" %ADD_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_CMD_LINE_ARGS_END%
:endStart
cd "%CURRENT_DIR%"
goto end
:stop
rem ===========================================================================
rem STOP SECTION
rem ===========================================================================
rem It loads the others configuration, the configuration of this bat, and stops
rem the application
rem
rem ---------------------------------------------------------------------------
echo stop %0
call %0 configOthers
call %0 plainStop %CMD_LINE_ARGS%
goto end
:plainStop
rem ===========================================================================
rem PLAINSTOP SECTION
rem ===========================================================================
rem It stops the application
rem
rem ---------------------------------------------------------------------------
echo plainStop %0
IF "%EXECUTABLE_STOP"=="" GOTO end
IF NOT "%STOP_EXECUTABLE_HOME%" == "" (
echo changing cd to %STOP_EXECUTABLE_HOME%
cd "%STOP_EXECUTABLE_HOME%"
)
rem echo DEBUG start /B "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS%
rem http://stackoverflow.com/questions/154075/using-the-dos-start-command-with-parameters-passed-to-the-started-program
IF NOT "%FORCE_CALL_STOP%" == "0" GOTO plainStopCall
IF "%1"=="plainStopCall" GOTO plainStopCall
rem start "" /B "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS% 2>nul //If we what no error messages
start "" /B "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_STOP_CMD_LINE_ARGS_END%
GOTO endStop
:plainStopCall
call "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_STOP_CMD_LINE_ARGS_END%
:endStop
cd "%CURRENT_DIR%"
goto end
:restart
rem ===========================================================================
rem RESTART SECTION
rem ===========================================================================
rem It loads the others configuration, the configuration of this bat, restarts
rem the application
rem
rem ---------------------------------------------------------------------------
echo restart %0
call %0 configOthers
call %0 plainRestart %CMD_LINE_ARGS%
goto end
:plainRestart
rem ===========================================================================
rem PLAINRESTART SECTION
rem ===========================================================================
rem It stops and starts the application
rem
rem ---------------------------------------------------------------------------
echo plainRestart %0
IF "%EXECUTABLE_RESTART%"=="" GOTO callstopstart
IF NOT "%RESTART_EXECUTABLE_HOME%" == "" (
echo changing cd to %RESTART_EXECUTABLE_HOME%
cd "%RESTART_EXECUTABLE_HOME%"
)
IF NOT "%FORCE_CALL_RESTART%" == "0" GOTO plainRestartCall
IF "%1"=="plainRestartCall" GOTO plainRestartCall
start "" /B "%EXECUTABLE_RESTART%" %ADD_RESTART_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_RESTART_CMD_LINE_ARGS_END%
GOTO endRestart
:plainRestartCall
call "%EXECUTABLE_RESTART%" %ADD_RESTART_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_RESTART_CMD_LINE_ARGS_END%
:endRestart
cd "%CURRENT_DIR%"
goto end
:callstopstart
call %0 plainStopCall %CMD_LINE_ARGS%
echo ERRORLEVEL = "%ERRORLEVEL%"
IF NOT "%ERRORLEVEL%" == "0" goto end
call %0 config
call %0 plainStart %CMD_LINE_ARGS%
goto end
:help
rem ===========================================================================
rem HELP SECTION
rem ===========================================================================
rem shows the usage
rem
rem ---------------------------------------------------------------------------
echo help %0
goto end
:end
@echo off
rem ---------------------------------------------------------------------------
rem Script for configuring and starting a given application
rem
rem $Id: *.bat 0000001 2014-05-23 14:48:00Z gbe $
rem ---------------------------------------------------------------------------
rem ===========================================================================
rem CHECK IF REQUIRED
rem ===========================================================================
set FILENAME=%~n0
set FILENAME_NO=%FILENAME:~0,3%
if "05-" == "%FILENAME_NO%" (
echo %FILENAME% %FILENAME_NO%
setlocal EnableDelayedExpansion
FOR /F "tokens=1,2 delims=- " %%a in ("%FILENAME%") do set APPNAME=%%b
if not exist %CD%\!APPNAME! goto end
endlocal
)
rem https://www.dostips.com/DtTipsStringManipulation.php
rem ===========================================================================
rem CONFIG IDENTIFIER
rem ===========================================================================
set CURRENT_CONF=-gbe64
set CURRENT_DIR=%CD%
set FORCE_CALL=0
set FORCE_CALL_STOP=0
set FORCE_CALL_RESTART=0
rem echo "Relative Path %0"
rem echo "Drive and Path -> %~dp0"
rem echo "Full Path -> %~f0"
set CONFIG_DIR=%~dp0
rem https://www.dostips.com/DtTipsStringManipulation.php
set CONFIG_DIR=%CONFIG_DIR:~0,-1%
rem ===========================================================================
rem SHIFT PARAMS
rem ===========================================================================
rem It adds params
rem
rem ---------------------------------------------------------------------------
set CMD_LINE_ARGS=
echo shiftParams %0
rem Get remaining unshifted command line arguments and save them in the
:setArgs
if ""%2""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %2
shift
goto setArgs
:doneSetArgs
rem ===========================================================================
rem Checking of the kind of execution aimed
rem ===========================================================================
IF "%1"=="configOthers" GOTO configOthers
IF "%1"=="config" GOTO config
IF "%1"=="start" GOTO start
IF "%1"=="stop" GOTO stop
IF "%1"=="restart" GOTO restart
IF "%1"=="plainConfig" GOTO plainConfig
IF "%1"=="plainStart" GOTO plainStart
IF "%1"=="plainStartCall" GOTO plainStart
IF "%1"=="plainStop" GOTO plainStop
IF "%1"=="plainStopCall" GOTO plainStop
IF "%1"=="plainRestart" GOTO plainRestart
IF "%1"=="plainRestartCall" GOTO plainRestart
IF "%1"=="help" GOTO help
IF "%1"=="shiftParams" GOTO shiftParams
goto default
:plainConfig
rem ===========================================================================
rem PLAINCONFIG SECTION
rem ===========================================================================
rem This configure the particular settings for this application, i.e. the path
rem environment variables, etc.
rem
rem ---------------------------------------------------------------------------
echo plainConfig %0
rem -----------------------------------constants-------------------------------
set EXECUTABLE=
set EXECUTABLE_HOME=
set ADD_CMD_LINE_ARGS=
set ADD_CMD_LINE_ARGS_END=
set EXECUTABLE_STOP=
set STOP_EXECUTABLE_HOME=
set ADD_STOP_CMD_LINE_ARGS=
set ADD_STOP_CMD_LINE_ARGS_END=
set EXECUTABLE_RESTART=
set RESTART_EXECUTABLE_HOME=
set ADD_RESTART_CMD_LINE_ARGS=
set ADD_RESTART_CMD_LINE_ARGS_END=
FOR /F "tokens=1,2 delims=- " %%a in ("%FILENAME%") do set CYGWIN_HOME_REL_PATH=%%b
set CYGWIN_HOME=%CURRENT_DIR%\%CYGWIN_HOME_REL_PATH%
set CYGWIN_PATH=%CURRENT_DIR%\%CYGWIN_HOME_REL_PATH%\bin
rem cygwin fstab fix, we check if cygwin is available
if "%VERBOSE%"=="Y" (echo Checking fstab issue https://stackoverflow.com/questions/5828037/cygwin-sets-file-permission-to-000)
echo %CYGWIN_HOME%\etc\fstab | %WINDIR%\System32\find.exe "noacl" /C >NUL
IF NOT ERRORLEVEL 1 GOTO fstabOK
if "%VERBOSE%"=="Y" (echo Fixing fstab adding noacl)
%CYGWIN_PATH%\sed -i "s\,user \,user,noacl \g" %CYGWIN_HOME%\etc\fstab
:fstabOK
rem cygwin home fix, we check if home is setup is available
if "%VERBOSE%"=="Y" (echo Checking fstab issue https://stackoverflow.com/questions/5828037/cygwin-sets-file-permission-to-000)
echo %CYGWIN_HOME%\etc\nsswitch.conf | %WINDIR%\System32\find.exe "# db_home:" /C >NUL
IF NOT ERRORLEVEL 1 GOTO homeOK
if "%VERBOSE%"=="Y" (echo Fixing home adding home)
for /f "tokens=*" %%i in ('"%CYGWIN_PATH%\cygpath %HOME%"') do set HOME_AUX=%%i
%CYGWIN_PATH%\sed -i "s\# db_home:.*\db_home: %HOME_AUX%\g" %CYGWIN_HOME%\etc\nsswitch.conf
:homeOK
echo The Current Dir is equal to %CURRENT_DIR%
echo The Current Conf is equal to %CURRENT_CONF%
echo The Config Dir is equal to %CONFIG_DIR%
echo The CYGWIN_HOME is equal to %CYGWIN_HOME%
echo The CYGWIN_HOME_REL_PATH is equal to %CYGWIN_HOME_REL_PATH%
rem ---------------------------------- Path --------------------------------
echo %PATH% | %WINDIR%\System32\find.exe "%CYGWIN_PATH%" /C >NUL
IF NOT ERRORLEVEL 1 GOTO pathDuplicate
SET PATH=%CYGWIN_PATH%;%PATH%
echo PATH has been updated PATH = %PATH%
:pathDuplicate
goto end
:default
rem ===========================================================================
rem DEFAULT SECTION
rem ===========================================================================
rem If not config, start, stop, restart, or help run we are supposed to run
rem all the other config in this folder, then config run the config and
rem finnally run (launch) the application that depends on this batch
rem
rem this consist on:
rem
rem - first I will enumerate the configuration files that are going to be launch
rem - then launch those applications
rem - finally the aplication specific configuration
rem - finally launch aplication
rem
rem ---------------------------------------------------------------------------
echo default %0
set CMD_LINE_ARGS=%1 %CMD_LINE_ARGS%
goto start
goto end
:configOthers
rem ===========================================================================
rem CONFIGOTHERS SECTION
rem ===========================================================================
rem This launch the config sections of others gbe-*.bats in this folder using
rem the config parameter
rem
rem ---------------------------------------------------------------------------
echo configOthers %0
FOR %%G IN (%CONFIG_DIR%\*%CURRENT_CONF%.bat) DO (
if NOT "%%G"=="%CURRENT_DIR%\%0" (
echo calling plainConfig in %%G
call %%G plainConfig
)
)
rem ----finally I load the plainConfig of this launcher to give priority-------
call %0 plainConfig
goto end
:config
rem ===========================================================================
rem CONFIG SECTION
rem ===========================================================================
rem This configure the particular settings for this application, i.e. the path
rem environment variables, etc.
rem
rem ---------------------------------------------------------------------------
echo config %0
call %0 configOthers
goto end
:start
rem ===========================================================================
rem START SECTION
rem ===========================================================================
rem It loads the others configuration, the configuration of this bat, and launch
rem the application
rem
rem ---------------------------------------------------------------------------
echo start %0
call %0 configOthers
call %0 plainStart %CMD_LINE_ARGS%
goto end
:plainStart
rem ===========================================================================
rem PLAINSTART SECTION
rem ===========================================================================
rem It runs the application
rem
rem ---------------------------------------------------------------------------
echo plainStart %0
IF "%EXECUTABLE%"=="" GOTO end
IF NOT "%EXECUTABLE_HOME%" == "" (
echo changing cd to %EXECUTABLE_HOME%
cd "%EXECUTABLE_HOME%"
)
IF NOT "%FORCE_CALL%" == "0" GOTO plainStartCall
IF "%1"=="plainStartCall" GOTO plainStartCall
start "" /B "%EXECUTABLE%" %ADD_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_CMD_LINE_ARGS_END%
GOTO endStart
:plainStartCall
call "%EXECUTABLE%" %ADD_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_CMD_LINE_ARGS_END%
:endStart
cd "%CURRENT_DIR%"
goto end
:stop
rem ===========================================================================
rem STOP SECTION
rem ===========================================================================
rem It loads the others configuration, the configuration of this bat, and stops
rem the application
rem
rem ---------------------------------------------------------------------------
echo stop %0
call %0 configOthers
call %0 plainStop %CMD_LINE_ARGS%
goto end
:plainStop
rem ===========================================================================
rem PLAINSTOP SECTION
rem ===========================================================================
rem It stops the application
rem
rem ---------------------------------------------------------------------------
echo plainStop %0
IF "%EXECUTABLE_STOP"=="" GOTO end
IF NOT "%STOP_EXECUTABLE_HOME%" == "" (
echo changing cd to %STOP_EXECUTABLE_HOME%
cd "%STOP_EXECUTABLE_HOME%"
)
rem echo DEBUG start /B "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS%
rem http://stackoverflow.com/questions/154075/using-the-dos-start-command-with-parameters-passed-to-the-started-program
IF NOT "%FORCE_CALL_STOP%" == "0" GOTO plainStopCall
IF "%1"=="plainStopCall" GOTO plainStopCall
rem start "" /B "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS% 2>nul //If we what no error messages
start "" /B "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_STOP_CMD_LINE_ARGS_END%
GOTO endStop
:plainStopCall
call "%EXECUTABLE_STOP%" %ADD_STOP_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_STOP_CMD_LINE_ARGS_END%
:endStop
cd "%CURRENT_DIR%"
goto end
:restart
rem ===========================================================================
rem RESTART SECTION
rem ===========================================================================
rem It loads the others configuration, the configuration of this bat, restarts
rem the application
rem
rem ---------------------------------------------------------------------------
echo restart %0
call %0 configOthers
call %0 plainRestart %CMD_LINE_ARGS%
goto end
:plainRestart
rem ===========================================================================
rem PLAINRESTART SECTION
rem ===========================================================================
rem It stops and starts the application
rem
rem ---------------------------------------------------------------------------
echo plainRestart %0
IF "%EXECUTABLE_RESTART%"=="" GOTO callstopstart
IF NOT "%RESTART_EXECUTABLE_HOME%" == "" (
echo changing cd to %RESTART_EXECUTABLE_HOME%
cd "%RESTART_EXECUTABLE_HOME%"
)
IF NOT "%FORCE_CALL_RESTART%" == "0" GOTO plainRestartCall
IF "%1"=="plainRestartCall" GOTO plainRestartCall
start "" /B "%EXECUTABLE_RESTART%" %ADD_RESTART_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_RESTART_CMD_LINE_ARGS_END%
GOTO endRestart
:plainRestartCall
call "%EXECUTABLE_RESTART%" %ADD_RESTART_CMD_LINE_ARGS% %CMD_LINE_ARGS% %ADD_RESTART_CMD_LINE_ARGS_END%
:endRestart
cd "%CURRENT_DIR%"
goto end
:callstopstart
call %0 plainStopCall %CMD_LINE_ARGS%
echo ERRORLEVEL = "%ERRORLEVEL%"
IF NOT "%ERRORLEVEL%" == "0" goto end
call %0 config
call %0 plainStart %CMD_LINE_ARGS%
goto end
:help
rem ===========================================================================
rem HELP SECTION
rem ===========================================================================
rem shows the usage
rem
rem ---------------------------------------------------------------------------
echo help %0
goto end
:end