Last active 1619348060

A windows startup cmd script, and bash script to execute it on vultr. installs all the things i think are useful to have on a new windows server

vultrwin.sh Raw
1#!/bin/bash
2domain="alyssasmith.id.au"
3if [ -z "$1" ]; then
4 region="syd"
5else
6 region="$1"
7fi
8if [ -z "$2" ]; then
9 size="vc2-4c-8gb"
10else
11 size="$2"
12fi
13echo "please don't run this script without reading it first"
14exit
15if (vultr-cli regions availability $region | grep $size); then
16 python -c "from datetime import datetime, timedelta; print('est time of completion: {} (9 minutes)'.format(datetime.now()+timedelta(minutes=9)))"
17 read ID <<<$((set -x; vultr-cli instance create --label "${region}w" --host "$region.w.$domain" --firewall-group a4496c76-4a45-4051-a923-3d2d08159dcc --script-id 03c1ae6a-59f6-4190-a8a1-af9f1e23c1f0 --region "$region" --os 371 --plan "$size") | egrep '^ID\t' | awk '{print $2}')
18 echo https://my.vultr.com/subs/vps/novnc/?id=$ID
19 echo -n Waiting for IP
20 until vultr-cli instance list | grep "${region}w" | awk '{print $2}' | grep -v "0.0.0.0" >/dev/null; do
21 echo -n "."
22 sleep 1;
23 done
24 read IP <<<$(vultr-cli instance list | grep "${region}w" | awk '{print $2}')
25 read DOID <<<$(doctl compute domain records list $domain | grep $region.w | awk '{print $1}')
26 if [ -z "$DOID" ]; then
27 (set -x; doctl compute domain records create $domain --record-name $region.w --record-type A --record-data $IP)
28 else
29 (set -x; doctl compute domain records update $domain --record-id $DOID --record-name $region.w --record-type A --record-data $IP)
30 fi
31 echo Waiting for ssh
32 until ssh -o StrictHostKeyChecking=no administrator@$IP; do
33 sleep 1
34 done
35 if read -p "Delete instance?" a; then
36 (set -x; vultr-cli instance delete $ID)
37 fi
38else
39 echo "$size not available in $region"
40fi
windows-init.cmd Raw
1rem replace all instances of alyssasmith.id.au with your own values, as well as the url for authorized keys
2
3powershell -Command "iwr https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x64.msi -OutFile c:\powershell.msi"
4msiexec /i c:\powershell.msi /quiet
5
6"C:\Program Files\PowerShell\7\pwsh" -Command "Invoke-WebRequest https://swupdate.openvpn.org/community/releases/openvpn-install-2.4.11-I601-Win10.exe -OutFile c:\openvpn-setup.exe"
7c:\openvpn-setup.exe /S
8"C:\Program Files\PowerShell\7\pwsh" -Command "set-service -name OpenVPNService -StartupType Automatic"
9netsh advfirewall firewall add rule name="3389" dir=in action=allow protocol=tcp localport=3389
10
11"C:\Program Files\PowerShell\7\pwsh" -Command "Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0"
12"C:\Program Files\PowerShell\7\pwsh" -Command "New-ItemProperty -Path 'HKLM:\SOFTWARE\OpenSSH' -Name DefaultShell -Value 'C:\Program Files\PowerShell\7\pwsh.exe' -PropertyType String -Force"
13netsh advfirewall firewall add rule name="22" dir=in action=allow protocol=tcp localport=22
14"C:\Program Files\PowerShell\7\pwsh" -Command "iwr example.com -OutFile c:\programdata\ssh\administrators_authorized_keys"
15"C:\Program Files\PowerShell\7\pwsh" -Command "$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys; $acl.SetAccessRuleProtection($true, $false); $administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule('Administrators','FullControl','Allow'); $systemRule = New-Object system.security.accesscontrol.filesystemaccessrule('SYSTEM','FullControl','Allow'); $acl.SetAccessRule($administratorsRule); $acl.SetAccessRule($systemRule); $acl | Set-Acl"
16"C:\Program Files\PowerShell\7\pwsh" -Command "set-service -name sshd -StartupType Automatic"
17
18"C:\Program Files\PowerShell\7\pwsh" -Command "iwr -useb get.scoop.sh | iex; scoop install git; scoop update; scoop bucket add extras; scoop install chromium rclone"
19
20"C:\Program Files\PowerShell\7\pwsh" -Command "$_host = ((iwr http://169.254.169.254/v1/hostname).Content -replace '.w.alyssasmith.id.au$'); rename-computer -newname $_host"