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
|
require_once("filter.inc");
|
8
|
require_once("shaper.inc");
|
9
|
require_once("rrd.inc");
|
10
|
|
11
|
conf_mount_rw();
|
12
|
|
13
|
exec("rm -rf /home/pfsense /root/pfsense /pfSenseGITREPO/");
|
14
|
|
15
|
$GIT_REPO="http://gitweb.pfsense.org/pfsense/mainline.git";
|
16
|
$CODIR = "/root/pfsense/";
|
17
|
|
18
|
global $argv;
|
19
|
global $command_split;
|
20
|
|
21
|
echo "\nRemoving downloaded cvssync data, please wait...";
|
22
|
exec("/bin/rm -rf /home/pfsense");
|
23
|
exec("mkdir -p /home/pfsense");
|
24
|
echo " done.\n";
|
25
|
|
26
|
unlink_if_exists("/tmp/config.cache");
|
27
|
|
28
|
if(!file_exists("/usr/local/bin/git")) {
|
29
|
echo "Cannot find git, fetching static git...";
|
30
|
system("pkg_add -r git");
|
31
|
}
|
32
|
|
33
|
# Remove mainline if exists (older)
|
34
|
if(is_dir("/root/pfsense/mainline"))
|
35
|
exec("rm -rf /root/pfsense/mainline");
|
36
|
|
37
|
# Remove RELENG_1_2 if exists (older)
|
38
|
if(is_dir("/root/pfsense/RELENG_1_2"))
|
39
|
exec("rm -rf /root/pfsense/RELENG_1_2");
|
40
|
|
41
|
# Remove HEAD if exists (older)
|
42
|
if(is_dir("/root/pfsense/HEAD"))
|
43
|
exec("rm -rf /root/pfsense/HEAD");
|
44
|
|
45
|
/* NOTE: Set branches here */
|
46
|
$branches = array(
|
47
|
"master" => "2.0 development branch",
|
48
|
"RELENG_1_2" => "1.2* release branch"
|
49
|
);
|
50
|
|
51
|
if(file_exists("/root/cvssync_backup.tgz")) {
|
52
|
$backup_date = `ls -lah /root/cvssync_backup.tgz | awk '{ print $6,$7,$8 }'`;
|
53
|
$tmp = array("RESTORE" => "Restores prior CVSSync backup data performed at {$backup_date}");
|
54
|
$branches = array_merge($branches, $tmp);
|
55
|
}
|
56
|
|
57
|
if($command_split[2]) {
|
58
|
$branch = $command_split[2];
|
59
|
} else {
|
60
|
if(!$argv[3]) {
|
61
|
echo "\nPlease select which branch you would like to sync against:\n\n";
|
62
|
foreach($branches as $branchname => $branchdesc) {
|
63
|
echo "{$branchname} \t {$branchdesc}\n";
|
64
|
}
|
65
|
echo "\nOr alternatively you may enter a custom branch URL.\n\n";
|
66
|
$branch = readline("> ");
|
67
|
echo "\n";
|
68
|
} else {
|
69
|
$branch = $argv[3];
|
70
|
}
|
71
|
}
|
72
|
|
73
|
if($argv[4] == "NOBACKUP")
|
74
|
$nobackup=true;
|
75
|
else
|
76
|
$nobackup = false;
|
77
|
|
78
|
exec("mkdir -p /root/pfsense/$BRANCHTAG");
|
79
|
|
80
|
$found = false;
|
81
|
foreach($branches as $branchname => $branchdesc) {
|
82
|
if($branchname == $branch)
|
83
|
$found = true;
|
84
|
}
|
85
|
if(!$found) {
|
86
|
if(isURL($branch)) {
|
87
|
echo "\n";
|
88
|
echo "NOTE: $branch was not found.\n\n";
|
89
|
$command = readline("Is this a custom GIT URL? [y]? ");
|
90
|
if(strtolower($command) == "y" or $command == "") {
|
91
|
$GIT_REPO = $branch;
|
92
|
$command = readline("Checkout which branch [master]? ");
|
93
|
if($command == "")
|
94
|
$branch = "master";
|
95
|
if($command)
|
96
|
$branch = $command;
|
97
|
$found = true;
|
98
|
}
|
99
|
}
|
100
|
if(!$found) {
|
101
|
echo "\nNo valid branch found. Exiting.\n\n";
|
102
|
exit;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
if($branch == "RESTORE" && $g['platform'] == "pfSense") {
|
107
|
if(!file_exists("/root/cvssync_backup.tgz")) {
|
108
|
echo "Sorry, we could not find a previous CVSSync backup file.\n";
|
109
|
exit();
|
110
|
}
|
111
|
echo "===> Restoring previous CVSSync backup... Please wait...\n";
|
112
|
exec("tar Uxpf /root/cvssync_backup.tgz -C /");
|
113
|
post_cvssync_commands();
|
114
|
exit();
|
115
|
} else {
|
116
|
$nobackup = true; // do not backup embedded, livecd
|
117
|
}
|
118
|
|
119
|
if($nobackup == false) {
|
120
|
echo "===> Backing up current pfSense information...\n";
|
121
|
echo "===> Please wait... ";
|
122
|
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 /");
|
123
|
$size = filesize("/root/cvssync_backup.tgz");
|
124
|
echo "{$size} bytes.\n\n";
|
125
|
sleep(5);
|
126
|
}
|
127
|
|
128
|
echo "===> Checking out $branch\n";
|
129
|
exec("mkdir -p /root/pfsense/$branch");
|
130
|
|
131
|
// Git 'er done!
|
132
|
if(is_dir("$CODIR/pfSenseGITREPO")) {
|
133
|
exec("cd $CODIR/pfSenseGITREPO && git fetch");
|
134
|
exec("cd $CODIR/pfSenseGITREPO && git merge $branch");
|
135
|
} else {
|
136
|
exec("mkdir -p $CODIR/pfSenseGITREPO");
|
137
|
echo "Executing cd $CODIR/pfSenseGITREPO && git clone $GIT_REPO pfSenseGITREPO\n";
|
138
|
exec("cd $CODIR/pfSenseGITREPO && git clone $GIT_REPO pfSenseGITREPO");
|
139
|
if(is_dir("$CODIR/pfSenseGITREPO/pfSense"))
|
140
|
exec("mv $CODIR/pfSenseGITREPO/pfSense $CODIR/pfSenseGITREPO/pfSenseGITREPO");
|
141
|
if(is_dir("$CODIR/pfSenseGITREPO/mainline"))
|
142
|
exec("mv $CODIR/pfSenseGITREPO/mainline $CODIR/pfSenseGITREPO/pfSenseGITREPO");
|
143
|
}
|
144
|
|
145
|
if($branch == "master") {
|
146
|
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && git checkout master");
|
147
|
} else {
|
148
|
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && git checkout -b $branch origin/$branch");
|
149
|
}
|
150
|
|
151
|
exec("mkdir -p /tmp/lighttpd/cache/compress/");
|
152
|
|
153
|
// Nuke CVS and pfSense tarballs
|
154
|
exec("cd ${CODIR}/pfSenseGITREPO/pfSenseGITREPO && find . -name CVS -exec rm -rf {} \; 2>/dev/null");
|
155
|
exec("cd ${CODIR}/pfSenseGITREPO/pfSenseGITREPO && find . -name pfSense.tgz -exec rm {} \; 2>/dev/null");
|
156
|
|
157
|
// Remove files that we do not want to overwrite the system with
|
158
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/usr/local/www/trigger_initial_wizard 2>/dev/null");
|
159
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/crontab 2>/dev/null");
|
160
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/master.passwd 2>/dev/null");
|
161
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/passwd 2>/dev/null");
|
162
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/fstab 2>/dev/null");
|
163
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/ttys 2>/dev/null");
|
164
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/group 2>/dev/null");
|
165
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/fstab 2>/dev/null");
|
166
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/platform 2>/dev/null");
|
167
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/boot/device.hints 2>/dev/null");
|
168
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/boot/loader.conf 2>/dev/null");
|
169
|
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/boot/loader.rc 2>/dev/null");
|
170
|
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/conf*");
|
171
|
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/cf 2>/dev/null");
|
172
|
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/root/.shrc");
|
173
|
exec("rm -rf ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/root/.tcshrc");
|
174
|
exec("rm -f ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/syslog.conf 2>/dev/null");
|
175
|
|
176
|
echo "===> Installing new files...\n";
|
177
|
|
178
|
if($g['platform'] == "pfSense")
|
179
|
$command = "cd $CODIR/pfSenseGITREPO/pfSenseGITREPO ; tar -cpf - . | (cd / ; tar -Uxpf -)";
|
180
|
else
|
181
|
$command = "cd $CODIR/pfSenseGITREPO/pfSenseGITREPO ; tar -cpf - . | (cd / ; tar -xpf -) 2>/dev/null";
|
182
|
exec($command);
|
183
|
|
184
|
post_cvssync_commands();
|
185
|
|
186
|
echo "===> Checkout complete.\n";
|
187
|
echo "\n";
|
188
|
echo "Your system is now sync'd and PHP and Lighty will be restarted in 5 seconds.\n\n";
|
189
|
|
190
|
function post_cvssync_commands() {
|
191
|
echo "===> Removing FAST-CGI temporary files...\n";
|
192
|
exec("find /tmp -name \"php-fastcgi.socket*\" -exec rm -rf {} \;");
|
193
|
exec("find /tmp -name \"*.tmp\" -exec rm -rf {} \;");
|
194
|
|
195
|
exec("rm -rf /tmp/xcache/* 2>/dev/null");
|
196
|
|
197
|
echo "===> Upgrading configuration (if needed)...\n";
|
198
|
convert_config();
|
199
|
|
200
|
echo "===> Restarting check_reload_status...\n";
|
201
|
exec("killall check_reload_status");
|
202
|
mwexec_bg("nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status");
|
203
|
|
204
|
echo "===> Configuring filter...";
|
205
|
exec("/etc/rc.filter_configure_sync");
|
206
|
exec("pfctl -f /tmp/rules.debug");
|
207
|
echo "\n";
|
208
|
|
209
|
echo "===> Signaling PHP and Lighty restart...";
|
210
|
$fd = fopen("/tmp/restart_lighty", "w");
|
211
|
fwrite($fd, "#!/bin/sh\n");
|
212
|
fwrite($fd, "sleep 5\n");
|
213
|
fwrite($fd, "killall php\n");
|
214
|
fwrite($fd, "touch /tmp/restart_webgui\n");
|
215
|
fclose($fd);
|
216
|
mwexec_bg("sh /tmp/restart_lighty");
|
217
|
echo "\n";
|
218
|
}
|
219
|
|
220
|
function isUrl($url = "") {
|
221
|
if($url)
|
222
|
if(strstr($url, "rcs.pfsense.org") or
|
223
|
strstr($url, "mainline") or
|
224
|
strstr($url, ".git"))
|
225
|
return true;
|
226
|
return false;
|
227
|
}
|
228
|
|
229
|
conf_mount_ro();
|