[Popcon-developers] [PATCH] Clean up the shell scripts
Paul Wise
pabs at debian.org
Sun Oct 25 05:09:43 UTC 2015
Issues-found-by: shellcheck
---
clean-genpkglist | 10 +++++-----
debian/cron.daily | 26 +++++++++++++-------------
debian/postinst | 12 ++++++------
debian/preinst | 4 ++--
examples/bin/popcon-process.sh | 8 ++++----
popcon-largest-unused | 2 +-
6 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/clean-genpkglist b/clean-genpkglist
index 5737abe..9f25da3 100755
--- a/clean-genpkglist
+++ b/clean-genpkglist
@@ -4,8 +4,8 @@
# Date: 2005-07-09
# Modified by Petter Reinholdtsen 2005-07-15
-tempname=`tempfile`
-temp2=`tempfile`
+tempname=$(tempfile)
+temp2=$(tempfile)
resultfile=packages
archs="alpha arm hppa i386 ia64 m68k mips mipsel powerpc s390 sparc"
@@ -13,9 +13,9 @@ mirror="http://ftp.fi.debian.org/debian"
for i in $archs; do
wget "$mirror/dists/Debian3.1r0/main/binary-${i}/Packages.gz" -O "$tempname"
- zcat $tempname | grep "^Package: " | sed -e 's/^Package: //' >> $temp2
+ zcat "$tempname" | grep "^Package: " | sed -e 's/^Package: //' >> "$temp2"
done
-sort -u $temp2 > $resultfile
+sort -u "$temp2" > $resultfile
-rm $tempname $temp2;
+rm "$tempname" "$temp2";
diff --git a/debian/cron.daily b/debian/cron.daily
index a3a92ef..9530f17 100644
--- a/debian/cron.daily
+++ b/debian/cron.daily
@@ -21,9 +21,9 @@ unset MTAOPS
. /etc/popularity-contest.conf
if test -d /etc/popularity-contest.d/; then
- for file in `run-parts --list --regex '\.conf$' /etc/popularity-contest.d/`;
+ for file in $(run-parts --list --regex '\.conf$' /etc/popularity-contest.d/);
do
- . $file
+ . "$file"
done
fi
@@ -45,7 +45,7 @@ if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
# Ensure that popcon runs at least once in the last week
if [ -f "$POPCONOLD" ] ; then
now=$(date +%s)
- lastrun=$(date -r $POPCONOLD +%s)
+ lastrun=$(date -r "$POPCONOLD" +%s)
if [ "$MODE" = "--crond" ]; then
# 6.5 days, in seconds
week=561600
@@ -53,7 +53,7 @@ if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
# 7.5 days, in seconds
week=648000
fi
- if [ "$(( $now - $lastrun ))" -le "$week" ]; then
+ if [ "$(( now - lastrun ))" -le "$week" ]; then
exit 0
fi
fi
@@ -72,15 +72,15 @@ run_popcon()
do_sendmail()
{
if [ -n "$MAILFROM" ]; then
- sendmail -oi $MTAOPS -f "$MAILFROM" $MAILTO
+ sendmail -oi "$MTAOPS" -f "$MAILFROM" "$MAILTO"
else
- sendmail -oi $MTAOPS $MAILTO
+ sendmail -oi "$MTAOPS" "$MAILTO"
fi
}
# generate the popularity contest data
-run_popcon > $POPCON
+run_popcon > "$POPCON"
GPG=/usr/bin/gpg
@@ -90,13 +90,13 @@ if [ "$ENCRYPT" = "yes" ] && ! [ -x "$GPG" ]; then
exit 1
fi
-if [ -x "$GPG" ] && [ "$ENCRYPT" = "maybe" ] || [ "$ENCRYPT" = "yes" ]; then
+if [ \( -x "$GPG" -a "$ENCRYPT" = "maybe" \) -o "$ENCRYPT" = "yes" ]; then
POPCONGPG="$POPCON.gpg"
rm -f "$POPCONGPG"
- GPGHOME=`mktemp -d`
+ GPGHOME=$(mktemp -d)
$GPG --batch --no-options --no-default-keyring --trust-model=always \
- --homedir "$GPGHOME" --keyring $KEYRING --quiet \
- --armor -o "$POPCONGPG" -r $POPCONKEY --encrypt "$POPCON"
+ --homedir "$GPGHOME" --keyring "$KEYRING" --quiet \
+ --armor -o "$POPCONGPG" -r "$POPCONKEY" --encrypt "$POPCON"
rm -rf "$GPGHOME"
POPCON="$POPCONGPG"
fi
@@ -107,7 +107,7 @@ SUBMITTED=no
if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
for URL in $SUBMITURLS ; do
if setsid /usr/share/popularity-contest/popcon-upload \
- -u $URL -f $POPCON 2>/dev/null ; then
+ -u "$URL" -f "$POPCON" 2>/dev/null ; then
SUBMITTED=yes
else
logger -t popularity-contest "unable to submit report to $URL."
@@ -118,7 +118,7 @@ fi
# try to email the popularity contest data
if [ "$MODE" = "--crond" ] && [ yes != "$SUBMITTED" ] && [ "$MAILTO" ]; then
- if [ -x "`which sendmail 2>/dev/null`" ]; then
+ if [ -x "$(which sendmail 2>/dev/null)" ]; then
(
if [ -n "$MAILFROM" ]; then
echo "From: <$MAILFROM>"
diff --git a/debian/postinst b/debian/postinst
index b4b6814..ffbb7de 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -27,21 +27,21 @@ fi
EMPTYID="d41d8cd98f00b204e9800998ecf8427e"
generate_id() {
- if which uuidgen >/dev/null 2>&1; then
- MY_HOSTID=`uuidgen | tr -d -`
+ if which uuidgen >/dev/null 2>&1 ; then
+ MY_HOSTID=$(uuidgen | tr -d -)
else
- MY_HOSTID=`dd if=/dev/urandom bs=1k count=1 2>/dev/null | md5sum | sed 's/ -//'''`
+ MY_HOSTID=$(dd if=/dev/urandom bs=1k count=1 2>/dev/null | md5sum | sed 's/ -//''')
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=$(bash -c 'echo $(($RANDOM % 7))')
}
generate_crond() {
- MIN=`bash -c 'echo $(($RANDOM % 60))'`
- HOUR=`bash -c 'echo $(($RANDOM % 24))'`
+ MIN=$(bash -c 'echo $(($RANDOM % 60))')
+ HOUR=$(bash -c 'echo $(($RANDOM % 24))')
FILE=/etc/cron.daily/popularity-contest
cat > /etc/cron.d/popularity-contest <<EOF
SHELL=/bin/sh
diff --git a/debian/preinst b/debian/preinst
index 1f229ba..f8663b5 100755
--- a/debian/preinst
+++ b/debian/preinst
@@ -10,8 +10,8 @@ install|upgrade)
CONFFILE="/etc/cron.weekly/popularity-contest"
NEWCONFFILE="/etc/cron.daily/popularity-contest"
if [ -e "$CONFFILE" ]; then
- md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
- old_md5sum="`dpkg-query -W -f='${Conffiles}' $PKGNAME | sed -n -e \"\\\\' $CONFFILE '{s/ obsolete$//;s/.* //p}\"`"
+ md5sum="$md5sum \"$CONFFILE\" | sed -e \"s/ .*//\")"
+ old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PKGNAME | sed -n -e \"\\\\' $CONFFILE '{s/ obsolete$//;s/.* //p}\")"
if [ "$md5sum" = "$old_md5sum" ]; then
rm -f "$CONFFILE"
else
diff --git a/examples/bin/popcon-process.sh b/examples/bin/popcon-process.sh
index f5f459c..37f64b7 100755
--- a/examples/bin/popcon-process.sh
+++ b/examples/bin/popcon-process.sh
@@ -34,7 +34,7 @@ if [ true = "$READMAIL" ] ; then
find popcon-gpg -type f -name '*.gpg' -execdir gpg {} \; >>$LOGDIR/gpg.log 2>&1
date >>$LOGDIR/gpg.log
#process decrypted reports
- find popcon-gpg -type f -name '*.txt'| xargs cat | $BINDIR/prepop.pl
+ find popcon-gpg -type f -name '*.txt' -print0 | xargs --null cat -- | $BINDIR/prepop.pl
fi
# delete outdated entries
@@ -42,14 +42,14 @@ rm -f results results.stable
find $DATADIR -type f -mtime +$DAYLIMIT -print0 | xargs -0 rm -f --
# Generate statistics
-find $DATADIR -type f | xargs cat \
+find $DATADIR -type f -print0 | xargs --null cat -- \
| nice -15 $BINDIR/popanal.py >$LOGDIR/popanal.out 2>&1
cp results $WEBDIR/all-popcon-results
cp results.stable $WEBDIR/stable/stable-popcon-results
gzip -f $WEBDIR/all-popcon-results
gzip -f $WEBDIR/stable/stable-popcon-results
-cp $WEBDIR/all-popcon-results.gz $SUMMARYDIR/popcon-`date +"%Y-%m-%d"`.gz
-cp $WEBDIR/stable/stable-popcon-results.gz $SUMMARYDIRSTABLE/popcon-`date +"%Y-%m-%d"`.stable.gz
+cp $WEBDIR/all-popcon-results.gz "$SUMMARYDIR/popcon-$(date +"%Y-%m-%d").gz"
+cp $WEBDIR/stable/stable-popcon-results.gz "$SUMMARYDIRSTABLE/popcon-$(date +"%Y-%m-%d").stable.gz"
cd ../popcon-stat
find $SUMMARYDIR -type f -print | sort | $BINDIR/popcon-stat.pl ../www/stat>$LOGDIR/popstat.log 2>&1
diff --git a/popcon-largest-unused b/popcon-largest-unused
index 9a8b714..156ea67 100755
--- a/popcon-largest-unused
+++ b/popcon-largest-unused
@@ -14,5 +14,5 @@ fi
grep '<OLD>' $datafile | cut -d' ' -f3 |
xargs -r apt-cache -o 'APT::Cache::AllVersions=0' show |
grep -E '^(Package|Installed-Size): ' |
- perl -ne 'if (/^Package: (.*)/) { $p = $1 }; if (/^Installed-Size: (.*)/) { print "$1 $p\n"; $p = 'BUG' }' |
+ perl -ne 'if (/^Package: (.*)/) { $p = $1 }; if (/^Installed-Size: (.*)/) { print "$1 $p\n"; $p = "BUG"; }' |
sort -rn
--
2.6.2
More information about the Popcon-developers
mailing list