[devscripts] 02/02: Make various scripts work when HOME is unset

Paul Wise pabs at moszumanska.debian.org
Mon Apr 3 11:49:40 UTC 2017


This is an automated email from the git hooks/post-receive script.

pabs pushed a commit to branch master
in repository devscripts.

commit 56e38636cdf44cbf5ab3102ebf4918365f2db272
Author: Paul Wise <pabs at debian.org>
Date:   Mon Apr 3 13:21:06 2017 +0800

    Make various scripts work when HOME is unset
    
    Use tilde expansion for the bash scripts and completion.
    
    Use File::HomeDir->my_home for the Perl scripts.
    Store results in $ENV{HOME} to minimise the changes.
    
    The scripts that had issues when HOME is unset include:
    
    bts
    chdist
    debcommit
    dscverify
    grep-excuses
    namecheck
    rc-alert
    svnpath
    wnpp-alert
---
 debian/changelog               | 3 +++
 scripts/bts.pl                 | 2 ++
 scripts/chdist.bash_completion | 2 +-
 scripts/chdist.pl              | 5 +++--
 scripts/debcommit.pl           | 3 ++-
 scripts/dscverify.pl           | 2 ++
 scripts/grep-excuses.pl        | 3 ++-
 scripts/namecheck.pl           | 8 +++++++-
 scripts/rc-alert.pl            | 2 ++
 scripts/svnpath.pl             | 7 +++++--
 scripts/wnpp-alert.sh          | 2 +-
 11 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 98de8ed..b406871 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,9 @@ devscripts (2.17.6) UNRELEASED; urgency=medium
   [ Paul Wise ]
   * chdist:
     + add support for running aptitude
+  * Make various scripts work when HOME is unset:
+    bts chdist debcommit dscverify grep-excuses
+    namecheck rc-alert svnpath wnpp-alert
 
  -- Osamu Aoki <osamu at debian.org>  Fri, 31 Mar 2017 02:03:30 +0900
 
diff --git a/scripts/bts.pl b/scripts/bts.pl
index 2a650d1..a2a64c5 100755
--- a/scripts/bts.pl
+++ b/scripts/bts.pl
@@ -47,6 +47,7 @@ use strict;
 use warnings;
 use File::Basename;
 use File::Copy;
+use File::HomeDir;
 use File::Path qw(make_path rmtree);
 use File::Spec;
 use File::Temp qw/tempfile/;
@@ -173,6 +174,7 @@ my @valid_severities=qw(wishlist minor normal important
 
 my $browser;  # Will set if necessary
 
+$ENV{HOME} = File::HomeDir->my_home;
 my $cachedir = $ENV{XDG_CACHE_HOME} || File::Spec->catdir($ENV{HOME}, '.cache');
 $cachedir = File::Spec->catdir($cachedir, 'devscripts', 'bts');
 
diff --git a/scripts/chdist.bash_completion b/scripts/chdist.bash_completion
index 0811a01..51dbf49 100644
--- a/scripts/chdist.bash_completion
+++ b/scripts/chdist.bash_completion
@@ -14,7 +14,7 @@ _chdist ()
        list'
   # Sync'd with buildd.debian.org on 2016-04-02:
   local archs="all alpha amd64 arm64 armel armhf hppa hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 m68k mips mips64el mipsel powerpc powerpcspe ppc64 ppc64el s390 s390x sh4 sparc sparc64 x32"
-  local dists=$(ls $HOME/.chdist 2>/dev/null)
+  local dists=$(ls ~/.chdist 2>/dev/null)
 
   COMPREPLY=()
 
diff --git a/scripts/chdist.pl b/scripts/chdist.pl
index 51a161b..832036c 100755
--- a/scripts/chdist.pl
+++ b/scripts/chdist.pl
@@ -40,7 +40,7 @@ Provide a usage message.
 
 =item B<-d>, B<--data-dir> I<DIR>
 
-Choose data directory (default: F<$HOME/.chdist/>).
+Choose data directory (default: F<~/.chdist/>).
 
 =item B<-a>, B<--arch> I<ARCH>
 
@@ -143,6 +143,7 @@ use warnings;
 no if $] >= 5.018, 'warnings', 'experimental::smartmatch';
 use feature 'switch';
 use File::Copy qw(cp);
+use File::HomeDir;
 use File::Path qw(make_path);
 use File::Basename;
 use Getopt::Long qw(:config gnu_compat bundling require_order);
@@ -181,7 +182,7 @@ License, version 2 or (at your option) any later version.
 EOF
 
 my $arch;
-my $datadir = $ENV{'HOME'} . '/.chdist';
+my $datadir = File::HomeDir->my_home . '/.chdist';
 
 GetOptions(
   "h|help"       => \$help,
diff --git a/scripts/debcommit.pl b/scripts/debcommit.pl
index d899ca1..f1d8963 100755
--- a/scripts/debcommit.pl
+++ b/scripts/debcommit.pl
@@ -185,6 +185,7 @@ use strict;
 use Getopt::Long qw(:config bundling permute no_getopt_compat);
 use Cwd;
 use File::Basename;
+use File::HomeDir;
 use File::Temp;
 my $progname = basename($0);
 
@@ -460,7 +461,7 @@ sub getprog {
     }
 
     # Test for this file to avoid interactive prompting from svk.
-    if (-d "$ENV{HOME}/.svk/local") {
+    if (-d File::HomeDir->my_home."/.svk/local") {
 	# svk has no useful directories so try to run it.
 	my $svkpath=`svk info . 2>/dev/null| grep -i '^Depot Path:' | cut -d ' ' -f 3`;
 	if (length $svkpath) {
diff --git a/scripts/dscverify.pl b/scripts/dscverify.pl
index 45f2c60..45fb0eb 100755
--- a/scripts/dscverify.pl
+++ b/scripts/dscverify.pl
@@ -28,6 +28,7 @@ use Cwd;
 use Fcntl;
 use Digest::MD5;
 use Dpkg::IPC;
+use File::HomeDir;
 use File::Spec;
 use File::Temp;
 use File::Basename;
@@ -94,6 +95,7 @@ sub get_rings {
     my @rings = @_;
     my @keyrings = qw(/usr/share/keyrings/debian-keyring.gpg
 	    /usr/share/keyrings/debian-maintainers.gpg);
+    $ENV{HOME} = File::HomeDir->my_home;
     if (defined $ENV{HOME} && -r "$ENV{HOME}/.gnupg/trustedkeys.gpg") {
 	unshift(@keyrings, "$ENV{HOME}/.gnupg/trustedkeys.gpg");
     }
diff --git a/scripts/grep-excuses.pl b/scripts/grep-excuses.pl
index adeeebd..8a4308f 100755
--- a/scripts/grep-excuses.pl
+++ b/scripts/grep-excuses.pl
@@ -22,6 +22,7 @@ use 5.006;
 use strict;
 use warnings;
 use File::Basename;
+use File::HomeDir;
 
 # Needed for --wipnity option
 
@@ -57,7 +58,7 @@ my $rmurl='https://udd.debian.org/cgi-bin/autoremovals.cgi';
 my $rmurl_yaml='https://udd.debian.org/cgi-bin/autoremovals.yaml.cgi';
 
 # No longer use these - see bug#309802
-my $cachedir = $ENV{'HOME'}."/.devscripts_cache/";
+my $cachedir = File::HomeDir->my_home."/.devscripts_cache/";
 my $cachefile = $cachedir . basename($url);
 unlink $cachefile if -f $cachefile;
 
diff --git a/scripts/namecheck.pl b/scripts/namecheck.pl
index e6ac5e6..a49c9ba 100755
--- a/scripts/namecheck.pl
+++ b/scripts/namecheck.pl
@@ -53,6 +53,12 @@ use LWP::UserAgent;
 
 
 #
+# A module for finding the user home dir.
+#
+use File::HomeDir;
+
+
+#
 #  Get the name from the command line.
 #
 my $name = shift;
@@ -95,7 +101,7 @@ exit;
 
 sub loadPatterns
 {
-    my $file  = $ENV{ 'HOME' } . "/.namecheckrc";
+    my $file  = File::HomeDir->my_home . "/.namecheckrc";
     my @lines = ();
 
     if ( -e $file )
diff --git a/scripts/rc-alert.pl b/scripts/rc-alert.pl
index 3b31672..5fa4fff 100755
--- a/scripts/rc-alert.pl
+++ b/scripts/rc-alert.pl
@@ -24,6 +24,7 @@ use warnings;
 use Devscripts::Packages;
 use File::Basename;
 use File::Copy qw(move);
+use File::HomeDir;
 use File::Path qw(make_path);
 use File::Spec;
 use Getopt::Long qw(:config bundling permute no_getopt_compat);
@@ -34,6 +35,7 @@ sub human_flags($);
 sub unhtmlsanit($);
 sub dt_parse_request($);
 
+$ENV{HOME} = File::HomeDir->my_home;
 my $cachedir = $ENV{XDG_CACHE_HOME} || File::Spec->catdir($ENV{HOME}, '.cache');
 $cachedir = File::Spec->catdir($cachedir, 'devscripts', 'rc-alert');
 
diff --git a/scripts/svnpath.pl b/scripts/svnpath.pl
index 99148e9..f9b4838 100755
--- a/scripts/svnpath.pl
+++ b/scripts/svnpath.pl
@@ -56,6 +56,8 @@ For example, the author uses this file:
 
 =cut
 
+use File::HomeDir;
+
 $ENV{LANG}="C";
 
 my $wanted=shift;
@@ -79,8 +81,9 @@ if (length $wanted) {
 	# Now jut substitute into it.
 	$url=~s!/(?:trunk|branches|tags)($|/)!/$wanted$1!;
 
-	if (-e "$ENV{HOME}/.svnpath") {
-		require "$ENV{HOME}/.svnpath";
+	my $svnpath = File::HomeDir->my_home."/.svnpath";
+	if (-e $svnpath) {
+		require $svnpath;
 	}
 }
 
diff --git a/scripts/wnpp-alert.sh b/scripts/wnpp-alert.sh
index 6132dd2..e3a5312 100755
--- a/scripts/wnpp-alert.sh
+++ b/scripts/wnpp-alert.sh
@@ -19,7 +19,7 @@ PROGNAME="${0##*/}"
 # TODO: Remove use of OLDCACHEDDIR post-Stretch
 OLDCACHEDIR=~/.devscripts_cache
 OLDCACHEDDIFF="${OLDCACHEDIR}/wnpp-diff"
-CACHEDIR=${XDG_CACHE_HOME:-$HOME/.cache}
+CACHEDIR=${XDG_CACHE_HOME:-~/.cache}
 CACHEDIR=${CACHEDIR%/}/devscripts
 CACHEDDIFF="${CACHEDIR}/wnpp-diff"
 CURLORWGET=""

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list