150479Speter/* $FreeBSD$ */ 2327Sjkh 3327Sjkh/* 4327Sjkh * FreeBSD install - a package for the installation and maintainance 5327Sjkh * of non-core utilities. 6327Sjkh * 7327Sjkh * Redistribution and use in source and binary forms, with or without 8327Sjkh * modification, are permitted provided that the following conditions 9327Sjkh * are met: 10327Sjkh * 1. Redistributions of source code must retain the above copyright 11327Sjkh * notice, this list of conditions and the following disclaimer. 12327Sjkh * 2. Redistributions in binary form must reproduce the above copyright 13327Sjkh * notice, this list of conditions and the following disclaimer in the 14327Sjkh * documentation and/or other materials provided with the distribution. 15327Sjkh * 16327Sjkh * Jordan K. Hubbard 17327Sjkh * 18 July 1993 18327Sjkh * 19327Sjkh * Include and define various things wanted by the library routines. 20327Sjkh * 21327Sjkh */ 22327Sjkh 23327Sjkh#ifndef _INST_LIB_LIB_H_ 24327Sjkh#define _INST_LIB_LIB_H_ 25327Sjkh 26327Sjkh/* Includes */ 2762154Sdes#include <sys/param.h> 2862154Sdes#include <sys/file.h> 2962154Sdes#include <sys/stat.h> 3083663Ssobomax#include <sys/queue.h> 31206043Sflz#include <sys/utsname.h> 3262154Sdes#include <ctype.h> 3362154Sdes#include <dirent.h> 3462154Sdes#include <stdarg.h> 35327Sjkh#include <stdio.h> 36327Sjkh#include <stdlib.h> 37327Sjkh#include <string.h> 38327Sjkh#include <unistd.h> 39327Sjkh 40327Sjkh/* Macros */ 41327Sjkh#define SUCCESS (0) 42327Sjkh#define FAIL (-1) 43327Sjkh 44327Sjkh#ifndef TRUE 45327Sjkh#define TRUE (1) 46327Sjkh#endif 47327Sjkh 48327Sjkh#ifndef FALSE 49327Sjkh#define FALSE (0) 50327Sjkh#endif 51327Sjkh 521338Sjkh#define YES 2 531338Sjkh#define NO 1 541338Sjkh 55206043Sflz/* Some more stat macros. */ 56206043Sflz#define S_IRALL 0000444 57206043Sflz#define S_IWALL 0000222 58206043Sflz#define S_IXALL 0000111 59206043Sflz 60327Sjkh/* Usually "rm", but often "echo" during debugging! */ 61131285Seik#define REMOVE_CMD "/bin/rm" 62327Sjkh 63327Sjkh/* Usually "rm", but often "echo" during debugging! */ 64131285Seik#define RMDIR_CMD "/bin/rmdir" 65327Sjkh 66173514Skrion/* Where the ports lives by default */ 67173514Skrion#define DEF_PORTS_DIR "/usr/ports" 68173514Skrion/* just in case we change the environment variable name */ 69173514Skrion#define PORTSDIR "PORTSDIR" 70173514Skrion/* macro to get name of directory where the ports lives */ 71173514Skrion#define PORTS_DIR (getenv(PORTSDIR) ? getenv(PORTSDIR) : DEF_PORTS_DIR) 72173514Skrion 737937Sjkh/* Where we put logging information by default, else ${PKG_DBDIR} if set */ 7481049Ssobomax#define DEF_LOG_DIR "/var/db/pkg" 757937Sjkh/* just in case we change the environment variable name */ 7681049Ssobomax#define PKG_DBDIR "PKG_DBDIR" 7781049Ssobomax/* macro to get name of directory where we put logging information */ 7881049Ssobomax#define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR) 79327Sjkh 80327Sjkh/* The names of our "special" files */ 8117338Sjkh#define CONTENTS_FNAME "+CONTENTS" 8217338Sjkh#define COMMENT_FNAME "+COMMENT" 8317338Sjkh#define DESC_FNAME "+DESC" 8417338Sjkh#define INSTALL_FNAME "+INSTALL" 8541866Sjkh#define POST_INSTALL_FNAME "+POST-INSTALL" 8617338Sjkh#define DEINSTALL_FNAME "+DEINSTALL" 8741866Sjkh#define POST_DEINSTALL_FNAME "+POST-DEINSTALL" 8817338Sjkh#define REQUIRE_FNAME "+REQUIRE" 894996Sjkh#define REQUIRED_BY_FNAME "+REQUIRED_BY" 9017338Sjkh#define DISPLAY_FNAME "+DISPLAY" 9117338Sjkh#define MTREE_FNAME "+MTREE_DIRS" 92327Sjkh 9317338Sjkh#define CMD_CHAR '@' /* prefix for extended PLIST cmd */ 94327Sjkh 951550Sasami/* The name of the "prefix" environment variable given to scripts */ 961550Sasami#define PKG_PREFIX_VNAME "PKG_PREFIX" 97479Sjkh 98103149Ssobomax/* 99196766Sflz * Version of the package tools - increase whenever you make a change 100196766Sflz * in the code that is not cosmetic only. 101103149Ssobomax */ 102241135Sbapt#define PKG_INSTALL_VERSION 20120918 103103149Ssobomax 104103149Ssobomax#define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf" 105103149Ssobomax#define main(argc, argv) real_main(argc, argv) 106103149Ssobomax 10784750Ssobomax/* Version numbers to assist with changes in package file format */ 10884750Ssobomax#define PLIST_FMT_VER_MAJOR 1 10984750Ssobomax#define PLIST_FMT_VER_MINOR 1 11084750Ssobomax 111327Sjkhenum _plist_t { 112327Sjkh PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD, 11317338Sjkh PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE, 11417338Sjkh PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY, 115157809Skrion PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM, 116147381Skrion PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN, 117147381Skrion PLIST_NOINST 118327Sjkh}; 119327Sjkhtypedef enum _plist_t plist_t; 120327Sjkh 12173134Ssobomaxenum _match_t { 122131275Seik MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX 12373134Ssobomax}; 12473134Ssobomaxtypedef enum _match_t match_t; 12573134Ssobomax 126327Sjkh/* Types */ 127327Sjkhtypedef unsigned int Boolean; 128327Sjkh 129327Sjkhstruct _plist { 130327Sjkh struct _plist *prev, *next; 131327Sjkh char *name; 132327Sjkh Boolean marked; 133327Sjkh plist_t type; 134327Sjkh}; 135327Sjkhtypedef struct _plist *PackingList; 136327Sjkh 137327Sjkhstruct _pack { 138327Sjkh struct _plist *head, *tail; 139131280Seik const char *name; 140131280Seik const char *origin; 14184750Ssobomax int fmtver_maj, fmtver_mnr; 142327Sjkh}; 143327Sjkhtypedef struct _pack Package; 144327Sjkh 14583663Ssobomaxstruct reqr_by_entry { 14683663Ssobomax STAILQ_ENTRY(reqr_by_entry) link; 14783663Ssobomax char pkgname[PATH_MAX]; 14883663Ssobomax}; 14983663SsobomaxSTAILQ_HEAD(reqr_by_head, reqr_by_entry); 150157809Skrion 151327Sjkh/* Prototypes */ 152327Sjkh/* Misc */ 153327Sjkhint vsystem(const char *, ...); 15474699Ssobomaxchar *vpipe(const char *, ...); 155327Sjkhvoid cleanup(int); 156194497Sbrianconst char *make_playpen(char *, off_t); 157383Sjkhchar *where_playpen(void); 158194497Sbrianint leave_playpen(void); 15984745Ssobomaxoff_t min_free(const char *); 160327Sjkh 161327Sjkh/* String */ 162327Sjkhchar *get_dash_string(char **); 16384745Ssobomaxchar *copy_string(const char *); 164115325Sliouxchar *copy_string_adds_newline(const char *); 16584745SsobomaxBoolean suffix(const char *, const char *); 166327Sjkhvoid nuke_suffix(char *); 167327Sjkhvoid str_lowercase(char *); 16884745Ssobomaxchar *strconcat(const char *, const char *); 16974699Ssobomaxchar *get_string(char *, int, FILE *); 170327Sjkh 171327Sjkh/* File */ 17284745SsobomaxBoolean fexists(const char *); 17384745SsobomaxBoolean isdir(const char *); 17484745SsobomaxBoolean isemptydir(const char *fname); 17584745SsobomaxBoolean isemptyfile(const char *fname); 176167972SnjlBoolean isfile(const char *); 17784745SsobomaxBoolean isempty(const char *); 17884745SsobomaxBoolean issymlink(const char *); 17984745SsobomaxBoolean isURL(const char *); 180194497Sbrianconst char *fileGetURL(const char *, const char *, int); 18184745Ssobomaxchar *fileFindByPath(const char *, const char *); 18284745Ssobomaxchar *fileGetContents(const char *); 18384745Ssobomaxvoid write_file(const char *, const char *); 18484745Ssobomaxvoid copy_file(const char *, const char *, const char *); 18584745Ssobomaxvoid move_file(const char *, const char *, const char *); 18684745Ssobomaxvoid copy_hierarchy(const char *, const char *, Boolean); 18784745Ssobomaxint delete_hierarchy(const char *, Boolean, Boolean); 18884745Ssobomaxint unpack(const char *, const char *); 189108778Sjkhvoid format_cmd(char *, int, const char *, const char *, const char *); 190327Sjkh 191327Sjkh/* Msg */ 192327Sjkhvoid upchuck(const char *); 193327Sjkhvoid barf(const char *, ...); 194327Sjkhvoid whinge(const char *, ...); 195327SjkhBoolean y_or_n(Boolean, const char *, ...); 196327Sjkh 197327Sjkh/* Packing list */ 198327SjkhPackingList new_plist_entry(void); 199327SjkhPackingList last_plist(Package *); 2001547SjkhPackingList find_plist(Package *, plist_t); 20184745Ssobomaxchar *find_plist_option(Package *, const char *name); 20284745Ssobomaxvoid plist_delete(Package *, Boolean, plist_t, const char *); 203327Sjkhvoid free_plist(Package *); 204327Sjkhvoid mark_plist(Package *); 205327Sjkhvoid csum_plist_entry(char *, PackingList); 20684745Ssobomaxvoid add_plist(Package *, plist_t, const char *); 20784745Ssobomaxvoid add_plist_top(Package *, plist_t, const char *); 20884745Ssobomaxvoid delete_plist(Package *pkg, Boolean all, plist_t type, const char *name); 209327Sjkhvoid write_plist(Package *, FILE *); 210327Sjkhvoid read_plist(Package *, FILE *); 21184745Ssobomaxint plist_cmd(const char *, char **); 2124996Sjkhint delete_package(Boolean, Boolean, Package *); 21384745SsobomaxBoolean make_preserve_name(char *, int, const char *, const char *); 214327Sjkh 215327Sjkh/* For all */ 216327Sjkhint pkg_perform(char **); 217103149Ssobomaxint real_main(int, char **); 218327Sjkh 21973134Ssobomax/* Query installed packages */ 22073134Ssobomaxchar **matchinstalled(match_t, char **, int *); 22196613Ssobomaxchar **matchbyorigin(const char *, int *); 222178753Spavchar ***matchallbyorigin(const char **, int *); 22396613Ssobomaxint isinstalledpkg(const char *name); 224131275Seikint pattern_match(match_t MatchType, char *pattern, const char *pkgname); 22573134Ssobomax 22674295Ssobomax/* Dependencies */ 22774295Ssobomaxint sortdeps(char **); 22884745Ssobomaxint chkifdepends(const char *, const char *); 22983663Ssobomaxint requiredby(const char *, struct reqr_by_head **, Boolean, Boolean); 23074295Ssobomax 23184750Ssobomax/* Version */ 23284750Ssobomaxint verscmp(Package *, int, int); 23398766Smarkmint version_cmp(const char *, const char *); 23484750Ssobomax 235327Sjkh/* Externs */ 236136643Sobrienextern Boolean Quiet; 237327Sjkhextern Boolean Fake; 23817338Sjkhextern Boolean Force; 2391338Sjkhextern int AutoAnswer; 240159554Sobrienextern int Verbose; 241327Sjkh 242327Sjkh#endif /* _INST_LIB_LIB_H_ */ 243