I made an update (attached) to the script. Further comments on https://github.com/msys2/msys2/issues/71

  Vincent.


Le 17/08/2017 à 12:27, David Macek a écrit :
I filed a ticket for this change: https://github.com/msys2/msys2/issues/71

We can continue the discussion there (or not).

On 17. 8. 2017 12:04, Vincent Belaïche wrote:
On second thought I think that this script is so tiny that it would certainly be simpler if it was created in the temporary directory and deleted after use.

Sounds good.




---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus
@echo off
setlocal EnableExtensions
setlocal

set "WD=%__CD__%"
if NOT EXIST "%WD%msys-2.0.dll" set "WD=%~dp0usr\bin\"

rem To activate windows native symlinks uncomment next line
set MSYS=winsymlinks:nativestrict

rem Set debugging program for errors
rem set 
MSYS=error_start:%WD%../../mingw64/bin/qtcreator.exe^|-debug^|^<process-id^>

rem To export full current PATH from environment into MSYS2 use 
'-use-full-path' parameter
rem or uncomment next line
rem set MSYS2_PATH_TYPE=inherit

rem default values
set UAC_ELEVATION=0

:checkparams
rem Help option
if "x%~1" == "x-help" (
  call :printhelp "%~nx0"
  exit /b %ERRORLEVEL%
)
if "x%~1" == "x--help" (
  call :printhelp "%~nx0"
  exit /b %ERRORLEVEL%
)
if "x%~1" == "x-?" (
  call :printhelp "%~nx0"
  exit /b %ERRORLEVEL%
)
if "x%~1" == "x/?" (
  call :printhelp "%~nx0"
  exit /b %ERRORLEVEL%
)
rem Shell types
if "x%~1" == "x-msys" shift& set MSYSTEM=MSYS& goto checkparams
if "x%~1" == "x-msys2" shift& set MSYSTEM=MSYS& goto :checkparams
if "x%~1" == "x-mingw32" shift& set MSYSTEM=MINGW32& goto :checkparams
if "x%~1" == "x-mingw64" shift& set MSYSTEM=MINGW64& goto :checkparams
if "x%~1" == "x-mingw" shift& (if exist "%WD%..\..\mingw64" (set 
MSYSTEM=MINGW64) else (set MSYSTEM=MINGW32))& goto :checkparams
rem Console types
if "x%~1" == "x-consolez" shift& set MSYSCON=console.exe& goto :checkparams
if "x%~1" == "x-mintty" shift& set MSYSCON=mintty.exe& goto :checkparams
if "x%~1" == "x-conemu" shift& set MSYSCON=conemu& goto :checkparams
if "x%~1" == "x-defterm" shift& set MSYSCON=defterm& goto :checkparams
rem Other parameters
if "x%~1" == "x-full-path" shift& set MSYS2_PATH_TYPE=inherit& goto :checkparams
if "x%~1" == "x-use-full-path" shift& set MSYS2_PATH_TYPE=inherit& goto 
:checkparams
if "x%~1" == "x-here" shift& set CHERE_INVOKING=enabled_from_arguments& goto 
:checkparams
if "x%~1" == "x-where" (
  if "x%~2" == "x" (
    echo Working directory is not specified for -where parameter. 1>&2
    exit /b 2
  )
  cd /d "%~2" || (
    echo Cannot set specified working diretory "%~2". 1>&2
    exit /b 2
  )
  set CHERE_INVOKING=enabled_from_arguments
)& shift& shift& goto :checkparams
if "%~1"=="-uac-elevation" shift & set UAC_ELEVATION=1& goto checkparams

rem check whether or not we need UAC elevalation
if "%MSYS%"=="winsymlinks:nativestrict" (rem
) else goto uac_elevation_not_needed

call :check_symlinks OK

if %OK% neq 0 goto uac_elevation_not_needed

if %UAC_ELEVATION% equ 1 goto uac_elevation_can_t_make_it

rem Here the user wants native symlinks, but they do not work. We
rem assume that this is because the user does not have UAC
rem elevation. This is a possible cause, but not the only one, the
rem user account may also be configured not to allow symlink creation.
rem We are going to re-launch this script with UAC elevation by means
rem of a VBScript.
call :mktemp elevate_script msys-elevate .vbs
echo Dim oShell,oWshShell,oWshProcessEnv,sArguments>"%elevate_script%"
echo Set oShell = CreateObject("Shell.Application")>>"%elevate_script%"
echo Set oWshShell = WScript.CreateObject("WScript.Shell")>>"%elevate_script%"
echo Set oWshProcessEnv = oWshShell.Environment("PROCESS")>>"%elevate_script%"
echo sArguments = oWshProcessEnv("ELEVATE_ARGUMENTS")>>"%elevate_script%"
echo oShell.ShellExecute "%~dpnx0", "-uac-elevation " ^& sArguments, "%WD%", 
"runas", 1 >>"%elevate_script%"
echo WScript.Quit >>"%elevate_script%"
endlocal & set ELEVATE_ARGUMENTS=%* & setlocal & set 
elevate_script=%elevate_script%
cscript //nologo "%elevate_script%"
set elevate_errorlevel=%ERRORLEVEL%
del /Q "%elevate_script%"
exit /B %elevate_errorlevel%

:uac_elevation_can_t_make_it
rem Here we have already done UAC elevation. However, native symlink
rem still don't work. This means that the user priviledge are not
rem configured correctly.
echo Your user account priviledge do not allow you to create native
echo MSW symlinks.  Please see
echo https://github.com/git-for-windows/git/wiki/Symbolic-Links about
echo ``Allowing non-administrators to create symbolic links''
pause
exit /B 3

:uac_elevation_not_needed
rem Setup proper title
if "%MSYSTEM%" == "MINGW32" (
  set "CONTITLE=MinGW x32"
) else if "%MSYSTEM%" == "MINGW64" (
  set "CONTITLE=MinGW x64"
) else (
  set "CONTITLE=MSYS2 MSYS"
)

if "x%MSYSCON%" == "xmintty.exe" goto startmintty
if "x%MSYSCON%" == "xconsole.exe" goto startconsolez
if "x%MSYSCON%" == "xconemu" goto startconemu
if "x%MSYSCON%" == "xdefterm" goto startsh

if NOT EXIST "%WD%mintty.exe" goto startsh
set MSYSCON=mintty.exe
:startmintty
start "%CONTITLE%" "%WD%mintty" -i /msys2.ico -e /usr/bin/bash --login %1 %2 %3 
%4 %5 %6 %7 %8 %9
exit /b %ERRORLEVEL%

:startconsolez
cd %WD%..\lib\ConsoleZ
start "%CONTITLE%" console -t "%CONTITLE%" -r %1 %2 %3 %4 %5 %6 %7 %8 %9
exit /b %ERRORLEVEL%

:startconemu
call :conemudetect || (
  echo ConEmu not found. Exiting. 1>&2
  exit /b 1
)
start "%CONTITLE%" "%ComEmuCommand%" /Here /Icon "%WD%..\..\msys2.ico" /cmd 
"%WD%bash" --login %1 %2 %3 %4 %5 %6 %7 %8 %9
exit /b %ERRORLEVEL%

:startsh
set MSYSCON=
start "%CONTITLE%" "%WD%bash" --login %1 %2 %3 %4 %5 %6 %7 %8 %9
exit /b %ERRORLEVEL%

:exit
exit /b 0

:conemudetect
set ComEmuCommand=
if defined ConEmuDir (
  if exist "%ConEmuDir%\ConEmu64.exe" (
    set "ComEmuCommand=%ConEmuDir%\ConEmu64.exe"
    set MSYSCON=conemu64.exe
  ) else if exist "%ConEmuDir%\ConEmu.exe" (
    set "ComEmuCommand=%ConEmuDir%\ConEmu.exe"
    set MSYSCON=conemu.exe
  )
)
if not defined ComEmuCommand (
  ConEmu64.exe /Exit 2>nul && (
    set ComEmuCommand=ConEmu64.exe
    set MSYSCON=conemu64.exe
  ) || (
    ConEmu.exe /Exit 2>nul && (
      set ComEmuCommand=ConEmu.exe
      set MSYSCON=conemu.exe
    )
  )
)
if not defined ComEmuCommand (
  FOR /F "tokens=*" %%A IN ('reg.exe QUERY 
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ConEmu64.exe" /ve 
2^>nul ^| find "REG_SZ"') DO (
    set "ComEmuCommand=%%A"
  )
  if defined ComEmuCommand (
    call set "ComEmuCommand=%%ComEmuCommand:*REG_SZ    =%%"
    set MSYSCON=conemu64.exe
  ) else (
    FOR /F "tokens=*" %%A IN ('reg.exe QUERY 
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ConEmu.exe" /ve 
2^>nul ^| find "REG_SZ"') DO (
      set "ComEmuCommand=%%A"
    )
    if defined ComEmuCommand (
      call set "ComEmuCommand=%%ComEmuCommand:*REG_SZ    =%%"
      set MSYSCON=conemu.exe
    )
  )
)
if not defined ComEmuCommand exit /b 2
exit /b 0

:printhelp
echo Usage:
echo     %~1 [options] [bash parameters]
echo.
echo Options:
echo     -mingw32 ^| -mingw64 ^| -msys[2]   Set shell type
echo     -defterm ^| -mintty ^| -conemu ^| -consolez
echo                                      Set terminal type
echo     -here                            Use current directory as working
echo                                      directory
echo     -where DIRECTORY                 Use specified DIRECTORY as working
echo                                      directory
echo     -[use-]full-path                 Use full current PATH variable
echo                                      instead of triming to minimal
echo     -help ^| --help ^| -? ^| /?         Display this help and exit
echo.
echo Any parameter that cannot be treated as valid option and all
echo following parameters are passed as bash command parameters.
echo.
exit /b 0

rem check the native symlinks are working
rem after execution we have in variabled named %1:
rem       1 when native symlinks are working
rem       0 otherwise
:check_symlinks
call :mktemp fic1 .\msys2_fic1 .tmp rem
echo Some 1st content>"%fic1%"
call :mktemp fic2 .\msys2_fic2 .tmp rem
set LN_CMD=%WD%ln.exe
"%WD%bash" -c "'%LN_CMD:\=/%' -s '%fic1:\=/%' '%fic2:.\=%'"
echo Some 2nd content>>"%fic1%"
fc "%fic1%" "%fic2%" > NUL
if ERRORLEVEL 1 (set "%1=0") else set "%1=1"
del /q "%fic1%" "%fic2%"
goto :EOF

rem create a temporary file
rem %1 : var name to which output result (w/o double quotes)
rem %2 : file name prefix
rem %3 : file name suffix
rem %4 : optional, set to rem for not creating an empty file.
:mktemp
rem if the prefix contains \ then we don't create the file under %TEMP%
rem but under the specified directory
for /F "tokens=1,2 delims=\\" %%i in ("%~2") do (
if "x%%j"=="x" (set "mktemp_prefix=%TEMP%\%~2") else set "mktemp_prefix=%~2")
:mktemp_again
set "mktemp_filename=%mktemp_prefix%%RANDOM%%~3"
if EXIST "%mktemp_filename%" goto :mktemp_again
set "%1=%mktemp_filename%"
%4 type NUL > "%mktemp_filename%"
goto :EOF

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Msys2-users mailing list
Msys2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/msys2-users

Reply via email to