Rox-filer: automount e icona dispositivo sul desktop: differenze tra le versioni
(→Configurazione) |
(→Creazione scripts) |
||
| Riga 54: | Riga 54: | ||
<halevt:Device match="hal.block.device & hal.block.is_volume = true & hal.volume.mount_point & hal.volume.is_disc = false"> |
<halevt:Device match="hal.block.device & hal.block.is_volume = true & hal.volume.mount_point & hal.volume.is_disc = false"> |
||
<halevt:Property name="hal.volume.is_mounted"> |
<halevt:Property name="hal.volume.is_mounted"> |
||
| − | <halevt:Action value="true" exec='/usr/local/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
+ | <halevt:Action value="true" exec='/usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
</halevt:Property> |
</halevt:Property> |
||
</halevt:Device> |
</halevt:Device> |
||
| Riga 61: | Riga 61: | ||
<halevt:Device match="hal.block.device & hal.block.is_volume = true & hal.volume.is_disc = true & hal.volume.disc.has_data = true"> |
<halevt:Device match="hal.block.device & hal.block.is_volume = true & hal.volume.is_disc = true & hal.volume.disc.has_data = true"> |
||
<halevt:Property name="hal.volume.is_mounted"> |
<halevt:Property name="hal.volume.is_mounted"> |
||
| − | <halevt:Action value="true" exec='/usr/local/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
+ | <halevt:Action value="true" exec='/usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
</halevt:Property> |
</halevt:Property> |
||
</halevt:Device> |
</halevt:Device> |
||
| Riga 93: | Riga 93: | ||
!--> |
!--> |
||
<halevt:Device match="&MOUNTABLE; & (!hal.volume.is_disc | hal.volume.is_disc=false)"> |
<halevt:Device match="&MOUNTABLE; & (!hal.volume.is_disc | hal.volume.is_disc=false)"> |
||
| − | <halevt:OnInit exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/local/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
+ | <halevt:OnInit exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
</halevt:Device> |
</halevt:Device> |
||
<halevt:Device match="&MOUNTABLE; & hal.volume.is_disc=true"> |
<halevt:Device match="&MOUNTABLE; & hal.volume.is_disc=true"> |
||
| − | <halevt:OnInit exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/local/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
+ | <halevt:OnInit exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/> |
</halevt:Device> |
</halevt:Device> |
||
<halevt:Device match="hal.storage.drive_type = cdrom"> |
<halevt:Device match="hal.storage.drive_type = cdrom"> |
||
| Riga 118: | Riga 118: | ||
UDI=`hal-find-by-property --key volume.mount_point --string "$TOUMOUNT"` |
UDI=`hal-find-by-property --key volume.mount_point --string "$TOUMOUNT"` |
||
DISC=`hal-get-property --udi "$UDI" --key volume.is_disc` |
DISC=`hal-get-property --udi "$UDI" --key volume.is_disc` |
||
| − | /usr/local/bin/rox.panelput.pl Remove "$TOUMOUNT" |
+ | /usr/bin/rox.panelput.pl Remove "$TOUMOUNT" |
halevt-umount "$1" |
halevt-umount "$1" |
||
halevt-umount -s |
halevt-umount -s |
||
| Riga 130: | Riga 130: | ||
TOSCAN=`echo "$1" | sed -e 's/ /\\\\\\\\040/g'` |
TOSCAN=`echo "$1" | sed -e 's/ /\\\\\\\\040/g'` |
||
TOUMOUNT=`grep "$TOSCAN" /proc/mounts | cut -d" " -f1` |
TOUMOUNT=`grep "$TOSCAN" /proc/mounts | cut -d" " -f1` |
||
| − | /usr/local/bin/rox.panelput.pl Remove "$1" nowait |
+ | /usr/bin/rox.panelput.pl Remove "$1" nowait |
halevt-umount "$1" |
halevt-umount "$1" |
||
halevt-umount -s |
halevt-umount -s |
||
Versione delle 17:13, 25 feb 2010
Indice |
Introduzione
Questa guida è pensata per chi usa sulla propria Slackware un Window Manager (FluxBox, IceWM, etc.) e vuole ottenere l'automount dei dispositivi, con annesse icone sul desktop, sfruttando le potenzialità di halvet e rox-filer.
Ricordiamo che rox-filer è un file-manager che offre anche gestione dello sfondo del desktop e delle icone.
Installazione
Installare semplicemente boolstuff e halevt.
Creazione scripts
Creare il file ~/.halevt/HalevtConfigActions.xml (nella home directory si intende) con dentro:
<!DOCTYPE halevt:Configuration [
<!-- this entity corresponds with mountable devices, which have
volume.policy.should_mount true or don't have
volume.policy.should_mount false and are block devices hotpluggable or
removable.
-->
<!ENTITY MOUNTABLE "hal.block.device & hal.block.is_volume = true & (hal.volume.policy.should_mount = true | ((! hal.volume.policy.should_mount = false) & (hal.block.storage_device.hal.storage.policy.should_mount = true | ((! hal.block.storage_device.hal.storage.policy.should_mount = false) & (hal.block.storage_device.hal.storage.hotpluggable = true | hal.block.storage_device.hal.storage.removable = true)))))">
]>
<halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.fr/perso/dumas/halevt.html">
<!-- audio CD -->
<halevt:Device match="hal.block.is_volume & hal.volume.disc.type=cd_rom & hal.volume.disc.has_audio=true & hal.volume.disc.has_data=false">
<halevt:Insertion exec="grip"/>
</halevt:Device>
<!-- blank CD/DVD -->
<halevt:Device match="hal.block.is_volume & hal.volume.is_disc=true & hal.volume.disc.is_blank=true">
<halevt:Insertion exec="k3b"/>
</halevt:Device>
<!--
This rule matches removable devices which have volume.policy.should_mount true
or don't have volume.policy.should_mount false.
Upon insertion, they are mounted and recorded by halevt-mount.
-m 002 sets the umask of mount to 002 when pmount is used system-wide
to mount the device. This allows regular users to read the device.
<halevt:Insertion exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/local/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/>
!-->
<halevt:Device match="&MOUNTABLE; & (!hal.volume.is_disc | hal.volume.is_disc=false)">
<halevt:Insertion exec='halevt-mount -u $hal.udi$ -m 002'/>
</halevt:Device>
<halevt:Device match="&MOUNTABLE; & hal.volume.is_disc=true">
<halevt:Insertion exec="halevt-mount -u $hal.udi$ -m 002"/>
</halevt:Device>
<!--
When a device get a mount point, it is passed to halevt-mount which can
record it. The property that changes is volume.is_mounted, and the action is
executed when the value of volume.is_mounted becomes true.
<halevt:Action value="true" exec="halevt-mount -s"/>
!-->
<!--USB-->
<halevt:Device match="hal.block.device & hal.block.is_volume = true & hal.volume.mount_point & hal.volume.is_disc = false">
<halevt:Property name="hal.volume.is_mounted">
<halevt:Action value="true" exec='/usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/>
</halevt:Property>
</halevt:Device>
<!--cdroms-->
<halevt:Device match="hal.block.device & hal.block.is_volume = true & hal.volume.is_disc = true & hal.volume.disc.has_data = true">
<halevt:Property name="hal.volume.is_mounted">
<halevt:Action value="true" exec='/usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/>
</halevt:Property>
</halevt:Device>
<!--
When a device is unmounted, it is recorded by halevt-mount.
!-->
<halevt:Device match="hal.block.device & hal.block.is_volume = true">
<halevt:Property name="hal.volume.is_mounted">
<halevt:Action value="false" exec="halevt-mount -s"/>
</halevt:Property>
</halevt:Device>
<!--
When a device is removed, it is recorded by halevt-mount.
Note that at that point the device is already out of hal, so we use
* which matches any device in the match attribute, and only pass the
udi to the command.
!-->
<halevt:Device match="hal.*">
<halevt:Removal exec="halevt-umount -u $hal.udi$; halevt-umount -s"/>
</halevt:Device>
<!--
Example of a use of OnInit. At startup all the devices are matched and the exec
comand is run for those that match. Here we match all the removable devices
that aren't already mounted and mount and register them.
<halevt:OnInit exec="halevt-mount -u $hal.udi$ -m 002"/>
!-->
<halevt:Device match="&MOUNTABLE; & (!hal.volume.is_disc | hal.volume.is_disc=false)">
<halevt:OnInit exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/>
</halevt:Device>
<halevt:Device match="&MOUNTABLE; & hal.volume.is_disc=true">
<halevt:OnInit exec='halevt-mount -u $hal.udi$ -m 002 ; /usr/bin/rox.panelput.pl Add "$hal.volume.mount_point$" "$hal.volume.label$"'/>
</halevt:Device>
<halevt:Device match="hal.storage.drive_type = cdrom">
<halevt:Condition name="EjectPressed" exec='eject.hal $hal.block.device$'/>
</halevt:Device>
</halevt:Configuration>
Fatto ciò, creare da root il file /usr/bin/eject.hal
#!/bin/bash
if [ -z $1 ]; then
echo "Usage: eject.hal <device>"
exit
else
echo "$1" | egrep "^/dev"
if [ "$?" == "0" ]; then
#echo "Device First, find mount point"
TOSCAN=`echo "$1" | sed -e 's/ /\\\\\\\\040/g'`
TOUMOUNT=`grep "$TOSCAN" /proc/mounts | cut -d" " -f2`
UDI=`hal-find-by-property --key volume.mount_point --string "$TOUMOUNT"`
DISC=`hal-get-property --udi "$UDI" --key volume.is_disc`
/usr/bin/rox.panelput.pl Remove "$TOUMOUNT"
halevt-umount "$1"
halevt-umount -s
if [ "$DISC" == "true" ]; then
/usr/bin/eject -p "$1" &>/dev/null
fi
else
#echo "Mount Point First, find device"
UDI=`hal-find-by-property --key volume.mount_point --string "$1"`
DISC=`hal-get-property --udi "$UDI" --key volume.is_disc`
TOSCAN=`echo "$1" | sed -e 's/ /\\\\\\\\040/g'`
TOUMOUNT=`grep "$TOSCAN" /proc/mounts | cut -d" " -f1`
/usr/bin/rox.panelput.pl Remove "$1" nowait
halevt-umount "$1"
halevt-umount -s
if [ "$DISC" == "true" ]; then
/usr/bin/eject -p "$TOUMOUNT" &>/dev/null
fi
fi
fi
</device>
e renderlo eseguibile con il comando, sempre da root
chmod +x /usr/bin/eject.hal.
In maniera analoga, creiamo il file /usr/bin/rox.panelput.pl
#!/usr/bin/perl
# Filename: rox.panelput.pl
# Version: 0.2
# Livense: GPLv3
#
# Description:
# simple perl script to assist in adding/removing device icons for ROX pinboard
# read more on: http://www.void.gr/kargig/blog/2009/06/23/using-halevt-to-automount-media-and-make-them-appear-on-rox-desktop/
# Created by George Kargiotakis kargig[at]void[dot]gr
#
# Changelog
# v0.2 Path Corrections by Antonio Sαnchez <introlinux[at]gmail[dot]com>
# v0.1 Original version
use warnings;
use strict;
use Env qw(HOME USER);
#VARIABLES
my $DEVICEFILE="$HOME/.halevt/mounted/devices";
my $DEVICEFILETEMP="$HOME/.halevt/mounted/devices_TEMP";
my $ROXFILE="$HOME/.config/rox.sourceforge.net/ROX-Filer/pb_pinboard";
my $ROXTEMP="$HOME/.config/rox.sourceforge.net/ROX-Filer/ROX-Filer/pb_pinboard_TEMP";
my $LOCKFILE="/tmp/rox-halevt-lock-$USER.tmp";
my $fail=0;
my $ARG1=$ARGV[0];
my $ARG2=$ARGV[1];
my $ARG3=$ARGV[2];
my $LABEL;
my $DEVPATH;
my $devicecount=0;
my $spot=0;
my $newspot=0;
my $counter=0;
my $psi=0;
sub roxrpc {
my ($ARG1,$DEVPATH,$LABEL,$psi) = @_;
my $tmpfile="/tmp/rox.tmp.$$";
open (FILEWRITE,">$tmpfile") || die "could not open $DEVICEFILE: $!\n";
flock FILEWRITE,2;
print FILEWRITE "<?xml version=\"1.0\"?>
<env:Envelope xmlns:env=\"http://www.w3.org/2001/12/soap-envelope\">
<env:Body xmlns=\"http://rox.sourceforge.net/SOAP/ROX-Filer\">
<Pinboard$ARG1>
<Path>$DEVPATH</Path>
<X>50</X>
<Y>$psi</Y>
<Label>$LABEL</Label>
</Pinboard$ARG1>
</env:Body>
</env:Envelope>";
flock FILEWRITE,8;
close FILEWRITE;
system("rox -R <$tmpfile");
unlink($tmpfile);
}
if ($ARG1 eq "Add") {
open (FILE, $DEVICEFILE) || die "could not open $DEVICEFILE: $!\n";
my @file=<FILE>;
my $lines=@file;
close FILE;
for (@file) {
if ($_ =~ /^$ARG2:/) {
$fail=1;
last
}
}
if ($fail == 1) { #if device already exists, exit
print "PHAIL Add!\n";
exit;
} else {
if ($ARG3) {
$DEVPATH=$ARG2;
$LABEL=$ARG3;
} else {
$DEVPATH=$ARG2;
$LABEL=$ARG2;
}
for (@file) { #find count of empty lines
if ($_ !~ /^$/) {
$devicecount++;
}
}
if ($devicecount < $lines) { #if there's an empty line in devicefile
$counter=0;
for (@file) { #find spot of first empty line
$counter++;
if ($_ =~ /^$/) {
$spot=$counter;
last;
}
}
$newspot=$spot-1;
$psi=$newspot * 100 + 50;
open (FILEREAD,"<$DEVICEFILE") || die "could not open $DEVICEFILE: $!\n";
open (FILEWRITE,">$DEVICEFILETEMP") || die "could not open $DEVICEFILETEMP: $!\n";
flock FILEWRITE,2;
while (<FILEREAD>) {
if ($. == $spot) {
$_ =~ s//$DEVPATH:$LABEL/;
}
print FILEWRITE;
}
close FILEREAD;
flock FILEWRITE,8;
close FILEWRITE;
rename($DEVICEFILETEMP,$DEVICEFILE);
} else {
$psi = $devicecount * 100 + 50;
open (FILEWRITE,">>$DEVICEFILE") || die "could not open $DEVICEFILE: $!\n";
flock FILEWRITE,2;
print FILEWRITE "$DEVPATH:$LABEL\n";
flock FILEWRITE,8;
close FILEWRITE;
}
roxrpc($ARG1,$DEVPATH,$LABEL,$psi);
}
} elsif ($ARG1 eq "Remove") {
open (FILE, $DEVICEFILE) || die "could not open $DEVICEFILE: $!\n";
while (<FILE>) {
if ($_ =~ /^$ARG2:/) {
$spot = $.;
($DEVPATH,$LABEL) = split(/:/);
chomp($DEVPATH);
chomp($LABEL);
$fail=1;
last
}
}
close FILE;
if ($fail == 0) { #if device does not exists, exit
print "PHAIL Remove!\n";
exit;
} else {
open (FILEREAD,"<$DEVICEFILE") || die "could not open $DEVICEFILE: $!\n";
open (FILEWRITE,">$DEVICEFILETEMP") || die "could not open $DEVICEFILETEMP: $!\n";
flock FILEWRITE,2;
while (<FILEREAD>) {
if ($. == $spot) {
$_ =~ s/.*//;
}
print FILEWRITE;
}
close FILEREAD;
flock FILEWRITE,8;
close FILEWRITE;
rename($DEVICEFILETEMP,$DEVICEFILE);
$psi=$spot * 100 + 50;
roxrpc($ARG1,$DEVPATH,$LABEL,$psi);
}
} elsif ($ARG1 eq "Restore") {
open (FILE, $DEVICEFILE) || die "could not open $DEVICEFILE: $!\n";
while (<FILE>) {
($DEVPATH,$LABEL) = split(/:/);
chomp($DEVPATH);
chomp($LABEL);
print "halevt file line=$_ DEVPATH=$DEVPATH LABEL=$LABEL\n";
open (FILEREAD,"<$ROXFILE") || die "could not open $ROXFILE: $!\n";
open (FILEWRITE,">$ROXTEMP") || die "could not open $ROXTEMP: $!\n";
flock FILEWRITE,2;
while (<FILEREAD>) {
if ($_ !~ /$LABEL/) {
print FILEWRITE;
}
}
}
close FILEREAD;
flock FILEWRITE,8;
close FILEWRITE;
rename($ROXTEMP,$ROXFILE);
close FILE;
open (FILE, ">$DEVICEFILE") || die "could not open $DEVICEFILE: $!\n";
flock FILE,2;
print FILE "";
flock FILE,8;
close FILE;
}
e rendiamolo eseguibile con chmod +x /usr/bin/rox.panelput.pl, il tutto sempre da root.
Configurazione
Editiamo il file ~/.fluxbox/startup aggiungendo le seguenti righe:
/usr/local/bin/rox.panelput.pl Restore killall -9 halevt; halevt -f -u YOURUSERNAME -g plugdev & /usr/bin/rox -p pinboard
Aprire il menu Opzioni di Rox e modificarlo come in immagine.
Se invece non usate le icone, commentate l'ultima riga di queste inserite e il gioco è fatto.
EDIT: segnalatomi da SIV, la modifica che vedete in immagine, al posto del comando mount inserire halevt-mount
Conclusione
E con questo è tutto! Ora riavviate fluxbox e godetevi l'automount!
Author: jimmy_page_89