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 |
id as id, |
46 |
id||'-'||title||'.html' as filename, |
47 |
length(content) as size, |
48 |
true as writable |
49 |
from multistatic |
50 |
}, |
51 |
'read' => q{ |
52 |
select content |
53 |
from multistatic |
54 |
where id = ?; |
55 |
}, |
56 |
'update' => q{ |
57 |
update multistatic |
58 |
set content = ? |
59 |
where id = ?; |
60 |
}, |
61 |
}; |
62 |
|
63 |
my $dsn = 'DBI:Pg:dbname='.$database; |
64 |
my $db; |
65 |
|
66 |
print "using database '$dsn', mountpoint $mount\n"; |
67 |
|
68 |
my $mnt = Fuse::DBI->mount({ |
69 |
filenames => $sql->{'filenames'}, |
70 |
read => $sql->{'read'}, |
71 |
update => $sql->{'update'}, |
72 |
dsn => $dsn, |
73 |
user => '', |
74 |
password => '', |
75 |
mount => $mount, |
76 |
fork => 1, |
77 |
# invalidate => sub { |
78 |
# print STDERR "invalidating content in $template_dir\n"; |
79 |
# opendir(DIR, $template_dir) || die "can't opendir $template_dir: $!"; |
80 |
# map { unlink "$template_dir/$_" || warn "can't remove $template_dir/$_: $!" } grep { !/^\./ && -f "$template_dir/$_" } readdir(DIR); |
81 |
# closedir DIR; |
82 |
# }, |
83 |
}); |
84 |
|
85 |
if (! $mnt) { |
86 |
print STDERR "can't mount filesystem!"; |
87 |
exit 1; |
88 |
} |
89 |
|
90 |
print "Press enter to exit..."; |
91 |
my $foo = <STDIN>; |
92 |
|
93 |
$mnt->umount; |
94 |
|
95 |
=head1 SEE ALSO |
96 |
|
97 |
C<Fuse::DBI> website |
98 |
L<https://www.rot13.org/~dpavlin/fuse_dbi.html> |
99 |
|
100 |
C<FUSE (Filesystem in USErspace)> website |
101 |
L<http://fuse.sourceforge.net/> |
102 |
|
103 |
=head1 AUTHOR |
104 |
|
105 |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
106 |
|
107 |
=head1 COPYRIGHT AND LICENSE |
108 |
|
109 |
Copyright (C) 2004 by Dobrica Pavlinusic |
110 |
|
111 |
This library is free software; you can redistribute it and/or modify |
112 |
it under the same terms as Perl itself, either Perl version 5.8.4 or, |
113 |
at your option, any later version of Perl 5 you may have available. |
114 |
|
115 |
=cut |
116 |
|