WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: version script  (Read 7651 times)

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
version script
« on: January 01, 2021, 10: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.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11673
Re: version script
« Reply #1 on: January 01, 2021, 10: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: 1036
Re: version script
« Reply #2 on: January 01, 2021, 11: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.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11673
Re: version script
« Reply #3 on: January 01, 2021, 12:28:55 PM »
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: 1036
Re: version script
« Reply #4 on: January 01, 2021, 02:02:46 PM »
/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.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11673
Re: version script
« Reply #5 on: January 01, 2021, 03: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.

Online curaga

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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11673
Re: version script
« Reply #7 on: January 02, 2021, 11: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: 14831
Re: version script
« Reply #8 on: January 02, 2021, 12:09:27 PM »
GitHub would be better  :)

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: version script
« Reply #9 on: January 02, 2021, 06: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: 14831
Re: version script
« Reply #10 on: January 03, 2021, 03:57:25 AM »
added to git - thanks

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

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1252
Re: version script
« Reply #11 on: January 09, 2021, 01:07:24 PM »
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: 14831
Re: version script
« Reply #12 on: January 10, 2021, 05: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: 1252
Re: version script
« Reply #13 on: January 10, 2021, 08: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.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11673
Re: version script
« Reply #14 on: January 10, 2021, 08: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.