Skip to content

Instantly share code, notes, and snippets.

View grenade's full-sized avatar

rob thijssen grenade

View GitHub Profile
@grenade
grenade / import-ami.ps1
Last active January 12, 2021 02:16
import bb ami to tc
<powershell>
function Write-Log {
param (
[string] $message,
[string] $severity = 'INFO',
[string] $source = 'OpenCloudConfig',
[string] $logName = 'Application'
)
if (!([Diagnostics.EventLog]::Exists($logName)) -or !([Diagnostics.EventLog]::SourceExists($source))) {
New-EventLog -LogName $logName -Source $source
$www = 'c:\log'
$listener = New-Object Net.HttpListener
$listener.Prefixes.Add("http://+:8000/")
$listener.Start()
While ($listener.IsListening) {
$context = $listener.GetContext()
$response = $context.Response
if ($context.Request.RawUrl.length -gt 1) {

why occ?

i wanted a text-manifest driven solution to the problem of knowing what's on an instance and how it is configured. i especially didn't want the manifest to contain any programming language so that there are fewer barriers to understanding the instance state and so that the effects of applying the manifest are as transparent as can be.

why not puppet?

puppet ticks many of the boxes for the requirement but the showstopper was that a puppet agent does not exist on a vanilla ec2 instance. which means that something else has to install puppet and you end up needing 2 things to solve 1 problem.

why powershell?

ec2 only gives you 2 options for bootstrapping a windows instance. cmd and powershell. cmd doesn't have any way of downloading something from the internet (without first having some tool like wget pre-exist on the instance), powershell does. out of the box, powershell can do lots of things but the ability to download over http is the kicker.

why dsc?

# list bb spot instances:
for i in $(aws ec2 describe-instances --region us-east-1 --filter Name=tag-key,Values=Name "Name=tag-value,Values=b-2008-spot-*" --query 'Reservations[*].Instances[*].Tags[?Key==`Name`].Value' --output text); do echo $i; done
# rdp bb spot instances:
for name in $(aws ec2 describe-instances --region us-east-1 --filter Name=tag-key,Values=Name "Name=tag-value,Values=b-2008-spot-*" --query 'Reservations[*].Instances[*].Tags[?Key==`Name`].Value' --output text); do `rdp cltbld@$name &>/dev/null &`; done
# rdesktop tc instances
for ip in $(aws ec2 describe-instances --profile taskcluster --region us-west-2 --filters Name=tag-key,Values=WorkerType "Name=tag-value,Values=win2012" --query 'Reservations[*].Instances[*].PublicIpAddress' --output text); do `nohup rdesktop -u Administrator -p ******** -k en-gb -g 2400x1200 -a 16 -K -r clipboard:CLIPBOARD $ip &>/dev/null &`; done
@grenade
grenade / minion.cs
Created April 28, 2016 00:38
a firefox build minion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.DirectoryServices.AccountManagement;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.AccessControl;
using Newtonsoft.Json;
using System.Collections;
set GECKO_HEAD_REV=a14283391eab25c83976735e057728aeb6fb8457
set NO_CACHE=1
set MOZHARNESS_ACTIONS=get-secrets build check-test generate-build-stats update
set MACHTYPE=i686-pc-msys
set MAKE_MODE=unix
set MSYSTEM=MINGW32
set TOOLTOOL_CACHE=c:\home\worker\tooltool-cache
set UPLOAD_HOST=localhost
set UPLOAD_PATH=c:\home\worker\public\build
@grenade
grenade / Add-WindowTransparencyToProfile.ps1
Last active January 5, 2024 08:25
make powershell and cmd terminals transparent
if (-not Test-Path -Path $profile) { New-Item -path $profile -type file -force }
Add-Content -Path $profile -Value '$user32 = Add-Type -Name ''User32'' -Namespace ''Win32'' -PassThru -MemberDefinition ''[DllImport("user32.dll")]public static extern int GetWindowLong(IntPtr hWnd, int nIndex);[DllImport("user32.dll")]public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);[DllImport("user32.dll", SetLastError = true)]public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, int bAlpha, uint dwFlags);'''
Add-Content -Path $profile -Value 'Get-Process | Where-Object { @(''powershell'', ''cmd'') -contains $_.ProcessName } | % { $user32::SetWindowLong($_.MainWindowHandle, -20, ($user32::GetWindowLong($_.MainWindowHandle, -20) -bor 0x80000)) | Out-Null;$user32::SetLayeredWindowAttributes($_.MainWindowHandle, 0, 200, 0x02) | Out-Null }'

How to build firefox on Windows

@grenade
grenade / PowerShellLsaWrapper.cs
Last active November 28, 2019 08:46
Grant privileges needed by sshd user for key based auth and impersonation. See also: http://www.ehow.com/how_10069214_configure-sshd-cygwin.html, https://cygwin.com/ml/cygwin/2008-08/msg00155.html
using System;
using System.Collections.Generic;
using System.Text;
namespace PowerShellLsaWrapper {
using System.Runtime.InteropServices;
using System.Security;
using System.Management;
using System.Runtime.CompilerServices;
using System.ComponentModel;