Installing sha1sum on git-bash (MinGW)

5,333

Solution 1

mingw-get is available at

sourceforge.net/projects/mingw/files/Installer/mingw-get

After you have that installed run

mingw-get install msys-coreutils

Solution 2

I solved this for myself by adding a shell function that uses the included openssl to replace the part of sha1sum that I used most often.

function openssl_sha1sum() {
    local i nf=0 binary= text=true
    local -a files

    # parse for -b/-t mode output arguments
    for (( i=1; i <= $#; i++ )); do
        case "${!i}" in
            (-t|--text)
                text=true
                binary=
                ;;
            (-b|--binary)
                binary=true
                text=
                ;;
            (-|-[cw]|--help|--version|--status|--check|--warn)
                ;;
            (*)
                let 'nf++'
                files[$nf]="${!i}"
                ;;
        esac
    done

    # execute the appropriate command and reformat the output
    if [ $nf -eq 0 ]; then
        local binfmt='s/$/ *-/;' txtfmt='s/$/  -/;'
        if [ -n "$binary" ]; then
            fmt=$binfmt
        else
            fmt=$txtfmt
        fi
        openssl dgst -sha1 -hex | sed -e "$fmt"
    else
        local commonfmt='s/^[A-Z0-9]\+(\(.*\))= \([0-9a-fA-F]\+\)$/\2'
        local binfmt="$commonfmt "'*\1/;' txtfmt="$commonfmt  "'\1/;'
        if [ -n "$binary" ]; then
            fmt=$binfmt
        else
            fmt=$txtfmt
        fi
        openssl dgst -sha1 -hex "${files[@]}" | sed -e "$fmt"
    fi
}

if ! type -p sha1sum &>/dev/null; then
    function sha1sum() { openssl_sha1sum "$@"; }
fi
Share:
5,333

Related videos on Youtube

mcgyver5
Author by

mcgyver5

Updated on September 18, 2022

Comments

  • mcgyver5
    mcgyver5 almost 2 years

    I've been using git-bash on Windows 7 a lot. I gather it is a wrapper of MinGW. It has md5sum but not sha1sum. I'd like to install sha1sum, but I can't figure out how.

    When I try mingw-get, it says "command not found"

    When I tried to download mingw-get from SourceForge, I only found an installer for the entire MinGW program but not for mingw-get.

    How do I install either getting sha1sum or getting mingw-get?

  • mcgyver5
    mcgyver5 over 12 years
    thanks for your response. I downloaded it and ran the installer. Unfortunately, this is the result: Welcome to Git (version 1.7.4-preview20110204) McGuiT1@ISTM-L-6328MJ1 ~ $ mingw-get install mysys-coreutils sh.exe": mingw-get: command not found
  • Zombo
    Zombo over 12 years
    You need to add mingw-get to your path wikipedia.org/wiki/PATH_%28variable%29
  • mcgyver5
    mcgyver5 over 10 years
    update: I successfully installed mingw-get and then msys-coreutils, but sha1sum command still not found