7 global $BASE_DATA, $BASE_LIB, $BACULA_USER;
9 require_once "$BASE_LIB/lib.php";
11 if(!isset($argv[2])) {
12 echo "Usage: ".$argv[0]." changer_name command\n";
13 echo "\tbacula-config - outputs bacula config\n";
14 echo "\tinit - inits the bacula php changer stuff\n";
15 echo "\tadd-disk - adds a disk\n";
16 echo "\tdisks - lists currently (known) disks\n";
17 echo "\tstatus - prints status (whats where in which slot, drive, etc)\n";
37 echo "invalid command\n";
42 global $BASE_DATA, $BASE_LIB, $BACULA_USER, $argv;
44 // check if we are the bacula user
45 $user = posix_getlogin();
46 if($user != $BACULA_USER) {
47 echo "This command must be run as the bacula user\n";
51 $changer_name = $argv[1];
53 echo "This command will init the data for $changer_name\n";
55 if(file_exists("$BASE_DATA/$changer_name.db")) {
56 //echo "Daemon is already init'd, are you sure you wish to do this, it will loose all config [y/n]:";
57 $r = readline("Daemon is already init'd, are you sure you wish to do this, it will loose all config [y/n]:");
59 echo "Ok, but its your disaster, waiting 5 seconds prior to init'ing the database (hit ctrl-c to exit)\n";
62 echo "Ok, not doing it, so long chum\n";
67 echo "Creating database\n";
68 $ra = readline("Directory where automount occurs [/changer/]:");
69 $rb = readline("Number of drives [1]:");
70 $rc = readline("Size of tapes [20] (in gb):");
72 if($ra == "") $ra = "/changer/";
73 if($rb == "") $rb = 1;
74 if($rc == "") $rc = 20;
76 db_getDB($changer_name);
81 // disks get inited by going to /changer_dir/disk_uuid/ then:
82 // creating pbdc/changer_name/stuff.
83 global $BASE_DATA, $BASE_LIB, $BACULA_USER, $argv;
85 $dh = opendir("/dev/disk/by-uuid");
90 while(($file = readdir($dh)) !== false) {
91 if($file != "." && $file != "..") {
92 $st = stat("/dev/disk/by-uuid/".$file);
93 $realname = basename(readlink("/dev/disk/by-uuid/".$file));
96 $fh = fopen("/sys/class/block/$realname/size", "r");
99 $realsize = (int)(((($rl/1024)*512)/1024)/1024);
101 echo "disk $i: /dev/$realname or /dev/disk/by-uuid/$file of size ".$realsize."gb\n";
102 $disk[$i]["real"] = "/dev/$realname";
103 $disk[$i]["syml"] = "/dev/disk/by-uuid/".$file;
104 $disk[$i]["size"] = $realsize;
111 $i = readline("Choose a disk from the list above:");
112 if(isset($disk[$i]["real"])) {
113 echo "you have chosen, ".$disk[$i]["syml"]." (".$disk[$i]["real"].") of size ".$disk[$i]["size"]."gb\n";
114 $ans = readline("is this correct? [y/n]:");
116 echo "you said no, i bail\n";
120 echo "invalid selection\n";
124 // now we try and init the disk
125 // we have to get automount directory config