1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
use blib; |
5 |
use Fuse::DBI; |
6 |
use blib; |
7 |
|
8 |
=head1 NAME |
9 |
|
10 |
strix.pl - mount Strix database as filesystem |
11 |
|
12 |
=head1 SYNOPSIS |
13 |
|
14 |
strix.pl database /mnt |
15 |
|
16 |
=head1 DESCRIPTION |
17 |
|
18 |
With this script, you can utilize C<Fuse> and C<Fuse::DBI> modules to mount |
19 |
content from Strix - knowledge owl portal and edit them using command-line |
20 |
utilities (like C<vi> or C<ftp>). |
21 |
|
22 |
=cut |
23 |
|
24 |
my ($database,$mount) = @ARGV; |
25 |
|
26 |
unless ($database && $mount) { |
27 |
print STDERR <<_USAGE_; |
28 |
usage: $0 database /mnt |
29 |
|
30 |
For more information see perldoc $0 |
31 |
_USAGE_ |
32 |
exit 1; |
33 |
} |
34 |
|
35 |
system "fusermount -u $mount" unless (-w $mount); |
36 |
|
37 |
unless (-w $mount) { |
38 |
print STDERR "Current user doesn't have permission on mount point $mount: $!"; |
39 |
exit 1; |
40 |
} |
41 |
|
42 |
my $sql = { |
43 |
'filenames' => q{ |
44 |
select |
45 |
multistatic_id as id, |
46 |
replace(getpathfromnav(multistatic_navigation.kategorija_id)||' > '||getpathfromms(multistatic_navigation.multistatic_id),' > ','/')||'.html' as filename, |
47 |
|
48 |
length(content) as size, |
49 |
true as writable |
50 |
from multistatic_navigation,multistatic |
51 |
where multistatic.id = multistatic_id and |
52 |
not multistatic_navigation.redirect; |
53 |
}, |
54 |
'read' => q{ |
55 |
select content |
56 |
from multistatic |
57 |
where id = ?; |
58 |
}, |
59 |
'update' => q{ |
60 |
update multistatic |
61 |
set content = ? |
62 |
where id = ?; |
63 |
}, |
64 |
}; |
65 |
|
66 |
my $dsn = 'DBI:Pg:dbname='.$database; |
67 |
my $db; |
68 |
|
69 |
print "using database '$dsn', mountpoint $mount\n"; |
70 |
|
71 |
my $mnt = Fuse::DBI->mount({ |
72 |
filenames => $sql->{'filenames'}, |
73 |
read => $sql->{'read'}, |
74 |
update => $sql->{'update'}, |
75 |
dsn => $dsn, |
76 |
user => '', |
77 |
password => '', |
78 |
mount => $mount, |
79 |
fork => 1, |
80 |
# invalidate => sub { |
81 |
# print STDERR "invalidating content in $template_dir\n"; |
82 |
# opendir(DIR, $template_dir) || die "can't opendir $template_dir: $!"; |
83 |
# map { unlink "$template_dir/$_" || warn "can't remove $template_dir/$_: $!" } grep { !/^\./ && -f "$template_dir/$_" } readdir(DIR); |
84 |
# closedir DIR; |
85 |
# }, |
86 |
}); |
87 |
|
88 |
if (! $mnt) { |
89 |
print STDERR "can't mount filesystem!"; |
90 |
exit 1; |
91 |
} |
92 |
|
93 |
print "Press enter to exit..."; |
94 |
my $foo = <STDIN>; |
95 |
|
96 |
$mnt->umount; |
97 |
|
98 |
=head1 SEE ALSO |
99 |
|
100 |
C<Fuse::DBI> website |
101 |
L<http://www.rot13.org/~dpavlin/fuse_dbi.html> |
102 |
|
103 |
C<FUSE (Filesystem in USErspace)> website |
104 |
L<http://fuse.sourceforge.net/> |
105 |
|
106 |
=head1 AUTHOR |
107 |
|
108 |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
109 |
|
110 |
=head1 COPYRIGHT AND LICENSE |
111 |
|
112 |
Copyright (C) 2004 by Dobrica Pavlinusic |
113 |
|
114 |
This library is free software; you can redistribute it and/or modify |
115 |
it under the same terms as Perl itself, either Perl version 5.8.4 or, |
116 |
at your option, any later version of Perl 5 you may have available. |
117 |
|
118 |
=cut |
119 |
|