s243a

intallkpkg.sh Ln# 532-701 fix .desktop issues

Apr 23rd, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.92 KB | None | 0 0
  1. # LN# 532-701 of /usr/local/petget/installpkg.sh - http://www.pearltrees.com/s243a/installpkg-sh-usr-local-petget/id20402080/item224200433
  2. #see if a .desktop file was installed, fix category... 120628 improve...
  3. #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).
  4. #note, similar code also in Woof 2createpackages.
  5. ONEDOT=""
  6. CATEGORY="`echo -n "$DB_ENTRY" | cut -f 5 -d '|'`" #exs: Document, Document;edit
  7. [ "$CATEGORY" = "" ] && CATEGORY='BuildingBlock' #paranoid precaution.
  8. #xCATEGORY and DEFICON will be the fallbacks if Categories entry in .desktop is invalid...
  9. xCATEGORY="`echo -n "$CATEGORY" | sed -e 's%^%X-%' -e 's%;%-%'`" #ex: X-Document-edit (refer /etc/xdg/menu/*.menu)
  10. 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.
  11. case $CATEGORY in
  12.  Calculate)     CATEGORY='Business'             ; xCATEGORY='X-Business'            ; DEFICON='mini-Business.xpm'            ;; #Calculate is old name, now Business.
  13.  Develop)       CATEGORY='Utility;development'  ; xCATEGORY='X-Utility-development' ; DEFICON='mini-Utility-development.xpm' ;; #maybe an old pkg has this.
  14.  Help)          CATEGORY='Utility;help'         ; xCATEGORY='X-Utility-help'        ; DEFICON='mini-Help.xpm'                ;; #maybe an old pkg has this.
  15.  BuildingBlock) CATEGORY='Utility'              ; xCATEGORY='Utility'               ; DEFICON='mini-BuildingBlock.xpm'       ;; #unlikely to have a .desktop file.
  16. esac
  17. topCATEGORY="`echo -n "$CATEGORY" | cut -f 1 -d ';'`"
  18. tPATTERN="^${topCATEGORY} "
  19. cPATTERN="s%^Categories=.*%Categories=${xCATEGORY}%"
  20. iPATTERN="s%^Icon=.*%Icon=${DEFICON}%"
  21.  
  22. #121119 if only one .desktop file, first check if a match in /usr/local/petget/categories.dat...
  23. CATDONE='no'
  24. if [ -f /usr/local/petget/categories.dat ];then #precaution, but it will be there.
  25.  NUMDESKFILE="$(grep 'share/applications/.*\.desktop$' /root/.packages/${DLPKG_NAME}.files | wc -l)"
  26.  if [ "$NUMDESKFILE" = "1" ];then
  27.   #to lookup categories.dat, we need to know the generic name of the package, which may be different from pkg name...
  28.   #db entry format: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  29.   DBNAMEONLY="$(echo -n "$DB_ENTRY" | cut -f 2 -d '|')"
  30.   DBPATH="$(echo -n "$DB_ENTRY" | cut -f 7 -d '|')"
  31.   DBCOMPILEDDISTRO="$(echo -n "$DB_ENTRY" | cut -f 11 -d '|')"
  32.   [ ! "$DBCOMPILEDDISTRO" ] && DBCOMPILEDDISTRO='puppy' #any name will do here.
  33.   case $DBCOMPILEDDISTRO in
  34.    debian|devuan|ubuntu|raspbian)
  35.     if [ "$DBPATH" ];then #precaution
  36.      xNAMEONLY="$(basename ${DBPATH})"
  37.     else
  38.      xNAMEONLY="$DBNAMEONLY"
  39.     fi
  40.    ;;
  41.    *) xNAMEONLY="$DBNAMEONLY" ;;
  42.   esac
  43.   xnPTN=" ${xNAMEONLY} "
  44.   #130126 categories.dat format changed slightly... 130219 ignore case...
  45.   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 "
  46.   if [ "$CATVARIABLE" ];then #ex: Graphic-camera
  47.    xCATEGORY="X-${CATVARIABLE}"
  48.    cPATTERN="s%^Categories=.*%Categories=${xCATEGORY}%" #121120
  49.    CATFOUND="yes"
  50.    CATDONE='yes'
  51.   fi
  52.  fi
  53. fi
  54.  
  55. for ONEDOT in `grep 'share/applications/.*\.desktop$' /root/.packages/${DLPKG_NAME}.files | tr '\n' ' '` #121119 exclude other strange .desktop files.
  56. do
  57.  #120901 get rid of param on end of Exec, ex: Exec=gimp-2.8 %U
  58.  #sed -i -e 's/\(^Exec=[^%]*\).*/\1/' -e 's/ *$//' $ONEDOT #'s/\(^Exec=[^ ]*\).*/\1/'
  59.  #121015 01micko: alternative that may work better...
  60.  for PARMATER in u U f F #refer:  http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
  61.  do
  62.   sed -i "s/ %${PARMATER}//" $ONEDOT
  63.  done
  64.  
  65.  #w478 find if category is already valid (see also 2createpackages)..
  66.  if [ "$CATDONE" = "no" ];then #121119
  67.   CATFOUND="no"
  68.   for ONEORIGCAT in `cat $ONEDOT | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' ' | rev` #search in reverse order.
  69.   do
  70.    ONEORIGCAT="`echo -n "$ONEORIGCAT" | rev`" #restore rev of one word.
  71.    oocPATTERN=' '"$ONEORIGCAT"' '
  72.    [ "`echo "$PUPHIERARCHY" | tr -s ' ' | grep "$tPATTERN" | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
  73.    #got a problem with sylpheed, "Categories=GTK;Network;Email;News;" this displays in both Network and Internet menus...
  74.    if [ "$CATFOUND" = "yes" ];then
  75.     cPATTERN="s%^Categories=.*%Categories=${ONEORIGCAT}%"
  76.     break
  77.    fi
  78.   done
  79.   #121109 above may fail, as DB_category field may not match that in .desktop file, so leave out that $tPATTERN match in $PUPHIERARCHY...
  80.   if [ "$CATFOUND" = "no" ];then
  81.    for ONEORIGCAT in `cat $ONEDOT | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' ' | rev` #search in reverse order.
  82.    do
  83.     ONEORIGCAT="`echo -n "$ONEORIGCAT" | rev`" #restore rev of one word.
  84.     oocPATTERN=' '"$ONEORIGCAT"' '
  85.     [ "`echo "$PUPHIERARCHY" | tr -s ' ' | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
  86.     #got a problem with sylpheed, "Categories=GTK;Network;Email;News;" this displays in both Network and Internet menus...
  87.     if [ "$CATFOUND" = "yes" ];then
  88.      cPATTERN="s%^Categories=.*%Categories=${ONEORIGCAT}%"
  89.      break
  90.     fi
  91.    done
  92.   fi
  93.  fi
  94.  sed -i -e "$cPATTERN" $ONEDOT #fix Categories= entry.
  95.  
  96.  #w019 does the icon exist?...
  97.  ICON="`grep '^Icon=' $ONEDOT | cut -f 2 -d '='`"
  98.  if [ "$ICON" != "" ];then
  99.   [ -e "$ICON" ] && continue #it may have a hardcoded path.
  100.   ICONBASE="`basename "$ICON"`"
  101.   #110706 fix icon entry in .desktop... 110821 improve...
  102.   #first search where jwm looks for icons... 111207...
  103.   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`"
  104.   if [ "$FNDICON" ];then
  105.    ICONNAMEONLY="`basename $FNDICON`"
  106.    iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
  107.    sed -i -e "$iPTN" $ONEDOT
  108.    continue
  109.   else
  110.    #look elsewhere... 111207...
  111.    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`"
  112.    #111207 look further afield, ex parole pkg has /usr/share/parole/pixmaps/parole.png...
  113.    [ ! "$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`"
  114.    #111207 getting desperate...
  115.    [ ! "$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`"
  116.    if [ "$FNDICON" ];then
  117.     ICONNAMEONLY="`basename "$FNDICON"`"
  118.     ln -snf "$FNDICON" /usr/share/pixmaps/${ICONNAMEONLY}
  119.     iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
  120.     sed -i -e "$iPTN" $ONEDOT
  121.     continue
  122.    fi
  123.   fi
  124.   #substitute a default icon...
  125.   sed -i -e "$iPATTERN" $ONEDOT #note, ONEDOT is name of .desktop file.
  126.  fi
  127.  
  128.  fi
  129.  
  130.  #120926 if a langpack installed, it will have /usr/share/applications.in (see /usr/sbin/momanager, /usr/share/doc/langpack-template/pinstall.sh).
  131.  ABASEDESKTOP="`basename $ONEDOT`"
  132.  ADIRDESKTOP="`dirname $ONEDOT`"
  133.  if [ -f /usr/share/applications.in/${ABASEDESKTOP} ];then
  134.   TARGETLANG="`echo -n $LANG_USER | cut -f 1 -d '_'`" #ex: de
  135.   tlPTN="^Name\[${TARGETLANG}\]"
  136.   if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  137.    if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  138.     #aaargh, these accursed back-slashes! ....
  139.     INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  140.     sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  141.    fi
  142.   fi
  143.   #do same for Comment field...
  144.   tlPTN="^Comment\[${TARGETLANG}\]"
  145.   if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  146.    if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  147.     #aaargh, these accursed back-slashes! ....
  148.     INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  149.     sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  150.    fi
  151.   fi
  152.   #well, i suppose need this too...
  153.   TARGETLANG="`echo -n $LANG_USER | cut -f 1 -d '.'`" #ex: de_DE
  154.   tlPTN="^Name\[${TARGETLANG}\]"
  155.   if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  156.    if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  157.     #aaargh, these accursed back-slashes! ....
  158.     INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  159.     sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  160.    fi
  161.   fi
  162.   #do same for Comment field...
  163.   tlPTN="^Comment\[${TARGETLANG}\]"
  164.   if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  165.    if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  166.     #aaargh, these accursed back-slashes! ....
  167.     INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  168.     sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  169.    fi
  170.   fi
  171.  fi
  172.  
  173. done
Add Comment
Please, Sign In to add comment