Changeset 346 in ProjectBuilder for devel/pb/bin
- Timestamp:
- Apr 2, 2008, 2:04:21 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb
r344 r346 202 202 203 203 Create a new virtual environment 204 205 =item B<setupvm> 206 207 Setup a virtual machine for pb usage 208 209 =item B<setupve> 210 211 Setup a virtual environment for pb usage 204 212 205 213 =item B<newver> … … 422 430 } elsif ($action =~ /^newvm$/) { 423 431 pb_launchv("vm",$ENV{'PBV'},1); 432 } elsif ($action =~ /^setupve$/) { 433 $pbaccount = "root"; 434 my $pbscript = pb_setup_v("ve"); 435 pb_script2v($pbscript,"ve"); 436 } elsif ($action =~ /^setupvm$/) { 437 $pbaccount = "root"; 438 my $pbscript = pb_setup_v("vm"); 439 pb_script2v($pbscript,"vm"); 424 440 } elsif ($action =~ /^newproj$/) { 425 441 # Nothing to do - already done in pb_env_init … … 1216 1232 } 1217 1233 1218 sub pb_setup_v {1219 1234 # Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo 1220 1235 # Needs to use root account to connect to the VM/VE 1221 1222 1236 # pb will take your local public SSH key to access 1223 # the pb account in the VM later on 1237 # the pb account in the VM later on if needed 1238 sub pb_setup_v { 1224 1239 1225 1240 my $vtype = shift; 1226 1241 1227 my $file = "$ENV{'HOME'}/.ssh/id_dsa.pub"; 1228 die "Unable to find your public ssh key as $file"; 1229 1230 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript"; 1242 # Script generated 1243 my $pbscript = "$ENV{'PBDESTDIR'}/setupv"; 1244 1245 # Name of the account to deal with for VM/VE 1246 my $pbaccount = pb_conf_get($vtype."login"); 1247 1248 # Prepare the script to be executed on the VM/VE 1249 # in $ENV{'PBDESTDIR'}/setupv 1250 1251 # Check the SSH environment 1252 my $file = undef; 1253 $file = "$ENV{'HOME'}/.ssh/id_rsa.pub" if (-s "$ENV{'HOME'}/.ssh/id_rsa.pub"); 1254 $file = "$ENV{'HOME'}/.ssh/id_dsa.pub" if (-s "$ENV{'HOME'}/.ssh/id_dsa.pub"); 1255 die "Unable to find your public ssh key under $file" if (not defined $file); 1256 1257 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript"; 1231 1258 print SCRIPT << 'EOF'; 1232 1259 #!/usr/bin/perl -w 1233 1260 1234 $file="/etc/passwd"; 1261 use strict; 1262 use File::Copy; 1263 1264 my $file="/etc/passwd"; 1235 1265 open(PBFILE,$file) || die "Unable to open $file"; 1236 1266 my $found = 0; 1237 1267 while (<PBFILE>) { 1238 $found = 1 if (/^pb:/); 1268 EOF 1269 print SCRIPT << "EOF" 1270 \$found = 1 if (/^$pbaccount:/); 1271 EOF 1272 print SCRIPT << 'EOF'; 1239 1273 } 1240 1274 close(PBFILE); … … 1244 1278 mkdir "/home"; 1245 1279 } 1246 system "groupadd pb"; 1247 system "useradd pb -g pb -m -d /home/pb"; 1280 EOF 1281 print SCRIPT << "EOF" 1282 system "groupadd $pbaccount"; 1283 system "useradd $pbaccount -g $pbaccount -m -d /home/$pbaccount"; 1284 1285 # For pb 1286 chdir "/home/$pbaccount"; 1287 mkdir ".ssh",0700; 1288 copy("/tmp/pbkey",".ssh/authorized_keys"); 1289 chmod 0600,".ssh/authorized_keys"; 1290 system 'chown -R $pbaccount:$pbaccount .ssh'; 1291 1292 EOF 1293 print SCRIPT << 'EOF'; 1248 1294 } 1249 1295 1250 1296 # For root 1251 1297 mkdir ".ssh",0700; 1252 system 'cp /tmp/pbkey .ssh/authorized_keys';1298 copy("/tmp/pbkey",".ssh/authorized_keys"); 1253 1299 chmod 0600,".ssh/authorized_keys"; 1254 1255 # For pb1256 chdir "/home/pb";1257 mkdir ".ssh",0700;1258 system 'cp /tmp/pbkey .ssh/authorized_keys';1259 chmod 0600,".ssh/authorized_keys";1260 system 'chown -R pb:pb .ssh';1261 1300 1262 1301 # No passwd for pb only keys … … 1265 1304 open(PBOUT,"> $file.new") || die "Unable to open $file.new"; 1266 1305 while (<PBFILE>) { 1267 s/^pb:\!\!:/pb:*:/; 1268 s/^pb:\!:/pb:*:/; #SLES 9 e.g. 1306 EOF 1307 print SCRIPT << "EOF" 1308 s/^$pbaccount:\!\!:/$pbaccount:*:/; 1309 s/^$pbaccount:\!:/$pbaccount:*:/; #SLES 9 e.g. 1310 EOF 1311 print SCRIPT << 'EOF' 1269 1312 print PBOUT $_; 1270 1313 } … … 1277 1320 unlink "/tmp/pbkey"; 1278 1321 1322 # Adapt sudoers 1323 $file="/etc/sudoers"; 1324 open(PBFILE,$file) || die "Unable to open $file"; 1325 open(PBOUT,"> $file.new") || die "Unable to open $file.new"; 1326 while (<PBFILE>) { 1327 EOF 1328 print SCRIPT << "EOF" 1329 next if (/^$pbaccount /); 1330 EOF 1331 print SCRIPT << 'EOF' 1332 s/Defaults[ \t]+requiretty//; 1333 print PBOUT $_; 1334 } 1335 close(PBFILE); 1336 EOF 1337 print SCRIPT << "EOF" 1338 # This is needed in order to be able to halt the machine from the $pbaccount account at least 1339 print PBOUT "$pbaccount ALL=(ALL) NOPASSWD:ALL\n"; 1340 EOF 1341 print SCRIPT << 'EOF' 1342 close(PBOUT); 1343 rename("$file.new",$file); 1344 chmod 0440,$file; 1345 1346 EOF 1347 1348 pb_install_pkg_deps(SCRIPT); 1349 1350 print SCRIPT << 'EOF'; 1351 # Suse wants sudoers as 640 1352 if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) { 1353 chmod 0640,$file; 1354 } 1355 1356 # Sync date 1357 system "/usr/sbin/ntpdate ntp.pool.org"; 1358 1359 system "rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; tar xvfz project-builder-latest.tar.gz ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .."; 1360 EOF 1361 close(SCRIPT); 1362 chmod 0755,"$pbscript"; 1363 return($pbscript); 1364 } 1365 1366 pb_install_pkg_deps { 1367 1368 my \*SCRIPT = shift; 1369 1370 print SCRIPT << 'EOF'; 1371 # We need to have that pb_distro_init function 1279 1372 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); 1280 1373 print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n"; … … 1283 1376 if ( $ddir eq "fedora" ) { 1284 1377 system "yum clean all"; 1285 system "yum update -y";1378 #system "yum update -y"; 1286 1379 my $arch=`uname -m`; 1287 1380 my $opt = ""; … … 1303 1396 } elsif ( $dfam eq "du" ) { 1304 1397 if (( $dver eq "3.1" ) && ($ddir eq "debian")) { 1305 system "apt-get update; apt-get -y install wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libdate-manip-perl"; 1398 #system "apt-get update"; 1399 system "apt-get -y install wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libdate-manip-perl"; 1306 1400 } else { 1307 1401 system "apt-get update; apt-get -y install wget patch openssh-server dpkg-dev sudo debian-builder dh-make fakeroot ntpdate rses5-dev libdate-manip-perl"; … … 1312 1406 print "No pkg to install\n"; 1313 1407 } 1314 1315 # Adapt sudoers1316 $file="/etc/sudoers";1317 open(PBFILE,$file) || die "Unable to open $file";1318 open(PBOUT,"> $file.new") || die "Unable to open $file.new";1319 while (<PBFILE>) {1320 next if (/^pb /);1321 s/Defaults[ \t]+requiretty//;1322 print PBOUT $_;1323 }1324 close(PBFILE);1325 print PBOUT "pb ALL=(ALL) NOPASSWD:ALL\n";1326 close(PBOUT);1327 rename("$file.new",$file);1328 chmod 0440,$file;1329 1330 # Suse wants sudoers as 6401331 if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {1332 chmod 0640,$file;1333 }1334 1335 # Sync date1336 system "/usr/sbin/ntpdate ntp.pool.org";1337 1338 system "rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; tar xvfz project-builder-latest.tar.gz ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd ..";1339 1408 EOF 1340 close(SCRIPT);1341 1409 } 1342 1410
Note:
See TracChangeset
for help on using the changeset viewer.