HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //proc/37321/root/bin/x86_64-linux-gnu-gi-compile-repository
#!/usr/bin/python3
# Copyright 2023 Collabora Ltd.
# Copyright 2024 Simon McVittie
# SPDX-License-Identifier: MIT

import os
import shutil
import subprocess
import sys
import sysconfig
from typing import NoReturn


CAN_RUN = '/usr/lib/x86_64-linux-gnu/glib-2.0/deb-can-run'
DEB_HOST_ARCH = 'amd64'
DEB_HOST_GNU_TYPE = 'x86_64-linux-gnu'
DEB_HOST_MULTIARCH = 'x86_64-linux-gnu'
TOOL = 'gi-compile-repository'
TOOL_PATH = '/usr/lib/x86_64-linux-gnu/glib-2.0/gi-compile-repository'

ME = f'{DEB_HOST_GNU_TYPE}-{TOOL}'


class CrossGirTool:
    def __init__(
        self,
        argv: list[str],
    ) -> None:
        self.argv = argv

    def can_run(self) -> bool:
        python_arch = sysconfig.get_config_var('MULTIARCH')

        if python_arch == DEB_HOST_MULTIARCH:
            # Common case: if python3 is already an executable of the desired
            # architecture, then trivially we can run it
            return True

        try:
            completed = subprocess.run(
                [CAN_RUN],
                check=False,
                stdout=subprocess.PIPE,
                stderr=subprocess.DEVNULL,
            )
        except OSError:
            return False
        else:
            return completed.stdout == b'ok\n' and completed.returncode == 0

    def find_qemu(self) -> str:
        qemu = shutil.which(f'qemu-{DEB_HOST_ARCH}')

        if qemu is not None:
            return qemu

        qemu = shutil.which(f'qemu-{DEB_HOST_ARCH}-static')

        if qemu is not None:
            return qemu

        raise SystemExit(f'{ME}: Cannot find qemu-{DEB_HOST_ARCH}(-static)')

    def exec(self) -> NoReturn:
        exe_wrapper = []

        if not self.can_run():
            print(
                (f'{ME}: Cannot run {DEB_HOST_ARCH} executables '
                 + 'directly, using qemu'),
                file=sys.stderr,
            )
            exe_wrapper = [self.find_qemu()]

        argv = exe_wrapper + [TOOL_PATH] + sys.argv[1:]
        try:
            os.execvp(argv[0], argv)
        except OSError:
            print(f'{ME}: Unable to run: {argv}')
            raise


if __name__ == '__main__':
    CrossGirTool(sys.argv).exec()