]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.sbin/pkg_install/lib/lib.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.sbin / pkg_install / lib / lib.h
1 /* $FreeBSD$ */
2
3 /*
4  * FreeBSD install - a package for the installation and maintainance
5  * of non-core utilities.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * Jordan K. Hubbard
17  * 18 July 1993
18  *
19  * Include and define various things wanted by the library routines.
20  *
21  */
22
23 #ifndef _INST_LIB_LIB_H_
24 #define _INST_LIB_LIB_H_
25
26 /* Includes */
27 #include <sys/param.h>
28 #include <sys/file.h>
29 #include <sys/stat.h>
30 #include <sys/queue.h>
31 #include <ctype.h>
32 #include <dirent.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
38
39 /* Macros */
40 #define SUCCESS (0)
41 #define FAIL    (-1)
42
43 #ifndef TRUE
44 #define TRUE    (1)
45 #endif
46
47 #ifndef FALSE
48 #define FALSE   (0)
49 #endif
50
51 #define YES             2
52 #define NO              1
53
54 /* Usually "rm", but often "echo" during debugging! */
55 #define REMOVE_CMD      "/bin/rm"
56
57 /* Usually "rm", but often "echo" during debugging! */
58 #define RMDIR_CMD       "/bin/rmdir"
59
60 /* Where the ports lives by default */
61 #define DEF_PORTS_DIR   "/usr/ports"
62 /* just in case we change the environment variable name */
63 #define PORTSDIR    "PORTSDIR"
64 /* macro to get name of directory where the ports lives */
65 #define PORTS_DIR       (getenv(PORTSDIR) ? getenv(PORTSDIR) : DEF_PORTS_DIR)
66
67 /* Where we put logging information by default, else ${PKG_DBDIR} if set */
68 #define DEF_LOG_DIR     "/var/db/pkg"
69 /* just in case we change the environment variable name */
70 #define PKG_DBDIR       "PKG_DBDIR"
71 /* macro to get name of directory where we put logging information */
72 #define LOG_DIR         (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR)
73
74 /* The names of our "special" files */
75 #define CONTENTS_FNAME          "+CONTENTS"
76 #define COMMENT_FNAME           "+COMMENT"
77 #define DESC_FNAME              "+DESC"
78 #define INSTALL_FNAME           "+INSTALL"
79 #define POST_INSTALL_FNAME      "+POST-INSTALL"
80 #define DEINSTALL_FNAME         "+DEINSTALL"
81 #define POST_DEINSTALL_FNAME    "+POST-DEINSTALL"
82 #define REQUIRE_FNAME           "+REQUIRE"
83 #define REQUIRED_BY_FNAME       "+REQUIRED_BY"
84 #define DISPLAY_FNAME           "+DISPLAY"
85 #define MTREE_FNAME             "+MTREE_DIRS"
86
87 #if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
88 #define INDEX_FNAME             "INDEX-9"
89 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 800000
90 #define INDEX_FNAME             "INDEX-8"
91 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
92 #define INDEX_FNAME             "INDEX-7"
93 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
94 #define INDEX_FNAME             "INDEX-6"
95 #else
96 #define INDEX_FNAME             "INDEX"
97 #endif
98
99 #define CMD_CHAR                '@'     /* prefix for extended PLIST cmd */
100
101 /* The name of the "prefix" environment variable given to scripts */
102 #define PKG_PREFIX_VNAME        "PKG_PREFIX"
103
104 /*
105  * Version of the package tools - increase whenever you make a change
106  * in the code that is not cosmetic only.
107  */
108 #define PKG_INSTALL_VERSION     20090902
109
110 #define PKG_WRAPCONF_FNAME      "/var/db/pkg_install.conf"
111 #define main(argc, argv)        real_main(argc, argv)
112
113 /* Version numbers to assist with changes in package file format */
114 #define PLIST_FMT_VER_MAJOR     1
115 #define PLIST_FMT_VER_MINOR     1
116
117 enum _plist_t {
118     PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
119     PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
120     PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
121     PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM,
122     PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN,
123     PLIST_NOINST
124 };
125 typedef enum _plist_t plist_t;
126
127 enum _match_t {
128     MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX
129 };
130 typedef enum _match_t match_t;
131
132 /* Types */
133 typedef unsigned int Boolean;
134
135 struct _plist {
136     struct _plist *prev, *next;
137     char *name;
138     Boolean marked;
139     plist_t type;
140 };
141 typedef struct _plist *PackingList;
142
143 struct _pack {
144     struct _plist *head, *tail;
145     const char *name;
146     const char *origin;
147     int fmtver_maj, fmtver_mnr;
148 };
149 typedef struct _pack Package;
150
151 struct reqr_by_entry {
152     STAILQ_ENTRY(reqr_by_entry) link;
153     char pkgname[PATH_MAX];
154 };
155 STAILQ_HEAD(reqr_by_head, reqr_by_entry);
156
157 /* Prototypes */
158 /* Misc */
159 int             vsystem(const char *, ...);
160 char            *vpipe(const char *, ...);
161 void            cleanup(int);
162 const char      *make_playpen(char *, off_t);
163 char            *where_playpen(void);
164 int             leave_playpen(void);
165 off_t           min_free(const char *);
166
167 /* String */
168 char            *get_dash_string(char **);
169 char            *copy_string(const char *);
170 char            *copy_string_adds_newline(const char *);
171 Boolean         suffix(const char *, const char *);
172 void            nuke_suffix(char *);
173 void            str_lowercase(char *);
174 char            *strconcat(const char *, const char *);
175 char            *get_string(char *, int, FILE *);
176
177 /* File */
178 Boolean         fexists(const char *);
179 Boolean         isdir(const char *);
180 Boolean         isemptydir(const char *fname);
181 Boolean         isemptyfile(const char *fname);
182 Boolean         isfile(const char *);
183 Boolean         isempty(const char *);
184 Boolean         issymlink(const char *);
185 Boolean         isURL(const char *);
186 const char      *fileGetURL(const char *, const char *, int);
187 char            *fileFindByPath(const char *, const char *);
188 char            *fileGetContents(const char *);
189 void            write_file(const char *, const char *);
190 void            copy_file(const char *, const char *, const char *);
191 void            move_file(const char *, const char *, const char *);
192 void            copy_hierarchy(const char *, const char *, Boolean);
193 int             delete_hierarchy(const char *, Boolean, Boolean);
194 int             unpack(const char *, const char *);
195 void            format_cmd(char *, int, const char *, const char *, const char *);
196
197 /* Msg */
198 void            upchuck(const char *);
199 void            barf(const char *, ...);
200 void            whinge(const char *, ...);
201 Boolean         y_or_n(Boolean, const char *, ...);
202
203 /* Packing list */
204 PackingList     new_plist_entry(void);
205 PackingList     last_plist(Package *);
206 PackingList     find_plist(Package *, plist_t);
207 char            *find_plist_option(Package *, const char *name);
208 void            plist_delete(Package *, Boolean, plist_t, const char *);
209 void            free_plist(Package *);
210 void            mark_plist(Package *);
211 void            csum_plist_entry(char *, PackingList);
212 void            add_plist(Package *, plist_t, const char *);
213 void            add_plist_top(Package *, plist_t, const char *);
214 void            delete_plist(Package *pkg, Boolean all, plist_t type, const char *name);
215 void            write_plist(Package *, FILE *);
216 void            read_plist(Package *, FILE *);
217 int             plist_cmd(const char *, char **);
218 int             delete_package(Boolean, Boolean, Package *);
219 Boolean         make_preserve_name(char *, int, const char *, const char *);
220
221 /* For all */
222 int             pkg_perform(char **);
223 int             real_main(int, char **);
224
225 /* Query installed packages */
226 char            **matchinstalled(match_t, char **, int *);
227 char            **matchbyorigin(const char *, int *);
228 char            ***matchallbyorigin(const char **, int *);
229 int             isinstalledpkg(const char *name);
230 int             pattern_match(match_t MatchType, char *pattern, const char *pkgname);
231
232 /* Dependencies */
233 int             sortdeps(char **);
234 int             chkifdepends(const char *, const char *);
235 int             requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
236
237 /* Version */
238 int             verscmp(Package *, int, int);
239 int             version_cmp(const char *, const char *);
240
241 /* Externs */
242 extern Boolean  Quiet;
243 extern Boolean  Fake;
244 extern Boolean  Force;
245 extern int      AutoAnswer;
246 extern int      Verbose;
247
248 #endif /* _INST_LIB_LIB_H_ */