lib.h revision 108778
10Sduke/* $FreeBSD: head/usr.sbin/pkg_install/lib/lib.h 108778 2003-01-06 07:39:02Z jkh $ */ 29330Slana 30Sduke/* 40Sduke * FreeBSD install - a package for the installation and maintainance 50Sduke * of non-core utilities. 60Sduke * 70Sduke * Redistribution and use in source and binary forms, with or without 80Sduke * modification, are permitted provided that the following conditions 90Sduke * are met: 100Sduke * 1. Redistributions of source code must retain the above copyright 110Sduke * notice, this list of conditions and the following disclaimer. 120Sduke * 2. Redistributions in binary form must reproduce the above copyright 130Sduke * notice, this list of conditions and the following disclaimer in the 140Sduke * documentation and/or other materials provided with the distribution. 150Sduke * 160Sduke * Jordan K. Hubbard 170Sduke * 18 July 1993 180Sduke * 192362Sohair * Include and define various things wanted by the library routines. 202362Sohair * 212362Sohair */ 220Sduke 230Sduke#ifndef _INST_LIB_LIB_H_ 240Sduke#define _INST_LIB_LIB_H_ 250Sduke 260Sduke/* Includes */ 270Sduke#include <sys/param.h> 280Sduke#include <sys/file.h> 290Sduke#include <sys/stat.h> 300Sduke#include <sys/queue.h> 310Sduke#include <ctype.h> 320Sduke#include <dirent.h> 330Sduke#include <stdarg.h> 340Sduke#include <stdio.h> 350Sduke#include <stdlib.h> 360Sduke#include <string.h> 370Sduke#include <unistd.h> 380Sduke 390Sduke/* Macros */ 400Sduke#define SUCCESS (0) 410Sduke#define FAIL (-1) 420Sduke 430Sduke#ifndef TRUE 440Sduke#define TRUE (1) 450Sduke#endif 460Sduke 470Sduke#ifndef FALSE 480Sduke#define FALSE (0) 490Sduke#endif 500Sduke 510Sduke#define YES 2 520Sduke#define NO 1 530Sduke 540Sduke/* Usually "rm", but often "echo" during debugging! */ 550Sduke#define REMOVE_CMD "rm" 560Sduke 570Sduke/* Usually "rm", but often "echo" during debugging! */ 580Sduke#define RMDIR_CMD "rmdir" 590Sduke 600Sduke/* Where we put logging information by default, else ${PKG_DBDIR} if set */ 610Sduke#define DEF_LOG_DIR "/var/db/pkg" 620Sduke/* just in case we change the environment variable name */ 630Sduke#define PKG_DBDIR "PKG_DBDIR" 640Sduke/* macro to get name of directory where we put logging information */ 650Sduke#define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR) 660Sduke 670Sduke/* The names of our "special" files */ 680Sduke#define CONTENTS_FNAME "+CONTENTS" 690Sduke#define COMMENT_FNAME "+COMMENT" 700Sduke#define DESC_FNAME "+DESC" 718858Smichaelm#define INSTALL_FNAME "+INSTALL" 720Sduke#define POST_INSTALL_FNAME "+POST-INSTALL" 730Sduke#define DEINSTALL_FNAME "+DEINSTALL" 740Sduke#define POST_DEINSTALL_FNAME "+POST-DEINSTALL" 750Sduke#define REQUIRE_FNAME "+REQUIRE" 768858Smichaelm#define REQUIRED_BY_FNAME "+REQUIRED_BY" 770Sduke#define DISPLAY_FNAME "+DISPLAY" 780Sduke#define MTREE_FNAME "+MTREE_DIRS" 790Sduke 800Sduke#define CMD_CHAR '@' /* prefix for extended PLIST cmd */ 810Sduke 828858Smichaelm/* The name of the "prefix" environment variable given to scripts */ 830Sduke#define PKG_PREFIX_VNAME "PKG_PREFIX" 842612Schegar 858858Smichaelm/* 860Sduke * Version of the package tools - increase only when some 870Sduke * functionality used by bsd.port.mk is changed, added or removed 880Sduke */ 890Sduke#define PKG_INSTALL_VERSION 20020908 900Sduke 910Sduke#define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf" 920Sduke#define main(argc, argv) real_main(argc, argv) 930Sduke 940Sduke/* Version numbers to assist with changes in package file format */ 958858Smichaelm#define PLIST_FMT_VER_MAJOR 1 960Sduke#define PLIST_FMT_VER_MINOR 1 970Sduke 980Sdukeenum _plist_t { 990Sduke PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD, 1000Sduke PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE, 1010Sduke PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY, 1020Sduke PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST, 1030Sduke PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN 1040Sduke}; 1050Sduketypedef enum _plist_t plist_t; 1060Sduke 1070Sdukeenum _match_t { 1080Sduke MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_REGEX 1090Sduke}; 1100Sduketypedef enum _match_t match_t; 1110Sduke 1120Sduke/* Types */ 1130Sduketypedef unsigned int Boolean; 1140Sduke 1150Sdukestruct _plist { 1160Sduke struct _plist *prev, *next; 1170Sduke char *name; 1180Sduke Boolean marked; 1198858Smichaelm plist_t type; 1208858Smichaelm}; 1218858Smichaelmtypedef struct _plist *PackingList; 1220Sduke 1230Sdukestruct _pack { 1240Sduke struct _plist *head, *tail; 1258858Smichaelm char *name; 1262612Schegar char *origin; 1278858Smichaelm int fmtver_maj, fmtver_mnr; 1280Sduke}; 1290Sduketypedef struct _pack Package; 1300Sduke 1310Sdukestruct reqr_by_entry { 1328858Smichaelm STAILQ_ENTRY(reqr_by_entry) link; 1338858Smichaelm char pkgname[PATH_MAX]; 1348858Smichaelm}; 1358858SmichaelmSTAILQ_HEAD(reqr_by_head, reqr_by_entry); 1360Sduke 1372612Schegar/* Prototypes */ 1388858Smichaelm/* Misc */ 1398858Smichaelmint vsystem(const char *, ...); 1408858Smichaelmchar *vpipe(const char *, ...); 1410Sdukevoid cleanup(int); 1420Sdukechar *make_playpen(char *, off_t); 1430Sdukechar *where_playpen(void); 1440Sdukevoid leave_playpen(void); 145off_t min_free(const char *); 146 147/* String */ 148char *get_dash_string(char **); 149char *copy_string(const char *); 150Boolean suffix(const char *, const char *); 151void nuke_suffix(char *); 152void str_lowercase(char *); 153char *strconcat(const char *, const char *); 154char *get_string(char *, int, FILE *); 155 156/* File */ 157Boolean fexists(const char *); 158Boolean isdir(const char *); 159Boolean isemptydir(const char *fname); 160Boolean isemptyfile(const char *fname); 161Boolean isfile(const char *); 162Boolean isempty(const char *); 163Boolean issymlink(const char *); 164Boolean isURL(const char *); 165char *fileGetURL(const char *, const char *); 166char *fileFindByPath(const char *, const char *); 167char *fileGetContents(const char *); 168void write_file(const char *, const char *); 169void copy_file(const char *, const char *, const char *); 170void move_file(const char *, const char *, const char *); 171void copy_hierarchy(const char *, const char *, Boolean); 172int delete_hierarchy(const char *, Boolean, Boolean); 173int unpack(const char *, const char *); 174void format_cmd(char *, int, const char *, const char *, const char *); 175 176/* Msg */ 177void upchuck(const char *); 178void barf(const char *, ...); 179void whinge(const char *, ...); 180Boolean y_or_n(Boolean, const char *, ...); 181 182/* Packing list */ 183PackingList new_plist_entry(void); 184PackingList last_plist(Package *); 185PackingList find_plist(Package *, plist_t); 186char *find_plist_option(Package *, const char *name); 187void plist_delete(Package *, Boolean, plist_t, const char *); 188void free_plist(Package *); 189void mark_plist(Package *); 190void csum_plist_entry(char *, PackingList); 191void add_plist(Package *, plist_t, const char *); 192void add_plist_top(Package *, plist_t, const char *); 193void delete_plist(Package *pkg, Boolean all, plist_t type, const char *name); 194void write_plist(Package *, FILE *); 195void read_plist(Package *, FILE *); 196int plist_cmd(const char *, char **); 197int delete_package(Boolean, Boolean, Package *); 198Boolean make_preserve_name(char *, int, const char *, const char *); 199 200/* For all */ 201int pkg_perform(char **); 202int real_main(int, char **); 203 204/* Query installed packages */ 205char **matchinstalled(match_t, char **, int *); 206char **matchbyorigin(const char *, int *); 207int isinstalledpkg(const char *name); 208 209/* Dependencies */ 210int sortdeps(char **); 211int chkifdepends(const char *, const char *); 212int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean); 213 214/* Version */ 215int verscmp(Package *, int, int); 216const char *version_of(const char *, int *, int *); 217int version_cmp(const char *, const char *); 218 219/* Externs */ 220extern Boolean Verbose; 221extern Boolean Fake; 222extern Boolean Force; 223extern int AutoAnswer; 224 225#endif /* _INST_LIB_LIB_H_ */ 226