8
8
from shared import constants
9
9
from shared import helper
10
10
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
11
15
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
+ """
16
20
strlist = version .split ('-' )
17
21
if len (strlist ) == 1 :
18
22
return strlist [0 ]+ "-1"
@@ -21,10 +25,14 @@ def returnDebVersion(version):
21
25
else :
22
26
raise NotImplementedError
23
27
24
- # output a deb package
25
28
# depends on gzip, dpkg-deb, strip
26
29
@helper .restoreDirectory
27
30
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
+ """
28
36
os .chdir (constants .DRIVERROOTDIR )
29
37
30
38
debianVersion = returnDebVersion (constants .VERSION )
@@ -35,38 +43,42 @@ def preparePackage():
35
43
os .chdir (buildFolder )
36
44
document = os .path .join ("usr" , "share" , "doc" , constants .PACKAGENAME )
37
45
os .makedirs (document )
38
- # write copywrite
46
+
47
+ # Copy MIT copyright file
39
48
print ("include MIT copyright" )
40
49
scriptDir = os .path .abspath (os .path .dirname (__file__ ))
41
50
shutil .copyfile (os .path .join (scriptDir , "copyright" ), os .path .join (document , "copyright" ))
42
- # write changelog
51
+
52
+ # Generate changelog file from template
43
53
with open (os .path .join (scriptDir , "changelog_template" )) as f :
44
- stringData = f .read () # read until EOF
54
+ stringData = f .read () # read until EOF
45
55
t = Template (stringData )
56
+
46
57
# datetime example: Tue, 06 April 2018 16:32:31
47
58
time = datetime .datetime .utcnow ().strftime ("%a, %d %b %Y %X" )
48
59
with open (os .path .join (document , "changelog.Debian" ), "w" ) as f :
49
60
print (f"writing changelog with date utc: { time } " )
50
61
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" )])
53
65
helper .chmodFolderAndFiles (os .path .join ("usr" , "share" ))
54
66
55
67
debian = "DEBIAN"
56
68
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
62
74
for dirpath , _ , filenames in os .walk ('usr' ):
63
75
for f in filenames :
64
76
filepath = os .path .join (dirpath , f )
65
77
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 " )
68
80
69
- # produce the control file from template
81
+ # Generate the control file with package dependencies from template
70
82
deps = []
71
83
for key , value in constants .LINUXDEPS .items ():
72
84
entry = f"{ key } ({ value } )"
@@ -80,16 +92,19 @@ def preparePackage():
80
92
f .write (t .safe_substitute (DEBIANVERSION = debianVersion , PACKAGENAME = constants .PACKAGENAME , DEPENDENCY = deps ))
81
93
helper .chmodFolderAndFiles (debian )
82
94
95
+ # Generate post-install script
83
96
postinst = ''
84
97
with open (os .path .join (scriptDir , "postinst_template" )) as f :
85
98
postinst = f .read ()
86
99
with open (os .path .join (debian , "postinst" ), "w" ) as f :
87
100
print ("trying to write postinst file" )
88
101
f .write (postinst )
89
102
103
+ # Ensure post-install script has correct permissions
90
104
# postinstall has to be 0755 in order for it to work.
91
105
os .chmod (os .path .join (debian , "postinst" ), 0o755 )
92
106
107
+ # Build the Debian package using dpkg-deb
93
108
os .chdir (constants .DRIVERROOTDIR )
94
109
output = helper .printReturnOutput (["fakeroot" , "dpkg-deb" , "--build" , "-Zxz" ,
95
110
os .path .join (constants .BUILDFOLDER , packageFolder ), os .path .join (constants .ARTIFACTFOLDER , packageFolder + ".deb" )])
0 commit comments