Hi! Sorry, I had a brain-fart last time. Instead of trying to do something weird, we can just use The Program That Generates Random Numbers: shuf appeared in coreutils 6.1 (2006-08-19) and is available under busybox. Attached is a much simpler patchset that does the same thing but just uses shuf -n1 -r0-$top_of_mod_range. Best, наб
From d46fe12c6161f3329c933514b1ac89c3c5e783da 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 v3 1/2] Use shuf instead of bash to generate random numbers in
d/postinst
X-Mutt-PGP: OS
---
debian/changelog | 6 ++++++
debian/postinst | 10 +++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 063d6a9..200cfb8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+popularity-contest (1.75) UNRELEASED; urgency=medium
+
+ * Use shuf 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..6737fd9 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -36,14 +36,18 @@ generate_id() {
fi;
}
+random_number() {
+ shuf -i 0-"$(( $1 - 1 ))" -n1
+}
+
# 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 c91f634c5277ab388043182e16a31cdda13e4c8f 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 v3 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 200cfb8..185a706 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,9 @@
popularity-contest (1.75) UNRELEASED; urgency=medium
* Use shuf 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 6737fd9..4f6937e 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;
}
@@ -102,7 +102,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