I'm attaching two scripts. One just converts 'old' /usr/lib/mime/packages/ directory to 'new' one. Why I'll explain later. Next is replacement for update-mime script to use 'new' format. It generates full compatible mailcap file, but inserts just one application (x and non x) for each mime type. I think this solution isn't worse than original. Although this script has one *big* disadvantage... It's shell script and it's very slow. I'm sorry but I don't know perl. Nevertheless it can't be improved, it's just a sample.
Now, why I think my structure of files in /usr/lib/mime/packages is better. It's very simple to take control of it. System wide script (my update-mime2) looks at .default files for each type and puts into mailcap. If it doesn't find defaults (admin didn't choose one) it puts first from directory (such as old one). In conclusion, we see that we generally don't loose usability but we're getting new one. Of course, this script propably doesn't use all of original update-mime features, because I don't even know them, but I can be improved. In contrast the 'power' of this special directory structure is appearing for user, not administrator. It's very easy to write a frontend to select apps from that tree. For each type it can show user all posibilities and extra show administrator suggestion (.default). Then in *simple* way it'd generate ~/.mailcap file. As we see, we don't loose usability, even compatibility. I replaced just one script, and provide converter for temporary. Please, look at it, and thinks is it interesting. Say rather about 'idealogic' solution, not technically scripts, because they can be improved by someone, who's good at it. PS. I'm now using this on my computer and I don't have any problems. I work know on a kind of frontend. PS2. For tests, you can change directiories in scripts vars. Regards, Marcin. -- .---, --: mcINEK :-- / ,. \ ' T h e O w l s a r e n o t | | ; ; W h a t T h e y S e e m . . . ' \ `._ / wrote on Debian GNU/Linux SID
#! /bin/bash # # This sctipt is a replacment for update-mime. # It uses new format of /usr/lib/mime/packages dir. # # Author: mcINEK <[EMAIL PROTECTED]> # if [ -x /usr/sbin/update-mimedir ]; then /usr/sbin/update-mimedir fi mime_dirs="/usr/lib/mime/packages" mailcap="/etc/mailcap" dirs=`find $mime_dirs -type d | sort` if [ "$mime_dirs" == "" ]; then echo "Is /usr/lib/mime/packages using new format?" exit fi echo "# File generated by update-mime2 script." > $mailcap echo >> $mailcap for dir in $dirs; do [ ! "$dir" == "$mime_dirs" ] || continue dir=`echo "$dir" | awk -F\/ '{ print $NF}'` cd "$mime_dirs/$dir" # check, if there's any program [ ! "`ls`" == "" ] || continue # looking for non x program, sed to make sure if chosen only one x_program=`ls x.*.default 2> /dev/null | sed q1` if [ ! "$x_program" ]; then # choose first available x_program=`ls x.* 2> /dev/null | sed q1` fi # if not will use terminal program # chech for a default term program term_program=`ls --ignore='x.*' 2> /dev/null | grep .*.default | sed q1` if [ ! "$term_program" ]; then term_program=`ls --ignore='x.*' 2> /dev/null | sed q1` fi mime_type=`echo $dir | sed 's/\./\//'` #echo "X - $x_program T - $term_program" if [ "$x_program" ]; then echo "$mime_type; `cat $mime_dirs/$dir/$x_program`" >> $mailcap fi if [ "$term_program" ]; then echo "$mime_type; `cat $mime_dirs/$dir/$term_program`" >> $mailcap fi echo >> $mailcap echo -n . done echo
#! /bin/bash # # This script converts old /usr/lib/mime/packages # to new format. # # Author mcINEK <[EMAIL PROTECTED]> # mimedirs="/usr/lib/mime/packages" new_mimedirs=$mimedirs files=`find $mimedirs -type f -maxdepth 0 | awk -F\/ '{ print $NF }'` [ ! "$files" == "" ] || exit for file in $files; do while read line; do [ ! "$line" == "" ] || continue mime_type=`echo $line | awk -F\; '{ print $1 }'` mime_dir=`echo $mime_type | sed 's/\//./'` # echo $mime_type # choose one of two: this echo -n . # or this mkdir "$new_mimedirs/$mime_dir" 2> /dev/null if [ "`echo $line | grep DISPLAY`" == "" ]; then echo $line | awk -F' ' '{ for(i=2;i<=NF;i++) {printf("%s ",$i)} }' \ > "$new_mimedirs/$mime_dir/$file" else echo $line | awk -F' ' '{ for(i=2;i<=NF;i++) {printf("%s ",$i)} }' \ > "$new_mimedirs/$mime_dir/x.$file" fi done < "$mimedirs/$file" rm "$mimedirs/$file" 2> /dev/null done echo
signature.asc
Description: PGP signature