VirtualBox

Ignore:
Timestamp:
Jun 27, 2017 5:59:55 PM (8 years ago)
Author:
vboxsync
Message:

IUnattended: Some refactoring, probably not quite working right yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r67619 r67652  
    12721272     * Options.
    12731273     */
    1274     Bstr vboxAdditionsIsoPath;
    1275     Bstr isoPath;
    1276     Bstr user;
    1277     Bstr password;
    1278     Bstr productKey;
    1279     Bstr auxiliaryCDPath;
    1280     Bstr auxiliaryFloppyPath;
     1274    Bstr bstrAdditionsIsoPath;
     1275    Bstr bstrIsoPath;
     1276    Bstr bstrUser;
     1277    Bstr bstrPassword;
     1278    Bstr bstrProductKey;
     1279    Bstr bstrAuxiliaryBasePath;
    12811280    Bstr group("group");
    1282     Bstr machineName;
    1283     Bstr fileWithSettings;
     1281    Bstr bstrMachineName;
     1282    Bstr bstrSettingsFile;
    12841283    unsigned short imageIndex = 1; // applied only to Windows installation
    1285     int cSpecificOptions = 0;
    1286     Bstr sessionType = "headless";
     1284    Bstr bstrSessionType = "headless";
    12871285
    12881286    /*
     
    12991297        { "--iso-path",             'i', RTGETOPT_REQ_STRING },
    13001298        { "--additions-iso-path",   'a', RTGETOPT_REQ_STRING },
    1301         { "--auxiliary-cd-path",    'c', RTGETOPT_REQ_STRING },
    1302         { "--auxiliary-floppy-path",'f', RTGETOPT_REQ_STRING },
     1299        { "--auxiliary-base-path",  'x', RTGETOPT_REQ_STRING },
    13031300        { "--image-index",          'm', RTGETOPT_REQ_UINT16 },
    13041301        { "--settings-file",        's', RTGETOPT_REQ_STRING },
     
    13171314        {
    13181315            case VINF_GETOPT_NOT_OPTION:
    1319                 if (machineName.isNotEmpty())
     1316                if (bstrMachineName.isNotEmpty())
    13201317                    return errorSyntax(USAGE_UNATTENDEDINSTALL, "VM name/UUID given more than once!");
    1321                 machineName = ValueUnion.psz;
    1322                 if (machineName.isEmpty())
     1318                bstrMachineName = ValueUnion.psz;
     1319                if (bstrMachineName.isEmpty())
    13231320                    return errorSyntax(USAGE_UNATTENDEDINSTALL, "VM name/UUID is empty!");
    13241321                break;
    13251322
    1326             case 's':   // --settings-file <a file with data prepared by user>
    1327                 if (cSpecificOptions > 0)
    1328                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--settings-file cannot be mixed with the other options");
    1329                 fileWithSettings = ValueUnion.psz;
    1330                 cSpecificOptions = -1;
     1323            case 's':   // --settings-file <key value file>
     1324                bstrSettingsFile = ValueUnion.psz;
    13311325                break;
    13321326
    13331327            case 'u':   // --user
    1334                 if (cSpecificOptions < 0)
    1335                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--user cannot be mixed with --settings-file");
    1336                 user = ValueUnion.psz;
    1337                 cSpecificOptions++;
     1328                bstrUser = ValueUnion.psz;
    13381329                break;
    13391330
    13401331            case 'p':   // --password
    1341                 if (cSpecificOptions < 0)
    1342                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--password cannot be mixed with --settings-file");
    1343                 password = ValueUnion.psz;
    1344                 cSpecificOptions++;
     1332                bstrPassword = ValueUnion.psz;
    13451333                break;
    13461334
    13471335            case 'k':   // --key
    1348                 if (cSpecificOptions < 0)
    1349                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--key cannot be mixed with --settings-file");
    1350                 productKey = ValueUnion.psz;
    1351                 cSpecificOptions++;
     1336                bstrProductKey = ValueUnion.psz;
    13521337                break;
    13531338
    13541339            case 'a':   // --additions-iso-path
    1355                 if (cSpecificOptions < 0)
    1356                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--additions-iso-path cannot be mixed with --settings-file");
    1357                 vboxAdditionsIsoPath = ValueUnion.psz;
    1358                 cSpecificOptions++;
     1340                bstrAdditionsIsoPath = ValueUnion.psz;
    13591341                break;
    13601342
    13611343            case 'i':   // --iso-path
    1362                 if (cSpecificOptions < 0)
    1363                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--iso-path cannot be mixed with --settings-file");
    1364                 isoPath = ValueUnion.psz;
    1365                 cSpecificOptions++;
    1366                 break;
    1367 
    1368             case 'f':  // --auxiliary-floppy-path
    1369                 if (cSpecificOptions < 0)
    1370                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--auxiliary-floppy-path cannot be mixed with --settings-file");
    1371                 auxiliaryFloppyPath = ValueUnion.psz;
    1372                 cSpecificOptions++;
    1373                 break;
    1374 
    1375             case 'c':  // --auxiliary-cd-path
    1376                 if (cSpecificOptions < 0)
    1377                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--auxiliary-cd-path cannot be mixed with --settings-file");
    1378                 auxiliaryCDPath = ValueUnion.psz;
    1379                 cSpecificOptions++;
     1344                bstrIsoPath = ValueUnion.psz;
     1345                break;
     1346
     1347            case 'x':  // --auxiliary-base-path
     1348                bstrAuxiliaryBasePath = ValueUnion.psz;
    13801349                break;
    13811350
    13821351            case 'm':   // --image-index
    1383                 if (cSpecificOptions < 0)
    1384                     return errorSyntax(USAGE_UNATTENDEDINSTALL, "--image-index cannot be mixed with --settings-file");
    13851352                imageIndex = ValueUnion.u16;
    1386                 cSpecificOptions++;
    13871353                break;
    13881354
    13891355            case 'S':   // --session-type
    1390                 sessionType = ValueUnion.psz;
     1356                bstrSessionType = ValueUnion.psz;
    13911357                break;
    13921358
     
    13991365     * Check for required stuff.
    14001366     */
    1401     if (machineName.isEmpty())
     1367    if (bstrMachineName.isEmpty())
    14021368        return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing VM name/UUID");
    14031369
    1404     if (cSpecificOptions > 0)
    1405     {
    1406         if (user.isEmpty())
    1407             return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --user option");
    1408         if (password.isEmpty())
    1409             return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --password option");
    1410         if (isoPath.isEmpty())
    1411             return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --iso-path option");
    1412     }
    1413     else if (fileWithSettings.isEmpty())
    1414         return errorSyntax(USAGE_UNATTENDEDINSTALL, "Requires either --file or --user & --password & --iso-path");
     1370    if (bstrSettingsFile.isEmpty())
     1371    {
     1372        if (bstrUser.isEmpty())
     1373            return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --user (or --settings-file) option");
     1374        if (bstrPassword.isEmpty())
     1375            return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --password (or --settings-file) option");
     1376        if (bstrIsoPath.isEmpty())
     1377            return errorSyntax(USAGE_UNATTENDEDINSTALL, "Missing required --iso-path (or --settings-file) option");
     1378    }
    14151379
    14161380    /*
     
    14211385    HRESULT rc;
    14221386    ComPtr<IMachine> machine;
    1423     CHECK_ERROR(a->virtualBox, FindMachine(machineName.raw(), machine.asOutParam()));
     1387    CHECK_ERROR(a->virtualBox, FindMachine(bstrMachineName.raw(), machine.asOutParam()));
    14241388    if (FAILED(rc))
    14251389        return RTEXITCODE_FAILURE;
    14261390
    1427     CHECK_ERROR_RET(machine, COMGETTER(Name)(machineName.asOutParam()), RTEXITCODE_FAILURE);
     1391    CHECK_ERROR_RET(machine, COMGETTER(Name)(bstrMachineName.asOutParam()), RTEXITCODE_FAILURE);
    14281392    Bstr bstrUuid;
    14291393    CHECK_ERROR_RET(machine, COMGETTER(Id)(bstrUuid.asOutParam()), RTEXITCODE_FAILURE);
     
    14351399    CHECK_ERROR(a->session, COMGETTER(Console)(console.asOutParam()));
    14361400    if (console)
    1437         return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '%ls' is currently running", machineName.raw());
     1401        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '%ls' is currently running", bstrMachineName.raw());
    14381402
    14391403    /* ... and session machine */
     
    14511415                 "UUID: %s\n",
    14521416                 strInstalledOS.c_str(),
    1453                  machineName.raw(),
     1417                 bstrMachineName.raw(),
    14541418                 Utf8Str(bstrUuid).c_str());
    14551419
     
    14601424        CHECK_ERROR_BREAK(machine, COMGETTER(Unattended)(unAttended.asOutParam()));
    14611425
    1462         if (fileWithSettings.isEmpty())//may use also this condition (!strcmp(a->argv[1], "usedata"))
    1463         {
    1464             CHECK_ERROR_BREAK(unAttended, COMSETTER(Group)(group.raw()));
    1465 
    1466             if (strInstalledOS.contains("Windows") && productKey.isEmpty())
    1467                 return errorSyntax(USAGE_UNATTENDEDINSTALL, "A product key is required (--key).");
    1468 
    1469             CHECK_ERROR_BREAK(unAttended, COMSETTER(IsoPath)(isoPath.raw()));
    1470             CHECK_ERROR_BREAK(unAttended, COMSETTER(User)(user.raw()));
    1471             CHECK_ERROR_BREAK(unAttended, COMSETTER(Password)(password.raw()));
    1472             CHECK_ERROR_BREAK(unAttended, COMSETTER(ProductKey)(productKey.raw()));
    1473             CHECK_ERROR_BREAK(unAttended, COMSETTER(AuxiliaryCDPath)(auxiliaryCDPath.raw()));
    1474             CHECK_ERROR_BREAK(unAttended, COMSETTER(AuxiliaryFloppyPath)(auxiliaryFloppyPath.raw()));
    1475             CHECK_ERROR_BREAK(unAttended, COMSETTER(AdditionsIsoPath)(vboxAdditionsIsoPath.raw()));
    1476             CHECK_ERROR_BREAK(unAttended, COMSETTER(InstallGuestAdditions)(vboxAdditionsIsoPath.isNotEmpty()));
    1477             CHECK_ERROR_BREAK(unAttended, COMSETTER(ImageIndex)(imageIndex));
    1478             CHECK_ERROR_BREAK(unAttended,Preparation());
    1479             CHECK_ERROR_BREAK(unAttended,ConstructScript());
    1480             CHECK_ERROR_BREAK(unAttended,ConstructMedia());
    1481         }
    1482         else
    1483         {
    1484             CHECK_ERROR_BREAK(unAttended, COMSETTER(FileWithPreparedData)(fileWithSettings.raw()));
    1485             CHECK_ERROR_BREAK(unAttended,Preparation());
    1486         }
    1487         CHECK_ERROR_BREAK(unAttended,ReconstructVM());
    1488         CHECK_ERROR_BREAK(unAttended,RunInstallation());
     1426        if (bstrSettingsFile.isNotEmpty())
     1427            CHECK_ERROR_BREAK(unAttended, LoadSettings(bstrSettingsFile.raw()));
     1428
     1429        CHECK_ERROR_BREAK(unAttended, COMSETTER(Group)(group.raw()));
     1430        CHECK_ERROR_BREAK(unAttended, COMSETTER(IsoPath)(bstrIsoPath.raw()));
     1431        CHECK_ERROR_BREAK(unAttended, COMSETTER(User)(bstrUser.raw()));
     1432        CHECK_ERROR_BREAK(unAttended, COMSETTER(Password)(bstrPassword.raw()));
     1433        CHECK_ERROR_BREAK(unAttended, COMSETTER(ProductKey)(bstrProductKey.raw()));
     1434        CHECK_ERROR_BREAK(unAttended, COMSETTER(AdditionsIsoPath)(bstrAdditionsIsoPath.raw()));
     1435        CHECK_ERROR_BREAK(unAttended, COMSETTER(InstallGuestAdditions)(bstrAdditionsIsoPath.isNotEmpty()));
     1436        CHECK_ERROR_BREAK(unAttended, COMSETTER(ImageIndex)(imageIndex));
     1437        CHECK_ERROR_BREAK(unAttended, COMSETTER(AuxiliaryBasePath)(bstrAuxiliaryBasePath.raw()));
     1438
     1439        CHECK_ERROR_BREAK(unAttended,Prepare());
     1440        CHECK_ERROR_BREAK(unAttended,ConstructScript());
     1441        CHECK_ERROR_BREAK(unAttended,ConstructMedia());
     1442        CHECK_ERROR_BREAK(unAttended,ReconfigureVM());
     1443        CHECK_ERROR_BREAK(unAttended,Done());
    14891444
    14901445
     
    15091464#endif
    15101465            ComPtr<IProgress> progress;
    1511             CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam()));
     1466            CHECK_ERROR(machine, LaunchVMProcess(a->session, bstrSessionType.raw(), env.raw(), progress.asOutParam()));
    15121467            if (SUCCEEDED(rc) && !progress.isNull())
    15131468            {
     
    15431498         * Retrieve and display the parameters actually used.
    15441499         */
    1545         CHECK_ERROR_BREAK(unAttended, COMGETTER(FileWithPreparedData)(fileWithSettings.asOutParam()));
    15461500        CHECK_ERROR_BREAK(unAttended, COMGETTER(Group)(group.asOutParam()));
    1547         CHECK_ERROR_BREAK(unAttended, COMGETTER(AdditionsIsoPath)(vboxAdditionsIsoPath.asOutParam()));
     1501        CHECK_ERROR_BREAK(unAttended, COMGETTER(AdditionsIsoPath)(bstrAdditionsIsoPath.asOutParam()));
    15481502        BOOL fInstallGuestAdditions = FALSE;
    15491503        CHECK_ERROR_BREAK(unAttended, COMGETTER(InstallGuestAdditions)(&fInstallGuestAdditions));
    1550         CHECK_ERROR_BREAK(unAttended, COMGETTER(IsoPath)(isoPath.asOutParam()));
    1551         CHECK_ERROR_BREAK(unAttended, COMGETTER(User)(user.asOutParam()));
    1552         CHECK_ERROR_BREAK(unAttended, COMGETTER(Password)(password.asOutParam()));
    1553         CHECK_ERROR_BREAK(unAttended, COMGETTER(ProductKey)(productKey.asOutParam()));
    1554         CHECK_ERROR_BREAK(unAttended, COMGETTER(AuxiliaryCDPath)(auxiliaryCDPath.asOutParam()));
    1555         CHECK_ERROR_BREAK(unAttended, COMGETTER(AuxiliaryFloppyPath)(auxiliaryFloppyPath.asOutParam()));
     1504        CHECK_ERROR_BREAK(unAttended, COMGETTER(IsoPath)(bstrIsoPath.asOutParam()));
     1505        CHECK_ERROR_BREAK(unAttended, COMGETTER(User)(bstrUser.asOutParam()));
     1506        CHECK_ERROR_BREAK(unAttended, COMGETTER(Password)(bstrPassword.asOutParam()));
     1507        CHECK_ERROR_BREAK(unAttended, COMGETTER(ProductKey)(bstrProductKey.asOutParam()));
     1508        CHECK_ERROR_BREAK(unAttended, COMGETTER(AuxiliaryBasePath)(bstrAuxiliaryBasePath.asOutParam()));
    15561509        imageIndex = 0;
    15571510        CHECK_ERROR_BREAK(unAttended, COMGETTER(ImageIndex)(&imageIndex));
    15581511        RTPrintf("Got values:\n"
    1559                  " fileWithSettings:      %s\n "
    1560                  " user:                  %s\n"
    1561                  " password:              %s\n"
    1562                  " productKey:            %s\n"
     1512                 " user:                  %ls\n"
     1513                 " password:              %ls\n"
     1514                 " productKey:            %ls\n"
    15631515                 " image index:           %u\n"
    1564                  " isoPath:               %s\n"
    1565                  " vboxAdditionsIsoPath:  %s\n"
     1516                 " isoPath:               %ls\n"
     1517                 " additionsIsoPath:      %ls\n"
    15661518                 " installGuestAdditions: %RTbool",
    1567                  Utf8Str(fileWithSettings).c_str(),
    1568                  Utf8Str(user).c_str(),
    1569                  Utf8Str(password).c_str(),
    1570                  Utf8Str(productKey).c_str(),
     1519                 " auxiliaryBasePath:     %ls",
     1520                 bstrUser.raw(),
     1521                 bstrPassword.raw(),
     1522                 bstrProductKey.raw(),
    15711523                 imageIndex,
    1572                  Utf8Str(isoPath).c_str(),
    1573                  Utf8Str(vboxAdditionsIsoPath).c_str(),
    1574                  fInstallGuestAdditions);
     1524                 bstrIsoPath.raw(),
     1525                 bstrAdditionsIsoPath.raw(),
     1526                 fInstallGuestAdditions,
     1527                 bstrAuxiliaryBasePath.raw());
    15751528    } while (0);
    15761529
     
    15781531             "UUID: %ls\n",
    15791532             strInstalledOS.c_str(),
    1580              machineName.raw(),
     1533             bstrMachineName.raw(),
    15811534             bstrUuid.raw());
    15821535
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette