Micha Niskin

May 30, 07:49 AM
Category  

Here is a shellscript I wrote to handle my master password file. It uses PGP for encryption.

Features:

  • You can use it just like you would use vipw(8) or visudo(8).
  • The data is never on the disk in an unencrypted state. There are no temporary files or anything like that containing plaintext.
  • Can (optionally) make full use of RCS(1) for version control.

You can download the script here.

Comment

Alan Dipert

May 25, 10:00 AM
Category  

Here’s a one-liner using tr, sort, and uniq, adapted from something I found in the book Literate Programming by Donald Knuth.

It’s awesome.

#!/bin/bash
tr -cs [:alpha:] \\n < $1 | \
sort | uniq -c | sort -r -k 1

Let’s take it for a spin:

giggles:/usr/local/bin alan$ ./wordfreq.sh\
 wordfreq.sh | head -n 3
   2 sort
   1 uniq
   1 tr

Comment

Alan Dipert

May 25, 09:51 AM
Category  

I’ve got a directory on my computer with lots of toy projects, many of which have Makefiles and build.xml files.

Every now and then I back up this directory, and to save space and time I decided I should probably figure out a way to ‘make clean’ on all of them before making a big tarball of source, object files, and executables.

I didn’t feel like handcoding a “meta Makefile” with a “make clean” directive for each subdirectory, so I pooped out cleanall.sh:

#!/bin/bash
# cleanall.sh - executes 'make clean' in subdirectories with Makefiles
MYDIR=`pwd`
for DIR in `find . -name Makefile -maxdepth 2 -exec dirname {} ';'`; do
	echo Cleaning $DIR...
	cd $DIR; make clean
	cd $MYDIR
done
MYDIR=`pwd`

save the current directory in MYDIR.

for DIR in `find . -name Makefile -maxdepth 2 
-exec dirname {} ';'`; do

execute find(1) starting in the current directory looking for files named Makefile and going no more than 2 directories deep. Execute dirname(1) on what’s found, and store the result in DIR.

cd $DIR; make clean

move into the Makefile’s directory and execute ‘make clean.’

cd $MYDIR

go back to the starting directory

This tiny script is a good example of how awesome find -exec is, and is a good starting point for doing lots of different things on files you dig up using find(1).

Comment [1]

Micha Niskin

Apr 16, 03:53 PM
Category  

If you are in the army and you use the Army Knowlege Online webmail, and you want to use fetchmail to automatically download it from IMAP, then this is what you want to do:

1. Create a directory to hold the AKO SSL certificate:

mkdir ~/.certs

2. Download the certificate:

openssl s_client -connect imap.us.army.mil:993 \
    |perl -ne '{print; /-END CERTIFICATE-/ && exit}' \
    |sed -ne '/-BEGIN CERTIFICATE-/,$p' \
    > ~/.certs/imap.us.army.mil.pem

The cert file (~/.certs/imap.us.army.mil.pem) should look something like this:

-----BEGIN CERTIFICATE-----
MIIEDDCCA3WgAwIBAgIDAiuQMA0GCSqGSIb3DQEBBQUAMF4xCzAJBgNVBAYTAlVT
MRgwFgYDVQQKEw9VLlMuIEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UE
CxMDUEtJMRkwFwYDVQQDExBET0QgQ0xBU1MgMyBDQS03MB4XDTA1MDcyNjE1MjQx
M1oXDTA4MDcyNjE1MjQxM1owgZgxCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9VLlMu
IEdvdmVybm1lbnQxDDAKBgNVBAsTA1BLSTEMMAoGA1UECxMDRG9EMQwwCgYDVQQL
EwNVU0ExGTAXBgNVBAMTEGltYXAudXMuYXJteS5taWwxKjAoBgkqhkiG9w0BCQEW
G3JheW1vbmQud2lsc29uMkB1cy5hcm15Lm1pbDCBnzANBgkqhkiG9w0BAQEFAAOB
jQAwgYkCgYEA7vZE/HJD1x0E3Sk09DDZwAmGmzAo+ZUdMFGKYYI+cM+JYp6nIYIW
Y0DHSQqLEsWMgYS4VkoQgT98UNX8yrvUZB61JUTTgZyMuqxKrEzESZKilhsl2Tf4
+193c2enhOymKGV7HPdNT9Witre7G8N+ZPPk4EOjryuszOnefdJ3FmECAwEAAaOC
AZswggGXMB8GA1UdIwQYMBaAFALFH0MRc2AyNz7mR4Yp3iG2cmYjMB0GA1UdDgQW
BBQQ1f8KwwPnkxN0DK5stJnQOQa5szAOBgNVHQ8BAf8EBAMCBaAwgawGA1UdHwSB
pDCBoTCBnqCBm6CBmIaBlSBsZGFwOi8vZHMtMy5jM3BraS5jaGFtYi5kaXNhLm1p
bC9jbiUzZERPRCUyMENMQVNTJTIwMyUyMENBLTclMmNvdSUzZFBLSSUyY291JTNk
RG9EJTJjbyUzZFUuUy4lMjBHb3Zlcm5tZW50JTJjYyUzZFVTP2NlcnRpZmljYXRl
cmV2b2NhdGlvbmxpc3Q7YmluYXJ5MBYGA1UdIAQPMA0wCwYJYIZIAWUCAQsFMH4G
A1UdEgR3MHWGc2xkYXA6Ly9kcy0zLmMzcGtpLmNoYW1iLmRpc2EubWlsL2NuJTNk
RE9EJTIwQ0xBU1MlMjAzJTIwQ0EtNyUyY291JTNkUEtJJTJjb3UlM2REb0QlMmNv
JTNkVS5TLiUyMEdvdmVybm1lbnQlMmNjJTNkVVMwDQYJKoZIhvcNAQEFBQADgYEA
haIiC/Adgm3gmL822RqvsJX4VGP0eX4MPKRdrzXh13eXavzwvVhwZjU7qZo7t6gC
NVaHCltTK5g1+zF0Nkhn+Coa70uJumYV1ay0KxP8PeiVWz6hz6URnZz3hGBKymse
SCR7iENgK+lqE2Bm4YYPimOKl+zTGVr7rX2esXyepvQ=
-----END CERTIFICATE-----

3. Edit your fetchmail configuration file (~/.fetchmailrc) to look something like this (for the fictional user ‘beetle.s.bailey@us.army.mil’ with password ‘sargesux’):

poll imap.us.army.mil
  port            993
  protocol        imap
  username        "beetle.s.bailey"
  password        "sargesux"
  sslfingerprint  "4C:64:D0:DD:DC:90:E6:93:E4:79:65:75:B6:4B:DB:E5"
  sslcertpath     "$HOME/.certs"
  mda             procmail
  keep
  ssl

The sslfingerprint option allows you to manually verify the authenticity of the SSL cert. You need to do this because AKO uses government self-signed certificates. As a workaround you can get the fingerprint using fetchmail with the -v option.

Be aware that this is a potential security issue if there is a “man in the middle” pretending to be the AKO imap server. Such an evesdropper could then set up an IMAP server to collect your login and password info. A sophisticated attacker could even relay your connection to the real AKO server and let you read your mail, etc. so you would not even necessarily know that any shenanigans were going on.

Also this configuration is set up to use procmail for the local mail delivery.

See: fetchmail(1)

Comment

Micha Niskin

Sep 17, 02:03 PM
Category  

This link is a pretty good reference for setting tabs and indentation in vim. I find the :retab command especially useful when I’m editing a file that has mixed tabs and spaces in it and I want to clean it up and have only spaces for indentation.

In this case doing a find/replace substitution for the tabs (like :%s/^I/ /g, for example) doesn’t really do what you want it to do. I mean, the whole point of having tabs is that they are not all the same width—-some of them may occupy only one character of space, while another may occupy 4 characters of space, depending on how you have your tabstops set. But :retab does it beautifully.

From the page:

After the ‘expandtab’ option is set, all the new tab characters entered will be changed to spaces. This will not affect the existing tab characters. To change all the existing tab characters to match the current tab settings, use :retab.

When you use this it’s probably a good idea to put a modeline at the top or bottom of the file to prevent those tabs from getting back in there.

Comment

Previous