def install_package(overwrite=False, r_library_path=r_library_path):
    """Install ArcGIS R bindings onto this machine."""
    if overwrite is True:
        overwrite = True
    else:
        overwrite = False
    if not overwrite:
        if PACKAGE_VERSION:
            msg = "The ArcGIS R bridge is installed, and overwrite is disabled."
            arcpy.AddError(msg)
            sys.exit()

    (install_dir, arc_version, product) = arcgis_platform()
    arcmap_needs_link = False

    # check that we're in a sane installation environment
    validate_environment()

    # detect if we we have a 10.3.1 install that needs linking
    if product == 'Pro' and arcmap_exists("10.3"):
        arcmap_needs_link = True
        msg_base = "Pro side by side with 10.3 detected,"
        if arcmap_install_path is not None:
            msg = "{} installing bridge for both environments.".format(msg_base)
            arcpy.AddMessage(msg)
        else:
            msg = "{} but unable to find install path.".format(msg_base) + \
                  "ArcGIS bridge must be manually installed in ArcGIS 10.3."
            arcpy.AddWarning(msg)

    # if we're going to install the bridge in 10.3.1, create the appropriate
    # directory before trying to install.
    if arc_version == '10.3.1' and product == 'ArcMap' or arcmap_needs_link:
        r_integration_dir = os.path.join(arcmap_install_path, "Rintegration")
        # TODO escalate privs here? test on non-admin user
        if not os.path.exists(r_integration_dir):
            try:
                write_test = os.path.join(install_dir, 'test.txt')
                with open(write_test, 'w') as f:
                    f.write('test')
                os.remove(write_test)
                os.makedirs(r_integration_dir)
            except IOError:
                arcpy.AddError(
                    "Insufficient privileges to create 10.3.1 bridge directory."
                    " Please start {} as an administrator, by right clicking"
                    " the icon, selecting \"Run as Administrator\", then run this"
                    " script again.".format(product))
                sys.exit()

    # set an R-compatible temporary folder, if needed.
    orig_tmpdir = os.getenv("TMPDIR")
    if not orig_tmpdir:
        set_env_tmpdir()

    download_url = release_info()[0]
    if download_url is None:
        arcpy.AddWarning(
            "Unable to get current release information."
            " Trying offline installation.")

    base_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
    zip_glob = glob.glob(os.path.join(base_path, "arcgisbinding*.zip"))
    # see if we have a local copy of the binding
    if zip_glob and os.path.exists(zip_glob[0]):
        zip_path = zip_glob[0]
        local_install = True
    else:
        local_install = False

    # we have a release, write it to disk for installation
    with mkdtemp() as temp_dir:
        zip_name = os.path.basename(download_url)
        package_path = os.path.join(temp_dir, zip_name)
        if local_install:
            arcpy.AddMessage("Found local copy of binding, installing from zip")
            shutil.copyfile(zip_path, package_path)
        else:
            save_url(download_url, package_path)
        if os.path.exists(package_path):
            # TODO -- need to do UAC escalation here?
            # call the R installation script
            execute_r('Rcmd', 'INSTALL', package_path)
        else:
            arcpy.AddError("No package found at {}".format(package_path))

    # return TMPDIR to its original value; only need it for Rcmd INSTALL
    set_env_tmpdir(orig_tmpdir)

    # at 10.4 and Pro <=1.2, if the user has installed a version with a non-
    # numeric patch level (e.g. 3.2.4revised), and the bridge is installed
    # into Program Files, the link will fail. In this case, set the
    # appropriate registry key so that the bridge will still work. Note that
    # this isn't ideal, because it will persist after updates, but it is
    # better than the bridge failing to work at all.
    if (arc_version == '10.4' and product == 'Desktop') or \
            (arc_version in ('1.1', '1.1.1', '1.2')
             and product == 'Pro'):

        (r_major, r_minor, r_patchlevel) = r_version_info.split(".")
        # if we have a patchlevel like '4revised' or '3alpha', and
        # the global library path is used, then use the registry key.
        if len(r_patchlevel) > 1 and 'Program Files' in r_library_path:
            # create_registry_entry(product, arc_version)
            msg = "Currently, the bridge doesn't support patched releases" + \
                  "  (e.g. 3.2.4 Revised) in a global install. Please use" + \
                  " another version of R."
            arcpy.AddError(msg)
            sys.exit()

    # at 10.3.1, we _must_ have the bridge installed at the correct location.
    # create a symlink that connects back to the correct location on disk.
    if arc_version == '10.3.1' and product == 'ArcMap' or arcmap_needs_link:
        link_dir = os.path.join(r_integration_dir, PACKAGE_NAME)

        if os.path.exists(link_dir):
            if junctions_supported(link_dir) or hardlinks_supported(link_dir):
                # os.rmdir uses RemoveDirectoryW, and can delete a junction
                os.rmdir(link_dir)
            else:
                shutil.rmtree(link_dir)

        # set up the link
        r_package_path = r_pkg_path()

        if r_package_path:
            arcpy.AddMessage("R package path: {}.".format(r_package_path))
        else:
            arcpy.AddError("Unable to locate R package library. Link failed.")
            sys.exit()

        detect_msg = "ArcGIS 10.3.1 detected."
        if junctions_supported(link_dir) or hardlinks_supported(link_dir):
            arcpy.AddMessage("{} Creating link to package.".format(detect_msg))
            kdll.CreateSymbolicLinkW(link_dir, r_package_path, 1)
        else:
            # working on a non-NTFS volume, copy instead
            vol_info = getvolumeinfo(link_dir)
            arcpy.AddMessage("{} Drive type: {}. Copying package files.".format(
                detect_msg, vol_info[0]))
            # NOTE: this will need to be resynced when the package is updated,
            #       if installed from the R side.
            shutil.copytree(r_package_path, link_dir)

# execute as standalone script, get parameters from sys.argv
dataset/ETHPy150Open R-ArcGIS/r-bridge-install/rtools/install_package.py/install_package/original