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