有趣的專案 exodus

使用場景主要是當你沒有 root 權限,但是需要一些 Linux Binary 應用程式,如果是 static 直接 copy 過去,架構符合就可以執行!但是如果是 Dynamic Binary 那就麻煩了!

這時候你可以用 exodus 來快速的把應用程式移植到遠端你沒有root的電腦上跑!

例如 htop 就符合可以移植的特性!

     whereis htop
    htop: /usr/bin/htop /usr/share/man/man1/htop.1.gz
     ldd /usr/bin/htop
    linux-vdso.so.1 (0x00007ffd805ff000)
    libncursesw.so.6 => /lib/x86_64-linux-gnu/libncursesw.so.6 (0x00007fce37ffb000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007fce37fcb000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fce37e7c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fce37c8a000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fce37c84000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fce38092000)
     file /usr/bin/htop
    /usr/bin/htop: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=732986edd7d25415061c74c17cb3db139bee2775, for GNU/Linux 3.2.0, stripped

開始安裝

     pip install --user exodus-bundler
     export PATH="~/.local/bin/:${PATH}"

執行

     exodus htop | ssh www.libthomas.org
    Pseudo-terminal will not be allocated because stdin is not a terminal.
    WARNING: Installing either the musl or diet C libraries will result in more efficient launchers (currently using bash fallbacks instead).
    Linux www 5.10.0-5-amd64 #1 SMP Debian 5.10.26-1 (2021-03-27) x86_64

    1 updates could not be installed automatically. For more details,
    see /var/log/unattended-upgrades/unattended-upgrades.log

    The programs included with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.

    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    You have no mail.
    Installing executable bundle in "/home/thomas/.exodus"...
    Successfully installed, be sure to add /home/thomas/.exodus/bin to your $PATH.

執行

    ./.exodus/bin/htop

看看細節:

    :~$ ls -l ./.exodus/bin/htop 
    lrwxrwxrwx 1 thomas thomas 88 12  6 10:59 ./.exodus/bin/htop -> ../bundles/d1a7ebca3b636f00f5a7b551a12b3a503f33121b7e922f8b367337d40c91d923/usr/bin/htop

    :~$ file ./.exodus/bundles/d1a7ebca3b636f00f5a7b551a12b3a503f33121b7e922f8b367337d40c91d923/usr/bin/htop 
    ./.exodus/bundles/d1a7ebca3b636f00f5a7b551a12b3a503f33121b7e922f8b367337d40c91d923/usr/bin/htop: Bourne-Again shell script, ASCII text executable
    :~$ cat  ./.exodus/bundles/d1a7ebca3b636f00f5a7b551a12b3a503f33121b7e922f8b367337d40c91d923/usr/bin/htop 

    #! /bin/bash

    current_directory="$(dirname "$(readlink -f "$0")")"
    executable="${current_directory}/./htop-x"
    library_path="../../lib64:../lib64:../../lib:../lib:../../lib32:../lib32:../../lib/x86_64-linux-gnu"
    library_path="${current_directory}/${library_path//:/:${current_directory}/}"
    linker="${current_directory}/./linker-1050e7bea7968d23eafee3fa70a34533523e3bb1159e5a424802b5e8b42688f1"
    if [ "true" == "true" ]; then
        exec "${linker}" --library-path "${library_path}" --inhibit-rpath "" "${executable}" "$@"
    else
        exec "${linker}" --library-path "${library_path}" "${executable}" "$@"
    fi

就是把linker+library+binary 放在一起跑!可以手動自己維護,但是有工具幫忙 why not?!

reference: https://github.com/intoli/exodus

Comments