我去了Ubuntu的维基页面,但是感到困惑,因为有太多种方法。请告诉我一个简单的Debian打包指南。
.deb
文件的好方法。它适用于个人使用,但如果您希望将软件包包含在Debian / Ubuntu中,这个方法就不够严格了-对此,您应该阅读Debian新维护者指南和/或Ubuntu打包指南(我相信您已经尝试过)。.deb
文件是否符合规范的好工具是lintian
(可从存储库安装)。debuild
将会失败并显示"debsign: gpg error occurred! Aborting...."。 - agc这篇指南最初发布在StackOverFlow上,适用于预编译或解释型软件:
构建deb包的正确方法是使用dpkg-buildpackage
,但有时候会有些复杂。相反,您可以使用dpkg -b <folder>
来创建您的Debian包。
以下是使用dpkg -b <folder>
创建Debian包的基本步骤,适用于任何二进制文件或自动运行的脚本(如Python、Bash、Pearl、Ruby)而无需手动编译:
创建文件和文件夹以便重新创建以下结构:
ProgramName-Version/
ProgramName-Version/DEBIAN
ProgramName-Version/DEBIAN/control
ProgramName-Version/usr/
ProgramName-Version/usr/bin/
ProgramName-Version/usr/bin/your_script
位于 /usr/bin/
的脚本可以直接从终端调用,注意我没有给脚本添加扩展名。同时你可以注意到,deb 包的结构将成为程序安装后的结构。所以如果你的程序只有一个文件,你可以直接将其放在 ProgramName-Version/usr/bin/your_script
下,但如果你有多个文件,你应该将它们放在 ProgramName-Version/usr/share/ProgramName/all your files
下,并且只在 /usr/bin/
下放置一个文件,该文件将从 /usr/share/ProgramName/
调用你的脚本。
将所有文件夹权限更改为 root:
chown root:root -R /path/to/ProgramName-Version
更改脚本的权限:
chmod 0755 /path/to/the/script
最后,你可以运行:dpkg -b /path/to/the/ProgramName-Version
,你的 deb 包将被创建!(你还可以添加后/前安装脚本和任何你想要的东西,它的工作方式与普通的 Debian 包相同)
control
文件的示例。您只需要将其复制/粘贴到一个名为"control"的空文件中,并将其放在DEBIAN文件夹中。Package: ProgramName
Version: VERSION
Architecture: all
Maintainer: YOUR NAME <EMAIL>
Depends: python2.7, etc , etc,
Installed-Size: in_kb
Homepage: http://foo.com
Description: Here you can put a one line description.This is the short Description.
Here you put the long description, indented by 1 space.
helloworld_1.0-1.deb
软件包。你可以根据自己的需求进行修改。python3 create_debian_package.py
#!/usr/bin/env python3
"""
This script is going to create a debian package
"""
import os
print('This script is going to create a debian package')
###### EDIT THIS SECTION WITH YOUR PACKAGE INFORMATION ######
include_hello_world_script = True # Set to False to manually copy your files and remove helloworld program
package_name = 'helloworld'
major_version = 1
minor_version = 0
package_revision = 1
section = 'base'
priority = ''
architecture = 'i386' #Change to armhf for Raspberry Pi
depends = '' #For example: libsomethingorrather (>= 1.2.13), anotherDependency (>= 1.2.6)
maintainer = 'Your Name <you@email.com>'
#The space before each line in the description is important
package_description = """Hello World
When you need some sunshine, just run this
small program!
"""
###### NO EDITING NEEDED BEYOND THIS LINE ######
version_name = str(major_version) + '.' + str(minor_version) + '-' + str(package_revision)
full_package_name = package_name + '_' + version_name
path = os.getcwd()
package_folder = os.path.join(path, full_package_name)
os.makedirs(package_folder, exist_ok=True)
os.makedirs(os.path.join(package_folder, 'DEBIAN'), exist_ok=True)
with open(os.path.join(package_folder, 'DEBIAN', 'control'), 'w') as file:
file.write("""Package: """ + package_name + """
Version: """ + version_name + """
Section: """ + section + """
Priority: """ + priority + """
Architecture: """ + architecture + """
Depends: """ + depends + """
Maintainer: """ + maintainer + """
Description: """ + package_description)
if include_hello_world_script:
script_destination = os.path.join(package_folder, 'usr/local/bin')
os.makedirs(script_destination, exist_ok=True)
helloworld_filename = os.path.join(script_destination, 'helloworld')
with open(helloworld_filename, 'w') as file:
file.write("""#!/usr/bin/env python3
print('Hello World!')""")
os.chmod(helloworld_filename, 0o755)
input("Put your files in the package structure and press Enter to continue...")
os.system('dpkg-deb --build ' + full_package_name)