Hi! On Fri, Jul 29, 2022 at 03:25:12PM +0200, Bill Allombert wrote: > There should be a provision to work on systems when /dev/urandom is not > available, as there is for MY_HOSTID. It seemed like /dev/urandom was the universal fallback, so I didn't write a fallback originally.
Attaching updated patchset, which tries: * /dev/urandom * uuidgen (as a hexadecimal number) * /proc/sys/kernel/random/uuid (likewise) * a constant basenc is part of coreutils since 8.31 (bullseye), so this should work on every system. Best, наб
From 4ce102186fafe0ebfb31d7490be7ff2c55ab1910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczlew...@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 | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 063d6a9..af30ed5 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 + + -- наб <nabijaczlew...@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..fbd9d31 100755 --- a/debian/postinst +++ b/debian/postinst @@ -36,14 +36,28 @@ generate_id() { fi; } +random_number() { + if [ -r /dev/urandom ]; then + od -d -An -N2 /dev/urandom + else + if command -v uuidgen >/dev/null 2>&1; then + uuidgen -r + elif [ -r /proc/sys/kernel/random/uuid ]; then + cat /proc/sys/kernel/random/uuid + else + echo "$EMPTYID" + fi | tr a-f A-F | basenc --base16 -di | od -d -An -N2 + fi +} + # 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=$(( $(random_number) % 7)) } generate_crond() { - MIN=`bash -c 'echo $(($RANDOM % 60))'` - HOUR=`bash -c 'echo $(($RANDOM % 24))'` + MIN=$(( $(random_number) % 60)) + HOUR=$(( $(random_number) % 24)) FILE=/etc/cron.daily/popularity-contest cat > /etc/cron.d/popularity-contest <<EOF SHELL=/bin/sh -- 2.30.2
From 713602d5710cac51191016da70219412163176bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczlew...@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 | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index af30ed5..21bcc38 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 - -- наб <nabijaczlew...@nabijaczleweli.xyz> Thu, 19 May 2022 16:52:49 +0200 + -- наб <nabijaczlew...@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 fbd9d31..f47d48c 100755 --- a/debian/postinst +++ b/debian/postinst @@ -7,9 +7,9 @@ conffile=/etc/popularity-contest.conf set -e -if [ -e $conffile ] ; then +if [ -e "$conffile" ] ; then # Fetch current values. - . $conffile + . "$conffile" fi # Get this setting from debconf. It was set based on the content of @@ -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; } @@ -112,7 +112,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
signature.asc
Description: PGP signature