#!/bin/bash # Add a Content-Disposition header line to patch files according to # their file name. # # Copyright (C) 2006 Jean Delvare # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details: # http://www.gnu.org/copyleft/gpl.html # # The latest official version of this script can be found at: # ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/scripts/add-content if [ $# -eq 0 ] then echo "Usage: add-content file [file...]" >&2 exit 1 fi for file in $@ do if [ ! -f $file ] then echo "$file doesn't exist or isn't a regular file" exit 1 fi filename="$(basename "$file")" awk ' NR==1 && /^From:/ { print ; next } /^[Cc]ontent-[Dd]isposition/ { next } !done { print "Content-Disposition: inline; filename='"$filename"'"; if (NF) { print "" }; done=1; print; next } { print } ' < "$file" > "$file.add-content" if ! diff -q "$file.add-content" "$file" > /dev/null then mv -f "$file.add-content" "$file" else echo "$file: Already OK, no change" rm -f "$file.add-content" fi done