WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12915
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: 808
  • ~.~
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: 12915
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: 12915
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.

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 808
  • ~.~
Re: Proposed update to tce-status script
« Reply #4 on: July 19, 2026, 06:52:22 PM »
hi rich

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

Quote
$md5sum ./tce-status3
adf7917a2c010870f403c38c9d274247  ./tce-status3

$wc  ./tce-status3
  66  199 1307 ./tce-status3


md5# of the one i previously saved and just tested  appears to be the same as the one i just re-downloaded

though
...for some reason ( perhaps likely im missing something!... )

Code: [Select]
$ for n in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do  ./tce-status3 -i $n* ; done | nl|tail -n 1
    76 zstd-dev


Quote
$./tce-status3 -i | nl

includes

   128   readline
   129   sed
   130   shared-mime-info
   131   sqlite3
   132   udev-lib
   133   util-linux_base-dev
...
   140   zstd-dev


however for some reason

Quote
tc@box:~$ ./tce-status3 -i o*
openssh
openssl
openssl-1.1.1
openssl-dev
tc@box:~$ ./tce-status3 -i s*
tc@box:~$ ./tce-status3 -i s*
tc@box:~$ ./tce-status3 -i "s*"
tc@box:~$ ./tce-status3 -i "s"
tc@box:~$ ./tce-status3 -i s
tc@box:~$ ./tce-status3 -i u*
udev-lib
util-linux_base-dev


weirdly
>./tce-status3 -i s*
*no results*

but
>./tce-status3 -i sq*
sqlite3

idk why? ( maybe i broke something ?)

& ftr
Quote
ls -d /tmp/tcloop/s*
/tmp/tcloop/sed/  /tmp/tcloop/shared-mime-info/  /tmp/tcloop/sqlite3/

ls /usr/local/tce.installed/s*
/usr/local/tce.installed/sed  /usr/local/tce.installed/shared-mime-info  /usr/local/tce.installed/sqlite3


it appears *for what ever reason* not possible to match "s*" or "l*"
... on picore 14.1

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 808
  • ~.~
Re: Proposed update to tce-status script
« Reply #5 on: July 19, 2026, 06:58:48 PM »
fwiw
Code: [Select]
$diff -u ./tce-status3 ./tce-status3-mod
--- ./tce-status3 2026-07-13 17:28:06.419822013 +0000
+++ ./tce-status3-mod 2026-07-19 22:31:35.503617313 +0000
@@ -37,20 +37,16 @@
 }
 
 Find() {
- Do="installed"
- [ "$1" == "-u" ] && Do="uninstalled"
 
  Param=${@:2}
-
- while IFS= read -r Ext
+       
+ [ $# -lt 2 ] && cat - ||  while IFS= read -r Ext
  do
  for P in $Param
  do
  case ${Ext%.tcz} in $P) echo ${Ext%.tcz};; esac
  done
- done << EOF
- $($Do)
-EOF
+ done
 }
 
 [ -z "$1" ] && Help
@@ -58,8 +54,8 @@
 while getopts iuoh OPTION
 do
  case ${OPTION} in
- i) [ $# -lt 2 ] && installed || Find "$@" ;;
- u) [ $# -lt 2 ] && uninstalled || Find "$@" ;;
+ i) installed | Find "$@" ;;
+ u) uninstalled | Find "$@" ;;
  o) orphaned ;;
  *) Help ;;
  esac


pipeing the input to Find and cating stdin if no extra args
removes a little of the "if args and x or y"  repetition
and the need for the heardoc and "$( )"

Quote
wc  ./tce-status3-mod
  62  184 1235 ./tce-status3-mod

---
oh and thanks for the
long winded reply.

imho it would be informative linking to that explanation of the process / reasoning
in the script / and or summarizing it in the wiki
« Last Edit: July 19, 2026, 07:08:37 PM by mocore »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12915
Re: Proposed update to tce-status script
« Reply #6 on: Today at 12:18:44 AM »
Hi mocore
... idk why? ( maybe i broke something ?) ...
No, you didn't break anything. It's a bug in the script.

It's in Find(). The asterisk is being expanded against the current
directory contents, none of which match any tcz names.

Add:
Code: [Select]
echo "$@"to the beginning of Find() and run:
Code: [Select]
./tce-status3 -i s*Then you should see what I mean.


Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 808
  • ~.~
Re: Proposed update to tce-status script
« Reply #7 on: Today at 05:54:47 AM »
hi rich
Add:
Code: [Select]
echo "$@"to the beginning of Find()

ahh subtle ... it fails because i have files that match "s*" and "l*" in the current directory 

any workaround ?

quoting or escaping "\*" appears to be ineffective =[
...

i have to admit on first reading Find()
i recognized the loop constructs but the globing
was not straightforward for me to parse
 
cases like this are a good example of how *sometimes*
such constructs can be tricky ( at least to me) to reason about
*generally* out side of testing in some specific env/context
(..and even then they can appear unreasonable to reason about )

oh globbits

« Last Edit: Today at 06:02:13 AM by mocore »

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 808
  • ~.~