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?
cat $(which "$COMMAND_NAME")or something else?tail -n +3to save the checksum of my source code into the 2 lines of my source code.