PageRenderTime 1727ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/GetGnuWin32/install.bat

https://gitlab.com/jjrobinson/win-utils
Batch | 392 lines | 296 code | 40 blank | 56 comment | 53 complexity | 6325a081880e1c1c2d5799069d62dac1 MD5 | raw file
  1. :: -------------------------------------------------------------------
  2. ::
  3. :: install.bat -- Install gnuwin32 package from a local archive
  4. :: whithin the cmd console of windows XP
  5. ::
  6. :: authors: Mathias Michaelis <michaelis@tcnet.ch>
  7. :: Jay Satiro <raysatiro@users.sourceforge.net>
  8. :: date : November 15, 2009
  9. :: version: 0.6.3
  10. ::
  11. :: Copyright (c) 2009 by Mathias Michaelis <michaelis@tcnet.ch>
  12. :: Copyright (c) 2009 by Jay Satiro <raysatiro@users.sourceforge.net>
  13. ::
  14. :: -------------------------------------------------------------------
  15. ::
  16. :: Permission is granted to copy, distribute and/or modify this document
  17. :: under the terms of the GNU Free Documentation License, Version 1.2
  18. :: or any later version published by the Free Software Foundation;
  19. :: with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  20. :: Texts. A copy of the license is included in the file LICENSE.TXT
  21. ::
  22. ::
  23. :: Acknowledgments
  24. :: ---------------
  25. ::
  26. :: See file README.TXT in this directory. Thanks to all who advised me,
  27. :: gave me some hints, sent me some patches or encouraged me to go on!
  28. ::
  29. @echo off
  30. setlocal ENABLEEXTENSIONS
  31. set LC_ALL=C
  32. set SORTPROG=sort-7.6
  33. set GETGNUWIN32_ID=94d563d1564001
  34. REM switch to this file's directory
  35. cd /d "%0\.." 1>NUL 2>&1
  36. if not exist bin\revision_%GETGNUWIN32_ID% (
  37. echo =
  38. echo = Unique ID bin\revision_%GETGNUWIN32_ID% not found. Probable solution:
  39. echo = Please switch to the getgnuwin32 directory before running this script.
  40. echo =
  41. echo = Install.bat cannot continue.
  42. goto bye
  43. )
  44. REM test ability to write to directory
  45. set GNUWIN32_RANDFILE=%GETGNUWIN32_ID%%RANDOM%.tmp
  46. bin\touch "%GNUWIN32_RANDFILE%"
  47. if not exist ".\%GNUWIN32_RANDFILE%" (
  48. echo =
  49. echo = Cannot write to directory:
  50. echo = "%CD%"
  51. echo = Please check the directory permissions.
  52. echo =
  53. echo = Install.bat cannot continue.
  54. goto bye
  55. )
  56. REM remove temporary files
  57. FOR %%A IN (tmp) DO (
  58. del "*.%%A" 1>NUL 2>&1
  59. if exist "*.%%A" (
  60. echo =
  61. echo = Error: These files should not exist and could not be removed:
  62. dir /b "*.%%A"
  63. echo =
  64. echo = Please make sure you have writable permissions to the
  65. echo = getgnuwin32 directory and all files therein.
  66. echo =
  67. echo = Install.bat cannot continue.
  68. goto bye
  69. )
  70. )
  71. set GNUWIN32_VERBOSE=
  72. set GNUWIN32_HASH_MISSING=
  73. set GNUWIN32_TESTING=
  74. set GNUWIN32_INSTALL_DIRECTORY=gnuwin32
  75. :command_line
  76. if .%1==. goto command_line_end
  77. if "%1"=="-v" goto set_verbose
  78. if "%1"=="/v" goto set_verbose
  79. if "%1"=="-m" goto set_hash_missing_is_ok
  80. if "%1"=="/m" goto set_hash_missing_is_ok
  81. if "%1"=="-j" goto set_just_testing
  82. if "%1"=="/j" goto set_just_testing
  83. if "%1"=="-h" goto show_help_text
  84. if "%1"=="/h" goto show_help_text
  85. if "%1"=="-?" goto show_help_text
  86. if "%1"=="/?" goto show_help_text
  87. if "%1"=="--help" goto show_help_text
  88. if "%1"=="--version" goto show_version_text
  89. set GNUWIN32_INSTALL_DIRECTORY=%1
  90. shift
  91. goto command_line
  92. :set_verbose
  93. set GNUWIN32_VERBOSE=TRUE
  94. shift
  95. goto command_line
  96. :set_hash_missing_is_ok
  97. set GNUWIN32_HASH_MISSING=TRUE
  98. shift
  99. goto command_line
  100. :set_just_testing
  101. REM not used yet
  102. set GNUWIN32_TESTING=TRUE
  103. shift
  104. goto command_line
  105. :show_help_text
  106. echo = install.bat (version 0.6.3^)
  107. echo = Copyright (c^) 2009 by Mathias Michaelis, ^<michaelis@tcnet.ch^>
  108. echo = Copyright (c^) 2009 by Jay Satiro, ^<raysatiro@users.sourceforge.net^>
  109. echo = This is free software; see the source for copying conditions. There is NO
  110. echo = warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  111. echo =
  112. echo = usage:
  113. echo = install --version
  114. echo = install --help
  115. echo = install [-v] [-m] [target-directory]
  116. echo =
  117. echo = description:
  118. echo = install.bat, started without any command line options, will try to do
  119. echo = three things:
  120. echo = 1. Unzip all verified packages in chronological order ^& check for conflicts.
  121. echo = 2. Update the current installation (overwrite with any newer files^)
  122. echo = 3. Separate/organize info and documentation for each package.
  123. echo =
  124. echo = The behaviour of install.bat can be modified by the following options:
  125. echo = -v : verbose mode. There are more lines printed on screen (debug^).
  126. echo = -m : install unverified files missing a filename entry in packages.sha
  127. echo =
  128. echo = If you do not choose a directory to install to, this batch file unzips to the
  129. echo = gnuwin32 subdirectory and you then must copy that directory to your
  130. echo = desired location. You can choose a directory, for example:
  131. echo =
  132. echo = install.bat C:\gnuwin32
  133. echo =
  134. echo = It is suggested that as administrator you do that or copy over to your actual
  135. echo = target location so that appropriate security permissions are inherited.
  136. echo = ^*Personally I suggest using a target path that does not contain spaces.
  137. goto bye
  138. :show_version_text
  139. echo = install.bat (version 0.6.3^)
  140. echo = Copyright (c^) 2009 by Mathias Michaelis, ^<michaelis@tcnet.ch^>
  141. echo = Copyright (c^) 2009 by Jay Satiro, ^<raysatiro@users.sourceforge.net^>
  142. echo = This is free software; see the source for copying conditions. There is NO
  143. echo = warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  144. echo =
  145. goto bye
  146. :command_line_end
  147. REM check for existence of GNUWIN32_INSTALL_DIRECTORY
  148. if not exist "%GNUWIN32_INSTALL_DIRECTORY%" mkdir "%GNUWIN32_INSTALL_DIRECTORY%"
  149. if not exist "%GNUWIN32_INSTALL_DIRECTORY%" (
  150. echo =
  151. echo = Error: failed to create install directory:
  152. echo = "%GNUWIN32_INSTALL_DIRECTORY%"
  153. echo =
  154. echo = Please make sure you have writable permissions to the
  155. echo = target path.
  156. echo =
  157. echo = Install.bat cannot continue.
  158. goto bye
  159. )
  160. set GETGNUWIN32_DIR=%CD%
  161. REM test ability to write to target directory
  162. set GNUWIN32_RANDFILE=%GETGNUWIN32_ID%%RANDOM%.tmp
  163. bin\touch "%GNUWIN32_INSTALL_DIRECTORY%\%GNUWIN32_RANDFILE%"
  164. if not exist "%GNUWIN32_INSTALL_DIRECTORY%\%GNUWIN32_RANDFILE%" (
  165. echo =
  166. echo = Cannot write to directory:
  167. echo = "%GNUWIN32_INSTALL_DIRECTORY%"
  168. echo = Please check the directory permissions.
  169. echo =
  170. echo = Install.bat cannot continue.
  171. goto bye
  172. )
  173. del "%GNUWIN32_INSTALL_DIRECTORY%\%GNUWIN32_RANDFILE%" >NUL 2>&1
  174. FOR %%A IN (bin contrib doc) DO (
  175. mkdir "%GNUWIN32_INSTALL_DIRECTORY%\%%A" 1>NUL 2>&1
  176. bin\touch "%GNUWIN32_INSTALL_DIRECTORY%\%%A\%GNUWIN32_RANDFILE%"
  177. if not exist "%GNUWIN32_INSTALL_DIRECTORY%\%%A\%GNUWIN32_RANDFILE%" (
  178. echo =
  179. echo = Cannot write to directory:
  180. echo = "%GNUWIN32_INSTALL_DIRECTORY%\%%A"
  181. echo = Please check the directory permissions.
  182. echo =
  183. echo = Install.bat cannot continue.
  184. goto bye
  185. )
  186. del "%GNUWIN32_INSTALL_DIRECTORY%\%%A\%GNUWIN32_RANDFILE%" >NUL 2>&1
  187. )
  188. set UNZIP_TOTAL_COUNT=0
  189. bin\test -s packages\hash_pass.txt
  190. if errorlevel 1 (
  191. echo =
  192. echo = Warning!: packages\hash_pass.txt missing or does not contain data
  193. dir packages\hash_pass.txt
  194. echo =
  195. echo = Possible solutions:
  196. echo = Re-Run download.bat
  197. echo =
  198. echo = Continuing anyway...
  199. ) else (
  200. bin\sed -n "$=" packages\hash_pass.txt > count.tmp
  201. bin\test -s count.tmp
  202. if errorlevel 1 (
  203. echo =
  204. echo = Error: File missing or does not contain data: "count.tmp"
  205. dir "count.tmp"
  206. echo =
  207. echo = Please make sure you have writable permissions to the
  208. echo = getgnuwin32 directory and all files therein.
  209. echo =
  210. echo = Download.bat cannot continue.
  211. goto bye
  212. )
  213. set /p UNZIP_TOTAL_COUNT=<count.tmp
  214. del count.tmp >NUL 2>&1
  215. if not defined UNZIP_TOTAL_COUNT set UNZIP_TOTAL_COUNT=0
  216. )
  217. echo =
  218. echo = Unzipping (and/or updating^) packages; also sorting documentation...
  219. echo =
  220. echo = This will take some time, be patient.
  221. echo = Interaction is necessary after the unzipping completes.
  222. echo =
  223. REM Mathias' addons
  224. bin\unzip -u -o -q bin\myaddons.zip -d "%GNUWIN32_INSTALL_DIRECTORY%" >NUL 2>&1
  225. REM for /f won't read from a file in quotes, it will interpret it as a string
  226. REM for has expansion issues (use delayedexpansion or call whatever_tag)
  227. REM can't test directories with "dir\NUL" in quotes. won't work.
  228. if defined GNUWIN32_HASH_MISSING (
  229. bin\test -s packages\hash_missing.txt
  230. if errorlevel 0 if not errorlevel 1 (
  231. FOR /f "tokens=*" %%f IN (packages\hash_missing.txt) DO (
  232. if exist "packages\%%f" (
  233. bin\unzip -u -o -q "packages\%%f" -d "%GNUWIN32_INSTALL_DIRECTORY%" 1>NUL 2>&1
  234. xcopy /Q /Y /I "%GNUWIN32_INSTALL_DIRECTORY%\contrib\*.*" "%GNUWIN32_INSTALL_DIRECTORY%\contrib\%%~nf" >NUL 2>&1
  235. del /F /Q "%GNUWIN32_INSTALL_DIRECTORY%\contrib\*.*" >NUL 2>&1
  236. xcopy /Q /Y /I "%GNUWIN32_INSTALL_DIRECTORY%\doc\*.*" "%GNUWIN32_INSTALL_DIRECTORY%\doc\%%~nf" >NUL 2>&1
  237. del /F /Q "%GNUWIN32_INSTALL_DIRECTORY%\doc\*.*" >NUL 2>&1
  238. )
  239. )
  240. )
  241. )
  242. REM count the total number of packages in hash_pass.txt
  243. set UNZIP_CURRENT_COUNT=0
  244. set PERCENT_DONE=5
  245. set TMP_NUMBER=0
  246. bin\test -s packages\hash_pass.txt
  247. if errorlevel 0 if not errorlevel 1 (
  248. FOR /f "tokens=*" %%f IN (packages\hash_pass.txt) DO (
  249. if exist "packages\%%f" (
  250. bin\unzip -u -o -q "packages\%%f" -d "%GNUWIN32_INSTALL_DIRECTORY%" 1>NUL 2>&1
  251. xcopy /Q /Y /I "%GNUWIN32_INSTALL_DIRECTORY%\contrib\*.*" "%GNUWIN32_INSTALL_DIRECTORY%\contrib\%%~nf" >NUL 2>&1
  252. del /F /Q "%GNUWIN32_INSTALL_DIRECTORY%\contrib\*.*" >NUL 2>&1
  253. xcopy /Q /Y /I "%GNUWIN32_INSTALL_DIRECTORY%\doc\*.*" "%GNUWIN32_INSTALL_DIRECTORY%\doc\%%~nf" >NUL 2>&1
  254. del /F /Q "%GNUWIN32_INSTALL_DIRECTORY%\doc\*.*" >NUL 2>&1
  255. )
  256. call :print_percent
  257. )
  258. )
  259. echo =
  260. echo = Unzipping/updating and documentation sorting has completed.
  261. cd "%GNUWIN32_INSTALL_DIRECTORY%"
  262. if errorlevel 1 (
  263. echo =
  264. echo = Error: failed to switch to install directory:
  265. echo = "%GNUWIN32_INSTALL_DIRECTORY%"
  266. echo =
  267. echo = Please make sure you have writable permissions to the
  268. echo = directory and all files therein.
  269. echo =
  270. echo = Install.bat cannot continue.
  271. goto bye
  272. )
  273. if exist "%GETGNUWIN32_DIR%\bin\supplemental_install.bat" (
  274. call "%GETGNUWIN32_DIR%\bin\supplemental_install.bat" "%CD%\bin"
  275. )
  276. echo =
  277. echo = Finished with packages. Fixing manifests and info entries...
  278. echo =
  279. ::
  280. :: COPY MANIFESTS
  281. :: This fixes Vista problems with files it incorrectly believes require administrator access
  282. ::
  283. copy /Y "%GETGNUWIN32_DIR%\asInvoker.manifest" bin\patch.exe.manifest >NUL 2>NUL
  284. copy /Y "%GETGNUWIN32_DIR%\asInvoker.manifest" bin\install.exe.manifest >NUL 2>NUL
  285. copy /Y "%GETGNUWIN32_DIR%\asInvoker.manifest" bin\install-info.exe.manifest >NUL 2>NUL
  286. :: TESTING SHOWS EXE MODIFIED TIME AND DATE *MUST* BE LATER THAN MANIFEST
  287. :: TOUCH INSTALL/INSTALL-INFO/PATCH AFTER MANIFEST COPY:
  288. "%GETGNUWIN32_DIR%\bin\touch" bin\patch.exe >NUL 2>NUL
  289. "%GETGNUWIN32_DIR%\bin\touch" bin\install.exe >NUL 2>NUL
  290. "%GETGNUWIN32_DIR%\bin\touch" bin\install-info.exe >NUL 2>NUL
  291. echo.
  292. ::
  293. :: Make a list of info-entries
  294. ::
  295. if not exist bin\install-info.exe goto orphan
  296. if exist info\dir del info\dir
  297. dir /a-d /b info >infolist.tmp 2>nul
  298. if errorlevel 1 goto orphan
  299. "%GETGNUWIN32_DIR%\bin\sed" -T "/^.*-[[:digit:]]\+\(\.gz\)\?$\|^dir$/d" infolist.tmp >infolist.txt
  300. ::
  301. :: Update dir entries of info files
  302. ::
  303. for /f "tokens=*" %%i in (infolist.txt) do (
  304. bin\install-info.exe --infodir=./info "info\%%i" 2>NUL
  305. )
  306. ::
  307. :: Remove orphan links, create new ones
  308. ::
  309. :orphan
  310. "%GETGNUWIN32_DIR%\bin\sed" -T "s/^gnuwin32\\bin\\ls -lgGRU gnuwin32 /bin\\ls -lgGRU /;s/\(\d037CD\(:[^\d037]\+\)\?\d037\)\\\{1,2\}gnuwin32/\1/g;s/gnuwin32\\\{1,2\}//g;" "%GETGNUWIN32_DIR%\update-links.bat" >update-links.bat
  311. if not "%GNUWIN32_INSTALL_DIRECTORY%"=="gnuwin32" (
  312. call update-links.bat
  313. ) else (
  314. echo The directory "gnuwin32" can now be copied to any desired place, e.g. to the
  315. echo directory "C:\gnuwin32".
  316. echo.
  317. echo Note that copying is the recommended method on an NTFS file system, since the
  318. echo file access rights are not inherited correctly from the parent directory if
  319. echo the files are moved. On a FAT32 file system, there are no access rights, so
  320. echo there is no disadvantage to moving files.
  321. echo.
  322. echo After moving/copying the gnuwin32 folder to the desired place (pref. as
  323. echo administrator^) run "update-links.bat" from within that (moved/copied^)
  324. echo directory. That will update links to documentation.
  325. )
  326. echo.
  327. echo.
  328. echo Optional:
  329. echo You can ^*append^* the bin subdir of your installation folder to your PATH:
  330. echo i.e. C:\gnuwin32\bin
  331. echo There are a few gnu conflicts with Windows utilities, so make sure to ^*append^*.
  332. echo That way the windows utilities take priority (i.e. sort^).
  333. echo ^*!!!!!! Please read README.txt for more information on your installation !!!!!^*
  334. echo.
  335. echo Done installing. yay. Have fun!
  336. goto bye
  337. :print_percent
  338. set /a UNZIP_CURRENT_COUNT+=1
  339. REM echo percentdone%PERCENT_DONE% total count%UNZIP_TOTAL_COUNT%
  340. set /a TMP_NUMBER="(UNZIP_TOTAL_COUNT/20)*(PERCENT_DONE/5)"
  341. REM echo %UNZIP_CURRENT_COUNT% %TMP_NUMBER%
  342. if /i %UNZIP_CURRENT_COUNT% GTR %TMP_NUMBER% (
  343. echo = %PERCENT_DONE% percent done unzipping / organizing...
  344. set /a PERCENT_DONE+=5
  345. )
  346. goto :EOF
  347. :bye
  348. if exist filelist.tmp del filelist.tmp >NUL 2>&1
  349. if exist infolist.txt del infolist.txt >NUL 2>&1
  350. if exist infolist.tmp del infolist.tmp >NUL 2>&1
  351. endlocal
  352. pause