Live data from Hacker News

Show HN: Checksum.sh verify every install script

checksum.sh

61–70 of 77 posts

Re: Show HN: Checksum.sh verify every install script

#61

Earlier quoted context omitted.

Got it. Thanks. Re --check, I suppose the way to do that would be to download the file to disk, which --check requires as fair as I can tell. So I could download the file to disk, --check, and then remove it. I think most of these installs scripts are trying not to leave any artifacts around from install, other than the resulting binary.

You only need to create a temp file for the checksum file, not the downloaded contents. In the below example, no file exists on disk with the contents of `$s`. > $ s='1 2' > $ printf %s\\n "$s" | shasum -a 256 > tmp.sum > $ printf %s\\n "$s" | shasum --check tmp.sum > -: OK So you can just `printf '%s -\n' "$c" > tmp.sum` and check with `printf %s\\n "$s" | shasum --check --status tmp.sum || { echo "checksum failed"…

Pr for that https://github.com/gavinuhma/checksum.sh/pull/4

I ended up trying with process substitution so no tmp file.

It works. Trying to decide if it’s more difficult to read

Re: Show HN: Checksum.sh verify every install script

#63
>I've found it a really useful tool for installing things like Rust or Deno.

For Rust you can ignore sh.rustup.rs and just download and set up rustup manually.

    CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
    mkdir -p "$CARGO_HOME/bin"
    curl -Lo "$CARGO_HOME/bin/rustup" 'https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init'
    chmod +x "$CARGO_HOME/bin/rustup"
    hash -r
    rustup set auto-self-update disable
    rustup set profile minimal
    rustup default stable
    rustup update --force
    rustup self update # Create hardlinks under $CARGO_HOME/bin/

Re: Show HN: Checksum.sh verify every install script

#64
post #48

Earlier quoted context omitted.

so you’re storing the checksums locally for each script then? is that much different than just storing the verified copies of the scripts?

Storing them in the readme which others can use as well. I jump around to new machines a lot so I can reference checksum.sh if I want to install rust for example

Makes sense, congrats on shipping!

Re: Show HN: Checksum.sh verify every install script

#65

There are two big problems with the use of `echo $s` in bash/POSIX sh: 1. Never use echo to output untrusted content as the first argument Let's say `s='-e 1\n2'`, then `echo $s` will output: > 1 > 2 Instead of: > -e 1\n2 Always use printf if you want to start output with untrusted content, e.g., `printf %s\\n "$s"`. 2. Never use unquoted variable expansion when trying to exactly reproduce contents of the variable Si…

Great post, you are wise in the ways of the shell. Minutiae like this is exactly why I stop writing shell scripts the moment I start, and reach for python or some other sane language. But, I can't help but respect when I see masters of sh work their magic.

Try enabling shellcheck linting in your editor! It would immediately warn about unquoted variable expansions and the like. For the vast majority of "gotchas" shellcheck will prod you in the right direction.

That said, to write good shell scripts requires actually learning the shell paradigm, instead of just trying to write "Python with Shell syntax".

Re: Show HN: Checksum.sh verify every install script

#66

This just shifts the trust to the checksum. How do you know you downloaded the right checksum? Checksum the checksum? Whatever you are doing to protect sending the checksum can also be used for protecting the script itself.

Checksum the checksum_s_

Checksum.sh could keep track of checksums. Then an attacker has to alter the original script and checksum.sh.

Re: Show HN: Checksum.sh verify every install script

#67

There are two big problems with the use of `echo $s` in bash/POSIX sh: 1. Never use echo to output untrusted content as the first argument Let's say `s='-e 1\n2'`, then `echo $s` will output: > 1 > 2 Instead of: > -e 1\n2 Always use printf if you want to start output with untrusted content, e.g., `printf %s\\n "$s"`. 2. Never use unquoted variable expansion when trying to exactly reproduce contents of the variable Si…

Great post, you are wise in the ways of the shell. Minutiae like this is exactly why I stop writing shell scripts the moment I start, and reach for python or some other sane language. But, I can't help but respect when I see masters of sh work their magic.

I think there's place for both. When I build software installers for our embedded systems, the "frontend" tools production uses are written in a "sane" language, but the actual installation of software and configuration of the systems is done in shell. Because for running a bunch of apt/tar/cp/ln/sed commands to configure a Linux machine, it is the sane language.

Re: Show HN: Checksum.sh verify every install script

#69

Earlier quoted context omitted.

> that script is just going to download more binaries from the Internet Not necessarily. A number of these scripts either configure a package manager or the shell script contains the binary itself which is unpacked when the script is run.

Sure, I suppose that's possible. Most of the ones I'm familiar with just download an architecture-compatible binary from a CDN somewhere. Even if there's a shar-style[1] packed binary in the script, you have no idea what that binary does when you verify that the checksum is correct.

Well-written scripts I've seen also contain the hash of binaries that are downloaded. So as long as the hash function is good, checking the hash of the script should still ensure that the binary downloaded is what you want.

> you have no idea what that binary does when you verify that the checksum is correct.

This isn't any different from using a package manager. You're still downloading a binary that could do anything and you have to have some level of trust in the source.

Re: Show HN: Checksum.sh verify every install script

#70

OP may want to take a look at "Shell script best practices" ( https://news.ycombinator.com/item?id=33354286 ) submitted two days ago. :)

Nice! Thanks for sharing. I also learned about shellcheck thanks to this thread, which has been super useful
Post reply on HN