WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Moving scripts into the base  (Read 148 times)

Offline polikuo

  • Hero Member
  • *****
  • Posts: 726
Moving scripts into the base
« on: November 21, 2024, 12:44:51 PM »
While coding, I can't help to find the script desktop.sh to be limited.

For example, on aarch64, there's an extension called non-daw.tcz.
It has 5 desktop files, but due to the nature of the way tce-load act, only non-daw.desktop will be processed.

So I decide to rewrite it, it should be backward compatible.
Instead of assigning, this script scans for newer files.
Code: [Select]
#!/bin/sh
# (c) polikuo 2024
# At the time of writing, desktop.sh is only called by /usr/bin/tce-load
# The old script always treats $1 as the name of the desktop file
# However, sometimes extensions can come with multiple desktop files
# Sometimes, program name doesn't match with extension name... etc
# This script scans for new desktop files every time tce-load is called

FREEDESK=$(echo /usr/local/share/applications/*.desktop)
TIMEMARK="/tmp/appserr"

LIST=$(find $FREEDESK -newer $TIMEMARK |
  grep -v '/usr/local/share/applications/tinycore-' |
  grep -v '~[1-9][1-9]*.desktop'
)

DESKTOP=$(cat /etc/sysconfig/desktop 2>/dev/null)
ICONS=$(cat /etc/sysconfig/icons 2>/dev/null)

D=$(which "${DESKTOP}_makemenu")
I=$(which "${ICONS}_update.sh")

if [ $(id -u) = 0 ]; then
  # root
  echo "Fatal error, desktop.sh should never be called by root." > /dev/tty
  exit 1
else
  # tcuser
  if [ "$LIST" ]; then
    for ENTRY in $LIST; do
      TARGET=$(basename $ENTRY)
      TARGET=${TARGET%.desktop}
      [ "$D" ] && eval $D $TARGET
      [ "$I" ] && eval $I $TARGET
    done
  fi
  # backward compatible
  B=$(echo "$LIST" | grep "/usr/local/share/applications/${1}.desktop")
  if [ -z "$B" ]; then
    [ "$D" ] && eval $D $1
    [ "$I" ] && eval $I $1
  fi
fi

I propose that this script should be merged into Core-scripts.
Juanito also points out that setupdesktop also acts similarly and should be merged as well.

Thoughts ?