def _find_bin(binary, basedir): # If it doesn't exist it might be in the path logger.debug('Checking that {!r} is in the $PATH'.format(binary)) try: shell_utils.which(binary, cwd=basedir) except subprocess.CalledProcessError: raise meta_errors.CommandError(binary)
def _find_bin(binary, basedir): # If it doesn't exist it might be in the path logger.debug('Checking that {!r} is in the $PATH'.format(binary)) try: shell_utils.which(binary, cwd=basedir) except subprocess.CalledProcessError: raise CommandError(binary)
def _write_wrap_exe(self, wrapexec, wrappath, shebang=None, args=None, cwd=None): assembled_env = self._assemble_runtime_environment() if args: quoted_args = ['"{}"'.format(arg) for arg in args] else: quoted_args = [] args = " ".join(quoted_args) + ' "$@"' if args else '"$@"' cwd = "cd {}".format(cwd) if cwd else "" executable = '"{}"'.format(wrapexec) if shebang: if shebang.startswith("/usr/bin/env "): shebang = shell_utils.which(shebang.split()[1]) new_shebang = self._install_path_pattern.sub("$SNAP", shebang) new_shebang = re.sub(self._prime_dir, "$SNAP", new_shebang) if new_shebang != shebang: # If the shebang was pointing to and executable within the # local 'parts' dir, have the wrapper script execute it # directly, since we can't use $SNAP in the shebang itself. executable = '"{}" "{}"'.format(new_shebang, wrapexec) with open(wrappath, "w+") as f: print("#!/bin/sh", file=f) if cwd: print("{}".format(cwd), file=f) print(assembled_env, file=f) print("exec {} {}".format(executable, args), file=f) os.chmod(wrappath, 0o755)
def _write_wrap_exe(self, wrapexec, wrappath, shebang=None, args=None, cwd=None): if args: quoted_args = ['"{}"'.format(arg) for arg in args] else: quoted_args = [] args = ' '.join(quoted_args) + ' "$@"' if args else '"$@"' cwd = 'cd {}'.format(cwd) if cwd else '' # If we are dealing with classic confinement it means all our # binaries are linked with `nodefaultlib` but we still do # not want to leak PATH or other environment variables # that would affect the applications view of the classic # environment it is dropped into. replace_path = re.compile(r'{}/[a-z0-9][a-z0-9+-]*/install'.format( re.escape(self._parts_dir))) if self._config_data['confinement'] == 'classic': assembled_env = None else: assembled_env = common.assemble_env() assembled_env = assembled_env.replace(self._prime_dir, '$SNAP') assembled_env = replace_path.sub('$SNAP', assembled_env) executable = '"{}"'.format(wrapexec) if shebang: if shebang.startswith('/usr/bin/env '): shebang = shell_utils.which(shebang.split()[1]) new_shebang = replace_path.sub('$SNAP', shebang) new_shebang = re.sub(self._prime_dir, '$SNAP', new_shebang) if new_shebang != shebang: # If the shebang was pointing to and executable within the # local 'parts' dir, have the wrapper script execute it # directly, since we can't use $SNAP in the shebang itself. executable = '"{}" "{}"'.format(new_shebang, wrapexec) with open(wrappath, 'w+') as f: print('#!/bin/sh', file=f) if assembled_env: print('{}'.format(assembled_env), file=f) print( 'export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:' '$LD_LIBRARY_PATH', file=f) if cwd: print('{}'.format(cwd), file=f) # TODO remove this once LP: #1656340 is fixed in snapd. print(dedent("""\ # Workaround for LP: #1656340 [ -n "$XDG_RUNTIME_DIR" ] && mkdir -p $XDG_RUNTIME_DIR -m 700 """), file=f) print('exec {} {}'.format(executable, args), file=f) os.chmod(wrappath, 0o755)
def _write_wrap_exe(self, wrapexec, wrappath, shebang=None, args=None, cwd=None): if args: quoted_args = ['"{}"'.format(arg) for arg in args] else: quoted_args = [] args = ' '.join(quoted_args) + ' "$@"' if args else '"$@"' cwd = 'cd {}'.format(cwd) if cwd else '' # If we are dealing with classic confinement it means all our # binaries are linked with `nodefaultlib` but we still do # not want to leak PATH or other environment variables # that would affect the applications view of the classic # environment it is dropped into. replace_path = re.compile(r'{}/[a-z0-9][a-z0-9+-]*/install'.format( re.escape(self._parts_dir))) # Confinement classic or when building on a host that does not match # the target base means we cannot setup an environment that will work. if (self._config_data['confinement'] == 'classic' or not self._is_host_compatible_with_base): assembled_env = None else: assembled_env = common.assemble_env() assembled_env = assembled_env.replace(self._prime_dir, '$SNAP') assembled_env = replace_path.sub('$SNAP', assembled_env) executable = '"{}"'.format(wrapexec) if shebang: if shebang.startswith('/usr/bin/env '): shebang = shell_utils.which(shebang.split()[1]) new_shebang = replace_path.sub('$SNAP', shebang) new_shebang = re.sub(self._prime_dir, '$SNAP', new_shebang) if new_shebang != shebang: # If the shebang was pointing to and executable within the # local 'parts' dir, have the wrapper script execute it # directly, since we can't use $SNAP in the shebang itself. executable = '"{}" "{}"'.format(new_shebang, wrapexec) with open(wrappath, 'w+') as f: print('#!/bin/sh', file=f) if assembled_env: print('{}'.format(assembled_env), file=f) print( 'export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:' '$LD_LIBRARY_PATH', file=f) if cwd: print('{}'.format(cwd), file=f) print('exec {} {}'.format(executable, args), file=f) os.chmod(wrappath, 0o755)
def _write_wrap_exe(self, wrapexec, wrappath, shebang=None, args=None, cwd=None): if args: quoted_args = ['"{}"'.format(arg) for arg in args] else: quoted_args = [] args = " ".join(quoted_args) + ' "$@"' if args else '"$@"' cwd = "cd {}".format(cwd) if cwd else "" # If we are dealing with classic confinement it means all our # binaries are linked with `nodefaultlib` but we still do # not want to leak PATH or other environment variables # that would affect the applications view of the classic # environment it is dropped into. replace_path = re.compile( r"{}/[a-z0-9][a-z0-9+-]*/install".format(re.escape(self._parts_dir)) ) # Confinement classic or when building on a host that does not match # the target base means we cannot setup an environment that will work. if ( self._config_data["confinement"] == "classic" or not self._is_host_compatible_with_base ): assembled_env = None else: assembled_env = common.assemble_env() assembled_env = assembled_env.replace(self._prime_dir, "$SNAP") assembled_env = replace_path.sub("$SNAP", assembled_env) executable = '"{}"'.format(wrapexec) if shebang: if shebang.startswith("/usr/bin/env "): shebang = shell_utils.which(shebang.split()[1]) new_shebang = replace_path.sub("$SNAP", shebang) new_shebang = re.sub(self._prime_dir, "$SNAP", new_shebang) if new_shebang != shebang: # If the shebang was pointing to and executable within the # local 'parts' dir, have the wrapper script execute it # directly, since we can't use $SNAP in the shebang itself. executable = '"{}" "{}"'.format(new_shebang, wrapexec) with open(wrappath, "w+") as f: print("#!/bin/sh", file=f) if assembled_env: print("{}".format(assembled_env), file=f) print( "export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH", file=f ) if cwd: print("{}".format(cwd), file=f) print("exec {} {}".format(executable, args), file=f) os.chmod(wrappath, 0o755)
def _write_wrap_exe(self, wrapexec, wrappath, shebang=None, args=None, cwd=None): args = ' '.join(args) + ' "$@"' if args else '"$@"' cwd = 'cd {}'.format(cwd) if cwd else '' # If we are dealing with classic confinement it means all our # binaries are linked with `nodefaultlib` but we still do # not want to leak PATH or other environment variables # that would affect the applications view of the classic # environment it is dropped into. replace_path = re.compile(r'{}/[a-z0-9][a-z0-9+-]*/install'.format( re.escape(self._parts_dir))) if self._config_data['confinement'] == 'classic': assembled_env = None else: assembled_env = common.assemble_env() assembled_env = assembled_env.replace(self._prime_dir, '$SNAP') assembled_env = replace_path.sub('$SNAP', assembled_env) executable = '"{}"'.format(wrapexec) if shebang: if shebang.startswith('/usr/bin/env '): shebang = shell_utils.which(shebang.split()[1]) new_shebang = replace_path.sub('$SNAP', shebang) new_shebang = re.sub(self._prime_dir, '$SNAP', new_shebang) if new_shebang != shebang: # If the shebang was pointing to and executable within the # local 'parts' dir, have the wrapper script execute it # directly, since we can't use $SNAP in the shebang itself. executable = '"{}" "{}"'.format(new_shebang, wrapexec) with open(wrappath, 'w+') as f: print('#!/bin/sh', file=f) if assembled_env: print('{}'.format(assembled_env), file=f) print('export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:' '$LD_LIBRARY_PATH', file=f) if cwd: print('{}'.format(cwd), file=f) print('exec {} {}'.format(executable, args), file=f) os.chmod(wrappath, 0o755)
def _write_wrap_exe(self, wrapexec, wrappath, shebang=None, args=None, cwd=None): if args: quoted_args = ['"{}"'.format(arg) for arg in args] else: quoted_args = [] args = " ".join(quoted_args) + ' "$@"' if args else '"$@"' cwd = "cd {}".format(cwd) if cwd else "" # If we are dealing with classic confinement it means all our # binaries are linked with `nodefaultlib` but we still do # not want to leak PATH or other environment variables # that would affect the applications view of the classic # environment it is dropped into. replace_path = re.compile(r"{}/[a-z0-9][a-z0-9+-]*/install".format( re.escape(self._parts_dir))) # Confinement classic or when building on a host that does not match # the target base means we cannot setup an environment that will work. if (self._config_data["confinement"] == "classic" or not self._is_host_compatible_with_base): assembled_env = None else: assembled_env = common.assemble_env() assembled_env = assembled_env.replace(self._prime_dir, "$SNAP") assembled_env = replace_path.sub("$SNAP", assembled_env) executable = '"{}"'.format(wrapexec) if shebang: if shebang.startswith("/usr/bin/env "): shebang = shell_utils.which(shebang.split()[1]) new_shebang = replace_path.sub("$SNAP", shebang) new_shebang = re.sub(self._prime_dir, "$SNAP", new_shebang) if new_shebang != shebang: # If the shebang was pointing to and executable within the # local 'parts' dir, have the wrapper script execute it # directly, since we can't use $SNAP in the shebang itself. executable = '"{}" "{}"'.format(new_shebang, wrapexec) with open(wrappath, "w+") as f: print("#!/bin/sh", file=f) if assembled_env: print("{}".format(assembled_env), file=f) print( 'export LD_LIBRARY_PATH="$SNAP_LIBRARY_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"', file=f, ) print( 'echo $LD_LIBRARY_PATH | grep -qE "::|^:|:$" && ' 'echo "WARNING: an empty LD_LIBRARY_PATH has been set. ' "CWD will be added to the library path. " 'This can cause the incorrect library to be loaded."', file=f, ) if cwd: print("{}".format(cwd), file=f) print("exec {} {}".format(executable, args), file=f) os.chmod(wrappath, 0o755)