#!/bin/sh
#
# tahoe-i2p-install - Install self-contained I2P mod of Tahoe-LAFS
#
# Authors:  smeghead <smeghead@mail.i2p> <smeghead@i2pmail.org>
#           duck <duck@mail.i2p> <duck@i2pmail.org>
#           killyourtv <killyourtv@mail.i2p> <killyourtv@i2pmail.org>
#           K1773R <k1773r@mail.i2p> <k1773r@i2pmail.org>
#
# License: public domain
#
# Requirements:
#
# - *BSD/Linux/Mac OS X/Solaris:
#     Bourne compatible shell, GCC, Python 2.5, 2.6, or 2.7 (not 3.x), wget, fetch, curl, or aria
#
# - Windows:
#     Unsupported, but same as above plus MinGW or Cygwin and probably lots of
#     spit, glue, duct tape and virgin sacrifices. If you make it work please
#     contribute your changes to this script's maintainer (by doing so you
#     agree to release the work into the public domain) and if they're sane
#     enough they'll be included in the next release.
#


# Release-specific metadata

INSTALLER_VERSION="1.3.1"

FOOLSCAP_VERSION="0.6.4"
FOOLSCAP_PATCH_REVISION="r0"
FOOLSCAP_PATCH_SHA256="c0b6239119f85fa79b3b983886a2aa42d9bf588c649c5a13ad8f8a358f90b9b7"
FOOLSCAP_SHA256="74b283dd68a3c9d68ebf4e9b4ebf5cfb37480915b6a808ac930fe858a66f8d99"

TAHOE_DEPS_VERSION="25"
TAHOE_DEPS_SHA256="d753cbf88e4f7e19785a73c01808946a441708c043bc2e53c98fc232d04cbdd6"

TAHOE_LAFS_VERSION="1.9.2"
TAHOE_LAFS_PATCH_REVISION="r0"
TAHOE_LAFS_PATCH_SHA256="8e2d8caf923d413a3b343700fac6a16ba69e758e889eea1d61a82c2655cd58a3"
TAHOE_LAFS_SHA256="04773b076004cfd41f60e16c1dd3f3ee247f2a3f1fc90942a7cf66bf557d2104"

# Fetch locations

PATCH_HOME_I2P="http://zam7u6vslhemddz347uusuzjdk5wma4h5hcmcqlng4ybbpdbjhnq.b32.i2p/tahoe-lafs/patches"
PATCH_HOME_WWW="http://k1773r.i2p.xyz/tahoe-lafs/patches"

FOOLSCAP_PKG="foolscap-${FOOLSCAP_VERSION}"
FOOLSCAP_PKG_EXTENSION=".tar.gz"
FOOLSCAP_PATCH="foolscap-i2p-${FOOLSCAP_VERSION}-${FOOLSCAP_PATCH_REVISION}.patch"
FOOLSCAP_HOME="http://foolscap.lothar.com/releases"
FOOLSCAP_HOME_I2P="http://zam7u6vslhemddz347uusuzjdk5wma4h5hcmcqlng4ybbpdbjhnq.b32.i2p/tahoe-lafs/upstream"

TAHOE_DEPS_PKG="tahoe-lafs-deps-v${TAHOE_DEPS_VERSION}"
TAHOE_DEPS_PKG_EXTENSION=".tar.bz2"
TAHOE_DEPS_HOME="https://tahoe-lafs.org/source/tahoe-lafs/deps"
TAHOE_DEPS_HOME_I2P="http://zam7u6vslhemddz347uusuzjdk5wma4h5hcmcqlng4ybbpdbjhnq.b32.i2p/tahoe-lafs/upstream"

TAHOE_LAFS_PKG="allmydata-tahoe-${TAHOE_LAFS_VERSION}"
TAHOE_LAFS_PKG_EXTENSION=".tar.bz2"
TAHOE_LAFS_PATCH="tahoe-lafs-i2p-${TAHOE_LAFS_VERSION}-${TAHOE_LAFS_PATCH_REVISION}.patch"
TAHOE_LAFS_HOME="https://tahoe-lafs.org/source/tahoe-lafs/releases"
TAHOE_LAFS_HOME_I2P="http://zam7u6vslhemddz347uusuzjdk5wma4h5hcmcqlng4ybbpdbjhnq.b32.i2p/tahoe-lafs/upstream"

# Don't mess with these or you might end up with a deleted WORKING_DIR

WORKING_DIR="$(pwd)"
INSTALL_DIR="${WORKING_DIR}/tahoe-lafs-i2p"
FOOLSCAP_DIR="${WORKING_DIR}/${FOOLSCAP_PKG:-foolscap-src}"
TAHOE_DEPS_DIR="${WORKING_DIR}/tahoe-deps"
TAHOE_LAFS_DIR="${WORKING_DIR}/${TAHOE_LAFS_PKG:-tahoe-lafs-src}"

if [ -f /etc/arch-release ]; then
    export PYCRYPTOPP_DISABLE_EMBEDDED_CRYPTOPP=1
        if [ ! -e /sbin/ifconfig ]; then
                echo "ERROR: The current version of Tahoe-LAFS requires ifconfig" >&2
                echo "       and this tool is deprecated in ArchLinux. Please install" >&2
                echo "       the net-tools package and re-run this script." >&2
                exit 1
        fi
    : ${PYTHON:="python2"}
else
    : ${PYTHON:="python"}
fi

export PYTHON
PYTHON_VERSION=$($PYTHON --version 2>&1 | cut -d ' ' -f2 | cut -c 1-3)
if [ $PYTHON_VERSION != "2.5" ] &&
        [ $PYTHON_VERSION != "2.6" ] &&
        [ $PYTHON_VERSION != "2.7" ]; then
        echo "ERROR: Python $PYTHON_VERSION is not supported." >&2
        echo >&2
        echo "       If you have Python 2.x on your system, set the environment" >&2
        echo "       variable PYTHON to the correct python binary." >&2
        echo >&2
        echo "For example, if the correct binary is called \"python2\"" >&2
        echo "re-run this script with PYTHON=\"python2\" $0 $@" >&2
        exit 1
fi

# Detect sha256 checksum binary

if [ $(which sha256sum) ]; then
        SHA256_BIN="sha256sum"
elif [ $(which sha256) ]; then
        SHA256_BIN="sha256 -r"
elif [ $(uname -s |tr "[A-Z]" "[a-z]") = "netbsd" ]; then
        if [ $(which cksum) ]; then
                SHA256_BIN="cksum -a sha256 -n"
        fi
elif [ $(which shasum) ]; then
        SHA256_BIN="shasum -a256"
else
        echo >&2
        echo "Error: Failed to locate sha256 checksum binary. Aborting." >&2
        echo >&2
        exit 1
fi

FETCH() {
    # We default to downloading with wget. If wget is not found, we look for
    # aria2c. If aria2c is not found, we fallback to curl. If curl is not
    # available, we try eepget before we exit.

    if [ -x "${HOME}/i2p/eepget" ] && [ ! $(echo ${PATH} |grep \/i2p) ]; then
        PATH=${PATH}:${HOME}/i2p
    fi

    if [ $(which wget) ]; then
        DOWNLOADTOOL="wget"
    elif [ $(which aria2c) ]; then
        DOWNLOADTOOL="aria2c"
    elif [ $(which curl) ]; then
        DOWNLOADTOOL="curl"
    elif [ $(which fetch) ]; then
        DOWNLOADTOOL="fetch"
    elif [ $(which eepget) ]; then
        DOWNLOADTOOL="eepget"
    else
        echo "ERROR: Couldn't locate any usable download tools." >&2
        echo "       Looked for wget, curl, aria2c, eepget and fetch." >&2
        exit 1
    fi

    if [ x$1 = 'x' ]; then
        # We'll end up here if the FETCH function is called without arguments, such as when
        # tahoe-i2p-install is called with the --version argument.
        echo "$DOWNLOADTOOL"
        return 0
    else
        if [ ${opt_no_proxy} ]; then
            unset http_proxy https_proxy
            if [ $DOWNLOADTOOL = "wget" ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} --no-proxy --tries=3 -c $1"
            elif [ $DOWNLOADTOOL = 'eepget' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} -p :0 -n 3 $1"
            elif [ $DOWNLOADTOOL = 'fetch' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} -a -m -d $1"
            elif [ $DOWNLOADTOOL = 'aria2c' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} --all-proxy \"\" $1"
            elif [ $DOWNLOADTOOL = 'curl' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} -OL -x \"\" $1"
            fi
        else
            if [ $DOWNLOADTOOL = 'wget' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} --tries=3 -c $1"
            elif [ $DOWNLOADTOOL = 'eepget' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} -p $http_proxy -n 3 $1"
            elif [ $DOWNLOADTOOL = 'fetch' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} -a -m -d $1"
            elif [ $DOWNLOADTOOL = 'aria2c' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} $1"
            elif [ $DOWNLOADTOOL = 'curl' ]; then
                DOWNLOADCMD="${DOWNLOADTOOL} -OL $1"
            fi
        fi
    fi

    echo "Attempting to download from $1"
    $DOWNLOADCMD
}

patching_failed() {
    echo >&2
    echo "Error: Failed to apply patch. Aborting." >&2
    echo >&2
    exit 1
}

apply_patches() {
    echo
    echo ">>> Patching sources"
    echo

    set "${FOOLSCAP_DIR}" "${FOOLSCAP_PATCH}" \
        "${TAHOE_LAFS_DIR}" "${TAHOE_LAFS_PATCH}"

    stack="$@"
    while [ -n "${stack}" ] ; do

        cd "${1}"

        patch -p1 < "${WORKING_DIR}/${2}" || patching_failed

        cd "$OLDPWD"

        shift 2
        stack="$@"
    done
}

build_foolscap() {
    cd "${FOOLSCAP_DIR}"

    echo
    echo ">>> Building foolscap"
    echo ">>>>> Note: You can ignore most C++ warnings."
    echo

    $PYTHON setup.py build || exit 1
    $PYTHON setup.py sdist || exit 1
    cp -f dist/* "${TAHOE_DEPS_DIR}"

    cd "$OLDPWD"
}

build_tahoe_lafs() {
    cd "${TAHOE_LAFS_DIR}"

    echo
    echo ">>> Building tahoe-lafs"
    echo

    mkdir -p "${TAHOE_LAFS_DIR}/support/lib/python${PYTHON_VERSION}/site-packages"
    export PYTHONPATH="${TAHOE_LAFS_DIR}/support/lib/python${PYTHON_VERSION}/site-packages"

    if [ ${opt_make_dist} ] ; then
        $PYTHON setup.py build || exit 1
        $PYTHON setup.py bdist || exit 1
        cp -f dist/* "${WORKING_DIR}"
    else
        $PYTHON setup.py build || exit 1
    fi

    cd "$OLDPWD"
}

clean_build_dirs() {
    cd "${WORKING_DIR}"

    echo
    echo ">>> Cleaning previously created build directories"
    echo

    rm -rf "${FOOLSCAP_DIR}" "${TAHOE_DEPS_DIR}" "${TAHOE_LAFS_DIR}"

    cd "$OLDPWD"
}

fetch_failed() {

    echo >&2
    echo "ERROR: Failed to download ${1}. Try fetching it manually and run" >&2
    echo "       tahoe-i2p-install again. Aborting." >&2
    echo >&2
    exit 1
}


fetch_packages() {
    cd "${WORKING_DIR}"

    echo
    echo ">>> Fetching patches and packages"
    echo


    for p in "${FOOLSCAP_PATCH}" "${TAHOE_LAFS_PATCH}" ; do

            if [ ${opt_no_proxy} ] ; then
                FETCH "${PATCH_HOME_WWW}/${p}"  || fetch_failed patch
            else
                FETCH "${PATCH_HOME_I2P}/${p}"  || fetch_failed patch
            fi
    done

        if [ ${opt_no_proxy} ] ; then
                unset http_proxy https_proxy
                set "${FOOLSCAP_HOME}" "${FOOLSCAP_PKG}" "${FOOLSCAP_PKG_EXTENSION}" \
                    "${TAHOE_DEPS_HOME}" "${TAHOE_DEPS_PKG}" "${TAHOE_DEPS_PKG_EXTENSION}" \
                    "${TAHOE_LAFS_HOME}" "${TAHOE_LAFS_PKG}" "${TAHOE_LAFS_PKG_EXTENSION}"

        else
                set "${FOOLSCAP_HOME_I2P}" "${FOOLSCAP_PKG}" "${FOOLSCAP_PKG_EXTENSION}" \
                    "${TAHOE_DEPS_HOME_I2P}" "${TAHOE_DEPS_PKG}" "${TAHOE_DEPS_PKG_EXTENSION}" \
                    "${TAHOE_LAFS_HOME_I2P}" "${TAHOE_LAFS_PKG}" "${TAHOE_LAFS_PKG_EXTENSION}"
        fi

        stack="$@"
        while [ -n "${stack}" ]; do
            FETCH "${1}/${2}${3}" || fetch_failed package
            shift 3
            stack="$@"
        done

    cd "$OLDPWD"
}

unpack_all() {
    local tar_filter_opt

    cd "${WORKING_DIR}"

    echo
    echo ">>> Unpacking archives"
    echo

    for pkg in \
        "${FOOLSCAP_PKG}${FOOLSCAP_PKG_EXTENSION}" \
        "${TAHOE_DEPS_PKG}${TAHOE_DEPS_PKG_EXTENSION}" \
        "${TAHOE_LAFS_PKG}${TAHOE_LAFS_PKG_EXTENSION}"
    do
        case "${pkg}" in
            *.7z)
                7z e "${pkg}"
                continue ;;

            *.tar.bz2|*.tbz)
                tar_filter_opt=-j ;;

            *.tar.gz|*.tgz)
                tar_filter_opt=-z ;;

            *.tar.lzma)
                tar_filter_opt=--lzma ;;

            *.tar.xz|*.txz)
                tar_filter_opt=-J ;;

            *.zip)
                unzip -v "${pkg}"
                continue ;;

            *)
                echo "Error: Package has unknown extension: ${pkg}" >&2
                echo "Aborting." >&2
                exit 1 ;;
        esac
        if [ ! $(which bzip2) ]; then
                echo "bzip2 not found!" >&2
                echo "Please install bzip2 then re-run this script." >&2
                exit 1
        fi

        if [ ! $(which tar) ]; then
                echo "tar not found!" >&2
                echo "Please install tar then re-run this script." >&2
        fi

        tar -x ${tar_filter_opt} -vf "${pkg}" || echo "Extraction failed." >&2
    done

    mkdir -p "${TAHOE_DEPS_DIR}"

    # This foolscap is replaced with our I2P-patched version
    rm -f "${TAHOE_DEPS_DIR}"/foolscap*

    cd "$OLDPWD"
}

print_urls() {
            echo
            echo "Files will be downloaded via I2P from"
            echo "  ${TAHOE_LAFS_HOME_I2P}/${TAHOE_LAFS_PKG}${TAHOE_LAFS_PKG_EXTENSION}"
            echo "  ${PATCH_HOME_I2P}/${FOOLSCAP_PATCH}"
            echo "  ${PATCH_HOME_I2P}/${TAHOE_LAFS_PATCH}"
            echo "  ${FOOLSCAP_HOME_I2P}/${FOOLSCAP_PKG}${FOOLSCAP_PKG_EXTENSION}"
            echo "  ${TAHOE_DEPS_HOME_I2P}/${TAHOE_DEPS_PKG}${TAHOE_DEPS_PKG_EXTENSION}"
            echo
            echo
            echo "If --no-proxy is specified, I'll use:"
            echo "  ${TAHOE_LAFS_HOME}/${TAHOE_LAFS_PKG}${TAHOE_LAFS_PKG_EXTENSION}"
            echo "  ${PATCH_HOME_WWW}/${FOOLSCAP_PATCH}"
            echo "  ${PATCH_HOME_WWW}/${TAHOE_LAFS_PATCH}"
            echo "  ${FOOLSCAP_HOME}/${FOOLSCAP_PKG}${FOOLSCAP_PKG_EXTENSION}"
            echo "  ${TAHOE_DEPS_HOME}/${TAHOE_DEPS_PKG}${TAHOE_DEPS_PKG_EXTENSION}"
            echo
            echo "If desired, you can download these files manully to $(pwd), and run"
            echo "this script with the --no-fetch option."
            exit 0
}

usage() {
    echo "Usage: tahoe-i2p-install [OPTIONS]"
    cat << EOF

Builds and installs tahoe-lafs-i2p in the current directory.

By default this attempts to download all required packages and patches
anonymously over I2P using the HTTP proxy listening on 127.0.0.1:4444 and the I2P
HTTPS proxy on 127.0.0.1:4445. The default proxy locations can be overridden
with the http_proxy & https_proxy environment variables but any used proxies
must be an I2P HTTP proxy; Tor proxies won't work.

For faster (but non-anonymous) downloads, specify --no-proxy; the files will
be downloaded directly from the Inernet. If all required packages and patches
already exist in the current directory, specify --no-fetch.

Finally, if you'd rather download the files yourself, the download locations
can be printed with --print-urls.

Options:
  -d, --make-dist             create distributable archive
  -h, --help                  show usage information and exit
  -k, --keep-build-dirs       don't remove build directories when done
  -n, --no-proxy              don't use proxy for fetching [NOT anonymous!]
  -v, --version               show version information and exit
  -x, --no-fetch              networkless install; don't download anything
  -f, --fetch                 fetch files from network
  -u, --print-urls            show download locations
EOF
    exit 0
}

# This gets set by default in the offline installer
#opt_no_fetch=1
verify_hashes() {
    local sha256

    cd "${WORKING_DIR}"

    echo
    echo ">>> Verifying SHA-256 sums"
    echo

    set "${FOOLSCAP_PATCH}" "${FOOLSCAP_PATCH_SHA256}" \
        "${TAHOE_LAFS_PATCH}" "${TAHOE_LAFS_PATCH_SHA256}" \
        "${FOOLSCAP_PKG}${FOOLSCAP_PKG_EXTENSION}" "${FOOLSCAP_SHA256}" \
        "${TAHOE_DEPS_PKG}${TAHOE_DEPS_PKG_EXTENSION}" "${TAHOE_DEPS_SHA256}" \
        "${TAHOE_LAFS_PKG}${TAHOE_LAFS_PKG_EXTENSION}" "${TAHOE_LAFS_SHA256}"

    stack="$@"
    while [ -n "${stack}" ] ; do
        echo -n "${1} ... "

        sha256=$(${SHA256_BIN} "${1}" | cut -d ' ' -f1)

        if [ ${sha256} = ${2} ] ; then
            echo "OK"
        else
            echo "FAILED" >&2
            echo >&2
            echo "Expected hash: ${2}" >&2
            echo "Computed hash: ${sha256}" >&2
            echo >&2
            echo "Error: A package or patch failed its hash check. Aborting." >&2
            echo >&2
            exit 1
        fi

        shift 2
        stack="$@"
    done

    echo
    cd "$OLDPWD"
}

while [ $# -gt 0 ] ; do
    case "${1}" in

        -d|--make-dist)
            opt_make_dist=1
            shift ;;

        -h|--help)
            usage ;;

        -k|--keep-build-dirs)
            opt_keep_build_dirs=1
            shift ;;

        -f|--fetch)
            unset opt_no_fetch
            shift ;;

        -n|--no-proxy)
            opt_no_proxy=1
            unset http_proxy https_proxy
            shift ;;

        -p|--http-proxy)
            echo "ERROR: Specifying the proxy with the \"-p\" or \"--http-proxy\"" >&2
            echo "parameters is no longer supported." >&2
            echo >&2
            echo "Please set the environment variables \"http_proxy\" and/or \"https_proxy\"" >&2
            echo "and re-run this script." >&2
            exit 1
            ;;

        -u|--print-urls|--print-uris)
            print_urls
            ;;
        -v|--version)
            echo "tahoe-i2p-install version ${INSTALLER_VERSION}"
            echo
            echo "This version provides:"
            echo
            echo "  ${TAHOE_LAFS_PKG}"
            echo "  ${TAHOE_DEPS_PKG}"
            echo "  ${FOOLSCAP_PKG}"
            echo
            echo "Patched with:"
            echo
            echo "  ${TAHOE_LAFS_PATCH}"
            echo "  ${FOOLSCAP_PATCH}"
            echo
            echo "Downloads will be performed using $(FETCH)"
            echo "and checksums will be verified with"
            echo "$SHA256_BIN."
            echo
            echo "Python version $PYTHON_VERSION detected."
            exit 0 ;;

        -x|--no-fetch)
            opt_no_fetch=1
            shift ;;

        -f|--fetch)
            unset opt_no_fetch
            shift ;;

        -*)
            echo "Unknown option: ${1}" >&2
            exit 1 ;;

        *)
            echo "Too many arguments: ${1}" >&2
            exit 1 ;;
    esac
done

: ${http_proxy:="127.0.0.1:4444"}
: ${https_proxy:="127.0.0.1:4445"}
export http_proxy https_proxy
set -e

NUMPROX=0

if [ $http_proxy != "127.0.0.1:4444" ] &&
   [ $http_proxy != "localhost:4444" ]; then
    NUMPROX=$(expr $NUMPROX + 1)
fi

if [ $https_proxy != "127.0.0.1:4445" ] &&
   [ $https_proxy != "localhost:4445" ]; then
    NUMPROX=$(expr $NUMPROX + 1)
fi

if [ $NUMPROX -gt 1 ]; then
    VARI="variables"
else
    VARI="variable"
fi

trap 'echo;echo "CTRL+C keypress detected.";
      echo "To use the default I2P Proxies you may call this script as";
      echo "        http_proxy=\"\" https_proxy=\"\" $0 [options]";
      echo' INT
if [ $http_proxy != "127.0.0.1:4444" ] &&
        [ $http_proxy != "localhost:4444" ]; then
        echo
        echo "WARNING: Detected the following non-default environment ${VARI}:"
        echo "         http_proxy: $http_proxy"
        if [ $https_proxy != "127.0.0.1:4445" ] &&
                [ $https_proxy != "localhost:4445" ]; then
                echo  "         https_proxy: $https_proxy"
                echo
        fi

        if [ $NUMPROX -gt 1 ]; then
            echo "If these are not I2P proxies, abort this script and set the"
            echo "http*_proxy variables to point to your I2P proxies."
            echo
            echo "If these *are* I2P proxies, please wait 10 seconds and this"
            echo "script will continue."
        else
            echo "If this is not an I2P proxy, abort this script and set the"
            echo "http*_proxy variables to point to your I2P proxies."
            echo
            echo "If is *is* an I2P proxy, please wait 10 seconds and this"
            echo "script will continue."
        fi
        echo
        sleep 10
fi

trap - INT TERM EXIT

# Always start with clean build dirs
clean_build_dirs

[ ! ${opt_no_fetch} ] && fetch_packages

verify_hashes
unpack_all
apply_patches
build_foolscap
build_tahoe_lafs

[ -d ${INSTALL_DIR} ] && rm -rf "${INSTALL_DIR}"

if [ ! ${opt_keep_build_dirs} ] ; then
    mv -f "${TAHOE_LAFS_DIR}" "${INSTALL_DIR}"
    clean_build_dirs
else
    mkdir -p ${INSTALL_DIR}
    cd "${TAHOE_LAFS_DIR}"
    tar cf - .| (cd "${INSTALL_DIR}" ; tar xf -)

fi

sed -e "s|${TAHOE_LAFS_DIR}/src|${INSTALL_DIR}/src|" \
         "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/allmydata-tahoe.egg-link" > \
         "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/allmydata-tahoe.egg-link.tmp"
sed -e "s|${TAHOE_LAFS_DIR}/src|${INSTALL_DIR}/src|" \
         "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/easy-install.pth" > \
         "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/easy-install.pth.tmp"
mv  "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/allmydata-tahoe.egg-link.tmp" \
    "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/allmydata-tahoe.egg-link"
mv  "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/easy-install.pth.tmp" \
    "${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages/easy-install.pth"

echo
echo ">>> Finished tahoe-i2p-install"
echo
if [ ! $(echo $PATH |grep "${INSTALL_DIR}/bin") ]; then
    echo "Be sure to update your environment:"
    echo
    echo "  export PATH=\"${INSTALL_DIR}/bin:\${PATH}\""
    #echo "  export PYTHONPATH=\"${INSTALL_DIR}/support/lib/python${PYTHON_VERSION}/site-packages:\${PYTHONPATH}\""
    echo
    echo "Otherwise, the full path will need to be used, such as \"${INSTALL_DIR}/bin/tahoe\""
else
    echo "Tahoe-LAFS is already in your PATH."
fi
# vim:fenc=utf-8:ai:si:ts=4:sw=4:et:nu:fdm=indent:fdn=1
