#!/bin/bash
# Bash postinstall script.  This ensures that /bin/sh exists and is
# runnable, updating older copies of ash or bash as appropriate, while
# leaving other shells (ksh or zsh) alone.

update=no
# Is /bin/sh missing, or have broken dependencies?
case `cygcheck /bin/sh.exe 2>&1` in
    *Error:\ could\ not\ find* | *Cannot\ open*) update=yes ;;
    *) # We can run it.  Is the version from ash or bash?
        case `/bin/sh.exe --version 2>&1` in
            Illegal\ option\ --* | GNU\ bash*) update=yes ;;
        esac ;;
esac
# Update, if needed.  Use copy, not hard or symlink, since symlinks won't
# work from Windows cmd and a hardlink to a running shell can't be broken.
# As a last-ditch fallback, try exec to stop the current running bash.
if test $update = yes ; then
    cp -fpuv /bin/bash.exe /bin/sh.exe ||
    exec cp -fpuv /bin/bash.exe /bin/sh.exe
fi
