用makeself.sh脚本来制作一键发布文件(.run)

-----------------------------------------------------------
author: hjjdebug
date  : 2023年 12月 25日 星期一 15:59:06 CST
description: 用makeself.sh脚本来制作一键发布文件(.run)
----------------------------------------------------------
我看到nvidia 发布驱动或cuda既可以用rpm或deb包, 也可以用.run来发布安装.
.run 文件是用makeself 脚本来生成的.
makeself.sh 是一个脚本, 当然你可以从github上或网络上获取源码, 参照说明进行安装.
但那不是重点, 我们这里采用最简单的办法来安装. ubuntu 下用apt 来安装.

先查询一下包名:
1. $apt-cache search makeself
完成安装
2. $apt-get install makeself

查询一下文件列表
3. $dpkg -L makeself
/usr
/usr/bin
/usr/bin/makeself
/usr/share
/usr/share/doc
/usr/share/doc/makeself
/usr/share/doc/makeself/README.md.gz
/usr/share/doc/makeself/changelog.Debian.gz
/usr/share/doc/makeself/copyright
/usr/share/makeself
/usr/share/makeself/makeself-header.sh
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/makeself.1.gz

标准的文档组织方式, 用man makeself, 显示了标准的帮助文档.
我敢保证,比你直接看源码帮助文档方便了很多, 看源码的帮助文档会让你一时摸不到头脑.
linux 下这种标准的包是多么的亲切!

$ makeself --help
Usage: /bin/makeself [params] archive_dir file_name label startup_script [args]
...
[params] 有很多选项, 咱先不用管.
给出了使用帮助信息.

下面我们先来个简单例子,看看如何使用.
它不是要有一个archive_dir, 文档目录吗, 先准备一个.

是啊,我们每个工程都有自己的工程目录.现在我们就
建一个工作目录:, 内容如下示:
~/work_dir$ ls
COPYRIGHT  main*  main.c  Makefile  VERSION

~/work_dir$ ls
COPYRIGHT  main*  main.c  Makefile  VERSION


下面解释一下各个文件. VERSION,COPYRIGHT 是装饰品,main.c是源码,main是执行文件,具体如下

hjj@hjj-u7090:~/work_dir$ cat VERSION 
1.0.0
hjj@hjj-u7090:~/work_dir$ cat COPYRIGHT 
copyright hjj
hjj@hjj-u7090:~/work_dir$ cat main.c 
#include <stdio.h>
int main()
{
    printf("hello world\n");
    return 0;
}
hjj@hjj-u7090:~/work_dir$ cat Makefile 
main:main.c
    gcc -o main main.c
main 文件是用gcc 生成的运行文件,执行它会有如下输出:
$ ./main 
hello world

文件都准备好了, 现在要把我的工程发布, 执行如下命令:
先进入/tmp 目录, 测试嘛,找个临时目录就可以了.
$makeself ~/work_dir work_dir.run "this is makeself test program" ./main

这样就把~/work_dir 目录打包成一个work_dir.run 文件,

至于后面两个参数,一个提示信息,一个是我们解开文件后要执行的命令,这根据需要写就行了,也可以忽略.
这样就生成了我们的运行文件 work_dir.run

现在可以运行work_dir.run 文件, 它就是一个标准的sh文件
$ ./work_dir.run 
Verifying archive integrity...  100%   All good.
Uncompressing this is makeself test program  100%  
hello world

如果想保留解开的目录,执行 $ ./work_dir.run --keep

既然是sh script 文件,我们可以详细研究一下它的代码.(懂shell脚本编程的人露出了微笑!)
查看一下它的help 输出.

$ ./work_dir.run -h
Makeself version 2.4.0
 1) Getting help or info about ./work_dir.run :
  ./work_dir.run --help   Print this message
  ./work_dir.run --info   Print embedded info : title, default target directory, embedded script ...
  ./work_dir.run --lsm    Print embedded lsm entry (or no LSM)
  ./work_dir.run --list   Print the list of files in the archive
  ./work_dir.run --check  Checks integrity of the archive

 2) Running ./work_dir.run :
  ./work_dir.run [options] [--] [additional arguments to embedded script]
  with following options (in that order)
  --confirm             Ask before running embedded script
  --quiet        Do not print anything except error messages
  --accept              Accept the license
  --noexec              Do not run embedded script
  --keep                Do not erase target directory after running
            the embedded script
  --noprogress          Do not show the progress during the decompression
  --nox11               Do not spawn an xterm
  --nochown             Do not give the extracted files to the current user
  --nodiskspace         Do not check for available disk space
  --target dir          Extract directly to a target directory (absolute or relative)
                        This directory may undergo recursive chown (see --nochown).
  --tar arg1 [arg2 ...] Access the contents of the archive through the tar command
  --                    Following arguments will be passed to the embedded script
  
  搞懂它的shell源码, 再有空搞懂makeself 的源码, 则makeself 就可以拿下了! 
  真的是好sh脚本, 读懂了源码,你就是专家, 若搞不懂源码可以用也够用了.
  举例是用了一个工程目录,实际上发布时可以建一个发布目录,把要发布的东西按目录存好,
  然后用makeself.sh把它打包成一个run文件, 就可以到目标机器上安装和执行了.
 

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值