-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·76 lines (61 loc) · 2.07 KB
/
init
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
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use FindBin;
use Data::Dumper;
my $prompt_vars = [
# ['env name', 'message', 'require', 'default value'],
['DAEMON_USER', 'daemon user', 1, 'skype'],
['SKYPE_NAME', 'skype name', 1],
['SKYPE_PASSWORD', 'skype password', 1],
['LOG_DIR', 'log dir', 1, '/var/log/skype'],
['RUN_DIR', 'tmp dir', 1, '/var/run/skype'],
['LIB_DIR', 'lib dir', 1, '/var/lib/skype'],
['X_SERVER_NUM', 'x server num', 1, '10'],
['X_SCREEN_NUM', 'x screen num', 1, '0'],
['X_SCREEN_WIDTH', 'x screen width', 1, '800'],
['X_SCREEN_HEIGHT', 'x screen height', 1, '600'],
['X_SCREEN_DEPTH', 'x screen_depth', 1, '8'],
];
sub run {
# header
print "#===================#\n";
print "# daemontools-skype #\n";
print "#===================#\n";
print "\n";
print "Initialize...\n";
my $env = &prompt($prompt_vars);
# DISPLAY
$env->{DISPLAY} = ":$env->{X_SERVER_NUM}.$env->{X_SCREEN_NUM}";
# XAUTHORITY
$env->{XAUTHORITY} = "$env->{RUN_DIR}/Xauthority";
# uid, pwd
my ($uid, $gid) = (getpwnam $env->{DAEMON_USER})[2, 3];
for (keys %$env) {
# make dir
if ($_ =~ /_DIR$/) {
system "sudo mkdir -p $env->{$_}" unless -d $env->{$_};
system "sudo chown $env->{DAEMON_USER}:$env->{DAEMON_USER} $env->{$_}";
}
mkdir "$FindBin::Bin/env" unless -d "$FindBin::Bin/env";
open FH, '+>', "$FindBin::Bin/env/$_";
print FH $env->{$_};
close FH;
}
}
sub prompt {
my $vars = shift;
my $env = +{};
while (my $var = shift @$vars) {
my ($env_name, $message, $require, $default) = @$var;
print " $message" . (defined $default ? " ($default)" : '') . ': ';
my $input = <STDIN>;
chomp $input;
$input ||= $default if defined $default;
die "Error: $message is required" unless defined $input and $input ne '';
$env->{uc $env_name} = $input;
}
return $env;
}
&run;