-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprofile.pl
More file actions
executable file
·100 lines (87 loc) · 2.56 KB
/
profile.pl
File metadata and controls
executable file
·100 lines (87 loc) · 2.56 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl
use strict;
use warnings;
my $rtDir = "/usr/share/sounds/ring-tones";
my @profiles = qw(general meeting outdoors silent);
my $ringingVolumes = [40, 60, 80, 100];
my $systemVolumes = [0, 1, 2, 3];
sub run(@);
sub generateProfile($$);
sub fixSize($$$);
my $tones = {
ringing => undef,
voip => undef,
email => undef,
sms => undef,
im => undef,
calendar => undef,
clock => undef,
};
my $ringingVolume = $$ringingVolumes[3];
my $systemVolume= $$systemVolumes[1];
my $vibrate = {
general => 1,
meeting => 1,
outdoors => 1,
silent => 1,
};
my @attributes = (
['ringing.alert.tone' => "$rtDir/Nokia tune.mp3"],
['voip.alert.tone' => "$rtDir/Nokia tune.mp3"],
['email.alert.tone' => "$rtDir/Email 1.mp3"],
['sms.alert.tone' => "$rtDir/Message 1.mp3"],
['im.alert.tone' => "$rtDir/Chat alert.wav"],
['calendar.alert.tone' => "$rtDir/Calendar 1.mp3"],
['clock.alert.tone' => "$rtDir/Clock 1.mp3"],
['system.sound.level' => 1],
['ringing.alert.volume' => 100],
['vibrating.alert.enabled' => undef],
);
my @attNames = map {$$_[0]} @attributes;
my %defaultValues = map{$$_[0] => $$_[1]} @attributes;
sub main(@){
my $s = "# custom profile values\n";
for my $profile(@profiles){
my %props = map {("$_.alert.tone" => $$tones{$_})} keys %$tones;
$props{'vibrating.alert.enabled'} = "Off" if $$vibrate{$profile} == 0;
$props{'ringing.alert.volume'} = $ringingVolume if $profile eq "general";
$props{'system.sound.level'} = $systemVolume if $profile ne "silent";
$s .= generateProfile $profile, \%props;
}
$s = fixSize $s, 4096, 78;
my $tmpFile = "/tmp/n9-profile-" . time . "-custom.ini";
open FH, "> $tmpFile" or die "Couldnt write $tmpFile\n";
print FH $s;
close FH;
my $host = `n9`;
chomp $host;
run "scp", $tmpFile, "user\@$host:/home/user/.profiled/custom.ini";
}
sub run(@){
print "@_\n";
system @_;
die "Error running @_\n" if $? != 0;
}
sub generateProfile($$){
my ($profile, $props) = @_;
my @lines;
for my $attName(@attNames){
my $val = $$props{$attName};
$val = undef if defined $val and $val eq $defaultValues{$attName};
push @lines, "$attName=$val\n" if defined $val;
}
@lines = sort @lines;
return "" if @lines == 0;
return "[$profile]\n\n" . (join '', @lines) . "\n";
}
sub fixSize($$$){
my ($s, $size, $perLine) = @_;
my $target = $size - length $s;
while($target > $perLine){
$s .= ("#"x($perLine - 1)) . "\n";
$target = $size - length $s;
}
$s .= ("#"x($target - 1)) . "\n";
return $s;
}
&main(@ARGV);