fixmime - fix invalid Mime entries and sloppy .desktop files

This script aims to reduce (significantly) the warnings in kbuildsycoca4 (the program which rebuilds KDE system configuration cache) and consequently the size of logs by applying the following 4 fixes to the mime database and applications .desktop files:

[ul]
[li]Add comment field to Mime types which lack one[/li][li]Add missing trailing semicolon to non XDG compliant .desktop files[/li][li]Add empty Exec line to .desktop files which require one[/li][li]Replace type Application with Type Service in .desktop files where it conflicts with X-KDE-Library (basically all YaST desktop files under openSUSE!).[/li][/ul]

What you should know:
All these flaws produce warnings and no fatal errors. If you belong to the 80% of people who believe they should no try to fix a working system and never put their noze in logs … you can safely ignore this post. If however you like Nietzsche and are tired of warnings which don’t seem to make sense but fill the logs - as I see from time to time some people complaining about this - you might find some interest in such a script.

[ul]
[li]1 and 2 are safe and advisable.[/li][li]3 is a hack I figured out. [/li][li]4 is ‘experimental’ (or should I say more artistic than scientific?) Therefore it is commented out in the code posted below.[/li][/ul]


#! /bin/bash
#: Title       : fixmime
#: Date Created: Sat Jan  8 06:48:59 PST 2011 
#: Last Edit   : Sat Jan  8 15:53:57 PST 2011 
#: Author      : please_try_again 
#: Version     : 1.0
#: Description : fixes some inconsistances in mime database and desktop files,
#:             : reducing significantly the amount of warnings during
#:             : KDE initialization (kbuildsycoca4 output)
#: usage       : fixmime
#: options:    : -u           : reverses changes applied in YaST2 apps 
#
# Copy and paste this text into a text file and save it in /usr/local/bin as the file fixmime
# change onwership to root and make it executable for the owner (root) and readable by all users.
# You run this script as root or sudo, as other users don't have right access to the .desktop files
# under /usr/share/applications, the ones this script aims to modify.
#
# su -l
# chown root:wheel /usr/local/bin/fixmime
# chmod 774 /usr/local/bin/fixmime
#
#
logFile=/tmp/kbuildsycoca4.log
mimeDir=/usr/share/mime

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# some missing comments for Mime types. You can add others (but you don't have to)
# Just replace the following invalid characters in variable names: 
# "/" with "___"
# "." with "__"
# "-" with "_"
# For example for: 
# application/vnd.ms-excel.sheet.binary.macroEnabled.12.xml
# You'll use the following variable name: 
# application___vnd__ms_excel__sheet__binary__macroEnabled__12

application___vnd__ms_excel__sheet__binary__macroEnabled__12="Excel Binary Workbook"
application___vnd__ms_excel__sheet__macroEnabled__12="Macro-enabled Excel Spreadsheet"
application___vnd__ms_excel__template__macroEnabled__12="Macro-enabled Excel Spreadsheet Template"
application___vnd__ms_powerpoint__presentation__macroEnabled__12="Macro-enabled PowerPoint Presentation"
application___vnd__ms_powerpoint__slideshow__macroEnabled__12="Macro-enabled PowerPoint Slideshow"
application___vnd__ms_powerpoint__template__macroEnabled__12="Macro-enabled PowerPoint Presentation Template"
application___vnd__ms_word__document__macroEnabled__12="Macro-enabled Word Document"
application___vnd__ms_word__template__macroEnabled__12="Macro-enabled Word Document Template"
application___vnd__openxmlformats_officedocument__presentationml__template="Microsoft PowerPoint Presentation Template"
application___vnd__openxmlformats_officedocument__spreadsheetml__template="Microsoft Excel Worksheet Template"
application___vnd__openxmlformats_officedocument__wordprocessingml__template="Microsoft Word Document Template"
application___x_ssh_key="SSH Authentication Key"
application___x_pem_key="Privacy Enhanced Mail authentication key"

# Other missing comments will be inferred from Mime types' names.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Add missing comments in Mime types and update mime database
function addMimeComments {
	printf "
 * adding missing <comment> field
"
	mimeType=($(awk '/[Mm]issing *<comment>/ {gsub(/"/,"",$NF) ; print $NF}' $logFile))

# add new mime types to Overrides.xml
	cat > $mimeDir/packages/Overrides.xml <<EOFOVERRIDES | sort -u 
`grep '&lt;mime-type' $mimeDir/packages/Overrides.xml 2&gt;/dev/null`
`for m in ${mimeType[li]} ; do[/li]c=$(echo ${m%.xml} | sed 's|/|___|g;s|\.|__|g;s|-|_|g') ; c=${!c}
C=$(echo ${m%.xml} | sed 's|.*/||;s|^x-||;s|-| |g;s|$| document|') ; c=${c:-$C}
sed "/DO NOT EDIT/d;/&lt;?xml/d;s|\(&lt;mime-type \).*\(type=.*&gt;\)|\1\2&lt;comment&gt;$c&lt;/comment&gt;|" $mimeDir/$m | tr -d "
" | sed 's|&gt; *&lt;|&gt;&lt;|g;s/^/    /'
echo
done`
EOFOVERRIDES

	cat > /tmp/Overrides.xml <<EOFOVERRIDES2
<?xml version='1.0' encoding='utf-8'?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
`grep '&lt;mime-type' $mimeDir/packages/Overrides.xml 2&gt;/dev/null`
</mime-info>
EOFOVERRIDES2
mv {/tmp,$mimeDir/packages}/Overrides.xml

# update mime database
update-mime-database $mimeDir
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fix Xdg not compliant .desktop files by ending MimeType lines with a semicolon. 
function makeXdgCompliant {
	printf "
 * fixing not XDG compliant .desktop files
"
	cat <<EOFXDGCOMPLIANT | sh -
$(sed -n '/missing trailing semicolon/s|^.*List entry \(.*\) in "\([^"]*\)".*|if [ -f \2 ] ; then cp \2 \2.org \&\& sed "/^\1/s/\\\([^;]\\\)$/\\1;/" \2.org > \2 \&\& rm \2.org \&\& echo " - \2" ; fi |p' $logFile | sed 's| \(ServiceMenus\)| /usr/share/kde4/services/\1|g' | sort -u)
EOFXDGCOMPLIANT

}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fix .desktop files with missing Exec by Adding Exec="" 
# I don't know if it's OK ... just figured out (?)
function addDummyExec {
	printf "
 * fixing .desktop files with missing Exec
"
	cat <<EOFMISSINGEXEC | sh -
$(sed -n '/but no Exec line/s|^.*desktop entry file *"\(.*\)" *has Type= "Application".*|if [ -f \1 ] ; then grep -q "X-KDE-Library" \1 \|\| echo Exec=\\"\\" >> \1 \&\& echo " - \1" ; fi |p' $logFile | sort -u | sed '/YaST2/d')
EOFMISSINGEXEC
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fix type "Application" / X-KDE-Library conflict in .desktop files 
# by replacing type=Application with type=Service in these files
# I'm not aware of the consequences of doing that, although it 
# doesn't seem to affect YaST functionality (for me).
#
# Option "-u" reverses these changes in YaST desktop files.    
# Therefore using it only makes sense under openSUSE

function fixKdeLibrary {
	printf "
 * resolving X-KDE-Library/Application type conflicts.
"

	case $1 in
	-u)
	[ -d /usr/share/applications/YaST2 ] || return
	desktopFiles=$(find /usr/share/applications/YaST2 -exec grep -q "Type=Service" "{}" ";" -exec echo "{}" ";")
	[ "$desktopFiles" ] || return
	for f in $desktopFiles ; do
		cp $f{,.org}
		echo " - changing $f"
		sed 's/Type *= *Service/Type=Application/' $f.org > $f
		rm $f.org
	done

	;;
	*)
    desktopFiles=$(sed -n '/but also has a X-KDE-Library/s|.*desktop entry file "\(.*\.desktop\)".*|\1|p' $logFile | sort -u)
	[ "$desktopFiles" ] || return

	for f in $desktopFiles ; do
		cp $f{,.org}
		echo " - changing $f"
		sed 's/Type *= *Application/Type=Service/' $f.org > $f
		rm $f.org
	done
	;;
	esac
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MAIN - BEGIN
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# exit if nor toot
[ $(id -u) -gt 0 ] && exec echo "This script can only be run by root"

# run kbuildsycoca4 once to find errors/warnings and write output in $logFile 
which kbuildsycoca4 &> /dev/null || exec echo "kbuilsycoca4 not found: Script aborted."
kbuildsycoca4 --noincremental > $logFile 2>&1

# 1) Fix mime types with missing comments
grep -q '[Mm]issing *<comment>' $logFile && addMimeComments

# 2) Fix non XDG compliant .desktop files
grep -q 'missing trailing semicolon' $logFile && makeXdgCompliant

# 3) Fix .desktop files with missing exec line
grep -q 'but no Exec line' $logFile && addDummyExec

# 4) Fix "Application" / X-KDE-Library conflict in .desktop files
# grep -q 'also has a X-KDE-Library' $logFile && fixKdeLibrary $1

# 5) Show remaining warnings in kbuildsycoca4 output.
printf "
***************************************************************
The following files still contain errors:

"
kbuildsycoca4 --noincremental 2>&1 | sed 's|.*::||;s|\. .*|.|;/^$/d;/kbuildsycoca4 running/d' | sort -u

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MAIN - END
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

More about 4.
kbuildsycoca4 complains about all YaST .desktop files in /usr/share/applications/YaST2 and outputs a warning for each of them. The trick is to replace the Type Application with the type Service. YaST developpers might have had a good reason to use type Application. Anyway, as far as I can tell, YaST modules work with the type Service and Kde doesn’t complain. I applied this change on all my openSUSE machines … However, since you can never be sure if you did a good job until sunset (not to mention that there are two moons on my planet), I added an option to reverse the changes: fixmime -u (just in case it would be needed). Actually, the output of

kbuildsycoca4  --noincremental 2>&1

after running fixmime and fixmime -u will show a huge difference in the quantity of warnings generated.

When I want to run YaST modules directly from wm menus (whether KDE, Gnome or another one), I leave the Type Application and remove the X-KDE-Library key, put the file in /usr/local/share/applications , following the warning which recommends to split those files. I first implemented this function in the script, but removed it afterwards, as I realised that nobody does that.

Put the script in /usr/local/bin or in your system path, make executable and run as root or sudo.

On slower systems, fixmime can take some time, specially if run outside of KDE (but KDE has to be installed, as the script parses kbuildsycoca4 output on standard error)

It is called “fixmime” because I started fixing mime types and ended up fixing desktop files.

As usual, you continue to amaze me please_try_again. This time fixing problems I did not even know that I had, with my computer that is. Well anyway, here is what it did for me.

Running on Pass One:

linux-ew60:~ # fixmime

 * adding missing <comment> field
Unknown media type in type 'all/all'

Unknown media type in type 'all/allfiles'

Unknown media type in type 'uri/mms'

Unknown media type in type 'uri/mmst'

Unknown media type in type 'uri/mmsu'

Unknown media type in type 'uri/pnm'

Unknown media type in type 'uri/rtspt'

Unknown media type in type 'uri/rtspu'

Unknown media type in type 'fonts/package'

Unknown media type in type 'interface/x-winamp-skin'


 * fixing not XDG compliant .desktop files
 - /usr/share/applications/gxine.desktop
 - /usr/share/applications/obconf.desktop
                                                                                                                                                                            
 * fixing .desktop files with missing Exec                                                                                                                                  
                                                                                                                                                                            
 * resolving X-KDE-Library/Application type conflicts.                                                                                                                      
 - changing /opt/kde3/share/applications/kde/kresources.desktop                                                                                                             
 - changing /usr/share/applications/YaST2/SD_Reports.desktop                                                                                                                
 - changing /usr/share/applications/YaST2/SD_add_profile.desktop                                                                                                            
 - changing /usr/share/applications/YaST2/SD_control_panel.desktop                                                                                                          
 - changing /usr/share/applications/YaST2/SD_delete_profile.desktop                                                                                                         
 - changing /usr/share/applications/YaST2/SD_edit_profile.desktop                                                                                                           
 - changing /usr/share/applications/YaST2/SD_genprof.desktop                                                                                                                
 - changing /usr/share/applications/YaST2/SD_logprof.desktop                                                                                                                
 - changing /usr/share/applications/YaST2/add-on.desktop                                                                                                                    
 - changing /usr/share/applications/YaST2/backup.desktop                                                                                                                    
 - changing /usr/share/applications/YaST2/bootloader.desktop                                                                                                                
 - changing /usr/share/applications/YaST2/checkmedia.desktop                                                                                                                
 - changing /usr/share/applications/YaST2/disk.desktop                                                                                                                      
 - changing /usr/share/applications/YaST2/dsl.desktop                                                                                                                       
 - changing /usr/share/applications/YaST2/firewall.desktop                                                                                                                  
 - changing /usr/share/applications/YaST2/groups/hardware.desktop
 - changing /usr/share/applications/YaST2/groups/high_availability.desktop
 - changing /usr/share/applications/YaST2/groups/misc.desktop
 - changing /usr/share/applications/YaST2/groups/network_devices.desktop
 - changing /usr/share/applications/YaST2/groups/network_services.desktop
 - changing /usr/share/applications/YaST2/groups/security.desktop
 - changing /usr/share/applications/YaST2/groups/software.desktop
 - changing /usr/share/applications/YaST2/groups/support.desktop
 - changing /usr/share/applications/YaST2/groups/system.desktop
 - changing /usr/share/applications/YaST2/groups/virtualization.desktop
 - changing /usr/share/applications/YaST2/host.desktop
 - changing /usr/share/applications/YaST2/http-server.desktop
 - changing /usr/share/applications/YaST2/hwinfo.desktop
 - changing /usr/share/applications/YaST2/inetd.desktop
 - changing /usr/share/applications/YaST2/irda.desktop
 - changing /usr/share/applications/YaST2/iscsi-client.desktop
 - changing /usr/share/applications/YaST2/isdn.desktop
 - changing /usr/share/applications/YaST2/joystick.desktop
 - changing /usr/share/applications/YaST2/kerberos.desktop
 - changing /usr/share/applications/YaST2/keyboard.desktop
 - changing /usr/share/applications/YaST2/lan.desktop
 - changing /usr/share/applications/YaST2/ldap.desktop
 - changing /usr/share/applications/YaST2/ldap_browser.desktop
 - changing /usr/share/applications/YaST2/mail.desktop
 - changing /usr/share/applications/YaST2/modem.desktop
 - changing /usr/share/applications/YaST2/mouse.desktop
 - changing /usr/share/applications/YaST2/nfs.desktop
 - changing /usr/share/applications/YaST2/nis.desktop
 - changing /usr/share/applications/YaST2/ntp-client.desktop
 - changing /usr/share/applications/YaST2/online_update.desktop
 - changing /usr/share/applications/YaST2/power-management.desktop
 - changing /usr/share/applications/YaST2/printer.desktop
 - changing /usr/share/applications/YaST2/proxy.desktop
 - changing /usr/share/applications/YaST2/remote.desktop
 - changing /usr/share/applications/YaST2/restore.desktop
 - changing /usr/share/applications/YaST2/runlevel.desktop
 - changing /usr/share/applications/YaST2/samba-client.desktop
 - changing /usr/share/applications/YaST2/samba-server.desktop
 - changing /usr/share/applications/YaST2/scanner.desktop
 - changing /usr/share/applications/YaST2/security.desktop
 - changing /usr/share/applications/YaST2/sound.desktop
 - changing /usr/share/applications/YaST2/sudo.desktop
 - changing /usr/share/applications/YaST2/sw_single.desktop
 - changing /usr/share/applications/YaST2/sw_source.desktop
 - changing /usr/share/applications/YaST2/sysconfig.desktop
 - changing /usr/share/applications/YaST2/system_settings.desktop
 - changing /usr/share/applications/YaST2/timezone.desktop
 - changing /usr/share/applications/YaST2/tv.desktop
 - changing /usr/share/applications/YaST2/users.desktop
 - changing /usr/share/applications/YaST2/vendor.desktop
 - changing /usr/share/applications/YaST2/webpin.desktop
 - changing /usr/share/applications/YaST2/xen.desktop
 - changing /usr/share/applications/YaST2/yast-language.desktop

***************************************************************
The following files still contain errors:

createEntry: Invalid Service :  "/usr/share/applications/YaST2/groups/apparmor.desktop" 
init: The desktop entry file  "/usr/share/applications/YaST2/groups/apparmor.desktop"  has Type= "Application"  but no Exec line 
kbuildsycoca4(3866) parseLayoutNode: The menu spec file contains a Layout or DefaultLayout tag without the mandatory Merge tag inside.

And after the standard fixes I assume, here is on pass Two:

linux-ew60:~ # fixmime

 * fixing .desktop files with missing Exec

***************************************************************
The following files still contain errors:

createEntry: Invalid Service :  "/usr/share/applications/YaST2/groups/apparmor.desktop" 
init: The desktop entry file  "/usr/share/applications/YaST2/groups/apparmor.desktop"  has Type= "Application"  but no Exec line 
kbuildsycoca4(3959) parseLayoutNode: The menu spec file contains a Layout or DefaultLayout tag without the mandatory Merge tag inside.

I placed the file into /usr/local/bin, marked it executable and I opened a terminal session and typed:

su -
password:
fixmime

Works like a champ as far as I can tell. Well done please_try_again…

Thank You,

oooops ! I thought I commented out #4. In fact I originally did. Then I ran the script on a Ubuntu machine (after testing it successfully on 6 openSUSE en 3 Arch Linux), copied/pasted back here and forgot to comment out #4. Well … anyway, I explained what it does and how to reverse the changes if it causes problem with YaST. I haven’t seen any so far. Amazingly, KDE doesn’t complain about “Invalid services”. Well done, James! And one more for your collection.:wink:

oooops ! I thought I commented out #4. In fact I originally did. Then I ran the script on a Ubuntu machine (after testing it successfully on 6 openSUSE en 3 Arch Linux), copied/pasted back here and forgot to comment out #4. Well … anyway, I explained what it does and how to reverse the changes if it causes problem with YaST. I haven’t seen any so far. Amazingly, KDE doesn’t complain about “Invalid services”. Well done, James! And one more for your collection.:wink:
Ah so, using me as a guinea pig aah? Well, now that we see that it works and no harm is done, why not give us an example in a log or what ever that this is fixing. I may live to be 100 due to your new script file, but how can I tell it is working right today? Sell me on using fixmime.

Thank You,

I think it’s OK. But I don’t know why it’s OK. It fixes the issue reported here: Yast2 generates lots of error messages… (among other places). But I can tell you what step #4 of the script exactly did: it replaced Type=Application with Type=Service in all files that also include the key X-KDE-Library… and now KDE is happy (and doesn’t complain about conflicts or invalid services). There are very few files on other Linux. But on openSUSE, there are all the files in /usr/share/applications/YaST2 (and subdirectories).

**fixmime -u ** reverses that changes by replacing “Type=Service” with “Type=Application” in all these files, and so you get back to ‘default’ behaviour, including all the warnings. I also installed 11.4 in a virtual machine and noticed that the issue was still there. That’s why I decided to include this function in the script (otherwise I would just have waited a couple months for 11.4 release).

fixmime - version 2.0

#! /bin/bash
#: Title       : fixmime
#: Date Created: Sat Jan  8 06:48:59 PST 2011 
#: Last Edit   : Mon Jan 10 22:53:29 PST 2011
#: Author      : please_try_again 
#: Version     : 2.0
#: Description : fixes some inconsistencies in mime database and desktop files,
#:             : reducing significantly the amount of warnings during
#:             : KDE initialization (kbuildsycoca4 output)
#: usage       : fixmime
#: options:    : -u  --undo          : reverse changes applied in YaST2 apps 
#:             : -d  --delete        : remove invalid Mime types from .desktop files 
#:             : -i  --interactive   : prompt to register or delete invalid  Mime types 
#
#
prg=`basename $0`
logFile=/tmp/kbuildsycoca4.log
mimeDir=/usr/share/mime
ASK=0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# some missing comments for Mime types. You can add others (but you don't have too)
# Just replace the following invalid characters in variable names: 
# "/" with "___"
# "." with "__"
# "-" with "_"
# For example for: 
# application/vnd.ms-excel.sheet.binary.macroEnabled.12.xml
# You'll use the following variable name: 
# application___vnd__ms_excel__sheet__binary__macroEnabled__12

application___vnd__ms_excel__sheet__binary__macroEnabled__12="Excel Binary Workbook"
application___vnd__ms_excel__sheet__macroEnabled__12="Macro-enabled Excel Spreadsheet"
application___vnd__ms_excel__template__macroEnabled__12="Macro-enabled Excel Spreadsheet Template"
application___vnd__ms_powerpoint__presentation__macroEnabled__12="Macro-enabled PowerPoint Presentation"
application___vnd__ms_powerpoint__slideshow__macroEnabled__12="Macro-enabled PowerPoint Slideshow"
application___vnd__ms_powerpoint__template__macroEnabled__12="Macro-enabled PowerPoint Presentation Template"
application___vnd__ms_word__document__macroEnabled__12="Macro-enabled Word Document"
application___vnd__ms_word__template__macroEnabled__12="Macro-enabled Word Document Template"
application___vnd__openxmlformats_officedocument__presentationml__template="Microsoft PowerPoint Presentation Template"
application___vnd__openxmlformats_officedocument__spreadsheetml__template="Microsoft Excel Worksheet Template"
application___vnd__openxmlformats_officedocument__wordprocessingml__template="Microsoft Word Document Template"
application___x_ssh_key="SSH Authentication Key"
application___x_pem_key="Privacy Enhanced Mail authentication key"

# Other missing comments will be inferred from Mime types' names.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Use GTK dialogs in X session if zenity is installed and X display is open.
if [ "$DISPLAY" ] ; then
	which zenity > /dev/null 2>&1 && ZDIALOG=1
	xset -q > /dev/null 2>&1 || unset ZDIALOG
fi
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# HELP 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function syntax {
cat << EOFSYNTAX
usage:
   $prg [options]
options:
   -u --undo         : reverse changes applied in YaST2 apps 
   -i --interactive  : interactively register invalid Mime Types (discouraged)
   -d --delete       : delete invalid Mime types
EOFSYNTAX
exit
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# display error message either in terminal or in GTK dialog (if zenity is installed)
function errormsg {
if [ "$ZDIALOG" ] ; then
	zenity --error --title="$prg - error" --text="$*"
else
	printf "
%s
" "$*"
fi
exit 1
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# prompt message either in terminal or in GTK dialog (if zenity is installed)
function ask {
case $1 in
	-d) title="Delete Mime type" ;;
	-r) title="Register Mime type" ;;
esac
shift
if [ "$ZDIALOG" ] ; then
	zenity --question --title="$title" --text="$title ${1}?"
 	ASK=$?
else
	while [ "true" ] ; do 	
		printf " - %s: %-40s	[y/n]
" "$title" "$1"
		read -N1 -s
		case $REPLY in
			y|Y) ASK=0 ; break ;;
			n|N) ASK=1 ; break ;;
		esac
	done
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# register Mime type (asking for extension(s) and comment)
function register {

if [ "$ZDIALOG" ] ; then
	ext=$(zenity --entry --title="Registering $1" --text="Extensions:") 
	cmt=$(zenity --entry --title="Registering $1" --text="Comment:") 
else
	read -p "Extensions: " ext
	read -p "Comment   : " cmt
fi
glob=$(echo $ext | tr ";,:" " " | tr " " "
" | sed 's|[^a-zA-Z0-9]||;s|^\(.*\)$|<glob pattern="*.\1"/>|' | tr -d "
")
printf "    <mime-type type=\"%s\"><comment>%s</comment>%s</mime-type>
" $1  "$cmt" "$glob" >> $mimeDir/packages/Overrides.xml
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Delete entrie for Mime type in .desktop files
function deleteMimeType {
	f=${1%:*} ; m=${1#*:}
	printf " - deleting Mime type %s from %s
" $m $f
	cp $f{,.org}
	sed "/MimeType/s|$m;*||;/MimeType= *$/d" $f.org > $f
	rm $f.org	
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Add missing comments in Mime types and update mime database
function addMimeComments {
	printf "
 * adding missing <comment> field
"
	mimeType=($(awk '/[Mm]issing *<comment>/ {gsub(/"/,"",$NF) ; print $NF}' $logFile))

# add new mime types to Overrides.xml
	cat > $mimeDir/packages/Overrides.xml <<EOFOVERRIDES | sort -u 
`grep '&lt;mime-type' $mimeDir/packages/Overrides.xml 2&gt;/dev/null`
`for m in ${mimeType[li]} ; do
[/li]c=$(echo ${m%.xml} | sed 's|/|___|g;s|\.|__|g;s|-|_|g') ; c=${!c}
C=$(echo ${m%.xml} | sed 's|.*/||;s|^x-||;s|-| |g;s|$| document|') ; c=${c:-$C}
sed "/DO NOT EDIT/d;/&lt;?xml/d;s|\(&lt;mime-type \).*\(type=.*&gt;\)|\1\2&lt;comment&gt;$c&lt;/comment&gt;|" $mimeDir/$m | tr -d "
" | sed 's|&gt; *&lt;|&gt;&lt;|g;s/^/    /'
echo
done`
EOFOVERRIDES
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Register or delete invalid Mime types
function registerOrDeletedMimeType {
	invalidMimeTypes=$(sed -n '/invalid MIME type/p' $logFile | awk '/^Error in file/ { print $4, $5 }' | tr -d "\" " | sort -u)
	oldMediaTypes=$(sed -n '/old media type/p' $logFile | awk '/^Warning in file/ { print $4, $9 }' | tr -d "\" " | sort -u)
	if [ $flag -ge 4 ] ; then
		printf "
 * deleting invalid Mime types
"
	# delete all invalid Mime types 
		for mt in $invalidMimeTypes ; do
			deleteMimeType $mt
		done
		printf "
 * deleting old media types
"
	# delete old media types 
		for mt in $oldMediaTypes ; do
			deleteMimeType $mt
		done
	else
	# interactively register/delete  invalid Mime types
		if [ "x$invalidMimeTypes" != "x" ]; then
			printf "
 * registering/deleting invalid Mime types
"
			for mt in $invalidMimeTypes ; do
				f=${mt%:*} ; m=${mt#*:}
				ask -r $m
				if [ $ASK -le 0 ] ; then
					register $m
				else
					InvalidMimeTypes="$InvalidMimeTypes $mt"
				fi
			done
		fi
		if [ "x$InvalidMimeTypes" != "x" ]; then
			for mt in $InvalidMimeTypes ; do
				f=${mt%:*} ; m=${mt#*:}
				ask -d $m
				[ $ASK -le 0 ] && deleteMimeType $mt
			done
		fi
	fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function FixInvalidMimeTypes {
	grep -q '[Mm]issing *<comment>' $logFile && addMimeComments
	# run update-desktop-databse once to find errors/warnings and write output in $dlogFile 
	which update-desktop-database &> /dev/null && update-desktop-database >> $logFile 2>&1
	if [ $flag -ge 2 ] ; then
		grep -q -e '^Warning' -e '^Error' $logFile && registerOrDeletedMimeType 
	fi
	cat > /tmp/Overrides.xml <<EOFOVERRIDES2
<?xml version='1.0' encoding='utf-8'?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
`grep '&lt;mime-type' $mimeDir/packages/Overrides.xml 2&gt;/dev/null | sort -u`
</mime-info>
EOFOVERRIDES2
mv {/tmp,$mimeDir/packages}/Overrides.xml

# update mime database
update-mime-database $mimeDir
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fix Xdg not compliant .desktop files by ending MimeType lines with a semicolon. 
function makeXdgCompliant {
	printf "
 * fixing not XDG compliant .desktop files
"
	cat <<EOFXDGCOMPLIANT | sh -
$(sed -n '/missing trailing semicolon/s|^.*List entry \(.*\) in "\([^"]*\)".*|if [ -f \2 ] ; then cp \2 \2.org \&\& sed "/^\1/s/\\\([^;]\\\)$/\\1;/" \2.org > \2 \&\& rm \2.org \&\& echo " - \2" ; fi |p' $logFile | sed 's| \(ServiceMenus\)| /usr/share/kde4/services/\1|g' | sort -u)
EOFXDGCOMPLIANT
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fix .desktop files with missing Exec by Adding Exec="" 
# I don't know about that hack ... just figured out (?)
function addDummyExec {
	printf "
 * fixing .desktop files with missing Exec
"
	cat <<EOFMISSINGEXEC | sh -
$(sed -n '/but no Exec line/s|^.*desktop entry file *"\(.*\)" *has Type= "Application".*|if [ -f \1 ] ; then grep -q "X-KDE-Library" \1 \|\| echo Exec=\\"\\" >> \1 \&\& echo " - \1" ; fi |p' $logFile | sort -u | sed '/YaST2/d')
EOFMISSINGEXEC
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fix type "Application" / X-KDE-Library conflict in .desktop files 
# by replacing type=Application with type=Service in these files
# I'm not aware of the consequences of doing that, although it 
# doesn't seem to affect YaST functionality (for me).
#
# Option "-u" reverses these changes in YaST desktop files.    
# Therefore using it only makes sense under openSUSE

function fixKdeLibrary {
	printf "
 * resolving X-KDE-Library/Application type conflicts.
"
	if [ $(( $flag % 2)) -gt 0 ] ; then
		[ -d /usr/share/applications/YaST2 ] || return
		desktopFiles=$(find /usr/share/applications/YaST2 -exec grep -q "Type=Service" "{}" ";" -exec echo "{}" ";")
		[ "$desktopFiles" ] || return
		for f in $desktopFiles ; do
			cp $f{,.org}
			echo " - changing $f"
			sed 's/Type *= *Service/Type=Application/' $f.org > $f
			rm $f.org
		done
	else
	    desktopFiles=$(sed -n '/but also has a X-KDE-Library/s|.*desktop entry file "\(.*\.desktop\)".*|\1|p' $logFile | sort -u)
		[ "$desktopFiles" ] || return
		for f in $desktopFiles ; do
			cp $f{,.org}
			echo " - changing $f"
			sed 's/Type *= *Application/Type=Service/' $f.org > $f
			grep -q 'Type=Service' $f || echo "Type=Service" >> $f
			rm $f.org
		done
	fi
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MAIN - BEGIN
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# exit if not root
[ $(id -u) -gt 0 ] && exec echo "This script can only be run by root"

ARGS=`getopt -q -o uid --long undo,interactive,delete -- "$@"`
[ "$?" == "0" ] || syntax
eval set -- "$ARGS"

flag=0

while true ; do
	case "$1" in
		-u|--undo) flag=$(($flag | 1)) ; shift ;;
		-i|--interactive) flag=$(($flag | 2)) ; shift ;;
		-d|--delete) flag=$(($flag | 4)) ; shift ;;
		--) shift ; break ;;
    esac
done

[ $flag -ge 6 ] && errormsg "options -i and -d are mutually exclusive"

# run kbuildsycoca4 once to find errors/warnings and write output in $logFile 
which kbuildsycoca4 &> /dev/null || exec echo "kbuilsycoca4 not found: Script aborted."
kbuildsycoca4 --noincremental > $logFile 2>&1

# 1) Fix invalid Mime Types
FixInvalidMimeTypes

# 2) Fix non XDG compliant .desktop files
grep -q 'missing trailing semicolon' $logFile && makeXdgCompliant

# 3) Fix .desktop files with missing exec line
grep -q 'but no Exec line' $logFile && addDummyExec

# 4) Fix "Application" / X-KDE-Library conflict in .desktop files
# fixKdeLibrary

# 5) Show remaining warnings in kbuildsycoca4 output.
printf "
***************************************************************
* The following files still contain errors:
"
kbuildsycoca4 --noincremental 2>&1 | sed 's|.*::||;s|\. .*|.|;/^$/d;/kbuildsycoca4 running/d' | sort -u
printf "
* The following files still contain invalid Mime types:
"
update-desktop-database 2>&1 | sed -n 's|Error in file "\([^"]*\)": "\([^"]*\)" is an invalid MIME type|\1: \2|p' | sort -u
printf "
* The following files still contain deprecated Mime or media types :
"
update-desktop-database  2>&1 | sed -n 's|Warning in file "\(.*\)": usage of MIME type "\(.*\)" is discouraged \(.*\)that should.*|\1 : \2 \3)|p'

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MAIN - END
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I had to remove some comments from the header in previous post, as the text was too long to fit in one post. This new version can detect/fix invalid Mime types based on the output of update-desktop-database.
Usage (su or sudo) :

  • **fixmime **
  1. fixes some invalid (incomplete) mime types and xdg not compliant .desktop files

  2. fixes other conflicts in .desktop files generating warnings (uncomment the line highlighted in red in the code above to enable this feature.

  • fixmime -u | --undo

reverse the changes applied in #2 above (should not be needed)

  • fixmime -d | --delete

delete all invalid Mime types and media types without prompting

  • fixmime -i | --interactive

[LIST=1]

  • prompt to register or not invalid Mime types
  • prompt to delete the unregistered ones

[/LIST]

  • deleting a Mime type
    means that it will be removed from the MimeType key in all .desktop files which include it. As it could appear in several files, you might be prompted more than one time for the same Mime type.
  • registering a Mime type
    means writing an entry (Mime Type/comment/extension) in /usr/share/packages/Overrides.xml and running update-mime-database at the end.

Of course, while registering Mime types, you have to provide appropriate comment and extensions. If zenity is installed (as for Gnome users) and the X display is open to root (which is normally the case but not always - check in /etc/pam.d/su, as stated in this post: Users accessing one another’s display.), fixmime will use GTK dialogs. You can type fixmime -id (these 2 options are mutually exclusive) to see if the error message appears in your terminal or in a popup window.

I usually do not register invalid Mime types, because if the Mime type is unregistered that’s often because the media type (the first part of the name) is invalid or deprecated. Thus these warnings you see while running fixmime are common while updating the Mime database. IMHO if doesn’t help to register Mime types with invalid media types, such as the chemical Mime types for example.

If you would register the Mime types generating the following error messages in fixmime:


* The following files still contain invalid Mime types:
/usr/share/applications/avogadro.desktop: chemical/x-cif ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-cml ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-daylight-smiles ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-gamess-input ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-gamess-output ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-gaussian-checkpoint ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-gaussian-cube ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-gaussian-log ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-mopac-out ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-pdb ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-qchem-output ("chemical" is an unregistered media type)
/usr/share/applications/avogadro.desktop: chemical/x-xyz ("chemical" is an unregistered media type)

The error messages will still be present in the next fixmime/update-desktop-database ouptut because - although the Mime type appears to be registered - the media type is not. This is the problem of all the chemical Mime types - among others: Chemical MIME Home page

Again, this script is not essential. It won’t fix things which do not work on your system. I will just remove a bunch of error messages and warnings, mostly front KDE initialization (kbuildsycoca4) output and logs.

Hi

I get this (on 11.3) after running fixmime:

* The following files still contain errors:
createEntry: Invalid Service :  "/usr/share/applications/YaST2/groups/apparmor.desktop" 
init: The desktop entry file  "/usr/share/applications/YaST2/groups/apparmor.desktop"  has Type= "Application"  but no Exec line 
kbuildsycoca4(4864) parseLayoutNode: The menu spec file contains a Layout or DefaultLayout tag without the mandatory Merge tag inside.

* The following files still contain invalid Mime types:
/usr/share/applications/ggl-gtk.desktop: app/gg ("app" is an unregistered media type)
/usr/share/applications/ggl-qt.desktop: app/gg ("app" is an unregistered media type)
/usr/share/applications/kde4/kfontview.desktop: fonts/package ("fonts" is an unregistered media type)

* The following files still contain deprecated Mime or media types :
/usr/share/applications/nautilus-folder-handler.desktop : x-directory/gnome-default-handler ("x-directory" is an old media type )
/usr/share/applications/nautilus-folder-handler.desktop : x-directory/normal ("x-directory" is an old media type )

Note: I did not (yet) run fixmime -d

But what about apparmor.desktop? Shouldn’t that have been fixed too?

Well, that one has originally 2 problems:

  • It has both type=Application and X-Kde-Libray set (causing a warning)
  • It has type Application but not Exec line (causing an error)

The addDummyExec function applies this:

if  -f /usr/share/applications/YaST2/groups/apparmor.desktop ] ; then grep -q "X-KDE-Library" /usr/share/applications/YaST2/groups/apparmor.desktop || echo Exec=\"\" >> /usr/share/applications/YaST2/groups/apparmor.desktop && echo " - /usr/share/applications/YaST2/groups/apparmor.desktop" ; fi 

So because this file has X-KDE-Library it doesn’t get added a blank Exec line. All others files in /usr/share/applications/YaST2/groups have Exec=yast2. I don’t know why it is missing in apparmor.desktop. Maybe it’s a bug or a reason that I don’t know. In doubt I didn’t touch it.

So I had the following error after running fixmime as shwon above:

createEntry: Invalid Service :  "/usr/share/applications/YaST2/groups/apparmor.desktop" 
init: The desktop entry file  "/usr/share/applications/YaST2/groups/apparmor.desktop"  has Type= "Application"  but no Exec line 

I just found this apparmor.desktop shortcut and modified it so that it had an exec line in it. I am not sure why it existed at all, but I found an apparmor utility file and added its name as a exec and then this error went away.

Thank You,

Hi
And you will probably break YaST :wink: None of the desktop entries there have exec lines as they are part of the YaST GUI…

Hi james,
Where did you find an executable called ‘apparmor’? I don’t see any.


rpm -ql yast2-apparmor | grep 'apparmor$'
which apparmor

To me, adding Exec=yast2 seems the most logical… just a guess.
Of course if you add any Exec line, the error message will disappear (whether the file exists or not). That’s why the script adds Exec="" in other cases (applications) - just not here.

No, they all do (have Exec=yast2) :

grep '^Exec' /usr/share/applications/YaST2/groups/*

Only apparmor.desktop doesn’t:

grep -L '^Exec' /usr/share/applications/YaST2/groups/*

I just added in the line:

Exec=/usr/sbin/apparmor_status

It is my opinion the entry does not matter as this is either not used, or modified when something is activated, such as doing or changing something in appamor. Without the exec, it simply does not work as we would think. My actions just got rid of the error from fixmime and I will let you know if that actually does anything at all, which I doubt. I continue to play with fixmime to see what good things can be attributed to correcting these system files. One thing is for sure, I am not losing sleep over the presence or absence of this error and I appreciate the effort put forth by please_try_again with the writing of the fixmime script. I kind of relate this to fixing errors in the Windows registry, many of which are indeed errors, but which may have little effect on the day to day operation of your computer, but which can on occasion cause some odd thing to occur due to the fact that these are still system errors that exist and could be fixed.

Thank You,

Here are the results for fixmime on 11.4 (haven’t modified the fixmime script at all).

[ul]
[li]It looks like kbuildsycoca4 doesn’t bother anymore about missing comments in mime types on recent KDE installations (not just openSUSE). Since they don’t cause warnings anymore, fixmime doesn’t catch them and the addMimeComments function isn’t used at all.
[/li]

[li]A couple XDG non-compliant .desktop files were found and corrected, mostly from 3rd party vendors (google-earth nxclient virtualbox) but some from openSUSE repo as well. On the systems I am building, they were in the packages:
[/li]
[LIST]
[li]leafpad
[/li][li]monodevelop
[/li][li]obconf
[/li][li]xfig
[/li][li]krename
[/li][/ul]

[li] The following invalid mime types (because of unregistered media types - in red) were deleted by fixmime -d:
[/li][ul]
[li]app/gg
[/li][li]zz-application/zz-winassoc-xls
[/li][li]virtual/bluedevil-audio
[/li][li]virtual/bluedevil-input
[/li][li]virtual/bluedevil-sendfile
[/li][/ul]

[li] fixKdeLibrary (which is commented out in the script) got rid of all warnings about duplicate X-KDE-Library by replacing the type service with application in YaST modules. It still didn’t break YaST for me … but I’m neither a big YaST user nor a big fan. Anyway this function is disabled by default in the version posted here.
[/li][/LIST]

Again fixmime doesn’t solve problems. It is just a perfectionnist kind of thing. :frowning:

@please_try_again

FWIW, after running v2 of your script I got

# ./fixmime
Unknown media type in type 'virtual/bluedevil-input'

Unknown media type in type 'virtual/bluedevil-audio'

Unknown media type in type 'virtual/bluedevil-sendfile'

Unknown media type in type 'all/all'

Unknown media type in type 'all/allfiles'

Unknown media type in type 'uri/mms'

Unknown media type in type 'uri/mmst'

Unknown media type in type 'uri/mmsu'

Unknown media type in type 'uri/pnm'

Unknown media type in type 'uri/rtspt'

Unknown media type in type 'uri/rtspu'

Unknown media type in type 'interface/x-winamp-skin'


 * fixing .desktop files with missing Exec

***************************************************************
* The following files still contain errors:
createEntry: Invalid Service :  "/usr/share/applications/YaST2/groups/apparmor.desktop" 
init: The desktop entry file "/usr/share/applications/YaST2/add-on.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/backup.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/bootloader.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/checkmedia.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/disk.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/dsl.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/fingerprint-reader.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/firewall.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file  "/usr/share/applications/YaST2/groups/apparmor.desktop"  has Type= "Application"  but no Exec line 
init: The desktop entry file "/usr/share/applications/YaST2/groups/hardware.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/high_availability.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/misc.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/network_devices.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/network_services.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/security.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/software.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/support.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/system.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/groups/virtualization.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/host.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/hwinfo.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/inetd.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/irda.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/iscsi-client.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/isdn.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/joystick.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/kerberos.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/keyboard.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/lan.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/ldap_browser.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/ldap.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/mail.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/modem.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/mouse.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/nfs.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/nis.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/ntp-client.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/online_update.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/printer.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/proxy.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/remote.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/restore.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/runlevel.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/samba-client.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/samba-server.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/scanner.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_add_profile.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_control_panel.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_delete_profile.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_edit_profile.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_genprof.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_logprof.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/SD_Reports.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/security.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/sound.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/sudo.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/sw_single.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/sw_source.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/sysconfig.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/system_settings.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/tftp-server.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/timezone.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/tv.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/users.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/vendor.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/webpin.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/xen.desktop" has Type= "Application" but also has a X-KDE-Library key.
init: The desktop entry file "/usr/share/applications/YaST2/yast-language.desktop" has Type= "Application" but also has a X-KDE-Library key.
kbuildsycoca4(17765) parseLayoutNode: The menu spec file contains a Layout or DefaultLayout tag without the mandatory Merge tag inside.
"KConfigIni: In file /usr/share/applications/wine-browsedrive.desktop, line 10: " "Invalid escape sequence "\ "." 
"KConfigIni: In file /usr/share/applications/wine-browsedrive.desktop, line 3: " "Invalid escape sequence "\ "." 
"KConfigIni: In file /usr/share/applications/wine-browsedrive.desktop, line 4: " "Invalid escape sequence "\ "." 

* The following files still contain invalid Mime types:
/usr/share/applications/kde4/bluedevil-audio.desktop: virtual/bluedevil-audio ("virtual" is an unregistered media type)
/usr/share/applications/kde4/bluedevil-input.desktop: virtual/bluedevil-input ("virtual" is an unregistered media type)
/usr/share/applications/kde4/bluedevil-sendfile.desktop: virtual/bluedevil-sendfile ("virtual" is an unregistered media type)

* The following files still contain deprecated Mime or media types :

This output shows the errors/warnings remaining (parsed from kbuildsycoca4 and update-desktop-database) after running fixmime. If you run fixmime -d, it will delete the 3 invalid bluedevil Mime types (“virtual” is an unknown media type) and they won’t show up anymore in the logs. If you uncomment the line

# fixKdeLibrary

in the script, it will get rid of the YaST2 errors by changing the type Application into Service in the files including the X-KDE-Library key causing the warning (unlike I said by mistake in my previous post, looking at the wrong machine). You can run kbuildsycoca4 --noincremental to see the untruncated message. I personnally don’t have problem changing that, but it is disabled by default - because I wasn’t sure if it would have a side effect. I didn’t notice any since I first ran fixmime couple months ago, but I added an option to reverse it just in case: fixmime -u.

I don’t fix the apparmor.desktop, because I don’t know what to do with that one.

That would leave you with only one error (3 times the same error) in the file wine-browsedrive.desktop, that fixmime did not handle:

"KConfigIni: In file /usr/share/applications/wine-browsedrive.desktop, line 10: " "Invalid escape sequence "\ "." 
"KConfigIni: In file /usr/share/applications/wine-browsedrive.desktop, line 3: " "Invalid escape sequence "\ "." 
"KConfigIni: In file /usr/share/applications/wine-browsedrive.desktop, line 4: " "Invalid escape sequence "\ "." 

You might want to take a look at this file.

Thanks for the analysis :slight_smile: