Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # LN# 532-701 of /usr/local/petget/installpkg.sh - http://www.pearltrees.com/s243a/installpkg-sh-usr-local-petget/id20402080/item224200433
- #see if a .desktop file was installed, fix category... 120628 improve...
- #120818 overhauled. Pkg db now has category[;subcategory] (see 0setup), xdg enhanced (see /etc/xdg and /usr/share/desktop-directories), and generic icons for all subcategories (see /usr/local/lib/X11/mini-icons).
- #note, similar code also in Woof 2createpackages.
- ONEDOT=""
- CATEGORY="`echo -n "$DB_ENTRY" | cut -f 5 -d '|'`" #exs: Document, Document;edit
- [ "$CATEGORY" = "" ] && CATEGORY='BuildingBlock' #paranoid precaution.
- #xCATEGORY and DEFICON will be the fallbacks if Categories entry in .desktop is invalid...
- xCATEGORY="`echo -n "$CATEGORY" | sed -e 's%^%X-%' -e 's%;%-%'`" #ex: X-Document-edit (refer /etc/xdg/menu/*.menu)
- DEFICON="`echo -n "$CATEGORY" | sed -e 's%^%mini-%' -e 's%;%-%'`"'.xpm' #ex: mini-Document-edit (refer /usr/local/lib/X11/mini-icons -- these are in jwm search path) 121206 need .xpm extention.
- case $CATEGORY in
- Calculate) CATEGORY='Business' ; xCATEGORY='X-Business' ; DEFICON='mini-Business.xpm' ;; #Calculate is old name, now Business.
- Develop) CATEGORY='Utility;development' ; xCATEGORY='X-Utility-development' ; DEFICON='mini-Utility-development.xpm' ;; #maybe an old pkg has this.
- Help) CATEGORY='Utility;help' ; xCATEGORY='X-Utility-help' ; DEFICON='mini-Help.xpm' ;; #maybe an old pkg has this.
- BuildingBlock) CATEGORY='Utility' ; xCATEGORY='Utility' ; DEFICON='mini-BuildingBlock.xpm' ;; #unlikely to have a .desktop file.
- esac
- topCATEGORY="`echo -n "$CATEGORY" | cut -f 1 -d ';'`"
- tPATTERN="^${topCATEGORY} "
- cPATTERN="s%^Categories=.*%Categories=${xCATEGORY}%"
- iPATTERN="s%^Icon=.*%Icon=${DEFICON}%"
- #121119 if only one .desktop file, first check if a match in /usr/local/petget/categories.dat...
- CATDONE='no'
- if [ -f /usr/local/petget/categories.dat ];then #precaution, but it will be there.
- NUMDESKFILE="$(grep 'share/applications/.*\.desktop$' /root/.packages/${DLPKG_NAME}.files | wc -l)"
- if [ "$NUMDESKFILE" = "1" ];then
- #to lookup categories.dat, we need to know the generic name of the package, which may be different from pkg name...
- #db entry format: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
- DBNAMEONLY="$(echo -n "$DB_ENTRY" | cut -f 2 -d '|')"
- DBPATH="$(echo -n "$DB_ENTRY" | cut -f 7 -d '|')"
- DBCOMPILEDDISTRO="$(echo -n "$DB_ENTRY" | cut -f 11 -d '|')"
- [ ! "$DBCOMPILEDDISTRO" ] && DBCOMPILEDDISTRO='puppy' #any name will do here.
- case $DBCOMPILEDDISTRO in
- debian|devuan|ubuntu|raspbian)
- if [ "$DBPATH" ];then #precaution
- xNAMEONLY="$(basename ${DBPATH})"
- else
- xNAMEONLY="$DBNAMEONLY"
- fi
- ;;
- *) xNAMEONLY="$DBNAMEONLY" ;;
- esac
- xnPTN=" ${xNAMEONLY} "
- #130126 categories.dat format changed slightly... 130219 ignore case...
- CATVARIABLE="$(grep -i "$xnPTN" /usr/local/petget/categories.dat | grep '^PKGCAT' | head -n 1 | cut -f 1 -d '=' | cut -f 2,3 -d '_' | tr '_' '-')" #ex: PKGCAT_Graphic_camera=" gphoto2 gtkam "
- if [ "$CATVARIABLE" ];then #ex: Graphic-camera
- xCATEGORY="X-${CATVARIABLE}"
- cPATTERN="s%^Categories=.*%Categories=${xCATEGORY}%" #121120
- CATFOUND="yes"
- CATDONE='yes'
- fi
- fi
- fi
- for ONEDOT in `grep 'share/applications/.*\.desktop$' /root/.packages/${DLPKG_NAME}.files | tr '\n' ' '` #121119 exclude other strange .desktop files.
- do
- #120901 get rid of param on end of Exec, ex: Exec=gimp-2.8 %U
- #sed -i -e 's/\(^Exec=[^%]*\).*/\1/' -e 's/ *$//' $ONEDOT #'s/\(^Exec=[^ ]*\).*/\1/'
- #121015 01micko: alternative that may work better...
- for PARMATER in u U f F #refer: http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
- do
- sed -i "s/ %${PARMATER}//" $ONEDOT
- done
- #w478 find if category is already valid (see also 2createpackages)..
- if [ "$CATDONE" = "no" ];then #121119
- CATFOUND="no"
- for ONEORIGCAT in `cat $ONEDOT | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' ' | rev` #search in reverse order.
- do
- ONEORIGCAT="`echo -n "$ONEORIGCAT" | rev`" #restore rev of one word.
- oocPATTERN=' '"$ONEORIGCAT"' '
- [ "`echo "$PUPHIERARCHY" | tr -s ' ' | grep "$tPATTERN" | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
- #got a problem with sylpheed, "Categories=GTK;Network;Email;News;" this displays in both Network and Internet menus...
- if [ "$CATFOUND" = "yes" ];then
- cPATTERN="s%^Categories=.*%Categories=${ONEORIGCAT}%"
- break
- fi
- done
- #121109 above may fail, as DB_category field may not match that in .desktop file, so leave out that $tPATTERN match in $PUPHIERARCHY...
- if [ "$CATFOUND" = "no" ];then
- for ONEORIGCAT in `cat $ONEDOT | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' ' | rev` #search in reverse order.
- do
- ONEORIGCAT="`echo -n "$ONEORIGCAT" | rev`" #restore rev of one word.
- oocPATTERN=' '"$ONEORIGCAT"' '
- [ "`echo "$PUPHIERARCHY" | tr -s ' ' | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
- #got a problem with sylpheed, "Categories=GTK;Network;Email;News;" this displays in both Network and Internet menus...
- if [ "$CATFOUND" = "yes" ];then
- cPATTERN="s%^Categories=.*%Categories=${ONEORIGCAT}%"
- break
- fi
- done
- fi
- fi
- sed -i -e "$cPATTERN" $ONEDOT #fix Categories= entry.
- #w019 does the icon exist?...
- ICON="`grep '^Icon=' $ONEDOT | cut -f 2 -d '='`"
- if [ "$ICON" != "" ];then
- [ -e "$ICON" ] && continue #it may have a hardcoded path.
- ICONBASE="`basename "$ICON"`"
- #110706 fix icon entry in .desktop... 110821 improve...
- #first search where jwm looks for icons... 111207...
- FNDICON="`find /usr/local/lib/X11/mini-icons /usr/share/pixmaps -maxdepth 1 -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
- if [ "$FNDICON" ];then
- ICONNAMEONLY="`basename $FNDICON`"
- iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
- sed -i -e "$iPTN" $ONEDOT
- continue
- else
- #look elsewhere... 111207...
- FNDICON="`find /usr/share/icons /usr/local/share/pixmaps -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
- #111207 look further afield, ex parole pkg has /usr/share/parole/pixmaps/parole.png...
- [ ! "$FNDICON" ] && [ -d /usr/share/$ICONBASE ] && FNDICON="`find /usr/share/${ICONBASE} -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
- #111207 getting desperate...
- [ ! "$FNDICON" ] && FNDICON="`find /usr/share -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
- if [ "$FNDICON" ];then
- ICONNAMEONLY="`basename "$FNDICON"`"
- ln -snf "$FNDICON" /usr/share/pixmaps/${ICONNAMEONLY}
- iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
- sed -i -e "$iPTN" $ONEDOT
- continue
- fi
- fi
- #substitute a default icon...
- sed -i -e "$iPATTERN" $ONEDOT #note, ONEDOT is name of .desktop file.
- fi
- fi
- #120926 if a langpack installed, it will have /usr/share/applications.in (see /usr/sbin/momanager, /usr/share/doc/langpack-template/pinstall.sh).
- ABASEDESKTOP="`basename $ONEDOT`"
- ADIRDESKTOP="`dirname $ONEDOT`"
- if [ -f /usr/share/applications.in/${ABASEDESKTOP} ];then
- TARGETLANG="`echo -n $LANG_USER | cut -f 1 -d '_'`" #ex: de
- tlPTN="^Name\[${TARGETLANG}\]"
- if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
- if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
- #aaargh, these accursed back-slashes! ....
- INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
- sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
- fi
- fi
- #do same for Comment field...
- tlPTN="^Comment\[${TARGETLANG}\]"
- if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
- if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
- #aaargh, these accursed back-slashes! ....
- INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
- sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
- fi
- fi
- #well, i suppose need this too...
- TARGETLANG="`echo -n $LANG_USER | cut -f 1 -d '.'`" #ex: de_DE
- tlPTN="^Name\[${TARGETLANG}\]"
- if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
- if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
- #aaargh, these accursed back-slashes! ....
- INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
- sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
- fi
- fi
- #do same for Comment field...
- tlPTN="^Comment\[${TARGETLANG}\]"
- if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
- if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
- #aaargh, these accursed back-slashes! ....
- INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
- sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
- fi
- fi
- fi
- done
Add Comment
Please, Sign In to add comment