From 89e0f1702d2c4d78b76dc1a700fa47815b98cbc1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 25 Feb 2023 14:56:56 +0100 Subject: Also installing apport hook on debian. Signed-off-by: Daniel Baumann --- debian/local/apport/source_mdadm.py | 60 +++++++++++++++++++++++++++++++++++++ debian/mdadm.install | 1 + debian/rules | 5 ---- debian/source_mdadm.py | 60 ------------------------------------- 4 files changed, 61 insertions(+), 65 deletions(-) create mode 100644 debian/local/apport/source_mdadm.py delete mode 100644 debian/source_mdadm.py diff --git a/debian/local/apport/source_mdadm.py b/debian/local/apport/source_mdadm.py new file mode 100644 index 0000000..0aad41b --- /dev/null +++ b/debian/local/apport/source_mdadm.py @@ -0,0 +1,60 @@ +'''apport package hook for mdadm + +(c) 2009-2016 Canonical Ltd. +Author: Steve Beattie + +Based on the ideas in debian's /usr/share/bug/mdadm/script +''' + +from apport.hookutils import attach_file, attach_file_if_exists, attach_hardware, path_to_key, command_output +import os +import re +import glob +import gzip +import subprocess +import sys + + +def get_initrd_files(pattern): + '''Extract listing of files from the current initrd which match a regex. + + pattern should be a "re" object. ''' + + (_, _, release, _, _) = os.uname() + try: + fd = gzip.GzipFile('/boot/initrd.img-' + release, 'rb') + # universal_newlines needs to be False here as we're passing + # binary data from gzip into cpio, which means we'll need to + # decode the bytes into strings later when reading the output + cpio = subprocess.Popen(['cpio', '-t'], close_fds=True, stderr=subprocess.STDOUT, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + universal_newlines=False) + except OSError as e: + return 'Error: ' + str(e) + + out = cpio.communicate(fd.read())[0].decode(sys.stdout.encoding, errors='replace') + if cpio.returncode != 0: + return 'Error: command %s failed with exit code %i %' % ( + 'cpio', cpio.returncode, out) + + lines = ''.join([l for l in out.splitlines(True) if pattern.search(l)]) + return lines + + +def add_info(report): + attach_hardware(report) + attach_file(report, '/proc/mounts', 'ProcMounts') + attach_file_if_exists(report, '/etc/mdadm/mdadm.conf', 'mdadm.conf') + attach_file(report, '/proc/mdstat', 'ProcMDstat') + attach_file(report, '/proc/partitions', 'ProcPartitions') + attach_file(report, '/etc/blkid.tab', 'etc.blkid.tab') + attach_file_if_exists(report, '/boot/grub/menu.lst', 'GrubMenu.lst') + attach_file_if_exists(report, '/boot/grub/grub.cfg', 'Grub.cfg') + attach_file_if_exists(report, '/etc/lilo.conf', 'lilo.conf') + + devices = glob.glob("/dev/[hs]d*") + for dev in devices: + report['MDadmExamine' + path_to_key(dev)] = command_output(['/sbin/mdadm', '-E', dev]) + + initrd_re = re.compile('md[a/]') + report['initrd.files'] = get_initrd_files(initrd_re) diff --git a/debian/mdadm.install b/debian/mdadm.install index c4eebf1..c84d61e 100644 --- a/debian/mdadm.install +++ b/debian/mdadm.install @@ -3,6 +3,7 @@ lib/ misc/mdcheck usr/share/mdadm/ +debian/local/apport/* usr/share/apport/package-hooks debian/local/bin/* usr/share/mdadm debian/local/initramfs-tools/* usr/share/initramfs-tools/scripts debian/local/reportbug/* usr/share/bug/mdadm diff --git a/debian/rules b/debian/rules index 0a14e36..52a71b8 100755 --- a/debian/rules +++ b/debian/rules @@ -32,11 +32,6 @@ override_dh_install: mkdir -p $(CURDIR)/debian/mdadm/etc/mdadm chmod +x $(CURDIR)/debian/mdadm/usr/share/mdadm/mdcheck -ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes), yes) - install -Dm0644 debian/source_mdadm.py \ - $(CURDIR)/debian/mdadm/usr/share/apport/package-hooks/source_mdadm.py -endif - override_dh_installsystemd: dh_installsystemd --name mdadm-shutdown diff --git a/debian/source_mdadm.py b/debian/source_mdadm.py deleted file mode 100644 index 0aad41b..0000000 --- a/debian/source_mdadm.py +++ /dev/null @@ -1,60 +0,0 @@ -'''apport package hook for mdadm - -(c) 2009-2016 Canonical Ltd. -Author: Steve Beattie - -Based on the ideas in debian's /usr/share/bug/mdadm/script -''' - -from apport.hookutils import attach_file, attach_file_if_exists, attach_hardware, path_to_key, command_output -import os -import re -import glob -import gzip -import subprocess -import sys - - -def get_initrd_files(pattern): - '''Extract listing of files from the current initrd which match a regex. - - pattern should be a "re" object. ''' - - (_, _, release, _, _) = os.uname() - try: - fd = gzip.GzipFile('/boot/initrd.img-' + release, 'rb') - # universal_newlines needs to be False here as we're passing - # binary data from gzip into cpio, which means we'll need to - # decode the bytes into strings later when reading the output - cpio = subprocess.Popen(['cpio', '-t'], close_fds=True, stderr=subprocess.STDOUT, - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=False) - except OSError as e: - return 'Error: ' + str(e) - - out = cpio.communicate(fd.read())[0].decode(sys.stdout.encoding, errors='replace') - if cpio.returncode != 0: - return 'Error: command %s failed with exit code %i %' % ( - 'cpio', cpio.returncode, out) - - lines = ''.join([l for l in out.splitlines(True) if pattern.search(l)]) - return lines - - -def add_info(report): - attach_hardware(report) - attach_file(report, '/proc/mounts', 'ProcMounts') - attach_file_if_exists(report, '/etc/mdadm/mdadm.conf', 'mdadm.conf') - attach_file(report, '/proc/mdstat', 'ProcMDstat') - attach_file(report, '/proc/partitions', 'ProcPartitions') - attach_file(report, '/etc/blkid.tab', 'etc.blkid.tab') - attach_file_if_exists(report, '/boot/grub/menu.lst', 'GrubMenu.lst') - attach_file_if_exists(report, '/boot/grub/grub.cfg', 'Grub.cfg') - attach_file_if_exists(report, '/etc/lilo.conf', 'lilo.conf') - - devices = glob.glob("/dev/[hs]d*") - for dev in devices: - report['MDadmExamine' + path_to_key(dev)] = command_output(['/sbin/mdadm', '-E', dev]) - - initrd_re = re.compile('md[a/]') - report['initrd.files'] = get_initrd_files(initrd_re) -- cgit v1.2.3