--- install/__init__.py.orig	2020-11-30 08:53:24.000000000 +1100
+++ install/__init__.py	2022-07-27 06:59:19.000000000 +1000
@@ -84,6 +84,8 @@
 else:
 
     def _copy_dir(src, dst, ignore=[]):  # type: (str, str, List[str]) -> None
+        if not os.path.exists(dst):
+            os.makedirs(dst)
         from distutils.dir_util import copy_tree
         for node in os.listdir(src):
             if node in ignore:
@@ -116,11 +118,7 @@
 
 
 def _replace_shebang(dir, interpreter):  # type: (str, str) -> None
-    scripts = [os.path.join(dir, script) for script in os.listdir(dir)]
-
-    for script in scripts:
-        if not os.path.isfile(script):
-            raise InstallException('Script is not a file: {}'.format(script))
+    scripts = [script for script in [os.path.join(dir, f) for f in os.listdir(dir)] if os.path.isfile(script)]
 
     # Python 2 does not support fileinput as a contex manager
     f = fileinput.input(scripts, inplace=True)
@@ -131,6 +129,17 @@
     f.close()
 
 
+def _make_executable(dir):  # type: (str) -> None
+    scripts = [os.path.join(dir, script) for script in os.listdir(dir)]
+    import stat
+
+    for script in scripts:
+        mode = os.stat(script).st_mode
+        mode |= stat.S_IRUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP \
+            | stat.S_IROTH | stat.S_IXOTH
+        os.chmod(script, mode)
+
+
 def _check_requirement(requirement_string):  # type: (str) -> bool
     import packaging.requirements
 
@@ -238,9 +247,12 @@
 
     if os.path.isfile(entrypoints_file):
         _generate_entrypoint_scripts(entrypoints_file, scripts_cache_dir)
+        if os.path.isdir(scripts_cache_dir):
+            _make_executable(scripts_cache_dir)
 
     if os.path.isdir(scripts_dir):
         _replace_shebang(scripts_dir, sys.executable)
+        _make_executable(scripts_dir)
 
     _save_pickle(cache_dir, 'wheel-info', wheel_info)
     _save_pickle(cache_dir, 'metadata', metadata)
@@ -258,7 +270,7 @@
     pkg_cache_dir = os.path.join(cache_dir, 'pkg')
     scripts_cache_dir = os.path.join(cache_dir, 'scripts')
     pkg_data_dir_name = '{}-{}.data'.format(wheel_info['distribution'], wheel_info['version'])
-    pkg_data_dir = os.path.join(cache_dir, pkg_data_dir_name)
+    pkg_data_dir = os.path.join(pkg_cache_dir, pkg_data_dir_name)
 
     pkg_dir = destdir_path('purelib' if metadata['Root-Is-Purelib'] == 'true' else 'platlib')
 
@@ -269,7 +281,7 @@
             _copy_dir(target, destdir_path(lib))
     if os.path.isdir(pkg_data_dir):
         for node in os.listdir(pkg_data_dir):
-            target = os.path.join(pkg_cache_dir, node)
+            target = os.path.join(pkg_data_dir, node)
             if node == 'purelib':
                 _copy_dir(target, destdir_path('purelib'))
             if node == 'platlib':
