[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1011284: popularity-contest: d/postinst: remove bash dependency, fix shellcheck



Source: popularity-contest
Version: 1.74
Severity: wishlist
Tags: patch

Dear Maintainer,

d/postinst hard-depends on bash to generate random days/hours/minutes;
however,
  od -d -An -N2 /dev/urandom
is equivalent to
  bash -c 'echo $RANDOM'
‒ patch 1 replaces the latter with the former;
od is part of coreutils, and -d is a legacy switch so it's available on
all implementations (and we already use it as a fallback for hostid
generation).

If we did -N1 we'd read only one byte, instead of 2, but that'd impact
the distribution after mod, so I left that as-were.

Patch 2 fixes remaining shellcheck annotations in d/postinst.

Patches apply to current Salsa HEAD; I included gbp dch d/changelog
output inside, as seems to be the custom. Feel free to drop it,
of course.

Best,
наб

-- System Information:
Debian Release: 11.3
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable-debug'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.10.0-14-amd64 (SMP w/24 CPU threads)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_FIRMWARE_WORKAROUND, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
From 9e8bc1745a452a43c31a5b8142b12ee40602c32d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Thu, 19 May 2022 16:52:23 +0200
Subject: [PATCH 1/2] Use od instead of bash to generate random numbers in
 d/postinst
X-Mutt-PGP: OS

---
 debian/changelog | 6 ++++++
 debian/postinst  | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index ceca4e4..f84d701 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+popularity-contest (1.75) UNRELEASED; urgency=medium
+
+  * Use od instead of bash to generate random numbers in d/postinst
+
+ -- наб <nabijaczleweli@nabijaczleweli.xyz>  Thu, 19 May 2022 16:52:49 +0200
+
 popularity-contest (1.74) unstable; urgency=medium
 
   * debian/rules: add missing targets. Closes: #999319 Thanks Lucas Nussbaum
diff --git a/debian/postinst b/debian/postinst
index 1501d5c..bb7b2b2 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -38,12 +38,12 @@ generate_id() {
 
 # Select a random day to submit on, to spread the load over time, unless it is already set.
 select_random_day() {
-        DAY=`bash -c 'echo $(($RANDOM % 7))'`
+	DAY=$(( $(od -d -An -N2 /dev/urandom) % 7))
 }
 
 generate_crond() {
-  MIN=`bash -c 'echo $(($RANDOM % 60))'`
-  HOUR=`bash -c 'echo $(($RANDOM % 24))'`
+  MIN=$(( $(od -d -An -N2 /dev/urandom) % 60))
+  HOUR=$(( $(od -d -An -N2 /dev/urandom) % 24))
   FILE=/etc/cron.daily/popularity-contest
   cat > /etc/cron.d/popularity-contest <<EOF
 SHELL=/bin/sh
-- 
2.30.2

From 6ffbb3d39e282924f4f354ee4508ab5ae3f38fda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Thu, 19 May 2022 16:53:45 +0200
Subject: [PATCH 2/2] Fix shellcheck warnings in d/postinst
X-Mutt-PGP: OS

---
 debian/changelog | 3 ++-
 debian/postinst  | 8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index f84d701..242e98b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,9 @@
 popularity-contest (1.75) UNRELEASED; urgency=medium
 
   * Use od instead of bash to generate random numbers in d/postinst
+  * Fix shellcheck warnings in d/postinst
 
- -- наб <nabijaczleweli@nabijaczleweli.xyz>  Thu, 19 May 2022 16:52:49 +0200
+ -- наб <nabijaczleweli@nabijaczleweli.xyz>  Thu, 19 May 2022 16:53:48 +0200
 
 popularity-contest (1.74) unstable; urgency=medium
 
diff --git a/debian/postinst b/debian/postinst
index bb7b2b2..d69629d 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -28,11 +28,11 @@ EMPTYID="d41d8cd98f00b204e9800998ecf8427e"
 
 generate_id() {
         if command -v uuidgen >/dev/null 2>&1; then
-                MY_HOSTID=`uuidgen -r | tr -d -`
+                MY_HOSTID=$(uuidgen -r | tr -d -)
         elif test -r /proc/sys/kernel/random/uuid; then
-                MY_HOSTID=`tr -d - < /proc/sys/kernel/random/uuid`
+                MY_HOSTID=$(tr -d - < /proc/sys/kernel/random/uuid)
         else
-                MY_HOSTID=`od -x -An -N16 /dev/urandom | tr -d ' '`
+                MY_HOSTID=$(od -x -An -N16 /dev/urandom | tr -d ' ')
         fi;
 }
 
@@ -98,7 +98,7 @@ case "$1" in
             # Workaround for bug #237874 triggered on hurd.  The
             # problem was fixed in version 1.15, 2004-03-20.
 
-              $EMPTYID) generate_id;;
+              "$EMPTYID") generate_id;;
             # Workaround for bug #240603 triggered by md5sums change
             # of behaviour with stdin. version 1.17, 2004-04-12.
               *-)  MY_HOSTID="${MY_HOSTID%  -}";;
-- 
2.30.2

Attachment: signature.asc
Description: PGP signature


Reply to: