WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Script to download extensions+dependencies on other Linux distros  (Read 1687 times)

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 7049
This is my attempt to try to ease a situation that comes up on a regular basis:
I can't get the extension(s) I need because I can't get my wireless connection up.

After downloading the script make it executable:
Code: [Select]
sudo chmod 777 FetchExt.sh
Adjust these 3 variables in the script to match your requirements:
Code: [Select]
# Repository to download from
ADDR="http://repo.tinycorelinux.net"

# Tinycore version
TC="10.x"

# Processor architecture, current options are  x86  x86_64  armv6  armv7
ARCH="x86"

Place the script in its own directory to keep all downloads in one place. To run it, go to that directory and:
Code: [Select]
./FetchExt.sh ExtensionNameNote the leading  dot  and  slash. They are required because the directory is not in your systems PATH.

This should run on any Linux machine that has an Internet connection. I tried to avoid any Tinycore specific references and kept
command options as simple as possible. Dependencies are resolved by reducing the  .tree  file to a sorted list of unique entries.
Files are downloaded to the directory you are in when you invoke the script.

I think the script is fairly well documented if you want to see what's going on. Comments and criticism are welcomed.

FetchExt.sh ExtensionName  without the  .tcz  will download the extension+dependencies including .dep and .md5 files
FetchExt.sh info  will download a list  of available extensions and attempt to display it using the  less  command in a separate terminal.
                          If that fails, just open  info.lst  with your favorite file viewer.

This is what the  ./Log.txt  file it generates looks like:
Code: [Select]
Mon Jul  8 00:55:48 UTC 2019
Processing http://repo.tinycorelinux.net/10.x/x86/tcz/wifi.tcz.tree
libiw.tcz downloaded.
libiw.tcz.md5.txt downloaded.
libnl.tcz downloaded.
libnl.tcz.md5.txt downloaded.
ncursesw.tcz downloaded.
ncursesw.tcz.md5.txt downloaded.
openssl.tcz downloaded.
openssl.tcz.md5.txt downloaded.
readline.tcz downloaded.
readline.tcz.md5.txt downloaded.
readline.tcz.dep downloaded.
wifi.tcz downloaded.
wifi.tcz.md5.txt downloaded.
wifi.tcz.dep downloaded.
wireless-4.19.10-tinycore.tcz downloaded.
wireless-4.19.10-tinycore.tcz.md5.txt downloaded.
wireless_tools.tcz downloaded.
wireless_tools.tcz.md5.txt downloaded.
wireless_tools.tcz.dep downloaded.
wpa_supplicant.tcz downloaded.
wpa_supplicant.tcz.md5.txt downloaded.
wpa_supplicant.tcz.dep downloaded.

Mon Jul  8 15:06:48 UTC 2019
Processing http://repo.tinycorelinux.net/10.x/x86/tcz/wireless-rtl8822be-4.19.10-tinycore.tcz.tree
firmware-rtlwifi.tcz downloaded.
firmware-rtlwifi.tcz.md5.txt downloaded.
wireless-4.19.10-tinycore.tcz already downloaded.
wireless-rtl8822be-4.19.10-tinycore.tcz downloaded.
wireless-rtl8822be-4.19.10-tinycore.tcz.md5.txt downloaded.
wireless-rtl8822be-4.19.10-tinycore.tcz.dep downloaded.

The line after each timestamp is what you add to your  onboot.lst  file, in this case  wireless-rtl8822be-4.19.10-tinycore.tcz
and  wifi,tcz.

Then copy  *.tcz*  from your download directory to your  tce/optional directory.

This is what the script looks like:
Code: [Select]
#!/bin/bash
# Script to download an extension and its dependencies written by Richard A. Rost July 7,2019
# The script downloads to the directory you are in when you start the script.
# There are no Tinycore specific commands, variables, or directories required so it should work
# on any Linux box.
# Some error checking is done, though it might not be as thorough as it should be.
# The script downloads the  .tcz,  .tcz.dep,  and  .tcz.md5.txt  files for each extension.
# MD5 is verified.
# File ownership is changed to tc:staff.
# A running timestamped log is kept in  ./Log.txt
# ./Extension.list  is a sorted  .tree  file with duplicates removed of the last extension downloaded.
#
# Usage:
#
# FetchExt.sh ExtensionName Fetches the extension and its dependencies. ExtensionName is
# case sensitive and should NOT include the  .tcz  extension.
#
# FetchExt.sh info Fetches the list of available extensions in the listed repository.
#

# Repository to download from
ADDR="http://repo.tinycorelinux.net"

# Tinycore version
TC="10.x"

# Processor architecture, current options are  x86  x86_64  armv6  armv7
ARCH="x86"

# This is where the extensions get downloaded from.
URL="$ADDR/$TC/$ARCH/tcz/"

EXT="$1"
TYPE=".tcz.tree"
if [ "$EXT" == "info" ]
then
TYPE=".lst"
fi

FILE=""

# This is a running log of all downloads
LOG="Log.txt"

# Remove previous copy of file if it exists so that  wget  doesn't create numbered backups.
rm -rf "$EXT$TYPE"

TREE="$URL$EXT$TYPE"
wget -q "$TREE" > /dev/null 2>&1
if [ "$?" != "0" ]
then
wget -q --spider "$URL$EXT.tcz" > /dev/null 2>&1 # No .tcz.tree found, check for .tcz
if [ "$?" == "0" ]
then # Extension exists but has no dependencies so create a tree file.
echo -e "$EXT.tcz\n" > "$EXT.tcz.tree"
else
echo "$TREE  not found."
exit 1
fi
fi

if [ "$EXT$TYPE" == "info.lst" ]
then # Dispaly the  info.lst  file in a terminal using the  less  command.
xterm +tr +sb -T "info.lst" -e less info.lst &
exit 0
fi

# awk '$1=$1' removes all whitespaces, sort -u sorts alphabetically and removes duplicate entries.
awk '$1=$1' "$EXT$TYPE" | sort -u > Extension.list
rm -rf "$EXT$TYPE"

# Update the log file with a newline, timestamp, a newline, and the name of the extension being processed.
echo -e "\n`date`\nProcessing $TREE" >> $LOG

for FILE in `cat Extension.list`
do
if [ -f "$FILE" ]
then
echo "$FILE already downloaded." >> $LOG
continue
fi

# Fetch extension
wget -q "$URL$FILE" > /dev/null 2>&1
if [ "$?" != "0" ]
then
echo "$FILE download failed." >> $LOG
else
echo "$FILE downloaded." >> $LOG
# Change ownership. Numeric values used because foreign Linux box won't have tc:staff.
chown 1001:50 "$FILE"
fi

# Fetch MD5
wget -q "$URL$FILE.md5.txt" > /dev/null 2>&1
if [ "$?" != "0" ]
then
echo "$FILE.md5.txt download failed." >> $LOG
else
echo "$FILE.md5.txt downloaded." >> $LOG
# Change ownership. Numeric values used because foreign Linux box won't have tc:staff.
chown 1001:50 "$FILE.md5.txt"
fi

# Fetch dependency file
wget -q "$URL$FILE.dep" > /dev/null 2>&1
if [ "$?" == "0" ]
then
echo "$FILE.dep downloaded." >> $LOG
# Change ownership. Numeric values used because foreign Linux box won't have tc:staff.
chown 1001:50 "$FILE.dep"
fi

# Verify MD%
md5sum -c "$FILE.md5.txt"
if [ "$?" != "0" ]
then
echo "$FILE md5 checksum failed." >> $LOG
fi

done

exit 0

A copy is attached for downloading.

    [EDIT]: Updated attachment.  Rich
    [EDIT]: Added some clarification to my post.  Rich
« Last Edit: December 07, 2019, 06:03:09 AM by Rich »

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #1 on: December 05, 2019, 04:17:08 PM »
Sorry, very noobish of me, but I have no clue how to run the script. My internet-able computer is running Kali Linux (which I also don't know how to use properly), and I tried navigating through CLI to various folders, specifically, where "FetchExt.sh" is located, and I tried just commandline execute of "FetchExt.sh ExtensionName", and I tried "nano FetchExt.sh" and I guess maybe I forgot to sudo some of these? I can try that next.

But maybe I am supposed to do something else with the file? How do I download TC.tcz, using FetchExt.sh ?

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 7049
Re: Script to download extensions+dependencies on other Linux distros
« Reply #2 on: December 05, 2019, 04:52:08 PM »
Hi doctoranonymous
The first thing you need to do after downloading the script is to make it executable. Go to the folder with the script and execute:
Code: [Select]
sudo chmod 777 FetchExt.sh
To fetch nano for example:
Code: [Select]
./FetchExt.sh nanoNote the leading dot and slash. I recommend placing  FetchExt.sh  in its own directory and running it there. This way you don't
clutter up one of your other directories with extensions.

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #3 on: December 05, 2019, 09:41:40 PM »
Several things, Rich. Thank you for being awesome; (a) helpful, (b) prompt reply, (c) not condescending or elitist. I have noticed a lot of really bad info on the internet, not because it is wrong, but because it tells and shows HOW to do a thing right, but explains nothing about the WHY of the HOW.

You are being a good teacher here, hence "moderator" status. Now, I have probably used the chmod command in ten or twenty other "recipes" and still don't know quite what it does. I have probably even read the man pages, but I think, if this works (I haven't tried it yet), I will forever remember "chmod" as "That instruction that makes a bash shell script, ".sh", executable". Now, the "777" is a bit more opaque and abstruse, and, quite frankly arbitrary? But I can't argue; I am a biologist, and our science probably looks crazy to you guys, and your science, too!

OK one last thing (that will probably make you pull your hair out, and whisper-muttering-yelling "NOOBIE!"), is Tannenbaum. Not, tis the season, "Oh Tannenbaum", but Arthur Tanenbaum, Minix, and Linux. I have been reading his Minix book, because I want to know about what Linus knew when he invented the stuff we are hacking away, diligently, daily, upon. And so, the file system structure (ambiguous terms here? yes. one meaning is e.g. minix, ext4, FAT, and another , meaning is the "Unix tree",  or "directory structure"? I sometimes wish I was better with the distinctions and finer minutiae of "programmer-speak"?). So, I was thinking about directories and those "holdover", "standard-folders", from the standard UNIX type OSes, and how, I am a silly windows freak (until 2016), so I just make a folder, anywhere, when I want one. In theory, this is incorrect for Linux? Or perhaps, just a "cluttery" type attitude?

I read somewhere that certain of these "standard folders", in a Linux system could be placed in different partition, and personal files kept there, so that, if wiping and installing a new OS, these personal "work files" will be retained in the new OS? Now the Tiny core "extensions" seem like a similar idea; (1) keep a clean boot, (2) don't mix up the superfluous with the essential, etc. ( I still "sort of" read the tiny core book... bad student sometimes.).

So, as per your instructions, and my predilection for clutter, I will make a FetchedExts directory, in root (though in truth, I am sometimes perplexed that "/" is root and "/root/" is root? Oh well, I guess we can't all make sense, all the time, and computer programmers are no exception to this rule?)

"Keep a clean boot, be careful not to clutter root, you don't need a Kali TAIL, to onion-out the plain suits"~Adapted/stolen from B. Dylan, by yours truly, just now ...

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #4 on: December 05, 2019, 09:55:00 PM »
OK, I get this :

root@localhost:/FetchedExts# ./FetchExt.sh TC
./FetchExt.sh: 53: [: 8: unexpected operator
http://repo.tinycorelinux.net/10.x/x86/tcz/TC.tcz.tree  not found.

root@localhost:/FetchedExts# ./FetchExt.sh nano
./FetchExt.sh: 107: [: 0: unexpected operator
nano.tcz: OK
./FetchExt.sh: 107: [: 8: unexpected operator
ncurses5.tcz: OK

synopsis: seems to have fetched nano, but not TC? I will try ( flailing? in vain?) to troubleshoot it?


Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #5 on: December 05, 2019, 10:01:22 PM »
Ahhhh, armv6 repo, not x86 repo !!! Maybe?

I think I have to alter the FetchExt.sh script to tell it where to go (and how to get there?) Maybe, then, re-chmod it?

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #6 on: December 05, 2019, 10:14:01 PM »
So, I altered the code very slightly, went back and deleted nano (cuz its x86 and 10.x), and saved my altered code under the name FetchExt2.sh.

Here is the mild alteration:

Code: [Select]
"


# Repository to download from
ADDR="http://repo.tinycorelinux.net"

# Tinycore version
TC="9.x"

# Processor architecture, current options are  x86  x86_64  armv6  armv7
ARCH="armv6"

# This is where the extensions get downloaded from.
URL="$ADDR/$TC/$ARCH/tcz/"

EXT="$1"
TYPE=".tcz.tree"
if [ "$EXT" = "info" ]
then
TYPE=".lst"
fi

FILE=""

"

So, I'll chmod the fetchext2 and then run it, as per your previous instructions. Thanks again!

    [EDIT]: Added code tags.  Rich
« Last Edit: December 06, 2019, 04:56:06 AM by Rich »

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #7 on: December 05, 2019, 10:23:12 PM »
So it is running now, and seems to be working; stuff is downloading. But still getting "[: 0/8: unexpected operator" messages?

Also, here is the directory tree for TC, which is basically superfluous for anyone else reading this, but completes and satisfies my questions. haich tee tee pee ://repo.tinycorelinux.net/9.x/armv6/tcz/TC.tcz.tree


Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #8 on: December 05, 2019, 11:03:05 PM »
And, final loose ends (for other noobs like me), bash vs sh. The unexpected operator error message is because of different syntax between bash and sh shell scripting languages. I think, maybe "==" vs "=" is a necessary distinction; but also the "shebang" (whatever that is?) , i.e. #/bin/ vs /bin/ ?

As I said, I'm a noob, and this is obvious to some people, but its nice to search around a bit, find answers, and share freely. Cheers, all!

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #9 on: December 06, 2019, 05:14:29 AM »
And .... Shebang! Now I have knowledge. haich tee tee pee ess ://en.wikipedia.org/wiki/Shebang_(Unix)

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 7049
Re: Script to download extensions+dependencies on other Linux distros
« Reply #10 on: December 06, 2019, 05:43:15 AM »
Hi doctoranonymous
... You are being a good teacher here, hence "moderator" status. Now, I have probably used the chmod command in ten or twenty other "recipes" and still don't know quite what it does. I have probably even read the man pages, but I think, if this works (I haven't tried it yet), I will forever remember "chmod" as "That instruction that makes a bash shell script, ".sh", executable". Now, the "777" is a bit more opaque and abstruse, and, quite frankly arbitrary? But I can't argue; I am a biologist, and our science probably looks crazy to you guys, and your science, too!
Short answer: chmod sets who has permission to read, write, and execute a file. 777 is a shotgun approach that lets anyone
                      run the script.

Longer answer: The following directory listing has been spread out so I could place titles above some fields.
Code: [Select]
    U    G    O         User    Group
-  rwx  rwx  rwx   1     tc     staff     3386 Jul  8 16:05 FetchExt.sh
You 'll see that U (tc), G (staff), and O (everyone else) have permission to read, write, and execute the file. Those are what
the 3 digits in  777  represent. r, w, and x have values like this:
Code: [Select]
4 2 1
r w x
So to give read and write permission it's  r+w  which equals  4+2  which equals  6.

The point of this was to set the  O (everyone else)  field to  7  to avoid dealing with users and groups on other Linux systems.

Quote
... in root (though in truth, I am sometimes perplexed that "/" is root and "/root/" is root? Oh well, I guess we can't all make sense, all the time, and computer programmers are no exception to this rule?) ...
The  /  is the root directory below which all directories get attached.  The  /root/  is a directory named root which happens to be
the  home  directory for the user  root (i.e superuser).
« Last Edit: December 06, 2019, 06:34:01 AM by Rich »

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 7049
Re: Script to download extensions+dependencies on other Linux distros
« Reply #11 on: December 06, 2019, 06:31:50 AM »
Hi doctoranonymous
And, final loose ends (for other noobs like me), bash vs sh. The unexpected operator error message is because of different syntax between bash and sh shell scripting languages. I think, maybe "==" vs "=" is a necessary distinction; ...
I tried the script under  bash  but could not reproduce your error messages. I do agree there were 2 places I should have
used  ==  instead of  =.  I have attached a corrected script in my original post. Please download it and let me know if the
error messages go away.

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #12 on: December 06, 2019, 03:15:06 PM »
about "==" vs "=", I wasn't being critical, but thanks for fixing anyway. I was going to try fixing it, on my end, for my own purposes, but I was basically "coding in my sleep" last night. Got some ideas, tried them out, read a lot, and somehow found the right answers. But as for commenting intelligently or tactfully, I did not.

My last few short posts were at exhaustion's limit, and I didn't have the energy to dive into a study of "shell scripting" of "bourne" versus "bash". (still don't have the energy, today. Maybe tomorrow?).

Thanks for fixing anyway; other noobs like me will see this and avoid silly mistakes.

Also, after I posted "/" vs "/root/" , I went tried it on my laptop Kali linux (GUI) system, and found that "/home/" is mixed up in it too. I read a good description of why this is, recently, but forgot. Basically, its a historical artifact of how Unix developed and how it turned into Linux, etc. I think maybe wikipedia, too, has a good "rundown" on what these directories have been used for historically, and how they are used now (good they do, because I'll be darned if know!).

I will dl it and try it. Can't remember if Kali is Bash or Bourne (Oh, I think it is Bash; it always yells that at me, because I am a noob and can't get the commands right! hahaha!), but will provide that info too, in my reply. Thanks again, not just for the code/computer fix, but for the "brain patch", i.e. wetware-brain, i.e. education.

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 7049
Re: Script to download extensions+dependencies on other Linux distros
« Reply #13 on: December 06, 2019, 05:11:55 PM »
Hi doctoranonymous
about "==" vs "=", I wasn't being critical, but thanks for fixing anyway. I was going to try fixing it, on my end, for my own purposes, but I was basically "coding in my sleep" last night. Got some ideas, tried them out, read a lot, and somehow found the right answers. But as for commenting intelligently or tactfully, I did not. ...

 ... Thanks for fixing anyway; other noobs like me will see this and avoid silly mistakes. ...
My script performed 4 tests for equality, with 2 coded as  =  and the other 2 coded as  == , so I'd say you were right to
question my silly mistakes. :)

Offline doctoranonymous

  • WikiUser
  • *
  • Posts: 22
Re: Script to download extensions+dependencies on other Linux distros
« Reply #14 on: December 07, 2019, 02:02:52 AM »
Looks good here, too.

Code: [Select]
root@localhost:/FetchExt2Bdeldls# ./FetchExtMod.sh nano
nano.tcz: OK
ncurses5.tcz: OK

I should probably mention here, for any other beginners trying to follow this thread, that I am working with piCore, 9.x, for the raspberry pi zero, and trying to get TC desktop extension, offline (not all my pi zeros are zero W; I have one zero W, and about five zero-plains). Bottom line? Success. This code snippet will work for you (if you know what you want)!

Eventually a cluster computer is envisioned, and I'd like to load piCore into RAM, resident, and then unplug the SD card and boot another pi zero with the same card. I was doing this, to save money on cards.

After the past two days of internet scouring, I have found some other methods, and tried a few, but I'll leave that in-depth discussion for another post, where it won't be so off-topic. I navigated to this string from a cluster computer topic, and I forgot that other people reading this don't necessarily know where I came from and what I'm doing ! (Like so many things, in "real life").

In short, I have also looked at ethernet gadget for several months (on and off; busy elsewhere), but stumbled across usbboot (github; official rpi site), and some discussions on USB host boot, vs. USB device boot. Its a long story and I don't understand it yet, but 2 more options, potentially SD-cardless!

One thing, if you are thinking of USB boot methods, be careful of the OTP, One Time Programming bits, because you can flip your pi one way, and then not get it back! I luckily, for a novice, have not done this, but suffice it to say I will procxeed to USB host/device boot methods with appropriate caution.
« Last Edit: December 07, 2019, 02:14:34 AM by doctoranonymous »