Exodus – 安全複製 Linux 二進製文件的工具

您是否曾經需要您的一個系統上安裝了一些二進製文件,並且您想在另一台機器上傳輸相同的二進製文件? 是的,對嗎? 我們將討論可以幫助您實現它的此類工具。 出埃及記 是一種工具,可以輕鬆地將 Linux ELF 二進製文件從一個系統成功重定位到另一個系統。 這在您在機器上沒有 root 訪問權限或軟件包根本不適用於給定 Linux 發行版的情況下很有用。

Exodus 管理所有二進制依賴項的集合,為直接調用重定位鏈接器的可執行文件編譯一個靜態鏈接的包裝器,並將包安裝在遠程機器上的 ~/.exodus/ 中。 讓我們看看它的實際效果。

出埃及記的安裝

Exodus 可以從 pypi 上的包. 執行以下命令為當前用戶在本地安裝它。

$ pip install --user exodus-bundler
Collecting exodus-bundler
Downloading exodus_bundler-1.1.8-py2.py3-none-any.whl
Installing collected packages: exodus-bundler
Successfully installed exodus-bundler-1.1.8

將 ~/.local/bin 添加到您的 PATH 變量以使 exodus 可執行。 這可以通過執行以下命令來完成。

export PATH="~/.local/bin/:${PATH}"

此 PATH 僅為當前會話設置,以使其永久添加到 ~/.bashrc 文件中的上述命令。 你已經安裝成功了,現在讓我們看看如何使用它。

出埃及記的用法

通過 ssh 安裝

您可以使用 Exodus 在遠程機器上安裝可執行包。 為了 example, 一台機器上安裝了包“tree”,而另一台機器沒有。 您可以通過在安裝了樹包的機器上執行以下命令來簡單地在另一台機器上安裝樹包。

$ exodus tree | ssh 192.168.0.144
Pseudo-terminal will not be allocated because stdin is not a terminal.
[email protected]'s password:
Installing executable bundle in "/opt/exodus"...
Successfully installed, be sure to add /opt/exodus/bin to your $PATH.

現在,轉到剛剛安裝 tree 的機器並將 /opt/exodus/bin 添加到 PATH 變量中。

$ export PATH="/opt/exodus/bin:${PATH}"

而已。 你完成了。 您可以開始在您的機器上使用樹包。 就這麼簡單。

重命名二進製文件

可以使用 -r/–rename 選項並行安裝具有相同名稱的二進製文件。假設如果您在 /bin/tree 和 /usr/local/bin/tree 有兩個版本的樹,那麼您可以為每個版本創建別名 – r 選項,您可以並行使用它們。

exodus -r tree-1 -r tree-2 /bin/tree /usr/local/bin/tree

現在,您可以分別通過 tree-1 和 tree-2 在 /bin/tree 和 /usr/local/bin/tree 使用 tree 。

手動提取安裝

您可以通過 –tarball 選項直接創建二進製文件的 tarball。 您可以將此 tarball 複製到遠程計算機,然後將其安裝到 ~/your-path

#create tarball of tree binaries
$ exodus --tarball tree --output tree.tgz

#copy generated tarball to remote machine
scp tree.tgz 192.168.0.144:~

#create ~/your-path
ssh 192.168.0.144 "mkdir -p ~/your-path"

#extract tarball to ~/your-path
ssh intoli.com "tar --strip 1 -C ~/your-path -zxf tree.tgz"

現在您需要將 ~/your-path 添加到 PATH 變量中,如前所述。 您可以開始在遠程計算機上使用樹二進製文件。

您可以使用 -h(help) 選項探索更多選項,它將為您提供用法和所有選項。

usage: exodus [-h] [--ldd LDD_SCRIPT] [-o OUTPUT_FILE] [-q] [-r NEW_NAME] [-t]
              [-v]
              EXECUTABLE [EXECUTABLE ...]

Bundle ELF binary executables with all of their runtime dependencies so that
they can be relocated to other systems with incompatible system libraries.

positional arguments:
  EXECUTABLE            One or more ELF executables to include in the exodus
                        bundle.

optional arguments:
  -h, --help            show this help message and exit
  --ldd LDD_SCRIPT      The linker that will be invoked to resolve
                        dependencies. In advanced usage, you may want to write
                        your own `ldd` script which invokes the linker with
                        custom arguments. (default: ldd)
  -o OUTPUT_FILE, --output OUTPUT_FILE
                        The file where the bundle will be written out to. The
                        extension depends on the output type. The
                        "{{executables}}" and "{{extension}}" template strings
                        can be used in the provided filename. If omitted, the
                        output will go to stdout when it is being piped, or to
                        "./exodus-{{executables}}-bundle.{{extension}}"
                        otherwise. (default: None)
  -q, --quiet           Suppress warning messages. (default: False)
  -r NEW_NAME, --rename NEW_NAME
                        Renames the binary executable(s) before packaging. The
                        order of rename tags must match the order of
                        positional executable arguments. (default: [])
  -t, --tarball         Creates a tarball for manual extraction instead of an
                        installation script. Note that this will change the
                        output extension from ".sh" to ".tgz". (default:
                        False)
  -v, --verbose         Output additional informational messages. (default:
                        False)

所以,我們已經安裝並了解如何使用 exodus 二進製文件重定位工具。 希望你覺得它有用,如果你對此有什麼想說的,請在評論部分告訴我。