source: box/trunk/lib/raidfile/raidfile-config.in @ 2498

Revision 2498, 1.9 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 != 4 && $#ARGV != 2)
12{
13        print <<__E;
14
15Setup raidfile config utility.
16
17Bad command line parameters.
18Usage:
19    raidfile-config config-dir block-size dir0 [dir1 dir2]
20
21Parameters:
22    config-dir        is usually @sysconfdir_expanded@/boxbackup
23    block-size        must be a power of two, and usually the block or
24                      fragment size of your file system
25    dir0, dir1, dir2  are the directories used as the root of the raid
26                      file system
27
28If only one directory is specified, then userland RAID is disabled.
29Specifying three directories enables it.
30
31__E
32        exit(1);
33}
34
35my ($config_dir,$block_size,@dirs) = @ARGV;
36
37my $conf = $config_dir . '/raidfile.conf';
38
39# check dirs are unique, and exist
40my %d;
41for(@dirs)
42{
43        die "$_ is used twice" if exists $d{$_};
44        die "$_ is not a directory" unless -d $_;
45        die "$_ should be an absolute path" unless m/\A\//;
46        $d{$_} = 1;
47}
48
49# check block size is OK
50$block_size = int($block_size);
51die "Bad block size" if $block_size <= 0;
52my $c = 1;
53while(1)
54{
55        last if $c == $block_size;
56        die "Block size $block_size is not a power of two" if $c > $block_size;
57        $c = $c * 2;
58}
59
60# check that it doesn't already exist
61if(-f $conf)
62{
63        die "$conf already exists. Delete and try again";
64}
65
66# create directory
67if(!-d $config_dir)
68{
69        print "Creating $config_dir...\n";
70        mkdir $config_dir,0755 or die "Can't create $config_dir";
71}
72
73# adjust if userland RAID is disabled
74if($#dirs == 0)
75{
76        $dirs[1] = $dirs[0];
77        $dirs[2] = $dirs[0];
78        print "WARNING: userland RAID is disabled.\n";
79}
80
81# write the file
82open CONFIG,">$conf" or die "Can't open $conf for writing";
83
84print CONFIG <<__E;
85
86disc0
87{
88        SetNumber = 0
89        BlockSize = $block_size
90        Dir0 = $dirs[0]
91        Dir1 = $dirs[1]
92        Dir2 = $dirs[2]
93}
94
95__E
96
97close CONFIG;
98
99print "Config file written.\n";
100
Note: See TracBrowser for help on using the repository browser.