Skip to content

Commit

Permalink
Initial dump of my custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed Oct 3, 2011
0 parents commit 1677b5a
Show file tree
Hide file tree
Showing 31 changed files with 3,223 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ac_add_override.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/perl -p -i

# copyright (c) Benjamin Mako Hill <[email protected]>
# This software comes with ABSOLUTELY NO WARRANTY.
# This is free software and is licensed under the GNU GPL.

if (not $edited and m/^\s*\n$/) {
s/^\s*\n$/X-AttachCheck-Override: Yes\n\n/;
$edited = 1;
}
127 changes: 127 additions & 0 deletions attachcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python

# AttachCheck -- A MTA wrapper to help check outgoing email for
# forgotten attachments.

# (c) 2005 -- Benjamin Mako Hill <[email protected]>
# Author/Software Homepage at: http://mako.cc

# This software comes with ABSOLUTELY NO WARRANTY.
# This is free software and is licensed under the GNU GPL.

__copyright__ = "Copyright (c) 2004 Benjamin Mako Hill"
__author__ = "Benjamin Mako Hill <[email protected]>"

### Configuration Options
###########################################

# location of the sendmail binary
sendmail = "/usr/local/bin/hashcash-sendmail"

# list of mimetype which are, for the sake of this program, not
# attachments
ignored_types = ( "applica/pgp-signat", "application/pgp-signature" )

# list of regular expressions which we will view as being indicative
# of an attachment
attachment_regexes = [ r'\battach(ed|ment|ing)?\b(?im)' ]


### No Edit Below This Line
###########################################

import sys
import os
import email
import re

## SUB: send message
def send_message():
mailpipe = os.popen("%s" % sendmail, 'w')
mailpipe.write( message_string )
sys.exit( mailpipe.close() )

## SUB: print error message
def print_error():
print >>sys.stderr, \
"""(Your message mentions attachments but does not include any.
Either:
(1) Add an attachment or add \"CONFIRM\" (in ALLCAPS to beginning of
the subject of the message and resend. \"CONFIRM\" will be
stripped from your message subject befor the message is sent.
(2) Add a \"X-AttachCheck-Override: Yes\" header the message.
Read the documentation for AttachCheck for more details."""

# get the mail from stdin
message_string = sys.stdin.read()
message = email.message_from_string( message_string )

attachment_expected = False
attachment_seen = False
text_seen = False

for part in message.walk():

# check to see if this part is a plain text entry
if part.get_content_type() == "text/plain":

# if this is the second text block, we should interrate
# through things
if text_seen:
attachment_seen = True
# otherwise, mark that we've now seen one text field
else:
text_seen = True

# search for the word "attach" or "attached" or "attachment"
# in the body of the message
for regex in attachment_regexes:

if re.search( regex, part.get_payload() ):
attachment_expected = True

# check to see if this mime-type is something we can ignore
elif ( re.match( r'message/(?m)', part.get_content_type() ) or
re.match( r'multipart/(?m)', part.get_content_type() ) or
part.get_content_type() in ignored_types ):
continue

# if it's not text and it's an ignored type, it's a seen attachment
else:
attachment_seen = True

# now check to see if we are expecting an attachment
if attachment_expected:

# if we are expecting an attachment and we've seen one, we should
# send the file and be done with things
if attachment_seen:
send_message()

# if we are expected have not seen it, we need to check to see if
# the mail has been confirmed

else:
# check for the confirmation

if re.search( r'Subject: CONFIRM', message_string ):
message_string = re.sub( r'(Subject: )(CONFIRM )(.*?)\n',
r'\1\3\n', message_string )
send_message()

elif message.get( 'X-AttachCheck-Override' ) == "Yes":
send_message()

else:
print_error()
sys.exit( 1 )


# if we are not expecting anything more, we should send the message
else:
send_message()
37 changes: 37 additions & 0 deletions compile_kernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# Used to compile a custom vanilla kernel into a Debian package
#

if [ ! -r .config ] ; then
echo "You must be in the source directory of a configured kernel."
exit 1
fi

VERSION=`git log --oneline | head | cut -d' ' -f2,3 | grep "^Linux" | head -1 | cut -d' ' -f2`

if [ "z$VERSION" = "z" ] ; then
echo "Could not extract kernel version from the git log."
exit 2;
fi

# Set the number of parallel runs of gcc
export CONCURRENCY_LEVEL=$1
if [ "z$1" = "z" ] ; then
export CONCURRENCY_LEVEL=3
fi

# Prime sudo for later
sudo -v

# Compile the kernel into a Debian package
sudo ionice -c3 fakeroot make-kpkg clean
nice eatmydata fakeroot make-kpkg --revision=1.0+custom kernel_image &
BACKGROUND_BUILD=$!
sudo ionice -c3 -p $BACKGROUND_BUILD
wait $BACKGROUND_BUILD || exit 1

# Install the package
sudo mount -o remount,exec /dev/mapper/ctmp
sudo dpkg -i ../linux-image-$VERSION-grsec+_1.0+custom_*.deb
sudo mount -o remount /dev/mapper/ctmp
15 changes: 15 additions & 0 deletions daap-download
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# Script used to download files from iTunes share

SECTION=$1
FILE=$2

if [ -z "$SECTION" -o -z "$FILE" ] ; then
echo "Usage: `basename $0` <section> <filename>"
echo
echo "e.g. `basename $0` 1 15404.mp3"
exit 1
fi

curl http://192.168.254.2:3689/databases/$SECTION/items/$FILE > $FILE
22 changes: 22 additions & 0 deletions debian-release-hints
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#
# Download the latest hint files for the upcoming Debian release

OUTFILE='debian-release.hints'
TMPFILE="`mktemp`"
touch $TMPFILE

for f in aba adeodato he joeyh luk madcoder neilm pkem rmurray vorlon zobel freeze freeze-exception ftpteam
do
curl --silent --show-error --compressed http://release.debian.org/testing/hints/$f >> $TMPFILE
done

if [ ! -e $OUTFILE ]
then
mv $TMPFILE $OUTFILE
exit 0
else
echo "$OUTFILE already exists."
echo "Look in $TMPFILE for the latest hints."
exit 1
fi
44 changes: 44 additions & 0 deletions debian-security-filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/perl

$headers_read = 0; # are we done reading the headers?
$buffer = 0; # should we keep on buffering everything ?
$msg = '';
while (<>) {
if (/^\s*$/ and !$headers_read) {
$buffer = 1;
$headers_read = 1;
} elsif (/^Package\s*:\s+([\w\-]+(,\s*[\w\-]+)*)\s*$/) {
@packages = split /,/, $1;

@package_versions = ();
foreach $package_name (@packages) {
$package_name =~ s/\s*([^\s]*)\s*/$1/g;

$dpkg_status = `dpkg -s $package_name 2> /dev/null`;
$installed_version = "none";
if ($dpkg_status =~ /^Version: ([^\s\n]+)$/m) {
$installed_version = $1;
}

if (@packages > 1) {
push @package_versions, "$package_name = $installed_version";
} else {
push @package_versions, "$installed_version";
}
}

$version_string = join ", ", @package_versions;
print "X-Installed-Version: $version_string\n";
print $msg;
$msg = '';
$buffer = 0;
}

if ($buffer) {
$msg .= $_;
} else {
print;
}
}

print $msg; # flush buffer
Loading

0 comments on commit 1677b5a

Please sign in to comment.