Tiny Core Linux

Tiny Core Base => TCB Bugs => Topic started by: andyj on January 01, 2021, 07:00:18 AM

Title: version script
Post by: andyj on January 01, 2021, 07:00:18 AM
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: [Select]
--- /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"

This doesn't help me going back, but at least it would cover all the new versions.
Title: Re: version script
Post by: Rich on January 01, 2021, 07:12:22 AM
Hi andyj
You know  /etc/init.d/tc-functions  provides that function:
Code: [Select]
tc@E310:~$ . /etc/init.d/tc-functions; echo $(getMajorVer)
10
tc@E310:~$
Title: Re: version script
Post by: andyj on January 01, 2021, 08:53:24 AM
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: [Select]
getMajorVer() {
awk '{printf "%d", $1}' /usr/share/doc/tc/release.txt
}

to

Code: [Select]
getMajorVer() {
version -m
}

Lets update both /usr/bin/version and /etc/init.d/tc-functions.
Title: Re: version script
Post by: Rich on January 01, 2021, 09:28:55 AM
Hi andyj
I was looking for a way to do it with less code, not more. ...
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?
Title: Re: version script
Post by: andyj on January 01, 2021, 11:02:46 AM
/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: [Select]
--- 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`

tc@box:~$ diff version.orig /usr/bin/version
Code: [Select]
--- 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

Yes, I used the relatively new and more standard /etc/os-release instead of the classic TC specific /usr/share/doc/tc/release.txt.
Title: Re: version script
Post by: Rich on January 01, 2021, 12:16:00 PM
Hi andyj
Very nice. I think that's a much cleaner solution. I would say wait and see if curaga or Juanito have comments and
express interest in a patch.
Title: Re: version script
Post by: curaga on January 01, 2021, 11:22:20 PM
Ok to me.
Title: Re: version script
Post by: Rich on January 02, 2021, 08:44:54 AM
Hi andyj
Unless someone else objects, you should submit your patches as files so they can be incorporated in the next release.
I'm not sure if they should be attached to this thread, submitted to:
http://patches.tinycorelinux.net/
or through github.
Title: Re: version script
Post by: Juanito on January 02, 2021, 09:09:27 AM
GitHub would be better  :)
Title: Re: version script
Post by: andyj on January 02, 2021, 03:33:58 PM
I didn't have any success getting any patches in through github, so here they are.
Title: Re: version script
Post by: Juanito on January 03, 2021, 12:57:25 AM
added to git - thanks

Edit: I see password authentication is depreciated  :(
Title: Re: version script
Post by: Paul_123 on January 09, 2021, 10:07:24 AM
Juanito, you can still use https, you just need to create a Personal Access Token, instead of your password.  (Its under developer settings)

I was also reviewing the version changes in git.  tc-functions is now pointing to /etc/os-release to get it's version. However, tc-config is still looking at /usr/share/tc/release.txt.  Would it not make more sense to point everything at os-release, and then remove /usr/share/tc/release.txt?

Title: Re: version script
Post by: Juanito on January 10, 2021, 02:50:14 AM
It would seem to make more sense to use one location for the version - is /usr/share/tc/release.txt used anywhere else?
Title: Re: version script
Post by: Paul_123 on January 10, 2021, 05:33:09 AM
I did a grep in Corescripts, and did non see any, other than tc-config.

I would hope any scripts in extensions use tc-functions.
Title: Re: version script
Post by: Rich on January 10, 2021, 05:51:16 AM
Hi Juanito
I ran a grep on all directories (except /proc and /sys) for "release.txt" on my TC10 x86 machine and found only the
3 instances currently mentioned.
Title: Re: version script
Post by: Juanito on January 10, 2021, 06:16:54 AM
OK - could somebody submit a patch/pull request to tc git?
Title: Re: version script
Post by: Paul_123 on January 10, 2021, 08:39:11 AM
Sure will.  I'm going to update the picore Branch too.
Title: Re: version script
Post by: andyj on January 10, 2021, 02:13:05 PM
Maybe we should make /usr/share/doc/tc/release.txt a symlink to /etc/os-release for TC 12 only, so people who might be using it can transition?
Title: Re: version script
Post by: curaga on January 11, 2021, 12:04:08 AM
The format is different, so a symlink would break things anyway.
Title: Re: version script
Post by: andyj on January 11, 2021, 05:04:11 AM
It will break somebody's scripts somehow regardless. The trick would be to try to break it in a nice way, if there is such a thing.
Title: Re: version script
Post by: Paul_123 on January 11, 2021, 07:46:57 AM
Well nothing will happen until a new release occurs.  So it's not like running tc-update will break things.