Automating pass phrase signings with expect

I got annoyed with entering the pass phrase to sign RPMs, especially when I had a script that would build many RPMs while I went off and did something else. So I used expect to script it, and it was quite easy.

This is what my rpm build command looked like when run manually:

rpmbuild -bb –sign –target=i386,x86_64 package.spec

Here’s the expect script that inputs the pass phrase when prompted:

#!/usr/bin/expect
spawn rpmbuild -bb –sign –target=i386,x86_64 [lindex $argv 0]
set pass sekretpassword
expect “phrase:”
send “$pass\r”
interact

To run the script once, I would just pass the filename.spec as an argument, but I’d rather use it to build many RPMs with a single command. Here’s the bash script I use to do it.

#!/bin/bash
cd /home/nathan/rpm/SPECS/
for file in `ls *.spec`
do
/home/nathan/scripts/rpmbuild_expect “$file”
done

Expect can be used to automate anything that requires standard input, it’s quite handy.

Advertisements

About this entry