File x2goumount_session of Package x2go
#!/usr/bin/perl
use strict;
my $session=shift;
my $only_path=shift;
my $uname=$ENV{'USER'};
my $serv=$ENV{'HOSTNAME'};
if($only_path)
{
$only_path=~s/\/ramdrive\/mnt\///;
$only_path=~ s/\//_/g;
my $end="_media";
$only_path="$ENV{'HOME'}/media/$only_path";
}
my $outp=`sudo x2gopgwrapper getdisplay $session`;
$outp=~s/ //g;
my $display=$outp;
$outp=`sudo x2gopgwrapper getmounts $session`;
my @outp=split("\n","$outp");
my $i;
open (F,"</etc/mtab") or die "Can't open /etc/mtab for reading";
my @mounts=<F>;
close(F);
my $use_zenity=0;
if($ENV{'GNOME_DESKTOP_SESSION_ID'} ne "")
{
$use_zenity=1;
}
for($i=0;$i<@outp;$i++)
{
@outp[$i]=~s/ //g;
chomp(@outp[$i]);
chomp(@outp[$i]);
chomp(@outp[$i]);
my @line=split('\|',"@outp[$i]");
my $path="@line[0]:@line[1]";
if($only_path)
{
if (@line[1] ne $only_path)
{
goto cont;
}
}
my $j;
my $found=0;
my $remote;
for($j;$j<@mounts;$j++)
{
if(@mounts[$j]=~m/sshfs/ && @mounts[$j]=~m/@line[0]/ && @mounts[$j]=~m/@line[1]/ )
{
$found=1;
$remote=(split(" ",@mounts[$j]))[0];
goto break;
}
}
break:
if($found)
{
if(system( "fusermount -u @line[1]" ) == 0)
{
$found=0;
}
else
{
$ENV{'DISPLAY'}=":$display";
if($use_zenity == 0)
{
system("kdialog --error \"@line[1]\"&");
}
else
{
system("zenity --error --text \"@line[1]\"&");
}
}
}
if(! $found)
{
$remote=~s/\//%2f/g;
$remote=(split(":","$remote"))[1];
$remote="$ENV{'HOME'}/Desktop/$remote";
if( -e "$remote(sshfs-disk)")
{
unlink("$remote(sshfs-disk)");
}
$remote=~s/%2framdrive%2fmnt%2f//;
if( -e "$remote(sshfs-removable)")
{
unlink("$remote(sshfs-removable)");
}
if( -e "$remote(sshfs-cdrom)")
{
unlink("$remote(sshfs-cdrom)");
}
#print "$session \"@line[1]\"\n";
system("sudo x2gopgwrapper deletemount $session \"@line[1]\"> /dev/null");
rmdir (@line[1]);
}
cont:
}