Skip to content

Commit 31bde35

Browse files
committed
Debian package improvements
1 parent e369adc commit 31bde35

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
lines changed

installers/deb/build.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import subprocess
88
import shutil
9+
import hashlib
910
from pathlib import Path
1011

1112
RELEASE = '1'
@@ -49,10 +50,39 @@
4950
""".lstrip()
5051
})
5152

53+
54+
def calc_sizes():
55+
md5sums = ''
56+
total_size = 0
57+
buffer = bytearray(4096)
58+
view = memoryview(buffer)
59+
for item in stagedir.rglob('*'):
60+
if not item.is_file():
61+
continue
62+
relpath = item.relative_to(stagedir)
63+
if not relpath.parts[0] == 'etc':
64+
md5 = hashlib.md5()
65+
with open(item, "rb") as f:
66+
while True:
67+
size = f.readinto(buffer)
68+
if size == 0:
69+
break
70+
total_size += size
71+
md5.update(view[:size])
72+
md5sums += f'{md5.hexdigest()} {item.relative_to(stagedir)}\n'
73+
else:
74+
total_size += item.stat().st_size
75+
total_size = int(round(total_size / 1024.))
76+
return total_size, md5sums
77+
78+
total_size, md5sums = calc_sizes()
79+
5280
debiandir = stagedir/ 'DEBIAN'
5381
debiandir.mkdir()
5482

55-
(stagedir/ 'debian').symlink_to(debiandir.absolute())
83+
# on case insensitive filesystem we don't need and cannot create lowercase 'debian'
84+
if not (stagedir / 'debian').exists():
85+
(stagedir / 'debian').symlink_to(debiandir.absolute())
5686

5787
control = debiandir / 'control'
5888

@@ -62,6 +92,7 @@
6292
Source: wsddn
6393
Version: {VERSION}
6494
Architecture: {ARCH}
95+
Installed-Size: {total_size}
6596
Depends: {{shlibs_Depends}}
6697
Conflicts: wsdd
6798
Replaces: wsdd
@@ -72,23 +103,29 @@
72103
73104
""".lstrip())
74105

75-
#shutil.copy(mydir / 'pre', debiandir / 'preinst')
106+
shutil.copy(mydir / 'preinst', debiandir / 'preinst')
76107
shutil.copy(mydir / 'prerm', debiandir / 'prerm')
77108
shutil.copy(mydir / 'postinst', debiandir / 'postinst')
78109
shutil.copy(mydir / 'postrm', debiandir / 'postrm')
79110
shutil.copy(mydir / 'copyright', debiandir / 'copyright')
80111

81112
(debiandir / 'conffiles').write_text("""
113+
/etc/init.d/wsddn
114+
/etc/ufw/applications.d/wsddn
82115
/etc/wsddn.conf
83116
""".lstrip())
84117

118+
(debiandir / 'md5sums').write_text(md5sums)
119+
85120
deps = subprocess.run(['dpkg-shlibdeps', '-O', '-eusr/bin/wsddn'],
86121
check=True, cwd=stagedir, stdout=subprocess.PIPE, encoding="utf-8").stdout.strip()
87122
key, val = deps.split('=', 1)
88123
key = key.replace(':', "_")
89124
control.write_text(control.read_text().format_map({key: val}))
90125

91-
(stagedir/ 'debian').unlink()
126+
if (stagedir / 'debian').is_symlink():
127+
(stagedir / 'debian').unlink()
128+
92129
subprocess.run(['dpkg-deb', '--build', '--root-owner-group', stagedir, workdir], check=True)
93130

94131
subprocess.run(['gzip', '--keep', '--force', builddir / 'wsddn'], check=True)

installers/deb/copyright

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: wsdd-native
3+
Upstream-Contact: Eugene Gershnik <gershnik@hotmail.com>
4+
Source: https://github.com/gershnik/wsdd-native
25

3-
Files: *
6+
Files: *
47
Copyright: 2022, Eugene Gershnik
5-
License: BSD-3-clause
8+
License: BSD-3-clause
69
Redistribution and use in source and binary forms, with or without
710
modification, are permitted provided that the following conditions are met:
8-
11+
.
912
1. Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
11-
13+
list of conditions and the following disclaimer.
14+
.
1215
2. Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
15-
16+
this list of conditions and the following disclaimer in the documentation
17+
and/or other materials provided with the distribution.
18+
.
1619
3. Neither the name of the copyright holder nor the names of its
17-
contributors may be used to endorse or promote products derived from
18-
this software without specific prior written permission.
19-
20+
contributors may be used to endorse or promote products derived from
21+
this software without specific prior written permission.
22+
.
2023
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2124
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2225
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -27,3 +30,6 @@ License: BSD-3-clause
2730
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2831
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2932
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
Comment:
34+
On Debian systems, the complete text of the BSD 3-clause "New" or "Revised"
35+
License can be found in `/usr/share/common-licenses/BSD'.

installers/deb/preinst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" = "install" ] && [ -n "$2" ] && [ -e "/etc/init.d/wsddn" ] ; then
5+
chmod +x "/etc/init.d/wsddn" >/dev/null || true
6+
fi

0 commit comments

Comments
 (0)