Changeset 64997 in vbox
- Timestamp:
- Dec 22, 2016 7:41:39 AM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r60865 r64997 120 120 { "startvm", USAGE_STARTVM, VBMG_CMD_TODO, handleStartVM, 0 }, 121 121 { "controlvm", USAGE_CONTROLVM, VBMG_CMD_TODO, handleControlVM, 0 }, 122 { "unattended", USAGE_UNATTENDEDINSTALL,VBMG_CMD_TODO, handleUnattendedInstall, 0 }, 122 123 { "discardstate", USAGE_DISCARDSTATE, VBMG_CMD_TODO, handleDiscardState, 0 }, 123 124 { "adoptstate", USAGE_ADOPTSTATE, VBMG_CMD_TODO, handleAdoptState, 0 }, -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r62493 r64997 134 134 #endif 135 135 136 #define USAGE_UNATTENDEDINSTALL RT_BIT(27) 137 136 138 typedef uint64_t USAGECATEGORY; 137 139 … … 214 216 /* VBoxManageControlVM.cpp */ 215 217 RTEXITCODE handleControlVM(HandlerArg *a); 218 RTEXITCODE handleUnattendedInstall(HandlerArg *a); 216 219 #ifndef VBOX_ONLY_DOCS 217 220 unsigned int getMaxNics(IVirtualBox* vbox, IMachine* mach); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r64906 r64997 1021 1021 } 1022 1022 1023 if (fCategory & USAGE_UNATTENDEDINSTALL) 1024 { 1025 RTStrmPrintf(pStrm, 1026 "%s unattended %s <uuid|vmname>\n" 1027 " --user <username>\n" 1028 " --password <password>\n" 1029 " --key <key>\n" 1030 " --isopath <OS ISO path>\n" 1031 " [--addisopath <additions ISO path>]" 1032 " [--imageindex <number>]\n" 1033 "\n", SEP); 1034 } 1035 1023 1036 if (fCategory & USAGE_DISCARDSTATE) 1024 1037 RTStrmPrintf(pStrm, -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r64434 r64997 1224 1224 } 1225 1225 1226 static const RTGETOPTDEF g_aUnattendedInstallOptions[] = 1227 { 1228 { "--user", 'u', RTGETOPT_REQ_STRING }, 1229 { "-user", 'u', RTGETOPT_REQ_STRING }, 1230 { "--password", 'p', RTGETOPT_REQ_STRING }, 1231 { "-password", 'p', RTGETOPT_REQ_STRING }, 1232 { "--key", 'k', RTGETOPT_REQ_STRING }, 1233 { "-key", 'k', RTGETOPT_REQ_STRING }, 1234 { "--isopath", 'i', RTGETOPT_REQ_STRING }, 1235 { "-isopath", 'i', RTGETOPT_REQ_STRING }, 1236 { "--addisopath", 'a', RTGETOPT_REQ_STRING }, 1237 { "-addisopath", 'a', RTGETOPT_REQ_STRING }, 1238 { "-imageindex", 'm', RTGETOPT_REQ_UINT16 }, 1239 { "--imageindex", 'm', RTGETOPT_REQ_UINT16 }, 1240 }; 1241 1242 RTEXITCODE handleUnattendedInstall(HandlerArg *a) 1243 { 1244 HRESULT rc; 1245 Bstr vboxAdditionsIsoPath; 1246 Bstr isoPath; 1247 Bstr user; 1248 Bstr password; 1249 Bstr productKey; 1250 Bstr group("group"); 1251 Bstr uuid = Guid(a->argv[0]).toUtf16().raw(); 1252 Bstr machineName; 1253 BOOL bInstallGuestAdditions; 1254 unsigned short imageIndex = 1;//applied only to Windows installation 1255 1256 int c; 1257 RTGETOPTUNION ValueUnion; 1258 RTGETOPTSTATE GetState; 1259 1260 // start at 0 because main() has hacked both the argc and argv given to us 1261 RTGetOptInit(&GetState, a->argc, a->argv, g_aUnattendedInstallOptions, RT_ELEMENTS(g_aUnattendedInstallOptions), 1262 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 1263 while ((c = RTGetOpt(&GetState, &ValueUnion))) 1264 { 1265 switch (c) 1266 { 1267 case 'u': // --user 1268 user = ValueUnion.psz; 1269 break; 1270 1271 case 'p': // --password 1272 password = ValueUnion.psz; 1273 break; 1274 1275 case 'k': // --key 1276 productKey = ValueUnion.psz; 1277 break; 1278 1279 case 'a': // --addisopath 1280 vboxAdditionsIsoPath = ValueUnion.psz; 1281 break; 1282 1283 case 'i': // --isopath 1284 isoPath = ValueUnion.psz; 1285 break; 1286 case 'm': // --image index 1287 imageIndex = ValueUnion.u8; 1288 break; 1289 default: 1290 return errorGetOpt(USAGE_UNATTENDEDINSTALL, c, &ValueUnion); 1291 } 1292 } 1293 1294 /* check for required options */ 1295 if (user.isEmpty() || 1296 password.isEmpty() || 1297 isoPath.isEmpty() 1298 ) 1299 return errorSyntax(USAGE_UNATTENDEDINSTALL, "One of needed parameters has been missed"); 1300 1301 /* try to find the given machine */ 1302 ComPtr<IMachine> machine; 1303 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())); 1304 if (FAILED(rc)) 1305 return RTEXITCODE_FAILURE; 1306 1307 CHECK_ERROR_RET(machine, COMGETTER(Name)(machineName.asOutParam()), RTEXITCODE_FAILURE); 1308 /* open a session for the VM */ 1309 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE); 1310 1311 ComPtr<IConsole> console; 1312 ComPtr<IMachine> sessionMachine; 1313 ComPtr<IUnattended> unAttended; 1314 1315 /* get the associated console */ 1316 CHECK_ERROR(a->session, COMGETTER(Console)(console.asOutParam())); 1317 if (console) 1318 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '%s' is currently running", Utf8Str(uuid).c_str()); 1319 1320 /* ... and session machine */ 1321 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE); 1322 1323 BSTR installedOSBSTR; 1324 1325 CHECK_ERROR_RET(sessionMachine, COMGETTER(OSTypeId)(&installedOSBSTR), RTEXITCODE_FAILURE); 1326 1327 Utf8Str installedOSStr(installedOSBSTR); 1328 1329 do{ 1330 RTPrintf("Start unattended installation OS %s on virtual machine '%ls'.\n" 1331 "UUID: %s\n", 1332 installedOSStr.c_str(), 1333 machineName.raw(), 1334 Utf8Str(uuid).c_str()); 1335 1336 CHECK_ERROR_BREAK(machine, COMGETTER(Unattended)(unAttended.asOutParam())); 1337 1338 CHECK_ERROR_BREAK(unAttended, COMSETTER(Group)(group.raw())); 1339 1340 if(installedOSStr.contains("Windows") && productKey.isEmpty()) 1341 { 1342 return errorSyntax(USAGE_UNATTENDEDINSTALL, "Product key has been missed."); 1343 } 1344 1345 CHECK_ERROR_BREAK(unAttended, COMSETTER(VboxAdditionsIsoPath)(vboxAdditionsIsoPath.raw())); 1346 1347 CHECK_ERROR_BREAK(unAttended, COMSETTER(IsoPath)(isoPath.raw())); 1348 1349 CHECK_ERROR_BREAK(unAttended, COMSETTER(User)(user.raw())); 1350 1351 CHECK_ERROR_BREAK(unAttended, COMSETTER(Password)(password.raw())); 1352 1353 CHECK_ERROR_BREAK(unAttended, COMSETTER(ProductKey)(productKey.raw())); 1354 1355 bool fInstallGuestAdditions = (vboxAdditionsIsoPath.isEmpty()) ? false: true; 1356 CHECK_ERROR_BREAK(unAttended, COMSETTER(InstallGuestAdditions)(fInstallGuestAdditions)); 1357 1358 CHECK_ERROR_BREAK(unAttended, COMSETTER(ImageIndex)(imageIndex)); 1359 1360 CHECK_ERROR_BREAK(unAttended,Preparation()); 1361 CHECK_ERROR_BREAK(unAttended,ConstructScript()); 1362 CHECK_ERROR_BREAK(unAttended,ConstructMedia()); 1363 CHECK_ERROR_BREAK(unAttended,ReconstructVM()); 1364 CHECK_ERROR_BREAK(unAttended,RunInstallation()); 1365 a->session->UnlockMachine(); 1366 // CHECK_ERROR_RET(sessionMachine, UnlockMachine(), RTEXITCODE_FAILURE); 1367 { 1368 Bstr env; 1369 Bstr sessionType = "headless";//"gui"; 1370 1371 #if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) 1372 /* make sure the VM process will start on the same display as VBoxManage */ 1373 Utf8Str str; 1374 const char *pszDisplay = RTEnvGet("DISPLAY"); 1375 if (pszDisplay) 1376 str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay); 1377 const char *pszXAuth = RTEnvGet("XAUTHORITY"); 1378 if (pszXAuth) 1379 str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth)); 1380 env = str; 1381 #endif 1382 ComPtr<IProgress> progress; 1383 CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(), 1384 env.raw(), progress.asOutParam())); 1385 if (SUCCEEDED(rc) && !progress.isNull()) 1386 { 1387 RTPrintf("Waiting for VM \"%s\" to power on...\n", Utf8Str(uuid).c_str()); 1388 CHECK_ERROR(progress, WaitForCompletion(-1)); 1389 if (SUCCEEDED(rc)) 1390 { 1391 BOOL completed = true; 1392 CHECK_ERROR(progress, COMGETTER(Completed)(&completed)); 1393 if (SUCCEEDED(rc)) 1394 { 1395 ASSERT(completed); 1396 1397 LONG iRc; 1398 CHECK_ERROR(progress, COMGETTER(ResultCode)(&iRc)); 1399 if (SUCCEEDED(rc)) 1400 { 1401 if (SUCCEEDED(iRc)) 1402 RTPrintf("VM \"%s\" has been successfully started.\n", Utf8Str(uuid).c_str()); 1403 else 1404 { 1405 ProgressErrorInfo info(progress); 1406 com::GluePrintErrorInfo(info); 1407 } 1408 rc = iRc; 1409 } 1410 } 1411 } 1412 } 1413 } 1414 1415 vboxAdditionsIsoPath.setNull(); 1416 isoPath.setNull(); 1417 user.setNull(); 1418 password.setNull(); 1419 productKey.setNull(); 1420 group.setNull(); 1421 bInstallGuestAdditions = false; 1422 imageIndex = 0; 1423 1424 CHECK_ERROR_BREAK(unAttended, COMGETTER(Group)(group.asOutParam())); 1425 CHECK_ERROR_BREAK(unAttended, COMGETTER(VboxAdditionsIsoPath)(vboxAdditionsIsoPath.asOutParam())); 1426 CHECK_ERROR_BREAK(unAttended, COMGETTER(IsoPath)(isoPath.asOutParam())); 1427 CHECK_ERROR_BREAK(unAttended, COMGETTER(User)(user.asOutParam())); 1428 CHECK_ERROR_BREAK(unAttended, COMGETTER(Password)(password.asOutParam())); 1429 CHECK_ERROR_BREAK(unAttended, COMGETTER(ProductKey)(productKey.asOutParam())); 1430 CHECK_ERROR_BREAK(unAttended, COMGETTER(ImageIndex)(&imageIndex)); 1431 RTPrintf("Got values:\n user: %s\n password: %s\n productKey: %s\n image index: %d\n " 1432 "isoPath: %s\n vboxAdditionsIsoPath: %s\n", 1433 Utf8Str(user).c_str(), 1434 Utf8Str(password).c_str(), 1435 Utf8Str(productKey).c_str(), 1436 imageIndex, 1437 Utf8Str(isoPath).c_str(), 1438 Utf8Str(vboxAdditionsIsoPath).c_str() 1439 ); 1440 } 1441 while (0); 1442 1443 a->session->UnlockMachine(); 1444 // CHECK_ERROR_RET(sessionMachine, UnlockMachine(), RTEXITCODE_FAILURE); 1445 1446 RTPrintf("Unattended installation OS %s has been running on virtual machine '%ls'.\n" 1447 "UUID: %s\n", 1448 installedOSStr.c_str(), 1449 machineName.raw(), 1450 Utf8Str(uuid).c_str()); 1451 1452 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1453 }
Note:
See TracChangeset
for help on using the changeset viewer.