DigiStorage pentru Developeri

Pentru a rula aceste scripturi aveţi nevoie de drepturi de root și de următorul utilitar:

  • apt-get install davfs2

Exemplu de script digimount.pl pentru montarea unui webdav în cli linux (script dezvoltat în perl):

#!/usr/bin/perl -X

$digidav="https://storage.rcs-rds.ro/dav";
print "Please give us the directory path where you want to mount the DigiStorage account: ";
chomp ($path = <STDIN>);
print "Cheking the path:..... ";

check_path ($path);

sub check_path ()
{
 $i = 1;
  $p = $_[0];
  if (-d "$p"){
    print "$p is OK!\n";
  }
  else {
    if ($i > 2) {
      print "something went wrong creating the path: $p\n;";
      exit 1;
    }
    else {
      $i = $i + 1;
      print "Path $p does not exists, we try to create it: ";
      system ("mkdir -p $p");
      check_path($p);
    }
  }
}
print "Mounting Digi Storage Account to $path\n";
system ("mount.davfs $digidav $path");
print "Displaying mount if it worked\n";
system ("mount | grep $path");

Exemplu de utilizare:

# perl digimount.pl Please give us the directory path where you want to mount the DigiStorage account: /home/user/webdav Cheking the path:..... /home/user/webdav is OK! Mounting Digi Storage Account to /home/user/webdav Please enter the username to authenticate with server https://storage.rcs-rds.ro/dav or hit enter for none. Username: email@domeniu.tld Please enter the password to authenticate user email@domeniu.tld with server https://storage.rcs-rds.ro/dav or hit enter for none. Password: Displaying mount if it worked https://storage.rcs-rds.ro/dav on /home/user/webdav type davfs (rw,nosuid,nodev,_netdev) #

Exemplu de script digiumount.pl pentru demontarea unui webdav în cli linux (script dezvoltat în perl):

#!/usr/bin/perl -X

$digidav="https://storage.rcs-rds.ro/dav";

print "Detecting mount of Digi Storage.... ";
my $path = qx/ mount | grep "$digidav" | awk '{ print \$3 }'/;
$path = trim ($path);

if ( length $path > 0) {
  print "Digi Storage mount detected at: $path\n";
  print "Do you want to unmount $path ?\n";
  print "Please use \"Yes\" or \"No\": ";
  chomp ($resp = <STDIN>);
  if ($resp eq "Yes"){
    print "Unmounting $path\n";
    qx /umount $path/;
  }
  elsif ($resp eq "No"){
   print "Please give us the path to unmount: ";
   chomp ($path2 = <STDIN>);
   if (-d $path2) {
     print "Path $path2 exists trying to unmount:\n";
     qx /umount $path2/;
   }
   else {
     print "Path does not exist, please run again script\n";
     exit 1;
   }
  }
  else {
  print "Your input was not correct: Yes or No\n";
  exit 1;
  }
} else {
  print "Nothing found!\n";
  print "Please give us the path to unmount: ";
  chomp ($path3 = <STDIN>);
  if (-d $path3) {
    print "Path $path3 exists trying to unmount:\n";
    qx /umount $path3/;
  }
  else {
    print "Path does not exist, please run again script\n";
    exit 1;
  }
}

sub trim { return $_[0] =~ s/^\s+|\s+$//rg; }

Exemplu de utilizare:

După executarea scriptului, acesta detectează toate dispozitivele webdav montate în sistem și apoi sunteţi întrebat dacă doriţi să demontaţi toate dispozitivele webdav. Selectând "Yes", se demontează dispozitivele webdav neutilizate; selectand "No", puteţi să introduceţi calea unui singur dispozitiv webdav pe care doriţi să-l demontaţi.

# perl digiumount.pl Detecting mount of Digi Storage.... Digi Storage mount detected at: /home/user2/test /home/user1/webdav /home/user2/digistoragetemp /home/user3/webdav Do you want to unmount /home/user2/test /home/user1/webdav /home/user2/digistoragetemp /home/user3/webdav ? Please use "Yes" or "No": No Please give us the path to unmount: /home/user3/webdav Path /home/User3/webdav exists trying to unmount: #