1*5c51f124SMoriah Waterland /* 2*5c51f124SMoriah Waterland * CDDL HEADER START 3*5c51f124SMoriah Waterland * 4*5c51f124SMoriah Waterland * The contents of this file are subject to the terms of the 5*5c51f124SMoriah Waterland * Common Development and Distribution License (the "License"). 6*5c51f124SMoriah Waterland * You may not use this file except in compliance with the License. 7*5c51f124SMoriah Waterland * 8*5c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing. 10*5c51f124SMoriah Waterland * See the License for the specific language governing permissions 11*5c51f124SMoriah Waterland * and limitations under the License. 12*5c51f124SMoriah Waterland * 13*5c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each 14*5c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the 16*5c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying 17*5c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner] 18*5c51f124SMoriah Waterland * 19*5c51f124SMoriah Waterland * CDDL HEADER END 20*5c51f124SMoriah Waterland */ 21*5c51f124SMoriah Waterland 22*5c51f124SMoriah Waterland /* 23*5c51f124SMoriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*5c51f124SMoriah Waterland * Use is subject to license terms. 25*5c51f124SMoriah Waterland */ 26*5c51f124SMoriah Waterland 27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*5c51f124SMoriah Waterland /* All Rights Reserved */ 29*5c51f124SMoriah Waterland 30*5c51f124SMoriah Waterland 31*5c51f124SMoriah Waterland #include <stdio.h> 32*5c51f124SMoriah Waterland #include <string.h> 33*5c51f124SMoriah Waterland #include <errno.h> 34*5c51f124SMoriah Waterland #include <limits.h> 35*5c51f124SMoriah Waterland #include <stdlib.h> 36*5c51f124SMoriah Waterland #include <unistd.h> 37*5c51f124SMoriah Waterland #include <sys/types.h> 38*5c51f124SMoriah Waterland #include <pkgstrct.h> 39*5c51f124SMoriah Waterland #include <pkginfo.h> 40*5c51f124SMoriah Waterland #include <locale.h> 41*5c51f124SMoriah Waterland #include <libintl.h> 42*5c51f124SMoriah Waterland 43*5c51f124SMoriah Waterland #include <pkglib.h> 44*5c51f124SMoriah Waterland #include <libadm.h> 45*5c51f124SMoriah Waterland #include <libinst.h> 46*5c51f124SMoriah Waterland 47*5c51f124SMoriah Waterland extern char *pkgfile; 48*5c51f124SMoriah Waterland 49*5c51f124SMoriah Waterland #define ERR_ROOT_SET "Could not set install root from the environment." 50*5c51f124SMoriah Waterland #define ERR_ROOT_CMD "Command line install root contends with environment." 51*5c51f124SMoriah Waterland #define ERR_MESG "unable to locate parameter information for \"%s\"" 52*5c51f124SMoriah Waterland #define ERR_FLT "parsing error in parameter file" 53*5c51f124SMoriah Waterland #define ERR_USAGE "usage:\n" \ 54*5c51f124SMoriah Waterland "\t%s [-v] [-d device] pkginst [param [param ...]]\n" \ 55*5c51f124SMoriah Waterland "\t%s [-v] -f file [param [param ...]]\n" 56*5c51f124SMoriah Waterland #define HASHSIZE 151 57*5c51f124SMoriah Waterland #define BSZ 4 58*5c51f124SMoriah Waterland 59*5c51f124SMoriah Waterland 60*5c51f124SMoriah Waterland static char *device = NULL; 61*5c51f124SMoriah Waterland static int errflg = 0; 62*5c51f124SMoriah Waterland static int vflag = 0; 63*5c51f124SMoriah Waterland 64*5c51f124SMoriah Waterland static void print_entry(char *, char *); 65*5c51f124SMoriah Waterland 66*5c51f124SMoriah Waterland static void 67*5c51f124SMoriah Waterland usage(void) 68*5c51f124SMoriah Waterland { 69*5c51f124SMoriah Waterland char *prog = get_prog_name(); 70*5c51f124SMoriah Waterland 71*5c51f124SMoriah Waterland (void) fprintf(stderr, gettext(ERR_USAGE), prog, prog); 72*5c51f124SMoriah Waterland exit(1); 73*5c51f124SMoriah Waterland } 74*5c51f124SMoriah Waterland 75*5c51f124SMoriah Waterland int 76*5c51f124SMoriah Waterland main(int argc, char *argv[]) 77*5c51f124SMoriah Waterland { 78*5c51f124SMoriah Waterland char *value, *pkginst; 79*5c51f124SMoriah Waterland char *param, parambuf[128]; 80*5c51f124SMoriah Waterland int c; 81*5c51f124SMoriah Waterland 82*5c51f124SMoriah Waterland pkgfile = NULL; 83*5c51f124SMoriah Waterland 84*5c51f124SMoriah Waterland /* initialize locale mechanism */ 85*5c51f124SMoriah Waterland 86*5c51f124SMoriah Waterland (void) setlocale(LC_ALL, ""); 87*5c51f124SMoriah Waterland 88*5c51f124SMoriah Waterland #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 89*5c51f124SMoriah Waterland #define TEXT_DOMAIN "SYS_TEST" 90*5c51f124SMoriah Waterland #endif 91*5c51f124SMoriah Waterland (void) textdomain(TEXT_DOMAIN); 92*5c51f124SMoriah Waterland 93*5c51f124SMoriah Waterland /* determine program name */ 94*5c51f124SMoriah Waterland 95*5c51f124SMoriah Waterland (void) set_prog_name(argv[0]); 96*5c51f124SMoriah Waterland 97*5c51f124SMoriah Waterland /* establish installation root directory */ 98*5c51f124SMoriah Waterland 99*5c51f124SMoriah Waterland if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) { 100*5c51f124SMoriah Waterland progerr(gettext(ERR_ROOT_SET)); 101*5c51f124SMoriah Waterland exit(1); 102*5c51f124SMoriah Waterland } 103*5c51f124SMoriah Waterland 104*5c51f124SMoriah Waterland while ((c = getopt(argc, argv, "R:vd:f:?")) != EOF) { 105*5c51f124SMoriah Waterland switch (c) { 106*5c51f124SMoriah Waterland case 'v': 107*5c51f124SMoriah Waterland vflag++; 108*5c51f124SMoriah Waterland break; 109*5c51f124SMoriah Waterland 110*5c51f124SMoriah Waterland case 'f': 111*5c51f124SMoriah Waterland /* -f could specify filename to get parameters from */ 112*5c51f124SMoriah Waterland pkgfile = optarg; 113*5c51f124SMoriah Waterland break; 114*5c51f124SMoriah Waterland 115*5c51f124SMoriah Waterland case 'd': 116*5c51f124SMoriah Waterland /* -d could specify stream or mountable device */ 117*5c51f124SMoriah Waterland device = flex_device(optarg, 1); 118*5c51f124SMoriah Waterland break; 119*5c51f124SMoriah Waterland 120*5c51f124SMoriah Waterland case 'R': 121*5c51f124SMoriah Waterland if (!set_inst_root(optarg)) { 122*5c51f124SMoriah Waterland progerr(gettext(ERR_ROOT_CMD)); 123*5c51f124SMoriah Waterland exit(1); 124*5c51f124SMoriah Waterland } 125*5c51f124SMoriah Waterland break; 126*5c51f124SMoriah Waterland 127*5c51f124SMoriah Waterland default: 128*5c51f124SMoriah Waterland case '?': 129*5c51f124SMoriah Waterland usage(); 130*5c51f124SMoriah Waterland } 131*5c51f124SMoriah Waterland } 132*5c51f124SMoriah Waterland 133*5c51f124SMoriah Waterland set_PKGpaths(get_inst_root()); 134*5c51f124SMoriah Waterland 135*5c51f124SMoriah Waterland if (pkgfile) { 136*5c51f124SMoriah Waterland if (device) 137*5c51f124SMoriah Waterland usage(); 138*5c51f124SMoriah Waterland pkginst = pkgfile; 139*5c51f124SMoriah Waterland } else { 140*5c51f124SMoriah Waterland if ((optind+1) > argc) 141*5c51f124SMoriah Waterland usage(); 142*5c51f124SMoriah Waterland 143*5c51f124SMoriah Waterland if (pkghead(device)) 144*5c51f124SMoriah Waterland return (1); /* couldn't obtain info about device */ 145*5c51f124SMoriah Waterland pkginst = argv[optind++]; 146*5c51f124SMoriah Waterland } 147*5c51f124SMoriah Waterland 148*5c51f124SMoriah Waterland /* If a filename was specified or install db does not exist */ 149*5c51f124SMoriah Waterland do { 150*5c51f124SMoriah Waterland param = argv[optind]; 151*5c51f124SMoriah Waterland if (!param) { 152*5c51f124SMoriah Waterland param = parambuf; 153*5c51f124SMoriah Waterland *param = '\0'; 154*5c51f124SMoriah Waterland } 155*5c51f124SMoriah Waterland value = pkgparam(pkginst, param); 156*5c51f124SMoriah Waterland if (value == NULL) { 157*5c51f124SMoriah Waterland if (errno == EFAULT) { 158*5c51f124SMoriah Waterland progerr(gettext(ERR_FLT)); 159*5c51f124SMoriah Waterland errflg++; 160*5c51f124SMoriah Waterland break; 161*5c51f124SMoriah Waterland } else if (errno != EINVAL) { 162*5c51f124SMoriah Waterland /* 163*5c51f124SMoriah Waterland * some other error besides no value for this 164*5c51f124SMoriah Waterland * particular parameter 165*5c51f124SMoriah Waterland */ 166*5c51f124SMoriah Waterland progerr(gettext(ERR_MESG), pkginst); 167*5c51f124SMoriah Waterland errflg++; 168*5c51f124SMoriah Waterland break; 169*5c51f124SMoriah Waterland } 170*5c51f124SMoriah Waterland if (!argv[optind]) 171*5c51f124SMoriah Waterland break; 172*5c51f124SMoriah Waterland continue; 173*5c51f124SMoriah Waterland } 174*5c51f124SMoriah Waterland 175*5c51f124SMoriah Waterland print_entry(param, value); 176*5c51f124SMoriah Waterland 177*5c51f124SMoriah Waterland } while (!argv[optind] || (++optind < argc)); 178*5c51f124SMoriah Waterland (void) pkgparam(NULL, NULL); /* close open FDs so umount won't fail */ 179*5c51f124SMoriah Waterland 180*5c51f124SMoriah Waterland (void) pkghead(NULL); 181*5c51f124SMoriah Waterland return (errflg ? 1 : 0); 182*5c51f124SMoriah Waterland } 183*5c51f124SMoriah Waterland 184*5c51f124SMoriah Waterland static void 185*5c51f124SMoriah Waterland print_entry(char *param, char *value) 186*5c51f124SMoriah Waterland { 187*5c51f124SMoriah Waterland if (vflag) { 188*5c51f124SMoriah Waterland (void) printf("%s='", param); 189*5c51f124SMoriah Waterland while (*value) { 190*5c51f124SMoriah Waterland if (*value == '\'') { 191*5c51f124SMoriah Waterland (void) printf("'\"'\"'"); 192*5c51f124SMoriah Waterland value++; 193*5c51f124SMoriah Waterland } else 194*5c51f124SMoriah Waterland (void) putchar(*value++); 195*5c51f124SMoriah Waterland } 196*5c51f124SMoriah Waterland (void) printf("'\n"); 197*5c51f124SMoriah Waterland } else 198*5c51f124SMoriah Waterland (void) printf("%s\n", value); 199*5c51f124SMoriah Waterland } 200*5c51f124SMoriah Waterland 201*5c51f124SMoriah Waterland void 202*5c51f124SMoriah Waterland quit(int retval) 203*5c51f124SMoriah Waterland { 204*5c51f124SMoriah Waterland exit(retval); 205*5c51f124SMoriah Waterland } 206