Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch rewrite that works on windows 11 running wsl with Ubuntu 22 #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions wsl_gui_autoinstall.bat
Original file line number Diff line number Diff line change
@@ -1,51 +1,56 @@
@ECHO OFF

REM Set WSLENV for passing WINTMP to WSL
set WSLENV=%WSLENV%:WINTMP
set WINTMP=%TMP%
set LINUXTMP='$(wslpath -u \"$WINTMP\")'

REM Convert Windows temp path to WSL path
for /f "delims=" %%i in ('C:\Windows\System32\wsl.exe wslpath -u "%WINTMP%"') do set LINUXTMP=%%i

ECHO --- Running Linux installation. You will be prompted for your Ubuntu user's password:
REM One big long command to be absolutely sure we're not prompted for a password repeatedly

echo yes ^| add-apt-repository ppa:aseering/wsl-pulseaudio > "%TMP%\script.sh"
echo apt-get update >> "%TMP%\script.sh"
echo apt-get -y install pulseaudio unzip >> "%TMP%\script.sh"
echo sed -i 's/; default-server =/default-server = 127.0.0.1/' /etc/pulse/client.conf >> "%TMP%\script.sh"
echo sed -i "s$<listen>.*</listen>$<listen>tcp:host=localhost,port=0</listen>$" /etc/dbus-1/session.conf >> "%TMP%\script.sh"
C:\Windows\System32\bash.exe -c "chmod +x '%LINUXTMP%/script.sh' ; tr -d $'\r' < '%LINUXTMP%/script.sh' | tee '%LINUXTMP%/script_clean.sh'; sudo '%LINUXTMP%/script_clean.sh'"
REM Create the script in the Windows temp directory
echo yes ^| sudo add-apt-repository ppa:aseering/wsl-pulseaudio > "%TMP%\script.sh"
echo sudo apt-get update >> "%TMP%\script.sh"
echo sudo apt-get -y install pulseaudio unzip >> "%TMP%\script.sh"
echo sudo sed -i 's/; default-server =/default-server = 127.0.0.1/' /etc/pulse/client.conf >> "%TMP%\script.sh"
echo sudo sed -i "s^<listen>.*</listen>^<listen>tcp:host=localhost,port=0</listen>^" /etc/dbus-1/session.conf >> "%TMP%\script.sh"

REM Execute the script in WSL
C:\Windows\System32\wsl.exe -e bash -c "chmod +x '%LINUXTMP%/script.sh' ; tr -d '\r' < '%LINUXTMP%/script.sh' | tee '%LINUXTMP%/script_clean.sh'; sudo bash '%LINUXTMP%/script_clean.sh'"

ECHO --- Downloading required third-party packages
ECHO --- VcXsrv...
C:\Windows\System32\bash.exe -xc "wget -cO '%LINUXTMP%/vcxsrv.exe' 'http://downloads.sourceforge.net/project/vcxsrv/vcxsrv/1.18.3.0/vcxsrv-64.1.18.3.0.installer.exe'"
C:\Windows\System32\wsl.exe -e bash -xc "wget -O '%LINUXTMP%/vcxsrv.exe' 'http://downloads.sourceforge.net/project/vcxsrv/vcxsrv/1.18.3.0/vcxsrv-64.1.18.3.0.installer.exe'"

ECHO --- PulseAudio...
C:\Windows\System32\bash.exe -xc "wget -cO '%LINUXTMP%/pulseaudio.zip' 'http://bosmans.ch/pulseaudio/pulseaudio-1.1.zip'"
C:\Windows\System32\wsl.exe -e bash -xc "wget -O '%LINUXTMP%/pulseaudio.zip' 'http://bosmans.ch/pulseaudio/pulseaudio-1.1.zip'"

ECHO --- Installing packages

ECHO --- Adding link for X Server to Startup Items
powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Start Menu\Programs\Startup\VcXsrv.lnk');$s.TargetPath='%ProgramFiles%\VcXsrv\vcxsrv.exe';$s.Arguments=':0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl';$s.Save()"
powershell -Command "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Start Menu\Programs\Start-up\VcXsrv.lnk');$s.TargetPath='%ProgramFiles%\VcXsrv\vcxsrv.exe';$s.Arguments=':0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl';$s.Save()"

ECHO --- Launching X Server. DO NOT grant access to any network interfaces if prompted; they are unnecessary.
START "%userprofile%\Start Menu\Programs\Startup\VcXsrv.lnk"
START "" "%userprofile%\Start Menu\Programs\Start-up\VcXsrv.lnk"

ECHO --- Adding X environment variable to your .bashrc
C:\Windows\System32\bash.exe -xc "echo 'export DISPLAY=localhost:0' >> ~/.bashrc"
C:\Windows\System32\wsl.exe -e bash -xc "echo 'export DISPLAY=localhost:0' >> ~/.bashrc"

ECHO --- Extracting PulseAudio
md "%TMP%\pulseaudio"
C:\Windows\System32\bash.exe -xc "unzip -o '%LINUXTMP%/pulseaudio.zip' -d '%LINUXTMP%/pulseaudio'"
C:\Windows\System32\wsl.exe -e bash -xc "unzip -o '%LINUXTMP%/pulseaudio.zip' -d '%LINUXTMP%/pulseaudio'"

ECHO --- Installing PulseAudio
xcopy /e "%TMP%\pulseaudio" "%AppData%\PulseAudio"

ECHO --- Setting PulseAudio to run at startup
echo set ws=wscript.createobject("wscript.shell") > "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\start_pulseaudio.vbe"
echo ws.run "%AppData%\PulseAudio\bin\pulseaudio.exe --exit-idle-time=-1",0 >> "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\start_pulseaudio.vbe"
echo set ws=wscript.createobject("wscript.shell") > "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\start_pulseaudio.vbe"
echo ws.run "%AppData%\PulseAudio\bin\pulseaudio.exe --exit-idle-time=-1",0 >> "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\start_pulseaudio.vbe"

REM Recomended/required settings
REM Recommended/required settings
echo load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1 >> "%AppData%\PulseAudio\etc\pulse\default.pa"
"%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\start_pulseaudio.vbe"
"%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\start_pulseaudio.vbe"
ECHO When prompted, DO NOT allow 'pulseaudio' access to any of your networks. It doesn't need access.

ECHO All Done
Expand Down