Skip to content

Instantly share code, notes, and snippets.

@Schokokex
Created December 15, 2020 20:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Schokokex/d88d515a238fe6eae8a66601b64404d0 to your computer and use it in GitHub Desktop.
Save Schokokex/d88d515a238fe6eae8a66601b64404d0 to your computer and use it in GitHub Desktop.
wsl2.centos8.install
;@Findstr -bv ;@F "%~f0" | powershell -command - & powershell -NoLogo & goto:eof
$osName='CentOS8'
$appdir = "$env:LOCALAPPDATA\$osName"
$downloadCent8 = $true # contains launcher and rootfs.tar.gz
$downloadLauncher = $false # in case downloadCent8 = $false
$rootFsFile = "rootfs.tar.gz"
$cent8Url = "https://github.com/yuk7/CentWSL/releases/download/8.1.1911.1/CentOS8.zip"
$launcherUrl = "https://github.com/yuk7/wsldl/releases/download/20100500/Launcher.exe"
mkdir $appdir >$null 2>$null
$exeName = "$appdir\$osName.exe"
rm -Force $exeName, $appdir\$rootFsFile 2> $null
if (!$downloadCent8) {
cp $rootFsFile $appdir
if (!$?) {exit}
}
cd $appdir
if ($downloadCent8){
rm rootfs.tar.gz 2> $null
curl -o CentOS8.zip $cent8Url
Expand-Archive -Force CentOS8.zip .
rm CentOS8.zip
mv CentOS8.exe $exeName
[System.IO.File]::WriteAllLines("$appdir\centos.cmd", "@echo off`nIF %0 == `"%~dpnx0`" (start $osName.exe %*) ELSE ($osName.exe %*)", (New-Object System.Text.UTF8Encoding))
} elseif ($downloadLauncher){
curl -o $exeName $launcherUrl
}
powershell "$exeName install"
[Environment]::SetEnvironmentVariable("Path", [System.Environment]::GetEnvironmentVariable("Path", "User") +"; "+$appdir, "User")
echo "start distro:`n`n $osName.exe`n`n"
echo "change root password:`n`n yum install -y -q passwd; passwd`n`n"
echo "create nonroot user:`n`n useradd -m -g wheel -s /bin/bash $env:UserName`n $osName.exe config --default-user $env:UserName`n`n"
echo "install docker:`n`n yum install -y -q podman-docker which; chmod u+s `$(which newuidmap); chmod u+s `$(which newgidmap); echo done`n`n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment