this post was submitted on 29 Aug 2024
5 points (85.7% liked)

Bash

720 readers
1 users here now

Talk about the Bash Shell and Bash scripting

founded 4 years ago
MODERATORS
 

Hi all,

I'm trying to put a command together to download a bz2 archive containing an img file and decompress it immediately, basically without saving it to the filesystem. Can this be done?

This is what I've come up with so far, but it's incomplete: wget -qO- "https://opnsense.com/.../img.bz2" | bzip2 -dv

Background: Trying to install OPNsense on Linode. Their hacky official guide says the best way to install FreeBSD is via the rescue mode. But FreeBSD posts their images as .img, so the filesystem size limitation of 1GB for the rescue image isn't an issue. But with OPNsense I need to decompress it.

I have a few different options on how to install this but I see it as a good reason to learn more about stdin/out, piping commands, etc.

Thanks in advance.

all 5 comments
sorted by: hot top controversial new old
[–] egsaqmojz@lemmy.ml 1 points 2 months ago (1 children)

When I use just the wget aspect of the command, it dumps a bunch of jargon to my terminal, so I think that means I have the "stdout" aspect of that command right.

[–] smpl@discuss.tchncs.de 2 points 2 months ago

I think you just need to redirect¹ stdout from bzip2 to a file.

wget -qO- "https://opnsense.com/.../img.bz2" | bzip2 -dv > img

1: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_07

[–] egsaqmojz@lemmy.ml 1 points 2 months ago

To button this up, I didn't figure out the one-line solution. I used a script that opnsense publishes to install opnsense on top of freebsd. This is the same script used in the opnsense installer img. Wasn't hard, but I was laser-focused on figuring out the one-line solution. :(

[–] Im_old@lemmy.world 0 points 2 months ago

I feel you need to save the whole file before bzip2 can open it (for decompression). Compression/decompression is done in patterns, so it can't decompress if it doesn't get the data to inflate.