usr/src/cmd/auto-install/auto_install.c
changeset 862 e9f31f2f2f2d
parent 846 70dd9e819f25
child 867 cfbbedf29419
equal deleted inserted replaced
861:ccd399d2c6f7 862:e9f31f2f2f2d
   202 	}
   202 	}
   203 	(void) pclose(file_ptr);
   203 	(void) pclose(file_ptr);
   204 }
   204 }
   205 
   205 
   206 /*
   206 /*
   207  * This function splits the file that is passed to AI manifest and SC manifest
   207  * This function splits the passed in file into AI manifest and SC manifest
   208  *
   208  *
   209  * Input:
   209  * Input:
   210  * char *input_file	- The file contains AI manifest (relax NG schema) and
   210  * char *input_file	- AI manifest file with embedded SC manifest
   211  *			  SC manifest (enhanced SMF profile DTD schema)
   211  *
   212  * Output:
   212  * Output:
   213  * char *ai_manifest	- Writes the AI manifest portion of the input on this
   213  * char *ai_manifest	- Writes the AI manifest portion of the input to this
   214  *			  file name
   214  *			  file name
   215  * char *sc_manifest	- Writes the SC manifest portion of the input on this
   215  * char *sc_manifest	- Writes the SC manifest portion of the input to this
   216  *			  file name
   216  *			  file name
   217  * Returns:
   217  * Returns:
   218  * AUTO_VALID_MANIFEST (0)	- If the operation is successful
   218  * AUTO_VALID_MANIFEST (0)	- If the operation is successful
   219  * AUTO_INVALID_MANIFEST (-1)	- If the operation fails
   219  * AUTO_INVALID_MANIFEST (-1)	- If the operation fails
   220  */
   220  */
   222 auto_split_manifests(char *input_file, char *ai_manifest, char *sc_manifest)
   222 auto_split_manifests(char *input_file, char *ai_manifest, char *sc_manifest)
   223 {
   223 {
   224 	FILE		*ifp;	/* Input file */
   224 	FILE		*ifp;	/* Input file */
   225 	FILE		*aifp;	/* AI manifest */
   225 	FILE		*aifp;	/* AI manifest */
   226 	FILE		*scfp;	/* SC manifest */
   226 	FILE		*scfp;	/* SC manifest */
   227 	boolean_t	writing_ai_manifest = B_FALSE;
   227 	boolean_t	writing_ai_manifest = B_TRUE;
   228 	boolean_t	writing_sc_manifest = B_FALSE;
   228 	boolean_t	writing_sc_manifest = B_FALSE;
   229 	char		buf[BUFSIZ];
   229 	char		buf[BUFSIZ];
   230 
   230 
   231 
   231 
   232 	if (input_file == NULL || ai_manifest == NULL || sc_manifest == NULL) {
   232 	if (input_file == NULL || ai_manifest == NULL || sc_manifest == NULL) {
   265 	}
   265 	}
   266 
   266 
   267 	while (fgets(buf, sizeof (buf), ifp) != NULL) {
   267 	while (fgets(buf, sizeof (buf), ifp) != NULL) {
   268 
   268 
   269 		/*
   269 		/*
   270 		 * The AI manifest begins with <ai_manifest and
       
   271 		 * ends with the line "</ai_manifest>"
       
   272 		 * The SC manifest begins with <?xml version='1.0'?> and
   270 		 * The SC manifest begins with <?xml version='1.0'?> and
   273 		 * ends with the line "</service_bundle>"
   271 		 * ends with the line "</service_bundle>". It is embedded
   274 		 *
   272 		 * in the input file between <sc_embedded_manifest ...>
       
   273 		 * and  </sc_embedded_manifest>.
   275 		 */
   274 		 */
   276 		if (strstr(buf, AI_MANIFEST_BEGIN_MARKER) != NULL) {
   275 		if (strstr(buf, SC_EMBEDDED_BEGIN_MARKER) != NULL) {
       
   276 			writing_ai_manifest = B_FALSE;
       
   277 			continue;
       
   278 		}
       
   279 		if (strstr(buf, SC_EMBEDDED_END_MARKER) != NULL) {
   277 			writing_ai_manifest = B_TRUE;
   280 			writing_ai_manifest = B_TRUE;
   278 		}
   281 			continue;
   279 		if (strstr(buf, SC_MANIFEST_BEGIN_MARKER) != NULL) {
   282 		}
       
   283 		if ((strstr(buf, SC_MANIFEST_BEGIN_MARKER) != NULL) &&
       
   284 		    (! writing_ai_manifest)) {
   280 			writing_sc_manifest = B_TRUE;
   285 			writing_sc_manifest = B_TRUE;
   281 
   286 
   282 			/*
   287 			/*
   283 			 * XML is pretty strict about format of XML prolog.
   288 			 * XML is pretty strict about format of XML prolog.
   284 			 * It is optional, but if present, no leading comments
   289 			 * It is optional, but if present, no leading comments
   290 			fputs(SC_MANIFEST_BEGIN_MARKER, scfp);
   295 			fputs(SC_MANIFEST_BEGIN_MARKER, scfp);
   291 			fputs("\n", scfp);
   296 			fputs("\n", scfp);
   292 			continue;
   297 			continue;
   293 		}
   298 		}
   294 		if (writing_ai_manifest) {
   299 		if (writing_ai_manifest) {
   295 			if (strstr(buf, AI_MANIFEST_END_MARKER) != NULL) {
       
   296 				writing_ai_manifest = B_FALSE;
       
   297 			}
       
   298 			fputs(buf, aifp);
   300 			fputs(buf, aifp);
   299 			continue;
   301 			continue;
   300 		} else if (writing_sc_manifest) {
   302 		} else if (writing_sc_manifest) {
   301 			if (strstr(buf, SC_MANIFEST_END_MARKER) != NULL) {
   303 			if (strstr(buf, SC_MANIFEST_END_MARKER) != NULL) {
   302 				writing_sc_manifest = B_FALSE;
   304 				writing_sc_manifest = B_FALSE;
   384 	if (pkg_list_type == AI_PACKAGE_LIST_INSTALL) {
   386 	if (pkg_list_type == AI_PACKAGE_LIST_INSTALL) {
   385 		package_list = ai_get_manifest_packages(&num_packages,
   387 		package_list = ai_get_manifest_packages(&num_packages,
   386 		    AIM_PACKAGE_INSTALL_NAME);
   388 		    AIM_PACKAGE_INSTALL_NAME);
   387 
   389 
   388 		if (package_list == NULL) {
   390 		if (package_list == NULL) {
   389 			auto_debug_print(AUTO_DBGLVL_INFO,
   391 			/* If no package list given, use default */
   390 			    "Tag %s not available, %s will be tried\n",
       
   391 			    AIM_PACKAGE_INSTALL_NAME,
       
   392 			    AIM_OLD_PACKAGE_INSTALL_NAME);
       
   393 
       
   394 			package_list = ai_get_manifest_packages(&num_packages,
       
   395 			    AIM_OLD_PACKAGE_INSTALL_NAME);
       
   396 		}
       
   397 
       
   398 		if (package_list == NULL) {
       
   399 			auto_debug_print(AUTO_DBGLVL_ERR,
   392 			auto_debug_print(AUTO_DBGLVL_ERR,
   400 			    "Couldn't obtain list of packages to be "
   393 			    "No install package list given, using default\n");
   401 			    "installed\n");
   394 
   402 
   395 			num_packages = 4;
   403 			(void) fclose(fp);
   396 			package_list = malloc((num_packages + 1) * sizeof (char *));
   404 			return (AUTO_INSTALL_FAILURE);
   397 			package_list[0] = strdup("pkg:/SUNWcsd");
       
   398 			package_list[1] = strdup("pkg:/SUNWcs");
       
   399 			package_list[2] = strdup("pkg:/babel_install");
       
   400 			package_list[3] = strdup("pkg:/entire");
       
   401 			package_list[4] = NULL;
   405 		}
   402 		}
   406 
   403 
   407 		auto_log_print(gettext(
   404 		auto_log_print(gettext(
   408 		    "list of packages to be installed is:\n"));
   405 		    "list of packages to be installed is:\n"));
   409 	} else {
   406 	} else {
   748 	return (0);
   745 	return (0);
   749 }
   746 }
   750 
   747 
   751 /*
   748 /*
   752  * Install the target based on the criteria specified in
   749  * Install the target based on the criteria specified in
   753  * the ai_manifest.xml.
   750  * ai.xml.
   754  *
   751  *
   755  * NOTE: ai_validate_manifest() MUST have been called prior
   752  * NOTE: ai_validate_manifest() MUST have been called prior
   756  * to calling this function.
   753  * to calling this function.
   757  *
   754  *
   758  * RETURNS:
   755  * RETURNS:
  1419 }
  1416 }
  1420 
  1417 
  1421 /*
  1418 /*
  1422  * Install the target based on the specified diskname
  1419  * Install the target based on the specified diskname
  1423  * or if no diskname is specified, install it based on
  1420  * or if no diskname is specified, install it based on
  1424  * the criteria specified in the ai_manifest.xml.
  1421  * the criteria specified in ai.xml.
  1425  *
  1422  *
  1426  * Returns
  1423  * Returns
  1427  *	AUTO_INSTALL_SUCCESS on a successful install
  1424  *	AUTO_INSTALL_SUCCESS on a successful install
  1428  *	AUTO_INSTALL_FAILURE on a failed install
  1425  *	AUTO_INSTALL_FAILURE on a failed install
  1429  */
  1426  */
  1806 
  1803 
  1807 	if (profile[0] != '\0') {
  1804 	if (profile[0] != '\0') {
  1808 		char	*ai_auto_reboot;
  1805 		char	*ai_auto_reboot;
  1809 
  1806 
  1810 		/*
  1807 		/*
  1811 		 * We are passed in a combined AI and SC manifest.
  1808 		 * We are passed in an AI manifest with an embedded
  1812 		 * Before we doing anything meaningful, they must
  1809 		 * SC manifest, both in DTD format. We want to
  1813 		 * be separated since they're in two different
  1810 		 * separate them.
  1814 		 * formats
       
  1815 		 *
       
  1816 		 * The AI manifest is in RelaxNG format whereas the
       
  1817 		 * SC manifest is in a DTD format.
       
  1818 		 */
  1811 		 */
  1819 		if (auto_split_manifests(profile, AI_MANIFEST_FILE,
  1812 		if (auto_split_manifests(profile, AI_MANIFEST_FILE,
  1820 		    SC_MANIFEST_FILE) != AUTO_VALID_MANIFEST) {
  1813 		    SC_MANIFEST_FILE) != AUTO_VALID_MANIFEST) {
  1821 			auto_log_print(gettext("Auto install failed. Invalid "
  1814 			auto_log_print(gettext("Auto install failed. Invalid "
  1822 			    "manifest file %s specified\n"), profile);
  1815 			    "manifest file %s specified\n"), profile);
  1836 			auto_log_print(gettext("Auto install failed. Error "
  1829 			auto_log_print(gettext("Auto install failed. Error "
  1837 			    "creating manifest %s\n"), profile);
  1830 			    "creating manifest %s\n"), profile);
  1838 			exit(AI_EXIT_FAILURE_AIM);
  1831 			exit(AI_EXIT_FAILURE_AIM);
  1839 		}
  1832 		}
  1840 
  1833 
       
  1834 		if (ai_setup_manifest_image() == AUTO_VALID_MANIFEST) {
       
  1835 			auto_log_print(gettext(
       
  1836 			    "%s manifest setup and validated\n"), profile);
       
  1837 		} else {
       
  1838 			char *setup_err = gettext("Auto install failed. Error "
       
  1839 			    "setting up and validating manifest %s\n");
       
  1840 			auto_log_print(setup_err, profile);
       
  1841 			(void) fprintf(stderr, setup_err, profile);
       
  1842 			exit(AI_EXIT_FAILURE_AIM);
       
  1843 		}
       
  1844 
  1841 		/*
  1845 		/*
  1842 		 * Install any drivers required for installation, in the
  1846 		 * Install any drivers required for installation, in the
  1843 		 * booted environment.  This must be done before semantic
  1847 		 * booted environment.
  1844 		 * validation, since this may add required devices which
       
  1845 		 * are needed to pass validation.
       
  1846 		 */
  1848 		 */
  1847 
  1849 
  1848 		/*
  1850 		/*
  1849 		 * First boolean: do not honor noinstall flag.
  1851 		 * First boolean: do not honor noinstall flag.
  1850 		 * Second boolean: do not update the boot archive.
  1852 		 * Second boolean: do not update the boot archive.
  1867 			    "  These drivers may or may not be required for "
  1869 			    "  These drivers may or may not be required for "
  1868 			    "the installation to proceed.\n"
  1870 			    "the installation to proceed.\n"
  1869 			    "  Will continue anyway...\n");
  1871 			    "  Will continue anyway...\n");
  1870 			auto_log_print(du_warning);
  1872 			auto_log_print(du_warning);
  1871 			(void) fprintf(stderr, du_warning);
  1873 			(void) fprintf(stderr, du_warning);
  1872 		}
       
  1873 
       
  1874 		if (ai_setup_manifest_image() == AUTO_VALID_MANIFEST) {
       
  1875 			auto_log_print(gettext(
       
  1876 			    "%s manifest setup and validated\n"), profile);
       
  1877 		} else {
       
  1878 			char *setup_err = gettext("Auto install failed. Error "
       
  1879 			    "setting up and validating manifest %s\n");
       
  1880 			auto_log_print(setup_err, profile);
       
  1881 			(void) fprintf(stderr, setup_err, profile);
       
  1882 			exit(AI_EXIT_FAILURE_AIM);
       
  1883 		}
  1874 		}
  1884 
  1875 
  1885 		diskname[0] = '\0';
  1876 		diskname[0] = '\0';
  1886 
  1877 
  1887 		/*
  1878 		/*