rewritten for
[nodeconfig.git] / PlanetLabConf / yum.conf.php
1 <?php
2 //
3 // /etc/yum.conf for production nodes
4 //
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2004-2006 The Trustees of Princeton University
7 //
8 // $Id$
9 //
10
11 // For PLC_NAME and PLC_BOOT_HOST
12 include('plc_config.php');
13
14 $PLC_NAME = PLC_NAME;
15 $PLC_BOOT_HOST = PLC_BOOT_HOST;
16
17 ////////////////////////////// mirror list
18
19 // Requesting a mirror list. Yum bombs out completely if a repository
20 // is (even temporarily) unavailable, so if CoBlitz is down, provide a
21 // few more options. Make sure that gpgcheck remains enabled.  Last
22 // chance option is ourselves so that yum never fails.
23 if (isset($_REQUEST['mirrorlist']) &&
24     isset($_REQUEST['repo']) &&
25     isset($_REQUEST['releasever'])) {
26   $mirrors = array("http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora/linux",
27                    "http://fedora.gtlib.cc.gatech.edu/pub/fedora.redhat/linux",
28                    "http://download.fedoraproject.org/pub/fedora/linux",
29                    "http://mirrors.kernel.org/fedora");
30                    #"ftp://rpmfind.net/linux/fedora",  still uses the old style of directory hierarchy
31   $releasever = $_REQUEST['releasever'];
32   switch ($_REQUEST['repo']) {
33   case "base":
34         if ( intval($releasever) >= 7 )
35         {
36                 foreach ($mirrors as $mirror) {
37                   echo "$mirror/releases/$releasever/Everything/\$ARCH/os/\n";
38                 }
39
40         } else {
41                 foreach ($mirrors as $mirror) {
42                   echo "$mirror/core/$releasever/\$ARCH/os/\n";
43                 }
44         }
45     break;
46   case "updates":
47         if ( intval($releasever) >= 7 )
48         {
49                 foreach ($mirrors as $mirror) {
50                   echo "$mirror/updates/$releasever/\$ARCH/\n";
51                 }
52
53         } else {
54                 foreach ($mirrors as $mirror) {
55                   echo "$mirror/core/updates/$releasever/\$ARCH/\n";
56                 }
57         }
58     break;
59   }
60
61   // Always list ourselves last
62   echo "https://$PLC_BOOT_HOST/install-rpms/planetlab/\n";
63   exit;
64 }
65
66 ////////////////////////////// plain yum.conf 
67
68 // Get admin API handle
69 require_once 'plc_api.php';
70 global $adm;
71
72 // Requesting yum.conf. See above for the mirrorlist definition.
73
74 if (isset($_REQUEST['gpgcheck'])) {
75   $gpgcheck = $_REQUEST['gpgcheck'];
76 } else {
77   $gpgcheck = 0;
78 }
79
80 // fedora stock : base & updates 
81
82 echo <<<__STD_REPOS__
83 [main]
84 # Do not scan /etc/yum.repos.d/
85 reposdir=/dev/null
86 cachedir=/var/cache/yum
87 debuglevel=2
88 logfile=/var/log/yum.log
89 pkgpolicy=newest
90 gpgcheck=$gpgcheck
91
92 [base]
93 name=Fedora Core \$releasever - \$basearch - Base
94 mirrorlist=https://$PLC_BOOT_HOST/PlanetLabConf/yum.conf.php?mirrorlist&repo=base&releasever=\$releasever
95 gpgcheck=$gpgcheck
96 # PlanetLab builds its own versions of these tools
97 exclude=kernel* iptables iproute
98
99 [updates]
100 name=Fedora Core \$releasever - \$basearch - Released Updates
101 mirrorlist=https://$PLC_BOOT_HOST/PlanetLabConf/yum.conf.php?mirrorlist&repo=updates&releasever=\$releasever
102 gpgcheck=$gpgcheck
103 # PlanetLab builds its own versions of these tools
104 exclude=kernel* iptables iproute
105
106 __STD_REPOS__;
107
108 echo "\n";
109
110 # get node family
111 if ( ! isset($_REQUEST['slicefamily'])) {
112   # legacy : use the old naming scheme
113   $nodefamily="planetlab";
114   $pldistro="planetlab";
115  } else {
116   $slicefamily = $_REQUEST['slicefamily'];
117   echo "# slicefamily $slicefamily \n" ;
118   list( $pldistro, $fcdistro, $arch) = split ("-", $slicefamily);
119   $nodefamily = "$pldistro-$arch";
120   echo "# nodefamily $nodefamily \n" ;
121  }
122
123 # the nodegroups the node is part of
124 $nodegroup_names=array();
125
126 if ( ! isset($_REQUEST['node_id'])) {
127   print "# Warning : node_id not set\n";
128  } else {
129   $node_id=intval($_REQUEST['node_id']);
130   echo "# node_id $node_id \n";
131   # compute nodegroups
132   $nodes = $adm->GetNodes(array('node_id'=>$node_id));
133   $nodegroup_ids = $nodes[0]['nodegroup_ids'];
134   $nodegroups = $adm->GetNodeGroups($nodegroup_ids);
135   foreach ($nodegroups as $nodegroup) {
136     $nodegroup_name = $nodegroup['name'];
137     $nodegroup_names [] = $nodegroup_name;
138     echo "# in nodegroup $nodegroup_name \n" ;
139   }
140  }
141
142 $topdir=$_SERVER['DOCUMENT_ROOT'] . "/install-rpms/";
143 $topurl="https://$PLC_BOOT_HOST" . "/install-rpms/";
144
145
146 # locate the planetlab repo for this node family & nodegroup
147 $repo=NULL;
148 foreach ($nodegroup_names as $nodegroup_name) {
149   $groupdir = "$nodefamily-$nodegroup_name";
150   # have we got a repo like /install-rpms/planetlab-i386-alpha ?
151   echo "# trying " . $topdir . $groupdir . "\n";
152   if (is_dir (realpath($topdir . $groupdir))) {
153     $repo=array($pldistro, $groupdir, "$PLC_NAME $nodefamily $nodegroup_name");
154     break;
155   }
156 }
157
158 # if not found yet
159 if ( ! $repo) {
160   echo "# trying default " . $topdir . $nodefamily . "\n";
161   if (is_dir (realpath($topdir . $nodefamily))) {
162     $repo = array($pldistro, $nodefamily, "$PLC_NAME $nodefamily regular");
163   }
164  }
165
166 # default: if we're here it's probably very wrong
167 if ( ! $repo) {
168   echo "# WARNING: could not find a decent planetlab repo for this node\n";
169   $repo = array ($pldistro, "planetlab", "default probably wrong");
170  }
171
172 list( $id, $dir, $name) = $repo;
173
174 echo <<< __PLC_REPO__
175 [$id]
176 name=$name
177 baseurl=$topurl/$dir
178 gpgcheck=$gpgcheck
179 __PLC_REPO__;
180
181 #################### I guess this might go to trash, but just in case:
182 # mention if exist: install-rpms/planetlab-i386-3rdparty 
183 $optional_repos = array (array ('ThirdParty', '3rdparty','Third Party RPMS'));
184
185 foreach ($optional_repos as $repo) {
186   list( $id, $dir, $name) = $repo;
187   if (is_dir (realpath($topdir . $dir))) {
188     echo <<< __OPT_REPO__
189 [$id]
190 name=$name
191 baseurl=$topurl/$dir
192 gpgcheck=$gpgcheck
193 __OPT_REPO__;
194
195   }
196 }
197
198 ?>