Project

General

Profile

« Previous | Next » 

Revision 6edc4c0c

Added by Scott Ullrich over 14 years ago

Fix misc errors. File now restores and throws an alert when completed.

View differences:

etc/ecl.php
1
#!/usr/local/bin/php
1
#!/usr/local/bin/php -q
2 2

  
3 3
<?php
4 4
/*  
......
31 31

  
32 32
require("globals.inc");
33 33
require("functions.inc");
34
require("config.lib.inc");
35
require("config.inc");
36

  
37
$debug = false;
34 38

  
35 39
function get_boot_disk() {
36
	global $g;
40
	global $g, $debug;
37 41
	$disk = `/sbin/mount | /usr/bin/grep "on / " | /usr/bin/cut -d'/' -f3 | /usr/bin/cut -d' ' -f1`;
38 42
	return $disk;
39 43
}
40 44

  
41 45
function get_disk_slices($disk) {
42
	global $g;
46
	global $g, $debug;
43 47
	$slices_array = array();
44
	$slices = `/bin/ls /dev/{$disk}s*`;
48
	$slices = trim(`/bin/ls /dev/{$disk}s* 2>/dev/null`);
49
	$slices = str_replace("/dev/", "", $slices);
45 50
	if($slices == "ls: No match.") 
46 51
		return;
47 52
	$slices_array = split(" ", $slices);
......
49 54
}
50 55

  
51 56
function get_disks() {
52
	global $g;
57
	global $g, $debug;
53 58
	$disks_array = array();
54 59
	$disks = `/sbin/sysctl kern.disks | cut -d':' -f2`;
55 60
	$disks_s = explode(" ", $disks);
......
60 65
}
61 66

  
62 67
function discover_config($mountpoint) {
63
	global $g;
68
	global $g, $debug;
64 69
	$locations_to_check = array("/", "/config");
65 70
	foreach($locations_to_check as $ltc) {
66
		$tocheck = "{$mountpoint}{$ltc}/config.xml";
71
		$tocheck = "/tmp/mnt/cf/{$ltc}/config.xml";
72
		if($debug) {
73
			echo "\nChecking for $tocheck";
74
			if(file_exists($tocheck)) 
75
				echo " -> found!";
76
		}
67 77
		if(file_exists($tocheck)) 
68 78
			return $tocheck;
69 79
	}
......
71 81
}
72 82

  
73 83
function test_config($file_location) {
74
	global $g;
84
	global $g, $debug;
75 85
	// config.xml was found.  ensure it is sound.
76
	$root_obj = trim($g['xml_rootobj']);
77
	$xml_file_head = trim(`/bin/cat {$file_location} | /usr/bin/head -n1`);
86
	$root_obj = trim("<{$g['xml_rootobj']}>");
87
	$xml_file_head = trim(`/bin/cat {$file_location} | /usr/bin/head -n2 | /usr/bin/tail -n1`);
88
	if($debug) {
89
		echo "\nroot obj  = $root_obj";
90
		echo "\nfile head = $xml_file_head";
91
	}
78 92
	if($xml_file_head == $root_obj) {
79 93
		// Now parse config to make sure
80 94
		$config_status = config_validate($file_location);
......
86 100

  
87 101
// Probes all disks looking for config.xml
88 102
function find_config_xml() {
89
	global $g;
103
	global $g, $debug;
90 104
	$disks = get_disks();
91 105
	$boot_disk = get_boot_disk();
92
	exec("mkdir -p /tmp/mnt/cf");
106
	exec("/bin/mkdir -p /tmp/mnt/cf");
93 107
	foreach($disks as $disk) {
94 108
		$slices = get_disk_slices($disk);
95 109
		if(is_array($slices)) {
96 110
			foreach($slices as $slice) {
111
				if($slice == "")
112
					continue;
97 113
				echo " $slice";
98 114
				// First try msdos fs
99
				$result = exec("/sbin/mount -t msdos /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
115
				if($debug) 
116
					echo "\n/sbin/mount -t msdosfs /dev/{$slice} /tmp/mnt/cf 2>/dev/null \n";
117
				$result = exec("/sbin/mount -t msdosfs /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
100 118
				// Next try regular fs (ufs)
101
				if(!$result) 
119
				if(!$result) {
120
					if($debug) 
121
						echo "\n/sbin/mount /dev/{$slice} /tmp/mnt/cf 2>/dev/null \n";
102 122
					$result = exec("/sbin/mount /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
103
				if($result == "0") {
123
				}
124
				$mounted = trim(exec("/sbin/mount | /usr/bin/grep -v grep | /usr/bin/grep '/tmp/mnt/cf' | /usr/bin/wc -l"));
125
				if($debug) 
126
					echo "\nmounted: $mounted ";
127
				if(intval($mounted) > 0) {
128
					echo " ! ";
104 129
					// Item was mounted - look for config.xml file
105 130
					$config_location = discover_config($slice);
106 131
					if($config_location) {
107 132
						if(test_config($config_location)) {
108 133
							// We have a valid configuration.  Install it.
109
							echo " -> found ";
134
							echo " -> found config.xml ";
110 135
							backup_config();
111 136
							restore_backup($config_location);
112
							exec("/sbin/unount /tmp/mnt/cf");
137
							exec("/sbin/umount /tmp/mnt/cf");
113 138
							break;
114 139
						}
115 140
					}
141
					exec("/sbin/umount /tmp/mnt/cf");
116 142
				}
117 143
			}
118 144
		}

Also available in: Unified diff