forked from perma-id/w3id.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.php
45 lines (38 loc) · 1.1 KB
/
git.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// open the token file
$tfile = fopen('remote-update-token.txt', 'r');
// Acquire the lock in a non-blocking manner
if($tfile == FALSE)
{
echo 'ERROR: You must create a file called remote-update-token.txt and ' .
'place a secret token in that file. See the README for more information.';
}
else if(flock($tfile, LOCK_EX | LOCK_NB))
{
$token = trim(fgets($tfile));
// check to make sure that the token value is correct
if(array_key_exists('token', $_GET) and $token === $_GET['token'])
{
// perform a git pull
chdir('..');
$gitdir = getcwd() . "/.git";
system("git --git-dir $gitdir pull");
echo 'git update successful';
// Sleep for 5 seconds to throttle the update rate to 12 per minute
sleep(5);
}
else
{
echo 'ERROR: Invalid secret token provided. ' .
'See the README for more information.';
}
// Release the lock file
flock($tfile, LOCK_UN); // release the lock
}
else
{
echo 'ERROR: An update is currently being performed, ' .
'this request has been rejected.';
}
fclose($tfile);
?>