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