OtaPackageToolOTA 打包工具
OtaPackageTool 是一个 OTA 打包工具,使用 git 获取不同提交之间的文件差异实现OTA包生成。
OtaPackageTool 工具默认提供了一个 linux-x86-64 的可执行文件,放于开源项目的 bin 目录下。该工具能够构建两种类型的包: 全量包和增量包。支持 tar 和 zip 两种文件类型的包文件。实现 OTA 包的构建,需要借助 git 实现版本文件的管理。
安装
二进制安装
OtaPackageTool 工具默认提供了一个 linux-x86-64 的可执行文件,放于开源项目的 bin 目录下。只需要克隆下载下来,即可执行:
$ git clone https://github.com/yicm/OtaPackageTool.git
$ cd OtaPackageTool/bin
$ ./ota_packer -h
 
源码编译安装
$ git clone https://github.com/yicm/OtaPackageTool.git
$ cd OtaPackageTool
$ go build -o bin ./...
 
编译完成后,生成的可执行文件已经输出到 bin 目录下。
使用
准备
- 将 OtaPackageTool 添加到环境变量 
$PATH(这里就不展开如何添加了) - 进入你的软件版本管理仓库根目录
 
$ cd your_installation_file_version_repository
 
- 就可以运行 OtaPackageTool 相关的打包功能了
 
示例
# -----------------------------------------------
---
# 查看工具版本
$ ota_packer version
ota_packer version 0.0.1
# --------------------------------------------------
# 查看工具帮助
$ ota_packer -h
Archive of the diff files using git on Linux system.
Usage:
  ota_packer [command]
Available Commands:
  gen         Generate package file
  help        Help about any command
  version     Get version of ota_packer
Flags:
  -c, --config string         Config file (default is $HOME/.ota_packer.yaml)
  -h, --help                  help for ota_packer
  -n, --project-name string   Your project name (default "OTA")
Use "ota_packer [command] --help" for more information about a command.
# --------------------------------------------------
# 查看OTA包生成帮助
$ ota_packer gen -h
Generate a specific version package by entering different configuration parameters.
Usage:
  ota_packer gen [flags]
Flags:
  -F, --diff-filter string       git diff --diff-filter and a similar designation (default "ACMRT")
  -e, --end-commit-id string     End revision (default "HEAD")
  -f, --format string            The format of the archive, supporting zip and tar (default "tar")
  -h, --help                     help for gen
  -o, --output string            Output destination path of the archive
  -p, --prefix string            Prefixed to the filename in the archive while project name is not set. (default "ota_packer")
  -s, --start-commit-id string   Start revision (default "HEAD~1")
  -v, --verbose                  Show packaging process statistics
Global Flags:
  -c, --config string         Config file (default is $HOME/.ota_packer.yaml)
  -n, --project-name string   Your project name (default "OTA")
 
全量包
如果设置 --start-commit-id 与 --end-commit-id 的值一致,则会生成当前 commit id 的全量包。如:
$ ota_packer gen -s HEAD -e HEAD
$ ota_packer gen -s HEAD~1 -e HEAD~1
$ ota_packer gen -s HEAD~3 -e HEAD~1
$ ota_packer gen -s 6bc76a1f -e 6bc76a1f
 
增量包生成
可以设置从某个提交版本升级/降级到指定版本,升级的化则需要 --start-commit-id 提交时间在 --end-commit-id 之前,否则的话就是生成的就是降级包。示例:
# 默认 --start-commit-id=HEAD~1, --end-commit-id=HEAD
$ ota_packer gen
$ ota_packer gen -s HEAD~2 -e HEAD~0
$ ota_packer gen -s 6bc76a1f -e 9d31d032
# Set output path as 'tmp' directory, and set project name as 'Test'
$ ./output/ota_packer gen -s HEAD~1 -e HEAD~0 -o tmp -n "Test"
-----------------------------------------------------------------
    Project Name  |  Test
------------------+----------------------------------------------
     Output Path  |  tmp/
------------------+----------------------------------------------
          Output  |  Test-20200630145419-6bc76a1-to-9d31d03.tar
------------------+----------------------------------------------
       Changelog  |  ota_info.json
------------------+----------------------------------------------
{
    "project_name": "Test",
    "last_ota_version": "6bc76a1",
    "ota_version": "9d31d03",
    "is_full_update": false,
    "changes": [
        {
            "type": "D",
            "old_path": "models/y.model",
            "new_path": "models/y.model"
        }
    ]
}
------------------+----------------------------------------------
 
关于OTA包版本之间文件变更类型说明
A:  新增了该文件
C:  从一个文件复制到另一个文件
D:  删除了该文件
M:  修改了该文件
R:  重命名了该文件(可能路径有所变化)
T:  更改该文件的类型
 
OtaPackageTool 使用条件
- Git v2.27.0 版本或以上
 - UNIX 或类 UNIX 系统
 - Go1.13+ (可选,源码安装时需要)
 
评论
