0

I'm creating a new script. I would like to implement a way to verify this script. So I'm using those commands to check the content of the file.

remote_file="$(curl -m2 -s "$1")"
checksum_remote="$(echo "$remote_file" | sha256sum | cut -d ' ' -f1)"
checksum_current="$(sha256sum < "$COMMAND_NAME" | cut -d ' ' -f1)"

But after further developments I realize that I could use my script with the command curl -s $SCRIPT_URL | bash. In this case my check [ "$checksum_remote" != "$checksum_current" ] always succeed as the $COMMAND_NAME is bash and not the content of my script.

Is anyone know how to retrieve the whole source code with the bash script itself when we are using pipe execution?

3
  • Are you looking for something like cat $(which "$COMMAND_NAME") or something else? Commented Nov 20, 2023 at 15:45
  • 1
    It depends if you have the checksum of the source code or the binary^^ Commented Nov 20, 2023 at 15:48
  • I guess I could use something like tail -n +3 to save the checksum of my source code into the 2 lines of my source code. Commented Nov 24, 2023 at 15:55

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.