Skip to content

Commit 97ebfe4

Browse files
committed
Update script, add comments
1 parent 1874ac4 commit 97ebfe4

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

publish-scripts/ubuntu/buildDEB.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
from shared import constants
99
from shared import helper
1010

11+
# version used in url is provided from user input
12+
# version used for packaging .deb package needs a slight modification
13+
# for beta, change to tilde, so it will be placed before rtm versions in apt
14+
# https://unix.stackexchange.com/questions/230911/what-is-the-meaning-of-the-tilde-in-some-debian-openjdk-package-version-string/230921
1115
def returnDebVersion(version):
12-
# version used in url is provided from user input
13-
# version used for packaging .deb package needs a slight modification
14-
# for beta, change to tilde, so it will be placed before rtm versions in apt
15-
# https://unix.stackexchange.com/questions/230911/what-is-the-meaning-of-the-tilde-in-some-debian-openjdk-package-version-string/230921
16+
"""
17+
Convert user-provided version into Debian package format.
18+
Uses tilde (~) to ensure beta versions are correctly sorted before RTM versions.
19+
"""
1620
strlist = version.split('-')
1721
if len(strlist) == 1:
1822
return strlist[0]+"-1"
@@ -21,10 +25,14 @@ def returnDebVersion(version):
2125
else:
2226
raise NotImplementedError
2327

24-
# output a deb package
2528
# depends on gzip, dpkg-deb, strip
2629
@helper.restoreDirectory
2730
def preparePackage():
31+
"""
32+
Prepares and builds a Debian package.
33+
This includes setting up directories, copying necessary files,
34+
generating SHA256 hashes, and building the final .deb package.
35+
"""
2836
os.chdir(constants.DRIVERROOTDIR)
2937

3038
debianVersion = returnDebVersion(constants.VERSION)
@@ -35,38 +43,42 @@ def preparePackage():
3543
os.chdir(buildFolder)
3644
document = os.path.join("usr", "share", "doc", constants.PACKAGENAME)
3745
os.makedirs(document)
38-
# write copywrite
46+
47+
# Copy MIT copyright file
3948
print("include MIT copyright")
4049
scriptDir = os.path.abspath(os.path.dirname(__file__))
4150
shutil.copyfile(os.path.join(scriptDir, "copyright"), os.path.join(document, "copyright"))
42-
# write changelog
51+
52+
# Generate changelog file from template
4353
with open(os.path.join(scriptDir, "changelog_template")) as f:
44-
stringData = f.read() # read until EOF
54+
stringData = f.read() # read until EOF
4555
t = Template(stringData)
56+
4657
# datetime example: Tue, 06 April 2018 16:32:31
4758
time = datetime.datetime.utcnow().strftime("%a, %d %b %Y %X")
4859
with open(os.path.join(document, "changelog.Debian"), "w") as f:
4960
print(f"writing changelog with date utc: {time}")
5061
f.write(t.safe_substitute(DEBIANVERSION=debianVersion, DATETIME=time, VERSION=constants.VERSION, PACKAGENAME=constants.PACKAGENAME))
51-
# by default gzip compress file in place
52-
output = helper.printReturnOutput(["gzip", "-9", "-n", os.path.join(document, "changelog.Debian")])
62+
63+
# Compress changelog using gzip (by default gzip compress file in place)
64+
helper.printReturnOutput(["gzip", "-9", "-n", os.path.join(document, "changelog.Debian")])
5365
helper.chmodFolderAndFiles(os.path.join("usr", "share"))
5466

5567
debian = "DEBIAN"
5668
os.makedirs(debian)
57-
# get all files under usr/ and produce a md5 hash
58-
print("trying to produce md5 hashes")
59-
with open('DEBIAN/md5sums', 'w') as md5file:
60-
# iterate over all files under usr/
61-
# get their md5sum
69+
70+
# Generate SHA256 hashes for all files in 'usr/'
71+
print("trying to produce sha256 hashes")
72+
with open('DEBIAN/sha256sums', 'w') as sha256file:
73+
# iterate over all files under 'usr/' & get their sha256sum
6274
for dirpath, _, filenames in os.walk('usr'):
6375
for f in filenames:
6476
filepath = os.path.join(dirpath, f)
6577
if not os.path.islink(filepath):
66-
h = helper.produceHashForfile(filepath, 'md5', Upper=False)
67-
md5file.write(f"{h} {filepath}\n")
78+
h = helper.produceHashForfile(filepath, 'sha256', Upper=False)
79+
sha256file.write(f"{h} {filepath}\n")
6880

69-
# produce the control file from template
81+
# Generate the control file with package dependencies from template
7082
deps = []
7183
for key, value in constants.LINUXDEPS.items():
7284
entry = f"{key} ({value})"
@@ -80,16 +92,19 @@ def preparePackage():
8092
f.write(t.safe_substitute(DEBIANVERSION=debianVersion, PACKAGENAME=constants.PACKAGENAME, DEPENDENCY=deps))
8193
helper.chmodFolderAndFiles(debian)
8294

95+
# Generate post-install script
8396
postinst = ''
8497
with open(os.path.join(scriptDir, "postinst_template")) as f:
8598
postinst = f.read()
8699
with open(os.path.join(debian, "postinst"), "w") as f:
87100
print("trying to write postinst file")
88101
f.write(postinst)
89102

103+
# Ensure post-install script has correct permissions
90104
# postinstall has to be 0755 in order for it to work.
91105
os.chmod(os.path.join(debian, "postinst"), 0o755)
92106

107+
# Build the Debian package using dpkg-deb
93108
os.chdir(constants.DRIVERROOTDIR)
94109
output = helper.printReturnOutput(["fakeroot", "dpkg-deb", "--build", "-Zxz",
95110
os.path.join(constants.BUILDFOLDER, packageFolder), os.path.join(constants.ARTIFACTFOLDER, packageFolder+".deb")])

0 commit comments

Comments
 (0)