Listing all used/unused Busybox applets

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Listing all used/unused Busybox applets

#1 Post by MochiMoppel »

The file /bin/busybox contains dozens of utilities (busybox calls them applets) which can all be executed in one way or another, no matter if their more powerful GNU cousins are installed or not.

If no GNU equivalents exist, busybox applets are normally installed as symlink, e.g. /usr/bin/beep => /bin/busybox.

If GNU equivalents exist, busybox symlinked applets may still exist but with a -BB-NOTUSED suffix, making it impossible to invoke the busybox applet by just using its original name.

A few applets have equivalents in bash shell builtins or keywords (e.g. the echo command). Bash will always use its builtin utilities instead of using busybox or GNU applets (unless builtins are deactivated, but there is hardly a good reason to do that). Still busybox links are usually provided as well (e.g. /bin/echo => /bin/busybox) and the user *can* use them if he really needs to.

Above 3 possibilities should account for all applets compiled into busybox and the command "type -a appletname" should find at least one executable location for each applet. If not - and this is the reason why I created the script - the applet can not be invoked merely by its name. The command "which appletname" will produce no result and it appears as if the applet is not installed. I experienced this with the very useful strings utility. Only when checking the busybox list of all included applets I realized that it's there.

I wanted to know if more such "stealth utilities" exist.
The script lists all busybox applet names in the 2nd column and indicates in the 1st column if installed as

builtin   bash builtin
keyword bash keyword
bb    symlink to busybox
gnu    GNU utility
script  script, usually a wrapper for either bb or gnu
BBNU  symlink to busybox with -BB-NOTUSED suffix
FULL  GNU utility or symlink to GNU utility with -FULL suffix
-----  "stealth" applet which can't be invoked merely by its name

Script execution takes a few second and outputs to leafpad. Be patient :wink:

Code: Select all

#!/bin/bash
LANG=C LF=$'\n' TB=$'\t' IFS=$LF SEP=..............
OUT="Type${TB}Applets in current $(/bin/busybox | grep -om1 '^[^(]*')
------------------------------------------"
gxmessage -fn 'bold 14' -bg forestgreen -fg white -bu '' -bo -c  $'\n   Please wait ... ' &
for applet in $(busybox --list); do
  locations=$(type -a ${applet} ${applet}-FULL ${applet}-BB-NOTUSED 2>&1)
  for item in $locations; do
    unset category hint mime real path
    case $item in
     *[DL]:*) continue ;;                   #ex: "bash: type: echo-FULL: not found"
  *$applet:*) category=----                 #ex: "bash: type: strings: not found"
              hint="${SEP:${#applet}}( \"$applet\" not in \$PATH )" ;;
    *'is /'*) path=/${item#*/}              #ex: "echo is /bin/echo"
              real=$(realpath "$path")
              mime=$(file "$real")
              case $path$mime in
              *-FULL*   ) category=FULL   ;;
              *-NOTUSED*) category=BBNU   ;;
              *busybox* ) category=bb     ;;
              *script*  ) category=script ;;
              *         ) category=gnu    ;;
              esac
              [[ $real = $path ]] && hint=$path || hint="$path => $real"
              hint="${SEP:${#applet}}$hint" ;;
    *'is a'*) category=${item##* } ;;       #ex: "echo is a shell builtin"
           *) continue ;;
    esac
    OUT="${OUT}${LF}$category${TB}$applet $hint"
  done
done
busybox pkill -n gxmessage
echo "$OUT" |awk 'NR<=3{v=$2;print;next} v!=$2{print ""} v=$2{print}' | leafpad &
PS: Above script will not work with busybox versions older than 1.17.0 (2010-7-6) as they lack the --list option (see following post). The script might work with any version when replacing
   $(busybox --list)
with
   $(busybox | sed '1,/:$/d' | tr -s ' \t,' '\n')

[Update 2019-2-28]: Now also lists scripts with same name as applet, GNU utilities renamed as appletname-FULL and busybox symlinks named appletname-BB-NOTUSED. Adds "Wait" message and blank lines for better readability. Outputs to leafpad to allow search.
Attachments
busybox_applets.png
Updated script now contains more types and outputs to leafpad instead of gxmessage
(41.97 KiB) Downloaded 520 times
Last edited by MochiMoppel on Thu 28 Feb 2019, 12:44, edited 3 times in total.

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#2 Post by tallboy »

Thank you for the script, MochiMoppel, it will be very useful.
Hmm, is applet a word that BB have used in earlier versions too, or is it just list? It seems list is not in the earlier version. If I want a list of applets, I only use the command busybox, whitout options. But that doesn't work in the script. I can search for bb-notused in pFind, but the result does not include builtins.
Attachments
bb-list-result.jpg
(21.99 KiB) Downloaded 444 times
True freedom is a live Puppy on a multisession CD/DVD.

oldaolgeezer
Posts: 64
Joined: Sun 03 Dec 2006, 19:34

Listing all used/unused Busybox applets

#3 Post by oldaolgeezer »

MochiMoppel, I also thank you for the interesting script.

MochiMoppel's script "Listing all used/unused Busybox applets"
shows in my xenial-7.5 (32 bit) that the "strings" command is only available
via busybox as:
busybox strings foo.txt

(not as: strings foo.txt )


So, my question is why are some puppy commands available via busybox but not linked from /usr/bin ?

Thanks for any comments.
Attachments
strings_only_in_busybox.png
(32.61 KiB) Downloaded 400 times

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

Re: Listing all used/unused Busybox applets

#4 Post by rufwoof »

oldaolgeezer wrote:So, my question is why are some puppy commands available via busybox but not linked from /usr/bin ?
I guess a similar reason to why your version of busybox has telnet, but mine doesn't. Developers drop in a version of busybox, maybe a upgraded version that contains different sets than before, but don't bother going through the laborious process of ensuring all of the commands (applets) links are updated within /bin

I believe that busybox is used to 'get things going' but the busybox commands are more limited than full(er) versions, so in some cases once things have got going may have fuller versions replacing (being used instead of) the busybox command/applet version. Somewhat like /bin (/sbin) and /usr/bin (/usr/sbin) ... where /bin (/sbin) contains the statics that are needed to boot the system (prior to /usr being mounted/available) and /usr/bin (/usr/sbin) contain the binaries once the system is up (/usr available).
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

MochiMoppei,

With all due respect, IMO, that is another waste of your formidable talent.
But it's yours to waste, not mine.

As for me, when I need this type of information, I type the following in terminal:

Code: Select all

ls --file-type -Algorh | awk '$NF ~ /busybox/ { print $7,$8,$9 }' | sort | more
If I need it more that once, I recall it with the up arrow in terminal.

(Edit: $NF; thanks to Fabrice for noticing.)

Best regards nevertheless.
Attachments
busybox-applets.jpg
Beginning of list created by above one-liner.
(161.11 KiB) Downloaded 339 times
Last edited by musher0 on Tue 26 Feb 2019, 08:24, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#6 Post by fabrice_035 »

Hello,

@musher0
Image

Code: Select all

root# awk --version
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)
Regard.
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#7 Post by some1 »

@fabrice_035:
Nothing to do with the awk-version,
just more crap and mind-pollution from
Musher0.Wasting everybodys time.


@Musher0: Please stop posting in threads in the Programming Section,
which you have not created.

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#8 Post by some1 »

@MochiMoppel: Nice. Try LANG=C - gave me 30%.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Listing all used/unused Busybox applets

#9 Post by MochiMoppel »

some1 wrote: Try LANG=C - gave me 30%.
Thanks. Here real time closer to 20% but CPU time 50%. I don't like the current performance, and things will get worse because I have to add more types. Naming everything that is not busybox as "gnu" is wrong. Could be that this "gnu" is not a GNU binary at all. Could be a script....linking to busybox :cry: Oh boy.
oldaolgeezer wrote: my question is why are some puppy commands available via busybox but not linked from /usr/bin ?.
Good question. Same as mine :lol: Let's call it bad system configuration.
For example I have 2 files, the first being a GNU binary, the second a symlink to busybox
/bin/grep
/bin/grep-BB-NOTUSED

The wisdom of these xxx-BB-NOTUSED files aside, this keeps both files neatly together. I see BB-NOTUSED as a mere reminder that a busybox applet exists.

In the case of /usr/bin/strings-BB-NOTUSED no GNU file exists, which would call for naming the bb symlink /usr/bin/strings. That's the way it is normally done. Why not here? I think the main reason is that GNU strings does exist. It is included in the devx sfs. If you load this sfs you will see
/usr/bin/strings
/usr/bin/strings-BB-NOTUSED
If the bb symlink in the main sfs would be named /usr/bin/strings, the GNU binary /usr/bin/strings of the devx sfs would not be "seen" by the system and would not be usable.

There would be several ways to avoid such conflicts. The cleanest way would be move the GNU binary to the main sfs. It's a tiny file and it is very useful even for non developers. Another way would be to keep conflicting files in different paths, putting the fully featured GNU utilities into a path with high priority and the busybox versions into a path with lower priority as a fallback (or is it backstop?).

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#10 Post by musher0 »

fabrice_035 wrote:Hello,

@musher0
Image

Code: Select all

root# awk --version
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)
Regard.
Corrected. Thanks for noticing.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
perdido
Posts: 1528
Joined: Mon 09 Dec 2013, 16:29
Location: ¿Altair IV , Just north of Eeyore Junction.?

#11 Post by perdido »

some1 wrote: Nothing to do with the awk-version,
just more crap and mind-pollution from
Musher0.Wasting everybodys time.


@Musher0: Please stop posting in threads in the Programming Section,
which you have not created.
+1

.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#12 Post by MochiMoppel »

I have updated my script (see first post for new code and explanation)

It now lists applet scripts and applet names suffixed with -FULL and/or -BB-NOTUSED.
When an applet is listed multiple times, the first entry in the list is the one that will be executed when invoked with just the applet name.

For example the screenshot shows that a user who enters just ps into a terminal will start a script (= first item in the list). A GNU utility exists but can only be directly executed by entering ps-FULL. Users who need to directly start the busybox applet would have to enter busybox ps. The file /bin/ps-BB-NOTUSED is linked to busybox but, as all -BB-NOTUSED symlinks, is not valid and will cause busybox to trigger an error when executed.

Since some applet names appear more than once I find the list easier to read with blank lines before each new applet name. Removing the awk statement will prevent blank line creation.
Attachments
busybox_applet_list.png
(54 KiB) Downloaded 158 times

Post Reply