15c51f124SMoriah Waterland /* 25c51f124SMoriah Waterland * CDDL HEADER START 35c51f124SMoriah Waterland * 45c51f124SMoriah Waterland * The contents of this file are subject to the terms of the 55c51f124SMoriah Waterland * Common Development and Distribution License (the "License"). 65c51f124SMoriah Waterland * You may not use this file except in compliance with the License. 75c51f124SMoriah Waterland * 85c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing. 105c51f124SMoriah Waterland * See the License for the specific language governing permissions 115c51f124SMoriah Waterland * and limitations under the License. 125c51f124SMoriah Waterland * 135c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each 145c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the 165c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying 175c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner] 185c51f124SMoriah Waterland * 195c51f124SMoriah Waterland * CDDL HEADER END 205c51f124SMoriah Waterland */ 215c51f124SMoriah Waterland 225c51f124SMoriah Waterland /* 23a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 245c51f124SMoriah Waterland */ 255c51f124SMoriah Waterland 265c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 275c51f124SMoriah Waterland /* All Rights Reserved */ 285c51f124SMoriah Waterland 295c51f124SMoriah Waterland 305c51f124SMoriah Waterland #include <stdio.h> 315c51f124SMoriah Waterland #include <time.h> 325c51f124SMoriah Waterland #include <wait.h> 335c51f124SMoriah Waterland #include <stdlib.h> 345c51f124SMoriah Waterland #include <unistd.h> 355c51f124SMoriah Waterland #include <ulimit.h> 365c51f124SMoriah Waterland #include <sys/stat.h> 375c51f124SMoriah Waterland #include <sys/statvfs.h> 385c51f124SMoriah Waterland #include <fcntl.h> 395c51f124SMoriah Waterland #include <errno.h> 405c51f124SMoriah Waterland #include <ctype.h> 415c51f124SMoriah Waterland #include <dirent.h> 425c51f124SMoriah Waterland #include <string.h> 435c51f124SMoriah Waterland #include <signal.h> 445c51f124SMoriah Waterland #include <locale.h> 455c51f124SMoriah Waterland #include <libintl.h> 465c51f124SMoriah Waterland #include <pkgstrct.h> 475c51f124SMoriah Waterland #include <pkginfo.h> 485c51f124SMoriah Waterland #include <pkgdev.h> 495c51f124SMoriah Waterland #include <pkglocs.h> 505c51f124SMoriah Waterland #include <pwd.h> 515c51f124SMoriah Waterland #include <assert.h> 525c51f124SMoriah Waterland #include <instzones_api.h> 535c51f124SMoriah Waterland #include <pkglib.h> 545c51f124SMoriah Waterland #include <pkgweb.h> 555c51f124SMoriah Waterland #include <install.h> 565c51f124SMoriah Waterland #include <libinst.h> 575c51f124SMoriah Waterland #include <libadm.h> 585c51f124SMoriah Waterland #include <dryrun.h> 595c51f124SMoriah Waterland #include <messages.h> 605c51f124SMoriah Waterland #include "pkginstall.h" 615c51f124SMoriah Waterland 625c51f124SMoriah Waterland /* imported globals */ 635c51f124SMoriah Waterland 645c51f124SMoriah Waterland extern char **environ; 655c51f124SMoriah Waterland extern char *pkgabrv; 665c51f124SMoriah Waterland extern char *pkgname; 675c51f124SMoriah Waterland extern char *pkgarch; 685c51f124SMoriah Waterland extern char *pkgvers; 695c51f124SMoriah Waterland extern char pkgwild[]; 705c51f124SMoriah Waterland 715c51f124SMoriah Waterland /* libadm(3LIB) */ 725c51f124SMoriah Waterland 735c51f124SMoriah Waterland extern char *get_install_root(void); 745c51f124SMoriah Waterland 755c51f124SMoriah Waterland /* quit.c */ 765c51f124SMoriah Waterland 775c51f124SMoriah Waterland extern sighdlrFunc_t *quitGetTrapHandler(void); 785c51f124SMoriah Waterland extern void quitSetDstreamTmpdir(char *a_dstreamTempDir); 795c51f124SMoriah Waterland extern void quitSetInstallStarted(boolean_t a_installStarted); 805c51f124SMoriah Waterland extern void quitSetPkgask(boolean_t a_pkgaskFlag); 815c51f124SMoriah Waterland extern void quitSetSilentExit(boolean_t a_silentExit); 825c51f124SMoriah Waterland extern void quitSetUpdatingExisting(boolean_t a_updatingExisting); 835c51f124SMoriah Waterland extern void quitSetZoneName(char *a_zoneName); 845c51f124SMoriah Waterland 855c51f124SMoriah Waterland 865c51f124SMoriah Waterland /* static globals */ 875c51f124SMoriah Waterland 885c51f124SMoriah Waterland static char path[PATH_MAX]; 895c51f124SMoriah Waterland static int ck_instbase(void); 905c51f124SMoriah Waterland static int cp_pkgdirs(void); 915c51f124SMoriah Waterland static int merg_pkginfos(struct cl_attr **pclass, 925c51f124SMoriah Waterland struct cl_attr ***mpclass); 935c51f124SMoriah Waterland static int merg_respfile(void); 945c51f124SMoriah Waterland static int mv_pkgdirs(void); 955c51f124SMoriah Waterland static int rdonly(char *p); 965c51f124SMoriah Waterland static void ck_w_dryrun(int (*func)(), int type); 975c51f124SMoriah Waterland static void copyright(void), usage(void); 985c51f124SMoriah Waterland static void do_pkgask(boolean_t a_run_request_as_root); 995c51f124SMoriah Waterland static void rm_icas(char *casdir); 1005c51f124SMoriah Waterland static void set_dryrun_dir_loc(void); 1015c51f124SMoriah Waterland static void unpack(void); 1025c51f124SMoriah Waterland 1035c51f124SMoriah Waterland void ckreturn(int retcode, char *msg); 1045c51f124SMoriah Waterland 1055c51f124SMoriah Waterland static char *ro_params[] = { 1065c51f124SMoriah Waterland "PATH", "NAME", "PKG", "PKGINST", 1075c51f124SMoriah Waterland "VERSION", "ARCH", 1085c51f124SMoriah Waterland "INSTDATE", "CATEGORY", 1095c51f124SMoriah Waterland NULL 1105c51f124SMoriah Waterland }; 1115c51f124SMoriah Waterland 1125c51f124SMoriah Waterland /* 1135c51f124SMoriah Waterland * The following variable is the name of the device to which stdin 1145c51f124SMoriah Waterland * is connected during execution of a procedure script. PROC_STDIN is 1155c51f124SMoriah Waterland * correct for all ABI compliant packages. For non-ABI-compliant 1165c51f124SMoriah Waterland * packages, the '-o' command line switch changes this to PROC_XSTDIN 1175c51f124SMoriah Waterland * to allow user interaction during these scripts. -- JST 1185c51f124SMoriah Waterland */ 1195c51f124SMoriah Waterland static char *script_in = PROC_STDIN; /* assume ABI compliance */ 1205c51f124SMoriah Waterland 1215c51f124SMoriah Waterland static char *pkgdrtarg = NULL; 1225c51f124SMoriah Waterland static char *pkgcontsrc = NULL; 1235c51f124SMoriah Waterland static int non_abi_scripts = 0; 1245c51f124SMoriah Waterland static char *respfile = NULL; 1255c51f124SMoriah Waterland static char *srcinst = NULL; 1265c51f124SMoriah Waterland static int suppressCopyright = 0; 1275c51f124SMoriah Waterland static int nointeract = 0; 1285c51f124SMoriah Waterland 1295c51f124SMoriah Waterland /* exported globals */ 1305c51f124SMoriah Waterland 1315c51f124SMoriah Waterland char *msgtext; 1325c51f124SMoriah Waterland char *pkginst = (char *)NULL; 1335c51f124SMoriah Waterland char *rw_block_size = NULL; 1345c51f124SMoriah Waterland char ilockfile[PATH_MAX]; 1355c51f124SMoriah Waterland char instdir[PATH_MAX]; 1365c51f124SMoriah Waterland char saveSpoolInstallDir[PATH_MAX]; 1375c51f124SMoriah Waterland char pkgbin[PATH_MAX]; 1385c51f124SMoriah Waterland char pkgloc[PATH_MAX]; 1395c51f124SMoriah Waterland char pkgloc_sav[PATH_MAX]; 1405c51f124SMoriah Waterland char pkgsav[PATH_MAX]; 1415c51f124SMoriah Waterland char rlockfile[PATH_MAX]; 1425c51f124SMoriah Waterland char savlog[PATH_MAX]; 1435c51f124SMoriah Waterland char tmpdir[PATH_MAX]; 1445c51f124SMoriah Waterland int dbchg; 1455c51f124SMoriah Waterland int dparts = 0; 1465c51f124SMoriah Waterland int dreboot = 0; 1475c51f124SMoriah Waterland int failflag = 0; 1485c51f124SMoriah Waterland static int askflag = 0; /* non-zero if invoked as "pkgask" */ 1495c51f124SMoriah Waterland int ireboot = 0; 1505c51f124SMoriah Waterland int maxinst = 1; 1515c51f124SMoriah Waterland int nocnflct; 1525c51f124SMoriah Waterland int nosetuid; 1535c51f124SMoriah Waterland int pkgverbose = 0; 1545c51f124SMoriah Waterland int rprcflag; 1555c51f124SMoriah Waterland int warnflag = 0; 1565c51f124SMoriah Waterland struct admin adm; 1575c51f124SMoriah Waterland struct cfextra **extlist; /* pkgmap structure and other path info */ 1585c51f124SMoriah Waterland struct pkgdev pkgdev; 1595c51f124SMoriah Waterland fsblkcnt_t pkgmap_blks = 0LL; 1605c51f124SMoriah Waterland 1615c51f124SMoriah Waterland /* 1625c51f124SMoriah Waterland * this global is referenced by: 1635c51f124SMoriah Waterland * getinst - [RW] - incremented if: 1645c51f124SMoriah Waterland * - installing same instance again 1655c51f124SMoriah Waterland * - overwriting an existing instance 1665c51f124SMoriah Waterland * - not installing a new instance 1675c51f124SMoriah Waterland * quit - [RO] - if non-zero and started non-zero: 1685c51f124SMoriah Waterland * - the new <PKGINST>/install directory and rename <PKGINST>/install.save 1695c51f124SMoriah Waterland * - back to <PKGINST>/install 1705c51f124SMoriah Waterland * main.c - [RO] - if non-zero: 1715c51f124SMoriah Waterland * - alter manner in which parameters are setup for scripts 1725c51f124SMoriah Waterland * - set UPDATE=yes in environment 1735c51f124SMoriah Waterland */ 1745c51f124SMoriah Waterland static int update = 0; 1755c51f124SMoriah Waterland 1765c51f124SMoriah Waterland /* Set by -O debug: debug output is enabled? */ 1775c51f124SMoriah Waterland 1785c51f124SMoriah Waterland static boolean_t debugFlag = B_FALSE; 1795c51f124SMoriah Waterland 1805c51f124SMoriah Waterland /* Set by the -G option: install packages in global zone only */ 1815c51f124SMoriah Waterland 1825c51f124SMoriah Waterland static boolean_t globalZoneOnly = B_FALSE; 1835c51f124SMoriah Waterland 1845c51f124SMoriah Waterland /* Set by -O preinstallcheck */ 1855c51f124SMoriah Waterland 1865c51f124SMoriah Waterland static boolean_t preinstallCheck = B_FALSE; 1875c51f124SMoriah Waterland 1885c51f124SMoriah Waterland /* Set by -O parent-zone-name= */ 1895c51f124SMoriah Waterland 1905c51f124SMoriah Waterland static char *parentZoneName = (char *)NULL; 1915c51f124SMoriah Waterland 1925c51f124SMoriah Waterland /* Set by -O parent-zone-type= */ 1935c51f124SMoriah Waterland 1945c51f124SMoriah Waterland static char *parentZoneType = (char *)NULL; 1955c51f124SMoriah Waterland 1965c51f124SMoriah Waterland #define DEFPATH "/sbin:/usr/sbin:/usr/bin" 1975c51f124SMoriah Waterland #define MALSIZ 4 /* best guess at likely maximum value of MAXINST */ 1985c51f124SMoriah Waterland #define LSIZE 256 /* maximum line size supported in copyright file */ 1995c51f124SMoriah Waterland 2005c51f124SMoriah Waterland #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 2015c51f124SMoriah Waterland #define TEXT_DOMAIN "SYS_TEST" 2025c51f124SMoriah Waterland #endif 2035c51f124SMoriah Waterland 2045c51f124SMoriah Waterland /* This is the text for the "-O parent-zone-name=" option */ 2055c51f124SMoriah Waterland 2065c51f124SMoriah Waterland #define PARENTZONENAME "parent-zone-name=" 2075c51f124SMoriah Waterland #define PARENTZONENAME_LEN ((sizeof (PARENTZONENAME))-1) 2085c51f124SMoriah Waterland 2095c51f124SMoriah Waterland /* This is the text for the "-O parent-zone-type=" option */ 2105c51f124SMoriah Waterland 2115c51f124SMoriah Waterland #define PARENTZONETYPE "parent-zone-type=" 2125c51f124SMoriah Waterland #define PARENTZONETYPE_LEN ((sizeof (PARENTZONETYPE))-1) 2135c51f124SMoriah Waterland 2145c51f124SMoriah Waterland static char *cpio_names[] = { 2155c51f124SMoriah Waterland "root", 2165c51f124SMoriah Waterland "root.cpio", 2175c51f124SMoriah Waterland "reloc", 2185c51f124SMoriah Waterland "reloc.cpio", 2195c51f124SMoriah Waterland "root.Z", 2205c51f124SMoriah Waterland "root.cpio.Z", 2215c51f124SMoriah Waterland "reloc.Z", 2225c51f124SMoriah Waterland "reloc.cpio.Z", 2235c51f124SMoriah Waterland 0 2245c51f124SMoriah Waterland }; 2255c51f124SMoriah Waterland 2265c51f124SMoriah Waterland int 2275c51f124SMoriah Waterland main(int argc, char *argv[]) 2285c51f124SMoriah Waterland { 22962224350SCasper H.S. Dik VFP_T *cfTmpVfp = NULL; /* temporary */ 2305c51f124SMoriah Waterland VFP_T *pkgmapVfp; /* "../pkgmap" file */ 2315c51f124SMoriah Waterland boolean_t run_request_as_root = B_FALSE; 2325c51f124SMoriah Waterland char **np; 2335c51f124SMoriah Waterland char *abi_comp_ptr; 2345c51f124SMoriah Waterland char *abi_nm_ptr; 2355c51f124SMoriah Waterland char *abi_sym_ptr; 2365c51f124SMoriah Waterland char *admnfile = NULL; 2375c51f124SMoriah Waterland char *device; 2385c51f124SMoriah Waterland char *p; 2395c51f124SMoriah Waterland char *prog_full_name = NULL; 2405c51f124SMoriah Waterland char *pt; 2415c51f124SMoriah Waterland char *updated = (char *)NULL; 2425c51f124SMoriah Waterland char *vfstab_file = NULL; 2435c51f124SMoriah Waterland char *zoneName = (char *)NULL; 2445c51f124SMoriah Waterland char cbuf[MAX_PKG_PARAM_LENGTH]; 2455c51f124SMoriah Waterland char cmdbin[PATH_MAX]; 2465c51f124SMoriah Waterland char p_pkginfo[PATH_MAX]; 2475c51f124SMoriah Waterland char p_pkgmap[PATH_MAX]; 2485c51f124SMoriah Waterland char param[MAX_PKG_PARAM_LENGTH]; 2495c51f124SMoriah Waterland char script[PATH_MAX]; 2505c51f124SMoriah Waterland char altscript[PATH_MAX]; 251a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" char *temp; 2525c51f124SMoriah Waterland int c; 2535c51f124SMoriah Waterland int disableAttributes = 0; 2545c51f124SMoriah Waterland int err; 2555c51f124SMoriah Waterland int init_install = 0; 2565c51f124SMoriah Waterland int is_comp_arch; 2575c51f124SMoriah Waterland int live_continue = 0; 2585c51f124SMoriah Waterland int map_client = 1; 2595c51f124SMoriah Waterland int n; 2605c51f124SMoriah Waterland int nparts; 2615c51f124SMoriah Waterland int npkgs; 2625c51f124SMoriah Waterland int part; 2635c51f124SMoriah Waterland int saveSpoolInstall = 0; 2645c51f124SMoriah Waterland boolean_t cont_file_read; 2655c51f124SMoriah Waterland struct cl_attr **pclass = NULL; 2665c51f124SMoriah Waterland struct cl_attr **mergd_pclass = NULL; 2675c51f124SMoriah Waterland struct pkginfo *prvinfo; 2685c51f124SMoriah Waterland struct sigaction nact; 2695c51f124SMoriah Waterland struct sigaction oact; 2705c51f124SMoriah Waterland struct stat statb; 2715c51f124SMoriah Waterland struct statvfs64 svfsb; 2725c51f124SMoriah Waterland time_t clock; 27362224350SCasper H.S. Dik PKGserver pkgserver = NULL; 2745c51f124SMoriah Waterland 2755c51f124SMoriah Waterland /* reset contents of all default paths */ 2765c51f124SMoriah Waterland 2775c51f124SMoriah Waterland (void) memset(path, '\0', sizeof (path)); 2785c51f124SMoriah Waterland (void) memset(cmdbin, '\0', sizeof (cmdbin)); 2795c51f124SMoriah Waterland (void) memset(script, '\0', sizeof (script)); 2805c51f124SMoriah Waterland (void) memset(cbuf, '\0', sizeof (cbuf)); 2815c51f124SMoriah Waterland (void) memset(param, '\0', sizeof (param)); 2825c51f124SMoriah Waterland 2835c51f124SMoriah Waterland /* initialize locale environment */ 2845c51f124SMoriah Waterland 2855c51f124SMoriah Waterland (void) setlocale(LC_ALL, ""); 2865c51f124SMoriah Waterland (void) textdomain(TEXT_DOMAIN); 2875c51f124SMoriah Waterland 2885c51f124SMoriah Waterland /* initialize program name */ 2895c51f124SMoriah Waterland 2905c51f124SMoriah Waterland prog_full_name = argv[0]; 2915c51f124SMoriah Waterland (void) set_prog_name(argv[0]); 2925c51f124SMoriah Waterland 2935c51f124SMoriah Waterland /* tell spmi zones interface how to access package output functions */ 2945c51f124SMoriah Waterland 2955c51f124SMoriah Waterland z_set_output_functions(echo, echoDebug, progerr); 2965c51f124SMoriah Waterland 2975c51f124SMoriah Waterland /* exit if not root */ 2985c51f124SMoriah Waterland 2995c51f124SMoriah Waterland if (getuid()) { 3005c51f124SMoriah Waterland progerr(ERR_NOT_ROOT, get_prog_name()); 3015c51f124SMoriah Waterland exit(1); 3025c51f124SMoriah Waterland /* NOTREACHED */ 3035c51f124SMoriah Waterland } 3045c51f124SMoriah Waterland 3055c51f124SMoriah Waterland /* 3065c51f124SMoriah Waterland * determine how pkgmap() deals with environment variables: 3075c51f124SMoriah Waterland * - MAPALL - resolve all variables 3085c51f124SMoriah Waterland * - MAPBUILD - map only build variables 3095c51f124SMoriah Waterland * - MAPINSTALL - map only install variables 3105c51f124SMoriah Waterland * - MAPNONE - map no variables 3115c51f124SMoriah Waterland */ 3125c51f124SMoriah Waterland 3135c51f124SMoriah Waterland setmapmode(MAPINSTALL); 3145c51f124SMoriah Waterland 3155c51f124SMoriah Waterland /* set sane umask */ 3165c51f124SMoriah Waterland 3175c51f124SMoriah Waterland (void) umask(0022); 3185c51f124SMoriah Waterland 3195c51f124SMoriah Waterland /* initially no source "device" */ 3205c51f124SMoriah Waterland 3215c51f124SMoriah Waterland device = NULL; 3225c51f124SMoriah Waterland 3235c51f124SMoriah Waterland /* reset npkgs (used as pkg remaining count in quit.c) */ 3245c51f124SMoriah Waterland 3255c51f124SMoriah Waterland npkgs = 0; 3265c51f124SMoriah Waterland 3275c51f124SMoriah Waterland /* Read PKG_INSTALL_ROOT from the environment, if it's there. */ 3285c51f124SMoriah Waterland 3295c51f124SMoriah Waterland if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) { 3305c51f124SMoriah Waterland progerr(ERR_ROOT_SET); 3315c51f124SMoriah Waterland exit(1); 3325c51f124SMoriah Waterland } 3335c51f124SMoriah Waterland 33462224350SCasper H.S. Dik pkgserversetmode(DEFAULTMODE); 33562224350SCasper H.S. Dik 3365c51f124SMoriah Waterland /* parse command line options */ 3375c51f124SMoriah Waterland 3385c51f124SMoriah Waterland while ((c = getopt(argc, argv, 3395c51f124SMoriah Waterland "?Aa:B:b:Cc:D:d:eFf:GhIiMm:N:noO:p:R:r:StV:vyz")) != EOF) { 3405c51f124SMoriah Waterland 3415c51f124SMoriah Waterland switch (c) { 3425c51f124SMoriah Waterland 3435c51f124SMoriah Waterland /* 3445c51f124SMoriah Waterland * Same as pkgadd: This disables attribute checking. 3455c51f124SMoriah Waterland * It speeds up installation a little bit. 3465c51f124SMoriah Waterland */ 3475c51f124SMoriah Waterland case 'A': 3485c51f124SMoriah Waterland disableAttributes++; 3495c51f124SMoriah Waterland break; 3505c51f124SMoriah Waterland 3515c51f124SMoriah Waterland /* 3525c51f124SMoriah Waterland * Same as pkgadd: Define an installation administration 3535c51f124SMoriah Waterland * file, admin, to be used in place of the default 3545c51f124SMoriah Waterland * administration file. The token none overrides the use 3555c51f124SMoriah Waterland * of any admin file, and thus forces interaction with the 3565c51f124SMoriah Waterland * user. Unless a full path name is given, pkgadd first 3575c51f124SMoriah Waterland * looks in the current working directory for the 3585c51f124SMoriah Waterland * administration file. If the specified administration 3595c51f124SMoriah Waterland * file is not in the current working directory, pkgadd 3605c51f124SMoriah Waterland * looks in the /var/sadm/install/admin directory for the 3615c51f124SMoriah Waterland * administration file. 3625c51f124SMoriah Waterland */ 3635c51f124SMoriah Waterland case 'a': 3645c51f124SMoriah Waterland admnfile = flex_device(optarg, 0); 3655c51f124SMoriah Waterland break; 3665c51f124SMoriah Waterland 3675c51f124SMoriah Waterland /* 3685c51f124SMoriah Waterland * Same as pkgadd: control block size given to 3695c51f124SMoriah Waterland * pkginstall - block size used in read()/write() loop; 3705c51f124SMoriah Waterland * default is st_blksize from stat() of source file. 3715c51f124SMoriah Waterland */ 3725c51f124SMoriah Waterland case 'B': 3735c51f124SMoriah Waterland rw_block_size = optarg; 3745c51f124SMoriah Waterland break; 3755c51f124SMoriah Waterland 3765c51f124SMoriah Waterland /* 3775c51f124SMoriah Waterland * Same as pkgadd: location where executables needed 3785c51f124SMoriah Waterland * by procedure scripts can be found 3795c51f124SMoriah Waterland * default is /usr/sadm/install/bin. 3805c51f124SMoriah Waterland */ 3815c51f124SMoriah Waterland case 'b': 3825c51f124SMoriah Waterland if (!path_valid(optarg)) { 3835c51f124SMoriah Waterland progerr(ERR_PATH, optarg); 3845c51f124SMoriah Waterland exit(1); 3855c51f124SMoriah Waterland } 3865c51f124SMoriah Waterland if (isdir(optarg) != 0) { 3875c51f124SMoriah Waterland char *p = strerror(errno); 3885c51f124SMoriah Waterland progerr(ERR_CANNOT_USE_DIR, optarg, p); 3895c51f124SMoriah Waterland exit(1); 3905c51f124SMoriah Waterland } 3915c51f124SMoriah Waterland (void) strlcpy(cmdbin, optarg, sizeof (cmdbin)); 3925c51f124SMoriah Waterland break; 3935c51f124SMoriah Waterland 3945c51f124SMoriah Waterland /* 3955c51f124SMoriah Waterland * Same as pkgadd: This disables checksum tests on 3965c51f124SMoriah Waterland * the source files. It speeds up installation a little bit. 3975c51f124SMoriah Waterland */ 3985c51f124SMoriah Waterland case 'C': 3995c51f124SMoriah Waterland (void) checksum_off(); 4005c51f124SMoriah Waterland break; 4015c51f124SMoriah Waterland 4025c51f124SMoriah Waterland /* 4035c51f124SMoriah Waterland * Same as pkgadd: This allows designation of a 4045c51f124SMoriah Waterland * continuation file. It is the same format as a dryrun file 4055c51f124SMoriah Waterland * but it is used to take up where the dryrun left off. 4065c51f124SMoriah Waterland */ 4075c51f124SMoriah Waterland case 'c': 4085c51f124SMoriah Waterland pkgcontsrc = optarg; 4095c51f124SMoriah Waterland set_continue_mode(); 4105c51f124SMoriah Waterland set_dr_info(DR_TYPE, INSTALL_TYPE); 4115c51f124SMoriah Waterland init_contfile(pkgcontsrc); 4125c51f124SMoriah Waterland break; 4135c51f124SMoriah Waterland 4145c51f124SMoriah Waterland /* 4155c51f124SMoriah Waterland * Same as pkgadd: This allows designation of a 4165c51f124SMoriah Waterland * dryrun file. This pkgadd will create dryrun files 4175c51f124SMoriah Waterland * in the directory provided. 4185c51f124SMoriah Waterland */ 4195c51f124SMoriah Waterland case 'D': 4205c51f124SMoriah Waterland pkgdrtarg = optarg; 4215c51f124SMoriah Waterland set_dryrun_mode(); 4225c51f124SMoriah Waterland set_dr_info(DR_TYPE, INSTALL_TYPE); 4235c51f124SMoriah Waterland break; 4245c51f124SMoriah Waterland 4255c51f124SMoriah Waterland /* 4265c51f124SMoriah Waterland * Same as pkgadd: Install or copy a package from 4275c51f124SMoriah Waterland * device. device can be a full path name to a directory 4285c51f124SMoriah Waterland * or the identifiers for tape, floppy disk, or removable 4295c51f124SMoriah Waterland * disk - for example, /var/tmp or /floppy/floppy_name. 4305c51f124SMoriah Waterland * It can also be a device alias - for example, 4315c51f124SMoriah Waterland * /floppy/floppy0, or a datastream created by pkgtrans. 4325c51f124SMoriah Waterland */ 4335c51f124SMoriah Waterland case 'd': 4345c51f124SMoriah Waterland device = flex_device(optarg, 1); 4355c51f124SMoriah Waterland break; 4365c51f124SMoriah Waterland 4375c51f124SMoriah Waterland /* 4385c51f124SMoriah Waterland * Different from pkgadd: disable the 32 char name 4395c51f124SMoriah Waterland * limit extension 4405c51f124SMoriah Waterland */ 4415c51f124SMoriah Waterland case 'e': 4425c51f124SMoriah Waterland (void) set_ABI_namelngth(); 4435c51f124SMoriah Waterland break; 4445c51f124SMoriah Waterland 4455c51f124SMoriah Waterland /* 4465c51f124SMoriah Waterland * Different from pkgadd: specify file system type for 4475c51f124SMoriah Waterland * the package device. Must be used with -m. 4485c51f124SMoriah Waterland */ 4495c51f124SMoriah Waterland case 'f': 4505c51f124SMoriah Waterland pkgdev.fstyp = optarg; 4515c51f124SMoriah Waterland break; 4525c51f124SMoriah Waterland 4535c51f124SMoriah Waterland /* 4545c51f124SMoriah Waterland * Same as pkgadd: install package in global zone only. 4555c51f124SMoriah Waterland */ 4565c51f124SMoriah Waterland case 'G': 4575c51f124SMoriah Waterland globalZoneOnly = B_TRUE; 4585c51f124SMoriah Waterland break; 4595c51f124SMoriah Waterland 4605c51f124SMoriah Waterland /* 4615c51f124SMoriah Waterland * Same as pkgadd: Enable hollow package support. When 4625c51f124SMoriah Waterland * specified, for any package that has SUNW_PKG_HOLLOW=true: 4635c51f124SMoriah Waterland * Do not calculate and verify package size against target. 4645c51f124SMoriah Waterland * Do not run any package procedure or class action scripts. 4655c51f124SMoriah Waterland * Do not create any target directories. 4665c51f124SMoriah Waterland * Do not perform any script locking. 4675c51f124SMoriah Waterland * Do not install any components of any package. 4685c51f124SMoriah Waterland * Do not output any status or database update messages. 4695c51f124SMoriah Waterland */ 4705c51f124SMoriah Waterland case 'h': 4715c51f124SMoriah Waterland set_depend_pkginfo_DB(B_TRUE); 4725c51f124SMoriah Waterland break; 4735c51f124SMoriah Waterland 4745c51f124SMoriah Waterland /* 4755c51f124SMoriah Waterland * Same as pkgadd: Informs scripts that this is 4765c51f124SMoriah Waterland * an initial install by setting the environment parameter 4775c51f124SMoriah Waterland * PKG_INIT_INSTALL=TRUE for all scripts. They may use it as 4785c51f124SMoriah Waterland * they see fit, safe in the knowledge that the target 4795c51f124SMoriah Waterland * filesystem is tabula rasa. 4805c51f124SMoriah Waterland */ 4815c51f124SMoriah Waterland case 'I': 4825c51f124SMoriah Waterland init_install++; 4835c51f124SMoriah Waterland break; 4845c51f124SMoriah Waterland 4855c51f124SMoriah Waterland /* 4865c51f124SMoriah Waterland * Different from pkgadd: use by pkgask. 4875c51f124SMoriah Waterland */ 4885c51f124SMoriah Waterland case 'i': 4895c51f124SMoriah Waterland askflag++; 4905c51f124SMoriah Waterland quitSetPkgask(B_TRUE); 4915c51f124SMoriah Waterland break; 4925c51f124SMoriah Waterland 4935c51f124SMoriah Waterland /* 4945c51f124SMoriah Waterland * Same as pkgadd: Instruct pkgadd not to use the 4955c51f124SMoriah Waterland * $root_path/etc/vfstab file for determining the client's 4965c51f124SMoriah Waterland * mount points. This option assumes the mount points are 4975c51f124SMoriah Waterland * correct on the server and it behaves consistently with 4985c51f124SMoriah Waterland * Solaris 2.5 and earlier releases. 4995c51f124SMoriah Waterland */ 5005c51f124SMoriah Waterland case 'M': 5015c51f124SMoriah Waterland map_client = 0; 5025c51f124SMoriah Waterland break; 5035c51f124SMoriah Waterland 5045c51f124SMoriah Waterland /* 5055c51f124SMoriah Waterland * Different from pkgadd: specify device to use for package 5065c51f124SMoriah Waterland * source. 5075c51f124SMoriah Waterland */ 5085c51f124SMoriah Waterland case 'm': 5095c51f124SMoriah Waterland pkgdev.mount = optarg; 5105c51f124SMoriah Waterland pkgdev.rdonly++; 5115c51f124SMoriah Waterland pkgdev.mntflg++; 5125c51f124SMoriah Waterland break; 5135c51f124SMoriah Waterland 5145c51f124SMoriah Waterland /* 5155c51f124SMoriah Waterland * Different from pkgadd: specify program name to use 5165c51f124SMoriah Waterland * for messages. 5175c51f124SMoriah Waterland */ 5185c51f124SMoriah Waterland case 'N': 5195c51f124SMoriah Waterland (void) set_prog_name(optarg); 5205c51f124SMoriah Waterland break; 5215c51f124SMoriah Waterland 5225c51f124SMoriah Waterland /* 5235c51f124SMoriah Waterland * Same as pkgadd: installation occurs in 5245c51f124SMoriah Waterland * non-interactive mode. Suppress output of the list of 5255c51f124SMoriah Waterland * installed files. The default mode is interactive. 5265c51f124SMoriah Waterland */ 5275c51f124SMoriah Waterland case 'n': 5285c51f124SMoriah Waterland nointeract++; 5295c51f124SMoriah Waterland (void) echoSetFlag(B_FALSE); 5305c51f124SMoriah Waterland break; 5315c51f124SMoriah Waterland 5325c51f124SMoriah Waterland /* 5335c51f124SMoriah Waterland * Almost same as pkgadd: the -O option allows the behavior 5345c51f124SMoriah Waterland * of the package tools to be modified. Recognized options: 5355c51f124SMoriah Waterland * -> debug 5365c51f124SMoriah Waterland * ---> enable debugging output 5375c51f124SMoriah Waterland * -> preinstallcheck 5385c51f124SMoriah Waterland * ---> perform a "pre installation" check of the specified 5395c51f124SMoriah Waterland * ---> package - suppress all regular output and cause a 5405c51f124SMoriah Waterland * ---> series of one or more "name=value" pair format lines 5415c51f124SMoriah Waterland * ---> to be output that describes the "installability" of 5425c51f124SMoriah Waterland * ---> the specified package 5435c51f124SMoriah Waterland * -> enable-hollow-package-support 5445c51f124SMoriah Waterland * --> Enable hollow package support. When specified, for any 5455c51f124SMoriah Waterland * --> package that has SUNW_PKG_HOLLOW=true: 5465c51f124SMoriah Waterland * --> Do not calculate and verify package size against target 5475c51f124SMoriah Waterland * --> Do not run any package procedure or class action scripts 5485c51f124SMoriah Waterland * --> Do not create or remove any target directories 5495c51f124SMoriah Waterland * --> Do not perform any script locking 5505c51f124SMoriah Waterland * --> Do not install or uninstall any components of any package 5515c51f124SMoriah Waterland * --> Do not output any status or database update messages 5525c51f124SMoriah Waterland */ 5535c51f124SMoriah Waterland case 'O': 5545c51f124SMoriah Waterland for (p = strtok(optarg, ","); p != (char *)NULL; 5555c51f124SMoriah Waterland p = strtok(NULL, ",")) { 5565c51f124SMoriah Waterland 5575c51f124SMoriah Waterland /* process debug option */ 5585c51f124SMoriah Waterland 5595c51f124SMoriah Waterland if (strcmp(p, "debug") == 0) { 5605c51f124SMoriah Waterland /* set debug flag/enable debug output */ 5615c51f124SMoriah Waterland if (debugFlag == B_TRUE) { 5625c51f124SMoriah Waterland smlSetVerbose(B_TRUE); 5635c51f124SMoriah Waterland } 5645c51f124SMoriah Waterland debugFlag = B_TRUE; 5655c51f124SMoriah Waterland (void) echoDebugSetFlag(debugFlag); 5665c51f124SMoriah Waterland 5675c51f124SMoriah Waterland /* debug info on arguments to pkgadd */ 5685c51f124SMoriah Waterland for (n = 0; n < argc && argv[n]; n++) { 5695c51f124SMoriah Waterland echoDebug(DBG_ARG, n, argv[n]); 5705c51f124SMoriah Waterland } 5715c51f124SMoriah Waterland 5725c51f124SMoriah Waterland continue; 5735c51f124SMoriah Waterland } 5745c51f124SMoriah Waterland 5755c51f124SMoriah Waterland /* process enable-hollow-package-support opt */ 5765c51f124SMoriah Waterland 5775c51f124SMoriah Waterland if (strcmp(p, 5785c51f124SMoriah Waterland "enable-hollow-package-support") == 0) { 5795c51f124SMoriah Waterland set_depend_pkginfo_DB(B_TRUE); 5805c51f124SMoriah Waterland continue; 5815c51f124SMoriah Waterland } 5825c51f124SMoriah Waterland 5835c51f124SMoriah Waterland /* process preinstallcheck option */ 5845c51f124SMoriah Waterland 5855c51f124SMoriah Waterland if (strcmp(p, "preinstallcheck") == 0) { 5865c51f124SMoriah Waterland preinstallCheck = B_TRUE; 5875c51f124SMoriah Waterland nointeract++; /* -n */ 5885c51f124SMoriah Waterland suppressCopyright++; /* -S */ 5895c51f124SMoriah Waterland quitSetSilentExit(B_TRUE); 5905c51f124SMoriah Waterland continue; 5915c51f124SMoriah Waterland } 5925c51f124SMoriah Waterland 5935c51f124SMoriah Waterland /* process addzonename option */ 5945c51f124SMoriah Waterland 5955c51f124SMoriah Waterland if (strcmp(p, "addzonename") == 0) { 5965c51f124SMoriah Waterland /* 5975c51f124SMoriah Waterland * set zone name to add to messages; 5985c51f124SMoriah Waterland * first look in the current environment 5995c51f124SMoriah Waterland * and use the default package zone name 6005c51f124SMoriah Waterland * if it is set; otherwise, use the name 6015c51f124SMoriah Waterland * of the current zone 6025c51f124SMoriah Waterland */ 6035c51f124SMoriah Waterland zoneName = 6045c51f124SMoriah Waterland getenv(PKG_ZONENAME_VARIABLE); 6055c51f124SMoriah Waterland 6065c51f124SMoriah Waterland if ((zoneName == (char *)NULL) || 6075c51f124SMoriah Waterland (*zoneName == '\0')) { 6085c51f124SMoriah Waterland zoneName = z_get_zonename(); 6095c51f124SMoriah Waterland } 6105c51f124SMoriah Waterland 6115c51f124SMoriah Waterland if (zoneName != (char *)NULL) { 6125c51f124SMoriah Waterland if (*zoneName != '\0') { 6135c51f124SMoriah Waterland quitSetZoneName( 6145c51f124SMoriah Waterland zoneName); 6155c51f124SMoriah Waterland } else { 6165c51f124SMoriah Waterland zoneName = (char *)NULL; 6175c51f124SMoriah Waterland } 6185c51f124SMoriah Waterland } 6195c51f124SMoriah Waterland continue; 6205c51f124SMoriah Waterland } 6215c51f124SMoriah Waterland 6225c51f124SMoriah Waterland /* process parent-zone-name option */ 6235c51f124SMoriah Waterland 6245c51f124SMoriah Waterland if (strncmp(p, PARENTZONENAME, 6255c51f124SMoriah Waterland PARENTZONENAME_LEN) == 0) { 6265c51f124SMoriah Waterland parentZoneName = p+PARENTZONENAME_LEN; 6275c51f124SMoriah Waterland continue; 6285c51f124SMoriah Waterland } 6295c51f124SMoriah Waterland 6305c51f124SMoriah Waterland /* process parent-zone-type option */ 6315c51f124SMoriah Waterland 6325c51f124SMoriah Waterland if (strncmp(p, PARENTZONETYPE, 6335c51f124SMoriah Waterland PARENTZONETYPE_LEN) == 0) { 6345c51f124SMoriah Waterland parentZoneType = p+PARENTZONETYPE_LEN; 6355c51f124SMoriah Waterland continue; 6365c51f124SMoriah Waterland } 6375c51f124SMoriah Waterland 63862224350SCasper H.S. Dik if (strncmp(p, PKGSERV_MODE, 63962224350SCasper H.S. Dik PKGSERV_MODE_LEN) == 0) { 64062224350SCasper H.S. Dik pkgserversetmode(pkgparsemode(p + 64162224350SCasper H.S. Dik PKGSERV_MODE_LEN)); 64262224350SCasper H.S. Dik continue; 64362224350SCasper H.S. Dik } 64462224350SCasper H.S. Dik 6455c51f124SMoriah Waterland /* option not recognized - issue warning */ 6465c51f124SMoriah Waterland 6475c51f124SMoriah Waterland progerr(ERR_INVALID_O_OPTION, p); 6485c51f124SMoriah Waterland continue; 6495c51f124SMoriah Waterland 6505c51f124SMoriah Waterland } 6515c51f124SMoriah Waterland break; 6525c51f124SMoriah Waterland 6535c51f124SMoriah Waterland /* 6545c51f124SMoriah Waterland * Different from pkgadd: This is an old non-ABI package 6555c51f124SMoriah Waterland */ 6565c51f124SMoriah Waterland case 'o': 6575c51f124SMoriah Waterland non_abi_scripts++; 6585c51f124SMoriah Waterland break; 6595c51f124SMoriah Waterland 6605c51f124SMoriah Waterland /* 6615c51f124SMoriah Waterland * Different from pkgadd: specify number of parts to package. 6625c51f124SMoriah Waterland */ 6635c51f124SMoriah Waterland case 'p': 6645c51f124SMoriah Waterland dparts = ds_getinfo(optarg); 6655c51f124SMoriah Waterland break; 6665c51f124SMoriah Waterland 6675c51f124SMoriah Waterland /* 6685c51f124SMoriah Waterland * Same as pkgadd: Define the full path name of a 6695c51f124SMoriah Waterland * directory to use as the root_path. All files, 6705c51f124SMoriah Waterland * including package system information files, are 6715c51f124SMoriah Waterland * relocated to a directory tree starting in the specified 6725c51f124SMoriah Waterland * root_path. The root_path may be specified when 6735c51f124SMoriah Waterland * installing to a client from a server (for example, 6745c51f124SMoriah Waterland * /export/root/client1). 6755c51f124SMoriah Waterland */ 6765c51f124SMoriah Waterland case 'R': 6775c51f124SMoriah Waterland if (!set_inst_root(optarg)) { 6785c51f124SMoriah Waterland progerr(ERR_ROOT_CMD); 6795c51f124SMoriah Waterland exit(1); 6805c51f124SMoriah Waterland } 6815c51f124SMoriah Waterland break; 6825c51f124SMoriah Waterland 6835c51f124SMoriah Waterland /* 6845c51f124SMoriah Waterland * Same as pkgadd: Identify a file or directory which 6855c51f124SMoriah Waterland * contains output from a previous pkgask(1M) 6865c51f124SMoriah Waterland * session. This file supplies the interaction responses 6875c51f124SMoriah Waterland * that would be requested by the package in interactive 6885c51f124SMoriah Waterland * mode. response must be a full pathname. 6895c51f124SMoriah Waterland */ 6905c51f124SMoriah Waterland case 'r': 6915c51f124SMoriah Waterland respfile = flex_device(optarg, 2); 6925c51f124SMoriah Waterland break; 6935c51f124SMoriah Waterland 6945c51f124SMoriah Waterland /* 6955c51f124SMoriah Waterland * Same as pkgadd: suppress copyright notice being 6965c51f124SMoriah Waterland * output during installation. 6975c51f124SMoriah Waterland */ 6985c51f124SMoriah Waterland case 'S': 6995c51f124SMoriah Waterland suppressCopyright++; 7005c51f124SMoriah Waterland break; 7015c51f124SMoriah Waterland 7025c51f124SMoriah Waterland /* 7035c51f124SMoriah Waterland * Same as pkgadd: disable save spool area creation; 7045c51f124SMoriah Waterland * do not spool any partial package contents, that is, 7055c51f124SMoriah Waterland * suppress the creation and population of the package save 7065c51f124SMoriah Waterland * spool area (var/sadm/pkg/PKG/save/pspool/PKG). 7075c51f124SMoriah Waterland */ 7085c51f124SMoriah Waterland case 't': 7095c51f124SMoriah Waterland disable_spool_create(); 7105c51f124SMoriah Waterland break; 7115c51f124SMoriah Waterland 7125c51f124SMoriah Waterland /* 7135c51f124SMoriah Waterland * Same as pkgadd: Specify an alternative fs_file to map 7145c51f124SMoriah Waterland * the client's file systems. For example, used in 7155c51f124SMoriah Waterland * situations where the $root_path/etc/vfstab file is 7165c51f124SMoriah Waterland * non-existent or unreliable. Informs the pkginstall 7175c51f124SMoriah Waterland * portion to mount up a client filesystem based upon the 7185c51f124SMoriah Waterland * supplied vfstab-like file of stable format. 7195c51f124SMoriah Waterland */ 7205c51f124SMoriah Waterland case 'V': 7215c51f124SMoriah Waterland vfstab_file = flex_device(optarg, 2); 7225c51f124SMoriah Waterland map_client = 1; 7235c51f124SMoriah Waterland break; 7245c51f124SMoriah Waterland 7255c51f124SMoriah Waterland /* 7265c51f124SMoriah Waterland * Same as pkgadd: Trace all of the scripts that get 7275c51f124SMoriah Waterland * executed by pkgadd, located in the pkginst/install 7285c51f124SMoriah Waterland * directory. This option is used for debugging the 7295c51f124SMoriah Waterland * procedural and non-procedural scripts 7305c51f124SMoriah Waterland */ 7315c51f124SMoriah Waterland case 'v': 7325c51f124SMoriah Waterland pkgverbose++; 7335c51f124SMoriah Waterland break; 7345c51f124SMoriah Waterland 7355c51f124SMoriah Waterland /* 7365c51f124SMoriah Waterland * Different from pkgadd: process this package using 7375c51f124SMoriah Waterland * old non-ABI symlinks 7385c51f124SMoriah Waterland */ 7395c51f124SMoriah Waterland case 'y': 7405c51f124SMoriah Waterland set_nonABI_symlinks(); 7415c51f124SMoriah Waterland break; 7425c51f124SMoriah Waterland 7435c51f124SMoriah Waterland /* 7445c51f124SMoriah Waterland * Same as pkgadd: perform fresh install from 7455c51f124SMoriah Waterland * package save spool area. When set, the package contents 7465c51f124SMoriah Waterland * are installed from the package spool save area instead 7475c51f124SMoriah Waterland * of from the package root area, so that the original 7485c51f124SMoriah Waterland * source packages are not required to install the 7495c51f124SMoriah Waterland * package. If the -h option is also specified and the 7505c51f124SMoriah Waterland * package is hollow, then this option is ignored. When -z 7515c51f124SMoriah Waterland * is specified: 7525c51f124SMoriah Waterland * - Editable files are installed from the package instance 7535c51f124SMoriah Waterland * save area. 7545c51f124SMoriah Waterland * - Volatile files are installed from the package instance 7555c51f124SMoriah Waterland * save area. 7565c51f124SMoriah Waterland * - Executable and data files are installed from the final 7575c51f124SMoriah Waterland * installed location as specified in the pkgmap file. 7585c51f124SMoriah Waterland * - Installation scripts are run from the package spool 7595c51f124SMoriah Waterland * save area. 7605c51f124SMoriah Waterland */ 7615c51f124SMoriah Waterland case 'z': 7625c51f124SMoriah Waterland saveSpoolInstall++; 7635c51f124SMoriah Waterland break; 7645c51f124SMoriah Waterland 7655c51f124SMoriah Waterland /* 7665c51f124SMoriah Waterland * unrecognized option 7675c51f124SMoriah Waterland */ 7685c51f124SMoriah Waterland default: 7695c51f124SMoriah Waterland usage(); 7705c51f124SMoriah Waterland /*NOTREACHED*/ 7715c51f124SMoriah Waterland /* 7725c51f124SMoriah Waterland * Although usage() calls a noreturn function, 7735c51f124SMoriah Waterland * needed to add return (1); so that main() would 7745c51f124SMoriah Waterland * pass compilation checks. The statement below 7755c51f124SMoriah Waterland * should never be executed. 7765c51f124SMoriah Waterland */ 7775c51f124SMoriah Waterland return (1); 7785c51f124SMoriah Waterland } 7795c51f124SMoriah Waterland } 7805c51f124SMoriah Waterland 7815c51f124SMoriah Waterland /* 7825c51f124SMoriah Waterland * ******************************************************************** 7835c51f124SMoriah Waterland * validate command line options 7845c51f124SMoriah Waterland * ******************************************************************** 7855c51f124SMoriah Waterland */ 7865c51f124SMoriah Waterland 7875c51f124SMoriah Waterland /* set "debug echo" flag according to setting of "-O debug" option */ 7885c51f124SMoriah Waterland 7895c51f124SMoriah Waterland (void) echoDebugSetFlag(debugFlag); 7905c51f124SMoriah Waterland (void) log_set_verbose(debugFlag); 7915c51f124SMoriah Waterland 7925c51f124SMoriah Waterland /* output entry debugging information */ 7935c51f124SMoriah Waterland 7945c51f124SMoriah Waterland if (z_running_in_global_zone()) { 7955c51f124SMoriah Waterland echoDebug(DBG_ENTRY_IN_GZ, prog_full_name); 7965c51f124SMoriah Waterland } else { 7975c51f124SMoriah Waterland echoDebug(DBG_ENTRY_IN_LZ, prog_full_name, getzoneid(), 7985c51f124SMoriah Waterland z_get_zonename()); 7995c51f124SMoriah Waterland } 8005c51f124SMoriah Waterland 8015c51f124SMoriah Waterland if (in_continue_mode() && !in_dryrun_mode()) { 8025c51f124SMoriah Waterland progerr(ERR_LIVE_CONTINUE_NOT_SUPPORTED); 8035c51f124SMoriah Waterland usage(); 8045c51f124SMoriah Waterland /*NOTREACHED*/ 8055c51f124SMoriah Waterland } 8065c51f124SMoriah Waterland 8075c51f124SMoriah Waterland /* pkgask requires a response file */ 8085c51f124SMoriah Waterland 8095c51f124SMoriah Waterland if (askflag && (respfile == NULL)) { 8105c51f124SMoriah Waterland usage(); 8115c51f124SMoriah Waterland /*NOTREACHED*/ 8125c51f124SMoriah Waterland } 8135c51f124SMoriah Waterland 8145c51f124SMoriah Waterland /* if device specified, set appropriate device in pkgdev */ 8155c51f124SMoriah Waterland 8165c51f124SMoriah Waterland if (device) { 8175c51f124SMoriah Waterland if (pkgdev.mount) { 8185c51f124SMoriah Waterland pkgdev.bdevice = device; 8195c51f124SMoriah Waterland } else { 8205c51f124SMoriah Waterland pkgdev.cdevice = device; 8215c51f124SMoriah Waterland } 8225c51f124SMoriah Waterland } 8235c51f124SMoriah Waterland 8245c51f124SMoriah Waterland /* if file system type specified, must have a device to mount */ 8255c51f124SMoriah Waterland 8265c51f124SMoriah Waterland if (pkgdev.fstyp && !pkgdev.mount) { 8275c51f124SMoriah Waterland progerr(ERR_F_REQUIRES_M); 8285c51f124SMoriah Waterland usage(); 8295c51f124SMoriah Waterland /*NOTREACHED*/ 8305c51f124SMoriah Waterland } 8315c51f124SMoriah Waterland 8325c51f124SMoriah Waterland /* BEGIN DATA GATHERING PHASE */ 8335c51f124SMoriah Waterland 8345c51f124SMoriah Waterland /* 8355c51f124SMoriah Waterland * Get the mount table info and store internally. 8365c51f124SMoriah Waterland */ 8375c51f124SMoriah Waterland cont_file_read = B_FALSE; 8385c51f124SMoriah Waterland if (in_continue_mode()) { 8395c51f124SMoriah Waterland int error; 8405c51f124SMoriah Waterland cont_file_read = read_continuation(&error); 8415c51f124SMoriah Waterland if (error == -1) { 8425c51f124SMoriah Waterland quit(99); 8435c51f124SMoriah Waterland /*NOTREACHED*/ 8445c51f124SMoriah Waterland } 8455c51f124SMoriah Waterland if (!in_dryrun_mode()) { 8465c51f124SMoriah Waterland live_continue = 1; 8475c51f124SMoriah Waterland } 8485c51f124SMoriah Waterland } 8495c51f124SMoriah Waterland /* Read the mount table if not done in continuation mode */ 8505c51f124SMoriah Waterland if (!cont_file_read) { 8515c51f124SMoriah Waterland if (get_mntinfo(map_client, vfstab_file)) { 8525c51f124SMoriah Waterland quit(99); 8535c51f124SMoriah Waterland /*NOTREACHED*/ 8545c51f124SMoriah Waterland } 8555c51f124SMoriah Waterland } 8565c51f124SMoriah Waterland 8575c51f124SMoriah Waterland /* 8585c51f124SMoriah Waterland * This function defines the standard /var/... directories used later 8595c51f124SMoriah Waterland * to construct the paths to the various databases. 8605c51f124SMoriah Waterland */ 8615c51f124SMoriah Waterland 8625c51f124SMoriah Waterland set_PKGpaths(get_inst_root()); 8635c51f124SMoriah Waterland 8645c51f124SMoriah Waterland /* 8655c51f124SMoriah Waterland * If this is being installed on a client whose /var filesystem is 8665c51f124SMoriah Waterland * mounted in some odd way, remap the administrative paths to the 8675c51f124SMoriah Waterland * real filesystem. This could be avoided by simply mounting up the 8685c51f124SMoriah Waterland * client now; but we aren't yet to the point in the process where 8695c51f124SMoriah Waterland * modification of the filesystem is permitted. 8705c51f124SMoriah Waterland */ 8715c51f124SMoriah Waterland if (is_an_inst_root()) { 8725c51f124SMoriah Waterland int fsys_value; 8735c51f124SMoriah Waterland 8745c51f124SMoriah Waterland fsys_value = fsys(get_PKGLOC()); 8755c51f124SMoriah Waterland if (use_srvr_map_n(fsys_value)) 8765c51f124SMoriah Waterland set_PKGLOC(server_map(get_PKGLOC(), fsys_value)); 8775c51f124SMoriah Waterland 8785c51f124SMoriah Waterland fsys_value = fsys(get_PKGADM()); 8795c51f124SMoriah Waterland if (use_srvr_map_n(fsys_value)) 8805c51f124SMoriah Waterland set_PKGADM(server_map(get_PKGADM(), fsys_value)); 8815c51f124SMoriah Waterland } 8825c51f124SMoriah Waterland 8835c51f124SMoriah Waterland /* 8845c51f124SMoriah Waterland * Initialize pkginfo PKGSAV entry, just in case we dryrun to 8855c51f124SMoriah Waterland * somewhere else. 8865c51f124SMoriah Waterland */ 8875c51f124SMoriah Waterland set_infoloc(get_PKGLOC()); 8885c51f124SMoriah Waterland 8895c51f124SMoriah Waterland /* pull off directory and package name from end of command line */ 8905c51f124SMoriah Waterland 8915c51f124SMoriah Waterland switch (argc-optind) { 8925c51f124SMoriah Waterland case 0: /* missing directory and package instance */ 8935c51f124SMoriah Waterland progerr(ERR_MISSING_DIR_AND_PKG); 8945c51f124SMoriah Waterland usage(); 8955c51f124SMoriah Waterland /*NOTREACHED*/ 8965c51f124SMoriah Waterland case 1: /* missing package instance */ 8975c51f124SMoriah Waterland progerr(ERR_MISSING_PKG_INSTANCE); 8985c51f124SMoriah Waterland usage(); 8995c51f124SMoriah Waterland /*NOTREACHED*/ 9005c51f124SMoriah Waterland case 2: /* just right! */ 9015c51f124SMoriah Waterland pkgdev.dirname = argv[optind++]; 9025c51f124SMoriah Waterland srcinst = argv[optind++]; 9035c51f124SMoriah Waterland break; 9045c51f124SMoriah Waterland default: /* too many args! */ 9055c51f124SMoriah Waterland progerr(ERR_TOO_MANY_CMD_ARGS); 9065c51f124SMoriah Waterland usage(); 9075c51f124SMoriah Waterland break; 9085c51f124SMoriah Waterland } 9095c51f124SMoriah Waterland 9105c51f124SMoriah Waterland (void) pkgparam(NULL, NULL); /* close up prior pkg file if needed */ 9115c51f124SMoriah Waterland 9125c51f124SMoriah Waterland /* 9135c51f124SMoriah Waterland * Initialize installation admin parameters by reading 9145c51f124SMoriah Waterland * the adminfile. 9155c51f124SMoriah Waterland */ 9165c51f124SMoriah Waterland 9175c51f124SMoriah Waterland if (!askflag && !live_continue) { 9185c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_ADMINFILE, admnfile ? admnfile : ""); 9195c51f124SMoriah Waterland setadminFile(admnfile); 9205c51f124SMoriah Waterland } 9215c51f124SMoriah Waterland 9225c51f124SMoriah Waterland /* 9235c51f124SMoriah Waterland * about to perform first operation that could be modified by the 9245c51f124SMoriah Waterland * preinstall check option - if preinstall check is selected (that is, 9255c51f124SMoriah Waterland * only gathering dependencies), then output a debug message to 9265c51f124SMoriah Waterland * indicate that the check is beginning. Also turn echo() output 9275c51f124SMoriah Waterland * off and set various other flags. 9285c51f124SMoriah Waterland */ 9295c51f124SMoriah Waterland 9305c51f124SMoriah Waterland if (preinstallCheck == B_TRUE) { 9315c51f124SMoriah Waterland (void) echoSetFlag(B_FALSE); 9325c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_PREINSCHK, 9335c51f124SMoriah Waterland pkginst ? pkginst : (srcinst ? srcinst : ""), 9345c51f124SMoriah Waterland zoneName ? zoneName : "global"); 9355c51f124SMoriah Waterland cksetPreinstallCheck(B_TRUE); 9365c51f124SMoriah Waterland cksetZoneName(zoneName); 9375c51f124SMoriah Waterland /* inform quit that the install has started */ 9385c51f124SMoriah Waterland quitSetInstallStarted(B_TRUE); 9395c51f124SMoriah Waterland } 9405c51f124SMoriah Waterland 9415c51f124SMoriah Waterland /* 9425c51f124SMoriah Waterland * validate the "rscriptalt" admin file setting 9435c51f124SMoriah Waterland * The rscriptalt admin file parameter may be set to either 9445c51f124SMoriah Waterland * RSCRIPTALT_ROOT or RSCRIPTALT_NOACCESS: 9455c51f124SMoriah Waterland * --> If rscriptalt is not set, or is set to RSCRIPTALT_NOACCESS, 9465c51f124SMoriah Waterland * --> or is set to any value OTHER than RSCRIPTALT_ROOT, then 9475c51f124SMoriah Waterland * --> assume that the parameter is set to RSCRIPTALT_NOACCESS 9485c51f124SMoriah Waterland * If rscriptalt is set to RSCRIPTALT_ROOT, then run request scripts 9495c51f124SMoriah Waterland * as the "root" user if user "install" is not defined. 9505c51f124SMoriah Waterland * Otherwise, assume rscriptalt is set to RSCRIPTALT_NOACCESS, and run 9515c51f124SMoriah Waterland * request scripts as the "alternative" user if user "install" is not 9525c51f124SMoriah Waterland * defined, as appropriate for the current setting of the NONABI_SCRIPTS 9535c51f124SMoriah Waterland * environment variable. 9545c51f124SMoriah Waterland */ 9555c51f124SMoriah Waterland 9565c51f124SMoriah Waterland if (ADMSET(RSCRIPTALT)) { 9575c51f124SMoriah Waterland p = adm.RSCRIPTALT; 9585c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_RSCRIPT_SET_TO, RSCRIPTALT_KEYWORD, p); 9595c51f124SMoriah Waterland if (strcasecmp(p, RSCRIPTALT_ROOT) == 0) { 9605c51f124SMoriah Waterland /* rscriptalt=root */ 9615c51f124SMoriah Waterland run_request_as_root = B_TRUE; 9625c51f124SMoriah Waterland } else if (strcasecmp(p, RSCRIPTALT_NOACCESS) == 0) { 9635c51f124SMoriah Waterland /* rscriptalt=noaccess */ 9645c51f124SMoriah Waterland run_request_as_root = B_FALSE; 9655c51f124SMoriah Waterland } else { 9665c51f124SMoriah Waterland /* rscriptalt=??? */ 9675c51f124SMoriah Waterland logerr(WRN_RSCRIPTALT_BAD, RSCRIPTALT_KEYWORD, p, 9685c51f124SMoriah Waterland RSCRIPTALT_ROOT, RSCRIPTALT_NOACCESS); 9695c51f124SMoriah Waterland logerr(WRN_RSCRIPTALT_USING, RSCRIPTALT_KEYWORD, 9705c51f124SMoriah Waterland RSCRIPTALT_NOACCESS); 9715c51f124SMoriah Waterland run_request_as_root = B_FALSE; 9725c51f124SMoriah Waterland } 9735c51f124SMoriah Waterland } else { 9745c51f124SMoriah Waterland /* rscriptalt not set - assume rscriptalt=noaccess */ 9755c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_RSCRIPT_NOT_SET, RSCRIPTALT_KEYWORD); 9765c51f124SMoriah Waterland run_request_as_root = B_FALSE; 9775c51f124SMoriah Waterland } 9785c51f124SMoriah Waterland 9795c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_RSCRIPT_IS_ROOT, run_request_as_root); 9805c51f124SMoriah Waterland 9815c51f124SMoriah Waterland /* 9825c51f124SMoriah Waterland * hook SIGINT and SIGHUP interrupts into quit.c's trap handler 9835c51f124SMoriah Waterland */ 9845c51f124SMoriah Waterland 9855c51f124SMoriah Waterland /* hold SIGINT/SIGHUP interrupts */ 9865c51f124SMoriah Waterland 9875c51f124SMoriah Waterland (void) sighold(SIGHUP); 9885c51f124SMoriah Waterland (void) sighold(SIGINT); 9895c51f124SMoriah Waterland 9905c51f124SMoriah Waterland /* connect quit.c:trap() to SIGINT */ 9915c51f124SMoriah Waterland 9925c51f124SMoriah Waterland nact.sa_handler = quitGetTrapHandler(); 9935c51f124SMoriah Waterland nact.sa_flags = SA_RESTART; 9945c51f124SMoriah Waterland (void) sigemptyset(&nact.sa_mask); 9955c51f124SMoriah Waterland 9965c51f124SMoriah Waterland (void) sigaction(SIGINT, &nact, &oact); 9975c51f124SMoriah Waterland 9985c51f124SMoriah Waterland /* connect quit.c:trap() to SIGHUP */ 9995c51f124SMoriah Waterland 10005c51f124SMoriah Waterland nact.sa_handler = quitGetTrapHandler(); 10015c51f124SMoriah Waterland nact.sa_flags = SA_RESTART; 10025c51f124SMoriah Waterland (void) sigemptyset(&nact.sa_mask); 10035c51f124SMoriah Waterland 10045c51f124SMoriah Waterland (void) sigaction(SIGHUP, &nact, &oact); 10055c51f124SMoriah Waterland 10065c51f124SMoriah Waterland /* release hold on signals */ 10075c51f124SMoriah Waterland 10085c51f124SMoriah Waterland (void) sigrelse(SIGHUP); 10095c51f124SMoriah Waterland (void) sigrelse(SIGINT); 10105c51f124SMoriah Waterland 10115c51f124SMoriah Waterland /* 10125c51f124SMoriah Waterland * create required /var... directories if they do not exist; 10135c51f124SMoriah Waterland * this function will call quit(99) if any required path cannot 10145c51f124SMoriah Waterland * be created. 10155c51f124SMoriah Waterland */ 10165c51f124SMoriah Waterland 10175c51f124SMoriah Waterland ckdirs(); 10185c51f124SMoriah Waterland 10195c51f124SMoriah Waterland tzset(); 10205c51f124SMoriah Waterland 10215c51f124SMoriah Waterland /* 10225c51f124SMoriah Waterland * create path to temporary directory "installXXXXXX" - if TMPDIR 10235c51f124SMoriah Waterland * environment variable is set, create the directory in $TMPDIR; 10245c51f124SMoriah Waterland * otherwise, create the directory in P_tmpdir. 10255c51f124SMoriah Waterland */ 10265c51f124SMoriah Waterland 10275c51f124SMoriah Waterland pt = getenv("TMPDIR"); 10285c51f124SMoriah Waterland (void) snprintf(tmpdir, sizeof (tmpdir), "%s/installXXXXXX", 10295c51f124SMoriah Waterland ((pt != (char *)NULL) && (*pt != '\0')) ? pt : P_tmpdir); 10305c51f124SMoriah Waterland 10315c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_TMPDIR, tmpdir); 10325c51f124SMoriah Waterland 10335c51f124SMoriah Waterland if ((mktemp(tmpdir) == NULL) || mkdir(tmpdir, 0771)) { 10345c51f124SMoriah Waterland progerr(ERR_MKDIR, tmpdir); 10355c51f124SMoriah Waterland quit(99); 10365c51f124SMoriah Waterland /*NOTREACHED*/ 10375c51f124SMoriah Waterland } 10385c51f124SMoriah Waterland 10395c51f124SMoriah Waterland /* 10405c51f124SMoriah Waterland * if the package device is a file containing a package stream, 10415c51f124SMoriah Waterland * unpack the stream into a temporary directory 10425c51f124SMoriah Waterland */ 10435c51f124SMoriah Waterland 10445c51f124SMoriah Waterland if ((isdir(pkgdev.dirname) != 0) && 10455c51f124SMoriah Waterland (pkgdev.cdevice == (char *)NULL) && 10465c51f124SMoriah Waterland (pkgdev.bdevice == (char *)NULL) && 10475c51f124SMoriah Waterland (isfile((char *)NULL, pkgdev.dirname) == 0)) { 10485c51f124SMoriah Waterland 10495c51f124SMoriah Waterland char *idsName = (char *)NULL; 10505c51f124SMoriah Waterland char *pkgnames[2]; 10515c51f124SMoriah Waterland char *device = pkgdev.dirname; 10525c51f124SMoriah Waterland boolean_t b; 10535c51f124SMoriah Waterland 10545c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_DS_ISFILE, pkgdev.dirname); 10555c51f124SMoriah Waterland 10565c51f124SMoriah Waterland /* 10575c51f124SMoriah Waterland * validate the package source device - return pkgdev info that 10585c51f124SMoriah Waterland * describes the package source device. 10595c51f124SMoriah Waterland */ 10605c51f124SMoriah Waterland 10615c51f124SMoriah Waterland if (devtype(device, &pkgdev)) { 10625c51f124SMoriah Waterland progerr(ERR_BAD_DEVICE, device); 10635c51f124SMoriah Waterland quit(99); 10645c51f124SMoriah Waterland /* NOTREACHED */ 10655c51f124SMoriah Waterland } 10665c51f124SMoriah Waterland 10675c51f124SMoriah Waterland /* generate the list of packages to verify */ 10685c51f124SMoriah Waterland 10695c51f124SMoriah Waterland pkgnames[0] = srcinst; 10705c51f124SMoriah Waterland pkgnames[1] = (char *)NULL; 10715c51f124SMoriah Waterland 10725c51f124SMoriah Waterland b = open_package_datastream(1, pkgnames, (char *)NULL, 10735c51f124SMoriah Waterland pkgdev.dirname, (int *)NULL, &idsName, tmpdir, &pkgdev, 10745c51f124SMoriah Waterland 1); 10755c51f124SMoriah Waterland 10765c51f124SMoriah Waterland if (b == B_FALSE) { 10775c51f124SMoriah Waterland progerr(ERR_CANNOT_OPEN_PKG_STREAM, 10785c51f124SMoriah Waterland pkgdev.dirname ? pkgdev.dirname : "?"); 10795c51f124SMoriah Waterland quit(99); 10805c51f124SMoriah Waterland /*NOTREACHED*/ 10815c51f124SMoriah Waterland } 10825c51f124SMoriah Waterland 10835c51f124SMoriah Waterland /* make sure temporary directory is removed on exit */ 10845c51f124SMoriah Waterland 10855c51f124SMoriah Waterland quitSetDstreamTmpdir(pkgdev.dirname); 10865c51f124SMoriah Waterland 10875c51f124SMoriah Waterland /* unpack the package instance from the data stream */ 10885c51f124SMoriah Waterland 10895c51f124SMoriah Waterland b = unpack_package_from_stream(idsName, srcinst, 10905c51f124SMoriah Waterland pkgdev.dirname); 10915c51f124SMoriah Waterland if (b == B_FALSE) { 10925c51f124SMoriah Waterland progerr(ERR_CANNOT_UNPACK_PKGSTRM, 10935c51f124SMoriah Waterland srcinst ? srcinst : "?", 10945c51f124SMoriah Waterland idsName ? idsName : "?", 10955c51f124SMoriah Waterland pkgdev.dirname ? pkgdev.dirname : "?"); 10965c51f124SMoriah Waterland quit(99); 10975c51f124SMoriah Waterland /*NOTREACHED*/ 10985c51f124SMoriah Waterland } 10995c51f124SMoriah Waterland 11005c51f124SMoriah Waterland /* close the datastream - no longer needed */ 11015c51f124SMoriah Waterland 11025c51f124SMoriah Waterland echoDebug(DBG_CLOSING_STREAM, idsName, pkgdev.dirname); 11035c51f124SMoriah Waterland (void) ds_close(1); 11045c51f124SMoriah Waterland } 11055c51f124SMoriah Waterland 11065c51f124SMoriah Waterland if (snprintf(instdir, PATH_MAX, "%s/%s", pkgdev.dirname, srcinst) 11075c51f124SMoriah Waterland >= PATH_MAX) { 11085c51f124SMoriah Waterland progerr(ERR_SNPRINTF, instdir); 11095c51f124SMoriah Waterland quit(99); 11105c51f124SMoriah Waterland /*NOTREACHED*/ 11115c51f124SMoriah Waterland } 11125c51f124SMoriah Waterland 11135c51f124SMoriah Waterland zoneName = getenv(PKG_ZONENAME_VARIABLE); 11145c51f124SMoriah Waterland 11155c51f124SMoriah Waterland /* 11165c51f124SMoriah Waterland * If the environment has a CLIENT_BASEDIR, that takes precedence 11175c51f124SMoriah Waterland * over anything we will construct. We need to save it here because 11185c51f124SMoriah Waterland * in three lines, the current environment goes away. 11195c51f124SMoriah Waterland */ 11205c51f124SMoriah Waterland (void) set_env_cbdir(); /* copy over environ */ 11215c51f124SMoriah Waterland 11225c51f124SMoriah Waterland getuserlocale(); 11235c51f124SMoriah Waterland 11245c51f124SMoriah Waterland /* 11255c51f124SMoriah Waterland * current environment has been read; clear environment out 11265c51f124SMoriah Waterland * so putparam() can be used to populate the new environment 11275c51f124SMoriah Waterland * to be passed to any executables/scripts. 11285c51f124SMoriah Waterland */ 11295c51f124SMoriah Waterland 11305c51f124SMoriah Waterland environ = NULL; 11315c51f124SMoriah Waterland 11325c51f124SMoriah Waterland /* write parent condition information to environment */ 11335c51f124SMoriah Waterland 11345c51f124SMoriah Waterland putConditionInfo(parentZoneName, parentZoneType); 11355c51f124SMoriah Waterland 11365c51f124SMoriah Waterland putuserlocale(); 11375c51f124SMoriah Waterland 11385c51f124SMoriah Waterland if (init_install) { 11395c51f124SMoriah Waterland putparam("PKG_INIT_INSTALL", "TRUE"); 11405c51f124SMoriah Waterland } 11415c51f124SMoriah Waterland 11425c51f124SMoriah Waterland if (is_an_inst_root()) { 11435c51f124SMoriah Waterland export_client_env(get_inst_root()); 11445c51f124SMoriah Waterland } 11455c51f124SMoriah Waterland 11465c51f124SMoriah Waterland if (zoneName != (char *)NULL) { 11475c51f124SMoriah Waterland putparam(PKG_ZONENAME_VARIABLE, zoneName); 11485c51f124SMoriah Waterland } 11495c51f124SMoriah Waterland 11505c51f124SMoriah Waterland putparam("INST_DATADIR", pkgdev.dirname); 11515c51f124SMoriah Waterland 11525c51f124SMoriah Waterland if (non_abi_scripts) { 11535c51f124SMoriah Waterland putparam("NONABI_SCRIPTS", "TRUE"); 11545c51f124SMoriah Waterland } 11555c51f124SMoriah Waterland 11565c51f124SMoriah Waterland if (nonABI_symlinks()) { 11575c51f124SMoriah Waterland putparam("PKG_NONABI_SYMLINKS", "TRUE"); 11585c51f124SMoriah Waterland } 11595c51f124SMoriah Waterland 11605c51f124SMoriah Waterland if (get_ABI_namelngth()) { 11615c51f124SMoriah Waterland putparam("PKG_ABI_NAMELENGTH", "TRUE"); 11625c51f124SMoriah Waterland } 11635c51f124SMoriah Waterland 11645c51f124SMoriah Waterland /* establish path and oambase */ 11655c51f124SMoriah Waterland 11665c51f124SMoriah Waterland if (cmdbin[0] == '\0') { 11675c51f124SMoriah Waterland (void) strlcpy(cmdbin, PKGBIN, sizeof (cmdbin)); 11685c51f124SMoriah Waterland } 11695c51f124SMoriah Waterland 11705c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), "%s:%s", DEFPATH, cmdbin); 11715c51f124SMoriah Waterland 11725c51f124SMoriah Waterland putparam("PATH", path); 11735c51f124SMoriah Waterland 11745c51f124SMoriah Waterland putparam("OAMBASE", OAMBASE); 11755c51f124SMoriah Waterland 11765c51f124SMoriah Waterland (void) snprintf(p_pkginfo, sizeof (p_pkginfo), 11775c51f124SMoriah Waterland "%s/%s", instdir, PKGINFO); 11785c51f124SMoriah Waterland (void) snprintf(p_pkgmap, sizeof (p_pkgmap), 11795c51f124SMoriah Waterland "%s/%s", instdir, PKGMAP); 11805c51f124SMoriah Waterland 11815c51f124SMoriah Waterland /* Read the environment (from pkginfo or '-e') ... */ 11825c51f124SMoriah Waterland abi_nm_ptr = getenv("PKG_ABI_NAMELENGTH"); 11835c51f124SMoriah Waterland 11845c51f124SMoriah Waterland /* Disable the 32 char name limit extension */ 11855c51f124SMoriah Waterland if (abi_nm_ptr && strncasecmp(abi_nm_ptr, "TRUE", 4) == 0) { 11865c51f124SMoriah Waterland (void) set_ABI_namelngth(); 11875c51f124SMoriah Waterland } 11885c51f124SMoriah Waterland 11895c51f124SMoriah Waterland /* 11905c51f124SMoriah Waterland * This tests the pkginfo and pkgmap files for validity and 11915c51f124SMoriah Waterland * puts all delivered pkginfo variables (except for PATH) into 11925c51f124SMoriah Waterland * our environment. This is where a delivered pkginfo BASEDIR 11935c51f124SMoriah Waterland * would come from. See set_basedirs() below. 11945c51f124SMoriah Waterland */ 11955c51f124SMoriah Waterland 11965c51f124SMoriah Waterland if (pkgenv(srcinst, p_pkginfo, p_pkgmap)) { 11975c51f124SMoriah Waterland quit(1); 11985c51f124SMoriah Waterland /*NOTREACHED*/ 11995c51f124SMoriah Waterland } 12005c51f124SMoriah Waterland 12015c51f124SMoriah Waterland echo("\n%s(%s) %s", pkgname, pkgarch, pkgvers); 12025c51f124SMoriah Waterland 12035c51f124SMoriah Waterland /* 12045c51f124SMoriah Waterland * If this script was invoked by 'pkgask', just 12055c51f124SMoriah Waterland * execute request script and quit (do_pkgask()). 12065c51f124SMoriah Waterland */ 12075c51f124SMoriah Waterland 12085c51f124SMoriah Waterland if (askflag) { 12095c51f124SMoriah Waterland do_pkgask(run_request_as_root); 12105c51f124SMoriah Waterland } 12115c51f124SMoriah Waterland 12125c51f124SMoriah Waterland /* validate package contents file */ 12135c51f124SMoriah Waterland 12145c51f124SMoriah Waterland if (vcfile() == 0) { 12155c51f124SMoriah Waterland quit(99); 12165c51f124SMoriah Waterland } 12175c51f124SMoriah Waterland 12185c51f124SMoriah Waterland /* if not in dryrun mode aquire packaging lock */ 12195c51f124SMoriah Waterland 12205c51f124SMoriah Waterland if (!in_dryrun_mode()) { 12215c51f124SMoriah Waterland /* acquire the package lock - at install initialization */ 12225c51f124SMoriah Waterland if (!lockinst(get_prog_name(), srcinst, "install-initial")) { 12235c51f124SMoriah Waterland quit(99); 12245c51f124SMoriah Waterland /*NOTREACHED*/ 12255c51f124SMoriah Waterland } 12265c51f124SMoriah Waterland } 12275c51f124SMoriah Waterland 12285c51f124SMoriah Waterland /* 12295c51f124SMoriah Waterland * Now do all the various setups based on ABI compliance 12305c51f124SMoriah Waterland */ 12315c51f124SMoriah Waterland 12325c51f124SMoriah Waterland /* Read the environment (from pkginfo or '-o') ... */ 12335c51f124SMoriah Waterland abi_comp_ptr = getenv("NONABI_SCRIPTS"); 12345c51f124SMoriah Waterland 12355c51f124SMoriah Waterland /* Read the environment (from pkginfo or '-y') ... */ 12365c51f124SMoriah Waterland abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS"); 12375c51f124SMoriah Waterland 12385c51f124SMoriah Waterland /* bug id 4244631, not ABI compliant */ 12395c51f124SMoriah Waterland if (abi_comp_ptr && strncasecmp(abi_comp_ptr, "TRUE", 4) == 0) { 12405c51f124SMoriah Waterland script_in = PROC_XSTDIN; 12415c51f124SMoriah Waterland non_abi_scripts = 1; 12425c51f124SMoriah Waterland } 12435c51f124SMoriah Waterland 12445c51f124SMoriah Waterland /* Set symlinks to be processed the old way */ 12455c51f124SMoriah Waterland if (abi_sym_ptr && strncasecmp(abi_sym_ptr, "TRUE", 4) == 0) { 12465c51f124SMoriah Waterland set_nonABI_symlinks(); 12475c51f124SMoriah Waterland } 12485c51f124SMoriah Waterland 12495c51f124SMoriah Waterland /* 12505c51f124SMoriah Waterland * At this point, script_in, non_abi_scripts & the environment are 12515c51f124SMoriah Waterland * all set correctly for the ABI status of the package. 12525c51f124SMoriah Waterland */ 12535c51f124SMoriah Waterland 12545c51f124SMoriah Waterland if (pt = getenv("MAXINST")) { 12555c51f124SMoriah Waterland maxinst = atol(pt); 12565c51f124SMoriah Waterland } 12575c51f124SMoriah Waterland 12585c51f124SMoriah Waterland /* 12595c51f124SMoriah Waterland * See if were are installing a package that only wants to update 12605c51f124SMoriah Waterland * the database or only install files associated with CAS's. We 12615c51f124SMoriah Waterland * only check the PKG_HOLLOW_VARIABLE variable if told to do so by 12625c51f124SMoriah Waterland * the caller. 12635c51f124SMoriah Waterland */ 12645c51f124SMoriah Waterland 12655c51f124SMoriah Waterland if (is_depend_pkginfo_DB()) { 12665c51f124SMoriah Waterland pt = getenv(PKG_HOLLOW_VARIABLE); 12675c51f124SMoriah Waterland if ((pt != NULL) && (strncasecmp(pt, "true", 4) == 0)) { 12685c51f124SMoriah Waterland echoDebug(DBG_PKGREMOVE_HOLLOW_ENABLED); 12695c51f124SMoriah Waterland if (disableAttributes) { 12705c51f124SMoriah Waterland disable_attribute_check(); 12715c51f124SMoriah Waterland } 12725c51f124SMoriah Waterland 12735c51f124SMoriah Waterland /* 12745c51f124SMoriah Waterland * this is a hollow package and hollow package support 12755c51f124SMoriah Waterland * is enabled -- override admin settings to suppress 12765c51f124SMoriah Waterland * checks that do not make sense since no scripts will 12775c51f124SMoriah Waterland * be executed and no files will be installed. 12785c51f124SMoriah Waterland */ 12795c51f124SMoriah Waterland 12805c51f124SMoriah Waterland setadminSetting("conflict", "nocheck"); 12815c51f124SMoriah Waterland setadminSetting("setuid", "nocheck"); 12825c51f124SMoriah Waterland setadminSetting("action", "nocheck"); 12835c51f124SMoriah Waterland setadminSetting("partial", "nocheck"); 12845c51f124SMoriah Waterland setadminSetting("space", "nocheck"); 12855c51f124SMoriah Waterland setadminSetting("authentication", "nocheck"); 12865c51f124SMoriah Waterland } else { 12875c51f124SMoriah Waterland echoDebug(DBG_PKGREMOVE_HOLLOW_DISABLED); 12885c51f124SMoriah Waterland set_depend_pkginfo_DB(B_FALSE); 12895c51f124SMoriah Waterland } 12905c51f124SMoriah Waterland } 12915c51f124SMoriah Waterland 12925c51f124SMoriah Waterland /* 12935c51f124SMoriah Waterland * if performing a fresh install to a non-global zone, and doing 12945c51f124SMoriah Waterland * more than just updating the package database (that is, the 12955c51f124SMoriah Waterland * package to install is NOT "hollow"), then set the global flag 12965c51f124SMoriah Waterland * that directs installation is from partially spooled packages 12975c51f124SMoriah Waterland * (that is, packages installed in the global zone). 12985c51f124SMoriah Waterland */ 12995c51f124SMoriah Waterland 13005c51f124SMoriah Waterland if (saveSpoolInstall && (!is_depend_pkginfo_DB())) { 13015c51f124SMoriah Waterland set_partial_inst(); 13025c51f124SMoriah Waterland } else { 13035c51f124SMoriah Waterland saveSpoolInstall = 0; 13045c51f124SMoriah Waterland } 13055c51f124SMoriah Waterland 13065c51f124SMoriah Waterland /* 13075c51f124SMoriah Waterland * verify that we are not trying to install an 13085c51f124SMoriah Waterland * INTONLY package with no interaction 13095c51f124SMoriah Waterland */ 13105c51f124SMoriah Waterland 13115c51f124SMoriah Waterland if (pt = getenv("INTONLY")) { 13125c51f124SMoriah Waterland if (askflag || nointeract) { 13135c51f124SMoriah Waterland progerr(ERR_INTONLY, pkgabrv ? pkgabrv : "?"); 13145c51f124SMoriah Waterland quit(1); 13155c51f124SMoriah Waterland /*NOTREACHED*/ 13165c51f124SMoriah Waterland } 13175c51f124SMoriah Waterland } 13185c51f124SMoriah Waterland 13195c51f124SMoriah Waterland if (!suppressCopyright && !pkgdev.cdevice) { 13205c51f124SMoriah Waterland copyright(); 13215c51f124SMoriah Waterland } 13225c51f124SMoriah Waterland 13235c51f124SMoriah Waterland /* 13245c51f124SMoriah Waterland * inspect the system to determine if any instances of the 13255c51f124SMoriah Waterland * package being installed already exist on the system 13265c51f124SMoriah Waterland */ 13275c51f124SMoriah Waterland 13285c51f124SMoriah Waterland prvinfo = (struct pkginfo *)calloc(MALSIZ, sizeof (struct pkginfo)); 13295c51f124SMoriah Waterland if (prvinfo == NULL) { 13305c51f124SMoriah Waterland progerr(ERR_MEMORY, errno); 13315c51f124SMoriah Waterland quit(99); 13325c51f124SMoriah Waterland /*NOTREACHED*/ 13335c51f124SMoriah Waterland } 13345c51f124SMoriah Waterland 13355c51f124SMoriah Waterland for (;;) { 13365c51f124SMoriah Waterland if (pkginfo(&prvinfo[npkgs], pkgwild, NULL, NULL)) { 13375c51f124SMoriah Waterland if ((errno == ESRCH) || (errno == ENOENT)) { 13385c51f124SMoriah Waterland break; 13395c51f124SMoriah Waterland } 13405c51f124SMoriah Waterland progerr(ERR_SYSINFO, errno); 13415c51f124SMoriah Waterland quit(99); 13425c51f124SMoriah Waterland /*NOTREACHED*/ 13435c51f124SMoriah Waterland } 13445c51f124SMoriah Waterland if ((++npkgs % MALSIZ) == 0) { 13455c51f124SMoriah Waterland prvinfo = (struct pkginfo *)realloc(prvinfo, 13465c51f124SMoriah Waterland (npkgs+MALSIZ) * sizeof (struct pkginfo)); 13475c51f124SMoriah Waterland if (prvinfo == NULL) { 13485c51f124SMoriah Waterland progerr(ERR_MEMORY, errno); 13495c51f124SMoriah Waterland quit(99); 13505c51f124SMoriah Waterland /*NOTREACHED*/ 13515c51f124SMoriah Waterland } 13525c51f124SMoriah Waterland } 13535c51f124SMoriah Waterland } 13545c51f124SMoriah Waterland 13555c51f124SMoriah Waterland /* 13565c51f124SMoriah Waterland * Determine the correct package instance based on how many packages are 13575c51f124SMoriah Waterland * already installed. If there are none (npkgs == 0), getinst() just 13585c51f124SMoriah Waterland * returns the package abbreviation. Otherwise, getinst() interacts with 13595c51f124SMoriah Waterland * the user (or reads the admin file) to determine if an instance which 13605c51f124SMoriah Waterland * is already installed should be overwritten, or possibly install a new 13615c51f124SMoriah Waterland * instance of this package 13625c51f124SMoriah Waterland */ 13635c51f124SMoriah Waterland 13645c51f124SMoriah Waterland pkginst = getinst(&update, prvinfo, npkgs, preinstallCheck); 13655c51f124SMoriah Waterland 13665c51f124SMoriah Waterland /* set "update flag" if updating an existing instance of this package */ 13675c51f124SMoriah Waterland 13685c51f124SMoriah Waterland if (update) { 13695c51f124SMoriah Waterland setUpdate(); 13705c51f124SMoriah Waterland } 13715c51f124SMoriah Waterland 13725c51f124SMoriah Waterland /* 1373*4656d474SGarrett D'Amore * Some pkgs (SUNWcsr) already spooled to the zone, check the 1374*4656d474SGarrett D'Amore * value of UPDATE in their postinstall script. After a pkg 1375*4656d474SGarrett D'Amore * has been patched UPDATE exists statically in the pkginfo 1376*4656d474SGarrett D'Amore * file and this value must be reset when installing a zone. 13775c51f124SMoriah Waterland */ 13785c51f124SMoriah Waterland 1379*4656d474SGarrett D'Amore if (saveSpoolInstall != 0 && !isUpdate()) { 13805c51f124SMoriah Waterland putparam("UPDATE", ""); 13815c51f124SMoriah Waterland } 13825c51f124SMoriah Waterland 13835c51f124SMoriah Waterland /* inform quit() if updating existing or installing new instance */ 13845c51f124SMoriah Waterland 13855c51f124SMoriah Waterland quitSetUpdatingExisting(update ? B_TRUE : B_FALSE); 13865c51f124SMoriah Waterland 13875c51f124SMoriah Waterland if (respfile) { 13885c51f124SMoriah Waterland (void) set_respfile(respfile, pkginst, RESP_RO); 13895c51f124SMoriah Waterland } 13905c51f124SMoriah Waterland 13915c51f124SMoriah Waterland (void) snprintf(pkgloc, sizeof (pkgloc), 13925c51f124SMoriah Waterland "%s/%s", get_PKGLOC(), pkginst); 13935c51f124SMoriah Waterland 13945c51f124SMoriah Waterland (void) snprintf(pkgbin, sizeof (pkgbin), 13955c51f124SMoriah Waterland "%s/install", pkgloc); 13965c51f124SMoriah Waterland 13975c51f124SMoriah Waterland (void) snprintf(pkgsav, sizeof (pkgsav), 13985c51f124SMoriah Waterland "%s/save", pkgloc); 13995c51f124SMoriah Waterland 14005c51f124SMoriah Waterland if (snprintf(saveSpoolInstallDir, PATH_MAX, "%s/pspool/%s", pkgsav, 14015c51f124SMoriah Waterland pkginst) < 0) { 14025c51f124SMoriah Waterland progerr(ERR_SNPRINTF, saveSpoolInstallDir); 14035c51f124SMoriah Waterland quit(99); 14045c51f124SMoriah Waterland /*NOTREACHED*/ 14055c51f124SMoriah Waterland } 14065c51f124SMoriah Waterland 14075c51f124SMoriah Waterland (void) snprintf(ilockfile, sizeof (ilockfile), 14085c51f124SMoriah Waterland "%s/!I-Lock!", pkgloc); 14095c51f124SMoriah Waterland (void) snprintf(rlockfile, sizeof (rlockfile), 14105c51f124SMoriah Waterland "%s/!R-Lock!", pkgloc); 14115c51f124SMoriah Waterland (void) snprintf(savlog, sizeof (savlog), 14125c51f124SMoriah Waterland "%s/logs/%s", get_PKGADM(), pkginst); 14135c51f124SMoriah Waterland 14145c51f124SMoriah Waterland putparam("PKGINST", pkginst); 14155c51f124SMoriah Waterland putparam("PKGSAV", pkgsav); 14165c51f124SMoriah Waterland 14175c51f124SMoriah Waterland /* 14185c51f124SMoriah Waterland * Be sure request script has access to PKG_INSTALL_ROOT if there is 14195c51f124SMoriah Waterland * one 14205c51f124SMoriah Waterland */ 14215c51f124SMoriah Waterland 14225c51f124SMoriah Waterland put_path_params(); 14235c51f124SMoriah Waterland 14245c51f124SMoriah Waterland if (!map_client) { 14255c51f124SMoriah Waterland putparam("PKG_NO_UNIFIED", "TRUE"); 14265c51f124SMoriah Waterland } 14275c51f124SMoriah Waterland 14285c51f124SMoriah Waterland /* 14295c51f124SMoriah Waterland * This maps the client filesystems into the server's space. 14305c51f124SMoriah Waterland */ 14315c51f124SMoriah Waterland 14325c51f124SMoriah Waterland if (map_client && !mount_client()) { 14335c51f124SMoriah Waterland logerr(MSG_MANMOUNT); 14345c51f124SMoriah Waterland } 14355c51f124SMoriah Waterland 14365c51f124SMoriah Waterland /* 14375c51f124SMoriah Waterland * If this is an UPDATE then either this is exactly the same version 14385c51f124SMoriah Waterland * and architecture of an installed package or a different package is 14395c51f124SMoriah Waterland * intended to entirely replace an installed package of the same name 14405c51f124SMoriah Waterland * with a different VERSION or ARCH string. 14415c51f124SMoriah Waterland * Don't merge any databases if only gathering dependencies. 14425c51f124SMoriah Waterland */ 14435c51f124SMoriah Waterland 14445c51f124SMoriah Waterland if ((preinstallCheck == B_FALSE) && (update)) { 14455c51f124SMoriah Waterland /* 14465c51f124SMoriah Waterland * If this version and architecture is already installed, 14475c51f124SMoriah Waterland * merge the installed and installing parameters and inform 14485c51f124SMoriah Waterland * all procedure scripts by defining UPDATE in the 14495c51f124SMoriah Waterland * environment. 14505c51f124SMoriah Waterland */ 14515c51f124SMoriah Waterland 14525c51f124SMoriah Waterland if (is_samepkg()) { 14535c51f124SMoriah Waterland /* 14545c51f124SMoriah Waterland * If it's the same ARCH and VERSION, then a merge 14555c51f124SMoriah Waterland * and copy operation is necessary. 14565c51f124SMoriah Waterland */ 14575c51f124SMoriah Waterland 14585c51f124SMoriah Waterland if (n = merg_pkginfos(pclass, &mergd_pclass)) { 14595c51f124SMoriah Waterland quit(n); 14605c51f124SMoriah Waterland /*NOTREACHED*/ 14615c51f124SMoriah Waterland } 14625c51f124SMoriah Waterland 14635c51f124SMoriah Waterland if (n = cp_pkgdirs()) { 14645c51f124SMoriah Waterland quit(n); 14655c51f124SMoriah Waterland /*NOTREACHED*/ 14665c51f124SMoriah Waterland } 14675c51f124SMoriah Waterland 14685c51f124SMoriah Waterland } else { 14695c51f124SMoriah Waterland /* 14705c51f124SMoriah Waterland * If it's a different ARCH and/or VERSION then this 14715c51f124SMoriah Waterland * is an "instance=overwrite" situation. The 14725c51f124SMoriah Waterland * installed base needs to be confirmed and the 14735c51f124SMoriah Waterland * package directories renamed. 14745c51f124SMoriah Waterland */ 14755c51f124SMoriah Waterland 14765c51f124SMoriah Waterland if (n = ck_instbase()) { 14775c51f124SMoriah Waterland quit(n); 14785c51f124SMoriah Waterland /*NOTREACHED*/ 14795c51f124SMoriah Waterland } 14805c51f124SMoriah Waterland 14815c51f124SMoriah Waterland if (n = mv_pkgdirs()) { 14825c51f124SMoriah Waterland quit(n); 14835c51f124SMoriah Waterland /*NOTREACHED*/ 14845c51f124SMoriah Waterland } 14855c51f124SMoriah Waterland } 14865c51f124SMoriah Waterland 14875c51f124SMoriah Waterland putparam("UPDATE", "yes"); 14885c51f124SMoriah Waterland 14895c51f124SMoriah Waterland } 14905c51f124SMoriah Waterland 14915c51f124SMoriah Waterland if (in_dryrun_mode()) { 14925c51f124SMoriah Waterland set_dryrun_dir_loc(); 14935c51f124SMoriah Waterland } 14945c51f124SMoriah Waterland 14955c51f124SMoriah Waterland if (preinstallCheck == B_FALSE) { 14965c51f124SMoriah Waterland /* 14975c51f124SMoriah Waterland * Determine if the package has been partially installed on or 14985c51f124SMoriah Waterland * removed from this system. 14995c51f124SMoriah Waterland */ 15005c51f124SMoriah Waterland ck_w_dryrun(ckpartial, PARTIAL); 15015c51f124SMoriah Waterland 15025c51f124SMoriah Waterland /* 15035c51f124SMoriah Waterland * make sure current runlevel is appropriate 15045c51f124SMoriah Waterland */ 15055c51f124SMoriah Waterland ck_w_dryrun(ckrunlevel, RUNLEVEL); 15065c51f124SMoriah Waterland } else { 15075c51f124SMoriah Waterland int r; 15085c51f124SMoriah Waterland 15095c51f124SMoriah Waterland /* 15105c51f124SMoriah Waterland * Just gathering dependencies - determine if the package has 15115c51f124SMoriah Waterland * been partially installed on or removed from this system and 15125c51f124SMoriah Waterland * output information to stdout 15135c51f124SMoriah Waterland */ 15145c51f124SMoriah Waterland r = ckpartial(); 15155c51f124SMoriah Waterland (void) fprintf(stdout, "ckpartialinstall=%d\n", r == 8 ? 1 : 0); 15165c51f124SMoriah Waterland (void) fprintf(stdout, "ckpartialremove=%d\n", r == 9 ? 1 : 0); 15175c51f124SMoriah Waterland 15185c51f124SMoriah Waterland /* 15195c51f124SMoriah Waterland * make sure current runlevel is appropriate 15205c51f124SMoriah Waterland */ 15215c51f124SMoriah Waterland r = ckrunlevel(); 15225c51f124SMoriah Waterland (void) fprintf(stdout, "ckrunlevel=%d\n", r); 15235c51f124SMoriah Waterland } 15245c51f124SMoriah Waterland 15255c51f124SMoriah Waterland if (pkgdev.cdevice) { 15265c51f124SMoriah Waterland /* get first volume which contains info files */ 15275c51f124SMoriah Waterland unpack(); 15285c51f124SMoriah Waterland if (!suppressCopyright) { 15295c51f124SMoriah Waterland copyright(); 15305c51f124SMoriah Waterland } 15315c51f124SMoriah Waterland } 15325c51f124SMoriah Waterland 15335c51f124SMoriah Waterland /* update the lock - at the request script */ 15345c51f124SMoriah Waterland 15355c51f124SMoriah Waterland lockupd("request"); 15365c51f124SMoriah Waterland 15375c51f124SMoriah Waterland /* 15385c51f124SMoriah Waterland * If no response file has been provided, initialize response file by 15395c51f124SMoriah Waterland * executing any request script provided by this package. Initialize 15405c51f124SMoriah Waterland * the response file if not gathering dependencies only. 15415c51f124SMoriah Waterland */ 15425c51f124SMoriah Waterland 15435c51f124SMoriah Waterland if ((!rdonly_respfile()) && (preinstallCheck == B_FALSE)) { 15445c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), 15455c51f124SMoriah Waterland "%s/%s", instdir, REQUEST_FILE); 15465c51f124SMoriah Waterland n = reqexec(update, path, non_abi_scripts, 15475c51f124SMoriah Waterland run_request_as_root); 15485c51f124SMoriah Waterland if (in_dryrun_mode()) { 15495c51f124SMoriah Waterland set_dr_info(REQUESTEXITCODE, n); 15505c51f124SMoriah Waterland } 15515c51f124SMoriah Waterland 15525c51f124SMoriah Waterland ckreturn(n, ERR_REQUEST); 15535c51f124SMoriah Waterland } 15545c51f124SMoriah Waterland 15555c51f124SMoriah Waterland /* 15565c51f124SMoriah Waterland * Look for all parameters in response file which begin with a 15575c51f124SMoriah Waterland * capital letter, and place them in the environment. 15585c51f124SMoriah Waterland */ 15595c51f124SMoriah Waterland 15605c51f124SMoriah Waterland if ((is_a_respfile()) && (preinstallCheck == B_FALSE)) { 15615c51f124SMoriah Waterland if (n = merg_respfile()) { 15625c51f124SMoriah Waterland quit(n); 15635c51f124SMoriah Waterland /*NOTREACHED*/ 15645c51f124SMoriah Waterland } 15655c51f124SMoriah Waterland } 15665c51f124SMoriah Waterland 15675c51f124SMoriah Waterland /* 15685c51f124SMoriah Waterland * Run a checkinstall script if one is provided by the package. 15695c51f124SMoriah Waterland * Don't execute checkinstall script if we are only updating the DB. 15705c51f124SMoriah Waterland * Don't execute checkinstall script if only gathering dependencies. 15715c51f124SMoriah Waterland */ 15725c51f124SMoriah Waterland 15735c51f124SMoriah Waterland /* update the lock - at the checkinstall script */ 15745c51f124SMoriah Waterland lockupd("checkinstall"); 15755c51f124SMoriah Waterland 15765c51f124SMoriah Waterland /* Execute checkinstall script if one is provided. */ 15775c51f124SMoriah Waterland (void) snprintf(script, sizeof (script), "%s/install/checkinstall", 15785c51f124SMoriah Waterland instdir); 15795c51f124SMoriah Waterland if (access(script, F_OK) != 0) { 15805c51f124SMoriah Waterland /* no script present */ 15815c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_COC_NONE, pkginst, script, 15825c51f124SMoriah Waterland zoneName ? zoneName : "global"); 15835c51f124SMoriah Waterland } else if (is_depend_pkginfo_DB()) { 15845c51f124SMoriah Waterland /* updating db only: skip checkinstall script */ 15855c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_COC_DBUPD, pkginst, script, 15865c51f124SMoriah Waterland zoneName ? zoneName : "global"); 15875c51f124SMoriah Waterland } else if (preinstallCheck == B_TRUE) { 15885c51f124SMoriah Waterland /* only gathering dependencies: skip checkinstall script */ 15895c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_COC_NODEL, pkginst, script, 15905c51f124SMoriah Waterland zoneName ? zoneName : "global"); 15915c51f124SMoriah Waterland } else { 15925c51f124SMoriah Waterland /* script present and ok to run: run the script */ 15935c51f124SMoriah Waterland if (zoneName == (char *)NULL) { 15945c51f124SMoriah Waterland echo(MSG_PKGINSTALL_EXECOC_GZ); 15955c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_EXECOC_GZ, pkginst, script); 15965c51f124SMoriah Waterland } else { 15975c51f124SMoriah Waterland echo(MSG_PKGINSTALL_EXECOC_LZ, zoneName); 15985c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_EXECOC_LZ, pkginst, script, 15995c51f124SMoriah Waterland zoneName); 16005c51f124SMoriah Waterland } 16015c51f124SMoriah Waterland n = chkexec(update, script); 16025c51f124SMoriah Waterland if (in_dryrun_mode()) { 16035c51f124SMoriah Waterland set_dr_info(CHECKEXITCODE, n); 16045c51f124SMoriah Waterland } 16055c51f124SMoriah Waterland 16065c51f124SMoriah Waterland if (n == 3) { 16075c51f124SMoriah Waterland echo(WRN_CHKINSTALL); 16085c51f124SMoriah Waterland ckreturn(4, NULL); 16095c51f124SMoriah Waterland } else if (n == 7) { 16105c51f124SMoriah Waterland /* access returned error */ 16115c51f124SMoriah Waterland progerr(ERR_CHKINSTALL_NOSCRIPT, script); 16125c51f124SMoriah Waterland ckreturn(4, ERR_CHKINSTALL); 16135c51f124SMoriah Waterland } else { 16145c51f124SMoriah Waterland ckreturn(n, ERR_CHKINSTALL); 16155c51f124SMoriah Waterland } 16165c51f124SMoriah Waterland } 16175c51f124SMoriah Waterland 16185c51f124SMoriah Waterland /* 16195c51f124SMoriah Waterland * Now that the internal data structures are initialized, we can 16205c51f124SMoriah Waterland * initialize the dryrun files (which may be the same files). 16215c51f124SMoriah Waterland */ 16225c51f124SMoriah Waterland 16235c51f124SMoriah Waterland if (pkgdrtarg) { 16245c51f124SMoriah Waterland init_dryrunfile(pkgdrtarg); 16255c51f124SMoriah Waterland } 16265c51f124SMoriah Waterland 16275c51f124SMoriah Waterland /* 16285c51f124SMoriah Waterland * Look for all parameters in response file which begin with a 16295c51f124SMoriah Waterland * capital letter, and place them in the environment. 16305c51f124SMoriah Waterland */ 16315c51f124SMoriah Waterland if (is_a_respfile()) { 16325c51f124SMoriah Waterland if (n = merg_respfile()) { 16335c51f124SMoriah Waterland quit(n); 16345c51f124SMoriah Waterland /*NOTREACHED*/ 16355c51f124SMoriah Waterland } 16365c51f124SMoriah Waterland } 16375c51f124SMoriah Waterland 16385c51f124SMoriah Waterland /* update the lock - doing analysis */ 16395c51f124SMoriah Waterland 16405c51f124SMoriah Waterland lockupd("analysis"); 16415c51f124SMoriah Waterland 16425c51f124SMoriah Waterland /* 16435c51f124SMoriah Waterland * Determine package base directory and client base directory 16445c51f124SMoriah Waterland * if appropriate. Then encapsulate them for future retrieval. 16455c51f124SMoriah Waterland */ 16465c51f124SMoriah Waterland if ((err = set_basedirs(isreloc(instdir), adm.basedir, pkginst, 16475c51f124SMoriah Waterland nointeract)) != 0) { 16485c51f124SMoriah Waterland quit(err); 16495c51f124SMoriah Waterland /*NOTREACHED*/ 16505c51f124SMoriah Waterland } 16515c51f124SMoriah Waterland 16525c51f124SMoriah Waterland /* 16535c51f124SMoriah Waterland * Create the base directory if specified. 16545c51f124SMoriah Waterland * Don't create if we are only updating the DB. 16555c51f124SMoriah Waterland * Don't create if only gathering dependencies. 16565c51f124SMoriah Waterland */ 16575c51f124SMoriah Waterland 16585c51f124SMoriah Waterland if (!is_depend_pkginfo_DB() && 16595c51f124SMoriah Waterland !preinstallCheck && is_a_basedir()) { 16605c51f124SMoriah Waterland mkbasedir(!nointeract, get_basedir()); 16615c51f124SMoriah Waterland echo(MSG_BASE_USED, get_basedir()); 16625c51f124SMoriah Waterland } 16635c51f124SMoriah Waterland 16645c51f124SMoriah Waterland /* 16655c51f124SMoriah Waterland * Store PKG_INSTALL_ROOT, BASEDIR & CLIENT_BASEDIR in our 16665c51f124SMoriah Waterland * environment for later use by procedure scripts. 16675c51f124SMoriah Waterland */ 16685c51f124SMoriah Waterland put_path_params(); 16695c51f124SMoriah Waterland 16705c51f124SMoriah Waterland /* 16715c51f124SMoriah Waterland * the following two checks are done in the corresponding 16725c51f124SMoriah Waterland * ck() routine, but are repeated here to avoid re-processing 16735c51f124SMoriah Waterland * the database if we are administered to not include these 16745c51f124SMoriah Waterland * processes 16755c51f124SMoriah Waterland */ 16765c51f124SMoriah Waterland if (ADM(setuid, "nochange")) { 16775c51f124SMoriah Waterland nosetuid++; /* Clear setuid/gid bits. */ 16785c51f124SMoriah Waterland } 16795c51f124SMoriah Waterland 16805c51f124SMoriah Waterland if (ADM(conflict, "nochange")) { 16815c51f124SMoriah Waterland nocnflct++; /* Don't install conflicting files. */ 16825c51f124SMoriah Waterland } 16835c51f124SMoriah Waterland 16845c51f124SMoriah Waterland /* 16855c51f124SMoriah Waterland * Get the filesystem space information for the filesystem on which 16865c51f124SMoriah Waterland * the "contents" file resides. 16875c51f124SMoriah Waterland */ 16885c51f124SMoriah Waterland 16895c51f124SMoriah Waterland svfsb.f_bsize = 8192; 16905c51f124SMoriah Waterland svfsb.f_frsize = 1024; 16915c51f124SMoriah Waterland 16925c51f124SMoriah Waterland if (statvfs64(get_PKGADM(), &svfsb) == -1) { 16935c51f124SMoriah Waterland int lerrno = errno; 16945c51f124SMoriah Waterland if (!access(get_PKGADM(), F_OK)) { 16955c51f124SMoriah Waterland progerr(ERR_PKGINSTALL_STATVFS, get_PKGADM(), 16965c51f124SMoriah Waterland strerror(errno)); 16975c51f124SMoriah Waterland logerr("(errno %d)", lerrno); 16985c51f124SMoriah Waterland quit(99); 16995c51f124SMoriah Waterland /*NOTREACHED*/ 17005c51f124SMoriah Waterland } 17015c51f124SMoriah Waterland } 17025c51f124SMoriah Waterland 17035c51f124SMoriah Waterland /* 17045c51f124SMoriah Waterland * Get the number of blocks used by the pkgmap, ocfile() 17055c51f124SMoriah Waterland * needs this to properly determine its space requirements. 17065c51f124SMoriah Waterland */ 17075c51f124SMoriah Waterland 17085c51f124SMoriah Waterland if (stat(p_pkgmap, &statb) == -1) { 17095c51f124SMoriah Waterland progerr(ERR_PKGINSTALL_STATOF, p_pkgmap, strerror(errno)); 17105c51f124SMoriah Waterland quit(99); 17115c51f124SMoriah Waterland /*NOTREACHED*/ 17125c51f124SMoriah Waterland } 17135c51f124SMoriah Waterland 17145c51f124SMoriah Waterland pkgmap_blks = nblk(statb.st_size, svfsb.f_bsize, svfsb.f_frsize); 17155c51f124SMoriah Waterland 17165c51f124SMoriah Waterland /* 17175c51f124SMoriah Waterland * Merge information in memory with the "contents" file; this creates 17185c51f124SMoriah Waterland * a temporary version of the "contents" file. Note that in dryrun 17195c51f124SMoriah Waterland * mode, we still need to record the contents file data somewhere, 17205c51f124SMoriah Waterland * but we do it in the dryrun directory. 17215c51f124SMoriah Waterland */ 17225c51f124SMoriah Waterland 17235c51f124SMoriah Waterland if (in_dryrun_mode()) { 17245c51f124SMoriah Waterland if (n = set_cfdir(pkgdrtarg)) { 17255c51f124SMoriah Waterland quit(n); 17265c51f124SMoriah Waterland /*NOTREACHED*/ 17275c51f124SMoriah Waterland } 17285c51f124SMoriah Waterland } else { 17295c51f124SMoriah Waterland if (n = set_cfdir(NULL)) { 17305c51f124SMoriah Waterland quit(n); 17315c51f124SMoriah Waterland /*NOTREACHED*/ 17325c51f124SMoriah Waterland } 17335c51f124SMoriah Waterland } 173462224350SCasper H.S. Dik if (!ocfile(&pkgserver, &cfTmpVfp, pkgmap_blks)) { 17355c51f124SMoriah Waterland quit(99); 17365c51f124SMoriah Waterland /*NOTREACHED*/ 17375c51f124SMoriah Waterland } 17385c51f124SMoriah Waterland 17395c51f124SMoriah Waterland /* 17405c51f124SMoriah Waterland * if cpio is being used, tell pkgdbmerg since attributes will 17415c51f124SMoriah Waterland * have to be check and repaired on all file and directories 17425c51f124SMoriah Waterland */ 17435c51f124SMoriah Waterland for (np = cpio_names; *np != NULL; np++) { 17445c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), 17455c51f124SMoriah Waterland "%s/%s", instdir, *np); 17465c51f124SMoriah Waterland if (iscpio(path, &is_comp_arch)) { 17475c51f124SMoriah Waterland is_WOS_arch(); 17485c51f124SMoriah Waterland break; 17495c51f124SMoriah Waterland } 17505c51f124SMoriah Waterland } 17515c51f124SMoriah Waterland 17525c51f124SMoriah Waterland /* Establish the class list and the class attributes. */ 17535c51f124SMoriah Waterland cl_sets(getenv("CLASSES")); 17545c51f124SMoriah Waterland find_CAS(I_ONLY, pkgbin, instdir); 17555c51f124SMoriah Waterland 17565c51f124SMoriah Waterland if (vfpOpen(&pkgmapVfp, p_pkgmap, "r", VFP_NEEDNOW) != 0) { 17575c51f124SMoriah Waterland progerr(ERR_PKGMAP, p_pkgmap); 17585c51f124SMoriah Waterland quit(99); 17595c51f124SMoriah Waterland /*NOTREACHED*/ 17605c51f124SMoriah Waterland } 17615c51f124SMoriah Waterland 17625c51f124SMoriah Waterland /* 17635c51f124SMoriah Waterland * This modifies the path list entries in memory to reflect 17645c51f124SMoriah Waterland * how they should look after the merg is complete 17655c51f124SMoriah Waterland */ 17665c51f124SMoriah Waterland 176762224350SCasper H.S. Dik nparts = sortmap(&extlist, pkgmapVfp, pkgserver, cfTmpVfp, zoneName); 17685c51f124SMoriah Waterland 17695c51f124SMoriah Waterland if ((n = files_installed()) > 0) { 17705c51f124SMoriah Waterland if (n > 1) { 17715c51f124SMoriah Waterland echo(MSG_INST_MANY, n); 17725c51f124SMoriah Waterland } else { 17735c51f124SMoriah Waterland echo(MSG_INST_ONE, n); 17745c51f124SMoriah Waterland } 17755c51f124SMoriah Waterland } 17765c51f124SMoriah Waterland 17775c51f124SMoriah Waterland /* 17785c51f124SMoriah Waterland * Check ulimit requirement (provided in pkginfo). The purpose of 17795c51f124SMoriah Waterland * this limit is to terminate pathological file growth resulting from 17805c51f124SMoriah Waterland * file edits in scripts. It does not apply to files in the pkgmap 17815c51f124SMoriah Waterland * and it does not apply to any database files manipulated by the 17825c51f124SMoriah Waterland * installation service. 17835c51f124SMoriah Waterland */ 17845c51f124SMoriah Waterland if (pt = getenv("ULIMIT")) { 17855c51f124SMoriah Waterland if (assign_ulimit(pt) == -1) { 17865c51f124SMoriah Waterland progerr(ERR_BADULIMIT, pt); 17875c51f124SMoriah Waterland quit(99); 17885c51f124SMoriah Waterland /*NOTREACHED*/ 17895c51f124SMoriah Waterland } 17905c51f124SMoriah Waterland putparam("PKG_ULIMIT", "TRUE"); 17915c51f124SMoriah Waterland } 17925c51f124SMoriah Waterland 17935c51f124SMoriah Waterland /* 17945c51f124SMoriah Waterland * If only gathering dependencies, check and output status of all 17955c51f124SMoriah Waterland * remaining dependencies and exit. 17965c51f124SMoriah Waterland */ 17975c51f124SMoriah Waterland 17985c51f124SMoriah Waterland if (preinstallCheck == B_TRUE) { 17995c51f124SMoriah Waterland /* update the lock file - final checking */ 18005c51f124SMoriah Waterland 18015c51f124SMoriah Waterland lockupd("preinstallcheck"); 18025c51f124SMoriah Waterland 18035c51f124SMoriah Waterland /* verify package information files are not corrupt */ 18045c51f124SMoriah Waterland 18055c51f124SMoriah Waterland (void) fprintf(stdout, "ckpkgfiles=%d\n", ckpkgfiles()); 18065c51f124SMoriah Waterland 18075c51f124SMoriah Waterland /* verify package dependencies */ 18085c51f124SMoriah Waterland 18095c51f124SMoriah Waterland (void) fprintf(stdout, "ckdepend=%d\n", ckdepend()); 18105c51f124SMoriah Waterland 18115c51f124SMoriah Waterland /* Check space requirements */ 18125c51f124SMoriah Waterland 18135c51f124SMoriah Waterland (void) fprintf(stdout, "ckspace=%d\n", ckspace()); 18145c51f124SMoriah Waterland 18155c51f124SMoriah Waterland /* 18165c51f124SMoriah Waterland * Determine if any objects provided by this package conflict 18175c51f124SMoriah Waterland * with the files of previously installed packages. 18185c51f124SMoriah Waterland */ 18195c51f124SMoriah Waterland 18205c51f124SMoriah Waterland (void) fprintf(stdout, "ckconflict=%d\n", ckconflct()); 18215c51f124SMoriah Waterland 18225c51f124SMoriah Waterland /* 18235c51f124SMoriah Waterland * Determine if any objects provided by this package will be 18245c51f124SMoriah Waterland * installed with setuid or setgid enabled. 18255c51f124SMoriah Waterland */ 18265c51f124SMoriah Waterland 18275c51f124SMoriah Waterland (void) fprintf(stdout, "cksetuid=%d\n", cksetuid()); 18285c51f124SMoriah Waterland 18295c51f124SMoriah Waterland /* 18305c51f124SMoriah Waterland * Determine if any packaging scripts provided with this package 18315c51f124SMoriah Waterland * will execute as a priviledged user. 18325c51f124SMoriah Waterland */ 18335c51f124SMoriah Waterland 18345c51f124SMoriah Waterland (void) fprintf(stdout, "ckpriv=%d\n", ckpriv()); 18355c51f124SMoriah Waterland 18365c51f124SMoriah Waterland /* Verify neccessary package installation directories exist */ 18375c51f124SMoriah Waterland 18385c51f124SMoriah Waterland (void) fprintf(stdout, "ckpkgdirs=%d\n", ckpkgdirs()); 18395c51f124SMoriah Waterland 18405c51f124SMoriah Waterland /* 18415c51f124SMoriah Waterland * ****** preinstall check done - exit ****** 18425c51f124SMoriah Waterland */ 18435c51f124SMoriah Waterland 18445c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_PREINSCHK_OK); 18455c51f124SMoriah Waterland quit(0); 18465c51f124SMoriah Waterland /*NOTREACHED*/ 18475c51f124SMoriah Waterland } 18485c51f124SMoriah Waterland 18495c51f124SMoriah Waterland /* 18505c51f124SMoriah Waterland * Not gathering dependencies only, proceed to check dependencies 18515c51f124SMoriah Waterland * and continue with the package installation operation. 18525c51f124SMoriah Waterland */ 18535c51f124SMoriah Waterland 18545c51f124SMoriah Waterland /* 18555c51f124SMoriah Waterland * verify package information files are not corrupt 18565c51f124SMoriah Waterland */ 18575c51f124SMoriah Waterland ck_w_dryrun(ckpkgfiles, PKGFILES); 18585c51f124SMoriah Waterland 18595c51f124SMoriah Waterland /* 18605c51f124SMoriah Waterland * verify package dependencies 18615c51f124SMoriah Waterland */ 18625c51f124SMoriah Waterland ck_w_dryrun(ckdepend, DEPEND); 18635c51f124SMoriah Waterland 18645c51f124SMoriah Waterland /* 18655c51f124SMoriah Waterland * Check space requirements. 18665c51f124SMoriah Waterland */ 18675c51f124SMoriah Waterland ck_w_dryrun(ckspace, SPACE); 18685c51f124SMoriah Waterland 18695c51f124SMoriah Waterland /* 18705c51f124SMoriah Waterland * Determine if any objects provided by this package conflict with 18715c51f124SMoriah Waterland * the files of previously installed packages. 18725c51f124SMoriah Waterland */ 18735c51f124SMoriah Waterland ck_w_dryrun(ckconflct, CONFLICT); 18745c51f124SMoriah Waterland 18755c51f124SMoriah Waterland /* 18765c51f124SMoriah Waterland * Determine if any objects provided by this package will be 18775c51f124SMoriah Waterland * installed with setuid or setgid enabled. 18785c51f124SMoriah Waterland */ 18795c51f124SMoriah Waterland ck_w_dryrun(cksetuid, SETUID); 18805c51f124SMoriah Waterland 18815c51f124SMoriah Waterland /* 18825c51f124SMoriah Waterland * Determine if any packaging scripts provided with this package will 18835c51f124SMoriah Waterland * execute as a priviledged user. 18845c51f124SMoriah Waterland */ 18855c51f124SMoriah Waterland ck_w_dryrun(ckpriv, PRIV); 18865c51f124SMoriah Waterland 18875c51f124SMoriah Waterland /* 18885c51f124SMoriah Waterland * Verify neccessary package installation directories exist. 18895c51f124SMoriah Waterland */ 18905c51f124SMoriah Waterland ck_w_dryrun(ckpkgdirs, PKGDIRS); 18915c51f124SMoriah Waterland 18925c51f124SMoriah Waterland /* 18935c51f124SMoriah Waterland * If we have assumed that we were installing setuid or conflicting 18945c51f124SMoriah Waterland * files, and the user chose to do otherwise, we need to read in the 18955c51f124SMoriah Waterland * package map again and re-merg with the "contents" file 18965c51f124SMoriah Waterland */ 18975c51f124SMoriah Waterland 18985c51f124SMoriah Waterland if (rprcflag) { 189962224350SCasper H.S. Dik nparts = sortmap(&extlist, pkgmapVfp, pkgserver, 19005c51f124SMoriah Waterland cfTmpVfp, zoneName); 19015c51f124SMoriah Waterland } 19025c51f124SMoriah Waterland 19035c51f124SMoriah Waterland (void) vfpClose(&pkgmapVfp); 19045c51f124SMoriah Waterland 19055c51f124SMoriah Waterland /* BEGIN INSTALLATION PHASE */ 19065c51f124SMoriah Waterland if (in_dryrun_mode()) { 19075c51f124SMoriah Waterland echo(MSG_PKGINSTALL_DRYRUN, pkgname, pkginst); 19085c51f124SMoriah Waterland } else if (zoneName == (char *)NULL) { 19095c51f124SMoriah Waterland echo(MSG_PKGINSTALL_INSIN_GZ, pkgname, pkginst); 19105c51f124SMoriah Waterland } else { 19115c51f124SMoriah Waterland echo(MSG_PKGINSTALL_INSIN_LZ, pkgname, pkginst, zoneName); 19125c51f124SMoriah Waterland } 19135c51f124SMoriah Waterland 19145c51f124SMoriah Waterland /* inform quit that the install has started */ 19155c51f124SMoriah Waterland 19165c51f124SMoriah Waterland quitSetInstallStarted(B_TRUE); 19175c51f124SMoriah Waterland 19185c51f124SMoriah Waterland /* 19195c51f124SMoriah Waterland * This replaces the contents file with recently created temp version 19205c51f124SMoriah Waterland * which contains information about the objects being installed. 19215c51f124SMoriah Waterland * Under old lock protocol it closes both files and releases the 19225c51f124SMoriah Waterland * locks. Beginning in Solaris 2.7, this lock method should be 19235c51f124SMoriah Waterland * reviewed. 19245c51f124SMoriah Waterland */ 19255c51f124SMoriah Waterland 192662224350SCasper H.S. Dik n = swapcfile(pkgserver, &cfTmpVfp, pkginst, dbchg); 19275c51f124SMoriah Waterland if (n == RESULT_WRN) { 19285c51f124SMoriah Waterland warnflag++; 19295c51f124SMoriah Waterland } else if (n == RESULT_ERR) { 19305c51f124SMoriah Waterland quit(99); 19315c51f124SMoriah Waterland /*NOTREACHED*/ 19325c51f124SMoriah Waterland } 19335c51f124SMoriah Waterland 19345c51f124SMoriah Waterland /* 19355c51f124SMoriah Waterland * Create install-specific lockfile to indicate start of 19365c51f124SMoriah Waterland * installation. This is really just an information file. If the 19375c51f124SMoriah Waterland * process dies, the initial lockfile (from lockinst(), is 19385c51f124SMoriah Waterland * relinquished by the kernel, but this one remains in support of the 19395c51f124SMoriah Waterland * post-mortem. 19405c51f124SMoriah Waterland */ 19415c51f124SMoriah Waterland 19425c51f124SMoriah Waterland if (access(ilockfile, F_OK) == 0) { 19435c51f124SMoriah Waterland (void) remove(ilockfile); 19445c51f124SMoriah Waterland } 19455c51f124SMoriah Waterland 19465c51f124SMoriah Waterland if (open(ilockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644) < 0) { 19475c51f124SMoriah Waterland progerr(ERR_LOCKFILE, ilockfile); 19485c51f124SMoriah Waterland quit(99); 19495c51f124SMoriah Waterland /*NOTREACHED*/ 19505c51f124SMoriah Waterland } 19515c51f124SMoriah Waterland 19525c51f124SMoriah Waterland (void) time(&clock); 1953a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 1954a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" /* 1955a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" * We do not want the time in locale in the pkginfo. 1956a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" * save the LC_TIME and set it to C. Reset it with saved one 1957a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" * after cftime(). 1958a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" */ 1959a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" temp = setlocale(LC_TIME, NULL); 1960a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" (void) setlocale(LC_TIME, "C"); 1961a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 19625c51f124SMoriah Waterland /* LINTED warning: do not use cftime(); ... */ 19635c51f124SMoriah Waterland (void) cftime(cbuf, "%b %d \045Y \045H:\045M", &clock); 19645c51f124SMoriah Waterland putparam("INSTDATE", qstrdup(cbuf)); 1965a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" (void) setlocale(LC_TIME, temp); 19665c51f124SMoriah Waterland 19675c51f124SMoriah Waterland /* 19685c51f124SMoriah Waterland * Store information about package being installed; 19695c51f124SMoriah Waterland * modify installation parameters as neccessary and 19705c51f124SMoriah Waterland * copy contents of 'install' directory into $pkgloc 19715c51f124SMoriah Waterland */ 19725c51f124SMoriah Waterland merginfo(mergd_pclass, saveSpoolInstall); 19735c51f124SMoriah Waterland 19745c51f124SMoriah Waterland /* If this was just a dryrun, then quit() will write out that file. */ 19755c51f124SMoriah Waterland if (in_dryrun_mode()) { 19765c51f124SMoriah Waterland quit(0); 19775c51f124SMoriah Waterland /*NOTREACHED*/ 19785c51f124SMoriah Waterland } 19795c51f124SMoriah Waterland 19805c51f124SMoriah Waterland /* 19815c51f124SMoriah Waterland * Execute preinstall script, if one was provided with the 19825c51f124SMoriah Waterland * package. We check the package to avoid running an old 19835c51f124SMoriah Waterland * preinstall script if one was provided with a prior instance. 19845c51f124SMoriah Waterland * Don't execute preinstall script if we are only updating the DB. 19855c51f124SMoriah Waterland */ 19865c51f124SMoriah Waterland 19875c51f124SMoriah Waterland /* update the lock - at the preinstall altscript */ 19885c51f124SMoriah Waterland lockupd("preinstall"); 19895c51f124SMoriah Waterland 19905c51f124SMoriah Waterland /* preinstall script in the media (package source) */ 19915c51f124SMoriah Waterland (void) snprintf(altscript, sizeof (altscript), "%s/install/preinstall", 19925c51f124SMoriah Waterland instdir); 19935c51f124SMoriah Waterland 19945c51f124SMoriah Waterland /* preinstall script in the pkgbin instead of media */ 19955c51f124SMoriah Waterland (void) snprintf(script, sizeof (script), "%s/preinstall", pkgbin); 19965c51f124SMoriah Waterland 19975c51f124SMoriah Waterland if (access(altscript, F_OK) != 0) { 19985c51f124SMoriah Waterland /* no script present */ 19995c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_POCALT_NONE, pkginst, altscript, 20005c51f124SMoriah Waterland zoneName ? zoneName : "global"); 20015c51f124SMoriah Waterland } else if (access(script, F_OK) != 0) { 20025c51f124SMoriah Waterland /* no script present */ 20035c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_POC_NONE, pkginst, script, 20045c51f124SMoriah Waterland zoneName ? zoneName : "global"); 20055c51f124SMoriah Waterland } else if (is_depend_pkginfo_DB()) { 20065c51f124SMoriah Waterland /* updating db only: skip preinstall script */ 20075c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_POC_DBUPD, pkginst, script, 20085c51f124SMoriah Waterland zoneName ? zoneName : "global"); 20095c51f124SMoriah Waterland } else { 20105c51f124SMoriah Waterland /* script present and ok to run: run the script */ 20115c51f124SMoriah Waterland assert(preinstallCheck == B_FALSE); 20125c51f124SMoriah Waterland 20135c51f124SMoriah Waterland set_ulimit("preinstall", ERR_PREINSTALL); 20145c51f124SMoriah Waterland if (zoneName == (char *)NULL) { 20155c51f124SMoriah Waterland echo(MSG_PKGINSTALL_EXEPOC_GZ); 20165c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_EXEPOC_GZ, pkginst, script); 20175c51f124SMoriah Waterland } else { 20185c51f124SMoriah Waterland echo(MSG_PKGINSTALL_EXEPOC_LZ, zoneName); 20195c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_EXEPOC_LZ, pkginst, script, 20205c51f124SMoriah Waterland zoneName); 20215c51f124SMoriah Waterland } 20225c51f124SMoriah Waterland putparam("PKG_PROC_script", "preinstall"); 20235c51f124SMoriah Waterland if (pkgverbose) { 20245c51f124SMoriah Waterland ckreturn(pkgexecl(script_in, PROC_STDOUT, 20255c51f124SMoriah Waterland PROC_USER, PROC_GRP, SHELL, "-x", 20265c51f124SMoriah Waterland script, NULL), ERR_PREINSTALL); 20275c51f124SMoriah Waterland } else { 20285c51f124SMoriah Waterland ckreturn(pkgexecl(script_in, PROC_STDOUT, 20295c51f124SMoriah Waterland PROC_USER, PROC_GRP, SHELL, script, 20305c51f124SMoriah Waterland NULL), ERR_PREINSTALL); 20315c51f124SMoriah Waterland } 20325c51f124SMoriah Waterland 20335c51f124SMoriah Waterland clr_ulimit(); 20345c51f124SMoriah Waterland (void) remove(script); /* no longer needed. */ 20355c51f124SMoriah Waterland } 20365c51f124SMoriah Waterland 20375c51f124SMoriah Waterland /* 20385c51f124SMoriah Waterland * Check delivered package for a postinstall script while 20395c51f124SMoriah Waterland * we're still on volume 1. 20405c51f124SMoriah Waterland */ 20415c51f124SMoriah Waterland 20425c51f124SMoriah Waterland (void) snprintf(script, sizeof (script), 20435c51f124SMoriah Waterland "%s/install/postinstall", instdir); 20445c51f124SMoriah Waterland if (access(script, F_OK) == 0) { 20455c51f124SMoriah Waterland (void) snprintf(script, sizeof (script), 20465c51f124SMoriah Waterland "%s/postinstall", pkgbin); 20475c51f124SMoriah Waterland } else { 20485c51f124SMoriah Waterland script[0] = '\0'; 20495c51f124SMoriah Waterland } 20505c51f124SMoriah Waterland 20515c51f124SMoriah Waterland /* update the lock - at the install phase */ 20525c51f124SMoriah Waterland 20535c51f124SMoriah Waterland lockupd("install"); 20545c51f124SMoriah Waterland 20555c51f124SMoriah Waterland /* 20565c51f124SMoriah Waterland * install package one part (volume) at a time 20575c51f124SMoriah Waterland */ 20585c51f124SMoriah Waterland 20595c51f124SMoriah Waterland part = 1; 20605c51f124SMoriah Waterland while (part <= nparts) { 20615c51f124SMoriah Waterland if ((part > 1) && pkgdev.cdevice) { 20625c51f124SMoriah Waterland unpack(); 20635c51f124SMoriah Waterland } 20645c51f124SMoriah Waterland 20655c51f124SMoriah Waterland instvol(extlist, srcinst, part, nparts, 20666e1ae2a3SGary Pennington pkgserver, &cfTmpVfp, &updated, zoneName); 20675c51f124SMoriah Waterland 20685c51f124SMoriah Waterland if (part++ >= nparts) { 20695c51f124SMoriah Waterland break; 20705c51f124SMoriah Waterland } 20715c51f124SMoriah Waterland } 20725c51f124SMoriah Waterland 20735c51f124SMoriah Waterland z_destroyMountTable(); 20745c51f124SMoriah Waterland 20755c51f124SMoriah Waterland /* 20765c51f124SMoriah Waterland * Now that all install class action scripts have been used, we 20775c51f124SMoriah Waterland * delete them from the package directory. 20785c51f124SMoriah Waterland */ 20795c51f124SMoriah Waterland rm_icas(pkgbin); 20805c51f124SMoriah Waterland 2081*4656d474SGarrett D'Amore if (globalZoneOnly) { 20825c51f124SMoriah Waterland boolean_t b; 20835c51f124SMoriah Waterland b = pkgAddPackageToGzonlyList(pkginst, get_inst_root()); 20845c51f124SMoriah Waterland if (b == B_FALSE) { 20855c51f124SMoriah Waterland progerr(ERR_PKGINSTALL_GZONLY_ADD, pkginst); 20865c51f124SMoriah Waterland ckreturn(1, NULL); 20875c51f124SMoriah Waterland } 20885c51f124SMoriah Waterland } 20895c51f124SMoriah Waterland 20905c51f124SMoriah Waterland /* 20915c51f124SMoriah Waterland * Execute postinstall script, if any 20925c51f124SMoriah Waterland * Don't execute postinstall script if we are only updating the DB. 20935c51f124SMoriah Waterland */ 20945c51f124SMoriah Waterland 20955c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_INSDONE, is_depend_pkginfo_DB(), 20965c51f124SMoriah Waterland is_depend_pkginfo_DB(), saveSpoolInstall, 20975c51f124SMoriah Waterland updated ? updated : "", 20985c51f124SMoriah Waterland script ? script : "", 20995c51f124SMoriah Waterland script ? access(script, F_OK) : -1); 21005c51f124SMoriah Waterland 21015c51f124SMoriah Waterland /* update the lock - at the postinstall script */ 21025c51f124SMoriah Waterland lockupd("postinstall"); 21035c51f124SMoriah Waterland 21045c51f124SMoriah Waterland if ((script == (char *)NULL) || (*script == '\0')) { 21055c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_POIS_NOPATH, pkginst, 21065c51f124SMoriah Waterland zoneName ? zoneName : "global"); 21075c51f124SMoriah Waterland } else if (access(script, F_OK) != 0) { 21085c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_POIS_NONE, pkginst, script, 21095c51f124SMoriah Waterland zoneName ? zoneName : "global"); 21105c51f124SMoriah Waterland } else if (is_depend_pkginfo_DB()) { 21115c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_POIS_DBUPD, pkginst, script, 21125c51f124SMoriah Waterland zoneName ? zoneName : "global"); 21136e1ae2a3SGary Pennington } else if ((saveSpoolInstall != 0) && (updated == (char *)NULL)) { 21145c51f124SMoriah Waterland /* 21155c51f124SMoriah Waterland * fresh installing into non-global zone, no object was 21166e1ae2a3SGary Pennington * updated (installed/verified in area), so do not run 21176e1ae2a3SGary Pennington * the postinstall script. 21185c51f124SMoriah Waterland */ 21196e1ae2a3SGary Pennington echoDebug(DBG_PKGINSTALL_POIS_NOUPDATING, 21205c51f124SMoriah Waterland zoneName ? zoneName : "global", pkginst, script); 21215c51f124SMoriah Waterland } else { 21225c51f124SMoriah Waterland /* script present and ok to run: run the script */ 21235c51f124SMoriah Waterland set_ulimit("postinstall", ERR_POSTINSTALL); 21245c51f124SMoriah Waterland if (zoneName == (char *)NULL) { 21255c51f124SMoriah Waterland echo(MSG_PKGINSTALL_EXEPIC_GZ); 21265c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_EXEPIC_GZ, pkginst, script); 21275c51f124SMoriah Waterland } else { 21285c51f124SMoriah Waterland echo(MSG_PKGINSTALL_EXEPIC_LZ, zoneName); 21295c51f124SMoriah Waterland echoDebug(DBG_PKGINSTALL_EXEPIC_LZ, pkginst, script, 21305c51f124SMoriah Waterland zoneName); 21315c51f124SMoriah Waterland } 21325c51f124SMoriah Waterland putparam("PKG_PROC_SCRIPT", "postinstall"); 21335c51f124SMoriah Waterland putparam("TMPDIR", tmpdir); 21345c51f124SMoriah Waterland if (pkgverbose) { 21355c51f124SMoriah Waterland ckreturn(pkgexecl(script_in, PROC_STDOUT, 21365c51f124SMoriah Waterland PROC_USER, PROC_GRP, SHELL, "-x", 21375c51f124SMoriah Waterland script, NULL), ERR_POSTINSTALL); 21385c51f124SMoriah Waterland } else { 21395c51f124SMoriah Waterland ckreturn(pkgexecl(script_in, PROC_STDOUT, 21405c51f124SMoriah Waterland PROC_USER, PROC_GRP, SHELL, script, 21415c51f124SMoriah Waterland NULL), ERR_POSTINSTALL); 21425c51f124SMoriah Waterland } 21435c51f124SMoriah Waterland 21445c51f124SMoriah Waterland clr_ulimit(); 21455c51f124SMoriah Waterland (void) remove(script); /* no longer needed */ 21465c51f124SMoriah Waterland } 21475c51f124SMoriah Waterland 21485c51f124SMoriah Waterland if (!warnflag && !failflag) { 21495c51f124SMoriah Waterland (void) remove(rlockfile); 21505c51f124SMoriah Waterland (void) remove(ilockfile); 21515c51f124SMoriah Waterland (void) remove(savlog); 21525c51f124SMoriah Waterland } 21535c51f124SMoriah Waterland 21545c51f124SMoriah Waterland /* release the generic package lock */ 21555c51f124SMoriah Waterland 21565c51f124SMoriah Waterland (void) unlockinst(); 21575c51f124SMoriah Waterland 215862224350SCasper H.S. Dik pkgcloseserver(pkgserver); 215962224350SCasper H.S. Dik 21605c51f124SMoriah Waterland quit(0); 21615c51f124SMoriah Waterland /* LINTED: no return */ 21625c51f124SMoriah Waterland } 21635c51f124SMoriah Waterland 21645c51f124SMoriah Waterland /* 21655c51f124SMoriah Waterland * This function merges the environment data in the response file with the 21665c51f124SMoriah Waterland * current environment. 21675c51f124SMoriah Waterland */ 21685c51f124SMoriah Waterland static int 21695c51f124SMoriah Waterland merg_respfile() 21705c51f124SMoriah Waterland { 21715c51f124SMoriah Waterland int retcode = 0; 21725c51f124SMoriah Waterland char *resppath = get_respfile(); 21735c51f124SMoriah Waterland char *locbasedir; 21745c51f124SMoriah Waterland char param[MAX_PKG_PARAM_LENGTH], *value; 21755c51f124SMoriah Waterland FILE *fp; 21765c51f124SMoriah Waterland 21775c51f124SMoriah Waterland if ((fp = fopen(resppath, "r")) == NULL) { 21785c51f124SMoriah Waterland progerr(ERR_RESPONSE, resppath); 21795c51f124SMoriah Waterland return (99); 21805c51f124SMoriah Waterland } 21815c51f124SMoriah Waterland 21825c51f124SMoriah Waterland param[0] = '\0'; 21835c51f124SMoriah Waterland 21845c51f124SMoriah Waterland while (value = fpkgparam(fp, param)) { 21855c51f124SMoriah Waterland if (!isupper(param[0])) { 21865c51f124SMoriah Waterland param[0] = '\0'; 21875c51f124SMoriah Waterland continue; 21885c51f124SMoriah Waterland } 21895c51f124SMoriah Waterland 21905c51f124SMoriah Waterland if (rdonly(param)) { 21915c51f124SMoriah Waterland progerr(ERR_RDONLY, param); 21925c51f124SMoriah Waterland param[0] = '\0'; 21935c51f124SMoriah Waterland continue; 21945c51f124SMoriah Waterland } 21955c51f124SMoriah Waterland 21965c51f124SMoriah Waterland /* 21975c51f124SMoriah Waterland * If this is an update, and the response file 21985c51f124SMoriah Waterland * specifies the BASEDIR, make sure it matches the 21995c51f124SMoriah Waterland * existing installation base. If it doesn't, we have 22005c51f124SMoriah Waterland * to quit. 22015c51f124SMoriah Waterland */ 22025c51f124SMoriah Waterland if (update && strcmp("BASEDIR", param) == 0) { 22035c51f124SMoriah Waterland locbasedir = getenv("BASEDIR"); 22045c51f124SMoriah Waterland if (locbasedir && strcmp(value, locbasedir) != 0) { 22055c51f124SMoriah Waterland char *dotptr; 22065c51f124SMoriah Waterland /* Get srcinst down to a name. */ 22075c51f124SMoriah Waterland if (dotptr = strchr(srcinst, '.')) 22085c51f124SMoriah Waterland *dotptr = '\000'; 22095c51f124SMoriah Waterland progerr(ERR_NEWBD, srcinst, 22105c51f124SMoriah Waterland locbasedir, value); 22115c51f124SMoriah Waterland retcode = 99; 22125c51f124SMoriah Waterland } 22135c51f124SMoriah Waterland } 22145c51f124SMoriah Waterland 22155c51f124SMoriah Waterland putparam(param, value); 22165c51f124SMoriah Waterland param[0] = '\0'; 22175c51f124SMoriah Waterland } 22185c51f124SMoriah Waterland (void) fclose(fp); 22195c51f124SMoriah Waterland 22205c51f124SMoriah Waterland return (retcode); 22215c51f124SMoriah Waterland } 22225c51f124SMoriah Waterland 22235c51f124SMoriah Waterland /* 22245c51f124SMoriah Waterland * This scans the installed pkginfo file for the current BASEDIR. If this 22255c51f124SMoriah Waterland * BASEDIR is different from the current BASEDIR, there will definitely be 22265c51f124SMoriah Waterland * problems. 22275c51f124SMoriah Waterland */ 22285c51f124SMoriah Waterland static int 22295c51f124SMoriah Waterland ck_instbase(void) 22305c51f124SMoriah Waterland { 22315c51f124SMoriah Waterland int retcode = 0; 22325c51f124SMoriah Waterland char param[MAX_PKG_PARAM_LENGTH], *value; 22335c51f124SMoriah Waterland char pkginfo_path[PATH_MAX]; 22345c51f124SMoriah Waterland FILE *fp; 22355c51f124SMoriah Waterland 22365c51f124SMoriah Waterland /* Open the old pkginfo file. */ 22375c51f124SMoriah Waterland (void) snprintf(pkginfo_path, sizeof (pkginfo_path), 22385c51f124SMoriah Waterland "%s/%s", pkgloc, PKGINFO); 22395c51f124SMoriah Waterland if ((fp = fopen(pkginfo_path, "r")) == NULL) { 22405c51f124SMoriah Waterland progerr(ERR_PKGINFO, pkginfo_path); 22415c51f124SMoriah Waterland return (99); 22425c51f124SMoriah Waterland } 22435c51f124SMoriah Waterland 22445c51f124SMoriah Waterland param[0] = '\000'; 22455c51f124SMoriah Waterland 22465c51f124SMoriah Waterland while (value = fpkgparam(fp, param)) { 22475c51f124SMoriah Waterland if (strcmp("BASEDIR", param) == 0) { 22485c51f124SMoriah Waterland if (adm.basedir && *(adm.basedir) && 22495c51f124SMoriah Waterland strchr("/$", *(adm.basedir))) { 22505c51f124SMoriah Waterland char *dotptr; 22515c51f124SMoriah Waterland 22525c51f124SMoriah Waterland /* 22535c51f124SMoriah Waterland * Get srcinst down to a name. 22545c51f124SMoriah Waterland */ 22555c51f124SMoriah Waterland if (dotptr = strchr(srcinst, '.')) 22565c51f124SMoriah Waterland *dotptr = '\000'; 22575c51f124SMoriah Waterland if (strcmp(value, 22585c51f124SMoriah Waterland adm.basedir) != 0) { 22595c51f124SMoriah Waterland progerr(ERR_ADMBD, srcinst, 22605c51f124SMoriah Waterland value, adm.basedir); 22615c51f124SMoriah Waterland retcode = 4; 22625c51f124SMoriah Waterland break; 22635c51f124SMoriah Waterland } 22645c51f124SMoriah Waterland } else if (ADM(basedir, "ask")) 22655c51f124SMoriah Waterland /* 22665c51f124SMoriah Waterland * If it's going to ask later, let it know 22675c51f124SMoriah Waterland * that it *must* agree with the BASEDIR we 22685c51f124SMoriah Waterland * just picked up. 22695c51f124SMoriah Waterland */ 22705c51f124SMoriah Waterland adm.basedir = "update"; 22715c51f124SMoriah Waterland 22725c51f124SMoriah Waterland putparam(param, value); 22735c51f124SMoriah Waterland break; 22745c51f124SMoriah Waterland } 22755c51f124SMoriah Waterland 22765c51f124SMoriah Waterland param[0] = '\0'; 22775c51f124SMoriah Waterland } 22785c51f124SMoriah Waterland (void) fclose(fp); 22795c51f124SMoriah Waterland 22805c51f124SMoriah Waterland return (retcode); 22815c51f124SMoriah Waterland } 22825c51f124SMoriah Waterland 22835c51f124SMoriah Waterland /* 22845c51f124SMoriah Waterland * Since this is an overwrite of a different version of the package, none of 22855c51f124SMoriah Waterland * the old files should remain, so we rename them. 22865c51f124SMoriah Waterland */ 22875c51f124SMoriah Waterland static int 22885c51f124SMoriah Waterland mv_pkgdirs(void) 22895c51f124SMoriah Waterland { 22905c51f124SMoriah Waterland /* 22915c51f124SMoriah Waterland * If we're not in dryrun mode and we can find an old set of package 22925c51f124SMoriah Waterland * files over which the new ones will be written, do the rename. 22935c51f124SMoriah Waterland */ 22945c51f124SMoriah Waterland if (!in_dryrun_mode() && pkgloc[0] && !access(pkgloc, F_OK)) { 22955c51f124SMoriah Waterland (void) snprintf(pkgloc_sav, sizeof (pkgloc_sav), 22965c51f124SMoriah Waterland "%s/.save.%s", get_PKGLOC(), 22975c51f124SMoriah Waterland pkginst); 22985c51f124SMoriah Waterland if (pkgloc_sav[0] && !access(pkgloc_sav, F_OK)) { 22995c51f124SMoriah Waterland (void) rrmdir(pkgloc_sav); 23005c51f124SMoriah Waterland } 23015c51f124SMoriah Waterland 23025c51f124SMoriah Waterland if (rename(pkgloc, pkgloc_sav) == -1) { 23035c51f124SMoriah Waterland progerr(ERR_PKGBINREN, pkgloc, pkgloc_sav); 23045c51f124SMoriah Waterland return (99); 23055c51f124SMoriah Waterland } 23065c51f124SMoriah Waterland } 23075c51f124SMoriah Waterland 23085c51f124SMoriah Waterland return (0); 23095c51f124SMoriah Waterland } 23105c51f124SMoriah Waterland 23115c51f124SMoriah Waterland /* 23125c51f124SMoriah Waterland * Name: merg_pkginfos 23135c51f124SMoriah Waterland * Description: This function scans the installed pkginfo and merges that 23145c51f124SMoriah Waterland * environment with the installing environment according to 23155c51f124SMoriah Waterland * the following rules: 23165c51f124SMoriah Waterland * 23175c51f124SMoriah Waterland * 1. CLASSES is a union of the installed and installing CLASSES 23185c51f124SMoriah Waterland * lists. 23195c51f124SMoriah Waterland * 2. The installed BASEDIR takes precedence. If it doesn't agree 23205c51f124SMoriah Waterland * with an administratively imposed BASEDIR, an ERROR is issued. 23215c51f124SMoriah Waterland * 3. All other installing parameters are preserved. 23225c51f124SMoriah Waterland * 4. All installed parameters are added if they do not overwrite 23235c51f124SMoriah Waterland * an existing installing parameter. 23245c51f124SMoriah Waterland * 23255c51f124SMoriah Waterland * The current environment contains the pkginfo settings for the 23265c51f124SMoriah Waterland * new package to be installed or to be updated. 23275c51f124SMoriah Waterland * 23285c51f124SMoriah Waterland * Arguments: pclass - returned list of current classes involved in install 23295c51f124SMoriah Waterland * mpclass - pointer to returned list of current install classes 23305c51f124SMoriah Waterland * Returns: int 23315c51f124SMoriah Waterland * == 0 - all OK 23325c51f124SMoriah Waterland * != 0 - an error code if a fatal error occurred 23335c51f124SMoriah Waterland */ 23345c51f124SMoriah Waterland 23355c51f124SMoriah Waterland static int 23365c51f124SMoriah Waterland merg_pkginfos(struct cl_attr **pclass, struct cl_attr ***mpclass) 23375c51f124SMoriah Waterland { 23385c51f124SMoriah Waterland FILE *fp; 23395c51f124SMoriah Waterland char SUNW_PKG_ALLZONES[MAX_PKG_PARAM_LENGTH] = {'\0'}; 23405c51f124SMoriah Waterland char SUNW_PKG_HOLLOW[MAX_PKG_PARAM_LENGTH] = {'\0'}; 23415c51f124SMoriah Waterland char SUNW_PKG_THISZONE[MAX_PKG_PARAM_LENGTH] = {'\0'}; 23425c51f124SMoriah Waterland char *newValue; 23435c51f124SMoriah Waterland char *oldValue; 23445c51f124SMoriah Waterland char *pkgName; 23455c51f124SMoriah Waterland char *pkgVersion; 23465c51f124SMoriah Waterland char param[MAX_PKG_PARAM_LENGTH]; 23475c51f124SMoriah Waterland char pkginfo_path[PATH_MAX]; 23485c51f124SMoriah Waterland int retcode = 0; 23495c51f124SMoriah Waterland 23505c51f124SMoriah Waterland /* obtain the name of the package (for error messages) */ 23515c51f124SMoriah Waterland 23525c51f124SMoriah Waterland pkgName = getenv("PKG"); 23535c51f124SMoriah Waterland if (pkgName == NULL) { 23545c51f124SMoriah Waterland pkgName = "*current*"; /* default name */ 23555c51f124SMoriah Waterland } 23565c51f124SMoriah Waterland 23575c51f124SMoriah Waterland /* obtain the version of the package (for error messages) */ 23585c51f124SMoriah Waterland 23595c51f124SMoriah Waterland pkgVersion = getenv("VERSION"); 23605c51f124SMoriah Waterland if (pkgVersion == NULL) { 23615c51f124SMoriah Waterland pkgVersion = "*current*"; /* default version */ 23625c51f124SMoriah Waterland } 23635c51f124SMoriah Waterland 23645c51f124SMoriah Waterland /* open installed package pkginfo file */ 23655c51f124SMoriah Waterland 23665c51f124SMoriah Waterland (void) snprintf(pkginfo_path, sizeof (pkginfo_path), 23675c51f124SMoriah Waterland "%s/%s", pkgloc, PKGINFO); 23685c51f124SMoriah Waterland if ((fp = fopen(pkginfo_path, "r")) == NULL) { 23695c51f124SMoriah Waterland progerr(ERR_PKGINFO, pkginfo_path); 23705c51f124SMoriah Waterland return (99); 23715c51f124SMoriah Waterland } 23725c51f124SMoriah Waterland 23735c51f124SMoriah Waterland /* entry debugging info */ 23745c51f124SMoriah Waterland 23755c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_ENTRY, pkginfo_path); 23765c51f124SMoriah Waterland 23775c51f124SMoriah Waterland /* 23785c51f124SMoriah Waterland * cycle through the currently installed package's pkginfo parameters 23795c51f124SMoriah Waterland * and let the currently installed package's settings survive if the 23805c51f124SMoriah Waterland * update to the package does not provide an overriding value 23815c51f124SMoriah Waterland */ 23825c51f124SMoriah Waterland 23835c51f124SMoriah Waterland for (param[0] = '\0'; (oldValue = fpkgparam(fp, param)) != NULL; 23845c51f124SMoriah Waterland param[0] = '\0') { 23855c51f124SMoriah Waterland 23865c51f124SMoriah Waterland boolean_t setZoneAttribute = B_FALSE; 23875c51f124SMoriah Waterland 23885c51f124SMoriah Waterland /* debug info - attribute currently set to value */ 23895c51f124SMoriah Waterland 23905c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_SET_TO, param, oldValue); 23915c51f124SMoriah Waterland 23925c51f124SMoriah Waterland /* 23935c51f124SMoriah Waterland * if zone package attribute is present in the currently 23945c51f124SMoriah Waterland * installed package, then remember the value for the 23955c51f124SMoriah Waterland * specific zone package attribute, and set the flag that 23965c51f124SMoriah Waterland * indicates a zone package attribute is being processed. 23975c51f124SMoriah Waterland */ 23985c51f124SMoriah Waterland 23995c51f124SMoriah Waterland if (strcmp(param, PKG_THISZONE_VARIABLE) == 0) { 24005c51f124SMoriah Waterland /* SUNW_PKG_THISZONE currently set */ 24015c51f124SMoriah Waterland setZoneAttribute = B_TRUE; 24025c51f124SMoriah Waterland (void) strlcpy(SUNW_PKG_THISZONE, oldValue, 24035c51f124SMoriah Waterland sizeof (SUNW_PKG_THISZONE)); 24045c51f124SMoriah Waterland } else if (strcmp(param, PKG_ALLZONES_VARIABLE) == 0) { 24055c51f124SMoriah Waterland /* SUNW_PKG_ALLZONES currently set */ 24065c51f124SMoriah Waterland setZoneAttribute = B_TRUE; 24075c51f124SMoriah Waterland (void) strlcpy(SUNW_PKG_ALLZONES, oldValue, 24085c51f124SMoriah Waterland sizeof (SUNW_PKG_ALLZONES)); 24095c51f124SMoriah Waterland } else if (strcmp(param, PKG_HOLLOW_VARIABLE) == 0) { 24105c51f124SMoriah Waterland /* SUNW_PKG_THISZONE currently set */ 24115c51f124SMoriah Waterland setZoneAttribute = B_TRUE; 24125c51f124SMoriah Waterland (void) strlcpy(SUNW_PKG_HOLLOW, oldValue, 24135c51f124SMoriah Waterland sizeof (SUNW_PKG_HOLLOW)); 24145c51f124SMoriah Waterland } 24155c51f124SMoriah Waterland 24165c51f124SMoriah Waterland /* handle CLASSES currently being set */ 24175c51f124SMoriah Waterland 24185c51f124SMoriah Waterland if (strcmp(param, "CLASSES") == 0) { 24195c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_SET_CLASSES, oldValue); 24205c51f124SMoriah Waterland /* create a list of the current classes */ 24215c51f124SMoriah Waterland (void) setlist(&pclass, qstrdup(oldValue)); 24225c51f124SMoriah Waterland /* set pointer to list of current classes */ 24235c51f124SMoriah Waterland *mpclass = pclass; 24245c51f124SMoriah Waterland continue; 24255c51f124SMoriah Waterland } 24265c51f124SMoriah Waterland 24275c51f124SMoriah Waterland /* handle BASEDIR currently being set */ 24285c51f124SMoriah Waterland 24295c51f124SMoriah Waterland if (strcmp("BASEDIR", param) == 0) { 24305c51f124SMoriah Waterland if (adm.basedir && *(adm.basedir) && 24315c51f124SMoriah Waterland strchr("/$", *(adm.basedir))) { 24325c51f124SMoriah Waterland char *dotptr; 24335c51f124SMoriah Waterland 24345c51f124SMoriah Waterland /* Get srcinst down to a* name */ 24355c51f124SMoriah Waterland 24365c51f124SMoriah Waterland if (dotptr = strchr(srcinst, '.')) { 24375c51f124SMoriah Waterland *dotptr = '\000'; 24385c51f124SMoriah Waterland } 24395c51f124SMoriah Waterland if (strcmp(oldValue, adm.basedir) != 0) { 24405c51f124SMoriah Waterland progerr(ERR_ADMBD, srcinst, 24415c51f124SMoriah Waterland oldValue, adm.basedir); 24425c51f124SMoriah Waterland /* administration */ 24435c51f124SMoriah Waterland retcode = 4; 24445c51f124SMoriah Waterland break; 24455c51f124SMoriah Waterland } 24465c51f124SMoriah Waterland } else if (ADM(basedir, "ask")) { 24475c51f124SMoriah Waterland /* 24485c51f124SMoriah Waterland * If it's going to ask 24495c51f124SMoriah Waterland * later, let it know that it 24505c51f124SMoriah Waterland * *must* agree with the 24515c51f124SMoriah Waterland * BASEDIR we just picked up. 24525c51f124SMoriah Waterland */ 24535c51f124SMoriah Waterland adm.basedir = "update"; 24545c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_ASK_BASEDIR); 24555c51f124SMoriah Waterland } 24565c51f124SMoriah Waterland 24575c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_SET_BASEDIR, oldValue); 24585c51f124SMoriah Waterland putparam(param, oldValue); 24595c51f124SMoriah Waterland continue; 24605c51f124SMoriah Waterland } 24615c51f124SMoriah Waterland 24625c51f124SMoriah Waterland /* 24635c51f124SMoriah Waterland * determine if there is a new value for this attribute. 24645c51f124SMoriah Waterland */ 24655c51f124SMoriah Waterland 24665c51f124SMoriah Waterland newValue = getenv(param); 24675c51f124SMoriah Waterland 24685c51f124SMoriah Waterland /* 2469*4656d474SGarrett D'Amore * If there is no new value, and a zone attribute 24705c51f124SMoriah Waterland * is being changed, it is the same as setting the zone package 24715c51f124SMoriah Waterland * attribute to 'false' - make sure current setting is 'false'. 24725c51f124SMoriah Waterland */ 24735c51f124SMoriah Waterland 2474*4656d474SGarrett D'Amore if ((newValue == NULL) && 24755c51f124SMoriah Waterland (setZoneAttribute == B_TRUE) && 24765c51f124SMoriah Waterland (strcasecmp(oldValue, "false") != 0)) { 24775c51f124SMoriah Waterland 24785c51f124SMoriah Waterland /* unset existing non-"false" zone pkg attr */ 24795c51f124SMoriah Waterland progerr(ERR_MERGINFOS_UNSET_ZONEATTR, 24805c51f124SMoriah Waterland pkgName, pkgVersion, param, oldValue); 24815c51f124SMoriah Waterland retcode = 1; 24825c51f124SMoriah Waterland break; 24835c51f124SMoriah Waterland } 24845c51f124SMoriah Waterland 24855c51f124SMoriah Waterland /* retain old value if no new value specified */ 24865c51f124SMoriah Waterland 24875c51f124SMoriah Waterland if (newValue == NULL) { 24885c51f124SMoriah Waterland /* no new value - retain the old value */ 24895c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_RETAIN_OLD, param, oldValue); 24905c51f124SMoriah Waterland putparam(param, oldValue); 24915c51f124SMoriah Waterland continue; 24925c51f124SMoriah Waterland } 24935c51f124SMoriah Waterland 24945c51f124SMoriah Waterland /* note if the old and new values are the same */ 24955c51f124SMoriah Waterland 24965c51f124SMoriah Waterland if (strcmp(newValue, oldValue) == 0) { 24975c51f124SMoriah Waterland /* set existing package parameter to same value */ 24985c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_SET_DUPLICATE, param, oldValue); 24995c51f124SMoriah Waterland continue; 25005c51f124SMoriah Waterland } 25015c51f124SMoriah Waterland 25025c51f124SMoriah Waterland /* 2503*4656d474SGarrett D'Amore * Check if old and new values differ. 25045c51f124SMoriah Waterland * Error if zone parameter 25055c51f124SMoriah Waterland */ 25065c51f124SMoriah Waterland 2507*4656d474SGarrett D'Amore if (setZoneAttribute == B_TRUE) { 25085c51f124SMoriah Waterland /* illegal change to zone attribute */ 25095c51f124SMoriah Waterland 25105c51f124SMoriah Waterland progerr(ERR_MERGINFOS_CHANGE_ZONEATTR, pkgName, 25115c51f124SMoriah Waterland pkgVersion, param, oldValue, newValue); 25125c51f124SMoriah Waterland 25135c51f124SMoriah Waterland /* set return code to "fatal error" */ 25145c51f124SMoriah Waterland retcode = 1; 25155c51f124SMoriah Waterland break; 25165c51f124SMoriah Waterland } 25175c51f124SMoriah Waterland 25185c51f124SMoriah Waterland /* note valid change to existing package parameter */ 25195c51f124SMoriah Waterland 25205c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_SET_CHANGE, param, 25215c51f124SMoriah Waterland oldValue, newValue); 25225c51f124SMoriah Waterland } 25235c51f124SMoriah Waterland 25245c51f124SMoriah Waterland /* close handle on currently installed package's pkginfo file */ 25255c51f124SMoriah Waterland 25265c51f124SMoriah Waterland (void) fclose(fp); 25275c51f124SMoriah Waterland 25285c51f124SMoriah Waterland /* return error if not successful up to this point */ 25295c51f124SMoriah Waterland 25305c51f124SMoriah Waterland if (retcode != 0) { 25315c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_EXIT, pkginfo_path, retcode); 25325c51f124SMoriah Waterland 25335c51f124SMoriah Waterland return (retcode); 25345c51f124SMoriah Waterland } 25355c51f124SMoriah Waterland 25365c51f124SMoriah Waterland /* 25375c51f124SMoriah Waterland * verify that no zone attribute has been 25385c51f124SMoriah Waterland * set to an invalid value 25395c51f124SMoriah Waterland */ 25405c51f124SMoriah Waterland 25415c51f124SMoriah Waterland /* SUNW_PKG_ALLZONES */ 25425c51f124SMoriah Waterland 25435c51f124SMoriah Waterland newValue = getenv(PKG_ALLZONES_VARIABLE); 25445c51f124SMoriah Waterland 25455c51f124SMoriah Waterland /* 25465c51f124SMoriah Waterland * complain if setting SUNW_PKG_ALLZONES to other than "false" 25475c51f124SMoriah Waterland */ 25485c51f124SMoriah Waterland 25495c51f124SMoriah Waterland 25505c51f124SMoriah Waterland if ((newValue != NULL) && (*SUNW_PKG_ALLZONES == '\0') && 25515c51f124SMoriah Waterland (strcasecmp(newValue, "false") != 0)) { 25525c51f124SMoriah Waterland /* change ALLZONES from "true" to "false" (unset) */ 25535c51f124SMoriah Waterland progerr(ERR_MERGINFOS_SET_ZONEATTR, pkgName, 25545c51f124SMoriah Waterland pkgVersion, PKG_ALLZONES_VARIABLE, newValue); 25555c51f124SMoriah Waterland return (1); 25565c51f124SMoriah Waterland } 25575c51f124SMoriah Waterland 25585c51f124SMoriah Waterland /* SUNW_PKG_THISZONE */ 25595c51f124SMoriah Waterland 25605c51f124SMoriah Waterland newValue = getenv(PKG_THISZONE_VARIABLE); 25615c51f124SMoriah Waterland 25625c51f124SMoriah Waterland /* 25635c51f124SMoriah Waterland * complain if setting SUNW_PKG_THISZONE to other than "false" 25645c51f124SMoriah Waterland */ 25655c51f124SMoriah Waterland 25665c51f124SMoriah Waterland if ((newValue != NULL) && (*SUNW_PKG_THISZONE == '\0') && 25675c51f124SMoriah Waterland (strcasecmp(newValue, "false") != 0)) { 25685c51f124SMoriah Waterland /* change THISZONE from "true" to "false" (unset) */ 25695c51f124SMoriah Waterland progerr(ERR_MERGINFOS_SET_ZONEATTR, pkgName, 25705c51f124SMoriah Waterland pkgVersion, PKG_THISZONE_VARIABLE, newValue); 25715c51f124SMoriah Waterland return (1); 25725c51f124SMoriah Waterland } 25735c51f124SMoriah Waterland 25745c51f124SMoriah Waterland /* SUNW_PKG_HOLLOW */ 25755c51f124SMoriah Waterland 25765c51f124SMoriah Waterland newValue = getenv(PKG_HOLLOW_VARIABLE); 25775c51f124SMoriah Waterland 25785c51f124SMoriah Waterland /* complain if setting SUNW_PKG_HOLLOW to other than "false" */ 25795c51f124SMoriah Waterland 25805c51f124SMoriah Waterland if ((newValue != NULL) && (*SUNW_PKG_HOLLOW == '\0') && 25815c51f124SMoriah Waterland (strcasecmp(newValue, "false") != 0)) { 25825c51f124SMoriah Waterland /* change HOLLOW from "true" to 'false" (unset) */ 25835c51f124SMoriah Waterland progerr(ERR_MERGINFOS_SET_ZONEATTR, pkgName, 25845c51f124SMoriah Waterland pkgVersion, PKG_HOLLOW_VARIABLE, newValue); 25855c51f124SMoriah Waterland return (1); 25865c51f124SMoriah Waterland } 25875c51f124SMoriah Waterland 25885c51f124SMoriah Waterland echoDebug(DBG_MERGINFOS_EXIT, pkginfo_path, 0); 25895c51f124SMoriah Waterland 25905c51f124SMoriah Waterland return (0); 25915c51f124SMoriah Waterland } 25925c51f124SMoriah Waterland 25935c51f124SMoriah Waterland static void 25945c51f124SMoriah Waterland set_dryrun_dir_loc(void) 25955c51f124SMoriah Waterland { 25965c51f124SMoriah Waterland /* Set pkg location to the dryrun directory */ 25975c51f124SMoriah Waterland set_PKGLOC(pkgdrtarg); 25985c51f124SMoriah Waterland (void) snprintf(pkgloc, sizeof (pkgloc), 25995c51f124SMoriah Waterland "%s/%s", get_PKGLOC(), pkginst); 26005c51f124SMoriah Waterland (void) snprintf(pkgbin, sizeof (pkgbin), 26015c51f124SMoriah Waterland "%s/install", pkgloc); 26025c51f124SMoriah Waterland (void) snprintf(pkgsav, sizeof (pkgsav), 26035c51f124SMoriah Waterland "%s/save", pkgloc); 26045c51f124SMoriah Waterland (void) snprintf(ilockfile, sizeof (ilockfile), 26055c51f124SMoriah Waterland "%s/!I-Lock!", pkgloc); 26065c51f124SMoriah Waterland (void) snprintf(rlockfile, sizeof (rlockfile), 26075c51f124SMoriah Waterland "%s/!R-Lock!", pkgloc); 26085c51f124SMoriah Waterland (void) snprintf(savlog, sizeof (savlog), 26095c51f124SMoriah Waterland "%s/logs/%s", get_PKGADM(), pkginst); 26105c51f124SMoriah Waterland } 26115c51f124SMoriah Waterland 26125c51f124SMoriah Waterland /* 26135c51f124SMoriah Waterland * If we are updating a pkg, then we need to copy the "old" pkgloc so that 26145c51f124SMoriah Waterland * any scripts that got removed in the new version aren't left around. So we 26155c51f124SMoriah Waterland * copy it here to .save.pkgloc, then in quit() we can restore our state, or 26165c51f124SMoriah Waterland * remove it. 26175c51f124SMoriah Waterland */ 26185c51f124SMoriah Waterland static int 26195c51f124SMoriah Waterland cp_pkgdirs(void) 26205c51f124SMoriah Waterland { 26215c51f124SMoriah Waterland if (in_dryrun_mode()) { 26225c51f124SMoriah Waterland set_dryrun_dir_loc(); 26235c51f124SMoriah Waterland } 26245c51f124SMoriah Waterland 26255c51f124SMoriah Waterland /* 26265c51f124SMoriah Waterland * If we're not in dryrun mode and we can find an old set of package 26275c51f124SMoriah Waterland * files over which the new ones will be written, do the copy. 26285c51f124SMoriah Waterland */ 26295c51f124SMoriah Waterland if (!in_dryrun_mode() && pkgloc[0] && !access(pkgloc, F_OK)) { 26305c51f124SMoriah Waterland int status; 26315c51f124SMoriah Waterland int r; 26325c51f124SMoriah Waterland 26335c51f124SMoriah Waterland (void) snprintf(pkgloc_sav, sizeof (pkgloc_sav), "%s/.save.%s", 26345c51f124SMoriah Waterland get_PKGLOC(), pkginst); 26355c51f124SMoriah Waterland 26365c51f124SMoriah Waterland /* 26375c51f124SMoriah Waterland * Even though it takes a while, we use a recursive copy here 26385c51f124SMoriah Waterland * because if the current pkgadd fails for any reason, we 26395c51f124SMoriah Waterland * don't want to lose this data. 26405c51f124SMoriah Waterland */ 26415c51f124SMoriah Waterland r = e_ExecCmdList(&status, (char **)NULL, (char *)NULL, 26425c51f124SMoriah Waterland "/usr/bin/cp", "cp", "-r", pkgloc, pkgloc_sav, 26435c51f124SMoriah Waterland (char *)NULL); 26445c51f124SMoriah Waterland 26455c51f124SMoriah Waterland if ((r != 0) || (status == -1) || (WEXITSTATUS(status) != 0)) { 26465c51f124SMoriah Waterland progerr(ERR_PKGBINCP, pkgloc, pkgloc_sav); 26475c51f124SMoriah Waterland return (99); 26485c51f124SMoriah Waterland } 26495c51f124SMoriah Waterland } 26505c51f124SMoriah Waterland 26515c51f124SMoriah Waterland return (0); 26525c51f124SMoriah Waterland } 26535c51f124SMoriah Waterland 26545c51f124SMoriah Waterland /* 26555c51f124SMoriah Waterland * This implements the pkgask function. It just executes the request script 26565c51f124SMoriah Waterland * and stores the results in a response file. 26575c51f124SMoriah Waterland */ 26585c51f124SMoriah Waterland static void 26595c51f124SMoriah Waterland do_pkgask(boolean_t a_run_request_as_root) 26605c51f124SMoriah Waterland { 26615c51f124SMoriah Waterland if (pkgdev.cdevice) { 26625c51f124SMoriah Waterland unpack(); 26635c51f124SMoriah Waterland if (!suppressCopyright) { 26645c51f124SMoriah Waterland copyright(); 26655c51f124SMoriah Waterland } 26665c51f124SMoriah Waterland } 26675c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), "%s/%s", instdir, REQUEST_FILE); 26685c51f124SMoriah Waterland if (access(path, F_OK)) { 26695c51f124SMoriah Waterland progerr(ERR_NOREQUEST); 26705c51f124SMoriah Waterland quit(1); 26715c51f124SMoriah Waterland /*NOTREACHED*/ 26725c51f124SMoriah Waterland } 26735c51f124SMoriah Waterland 26745c51f124SMoriah Waterland (void) set_respfile(respfile, srcinst, RESP_WR); 26755c51f124SMoriah Waterland 26765c51f124SMoriah Waterland if (is_a_respfile()) { 26775c51f124SMoriah Waterland ckreturn(reqexec(update, path, non_abi_scripts, 26785c51f124SMoriah Waterland a_run_request_as_root), ERR_REQUEST); 26795c51f124SMoriah Waterland } else { 26805c51f124SMoriah Waterland failflag++; 26815c51f124SMoriah Waterland } 26825c51f124SMoriah Waterland 26835c51f124SMoriah Waterland if (warnflag || failflag) { 26845c51f124SMoriah Waterland (void) remove(respfile); 26855c51f124SMoriah Waterland echo("\nResponse file <%s> was not created.", 26865c51f124SMoriah Waterland get_respfile()); 26875c51f124SMoriah Waterland } else { 26885c51f124SMoriah Waterland echo("\nResponse file <%s> was created.", 26895c51f124SMoriah Waterland get_respfile()); 26905c51f124SMoriah Waterland } 26915c51f124SMoriah Waterland 26925c51f124SMoriah Waterland quit(0); 26935c51f124SMoriah Waterland /*NOTREACHED*/ 26945c51f124SMoriah Waterland } 26955c51f124SMoriah Waterland 26965c51f124SMoriah Waterland /* 26975c51f124SMoriah Waterland * This function runs a check utility and acts appropriately based upon the 26985c51f124SMoriah Waterland * return code. It deals appropriately with the dryrun file if it is present. 26995c51f124SMoriah Waterland */ 27005c51f124SMoriah Waterland static void 27015c51f124SMoriah Waterland ck_w_dryrun(int (*func)(), int type) 27025c51f124SMoriah Waterland { 27035c51f124SMoriah Waterland int n; 27045c51f124SMoriah Waterland 27055c51f124SMoriah Waterland n = func(); 27065c51f124SMoriah Waterland if (in_dryrun_mode()) 27075c51f124SMoriah Waterland set_dr_info(type, !n); 27085c51f124SMoriah Waterland 27095c51f124SMoriah Waterland if (n) { 27105c51f124SMoriah Waterland quit(n); 27115c51f124SMoriah Waterland /*NOTREACHED*/ 27125c51f124SMoriah Waterland } 27135c51f124SMoriah Waterland } 27145c51f124SMoriah Waterland 27155c51f124SMoriah Waterland /* 27165c51f124SMoriah Waterland * This function deletes all install class action scripts from the package 27175c51f124SMoriah Waterland * directory on the root filesystem. 27185c51f124SMoriah Waterland */ 27195c51f124SMoriah Waterland static void 27205c51f124SMoriah Waterland rm_icas(char *cas_dir) 27215c51f124SMoriah Waterland { 27225c51f124SMoriah Waterland DIR *pdirfp; 27235c51f124SMoriah Waterland struct dirent *dp; 27245c51f124SMoriah Waterland char path[PATH_MAX]; 27255c51f124SMoriah Waterland 27265c51f124SMoriah Waterland if ((pdirfp = opendir(cas_dir)) == NULL) 27275c51f124SMoriah Waterland return; 27285c51f124SMoriah Waterland 27295c51f124SMoriah Waterland while ((dp = readdir(pdirfp)) != NULL) { 27305c51f124SMoriah Waterland if (dp->d_name[0] == '.') 27315c51f124SMoriah Waterland continue; 27325c51f124SMoriah Waterland 27335c51f124SMoriah Waterland if (dp->d_name[0] == 'i' && dp->d_name[1] == '.') { 27345c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), 27355c51f124SMoriah Waterland "%s/%s", cas_dir, dp->d_name); 27365c51f124SMoriah Waterland (void) remove(path); 27375c51f124SMoriah Waterland } 27385c51f124SMoriah Waterland } 27395c51f124SMoriah Waterland (void) closedir(pdirfp); 27405c51f124SMoriah Waterland } 27415c51f124SMoriah Waterland 27425c51f124SMoriah Waterland void 27435c51f124SMoriah Waterland ckreturn(int retcode, char *msg) 27445c51f124SMoriah Waterland { 27455c51f124SMoriah Waterland switch (retcode) { 27465c51f124SMoriah Waterland case 2: 27475c51f124SMoriah Waterland case 12: 27485c51f124SMoriah Waterland case 22: 27495c51f124SMoriah Waterland warnflag++; 27505c51f124SMoriah Waterland if (msg) { 27515c51f124SMoriah Waterland progerr("%s", msg); 27525c51f124SMoriah Waterland } 27535c51f124SMoriah Waterland /*FALLTHRU*/ 27545c51f124SMoriah Waterland case 10: 27555c51f124SMoriah Waterland case 20: 27565c51f124SMoriah Waterland if (retcode >= 10 && retcode < 20) { 27575c51f124SMoriah Waterland dreboot++; 27585c51f124SMoriah Waterland } 27595c51f124SMoriah Waterland if (retcode >= 20) { 27605c51f124SMoriah Waterland ireboot++; 27615c51f124SMoriah Waterland } 27625c51f124SMoriah Waterland /*FALLTHRU*/ 27635c51f124SMoriah Waterland case 0: 27645c51f124SMoriah Waterland break; /* okay */ 27655c51f124SMoriah Waterland 27665c51f124SMoriah Waterland case -1: 27675c51f124SMoriah Waterland retcode = 99; 27685c51f124SMoriah Waterland /*FALLTHRU*/ 27695c51f124SMoriah Waterland case 99: 27705c51f124SMoriah Waterland case 1: 27715c51f124SMoriah Waterland case 11: 27725c51f124SMoriah Waterland case 21: 27735c51f124SMoriah Waterland case 4: 27745c51f124SMoriah Waterland case 14: 27755c51f124SMoriah Waterland case 24: 27765c51f124SMoriah Waterland case 5: 27775c51f124SMoriah Waterland case 15: 27785c51f124SMoriah Waterland case 25: 27795c51f124SMoriah Waterland if (msg) { 27805c51f124SMoriah Waterland progerr("%s", msg); 27815c51f124SMoriah Waterland } 27825c51f124SMoriah Waterland /*FALLTHRU*/ 27835c51f124SMoriah Waterland case 3: 27845c51f124SMoriah Waterland case 13: 27855c51f124SMoriah Waterland case 23: 27865c51f124SMoriah Waterland quit(retcode); 27875c51f124SMoriah Waterland /*NOTREACHED*/ 27885c51f124SMoriah Waterland default: 27895c51f124SMoriah Waterland if (msg) { 27905c51f124SMoriah Waterland progerr("%s", msg); 27915c51f124SMoriah Waterland } 27925c51f124SMoriah Waterland quit(1); 27935c51f124SMoriah Waterland /*NOTREACHED*/ 27945c51f124SMoriah Waterland } 27955c51f124SMoriah Waterland } 27965c51f124SMoriah Waterland 27975c51f124SMoriah Waterland static void 27985c51f124SMoriah Waterland copyright(void) 27995c51f124SMoriah Waterland { 28005c51f124SMoriah Waterland FILE *fp; 28015c51f124SMoriah Waterland char line[LSIZE]; 28025c51f124SMoriah Waterland char path[PATH_MAX]; 28035c51f124SMoriah Waterland 28045c51f124SMoriah Waterland /* Compose full path for copyright file */ 28055c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), "%s/%s", instdir, COPYRIGHT_FILE); 28065c51f124SMoriah Waterland 28075c51f124SMoriah Waterland if ((fp = fopen(path, "r")) == NULL) { 28085c51f124SMoriah Waterland if (getenv("VENDOR") != NULL) 28095c51f124SMoriah Waterland echo(getenv("VENDOR")); 28105c51f124SMoriah Waterland } else { 28115c51f124SMoriah Waterland while (fgets(line, LSIZE, fp)) 28125c51f124SMoriah Waterland (void) fprintf(stdout, "%s", line); /* bug #1083713 */ 28135c51f124SMoriah Waterland (void) fclose(fp); 28145c51f124SMoriah Waterland } 28155c51f124SMoriah Waterland } 28165c51f124SMoriah Waterland 28175c51f124SMoriah Waterland static int 28185c51f124SMoriah Waterland rdonly(char *p) 28195c51f124SMoriah Waterland { 28205c51f124SMoriah Waterland int i; 28215c51f124SMoriah Waterland 28225c51f124SMoriah Waterland for (i = 0; ro_params[i]; i++) { 28235c51f124SMoriah Waterland if (strcmp(p, ro_params[i]) == 0) 28245c51f124SMoriah Waterland return (1); 28255c51f124SMoriah Waterland } 28265c51f124SMoriah Waterland return (0); 28275c51f124SMoriah Waterland } 28285c51f124SMoriah Waterland 28295c51f124SMoriah Waterland static void 28305c51f124SMoriah Waterland unpack(void) 28315c51f124SMoriah Waterland { 28325c51f124SMoriah Waterland /* 28335c51f124SMoriah Waterland * read in next part from stream, even if we decide 28345c51f124SMoriah Waterland * later that we don't need it 28355c51f124SMoriah Waterland */ 28365c51f124SMoriah Waterland if (dparts < 1) { 28375c51f124SMoriah Waterland progerr(ERR_DSTREAMCNT); 28385c51f124SMoriah Waterland quit(99); 28395c51f124SMoriah Waterland /*NOTREACHED*/ 28405c51f124SMoriah Waterland } 28415c51f124SMoriah Waterland if ((access(instdir, F_OK) == 0) && rrmdir(instdir)) { 28425c51f124SMoriah Waterland progerr(ERR_RMDIR, instdir); 28435c51f124SMoriah Waterland quit(99); 28445c51f124SMoriah Waterland /*NOTREACHED*/ 28455c51f124SMoriah Waterland } 28465c51f124SMoriah Waterland if (mkdir(instdir, 0755)) { 28475c51f124SMoriah Waterland progerr(ERR_MKDIR, instdir); 28485c51f124SMoriah Waterland quit(99); 28495c51f124SMoriah Waterland /*NOTREACHED*/ 28505c51f124SMoriah Waterland } 28515c51f124SMoriah Waterland if (chdir(instdir)) { 28525c51f124SMoriah Waterland progerr(ERR_CHDIR, instdir); 28535c51f124SMoriah Waterland quit(99); 28545c51f124SMoriah Waterland /*NOTREACHED*/ 28555c51f124SMoriah Waterland } 28565c51f124SMoriah Waterland if (!ds_fd_open()) { 28575c51f124SMoriah Waterland dparts = ds_findpkg(pkgdev.cdevice, srcinst); 28585c51f124SMoriah Waterland if (dparts < 1) { 28595c51f124SMoriah Waterland progerr(ERR_DSARCH, srcinst); 28605c51f124SMoriah Waterland quit(99); 28615c51f124SMoriah Waterland /*NOTREACHED*/ 28625c51f124SMoriah Waterland } 28635c51f124SMoriah Waterland } 28645c51f124SMoriah Waterland 28655c51f124SMoriah Waterland dparts--; 28665c51f124SMoriah Waterland 28675c51f124SMoriah Waterland if (ds_next(pkgdev.cdevice, instdir)) { 28685c51f124SMoriah Waterland progerr(ERR_DSTREAM); 28695c51f124SMoriah Waterland quit(99); 28705c51f124SMoriah Waterland /*NOTREACHED*/ 28715c51f124SMoriah Waterland } 28725c51f124SMoriah Waterland if (chdir(get_PKGADM())) { 28735c51f124SMoriah Waterland progerr(ERR_CHDIR, get_PKGADM()); 28745c51f124SMoriah Waterland quit(99); 28755c51f124SMoriah Waterland /*NOTREACHED*/ 28765c51f124SMoriah Waterland } 28775c51f124SMoriah Waterland ds_close(1); 28785c51f124SMoriah Waterland } 28795c51f124SMoriah Waterland 28805c51f124SMoriah Waterland static void 28815c51f124SMoriah Waterland usage(void) 28825c51f124SMoriah Waterland { 28835c51f124SMoriah Waterland (void) fprintf(stderr, ERR_USAGE_PKGINSTALL); 28845c51f124SMoriah Waterland exit(1); 28855c51f124SMoriah Waterland /*NOTREACHED*/ 28865c51f124SMoriah Waterland } 2887