diff --git a/README.md b/README.md index 89694ee..51ea2af 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ $ curl -O https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Fedora To bootstrap a Windows instance: ```console -$ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.cmd %cd%\bootstrap-Windows.cmd & %cd%\bootstrap-Windows.cmd +$ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.ps1')) ``` ## Package diff --git a/bootstrap-Windows.cmd b/bootstrap-Windows.cmd deleted file mode 100644 index 9b6bc47..0000000 --- a/bootstrap-Windows.cmd +++ /dev/null @@ -1,193 +0,0 @@ -@echo off -setlocal - -if [%1]==[/?] goto :help -echo %* | find "/?" > nul -if errorlevel 1 goto :main - -:help -echo usage: %0 [/?] -echo -echo Bootstrap a macOS instance with: -echo -echo * Windows SDK - from MSDN -echo * Chocolatey - package manager -echo * Cmder, including Git - from Chocolatey -echo * Python - from Chocolatey -echo * virtualenv - from pip -echo * SSH key - from ssh-keygen -echo * GitHub public key - with SSH key -echo * GitLab public key - with SSH key -echo * BitBucket Cloud public key - with SSH key -echo * Gogs Cloud public key - with SSH key -echo * conduit - configuration manager -echo -echo optional arguments: -echo /? show this help message and exit -goto end - -:main - -:: Check for admin permissions ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" -if errorlevel 1 ( - echo Administrator privilages required! - exit /B 1 -) - -:: Install Windows SDK -:windows_sdk -set choice= -set /p choice="Install Windows SDK [Y/n]? " -if "%choice%"=="" goto windows_sdk_yes -if "%choice%"=="Y" goto windows_sdk_yes -if "%choice%"=="y" goto windows_sdk_yes -if "%choice%"=="N" goto windows_sdk_no -if "%choice%"=="n" goto windows_sdk_no -echo invalid value: %choice% -goto windows_sdk -:windows_sdk_yes -bitsadmin.exe /transfer "Download Windows SDK" https://go.microsoft.com/fwlink/p/?linkid=845298 %~dp0\winsdksetup.exe -if errorlevel 1 exit /B 1 -echo Installing Windows SDK... -%~dp0\winsdksetup.exe /features + /q -if errorlevel 1 exit /B 1 -del %~dp0\winsdksetup.exe -:windows_sdk_no - -:: Install Chocolatey -:choco -set choice= -set /p choice="Install Chocolatey [Y/n]? " -if "%choice%"=="" goto choco_yes -if "%choice%"=="Y" goto choco_yes -if "%choice%"=="y" goto choco_yes -if "%choice%"=="N" goto choco_no -if "%choice%"=="n" goto choco_no -echo invalid value: %choice% -goto choco -:choco_yes -@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" -if errorlevel 1 exit /B 1 -:choco_no - -:: Install Cmder, including Git -:git -set choice= -set /p choice="Install Cmder, including Git [Y/n]? " -if "%choice%"=="" goto git_yes -if "%choice%"=="Y" goto git_yes -if "%choice%"=="y" goto git_yes -if "%choice%"=="N" goto git_no -if "%choice%"=="n" goto git_no -echo invalid value: %choice% -goto git -:git_yes -choco install cmder --yes -if errorlevel 1 exit /B 1 -:git_no - -:: Install Python -:python -set choice= -set /p choice="Install Python [Y/n]? " -if "%choice%"=="" goto python_yes -if "%choice%"=="Y" goto python_yes -if "%choice%"=="y" goto python_yes -if "%choice%"=="N" goto python_no -if "%choice%"=="n" goto python_no -echo invalid value: %choice% -goto python -:python_yes -choco install python2 --yes -if errorlevel 1 exit /B 1 -:python_no - -:: Install virtualenv -:virtualenv -set choice= -set /p choice="Install virtualenv [Y/n]? " -if "%choice%"=="" goto virtualenv_yes -if "%choice%"=="Y" goto virtualenv_yes -if "%choice%"=="y" goto virtualenv_yes -if "%choice%"=="N" goto virtualenv_no -if "%choice%"=="n" goto virtualenv_no -echo invalid value: %choice% -goto virtualenv -:virtualenv_yes -"C:\Python27\Scripts\pip.exe" install virtualenv -if errorlevel 1 exit /B 1 -:virtualenv_no - -:: Generate SSH key -:ssh_key -set choice= -set /p choice="Generate SSH key [Y/n]? " -if "%choice%"=="" goto ssh_key_yes -if "%choice%"=="Y" goto ssh_key_yes -if "%choice%"=="y" goto ssh_key_yes -if "%choice%"=="N" goto ssh_key_no -if "%choice%"=="n" goto ssh_key_no -echo invalid value: %choice% -goto ssh_key -:ssh_key_yes -mkdir %USERPROFILE%\.ssh -set /P email="SSH email: " -"C:\tools\cmder\vendor\git-for-windows\usr\bin\ssh-keygen.exe" -t rsa -b 4096 -C "%email%" -N "" -f %USERPROFILE%\.ssh\id_rsa -if errorlevel 1 exit /B 1 -:ssh_key_no - -:: Set SSH keys on remote Git servers -:remote_ssh_keys -:: Add git to the PATH to pip can find it -set PATH=C:\tools\cmder\vendor\git-for-windows\bin;%PATH% -set choice= -set /p choice="Set SSH keys on remote Git servers [Y/n]? " -if "%choice%"=="" goto remote_ssh_keys_yes -if "%choice%"=="Y" goto remote_ssh_keys_yes -if "%choice%"=="y" goto remote_ssh_keys_yes -if "%choice%"=="N" goto remote_ssh_keys_no -if "%choice%"=="n" goto remote_ssh_keys_no -echo invalid value: %choice% -goto remote_ssh_keys -:remote_ssh_keys_yes -"C:\Python27\Scripts\virtualenv.exe" %~dp0\bootstrap_env -if errorlevel 1 exit /B 1 -"%~dp0\bootstrap_env\Scripts\pip.exe" install git+https://code.infektor.net/config/bootstrap.git -if errorlevel 1 exit /B 1 -"%~dp0\bootstrap_env\Scripts\python.exe" -c "import bootstrap; bootstrap.set_ssh_keys()" -if errorlevel 1 exit /B 1 -:remote_ssh_keys_no - -:: Install conduit -:conduit -set choice= -set /p choice="Install conduit [Y/n]? " -if "%choice%"=="" goto conduit_yes -if "%choice%"=="Y" goto conduit_yes -if "%choice%"=="y" goto conduit_yes -if "%choice%"=="N" goto conduit_no -if "%choice%"=="n" goto conduit_no -echo invalid value: %choice% -goto conduit -:conduit_yes -"C:\Python27\Scripts\pip.exe" install git+ssh://git@github.com/kbenzie/conduit.git -rmdir /Q /S "%~dp0\bootstrap_env" -:conduit_no - -:remove_bootstrap -set choice= -set /p choice="Remove bootstrap-Windows.cmd [y/N]? " -if "%choice%"=="" goto remove_bootstrap_no -if "%choice%"=="Y" goto remove_bootstrap_yes -if "%choice%"=="y" goto remove_bootstrap_yes -if "%choice%"=="N" goto remove_bootstrap_no -if "%choice%"=="n" goto remove_bootstrap_no -echo invalid value: %choice% -goto remove_bootstrap -:remove_bootstrap_yes -start /b "" cmd /c del "%~f0"&exit /b -:remove_bootstrap_no - -:end -endlocal diff --git a/bootstrap-Windows.ps1 b/bootstrap-Windows.ps1 new file mode 100644 index 0000000..f9f71a9 --- /dev/null +++ b/bootstrap-Windows.ps1 @@ -0,0 +1,23 @@ +# Install Chocolatey +Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + +# Enable Hyper-V and containters +Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All +Enable-WindowsOptionalFeature -Online -FeatureName Containers -All + +# Install OpenSSH and start service +choco install "--package-parameters=/SSHServerFeature" openssh +Start-Service sshd +Set-Service -Name sshd -StartupType 'Automatic' + +# generate keys and authorize them +# TODO: Ask for email address to use, make sshKeyType optional +$sshKeyType = "ed25519" +ssh-keygen -t "$sshKeyType" -C "benie@infektor.net" -N '' -f "$env:USERPROFILE/.ssh/$sshKeyType" +# TODO: authorize public key for admin + +# Install Windows-Terminal and Debian +choco install microsoft-windows-terminal +wsl --install --distribution Debia + +Restart-Computer diff --git a/bootstrap-Windows.sh b/bootstrap-Windows.sh new file mode 100755 index 0000000..ea4c140 --- /dev/null +++ b/bootstrap-Windows.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Copy SSH keys from Windows host. +cp -r /mnt/c/Users/Benie/.ssh ~/.ssh +chown benie:benie ~/.ssh +for file in ~/.ssh/*; do + chmod 0600 $file +done + +# Upgrade Debian to unstable +sudo apt-get update +sudo apt-get upgrade --yes + +sudo sed 's/stretch/buster/g' -i /etc/apt/sources.list +sudo apt-get update +sudo apt-get full-upgrade --yes + +sudo sed 's/buster/bullseye/g' -i /etc/apt/sources.list +sudo apt-get update +sudo apt-get full-upgrade --yes + +sudo sed 's/bullseye/unstable/g' -i /etc/apt/sources.list +sudo apt-get update +sudo apt-get full-upgrade --yes + +# Install ansible +sudo apt-get install ansible git python3-apt python3-pip