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