Skip to content

Instantly share code, notes, and snippets.

@elieux
Created June 15, 2016 19:18

Revisions

  1. elieux created this gist Jun 15, 2016.
    50 changes: 50 additions & 0 deletions midipix.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/bin/sh

    prepend_path() {
    local _pname _pname_prepend="${1}" IFS=":"
    for _pname in ${PATH}; do
    if [ "${_pname}" = "${_pname_prepend}" ]; then
    return
    fi
    done
    export PATH="${_pname_prepend}${PATH:+:${PATH}}"
    }

    prepend_path "/bin"
    export MSYS2_ARG_CONV_EXCL="*"

    if [ "${1}" = -h ]; then
    echo "Usage: $0 [path_to_native]"
    exit 0
    elif [ ${#} -eq 0 ]; then
    PWD_ABSOLUTE="$(cygpath -am native)" || exit 1
    MIDIPIX_PATH="${PWD_ABSOLUTE%%:*}${PWD_ABSOLUTE#*:}"
    unset PWD_ABSOLUTE
    elif [ ${#} -eq 1 ]; then
    MIDIPIX_PATH="${1}"
    else
    echo "Usage: $0 [path_to_native]"
    exit 6
    fi
    if [ "${MIDIPIX_PATH#*[ ]*}" != "${MIDIPIX_PATH}" ]; then
    echo "Error: path_to_native must not contain spaces nor tabs."
    exit 3
    fi
    MIDIPIX_PATH=${MIDIPIX_PATH#/}
    MIDIPIX_PATH=${MIDIPIX_PATH%/}
    if [ ! -f "/proc/cygdrive/${MIDIPIX_PATH}/bin/ntctty.exe" ]; then
    echo "Error: Midipix path invalid. Could not find '/${MIDIPIX_PATH}/bin/ntctty.exe'."
    exit 4
    else
    if [ -f "/proc/cygdrive/${MIDIPIX_PATH}/bin/libpsxscl.log" ]; then
    echo "Found libpsxscl.log, copying to /${MIDIPIX_PATH}/libpsxscl.last."
    mv "/proc/cygdrive/${MIDIPIX_PATH}/bin/libpsxscl.log" "/proc/cygdrive/${MIDIPIX_PATH}/libpsxscl.last" || exit 5
    fi
    echo "Midipix native root: /${MIDIPIX_PATH}"
    mintty -h always -e /bin/sh -c "
    set -o errexit
    stty raw -echo
    cd /proc/cygdrive/${MIDIPIX_PATH}/bin
    export PATH=/proc/cygdrive/${MIDIPIX_PATH}/bin:/proc/cygdrive/${MIDIPIX_PATH}/lib
    ./ntctty.exe -e chroot //${MIDIPIX_PATH} /bin/bash" &
    fi