ignore gitweb.git in scandir_replace function
[gitweb.git] / git_download.php
1 <?php
2 $args = explode(";", $_SERVER["QUERY_STRING"]);
3 foreach($args as $arg) {
4 $arg = explode("=", $arg, 2);
5 $_GET[$arg[0]] = $arg[1];
6 }
7
8 function scandir_replace($folder,$arg){
9 $out = array();
10 if($content = opendir($folder)){
11 while(false !== ($file = readdir($content))){
12 if(is_dir("$folder/$file") && $file != "." && $file != ".." && $file != ".git"){
13 scandir_replace("$folder/$file",$arg);
14 } elseif($file != "." && $file != ".." && $file != ".git"){
15 $out[] = "$folder/$file";
16 }
17 }
18 closedir($content);
19 }
20 foreach($out as $id => $v) {
21 chmod($v,0777);
22 $maincode=file_get_contents($v);
23 $maincode = str_replace('$__GIT__', '"'.$arg.'"', $maincode); // replace $__GIT__ with the git version
24 $fp = fopen($v, 'w');
25 fwrite($fp, $maincode);
26 fclose($fp);
27 }
28 }
29
30 if(isset($_GET['p'])){
31 if(file_exists("/home/git/".$_GET['p'])){
32 $hash = shell_exec("git --git-dir=/home/git/".$_GET["p"]." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
33 $con= shell_exec('git --git-dir=/home/git/'.$_GET["p"].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
34 if(!$hash){
35 echo "No Download available";
36 }else{
37 $name=substr($_GET["p"],0,strlen($_GET["p"])-4);
38 if(file_exists("/usr/share/gitweb/dl/".$name."-".substr($hash, 0, -1).".tar.gz")) {
39 echo "<a href='http://git.nexus-irc.de/dl/".$name."-".substr($hash, 0, -1).".tar.gz'>".$name."-".substr($hash, 0, -1)." (tar.gz)</a>";
40 } else {
41 echo "No Download available (<a href='http://git.nexus-irc.de/git_download.php?build=".$_GET["p"]."'>Build snapshot</a>)";
42 }
43 }
44 }else{
45 echo "unknown project";
46 }
47 }elseif(isset($_GET['git'])){
48 if(file_exists("/home/git/".$_GET['git'])){
49 $hash = shell_exec("git --git-dir=/home/git/".$_GET["git"]." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
50 $con= shell_exec('git --git-dir=/home/git/'.$_GET["git"].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
51 if(!$hash){
52 echo "<p>".$_GET["git"].": No Download available</p>";
53 }else{
54 $name=substr($_GET["git"],0,strlen($_GET["git"])-4);
55 if(file_exists("/usr/share/gitweb/dl/".$name."-".substr($hash, 0, -1).".tar.gz")) {
56 echo "<p><a href='http://git.nexus-irc.de/dl/".$name."-".substr($hash, 0, -1).".tar.gz'>".$name."-".substr($hash, 0, -1)." (tar.gz)</a></p>";
57 } else {
58 echo "<p>No Download available (<a href='http://git.nexus-irc.de/git_download.php?build=".$_GET["git"]."'>Build snapshot</a>)</p>";
59 }
60 }
61 }else{
62 echo "unknown project";
63 }
64 }elseif(isset($_GET['build'])){
65 if(file_exists("/home/git/".$_GET['build'])){
66 $hash = shell_exec("git --git-dir=/home/git/".$_GET['build']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
67 $con= shell_exec('git --git-dir=/home/git/'.$_GET['build'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
68 $name=substr($_GET['build'],0,strlen($_GET['build'])-4);
69 if(file_exists("/usr/share/gitweb/dl/".$name."-".substr($hash, 0, -1).".tar.gz")) {
70 echo '<meta http-equiv="refresh" content="0; URL='.$_SERVER['HTTP_REFERER'].'"> ';
71 }else{
72 $b = shell_exec("cd /usr/share/gitweb/dl; git clone git://git.nexus-irc.de/".$_GET['build']);
73 if($_GET['build'] != "gitweb.git") {
74 scandir_replace("/usr/share/gitweb/dl/".$name,"git-".substr($con, 0, -1)."-".substr($hash, 0, -1));
75 }
76 $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-".substr($hash, 0, -1).".tar.gz ".$name);
77 $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
78 echo '<meta http-equiv="refresh" content="0; URL='.$_SERVER['HTTP_REFERER'].'"> ';
79 }
80 }else{
81 echo "unknown project";
82 }
83 }elseif(isset($_GET['build2']) && isset($_GET['h'])){
84 if(file_exists("/home/git/".$_GET['build2'])){
85 $name=substr($_GET['build2'],0,strlen($_GET['build2'])-4);
86 if(strtolower($_GET['h']) == "head") {
87 $hash = substr(shell_exec("git --git-dir=/home/git/".$_GET['build2']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'"), 0, -1);
88 }else{
89 $hash = substr($_GET['h'], 0, 7);
90 }
91 if(file_exists("/usr/share/gitweb/dl/".$name."-".$hash.".tar.gz")) {
92 header("Content-Type: application/x-gzip");
93 header("Content-Disposition: attachment; filename=".$name."-".$hash.".tar.gz");
94 readfile("/usr/share/gitweb/dl/".$name."-".$hash.".tar.gz");
95 }else{
96 $b = shell_exec("cd /usr/share/gitweb/dl/; git clone git://git.nexus-irc.de/".$_GET['build2']);
97 $c = shell_exec("cd /usr/share/gitweb/dl/".$name."/; git reset ".$_GET['h']);
98 $con= shell_exec('git --git-dir=/home/git/'.$_GET['build2'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
99 if($_GET['build2'] != "gitweb.git") {
100 scandir_replace("/usr/share/gitweb/dl/".$name,"git-".substr($con, 0, -1)."-".$hash);
101 }
102 $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-".$hash.".tar.gz ".$name);
103 $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
104 header("Content-Type: application/x-gzip");
105 header("Content-Disposition: attachment; filename=".$name."-".$hash.".tar.gz");
106 readfile("/usr/share/gitweb/dl/".$name."-".$hash.".tar.gz");
107 }
108 }else{
109 echo "unknown project";
110 }
111 }else{
112 $a = file_get_contents("http://git.nexus-irc.de/index.cgi?a=project_index2");
113 $b = explode("\n",$a);
114 foreach($b as $id => $v) {
115 if($v == ""){ }else{
116 $hash = shell_exec("git --git-dir=/home/git/".$v." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
117 $con= shell_exec('git --git-dir=/home/git/'.$v.' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
118 if(!$hash){
119 echo "<p>".$v.": No Download available</p>";
120 }else{
121 $name=substr($v,0,strlen($v)-4);
122 if(file_exists("/usr/share/gitweb/dl/".$name."-".substr($hash, 0, -1).".tar.gz")) {
123 echo "<p>".$v.": Download <a href='http://git.nexus-irc.de/dl/".$name."-".substr($hash, 0, -1).".tar.gz'>".$name."-".substr($hash, 0, -1)." (tar.gz)</a></p>";
124 } else {
125 echo "<p>".$v.": No Download available (<a href='http://git.nexus-irc.de/git_download.php?build=".$v."'>Build snapshot</a>)</p>";
126 }
127 }
128 }
129 }
130 }
131 ?>