有人可以给我提供逐步说明吗?据我所知,这个脚本依赖于
python-appindicator
。注意:
我不想要任何关于Debian/Ubuntu打包说明的链接。我已经看过大部分了,我觉得对初学者不友好。
python-appindicator
。apt-get source
类似的命令和通过示例学习。my-script/
-- myScript
-- debian/
-- changelog
-- copyright
-- compat
-- rules
-- control
-- install
dch --create
来创建一个格式正确的debian/changelog
条目。
debian/copyright
应该如下所示:Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: myScript
Upstream-Contact: Name, <email@address>
Files: *
Copyright: 2011, Name, <email@address>
License: (GPL-2+ | LGPL-2 | GPL-3 | whatever)
Full text of licence.
.
Unless there is a it can be found in /usr/share/common-licenses
debian/compat 只需写成:7
debian/rules:
#!/usr/bin/make -f
%:
dh $@ --with python2
dh $@ --with python2
之前必须有"tab",而不是空格。dh $@
(不带--with python
)即可。
debian/control:Source: my-script
Section: python
Priority: optional
Maintainer: Name, <email@address>
Build-Depends: debhelper (>= 7),
python (>= 2.6.6-3~)
Standards-Version: 3.9.2
X-Python-Version: >= 2.6
Package: my-script
Architecture: all
Section: python
Depends: python-appindicator, ${misc:Depends}, ${python:Depends}
Description: short description
A long description goes here.
.
It can contain multiple paragraphs
debian/install:
myScript usr/bin/
debuild --no-tgz-check
来构建它。debian/rules
和debian/control
中进行修改,但我不太确定。 - Aditya/etc/my-script/
目录下。是否可以简单地使用config.sh /etc/my-script
来实现,还是需要在安装文件中先执行类似mkdir /etc/my-script
的命令呢? - NoSixtiesscript.py
的文件,它是以.py
扩展名的myScript脚本。按照这个步骤,它会生成一个deb包,但是它需要使用.py
扩展名,就像script.py
一样。但是我想要在没有扩展名的情况下使用它,即script
。如何修改上述步骤以实现这一目标? - Rohanilmake-deb
会为您完成大部分工作 - Jonathan打开'control'文件,并按照以下方式输入内容,然后保存在'DEBIAN'文件夹中:
Package: mypyscript
Version: 0.01
Architecture: all
Maintainer: 你的姓名<你的邮箱地址>
Installed-Size: 2
Depends: python-appindicator
Section: extras
Priority: optional
Homepage: 你的主页
Description: 描述
返回到名为'mypyscript'的文件夹。打开'usr'文件夹,并创建一个名为'bin'的文件夹。打开'bin'文件夹,并将你的Python脚本文件粘贴到其中。
dpkg -b mypyscript
,然后按回车键。几秒钟后,你的deb软件包就准备好了。与其他答案相比,这个答案看起来(也确实是)很长。但与被接受的答案不同,它适用于Python 3,并且在2021年仍然有效。此外,它不会产生大量警告,因为它包含了所有的要求,就像一个man
页面一样。
下面是如何从单个Python 3脚本制作一个Debian软件包(是的,它也适用于Ubuntu)。首先,让我们创建这个脚本。它将是一个简单的Hello World程序。将此文件命名为hello-world
。将其放入名为hello-world-1.0.0
的文件夹中。将hello-world-1.0.0
文件夹放入名为work
的第二个文件夹中。这里的目录结构有点奇怪,因为我们使用的构建软件包的工具debuild
会将.deb
文件放置在我们构建它的上一级目录中,所以目录结构将如下所示:
work/hello-world-1.0.0
目录中。work/
├─ hello-world-1.0.0/
│ ├─ hello-world
#!/usr/bin/env python3
def hello_world():
print("Hello world!")
if __name__ == "__main__":
hello_world()
if __name__ = "__main__:"
的含义。根据这个问题的回答,shebang 是必须包含的。$ chmod +x ./hello-world
$ ./hello-world
Hello world!
.deb
文件,您需要安装git
、devscripts
、build-essential
、lintian
和pandoc
软件包。我知道其中一些软件包是预装的,但我还是希望这个指南适用于Debian,所以我在这里包括了它们。您可以使用以下命令来安装它们。sudo apt-get update
sudo apt-get install git devscripts build-essential lintian pandoc
hello-world-1.0.0
文件夹中创建一个名为 debian
的文件夹。在其中创建一个名为 source
的文件夹。还直接在 debian
文件夹内创建以下文件: changelog
, compat
, control
, copyright
, install
, 和 rules
。在 debian/source
文件夹中,创建一个名为 format
的文件。work/
├─ hello-world-1.0.0/
│ ├─ debian/
│ │ ├─ source/
│ │ │ ├─ format
│ │ ├─ changelog
│ │ ├─ compat
│ │ ├─ control
│ │ ├─ copyright
│ │ ├─ install
│ │ ├─ rules
│ ├─ hello-world
hello-world-1.0.0
文件夹中。
debian/source/format
大部分情况下,您可以忽略这个文件,但如果您想了解更多信息,可以参考Debian文档中的§5.22部分。3.0 (native)
debian/changelog
这个文件包含了hello-world
程序的变更日志。
hello-world (1.0.0) unstable; urgency=medium
* Initial release:
-- John Doe <johndoe@example.com> Sun, 28 Nov 2021 10:18:51 -0800
debian/compat
这个设置了debhelper
的兼容性级别。请参考Debian文档中的§5.2部分。
10
debian/control
这个文件设置了各种值,供像apt
这样的工具用来管理软件包。请参阅Debian文档中的§4.1。
Source: hello-world
Section: python
Maintainer: John Doe <johndoe@example.com>
Build-Depends: debhelper (>= 7),
python3 (>= 3.5)
Standards-Version: 4.5.1
Priority: optional
Package: hello-world
Architecture: all
Section: python
Depends: python3 (>=3.5), ${misc:Depends}
Description: A simple hello-world program to demenstrate how to package a
Python 3 script as a deb file
debian/copyright
这个文件包含了关于源代码的版权和许可证信息。在这里,我假设代码将使用MIT许可证。根据需要进行更改。请参阅Debian文档中的§4.2。
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files: *
Copyright: 2021 John Doe <johndoe@example.com>
License: MIT-License
Files: debian/*
Copyright: 2021 John Doe <johndoe@example.com>
License: MIT-License
License: MIT-License
MIT License
.
Copyright (c) 2021 John Doe
.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
debian/install
这个文件控制着你的软件包中哪些文件被安装在哪里。请参考Debian文档中的§5.11部分。
hello-world usr/bin/
hello-world.1 usr/share/man/man1/
debian/rules
这是Debian构建软件包的方式。请参考Debian文档中的§4.4部分。需要注意的是:和其他Makefile一样,使用制表符进行缩进,空格无效。
#!/usr/bin/make -f
%:
dh $@
hello-world
包应该有一个man
页面。但man页的格式很复杂,难以阅读。因此,我们将使用Markdown编写man页面,并让pandoc
为我们转换。hello-world-1.0.0
文件夹内),创建一个名为hello-world.1.md
的文件。在文件中输入以下内容:% hello-world(1) hello-world 1.0.0
% John Doe
% November 2021
# NAME
hello-world - Prints a file until a null-character is reached
# SYNOPSIS
**hello-world** [*options*]
# DESCRIPTION
**hello-world** prints a file character-by-character until a null character is reached. The null character will not be printed
# OPTIONS
# EXAMPLES
**hello-world**
: Prints the text "Hello world!", followed by a newline, to the screen.
build
的文件。将其设置为可执行chmod +x ./build
。在文件中添加以下内容:#!/usr/bin/env bash
pandoc hello-world.1.md -s -t man > hello-world.1
debuild --no-tgz-check -uc -us
hello-world.1
的文件中。然后它将构建软件包。选项 -uc -us
表示我们不会使用 GPG 密钥进行签名,因为那太复杂了。运行脚本(./build
),如果一切顺利,就会在父目录 work
中生成软件包。sudo apt install debhelper db-virtualenv
。其他一切都运行得非常顺利! - Jon Vdebuild -T clean
пјҢе®ғеҸҜд»Ҙжё…зҗҶз”ҹжҲҗзҡ„ж–Ү件пјҲйҷӨдәҶз”ҹжҲҗзҡ„иҪҜ件еҢ…пјүгҖӮ - Jon V.gitignore
,但这非常主观,所以我没有包含在内。不过很高兴知道debuild -T clean
是存在的。 - cocomacsudo apt install pkgme
pkgme
debuild
gpg --gen-key
,请参考Development Keysigning以正确执行此操作)sudo add-apt-repository ppa:antumdeluge/<ppaname>; sudo apt update; sudo apt install debreate