返回 Skill 列表
extension
分类: 开发与工程无需 API Key

self-extracting-script

创建自解压的Bash脚本,使用base64编码嵌入任何载荷(如压缩包、可执行文件、配置文件)。适用于创建便携式单文件安装程序、部署包或分发不依赖外部资源的文件。

person作者: jakexiaohubgithub

Self-Extracting Script Skill

Generate self-extracting Bash scripts from any payload file. The generated scripts embed the payload as base64 and extract it when executed.

Quick Start

# Basic extraction script
python scripts/create_self_extractor.py payload.tar.gz output.sh

# Auto-execute after extraction
python scripts/create_self_extractor.py setup.sh installer.sh --execute

# Custom output filename
python scripts/create_self_extractor.py config.json deploy.sh --output prod_config.json

Features

  • Embeds any file type (binary or text) using base64 encoding
  • Optional auto-execution of extracted content
  • Custom output filenames
  • Descriptive headers in generated scripts
  • Portable - requires only bash and base64

Usage

python scripts/create_self_extractor.py <payload> <output_script> [options]

Arguments

| Argument | Description | |----------|-------------| | payload | Path to the file to embed | | output_script | Path for the generated self-extracting script |

Options

| Option | Description | |--------|-------------| | --execute, -e | Run extracted file after extraction (for scripts) | | --output, -o | Custom filename for extracted content | | --description, -d | Description to include in script header |

Examples

Software Deployment

python scripts/create_self_extractor.py myapp.tar.gz deploy_myapp.sh \
    --description "MyApp v1.2.3 deployment package"

Auto-Running Installer

python scripts/create_self_extractor.py install.sh installer.sh --execute

Configuration Distribution

python scripts/create_self_extractor.py config.yaml setup.sh \
    --output /etc/myapp/config.yaml

How It Works

  1. Reads the payload file (binary or text)
  2. Base64-encodes the content
  3. Generates a Bash script with embedded payload
  4. Script uses heredoc to safely store encoded data
  5. On execution: decodes payload → writes to file → optionally executes

Size Considerations

Base64 encoding increases size by ~33%:

  • 1 MB → ~1.33 MB
  • 10 MB → ~13.3 MB

For payloads >50MB, consider alternative distribution methods.

Dependencies

Generation: Python 3.6+ Execution: bash, base64 (standard on most Unix systems)