Tiny Core Base > TCB Bugs
version script
andyj:
It would be nice if there were a "major" version option in /usr/bin/version, that would just return 10, 11, etc. without the minor versions:
--- Code: ------ /usr/bin/version 2020-03-30 10:38:10.000000000 +0000
+++ version-m 2021-01-01 14:53:49.126637566 +0000
@@ -7,7 +7,7 @@
. /etc/init.d/tc-functions
useBusybox
RESULTS="$(cat /usr/share/doc/tc/release.txt)"
-while getopts cls OPTION
+while getopts clsm OPTION
do
case ${OPTION} in
c) LATEST=`wget -q -O - $(cat /opt/tcemirror)/latest-$(getBuild) 2>/dev/null`
@@ -27,6 +27,9 @@
s) echo "${RESULTS##*_}"
exit
;;
+ m) echo "${RESULTS%.*}"
+ exit
+ ;;
esac
done
echo "$RESULTS"
--- End code ---
This doesn't help me going back, but at least it would cover all the new versions.
Rich:
Hi andyj
You know /etc/init.d/tc-functions provides that function:
--- Code: ---tc@E310:~$ . /etc/init.d/tc-functions; echo $(getMajorVer)
10
tc@E310:~$
--- End code ---
andyj:
I was looking for a way to do it with less code, not more. Plus, this looks like some duplication of "version" parsing the release.txt file. Implementing the version patch, getMajorVer goes from:
--- Code: ---getMajorVer() {
awk '{printf "%d", $1}' /usr/share/doc/tc/release.txt
}
--- End code ---
to
--- Code: ---getMajorVer() {
version -m
}
--- End code ---
Lets update both /usr/bin/version and /etc/init.d/tc-functions.
Rich:
Hi andyj
--- Quote from: andyj on January 01, 2021, 11:53:24 AM ---I was looking for a way to do it with less code, not more. ...
--- End quote ---
No argument here. I was just pointing out that /usr/bin/version already sources /etc/init.d/tc-functions which already
provides getMajorVer.
I like your solution because it provides simplicity and consistency. Many scripts depend on tc-functions as a source of
common Tinycore functions. That leaves me with one question, should a file of common functions rely on an eternal script?
andyj:
/etc/init.d/tc-functions uses /usr/bin/autoscan-devices, which is a separate executable. Compiled code versus shell script for executables is splitting hairs, I would say. The version command sources /etc/init.d/tc-functions, so why not update tc-functions and version so the work is done in tc-functions and version is just a quick way of calling the particular function:
tc@box:~$ diff tc-functions.orig /etc/init.d/tc-functions
--- Code: ------ tc-functions.orig
+++ /etc/init.d/tc-functions
@@ -273,10 +273,15 @@
} ' "$1"
}
-getMajorVer() {
-awk '{printf "%d", $1}' /usr/share/doc/tc/release.txt
+getFullVer() {
+verid=$(grep VERSION_ID /etc/os-release)
+echo ${verid#*=}
}
+getMajorVer() {
+fullver=$(getFullVer)
+echo ${fullver%.*}
+}
getBuild() {
BUILD=`uname -m`
--- End code ---
tc@box:~$ diff version.orig /usr/bin/version
--- Code: ------ version.orig
+++ /usr/bin/version
@@ -6,8 +6,8 @@
. /etc/init.d/tc-functions
useBusybox
-RESULTS="$(cat /usr/share/doc/tc/release.txt)"
-while getopts cls OPTION
+RESULTS="$(getFullVer)"
+while getopts clsm OPTION
do
case ${OPTION} in
c) LATEST=`wget -q -O - $(cat /opt/tcemirror)/latest-$(getBuild) 2>/dev/null`
@@ -25,6 +25,9 @@
exit
;;
s) echo "${RESULTS##*_}"
+ exit
+ ;;
+ m) echo "$(getMajorVer)"
exit
;;
esac
--- End code ---
Yes, I used the relatively new and more standard /etc/os-release instead of the classic TC specific /usr/share/doc/tc/release.txt.
Navigation
[0] Message Index
[#] Next page
Go to full version