#!/bin/bash # (c) Kim Holburn 2005 kim@holburn.net # GPL v2 http://www.gnu.org/copyleft/gpl.html # next line like basename but a bash builtin so faster short=${0##*/} if [ $# -lt 1 ]; then echo "$short: No argument" exit 1 fi file="$1" if [ ! -e "$file" ]; then echo "$short: \"$file\": No such file." exit 1 fi if [ ! -r "$file" ]; then echo "$short: Cannot read file \"$file\"."; exit 1; fi if ! plutil -lint -s "$file" ; then echo "$short: \"$file\": Invalid plist file."; exit 1; fi case "$short" in pledit);; plmore) plutil -convert xml1 -o /dev/stdout "$file" | more; exit;; plless) plutil -convert xml1 -o /dev/stdout "$file" | less; exit;; plcat|*) plutil -convert xml1 -o /dev/stdout "$file"; exit;; esac if [ ! -w "$file" ]; then echo "$short: Cannot write file \"$file\"."; exit 1; fi # dated backups date=`date '+%Y-%m-%d'` backup="$file.$date"; if [ -e $backup ]; then date=`date '+%Y-%m-%dT%H:%M:%S'` backup="$file.$date" if [ -e $backup ]; then $backup = `mktemp $backup.XXXX` fi fi file1=${file##*/} temp=`mktemp /tmp/$file1.TEMP.XXXX` temp2=`mktemp /tmp/$file1.TEMP2.XXXX` new=`mktemp $file.NEW.XXXX` if ! plutil -convert xml1 -o "$temp" "$file"; then echo "$short: Couldn't convert file \"$file\"." exit fi if ! cp "$temp" "$temp2"; then echo "$short: Couldn't copy converted file \"$file\"." echo " from \"$temp\" to \"$temp2\"" rm "$temp" exit fi if ! vim "$temp"; then echo "$short: Couldn't edit converted file \"$temp\"." rm "$temp" "$temp2" exit fi if diff -b -q "$temp" "$temp2" > /dev/null; then echo "$short: No change in edited converted file \"$temp\"." rm "$temp" "$temp2" else plutil -convert binary1 -o "$new" "$temp" rm "$temp" "$temp2" if [ -e "$temp~" ]; then rm "$temp~" fi mv "$file" "$backup" mv "$new" "$file" fi