-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenconfig.pl
executable file
·59 lines (42 loc) · 1.5 KB
/
genconfig.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
use strict;
use warnings;
use DBCredentials;
use POSIX qw(getuid getgid);
use WebService::Dropbox;
sub setup_dropbox_credentials
{
my $settings_file = $_[0];
my $dropbox = WebService::Dropbox->new(DBCredentials::get_credentials());
my $access_url = $dropbox->login or die($dropbox->error);
print("Open this URL in browser and press ENTER:\n$access_url\n");
<>;
$dropbox->auth or die $dropbox->error;
print $settings_file "\n# DropBox configuration\n";
print $settings_file "access_token=".$dropbox->access_token."\n";
print $settings_file "access_secret=".$dropbox->access_secret."\n";
print $settings_file "access_type=sandbox\n";
}
sub setup_basic_configuration
{
my ($settings_file, $mountpoint, $mode) = @_;
print $settings_file "\n# FUSE settings configuration\n";
print $settings_file "mountpoint=$mountpoint\n";
print $settings_file "uid=".getuid()."\n";
print $settings_file "gid=".getgid()."\n";
printf $settings_file "mode=%#o\n", $mode;
}
sub create_config_file
{
my ($path, $mountpoint, $mode) = @_;
open my $settings_file, '>', $path;
print $settings_file "# This file was automaticaly generated by genconfig.pl\n";
print $settings_file "# ".localtime()."\n";
setup_basic_configuration($settings_file, $mountpoint, $mode);
setup_dropbox_credentials($settings_file);
close $settings_file;
}
my $settings_file_path = shift || $ENV{HOME}."/.perldrops";
my $mountpoint = shift || "/mnt";
my $mode = shift || 0644;
create_config_file($settings_file_path, $mountpoint, $mode);