source: box/trunk/bin/bbstored/bbstored-config.in @ 2498

Revision 2498, 5.7 KB checked in by chris, 3 years ago (diff)

Change default location for config files from /etc/box to
/etc/boxbackup, thanks to Reinhard Tartler and the Debian Project.

  • Property svn:eol-style set to native
Line 
1#!@PERL@
2use strict;
3
4# should be running as root
5if($> != 0)
6{
7        printf "\nWARNING: this should be run as root\n\n"
8}
9
10# check and get command line parameters
11if($#ARGV < 2)
12{
13        print <<__E;
14
15Setup bbstored config utility.
16
17Bad command line parameters.
18Usage:
19    bbstored-config config-dir server-hostname username [raidfile-config]
20
21Parameters:
22    config-dir       is usually @sysconfdir_expanded@/boxbackup
23    server-hostname  is the hostname that clients will use to connect to
24                     this server
25    username         is the user to run the server under
26    raidfile-config  is optional. Use if you have a non-standard
27                     raidfile.conf file.
28
29__E
30        exit(1);
31}
32
33# check for OPENSSL_CONF environment var being set
34if(exists $ENV{'OPENSSL_CONF'})
35{
36        print <<__E;
37
38---------------------------------------
39
40WARNING:
41    You have the OPENSSL_CONF environment variable set.
42    Use of non-standard openssl configs may cause problems.
43
44---------------------------------------
45
46__E
47}
48
49# default locations
50my $default_config_location = '@sysconfdir_expanded@/boxbackup/bbstored.conf';
51
52# command line parameters
53my ($config_dir,$server,$username,$raidfile_config) = @ARGV;
54
55$raidfile_config = $config_dir . '/raidfile.conf' unless $raidfile_config ne '';
56
57# check server exists, but don't bother checking that it's actually this machine.
58{
59        my @r = gethostbyname($server);
60        if($#r < 0)
61        {
62                die "Server '$server' not found. (check server name, test DNS lookup failed.)"
63        }
64}
65
66# check this exists
67if(!-f $raidfile_config)
68{
69        print "The RaidFile configuration file $raidfile_config doesn't exist.\nYou may need to create it with raidfile-config.\nWon't configure bbstored without it.\n";
70        exit(1);
71}
72
73# check that the user exists
74die "You shouldn't run bbstored as root" if $username eq 'root';
75my $user_uid = 0;
76(undef,undef,$user_uid) = getpwnam($username);
77if($user_uid == 0)
78{
79        die "User $username doesn't exist\n";
80}
81
82# check that directories are writeable
83open RAIDCONF,$raidfile_config or die "Can't open $raidfile_config";
84{
85        my %done = ();
86        while(<RAIDCONF>)
87        {
88                next unless m/Dir\d\s*=\s*(.+)/;
89                my $d = $1;
90                $d = $d.'/backup' if -e $d.'/backup';
91                print "Checking permissions on $d\n";
92                my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($d);
93                my $req_perms = ($uid == $user_uid)?0700:0007;
94                if(($mode & $req_perms) != $req_perms)
95                {
96                        print "$username doesn't appear to have the necessary permissions on $d\n";
97                        print "Either adjust permissions, or create a directory 'backup' inside the\n";
98                        print "directory specified in raidfile.conf which is writable.\n";
99                        exit(1);
100                }
101        }
102}
103close RAIDCONF;
104
105# ssl stuff
106my $private_key = "$config_dir/bbstored/$server-key.pem";
107my $certificate_request = "$config_dir/bbstored/$server-csr.pem";
108my $certificate = "$config_dir/bbstored/$server-cert.pem";
109my $ca_root_cert = "$config_dir/bbstored/clientCA.pem";
110
111# other files
112my $config_file = "$config_dir/bbstored.conf";
113my $accounts_file = "$config_dir/bbstored/accounts.txt";
114
115# summarise configuration
116
117print <<__E;
118
119Setup bbstored config utility.
120
121Configuration:
122   Writing configuration file: $config_file
123   Writing empty accounts file: $accounts_file
124   Server hostname: $server
125   RaidFile config: $raidfile_config
126
127__E
128
129# create directories
130if(!-d $config_dir)
131{
132        print "Creating $config_dir...\n";
133        mkdir $config_dir,0755 or die "Can't create $config_dir";
134}
135
136if(!-d "$config_dir/bbstored")
137{
138        print "Creating $config_dir/bbstored\n";
139        mkdir "$config_dir/bbstored",0755 or die "Can't create $config_dir/bbstored";
140}
141
142# create blank accounts file
143if(!-f $accounts_file)
144{
145        print "Creating blank accounts file\n";
146        open ACC,">$accounts_file";
147        close ACC;
148}
149
150# generate the private key for the server
151if(!-f $private_key)
152{
153        print "Generating private key...\n";
154        if(system("openssl genrsa -out $private_key 2048") != 0)
155        {
156                die "Couldn't generate private key."
157        }
158}
159
160# generate a certificate request
161if(!-f $certificate_request)
162{
163        die "Couldn't run openssl for CSR generation" unless
164                open(CSR,"|openssl req -new -key $private_key -sha1 -out $certificate_request");
165        print CSR <<__E;
166.
167.
168.
169.
170.
171$server
172.
173.
174.
175
176__E
177        close CSR;
178        print "\n\n";
179        die "Certificate request wasn't created.\n" unless -f $certificate_request
180}
181
182# write the configuration file
183print "Writing configuration file $config_file\n";
184open CONFIG,">$config_file" or die "Can't open config file for writing";
185print CONFIG <<__E;
186
187RaidFileConf = $raidfile_config
188AccountDatabase = $accounts_file
189
190# Uncomment this line to see exactly what commands are being received from clients.
191# ExtendedLogging = yes
192
193# scan all accounts for files which need deleting every 15 minutes.
194
195TimeBetweenHousekeeping = 900
196
197Server
198{
199        PidFile = @localstatedir_expanded@/run/bbstored.pid
200        User = $username
201        ListenAddresses = inet:$server
202        CertificateFile = $certificate
203        PrivateKeyFile = $private_key
204        TrustedCAsFile = $ca_root_cert
205}
206
207
208__E
209
210close CONFIG;
211
212# explain to the user what they need to do next
213my $daemon_args = ($config_file eq $default_config_location)?'':" $config_file";
214
215print <<__E;
216
217===================================================================
218
219bbstored basic configuration complete.
220
221What you need to do now...
222
2231) Sign $certificate_request
224   using the bbstored-certs utility.
225
2262) Install the server certificate and root CA certificate as
227      $certificate
228      $ca_root_cert
229
2303) You may wish to read the configuration file
231      $config_file
232   and adjust as appropraite.
233
2344) Create accounts with bbstoreaccounts
235
2365) Start the backup store daemon with the command
237      @sbindir_expanded@/bbstored$daemon_args
238   in /etc/rc.local, or your local equivalent.
239
240===================================================================
241
242__E
243
244
245
Note: See TracBrowser for help on using the repository browser.