Project

General

Profile

Download (5.49 KB) Statistics
| Branch: | Tag: | Revision:
1
/*   cvs_sync
2
 *   Written by Scott Ullrich
3
 *   (C)2005-2007 Scott Ullrich
4
 *   Part of the pfSense project pfSsh.php subsystem
5
 */
6

    
7
$GIT_REPO="http://gitweb.pfsense.org/pfsense/mainline.git";
8

    
9
global $argv;
10
global $command_split;
11

    
12
conf_mount_rw();
13

    
14
if(is_dir("/home/pfsense")) {
15
	echo "\nRemoving downloaded cvssync data, please wait...";
16
	exec("rm -rf /home/pfsense");
17
	echo " done.\n";
18
}
19

    
20
unlink_if_exists("/tmp/config.cache");
21

    
22
if(!file_exists("/usr/local/bin/git")) {
23
	echo "Cannot find git, fetching static git...";
24
	system("fetch -o /usr/local/bin/git http://files.pfsense.org/extras/7/git");
25
	system("chmod a+rx /usr/local/bin/git");
26
}
27

    
28
/* NOTE: Set branches here */
29
$branches = array(
30
	"master" => "2.0 development branch",
31
	"RELENG_1_2" => "1.2* release branch"
32
);
33

    
34
if(file_exists("/root/cvssync_backup.tgz")) {
35
	$backup_date = `ls -lah /root/cvssync_backup.tgz | awk '{ print $6,$7,$8 }'`;
36
	$tmp = array("RESTORE" => "Restores prior CVSSync backup data performed at {$backup_date}");
37
	$branches = array_merge($branches, $tmp);
38
}
39

    
40
if($command_split[2]) {
41
	$branch = $command_split[2];
42
} else {
43
	if(!$argv[3]) {
44
		echo "\nPlease select which branch you would like to sync against:\n\n";
45
		foreach($branches as $branchname => $branchdesc) {
46
			echo "{$branchname} \t {$branchdesc}\n";
47
		}
48
		$branch = readline("> ");
49
		echo "\n";
50
	} else {
51
		$branch = $argv[3];
52
	}
53
}
54

    
55
if($argv[4] == "NOBACKUP") 
56
	$nobackup=true;
57
else 
58
	$nobackup = false;
59

    
60
$CODIR =  "/root/pfsense/";
61

    
62
exec("mkdir -p /root/pfsense/$BRANCHTAG");
63

    
64
$found = false;
65
foreach($branches as $branchname => $branchdesc) {
66
	if($branchname == $branch) 
67
		$found = true;
68
}
69
if(!$found) {
70
	echo "\nInvalid branch.\n";
71
	exit;
72
}
73

    
74
if($branch == "RESTORE" && $g['platform'] == "pfSense") {
75
	if(!file_exists("/root/cvssync_backup.tgz")) {
76
		echo "Sorry, we could not find a previous CVSSync backup file.\n";
77
		exit();
78
	}
79
	echo "===> Restoring previous CVSSync backup... Please wait...\n";
80
	exec("tar Uxpf /root/cvssync_backup.tgz -C /");
81
	post_cvssync_commands();
82
	exit();
83
} else {
84
	$nobackup = true; // do not backup embedded, livecd
85
}
86

    
87
if($nobackup == false) {
88
	echo "===> Backing up current pfSense information...\n";
89
	echo "===> Please wait... ";
90
	exec("tar czPf /root/cvssync_backup.tgz --exclude /root --exclude /dev --exclude /var/db/racoon/racoon.sock --exclude /tmp --exclude /var/run --exclude /var/empty /");
91
	$size = filesize("/root/cvssync_backup.tgz");
92
	echo "{$size} bytes.\n\n";
93
	sleep(5);
94
}
95

    
96
echo "===> Checking out $branch\n";
97
exec("mkdir -p /root/pfsense/$branch");
98

    
99
// Git 'er done!
100
if(is_dir("$CODIR/master/mainline"))
101
	exec("cd $CODIR/master/mainline && git fetch");
102
else
103
	exec("cd $CODIR && git clone $GIT_REPO");
104

    
105
if($branch == "master")
106
	exec("cd $CODIR/master/mainline && git pull && git checkout master");
107
else 
108
	exec("cd $CODIR/master/mainline && git pull && checkout -b $BRANCHTAG origin/$BRANCHTAG");
109

    
110
exec("mkdir -p /tmp/lighttpd/cache/compress/");
111

    
112
// Nuke CVS and pfSense tarballs
113
exec("cd ${CODIR}/master/mainline && find . -name CVS -exec rm -rf {} \; 2>/dev/null");
114
exec("cd ${CODIR}/master/mainline && find . -name pfSense.tgz -exec rm {} \; 2>/dev/null");
115

    
116
// Remove files that we do not want to overwrite the system with 
117
exec("rm ${CODIR}/master/mainline/usr/local/www/trigger_initial_wizard 2>/dev/null");
118
exec("rm ${CODIR}/master/mainline/etc/crontab 2>/dev/null");
119
exec("rm ${CODIR}/master/mainline/etc/master.passwd 2>/dev/null");
120
exec("rm ${CODIR}/master/mainline/etc/passwd 2>/dev/null");
121
exec("rm ${CODIR}/master/mainline/etc/fstab 2>/dev/null");
122
exec("rm ${CODIR}/master/mainline/etc/ttys 2>/dev/null");
123
exec("rm ${CODIR}/master/mainline/etc/group 2>/dev/null");
124
exec("rm ${CODIR}/master/mainline/etc/fstab 2>/dev/null");
125
exec("rm ${CODIR}/master/mainline/etc/platform 2>/dev/null");
126
exec("rm ${CODIR}/master/mainline/boot/device.hints 2>/dev/null");
127
exec("rm ${CODIR}/master/mainline/boot/loader.conf 2>/dev/null");
128
exec("rm ${CODIR}/master/mainline/boot/loader.rc 2>/dev/null");
129
exec("rm -rf ${CODIR}/master/mainline/conf*");
130
exec("rm -rf ${CODIR}/master/mainline/cf 2>/dev/null");
131
exec("rm -rf ${CODIR}/master/mainline/root/.shrc");
132
exec("rm -rf ${CODIR}/master/mainline/root/.tcshrc");
133
exec("rm -f ${CODIR}/master/mainline/etc/syslog.conf 2>/dev/null");
134

    
135
echo "===> Installing new files...\n";
136

    
137
if($g['platform'] == "pfSense") 
138
	$command = "cd $CODIR/master/mainline ; tar -cpf - . | (cd / ; tar -Uxpf -)";
139
else 
140
	$command = "cd $CODIR/master/mainline ; tar -cpf - . | (cd / ; tar -xpf -) 2>/dev/null";
141
exec($command);
142

    
143
post_cvssync_commands();
144

    
145
echo "===> Checkout complete.\n";
146
echo "\n";
147
echo "Your system is now sync'd and PHP and Lighty will be restarted in 5 seconds.\n\n";
148

    
149
function post_cvssync_commands() {
150
	echo "===> Removing FAST-CGI temporary files...\n";
151
	exec("find /tmp -name \"php-fastcgi.socket*\" -exec rm -rf {} \;");
152
	exec("find /tmp -name \"*.tmp\" -exec rm -rf {} \;");
153

    
154
	exec("rm -rf /tmp/xcache/* 2>/dev/null");
155

    
156
	echo "===> Upgrading configuration (if needed)...\n";
157
	convert_config();
158

    
159
	echo "===> Restarting check_reload_status...\n";
160
	exec("killall check_reload_status");
161
	mwexec_bg("nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status");
162

    
163
	echo "===> Configuring filter...";
164
	exec("/etc/rc.filter_configure_sync");
165
	exec("pfctl -f /tmp/rules.debug");
166
	echo "\n";
167

    
168
	echo "===> Signaling PHP and Lighty restart...";
169
	$fd = fopen("/tmp/restart_lighty", "w");
170
	fwrite($fd, "#!/bin/sh\n");
171
	fwrite($fd, "sleep 5\n");
172
	fwrite($fd, "killall php\n");
173
	fwrite($fd, "touch /tmp/restart_webgui\n");
174
	fclose($fd);
175
	mwexec_bg("sh /tmp/restart_lighty");
176
	echo "\n";
177
}
178

    
179
conf_mount_ro();
(1-1/6)