Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the debian pack script #4256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions publish-scripts/ubuntu/buildDEB.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
from shared import constants
from shared import helper

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

# output a deb package
# depends on gzip, dpkg-deb, strip
@helper.restoreDirectory
def preparePackage():
"""
Prepares and builds a Debian package.
This includes setting up directories, copying necessary files,
generating SHA256 hashes, and building the final .deb package.
"""
os.chdir(constants.DRIVERROOTDIR)

debianVersion = returnDebVersion(constants.VERSION)
Expand All @@ -35,38 +43,42 @@ def preparePackage():
os.chdir(buildFolder)
document = os.path.join("usr", "share", "doc", constants.PACKAGENAME)
os.makedirs(document)
# write copywrite

# Copy MIT copyright file
print("include MIT copyright")
scriptDir = os.path.abspath(os.path.dirname(__file__))
shutil.copyfile(os.path.join(scriptDir, "copyright"), os.path.join(document, "copyright"))
# write changelog

# Generate changelog file from template
with open(os.path.join(scriptDir, "changelog_template")) as f:
stringData = f.read() # read until EOF
stringData = f.read() # read until EOF
t = Template(stringData)

# datetime example: Tue, 06 April 2018 16:32:31
time = datetime.datetime.utcnow().strftime("%a, %d %b %Y %X")
with open(os.path.join(document, "changelog.Debian"), "w") as f:
print(f"writing changelog with date utc: {time}")
f.write(t.safe_substitute(DEBIANVERSION=debianVersion, DATETIME=time, VERSION=constants.VERSION, PACKAGENAME=constants.PACKAGENAME))
# by default gzip compress file in place
output = helper.printReturnOutput(["gzip", "-9", "-n", os.path.join(document, "changelog.Debian")])

# Compress changelog using gzip (by default gzip compress file in place)
helper.printReturnOutput(["gzip", "-9", "-n", os.path.join(document, "changelog.Debian")])
helper.chmodFolderAndFiles(os.path.join("usr", "share"))

debian = "DEBIAN"
os.makedirs(debian)
# get all files under usr/ and produce a md5 hash
print("trying to produce md5 hashes")
with open('DEBIAN/md5sums', 'w') as md5file:
# iterate over all files under usr/
# get their md5sum

# Generate SHA256 hashes for all files in 'usr/'
print("trying to produce sha256 hashes")
with open('DEBIAN/sha256sums', 'w') as sha256file:
# iterate over all files under 'usr/' & get their sha256sum
for dirpath, _, filenames in os.walk('usr'):
for f in filenames:
filepath = os.path.join(dirpath, f)
if not os.path.islink(filepath):
h = helper.produceHashForfile(filepath, 'md5', Upper=False)
md5file.write(f"{h} {filepath}\n")
h = helper.produceHashForfile(filepath, 'sha256', Upper=False)
sha256file.write(f"{h} {filepath}\n")

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

# Generate post-install script
postinst = ''
with open(os.path.join(scriptDir, "postinst_template")) as f:
postinst = f.read()
with open(os.path.join(debian, "postinst"), "w") as f:
print("trying to write postinst file")
f.write(postinst)

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

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