4 * FreeBSD install - a package for the installation and maintainance
5 * of non-core utilities.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
19 * Include and define various things wanted by the library routines.
23 #ifndef _INST_LIB_LIB_H_
24 #define _INST_LIB_LIB_H_
27 #include <sys/param.h>
30 #include <sys/queue.h>
54 /* Usually "rm", but often "echo" during debugging! */
55 #define REMOVE_CMD "/bin/rm"
57 /* Usually "rm", but often "echo" during debugging! */
58 #define RMDIR_CMD "/bin/rmdir"
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)
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)
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"
87 #if defined(__FreeBSD_version) && __FreeBSD_version >= 800000
88 #define INDEX_FNAME "INDEX-8"
89 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
90 #define INDEX_FNAME "INDEX-7"
91 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
92 #define INDEX_FNAME "INDEX-6"
93 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 500036
94 #define INDEX_FNAME "INDEX-5"
96 #define INDEX_FNAME "INDEX"
99 #define CMD_CHAR '@' /* prefix for extended PLIST cmd */
101 /* The name of the "prefix" environment variable given to scripts */
102 #define PKG_PREFIX_VNAME "PKG_PREFIX"
105 * Version of the package tools - increase only when some
106 * functionality used by bsd.port.mk is changed, added or removed
108 #define PKG_INSTALL_VERSION 20040629
110 #define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf"
111 #define main(argc, argv) real_main(argc, argv)
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
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,
125 typedef enum _plist_t plist_t;
128 MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX
130 typedef enum _match_t match_t;
133 typedef unsigned int Boolean;
136 struct _plist *prev, *next;
141 typedef struct _plist *PackingList;
144 struct _plist *head, *tail;
147 int fmtver_maj, fmtver_mnr;
149 typedef struct _pack Package;
151 struct reqr_by_entry {
152 STAILQ_ENTRY(reqr_by_entry) link;
153 char pkgname[PATH_MAX];
155 STAILQ_HEAD(reqr_by_head, reqr_by_entry);
159 int vsystem(const char *, ...);
160 char *vpipe(const char *, ...);
162 char *make_playpen(char *, off_t);
163 char *where_playpen(void);
164 void leave_playpen(void);
165 off_t min_free(const char *);
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 *);
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 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 *);
198 void upchuck(const char *);
199 void barf(const char *, ...);
200 void whinge(const char *, ...);
201 Boolean y_or_n(Boolean, const char *, ...);
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 *);
222 int pkg_perform(char **);
223 int real_main(int, char **);
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);
233 int sortdeps(char **);
234 int chkifdepends(const char *, const char *);
235 int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
238 int verscmp(Package *, int, int);
239 int version_cmp(const char *, const char *);
242 extern Boolean Quiet;
244 extern Boolean Force;
245 extern int AutoAnswer;
248 #endif /* _INST_LIB_LIB_H_ */