---
 texmf-dist/doc/man/man1/tlmgr.1     |    2 +
 texmf-dist/scripts/texlive/tlmgr.pl |   65 +++++++++---------------------------
 2 files changed, 20 insertions(+), 47 deletions(-)

--- a/texmf-dist/scripts/texlive/tlmgr.pl
+++ b/texmf-dist/scripts/texlive/tlmgr.pl
@@ -21,7 +21,7 @@ $datrev =~ s/ \(.*$//;
 $tlmgrversion = "$tlmgrrevision ($datrev)";
 
 our $Master;
-our $ismain;
+our $ismain = 1;
 our $loadmediasrcerror;
 our $packagelogfile;
 our $packagelogged;
@@ -41,50 +41,8 @@ END {
 
 BEGIN {
   $^W = 1;
-  $ismain = (__FILE__ eq $0);
-  # WARNING
-  # The only use anticipated for tlmgr.pl as library for the 2009 release
-  # is the Windows w32client prototype script.
-  # Unix-specific problems with use as library will probably go undetected.
-
-  # make subprograms (including kpsewhich) have the right path:
-  my $kpsewhichname;
-  if ($^O =~ /^MSWin/i) {
-    # on w32 $0 and __FILE__ point directly to tlmgr.pl; they can be relative
-    $Master = __FILE__;
-    $Master =~ s!\\!/!g;
-    $Master =~ s![^/]*$!../../..!
-      unless ($Master =~ s!/texmf-dist/scripts/texlive/tlmgr\.pl$!!i);
-    $bindir = "$Master/bin/win32";
-    $kpsewhichname = "kpsewhich.exe";
-    # path already set by wrapper batchfile
-  } else {
-    $Master = __FILE__;
-    $Master =~ s,/*[^/]*$,,;
-    if ($ismain) {
-      $bindir = $Master;
-      $Master = "$Master/../..";
-    } else {
-      # for the time being, this code will not be used or tested
-      $Master = "$Master/../../..";
-      # no code yet for $bindir; would have to detect platform
-    }
-    # make subprograms (including kpsewhich) have the right path:
-    $ENV{"PATH"} = "$bindir:$ENV{PATH}";
-    $kpsewhichname = "kpsewhich";
-  }
-  if (-r "$bindir/$kpsewhichname") {
-    # if not in bootstrapping mode => kpsewhich exists, so use it to get $Master
-    chomp($Master = `kpsewhich -var-value=SELFAUTOPARENT`);
-  }
-
-  # if we have no directory in which to find our modules,
-  # no point in going on.
-  if (! $Master) {
-    die ("Could not determine directory of tlmgr executable, "
-         . "maybe shared library woes?\nCheck for error messages above");
-  }
-
+  
+  $Master = "/usr/share/texlive";
   $::installerdir = $Master;  # for config.guess et al., see TLUtils.pm
 
   # make Perl find our packages first:
@@ -621,6 +579,13 @@ for the full story.\n";
     tldie("$prg: Try --help if you need it.\n");
   }
 
+  # automatically switch to user mode on Debian, and warn
+  if (!$opts{"usermode"} && $action ne "init-usertree") {
+    $opts{"usermode"} = 1;
+    print "(running on Debian, switching to user mode!)\n";
+    print "(see /usr/share/doc/texlive-base/README.tlmgr-on-Debian.md)\n";
+  }
+
   #
   # the main tree we will be working on
   $::maintree = $Master;
@@ -6098,7 +6063,9 @@ sub action_postaction {
 # sets up the user tree for tlmgr in user mode
 sub action_init_usertree {
   # init_local_db but do not die if localtlpdb is not found!
-  init_local_db(2);
+  # Debian: we don't ship tlpdb for system files, so don't even
+  # try to initialize it.
+  # init_local_db(2);
   my $tlpdb = TeXLive::TLPDB->new;
   my $usertree;
   if ($opts{"usertree"}) {
@@ -6738,7 +6705,11 @@ sub init_local_db {
     if ($should_i_die == 2) {
       return undef;
     } else {
-      die("cannot setup TLPDB in $::maintree");
+      if ($opts{'usermode'}) {
+        die("$prg: user mode not initialized, please read the documentation!\n");
+      } else {
+        die("cannot setup TLPDB in $::maintree");
+      }
     }
   }
   # setup the programs, for w32 we need the shipped wget/xz etc, so we
--- a/texmf-dist/doc/man/man1/tlmgr.1
+++ b/texmf-dist/doc/man/man1/tlmgr.1
@@ -154,6 +154,8 @@ the development sources) is available at
 <https://tug.org/texlive/tlmgr.html>, along with procedures for updating
 \&\f(CW\*(C`tlmgr\*(C'\fR itself and information about test versions.
 .PP
+WARNING: tlmgr in Debian runs always in user mode
+.PP
 TeX Live is organized into a few top-level \fIschemes\fR, each of which is
 specified as a different set of \fIcollections\fR and \fIpackages\fR, where a
 collection is a set of packages, and a package is what contains actual
