- Timestamp:
- Apr 28, 2022 6:45:41 PM (3 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/UnattendedTemplates/ubuntu_preseed.cfg
r93957 r94748 1 d-i ubiquity/use_nonfree true 2 d-i ubiquity/install_oem false 3 1 4 ### Partitioning 2 5 d-i partman-auto/disk string /dev/sda -
trunk/src/VBox/Main/include/UnattendedInstaller.h
r94335 r94748 589 589 RTVFS hVfsOrgIso, bool fOverwrite); 590 590 /** 591 * Performs basic edits on menu configuration file(s) (txt.cfg or menu.cfg etc).591 * Performs basic edits on menu configuration file(s) of isolinux (txt.cfg or menu.cfg etc). 592 592 * 593 593 * @returns COM status code 594 * @param pEditor Editor with the isolinux.cfg file loaded and parsed. 595 */ 596 HRESULT editDebianMenuCfg(GeneralTextScript *pEditor); 594 * @param pEditor Editor with the menu config. file loaded and parsed. 595 * @param pszMenuConfigFileName Name of the menu file. 596 */ 597 HRESULT editDebianMenuCfg(GeneralTextScript *pEditor, const char *pszMenuConfigFileName); 598 /** 599 * Performs basic edits on grub configuration file (grub.cfg). 600 * 601 * @returns COM status code 602 * @param pEditor Editor with the grub.cfg file loaded and parsed. 603 * @param pszMenuGrubFileName Name of the grub config file. 604 */ 605 HRESULT editDebianGrubCfg(GeneralTextScript *pEditor, const char *pszGrubConfigFileName); 606 597 607 /** 598 608 * Performs basic edits on a isolinux.cfg file. -
trunk/src/VBox/Main/src-server/UnattendedImpl.cpp
r94533 r94748 3629 3629 } 3630 3630 } 3631 /* Earlier than OL 6.4 cannot be installe r. OL 6.x fails with unsupported hardware error (CPU family). */3631 /* Earlier than OL 6.4 cannot be installed. OL 6.x fails with unsupported hardware error (CPU family). */ 3632 3632 if (mEnmOsType == VBOXOSTYPE_Oracle || mEnmOsType == VBOXOSTYPE_Oracle_x64) 3633 3633 { -
trunk/src/VBox/Main/src-server/UnattendedInstaller.cpp
r94460 r94748 996 996 { 997 997 /* On Debian Live ISOs (at least from 9 to 11) the there is only menu.cfg. */ 998 const char *pszMenuConfigFileName = "/isolinux/txt.cfg";999 if ( !hlpVfsFileExists(hVfsOrgIso, pszMenuConfigFileName)998 RTCString strMenuConfigFileName("/isolinux/txt.cfg"); 999 if ( !hlpVfsFileExists(hVfsOrgIso, strMenuConfigFileName.c_str()) 1000 1000 && hlpVfsFileExists(hVfsOrgIso, "/isolinux/menu.cfg")) 1001 pszMenuConfigFileName = "/isolinux/menu.cfg"; 1002 1001 strMenuConfigFileName = "/isolinux/menu.cfg"; 1002 1003 /* Ubuntus 21.10+ are UEFI only. No isolinux directory. We modify grub.cfg. */ 1004 if ( !hlpVfsFileExists(hVfsOrgIso, strMenuConfigFileName.c_str()) 1005 && hlpVfsFileExists(hVfsOrgIso, "/boot/grub/grub.cfg")) 1006 strMenuConfigFileName = "/boot/grub/grub.cfg"; 1007 1008 /* Check for existence of isolinux.cfg since UEFI-only ISOs do not have this file. */ 1009 bool fIsoLinuxCfgExists = hlpVfsFileExists(hVfsOrgIso, "isolinux/isolinux.cfg"); 1003 1010 /* 1004 1011 * VISO bits and filenames. … … 1018 1025 rVecArgs.append() = "--dir-mode=0555"; 1019 1026 1020 /* Remove the two isolinux configure files we'll be replacing. */ 1021 rVecArgs.append() = "isolinux/isolinux.cfg=:must-remove:"; 1022 rVecArgs.append().assign(&pszMenuConfigFileName[1]).append("=:must-remove:"); 1023 1024 /* Add the replacement files. */ 1025 strIsoLinuxCfg = mpParent->i_getAuxiliaryBasePath(); 1026 strIsoLinuxCfg.append("isolinux-isolinux.cfg"); 1027 rVecArgs.append().append("isolinux/isolinux.cfg=").append(strIsoLinuxCfg); 1028 1027 /* Replace the isolinux.cfg configuration file. */ 1028 if (fIsoLinuxCfgExists) 1029 { 1030 /* First remove. */ 1031 rVecArgs.append() = "isolinux/isolinux.cfg=:must-remove:"; 1032 /* Then add the modified file. */ 1033 strIsoLinuxCfg = mpParent->i_getAuxiliaryBasePath(); 1034 strIsoLinuxCfg.append("isolinux-isolinux.cfg"); 1035 rVecArgs.append().append("isolinux/isolinux.cfg=").append(strIsoLinuxCfg); 1036 } 1037 1038 /* Replace menu configuration file as well. */ 1039 rVecArgs.append().assign(strMenuConfigFileName).append("=:must-remove:"); 1029 1040 strTxtCfg = mpParent->i_getAuxiliaryBasePath(); 1030 strTxtCfg.append("isolinux-txt.cfg"); 1031 rVecArgs.append().assign(&pszMenuConfigFileName[1]).append("=").append(strTxtCfg); 1041 if (strMenuConfigFileName.compare("/boot/grub/grub.cfg", RTCString::CaseInsensitive) == 0) 1042 strTxtCfg.append("grub.cfg"); 1043 else 1044 strTxtCfg.append("isolinux-.cfg"); 1045 rVecArgs.append().assign(strMenuConfigFileName).append("=").append(strTxtCfg); 1032 1046 } 1033 1047 catch (std::bad_alloc &) … … 1037 1051 1038 1052 /* 1039 * Edit the isolinux.cfg file. 1040 */ 1053 * Edit the isolinux.cfg file if it is there. 1054 */ 1055 if (fIsoLinuxCfgExists) 1041 1056 { 1042 1057 GeneralTextScript Editor(mpParent); 1043 1058 HRESULT hrc = loadAndParseFileFromIso(hVfsOrgIso, "/isolinux/isolinux.cfg", &Editor); 1044 1059 if (SUCCEEDED(hrc)) 1045 hrc = editIsoLinuxCfg(&Editor, RTPathFilename( pszMenuConfigFileName));1060 hrc = editIsoLinuxCfg(&Editor, RTPathFilename(strMenuConfigFileName.c_str())); 1046 1061 if (SUCCEEDED(hrc)) 1047 1062 { … … 1065 1080 1066 1081 /* 1067 * Edit the menu config file file.1082 * Edit the menu config file. 1068 1083 */ 1069 1084 { 1070 1085 GeneralTextScript Editor(mpParent); 1071 HRESULT hrc = loadAndParseFileFromIso(hVfsOrgIso, pszMenuConfigFileName, &Editor);1086 HRESULT hrc = loadAndParseFileFromIso(hVfsOrgIso, strMenuConfigFileName.c_str(), &Editor); 1072 1087 if (SUCCEEDED(hrc)) 1073 hrc = editDebianMenuCfg(&Editor); 1088 { 1089 if (strMenuConfigFileName.compare("/boot/grub/grub.cfg", RTCString::CaseInsensitive) == 0) 1090 hrc = editDebianGrubCfg(&Editor, strMenuConfigFileName.c_str()); 1091 else 1092 hrc = editDebianMenuCfg(&Editor, strMenuConfigFileName.c_str()); 1093 } 1074 1094 if (SUCCEEDED(hrc)) 1075 1095 { … … 1136 1156 } 1137 1157 1138 HRESULT UnattendedDebianInstaller::editDebianMenuCfg(GeneralTextScript *pEditor )1158 HRESULT UnattendedDebianInstaller::editDebianMenuCfg(GeneralTextScript *pEditor, const char *pszMenuConfigFileName) 1139 1159 { 1140 1160 /* … … 1145 1165 try 1146 1166 { 1167 HRESULT hrc = S_OK; 1147 1168 const char *pszNewLabel = "VBoxUnatendedInstall"; 1148 1169 std::vector<size_t> vecLineNumbers = pEditor->findTemplate("label", RTCString::CaseInsensitive); … … 1161 1182 Utf8Str strNewLabel("label "); 1162 1183 strNewLabel.append(pszNewLabel); 1163 HRESULT hrc = pEditor->setContentOfLine(vecLineNumbers[i], strNewLabel); 1164 if (!SUCCEEDED(hrc)) 1165 return hrc; 1166 fLabelFound = true; 1167 break; 1184 hrc = pEditor->setContentOfLine(vecLineNumbers[i], strNewLabel); 1185 if (SUCCEEDED(hrc)) 1186 { 1187 fLabelFound = true; 1188 break; 1189 } 1168 1190 } 1169 1191 } 1170 1192 if (!fLabelFound) 1171 return E_FAIL; 1172 /* Modify the content of default lines so that they point to label we have chosen above. */ 1173 Utf8Str strNewContent("default "); 1174 strNewContent.append(pszNewLabel); 1175 1176 std::vector<size_t> vecDefaultLineNumbers = pEditor->findTemplate("default", RTCString::CaseInsensitive); 1177 if (!vecDefaultLineNumbers.empty()) 1178 { 1179 for (size_t j = 0; j < vecDefaultLineNumbers.size(); ++j) 1180 { 1181 HRESULT hrc = pEditor->setContentOfLine(vecDefaultLineNumbers[j], strNewContent); 1193 hrc = VBOX_E_FILE_ERROR; 1194 1195 if (SUCCEEDED(hrc)) 1196 { 1197 /* Modify the content of default lines so that they point to label we have chosen above. */ 1198 Utf8Str strNewContent("default "); 1199 strNewContent.append(pszNewLabel); 1200 1201 std::vector<size_t> vecDefaultLineNumbers = pEditor->findTemplate("default", RTCString::CaseInsensitive); 1202 if (!vecDefaultLineNumbers.empty()) 1203 { 1204 for (size_t j = 0; j < vecDefaultLineNumbers.size(); ++j) 1205 { 1206 hrc = pEditor->setContentOfLine(vecDefaultLineNumbers[j], strNewContent); 1207 if (FAILED(hrc)) 1208 break; 1209 } 1210 } 1211 /* Add a defaul label line. */ 1212 else 1213 hrc = pEditor->appendLine(strNewContent); 1214 } 1215 if (FAILED(hrc)) 1216 return mpParent->setErrorBoth(VBOX_E_FILE_ERROR, hrc, 1217 tr("Failed to edit menu configuration file: \"%s\": (%Rrc)"), 1218 pszMenuConfigFileName, hrc); 1219 } 1220 catch (std::bad_alloc &) 1221 { 1222 return E_OUTOFMEMORY; 1223 } 1224 return UnattendedLinuxInstaller::editIsoLinuxCommon(pEditor); 1225 } 1226 1227 HRESULT UnattendedDebianInstaller::editDebianGrubCfg(GeneralTextScript *pEditor, const char *pszGrubConfigFileName) 1228 { 1229 /* Default menu entry of grub.cfg is set in /etc/deafult/grub file. */ 1230 try 1231 { 1232 /* Set timeouts to 10 seconds. */ 1233 std::vector<size_t> vecLineNumbers = pEditor->findTemplate("set timeout", RTCString::CaseInsensitive); 1234 for (size_t i = 0; i < vecLineNumbers.size(); ++i) 1235 if (pEditor->getContentOfLine(vecLineNumbers[i]).startsWithWord("set timeout", RTCString::CaseInsensitive)) 1236 { 1237 HRESULT hrc = pEditor->setContentOfLine(vecLineNumbers.at(i), "set timeout=10"); 1182 1238 if (FAILED(hrc)) 1183 1239 return hrc; 1184 1240 } 1185 } 1186 /* Add a defaul label line. */ 1187 else 1188 { 1189 HRESULT hrc = pEditor->appendLine(strNewContent); 1190 if (FAILED(hrc)) 1191 return hrc; 1192 } 1193 1241 1242 /* Modify kernel lines assuming that they starts with 'linux' keyword and 2nd word is the kernel command.* 1243 * we remove whatever comes after command and add our own command line options. */ 1244 vecLineNumbers = pEditor->findTemplate("linux", RTCString::CaseInsensitive); 1245 if (vecLineNumbers.size() > 0) 1246 { 1247 Utf8Str const &rStrAppend = mpParent->i_getExtraInstallKernelParameters().isNotEmpty() 1248 ? mpParent->i_getExtraInstallKernelParameters() 1249 : mStrDefaultExtraInstallKernelParameters; 1250 1251 for (size_t i = 0; i < vecLineNumbers.size(); ++i) 1252 { 1253 HRESULT hrc = S_OK; 1254 if (pEditor->getContentOfLine(vecLineNumbers[i]).startsWithWord("linux", RTCString::CaseInsensitive)) 1255 { 1256 Utf8Str strLine = pEditor->getContentOfLine(vecLineNumbers[i]); 1257 size_t cbPos = strLine.find("linux") + strlen("linux"); 1258 bool fSecondWord = false; 1259 /* Find the end of 2nd word assuming that it is kernel command. */ 1260 while (cbPos < strLine.length()) 1261 { 1262 if (!fSecondWord) 1263 { 1264 if (strLine[cbPos] != '\t' && strLine[cbPos] != ' ') 1265 fSecondWord = true; 1266 } 1267 else 1268 { 1269 if (strLine[cbPos] == '\t' || strLine[cbPos] == ' ') 1270 break; 1271 } 1272 ++cbPos; 1273 } 1274 if (!fSecondWord) 1275 hrc = VBOX_E_FILE_ERROR; 1276 1277 if (SUCCEEDED(hrc)) 1278 { 1279 strLine.erase(cbPos, strLine.length() - cbPos); 1280 1281 /* Do the appending. */ 1282 if (rStrAppend.isNotEmpty()) 1283 { 1284 if (!rStrAppend.startsWith(" ") && !strLine.endsWith(" ")) 1285 strLine.append(' '); 1286 strLine.append(rStrAppend); 1287 } 1288 1289 /* Update line. */ 1290 hrc = pEditor->setContentOfLine(vecLineNumbers.at(i), strLine); 1291 } 1292 if (FAILED(hrc)) 1293 return mpParent->setErrorBoth(VBOX_E_FILE_ERROR, hrc, 1294 tr("Failed to edit grub configuration file: \"%s\": (%Rrc)"), 1295 pszGrubConfigFileName, hrc); 1296 } 1297 } 1298 } 1194 1299 } 1195 1300 catch (std::bad_alloc &) … … 1197 1302 return E_OUTOFMEMORY; 1198 1303 } 1199 return UnattendedLinuxInstaller::editIsoLinuxCommon(pEditor); 1200 } 1201 1304 return S_OK; 1305 } 1202 1306 1203 1307 //////////////////////////////////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.