Changeset 67614 in vbox
- Timestamp:
- Jun 26, 2017 5:00:42 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r67227 r67614 1022 1022 1023 1023 if (fCategory & USAGE_UNATTENDEDINSTALL) 1024 {1025 1024 RTStrmPrintf(pStrm, 1026 1025 "%s unattended %s <uuid|vmname>\n" 1027 " usefile --file <file>\n" 1028 " usedata\n" 1029 " --user <username>\n" 1026 " --settings-file <file>\n" 1027 " [--session-type <type>]\n" 1028 "%s unattended %s <uuid|vmname>\n" 1029 " --user <user>\n" 1030 1030 " --password <password>\n" 1031 " -- key <key>\n"1032 " --isopath <OS ISO path>\n"1033 " [--addi sopath <additions ISOpath>]\n"1034 " [--image index <number>]\n"1035 " \n", SEP);1036 }1031 " --iso-path <path>\n" 1032 " [--key <CD-key>]\n" 1033 " [--additions-iso-path <path>]\n" 1034 " [--image-index <index>]\n" 1035 " [--session-type <type>]\n" 1036 "\n", SEP, SEP); 1037 1037 1038 1038 if (fCategory & USAGE_DISCARDSTATE) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r66297 r67614 1267 1267 } 1268 1268 1269 static const RTGETOPTDEF g_aUnattendedInstallOptions[] =1270 {1271 { "--user", 'u', RTGETOPT_REQ_STRING },1272 { "-user", 'u', RTGETOPT_REQ_STRING },1273 { "--password", 'p', RTGETOPT_REQ_STRING },1274 { "-password", 'p', RTGETOPT_REQ_STRING },1275 { "--key", 'k', RTGETOPT_REQ_STRING },1276 { "-key", 'k', RTGETOPT_REQ_STRING },1277 { "--isopath", 'i', RTGETOPT_REQ_STRING },1278 { "-isopath", 'i', RTGETOPT_REQ_STRING },1279 { "--addisopath", 'a', RTGETOPT_REQ_STRING },1280 { "-addisopath", 'a', RTGETOPT_REQ_STRING },1281 { "-imageindex", 'm', RTGETOPT_REQ_UINT16 },1282 { "--imageindex", 'm', RTGETOPT_REQ_UINT16 },1283 { "-settingfile", 's', RTGETOPT_REQ_STRING },1284 { "--settingfile", 's', RTGETOPT_REQ_STRING },1285 };1286 1287 1269 RTEXITCODE handleUnattendedInstall(HandlerArg *a) 1288 1270 { 1289 HRESULT rc; 1271 /* 1272 * Options. 1273 */ 1290 1274 Bstr vboxAdditionsIsoPath; 1291 1275 Bstr isoPath; … … 1294 1278 Bstr productKey; 1295 1279 Bstr group("group"); 1296 Bstr uuid = Guid(a->argv[0]).toUtf16().raw();1297 1280 Bstr machineName; 1298 BOOL bInstallGuestAdditions;1281 BOOL fInstallGuestAdditions; 1299 1282 Bstr fileWithSettings; 1300 unsigned short imageIndex = 1;//applied only to Windows installation 1283 unsigned short imageIndex = 1; // applied only to Windows installation 1284 int cSpecificOptions = 0; 1285 Bstr sessionType = "headless"; 1286 1287 /* 1288 * Parse options. 1289 */ 1290 if (a->argc <= 1) 1291 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing VM name/UUID."); 1292 1293 static const RTGETOPTDEF s_aOptions[] = 1294 { 1295 { "--user", 'u', RTGETOPT_REQ_STRING }, 1296 { "--password", 'p', RTGETOPT_REQ_STRING }, 1297 { "--key", 'k', RTGETOPT_REQ_STRING }, 1298 { "--iso-path", 'i', RTGETOPT_REQ_STRING }, 1299 { "--additions-iso-path", 'a', RTGETOPT_REQ_STRING }, 1300 { "--image-index", 'm', RTGETOPT_REQ_UINT16 }, 1301 { "--settings-file", 's', RTGETOPT_REQ_STRING }, 1302 { "--session-type", 'S', RTGETOPT_REQ_STRING }, 1303 }; 1304 1305 RTGETOPTSTATE GetState; 1306 int vrc = RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1307 AssertRCReturn(vrc, RTEXITCODE_FAILURE); 1301 1308 1302 1309 int c; 1303 1310 RTGETOPTUNION ValueUnion; 1304 RTGETOPTSTATE GetState; 1305 1306 // start at 2(third) argument because 0(first) is <uuid\vmname>, 1(second) is <usedata\usefile> 1307 RTGetOptInit(&GetState, a->argc, a->argv, g_aUnattendedInstallOptions, RT_ELEMENTS(g_aUnattendedInstallOptions), 1308 2, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 1309 1310 if (!strcmp(a->argv[1], "usefile")) 1311 { 1312 while ((c = RTGetOpt(&GetState, &ValueUnion))) 1313 { 1314 switch (c) 1315 { 1316 case 's': // --a file with data prepared by user 1317 fileWithSettings = ValueUnion.psz; 1318 break; 1319 default: 1320 return errorGetOpt(USAGE_UNATTENDEDINSTALL, c, &ValueUnion); 1321 } 1322 } 1323 1324 /* check for required options */ 1325 if (fileWithSettings.isEmpty()) 1326 return errorSyntax(USAGE_UNATTENDEDINSTALL, "One of needed parameters has been missed"); 1327 } 1328 else if(!strcmp(a->argv[1], "usedata")) 1329 { 1330 while ((c = RTGetOpt(&GetState, &ValueUnion))) 1331 { 1332 switch (c) 1333 { 1334 case 'u': // --user 1335 user = ValueUnion.psz; 1336 break; 1337 1338 case 'p': // --password 1339 password = ValueUnion.psz; 1340 break; 1341 1342 case 'k': // --key 1343 productKey = ValueUnion.psz; 1344 break; 1345 1346 case 'a': // --addisopath 1347 vboxAdditionsIsoPath = ValueUnion.psz; 1348 break; 1349 1350 case 'i': // --isopath 1351 isoPath = ValueUnion.psz; 1352 break; 1353 case 'm': // --image index 1354 imageIndex = ValueUnion.u8; 1355 break; 1356 default: 1357 return errorGetOpt(USAGE_UNATTENDEDINSTALL, c, &ValueUnion); 1358 } 1359 } 1360 1361 /* check for required options */ 1362 if (user.isEmpty() || password.isEmpty() || isoPath.isEmpty()) 1363 return errorSyntax(USAGE_UNATTENDEDINSTALL, "One of needed parameters has been missed"); 1364 } 1365 else 1366 { 1367 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Unknown subcommand. Must be \"usefile\" or \"usedata\" "); 1368 } 1311 while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0) 1312 { 1313 switch (c) 1314 { 1315 case VINF_GETOPT_NOT_OPTION: 1316 if (machineName.isNotEmpty()) 1317 return errorSyntax(USAGE_UNATTENDEDINSTALL, "VM name/UUID given more than once!"); 1318 machineName = ValueUnion.psz; 1319 if (machineName.isEmpty()) 1320 return errorSyntax(USAGE_UNATTENDEDINSTALL, "VM name/UUID is empty!"); 1321 break; 1322 1323 case 's': // --settings-file <a file with data prepared by user> 1324 if (cSpecificOptions > 0) 1325 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--settings-file cannot be mixed with the other options"); 1326 fileWithSettings = ValueUnion.psz; 1327 cSpecificOptions = -1; 1328 break; 1329 1330 case 'u': // --user 1331 if (cSpecificOptions < 0) 1332 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--user cannot be mixed with --settings-file"); 1333 user = ValueUnion.psz; 1334 cSpecificOptions++; 1335 break; 1336 1337 case 'p': // --password 1338 if (cSpecificOptions < 0) 1339 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--password cannot be mixed with --settings-file"); 1340 password = ValueUnion.psz; 1341 cSpecificOptions++; 1342 break; 1343 1344 case 'k': // --key 1345 if (cSpecificOptions < 0) 1346 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--key cannot be mixed with --settings-file"); 1347 productKey = ValueUnion.psz; 1348 cSpecificOptions++; 1349 break; 1350 1351 case 'a': // --additions-iso-path 1352 if (cSpecificOptions < 0) 1353 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--additions-iso-path cannot be mixed with --settings-file"); 1354 vboxAdditionsIsoPath = ValueUnion.psz; 1355 cSpecificOptions++; 1356 break; 1357 1358 case 'i': // --iso-path 1359 if (cSpecificOptions < 0) 1360 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--iso-path cannot be mixed with --settings-file"); 1361 isoPath = ValueUnion.psz; 1362 cSpecificOptions++; 1363 break; 1364 1365 case 'm': // --image-index 1366 if (cSpecificOptions < 0) 1367 return errorSyntax(USAGE_UNATTENDEDINSTALL, "--image-index cannot be mixed with --settings-file"); 1368 imageIndex = ValueUnion.u16; 1369 cSpecificOptions++; 1370 break; 1371 1372 case 'S': // --sesion-type 1373 sessionType = ValueUnion.psz; 1374 break; 1375 1376 default: 1377 return errorGetOpt(USAGE_UNATTENDEDINSTALL, c, &ValueUnion); 1378 } 1379 } 1380 1381 /* 1382 * Check for required stuff. 1383 */ 1384 if (machineName.isEmpty()) 1385 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing VM name/UUID"); 1386 1387 if (cSpecificOptions > 0) 1388 { 1389 if (user.isEmpty()) 1390 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --user option"); 1391 if (password.isEmpty()) 1392 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --password option"); 1393 if (isoPath.isEmpty()) 1394 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --iso-path option"); 1395 } 1396 else if (fileWithSettings.isEmpty()) 1397 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Requires either --file or --user & --password & --iso-path"); 1398 1399 /* 1400 * Prepare. 1401 */ 1369 1402 1370 1403 /* try to find the given machine */ 1404 HRESULT rc; 1371 1405 ComPtr<IMachine> machine; 1372 CHECK_ERROR(a->virtualBox, FindMachine( Bstr(a->argv[0]).raw(), machine.asOutParam()));1406 CHECK_ERROR(a->virtualBox, FindMachine(machineName.raw(), machine.asOutParam())); 1373 1407 if (FAILED(rc)) 1374 1408 return RTEXITCODE_FAILURE; 1375 1409 1376 1410 CHECK_ERROR_RET(machine, COMGETTER(Name)(machineName.asOutParam()), RTEXITCODE_FAILURE); 1411 Bstr bstrUuid; 1412 CHECK_ERROR_RET(machine, COMGETTER(Id)(bstrUuid.asOutParam()), RTEXITCODE_FAILURE); 1377 1413 /* open a session for the VM */ 1378 1414 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE); 1379 1415 1416 /* get the associated console */ 1380 1417 ComPtr<IConsole> console; 1381 ComPtr<IMachine> sessionMachine;1382 ComPtr<IUnattended> unAttended;1383 1384 /* get the associated console */1385 1418 CHECK_ERROR(a->session, COMGETTER(Console)(console.asOutParam())); 1386 1419 if (console) 1387 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '% s' is currently running", Utf8Str(uuid).c_str());1420 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '%ls' is currently running", machineName.raw()); 1388 1421 1389 1422 /* ... and session machine */ 1423 ComPtr<IMachine> sessionMachine; 1390 1424 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE); 1391 1425 1392 BSTR installedOSBSTR;1393 1394 CHECK_ERROR_RET(sessionMachine, COMGETTER(OSTypeId)(& installedOSBSTR), RTEXITCODE_FAILURE);1395 1396 Utf8Str installedOSStr(installedOSBSTR); 1397 1398 do{1426 /* Get the OS type name of the VM. */ 1427 BSTR bstrInstalledOS; 1428 CHECK_ERROR_RET(sessionMachine, COMGETTER(OSTypeId)(&bstrInstalledOS), RTEXITCODE_FAILURE); 1429 Utf8Str strInstalledOS(bstrInstalledOS); 1430 1431 do 1432 { 1399 1433 RTPrintf("Start unattended installation OS %s on virtual machine '%ls'.\n" 1400 1434 "UUID: %s\n", 1401 installedOSStr.c_str(),1435 strInstalledOS.c_str(), 1402 1436 machineName.raw(), 1403 Utf8Str(uuid).c_str()); 1404 1437 Utf8Str(bstrUuid).c_str()); 1438 1439 /* 1440 * Instantiate and configure the unattended installer. 1441 */ 1442 ComPtr<IUnattended> unAttended; 1405 1443 CHECK_ERROR_BREAK(machine, COMGETTER(Unattended)(unAttended.asOutParam())); 1406 1444 … … 1409 1447 CHECK_ERROR_BREAK(unAttended, COMSETTER(Group)(group.raw())); 1410 1448 1411 if (installedOSStr.contains("Windows") && productKey.isEmpty()) 1412 { 1413 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Product key has been missed."); 1414 } 1449 if (strInstalledOS.contains("Windows") && productKey.isEmpty()) 1450 return errorSyntax(USAGE_UNATTENDEDINSTALL, "A product key is required (--key)."); 1415 1451 1416 1452 CHECK_ERROR_BREAK(unAttended, COMSETTER(VboxAdditionsIsoPath)(vboxAdditionsIsoPath.raw())); … … 1424 1460 CHECK_ERROR_BREAK(unAttended, COMSETTER(ProductKey)(productKey.raw())); 1425 1461 1426 bool fInstallGuestAdditions = (vboxAdditionsIsoPath.isEmpty()) ? false: true;1462 bool fInstallGuestAdditions = vboxAdditionsIsoPath.isNotEmpty(); 1427 1463 CHECK_ERROR_BREAK(unAttended, COMSETTER(InstallGuestAdditions)(fInstallGuestAdditions)); 1428 1464 … … 1431 1467 CHECK_ERROR_BREAK(unAttended,ConstructScript()); 1432 1468 CHECK_ERROR_BREAK(unAttended,ConstructMedia()); 1433 CHECK_ERROR_BREAK(unAttended,ReconstructVM());1434 CHECK_ERROR_BREAK(unAttended,RunInstallation());1435 1436 1469 } 1437 1470 else … … 1439 1472 CHECK_ERROR_BREAK(unAttended, COMSETTER(FileWithPreparedData)(fileWithSettings.raw())); 1440 1473 CHECK_ERROR_BREAK(unAttended,Preparation()); 1441 CHECK_ERROR_BREAK(unAttended,ReconstructVM()); 1442 CHECK_ERROR_BREAK(unAttended,RunInstallation()); 1443 } 1444 1474 } 1475 CHECK_ERROR_BREAK(unAttended,ReconstructVM()); 1476 CHECK_ERROR_BREAK(unAttended,RunInstallation()); 1477 1478 1479 /* 1480 * Start the VM. 1481 */ 1445 1482 a->session->UnlockMachine(); 1446 1483 1447 1484 { 1448 1485 Bstr env; 1449 Bstr sessionType = "headless";//"gui";1450 1486 1451 1487 #if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) … … 1461 1497 #endif 1462 1498 ComPtr<IProgress> progress; 1463 CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(), 1464 env.raw(), progress.asOutParam())); 1499 CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())); 1465 1500 if (SUCCEEDED(rc) && !progress.isNull()) 1466 1501 { 1467 RTPrintf("Waiting for VM \"%s\" to power on...\n", Utf8Str( uuid).c_str());1502 RTPrintf("Waiting for VM \"%s\" to power on...\n", Utf8Str(bstrUuid).c_str()); 1468 1503 CHECK_ERROR(progress, WaitForCompletion(-1)); 1469 1504 if (SUCCEEDED(rc)) 1470 1505 { 1471 BOOL completed = true;1472 CHECK_ERROR(progress, COMGETTER(Completed)(& completed));1506 BOOL fCompleted = true; 1507 CHECK_ERROR(progress, COMGETTER(Completed)(&fCompleted)); 1473 1508 if (SUCCEEDED(rc)) 1474 1509 { 1475 ASSERT( completed);1510 ASSERT(fCompleted); 1476 1511 1477 1512 LONG iRc; … … 1480 1515 { 1481 1516 if (SUCCEEDED(iRc)) 1482 RTPrintf("VM \"%s\" has been successfully started.\n", Utf8Str( uuid).c_str());1517 RTPrintf("VM \"%s\" has been successfully started.\n", Utf8Str(bstrUuid).c_str()); 1483 1518 else 1484 1519 { … … 1493 1528 } 1494 1529 1495 vboxAdditionsIsoPath.setNull(); 1496 isoPath.setNull(); 1497 user.setNull(); 1498 password.setNull(); 1499 productKey.setNull(); 1500 group.setNull(); 1501 bInstallGuestAdditions = false; 1502 imageIndex = 0; 1503 fileWithSettings.setNull(); 1504 1530 /* 1531 * Retrieve and display the parameters actually used. 1532 */ 1505 1533 CHECK_ERROR_BREAK(unAttended, COMGETTER(FileWithPreparedData)(fileWithSettings.asOutParam())); 1506 1534 CHECK_ERROR_BREAK(unAttended, COMGETTER(Group)(group.asOutParam())); 1507 1535 CHECK_ERROR_BREAK(unAttended, COMGETTER(VboxAdditionsIsoPath)(vboxAdditionsIsoPath.asOutParam())); 1536 fInstallGuestAdditions = false; 1537 CHECK_ERROR_BREAK(unAttended, COMGETTER(InstallGuestAdditions)(&fInstallGuestAdditions)); 1508 1538 CHECK_ERROR_BREAK(unAttended, COMGETTER(IsoPath)(isoPath.asOutParam())); 1509 1539 CHECK_ERROR_BREAK(unAttended, COMGETTER(User)(user.asOutParam())); 1510 1540 CHECK_ERROR_BREAK(unAttended, COMGETTER(Password)(password.asOutParam())); 1511 1541 CHECK_ERROR_BREAK(unAttended, COMGETTER(ProductKey)(productKey.asOutParam())); 1542 imageIndex = 0; 1512 1543 CHECK_ERROR_BREAK(unAttended, COMGETTER(ImageIndex)(&imageIndex)); 1513 RTPrintf("Got values:\n fileWithSettings: %s\n user: %s\n password: %s\n productKey: %s\n image index: %d\n " 1514 "isoPath: %s\n vboxAdditionsIsoPath: %s\n", 1544 RTPrintf("Got values:\n" 1545 " fileWithSettings: %s\n " 1546 " user: %s\n" 1547 " password: %s\n" 1548 " productKey: %s\n" 1549 " image index: %u\n" 1550 " isoPath: %s\n" 1551 " vboxAdditionsIsoPath: %s\n" 1552 " installGuestAdditions: %RTbool", 1515 1553 Utf8Str(fileWithSettings).c_str(), 1516 1554 Utf8Str(user).c_str(), … … 1519 1557 imageIndex, 1520 1558 Utf8Str(isoPath).c_str(), 1521 Utf8Str(vboxAdditionsIsoPath).c_str() 1522 ); 1523 } 1524 while (0); 1559 Utf8Str(vboxAdditionsIsoPath).c_str(), 1560 fInstallGuestAdditions); 1561 } while (0); 1525 1562 1526 1563 RTPrintf("Unattended installation OS %s has been running on virtual machine '%ls'.\n" 1527 "UUID: % s\n",1528 installedOSStr.c_str(),1564 "UUID: %ls\n", 1565 strInstalledOS.c_str(), 1529 1566 machineName.raw(), 1530 Utf8Str(uuid).c_str());1567 bstrUuid.raw()); 1531 1568 1532 1569 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
Note:
See TracChangeset
for help on using the changeset viewer.