WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Proposed update to tce-status script  (Read 175 times)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12909
Proposed update to tce-status script
« on: July 06, 2026, 12:20:37 AM »
In the past, I've used commands like this:
Code: [Select]
tce-status -i | grep ExtensionNameto see if an extension was installed.

I decided to add a Find (-f) option.

It allows searching for specific names as well as wildcards:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status -f openssl
openssl
tc@E310:~/tce-status$ ./tce-status -f openssl*
openssl
openssl-1.1.1

Or all extensions with 86 in their name:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status -f *86*
libXxf86dga
libXxf86vm
xf86-input-evdev
xf86-video-intel
xf86-video-vesa

It can also handle multiple extensions:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status -f Xprogs Xlib* grabber util*
Xprogs
Xlibs
grabber
util-linux
util-linux_base-dev


I also made the help message a little more user friendly.
Old message:
Code: [Select]
tc@E310:~/tce-status$ /usr/bin/tce-status
Usage tce-status -i | -u | -o

New Message:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status
Display installed (-i), uninstalled (-u), orphaned (-o), or find installed (-f name [ name ... ])

Also remove this unused variable definition:
Code: [Select]
TCELIST="/tmp/tcelist"
The size increased from 1115 to 1334 bytes.

A copy is attached to this post in case anyone wants to try it out
or review my changes. Comments would be appreciated.

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 807
  • ~.~
Re: Proposed update to tce-status script
« Reply #1 on: July 06, 2026, 12:29:35 PM »
>In the past, I've used commands like

on a bit of a tangent
this sentiment reminded me of
mount | grep -v loop ;
often
Code: [Select]
mnt() { mount | grep -v loop ; }
wrt: tce-status

i like the idea!

... if you shift on each original OPTION
..and.. test for *extra args*

concatenate the extra strings in to an or regexp
something like
while $# -gt 0
extra_arg_exp="$extra_arg_exp""|""$1"; shift

eg
Code: [Select]
echo -e "ab\nd\nz" | busybox grep -E "z|ab"
ab
z

then *you could* ( i think ** )

| grep -E  "$extra_arg_exp"

eg
Code: [Select]

f2(){
     [ $# -gt 0 ] && {
     export _exp="$( mk_exp "$@" )";
     grep -E "$_exp"
     } || \
     cat ;
}

mk_exp(){
while [ $# -gt 0 ] ; do [ -z "$1" ] ||  { [ -z "$s" ] && s="$1" || s="$s|$1" ; } ; shift; done ; echo "$s" ;
}

while getopts iuof OPTION
do
        case ${OPTION} in
                i) shift ;installed ;;
                u) shift uninstalled ;;
                o) shift orphaned ;;
                f) Find "$@";;
        esac
done | { shift $OPTIND; f2 "$@" ;}


Quote
sh  ./tce-status-mod -i ^z ^s
sed
shared-mime-info
sqlite3
zlib_base-dev
zstd
zstd-dev


so just filter *whatever* original output
like the first example
but also for each extra arg

was my initial impression
tbh

the shift's in the case are i think not needed
https://superuser.com/questions/541644/bash-how-to-use-while-shift-do-case-1-in
and i found about $OPTIND !
and i dont recall seeing
>Params=${@/-f/}
trick before !
« Last Edit: July 06, 2026, 12:37:50 PM by mocore »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12909
Re: Proposed update to tce-status script
« Reply #2 on: July 08, 2026, 12:54:22 PM »
Hi mocore
Sorry for the delay and this long winded reply.

I originally did something similar to  mk_exp()  to load the search
terms into a variable. Only I wanted to use built in commands so I
was using a case statement. Problem was the case statement won't
interpret the  or  symbol when it's embedded in a variable.

That lead me to a simpler solution, parse  /usr/local/tce.installed
directly. The  ls  command is not needed for this, so it can still
be done using only built in commands.

Like yours, I can also search for extensions beginning with z and s:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status -f z* s*
zip-unzip
zlib_base-dev
zstd
zsync
schumacher-clean-fonts
sed
shared-mime-info
slang
socat
sox
speex
sqlite3
sqlite3-bin
squashfs-tools
strace
submitqc
syslinux
but I don't need anchors to do it.

or starting with o and ending with l:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status -f o*l
openssl

That doesn't work with your version:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status2 -i o*l | wc -l
202

That's because grep needs the asterisk escaped with a period:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status2 -i o.*l
Xorg-7.7-lib
alsa-modules-4.19.10-tinycore
cdrtools
compiletc
coreutils
dosfstools
getlocale
glibc_i18n_locale
hicolor-icon-theme
inotify-tools
libopenal
mtools
net-tools
openldap
openssl
openssl-1.1.1
poppler07
poppler07-bin
postgresql-12-client
rollcall
squashfs-tools
twolame
xdotool
xf86-video-intel

Still not what I was looking for, you need anchors at both ends of the search term:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status2 -i ^o.*l$
openssl

Even adding  -w  (Match whole words only) to your grep command didn't quite fix it:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status2 -i o.*l
openssl
openssl-1.1.1
That second entry ends with a 1, not an l.

Piping the  while getopts  loop through your f2 function and testing for extra parameters
was clever, but I see other issues.

The 3 options output different data formats.
-i ExtensionName

-u ExtensionName.tcz

-o ExtensionName.tcz and/or ExtensionName.tcz.md5.txt and/or ExtensionName.tcz.dep
   It checks every *.tcz* file it finds.

I chose -i because:
1. I use it fairly often.
2. It shows up in the forum sometimes.
3. It was simple to implement, all of the info is in  /usr/local/tce.installed.

I avoided -u because:
1. I don't think I've ever used it.
2. I didn't have a plan for dealing with the 2 different data formats.
3. I was not aware of your clever piping trick.

I avoided -o because:
1. It can take a very long time to run (about 8 minutes on one of my machines).
2. If you use the wrong search filter, it can take a very long time to run again.

In light of your piping trick, I may take another look at -u.
I also feel the globbing patterns are easier for the average person to understand
than the regex patterns.

... and i dont recall seeing
>Params=${@/-f/}
trick before !
It can be quite useful:
Code: [Select]
   Find/replace pattern in variable
${var/Pattern/Replacement}   First match of Pattern, within var replaced with Replacement.
${var//Pattern/Replacement}  All matches of Pattern, within var replaced with Replacement.
${var/#Pattern/Replacement}  Prefix of var matches Pattern, Pattern  replaces Replacement.
${var/%Pattern/Replacement}  Suffix of var matches Pattern, Pattern  replaces Replacement.
# If Replacement is omitted, then Pattern is replaced by nothing, that is, deleted.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12909
Re: Proposed update to tce-status script
« Reply #3 on: July 09, 2026, 11:55:40 PM »
Hi mocore
I've modified tce-status to allow searching for installed extensions:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status3 -i *7.7*
Xorg-7.7
Xorg-7.7-3d
Xorg-7.7-bin
Xorg-7.7-lib

and uninstalled extensions:
Code: [Select]
tc@E310:~/tce-status$ ./tce-status3 -u *7.7*
Xorg-7.7-3d-dev
Xorg-7.7-dev

In both cases I output extension names without the .tcz extension.

If you run  tce-status3 -u  without a search term, it outputs the
extension names with the .tcz extension, just like it used to. That's
because  apps  uses  tce-status  and I didn't want to change its format.

I attached a copy to this post. Its size is 1307 bytes.