General TC > Programming & Scripting - Unofficial

tce with comments + explicit path busybox applets, in future Tc14?

(1/3) > >>

nick65go:
Hi, /usr/bin/tce depends on scripts /usr/bin/{search.sh, provides.sh, select, tce-size}.
I explicitly replaced all the busybox commands with their full path (/bin, /usr/bin), by that I eliminated the need for

--- Code: ---. /etc/init.d/tc-functions && useBusybox
--- End code ---

There is now no need to call /source tc-config (18497 bytes) by 4 times;
yes, I know was already in RAM, but I least I documented who call whom, which minimum busybox applets are in need for each script, etc. The speed could not be lower than original scripts.

The new scripts remain very small (less than 4KB -- as page cache): tce (2753 Bytes), tce-size (2499 bytes), select (1353 bytes), provides.sh (945 bytes), search.sh (921 bytes).

Also I commented each script, in its top, with which busybox was explicitly used. Sample:

--- Code: ---# /usr/bin/tce call scripts from /usr/bin/{search.sh, provides.sh, select, tce-size}
# only used: /usr/bin/id, /bin/mktemp

# /usr/bin/search.sh only used: /bin/gunzip, /bin/date, /bin/awk

# provides.sh only used tc-functions:getMirror, /usr/bin/wget, /usr/bin/zsync, /bin/awk

# /usr/bin/select only used /bin/awk

# /usr/bin/tce-size only used: /bin/sed, /usr/bin/sort, /usr/bin/uniq,
# /bin/grep, /usr/bin/awk, /bin/gunzip, /bin/date, /bin/touch
--- End code ---

Is any interest to have something like these (comments + explicit path busybox applets) in future Tc14?

EDIT: for provides.sh I did a substitution like:
--- Code: ---# getMirror from tc-functions
getBuild() {
ARCH=`uname -m`
case ${ARCH} in
    armv6l) echo "armv6" ;;
    armv7l) echo "armv7" ;;
    aarch64) echo "aarch64" ;;
    i686)   echo "x86" ;;
    x86_64) [ -f /lib/ld-linux-x86-64.so.2 ] && echo "x86_64" || echo "x86" ;;
    *)      echo "x86" ;;
esac
}
BUILD=$(getBuild)

verid=$(grep '^VERSION_ID=' /etc/os-release)
verid=${verid#*=}
getMajorVer=${verid%.*}

read MIRROR < /opt/tcemirror
MIRROR="${MIRROR%/}/$(getMajorVer).x/$BUILD/tcz"
--- End code ---
and for tce one like:
--- Code: ---# checknotroot from tc-functions
 if [ `/usr/bin/id -u` -eq 0 ]; then
   echo "Don't run this as root." >&2
   exit 1
 fi
--- End code ---
to avoid full tc-config sourcing for just few bytes functions.

hiro:
the point of PATH is to not burden a programmer or user with absolute paths.
i'd rather make the computer do something useful for me than micromanage such things.

nick65go:
@Hiro: Agree it! I know the role of PATH.
The point of the exercise (learning / fun) was to understand the main logic, why few of busybox functions would need to be sourced separably by usebusybox(). I think even GNU tools will behave similar, taken into account these functions do not use many parameters (one or two) in these specific scripts.

These TC scripts are 2 .. 10 years old, and will stay like this for many years maybe. Then, there are only few scripts (less than 30?) so will be one time job, to do not need reverse-engineering /understand it again, without documentation.
PS: the specific TC scripts make TC unique. So "porting" them to any other linux base, can be beneficial, to quickly grab (from a mirror) any tcz+deps and run them, from any arbitrary folders, etc.

hiro:
well, you have to draw a line somewhere.

whether it's complexity in the code, numer of lines, long lines, wrapped lines, documentation, long names, absolute names, unneeded verbosity, syntactical noise, they all comes with a cost. you need a balance.

every extra character needs a little extra time for a human to parse (even if it's the same for a computer).

i think this goes too far. but that's just my opinion :)

GNUser:

--- Quote from: nick65go on February 25, 2023, 04:57:04 PM ---to quickly grab (from a mirror) any tcz+deps

--- End quote ---
Hi nick65go. For this specific task, Rich wrote a nice script that can be used on any linux distro. The script is called FetchExt.sh and can be downloaded from here.

Navigation

[0] Message Index

[#] Next page

Go to full version