<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env perl

#Mount Windows shares on Probe using Samba

#WRJF 2010 Jul  5 New, based on my smbmount.csh
#WRJF 2010 Jul  6 Check for unrecognized logname; cleaned up
#WRJF 2010 Sep  5 Added file.campus, but commented out because it wreaked havoc
#WRJF 2011 Apr  5 Added use of sudo because of change from lenny to squeeze
#WRJF 2011 Apr  7 Added specification of uid and gid
#WRJF 2011 May 20 Added nobrl option (cf. diary_earmuff.txt for today)
#WRJF 2011 Jul  4 Added mounting of Earwig, but it doesn't work
#WRJF 2012 Feb  8 Added username ...
#WRJF 2012 Aug 13 Added mounting of probeBMEdisk
#WRJF 2012 Aug 27 Added history comment for 2012 Aug 13
#WRJF 2013 Jan 17 Added username ...
#WRJF 2013 May  7 Added username ...
#WRJF 2013 Jun 26 Added username ...
#WRJF 2013 Aug 30 Added username ...
#WRJF 2013 Sep  4 Updated to use 'mount -t cifs' rather than smbmount
#WRJF 2013 Nov 27 Added username ...
#WRJF 2014 Jun 17 Added username ...
#WRJF 2014 Jul  7 Added username ...
#WRJF 2014 Aug  1 Added username ...
#WRJF 2014 Aug 26 Added username ...
#WRJF 2015 Feb 12 Commented out obsolete do_mount for probe_bmedisk
#		  Added instructions about which passwords to enter
#		  Commented out printing of @args
#WRJF 2015 May 11 Added username ...
#WRJF 2015 Jun  8 Added username ...
#WRJF 2015 Jun 22 Added username ...
#WRJF 2015 Jul 15 Added username ...
#WRJF 2015 Jul 30 Added username ...
#                 Use of strict, warnings &amp; autodie, and more uses of 'my'
#                 Implemented reading of ~/.shortuname
#WRJF 2015 Jul 31 Implemented creation of ~/.shortuname if it doesn't exist
#WRJF 2015 Sep  2 Removed usernames from these history comments
#WRJF 2018 Mar 16 Added mounting of medicine/research/imagingfacility
#WRJF 2022 Aug 24 Commented out mounting of medicine/research/imagingfacility
#WRJF 2022 Aug 25 Added 'vers=3.0' to options, required for new Probe
#                   (supported by Earlet but not by Earmuff)

use strict;
use warnings;
use autodie;

print "Give local Linux password first, and then McGill password (twice).\n";
print "(This script requires package cifs-utils.)\n";

my $loginname = $ENV{'LOGNAME'};
my $dir = "/home/$loginname";
my $file = "$dir/.shortuname";
my $smbname;

if (-e $file)
{ open(my $fh, "&lt;", $file);  #open file, get filehandle
  while ( ! eof($fh) )
  { my $line = readline($fh);
    my $char1 = substr($line,0,1);
    if ($char1 ne ";")
    { $smbname = $line;
      chomp($smbname);
    }
  }
  print "Got short user name '$smbname'\n";
}
else
{ print "McGill short username? ";
  $smbname = &lt;STDIN&gt;;
  chomp $smbname;
  if($smbname eq "")
  { print "A short username must be specified. Quitting.\n";
    exit 0
  }
  open(my $fh, "&gt;", $file);  #open file, get filehandle
  print{$fh} "$smbname\n";
  print "Created file $file\n";
}

do_mount("//probe.campus.mcgill.ca/probeshare", "probeShare");
do_mount("//probe.campus.mcgill.ca/biomedusers", "probe");
#do_mount("//campus.mcgill.ca/medicine/research/imagingfacility", "abif");
#do_mount("//hnasbhevs2.campus.mcgill.ca/probe_bmedisk", "probeBMEdisk");
#do_mount("//217w-earwig/d", "earwig");
#do_mount("//file.campus.mcgill.ca/staff/Group3/rfunne", "mcFile");
exit;

sub do_mount {
    my $logname = $ENV{'LOGNAME'};

    my $service = $_[0];
    my $mountpt = "/home/$logname/$_[1]";

    unless (-d $mountpt)
    { my $mkdir_cmd = "mkdir $mountpt";
      my @args = $mkdir_cmd;
      print "Creating mount point $mountpt\n";
      system @args;
  }

    print "\nMounting $service\n    at $mountpt for $smbname\n";
    my $options = "-o nobrl,vers=3.0,workgroup=campus,username=$smbname,uid=$logname,gid=$logname";
    my @args = "sudo mount -t cifs $service $mountpt $options";
#    print "cmd=@args\n";
    system @args;
}
</pre></body></html>