WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: version script  (Read 1069 times)

Offline andyj

  • Hero Member
  • *****
  • Posts: 947
version script
« 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.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8818
Re: version script
« Reply #1 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:~$

Offline andyj

  • Hero Member
  • *****
  • Posts: 947
Re: version script
« Reply #2 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.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8818
Re: version script
« Reply #3 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?

Offline andyj

  • Hero Member
  • *****
  • Posts: 947
Re: version script
« Reply #4 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.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8818
Re: version script
« Reply #5 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.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10423
Re: version script
« Reply #6 on: January 01, 2021, 11:22:20 PM »
Ok to me.
The only barriers that can stop you are the ones you create yourself.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8818
Re: version script
« Reply #7 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.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12874
Re: version script
« Reply #8 on: January 02, 2021, 09:09:27 AM »
GitHub would be better  :)

Offline andyj

  • Hero Member
  • *****
  • Posts: 947
Re: version script
« Reply #9 on: January 02, 2021, 03:33:58 PM »
I didn't have any success getting any patches in through github, so here they are.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12874
Re: version script
« Reply #10 on: January 03, 2021, 12:57:25 AM »
added to git - thanks

Edit: I see password authentication is depreciated  :(
« Last Edit: January 03, 2021, 01:03:40 AM by Juanito »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 704
Re: version script
« Reply #11 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?


Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12874
Re: version script
« Reply #12 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?

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 704
Re: version script
« Reply #13 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.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8818
Re: version script
« Reply #14 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.