#!/bin/bash REPO_DIR=/home/cem/Source/MAINTAINER/xfs-linux FORMAIL=$(which formail) B4=$(which b4) _die() { echo $1 exit 1 } check_env() { if [ ! -d $REPO_DIR ]; then _die "Linux repo does not exist" fi if [ -z $FORMAIL ]; then _die "Formail program missing" fi if [ -z $B4 ]; then _die "b4 program missing" fi } shazam_message() { local MSG_ID=$1 local CUR_DIR=$PWD cd $REPO_DIR $B4 shazam -s $MSG_ID if [ $? -ne 0 ]; then cd $CUR_DIR _die "Failed to apply $MSG_ID" fi cd $CUR_DIR echo "Message/Series $MSG_ID applied" } check_env MSG="" if [ ! -t 0 ]; then MSG=$(cat) else _die "No email has been piped" fi # Quote $MSG to trick the shell's IFS MESSAGE_ID=$(echo "$MSG" | formail -x message-id | sed 's/[<>]//g') if [ -z $MESSAGE_ID ]; then _die "Message is empty" fi shazam_message $MESSAGE_ID