Project

General

Profile

Download (6.7 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
exec("rm -rf /home/pfsense /root/pfsense /pfSenseGITREPO/");
8

    
9
$GIT_REPO="http://gitweb.pfsense.org/pfsense/mainline.git";
10
$CODIR =  "/root/pfsense/";
11

    
12
global $argv;
13
global $command_split;
14

    
15
conf_mount_rw();
16

    
17
echo "\nRemoving downloaded cvssync data, please wait...";
18
exec("/bin/rm -rf /home/pfsense");
19
exec("mkdir -p /home/pfsense");
20
echo " done.\n";
21

    
22
unlink_if_exists("/tmp/config.cache");
23

    
24
if(!file_exists("/usr/local/bin/git")) {
25
	echo "Cannot find git, fetching static git...";
26
    system("pkg_add -r git");
27
}
28

    
29
# Remove mainline if exists (older)
30
if(is_dir("/root/pfsense/mainline")) 
31
	exec("rm -rf /root/pfsense/mainline");
32

    
33
# Remove RELENG_1_2 if exists (older)
34
if(is_dir("/root/pfsense/RELENG_1_2")) 
35
	exec("rm -rf /root/pfsense/RELENG_1_2");
36

    
37
# Remove HEAD if exists (older)
38
if(is_dir("/root/pfsense/HEAD")) 
39
	exec("rm -rf /root/pfsense/HEAD");
40

    
41
/* NOTE: Set branches here */
42
$branches = array(
43
	"master" => "2.0 development branch",
44
	"RELENG_1_2" => "1.2* release branch"
45
);
46

    
47
if(file_exists("/root/cvssync_backup.tgz")) {
48
	$backup_date = `ls -lah /root/cvssync_backup.tgz | awk '{ print $6,$7,$8 }'`;
49
	$tmp = array("RESTORE" => "Restores prior CVSSync backup data performed at {$backup_date}");
50
	$branches = array_merge($branches, $tmp);
51
}
52

    
53
if($command_split[2]) {
54
	$branch = $command_split[2];
55
} else {
56
	if(!$argv[3]) {
57
		echo "\nPlease select which branch you would like to sync against:\n\n";
58
		foreach($branches as $branchname => $branchdesc) {
59
			echo "{$branchname} \t {$branchdesc}\n";
60
		}
61
		$branch = readline("> ");
62
		echo "\n";
63
	} else {
64
		$branch = $argv[3];
65
	}
66
}
67

    
68
if($argv[4] == "NOBACKUP") 
69
	$nobackup=true;
70
else 
71
	$nobackup = false;
72

    
73
exec("mkdir -p /root/pfsense/$BRANCHTAG");
74

    
75
$found = false;
76
foreach($branches as $branchname => $branchdesc) {
77
	if($branchname == $branch) 
78
		$found = true;
79
}
80
if(!$found) {
81
	echo "\nInvalid branch.\n";
82
	exit;
83
}
84

    
85
if($branch == "RESTORE" && $g['platform'] == "pfSense") {
86
	if(!file_exists("/root/cvssync_backup.tgz")) {
87
		echo "Sorry, we could not find a previous CVSSync backup file.\n";
88
		exit();
89
	}
90
	echo "===> Restoring previous CVSSync backup... Please wait...\n";
91
	exec("tar Uxpf /root/cvssync_backup.tgz -C /");
92
	post_cvssync_commands();
93
	exit();
94
} else {
95
	$nobackup = true; // do not backup embedded, livecd
96
}
97

    
98
if($nobackup == false) {
99
	echo "===> Backing up current pfSense information...\n";
100
	echo "===> Please wait... ";
101
	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 /");
102
	$size = filesize("/root/cvssync_backup.tgz");
103
	echo "{$size} bytes.\n\n";
104
	sleep(5);
105
}
106

    
107
echo "===> Checking out $branch\n";
108
exec("mkdir -p /root/pfsense/$branch");
109

    
110
// Git 'er done!
111
if(is_dir("$CODIR/pfSenseGITREPO")) {
112
	exec("cd $CODIR/pfSenseGITREPO && git fetch");
113
	exec("cd $CODIR/pfSenseGITREPO && git merge $branch");	
114
} else {
115
    exec("mkdir -p $CODIR/pfSenseGITREPO");
116
    echo "Executing cd $CODIR/pfSenseGITREPO && git clone $GIT_REPO pfSenseGITREPO";
117
	exec("cd $CODIR/pfSenseGITREPO && git clone $GIT_REPO pfSenseGITREPO");
118
	if(is_dir("$CODIR/pfSenseGITREPO/pfSense")) 
119
		exec("mv $CODIR/pfSenseGITREPO/pfSense $CODIR/pfSenseGITREPO/pfSenseGITREPO");
120
	if(is_dir("$CODIR/pfSenseGITREPO/mainline")) 
121
		exec("mv $CODIR/pfSenseGITREPO/mainline $CODIR/pfSenseGITREPO/pfSenseGITREPO");
122
}
123

    
124
if($branch == "master") {
125
	exec("cd $CODIR/pfSenseGITREPO && git checkout master");
126
} else {
127
	$current_branch=`git branch | grep $branch`;
128
	if($current_branch == "") {
129
		exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && git checkout -b $branch origin/$branch");
130
	} else {
131
		exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && git checkout $branch");
132
	}
133
}
134

    
135
exec("mkdir -p /tmp/lighttpd/cache/compress/");
136

    
137
// Nuke CVS and pfSense tarballs
138
exec("cd ${CODIR}/pfSenseGITREPO/pfSenseGITREPO && find . -name CVS -exec rm -rf {} \; 2>/dev/null");
139
exec("cd ${CODIR}/pfSenseGITREPO/pfSenseGITREPO && find . -name pfSense.tgz -exec rm {} \; 2>/dev/null");
140

    
141
// Remove files that we do not want to overwrite the system with 
142
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/usr/local/www/trigger_initial_wizard 2>/dev/null");
143
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/crontab 2>/dev/null");
144
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/master.passwd 2>/dev/null");
145
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/passwd 2>/dev/null");
146
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/fstab 2>/dev/null");
147
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/ttys 2>/dev/null");
148
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/group 2>/dev/null");
149
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/fstab 2>/dev/null");
150
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/platform 2>/dev/null");
151
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/boot/device.hints 2>/dev/null");
152
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/boot/loader.conf 2>/dev/null");
153
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/boot/loader.rc 2>/dev/null");
154
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/conf*");
155
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/cf 2>/dev/null");
156
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/root/.shrc");
157
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/root/.tcshrc");
158
exec("rm -f ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/syslog.conf 2>/dev/null");
159

    
160
echo "===> Installing new files...\n";
161

    
162
if($g['platform'] == "pfSense") 
163
	$command = "cd $CODIR/pfSenseGITREPO/pfSenseGITREPO ; tar -cpf - . | (cd / ; tar -Uxpf -)";
164
else 
165
	$command = "cd $CODIR/pfSenseGITREPO/pfSenseGITREPO ; tar -cpf - . | (cd / ; tar -xpf -) 2>/dev/null";
166
exec($command);
167

    
168
post_cvssync_commands();
169

    
170
echo "===> Checkout complete.\n";
171
echo "\n";
172
echo "Your system is now sync'd and PHP and Lighty will be restarted in 5 seconds.\n\n";
173

    
174
function post_cvssync_commands() {
175
	echo "===> Removing FAST-CGI temporary files...\n";
176
	exec("find /tmp -name \"php-fastcgi.socket*\" -exec rm -rf {} \;");
177
	exec("find /tmp -name \"*.tmp\" -exec rm -rf {} \;");
178

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

    
181
	echo "===> Upgrading configuration (if needed)...\n";
182
	convert_config();
183

    
184
	echo "===> Restarting check_reload_status...\n";
185
	exec("killall check_reload_status");
186
	mwexec_bg("nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status");
187

    
188
	echo "===> Configuring filter...";
189
	exec("/etc/rc.filter_configure_sync");
190
	exec("pfctl -f /tmp/rules.debug");
191
	echo "\n";
192

    
193
	echo "===> Signaling PHP and Lighty restart...";
194
	$fd = fopen("/tmp/restart_lighty", "w");
195
	fwrite($fd, "#!/bin/sh\n");
196
	fwrite($fd, "sleep 5\n");
197
	fwrite($fd, "killall php\n");
198
	fwrite($fd, "touch /tmp/restart_webgui\n");
199
	fclose($fd);
200
	mwexec_bg("sh /tmp/restart_lighty");
201
	echo "\n";
202
}
203

    
204
conf_mount_ro();
(1-1/7)