Skip to content

Instantly share code, notes, and snippets.

View pmbuko's full-sized avatar
💁‍♂️
captive devopsian

Peter Bukowinski pmbuko

💁‍♂️
captive devopsian
View GitHub Profile
@pmbuko
pmbuko / python_line_matcher.py
Last active August 29, 2015 13:58
This is a python example for an easy way to search file lines for lines matching a specific regex. You need to pass the filename to search as the first argument.
#!/usr/bin/env python
import sys, re
# get first command line argument as filename
input_file = sys.argv[1]
# suck in file contents
with open(input_file) as f:
content = f.readlines()
display dialog "Please enter the account to give administrator privileges." default answer ""
set username to text returned of result
try
do shell script "/usr/sbin/dseditgroup -o edit -a 'DOMAIN\\" & username & "' -t user admin" with administrator privileges
set question to display dialog "Successfully granted administrator privileges to " & username & "." buttons {"Quit"} default button 1
set answer to button returned of question
if answer is equal to "Quit" then
return
end if
on error
@pmbuko
pmbuko / character_test.applescript
Created September 16, 2014 13:20
Applescript apparently can't handle certain diacritics (those requiring multiple keystrokes) when using a hidden answer dialog prompt. You can use this simple test script to verify. If you remove "with hidden answer" from line 1, it will work as expected.
set testPass to text returned of (display dialog "Enter a test password:" default answer "" with hidden answer)
do shell script "/bin/echo '" & testPass & "' > /var/tmp/pass_file"
set echoedPass to (do shell script "/bin/cat /var/tmp/pass_file")
display dialog "This is what you typed:
" & testPass & "
This is what AppleScript echoed to a temp file:
" & echoedPass
@pmbuko
pmbuko / bad_puppet.pp
Created September 26, 2014 13:52
The worst example of puppet code I've seen in a long time, lifted from a blog commenter who suggested using this to patch bash.
exec { 'patch_shellshock_security_hole':
command => "/usr/bin/yes | /usr/bin/yum update bash; touch /root/shellshock_bug_has_been_patched",
creates => '/root/shellshock_bug_has_been_patched',
}
@pmbuko
pmbuko / os_decider.sh
Last active August 29, 2015 14:09
Script template that will do different things for bootable Mac and Windows volumes
#!/bin/bash
for vol in /Volumes/*; do
if [ -e "${vol}/System/Library/CoreServices/boot.efi" ]; then
echo "Partition info for Mac bootable volume:"
diskutil list "${vol}"
# more stuff here
elif [ -e "${vol}/Windows/System32/winload.exe" ]; then
echo "Partition info for Win bootable volume:"
diskutil list "${vol}"
@pmbuko
pmbuko / scratchdir_type.pp
Last active August 29, 2015 14:10
I use this defined resource type mostly as a space-saver. We have a few hundred HPC cluster nodes and each of the ~300 cluster users has their own scratch directory on each node. When a cluster user is added or removed, it triggers a script that programmatically generates an updated puppet manifest that manages these directories.
class cluster::scratchroot {
file { '/scratch':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
}
define cluster::scratchdir( $u, $g, $m ) {
@pmbuko
pmbuko / hdfsstruct.pp
Created November 25, 2014 17:49
I use this defined resource type set up HDFS volumes on servers that are part of our Hadoop system.
define hdfsstruct ($mountpoint = $name, $device) {
file { "$mountpoint":
ensure => directory,
}
exec { "format-$device":
command => "/sbin/mkfs.ext4 $device",
unless => "/bin/mount | /bin/grep $device",
refreshonly => true,
}
mount { $mountpoint:
@pmbuko
pmbuko / kerberos_id.sh
Created December 3, 2014 17:55
This snippet will retrieve the fully-qualified Kerberos authentication account used for retrieving tickets on OS X. Useful if you need to renew tickets programmatically.
dscl /Search read /Users/$USER AuthenticationAuthority | egrep -o "[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)"
@pmbuko
pmbuko / tkinter_password.py
Last active August 29, 2015 14:10
Here's a tkinter password prompt that kinda works on OS X.
#!/usr/bin/pythonw
from Tkinter import Tk
from tkSimpleDialog import askstring
def passPrompt(title, prompt):
"""Prompts for a password."""
password = askstring(title, prompt, show="*")
print "Seriously? '" + password + "'?? That's a lame password."
@pmbuko
pmbuko / password_dialog.py
Last active August 29, 2015 14:11
Simple python example of a Pashua password prompt dialog with a checkbox to save the password. Requires Pashua.app and the Pashua.py connector in the same path.
#!/usr/bin/python
#
# Simple python example of a Pashua password prompt window with a checkbox
# for saving the password to the keychain. None of it is wired up to
# actually function. It's just an example of what you can do.
#
# For easiest testing, you should have the Pashua.py connector and Pashua.app
# in the same directory as this script.
#
# The test password is 'password'.