10-chocolatey64-gbe64.bat 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
@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 "10-" == "%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 ===========================================================================
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=notepad++.exe
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 CHOCOLATEY_HOME_REL_PATH=%%b
set CHOCOLATEY_HOME=%CURRENT_DIR%\%CHOCOLATEY_HOME_REL_PATH%
set CHOCOLATEY_PATH=%CHOCOLATEY_HOME%\bin
SET ChocolateyInstall=%CHOCOLATEY_HOME%

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 CHOCOLATEY_HOME is equal to %CHOCOLATEY_HOME%
echo The CHOCOLATEY_HOME_REL_PATH is equal to %CHOCOLATEY_HOME_REL_PATH%
echo The CHOCOLATEY_PATH is equal to %CHOCOLATEY_PATH%

rem ----------------------------------  Path   --------------------------------

echo %PATH% | %WINDIR%\System32\find.exe "%CHOCOLATEY_PATH%" /C >NUL
IF NOT ERRORLEVEL 1 GOTO pathDuplicate
SET PATH=%CHOCOLATEY_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