Created
December 15, 2020 20:24
-
-
Save Schokokex/d88d515a238fe6eae8a66601b64404d0 to your computer and use it in GitHub Desktop.
wsl2.centos8.install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;@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