WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Proposal: improve provides.sh to wget provides.db.gz, instead of provides.db  (Read 2423 times)

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
the /usr/bin/provides.sh will try zsync the file, and if it fails then will download the not-compressed file:
Code: [Select]
TCEDIR="/etc/sysconfig/tcedir"
DB="provides.db"
if /usr/bin/zsync -i "$TCEDIR"/"$DB" -q "$MIRROR"/"$DB".zsync
then
    rm -f "$DB".zs-old
else
    /usr/bin/wget -O "$TCEDIR"/"$DB" "$MIRROR"/"$DB"
fi
FYI: provides.db is 22.1 MB, but provides.db.gz is 2.2 MB
« Last Edit: February 27, 2023, 02:14:35 AM by nick65go »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10974
This would be fine. Please make the change and send a patch.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
Hi, please find attached the new provides.sh and the
Code: [Select]
diff -ad provides.sh 2provides.sh > provides.diff
« Last Edit: February 27, 2023, 11:20:23 AM by nick65go »

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
hi curaga,

Please check the diff file. It does undesirable things IMO.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
Hi, if you agree with explicit path for busybox external applets, and to not source /etc/init.d/tc-functions (7.2 KB), then please find attached a tce-fetch.sh (880 bytes) and its diff
Code: [Select]
diff -ad tce-fetch.sh 2tce-fetch.sh > tce-fetch.diffI believe that any incompatible bash, gnu-tools will load in /usr/local/ so they will not influence explicit busybox functions from script.
« Last Edit: February 27, 2023, 11:43:16 AM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
Please check the diff file. It does undesirable things IMO.
I admit that I am not a programmer, so please help me to improve myself, by highlighting the "undesirable things" ; thanks for the feed-back.

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
I am not a programmer either.  ;)

So these are strictly IMO.

useBusybox tells the script to use BusyBox version of commands. This is important when people have downloaded GNU version of the command.

Adding the full path for commands is not the right thing to do. I know this is not consistent through out all the scripts, probably because of a missing useBusybox?

Do not copy functions from tc-functions. Fix the function in tc-functions if necessary.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
I found a mistake in initial provides.diff
- MIRROR="${MIRROR%/}/$(getMajorVer).x/$BUILD/tcz"
+ MIRROR="${MIRROR%/}/$getMajorVer.x/$BUILD/tcz"
Anyway, the idea was/IS to do not call external script/function of 7KB for a block of text of few bytes.
If the script fits in 4KB =page in RAM, what do I loose by "my method"? Used ONLY for these small scripts.
I wish any small script to be independent/portable outside tinycore. In general you are right to use complex function, but maybe not for a 400 -800 bytes script, come on  :P
FYI: is it correct that ANY new tcz (with bash, gnu tools, whatever) will be linked into /usr/local/bin, or /usr/local/sbin? So will NOT influence "my"/ these specific tc scripts which are without use_busybox.
« Last Edit: February 27, 2023, 01:16:11 PM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
Greg Erskine, may I have a joke, as between two non-programmers?
I have a A.sh script (1 KB) which needs to import / source a small function (10 bytes) from a B.sh (10 MB). Unfortunately this B.sh is scattered in100 pieces of 100 KB all over a rotation disk, not even in right order of pieces on disk to be read sequentially. How fast execution will my A.sh script archive?
So, not all the time we should play by the thumb / general rules (imposed by others on us) in any circumstances. Q.E.D.



Offline CNK

  • Full Member
  • ***
  • Posts: 249
In 2provides.sh:
Code: [Select]
DB=$DB.gz
if [ ! -f "$TCEDIR"/"DB" ]
/usr/bin/wget -O "$TCEDIR"/"$DB" "$MIRROR"/"$DB"
/bin/gunzip "$TCEDIR"/"DB"
fi

You missed the "$" before "DB" on the gunzip line and the test statement. Also it's pointless quoting "$DB" if you don't quote it where you append .gz on the end. Actually I sussest that you just add ".gz" on the end of the wget and gunzip lines and leave the DB variable itself alone. Plus there's no "then" statement after the "if".

I don't think you need to change other parts of the script for this purpose.

One separate problem that I have with the original provides.sh script is that read/write permission gets removed for the group (by the zsync command) whenever it's run, so only the user that owns the provides.db file can access it (it tries to download again via wget if another user runs provides.sh, because zsync can't read the existing file). Adding this at the end fixes the problem:
Code: [Select]
chmod g+rw "$TCEDIR"/"$DB"

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10974
- please keep other changes separate, one change per patch
- please use unified diffs (diff -u)

The change to full paths and avoiding the include would not be accepted.

CNK: that permissions change would be fine.
The only barriers that can stop you are the ones you create yourself.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10974
Regarding the speed of including tc-functions, it will be in cache after the first use. So its inclusion is very fast, and removing it does not bring significant benefits.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 805
@curaga: yes, it is crystal clear, i understood.
@CNK please take over the patch, thank you.

Offline CNK

  • Full Member
  • ***
  • Posts: 249
It turns out that zsync has this logic all built in already, so the current script already downloads the provides.db.gz file and decompresses it if /etc/sysconfig/tcedir/provides.db doesn't exist. It explains itself if you remove "-q" from the zsync command. So I guess the wget part is just some backup in case the zsync program fails, or provides.db.zsync is missing on the mirror?

Code: [Select]
$ rm /etc/sysconfig/tcedir/provides.db
$ ./provides-git.sh fltk
#################### 100.0% 29.4 kBps DONE     

open: No such file or directory
not using seed file /etc/sysconfig/tcedir/provides.db
Read /etc/sysconfig/tcedir/provides.db. Target 0.0% complete.     
No relevent local data found - I will be downloading the whole file. If that's not what you want, CTRL-C out. You should specify the local file is the old version of the file to download with -i (you might have to decompress it with gzip -d first). Or perhaps you just have no data that helps download the file
downloading from http://mirrors.dotsrc.org/tinycorelinux/13.x/x86_64/tcz/provides.db.gz:
#################### 100.0% 363.5 kBps DONE     

verifying download...checksum matches OK
used 0 local, fetched 2261741
fltk-1.3-dev.tcz
fltk-1.3.tcz
fltk-full-dev.tcz
fltk-full-man.tcz
fltk-full.tcz
fltk-xft-dev.tcz
fltk-xft.tcz
pinentry-fltk.tcz
webkitfltk-dev.tcz
Xlibs.tcz

Anyway, attached is a modified version where wget also downloads the gzip compressed version (I had to sabotage zsync to test it), and my chmod line is also added at the end. The patch is for the current version in the git repo.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10974
Applied, thanks.
The only barriers that can stop you are the ones you create yourself.