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 we put logging information by default, else ${PKG_DBDIR} if set */
61 #define DEF_LOG_DIR "/var/db/pkg"
62 /* just in case we change the environment variable name */
63 #define PKG_DBDIR "PKG_DBDIR"
64 /* macro to get name of directory where we put logging information */
65 #define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR)
67 /* The names of our "special" files */
68 #define CONTENTS_FNAME "+CONTENTS"
69 #define COMMENT_FNAME "+COMMENT"
70 #define DESC_FNAME "+DESC"
71 #define INSTALL_FNAME "+INSTALL"
72 #define POST_INSTALL_FNAME "+POST-INSTALL"
73 #define DEINSTALL_FNAME "+DEINSTALL"
74 #define POST_DEINSTALL_FNAME "+POST-DEINSTALL"
75 #define REQUIRE_FNAME "+REQUIRE"
76 #define REQUIRED_BY_FNAME "+REQUIRED_BY"
77 #define DISPLAY_FNAME "+DISPLAY"
78 #define MTREE_FNAME "+MTREE_DIRS"
80 #if defined(__FreeBSD_version) && __FreeBSD_version >= 700000
81 #define INDEX_FNAME "INDEX-7"
82 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
83 #define INDEX_FNAME "INDEX-6"
84 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 500036
85 #define INDEX_FNAME "INDEX-5"
87 #define INDEX_FNAME "INDEX"
90 #define CMD_CHAR '@' /* prefix for extended PLIST cmd */
92 /* The name of the "prefix" environment variable given to scripts */
93 #define PKG_PREFIX_VNAME "PKG_PREFIX"
96 * Version of the package tools - increase only when some
97 * functionality used by bsd.port.mk is changed, added or removed
99 #define PKG_INSTALL_VERSION 20040629
101 #define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf"
102 #define main(argc, argv) real_main(argc, argv)
104 /* Version numbers to assist with changes in package file format */
105 #define PLIST_FMT_VER_MAJOR 1
106 #define PLIST_FMT_VER_MINOR 1
109 PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
110 PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
111 PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
112 PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM,
113 PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN,
116 typedef enum _plist_t plist_t;
119 MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX
121 typedef enum _match_t match_t;
124 typedef unsigned int Boolean;
127 struct _plist *prev, *next;
132 typedef struct _plist *PackingList;
135 struct _plist *head, *tail;
138 int fmtver_maj, fmtver_mnr;
140 typedef struct _pack Package;
142 struct reqr_by_entry {
143 STAILQ_ENTRY(reqr_by_entry) link;
144 char pkgname[PATH_MAX];
146 STAILQ_HEAD(reqr_by_head, reqr_by_entry);
150 int vsystem(const char *, ...);
151 char *vpipe(const char *, ...);
153 char *make_playpen(char *, off_t);
154 char *where_playpen(void);
155 void leave_playpen(void);
156 off_t min_free(const char *);
159 char *get_dash_string(char **);
160 char *copy_string(const char *);
161 char *copy_string_adds_newline(const char *);
162 Boolean suffix(const char *, const char *);
163 void nuke_suffix(char *);
164 void str_lowercase(char *);
165 char *strconcat(const char *, const char *);
166 char *get_string(char *, int, FILE *);
169 Boolean fexists(const char *);
170 Boolean isdir(const char *);
171 Boolean isemptydir(const char *fname);
172 Boolean isemptyfile(const char *fname);
173 Boolean isfile(const char *);
174 Boolean isempty(const char *);
175 Boolean issymlink(const char *);
176 Boolean isURL(const char *);
177 char *fileGetURL(const char *, const char *, int);
178 char *fileFindByPath(const char *, const char *);
179 char *fileGetContents(const char *);
180 void write_file(const char *, const char *);
181 void copy_file(const char *, const char *, const char *);
182 void move_file(const char *, const char *, const char *);
183 void copy_hierarchy(const char *, const char *, Boolean);
184 int delete_hierarchy(const char *, Boolean, Boolean);
185 int unpack(const char *, const char *);
186 void format_cmd(char *, int, const char *, const char *, const char *);
189 void upchuck(const char *);
190 void barf(const char *, ...);
191 void whinge(const char *, ...);
192 Boolean y_or_n(Boolean, const char *, ...);
195 PackingList new_plist_entry(void);
196 PackingList last_plist(Package *);
197 PackingList find_plist(Package *, plist_t);
198 char *find_plist_option(Package *, const char *name);
199 void plist_delete(Package *, Boolean, plist_t, const char *);
200 void free_plist(Package *);
201 void mark_plist(Package *);
202 void csum_plist_entry(char *, PackingList);
203 void add_plist(Package *, plist_t, const char *);
204 void add_plist_top(Package *, plist_t, const char *);
205 void delete_plist(Package *pkg, Boolean all, plist_t type, const char *name);
206 void write_plist(Package *, FILE *);
207 void read_plist(Package *, FILE *);
208 int plist_cmd(const char *, char **);
209 int delete_package(Boolean, Boolean, Package *);
210 Boolean make_preserve_name(char *, int, const char *, const char *);
213 int pkg_perform(char **);
214 int real_main(int, char **);
216 /* Query installed packages */
217 char **matchinstalled(match_t, char **, int *);
218 char **matchbyorigin(const char *, int *);
219 int isinstalledpkg(const char *name);
220 int pattern_match(match_t MatchType, char *pattern, const char *pkgname);
223 int sortdeps(char **);
224 int chkifdepends(const char *, const char *);
225 int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
228 int verscmp(Package *, int, int);
229 int version_cmp(const char *, const char *);
232 extern Boolean Quiet;
234 extern Boolean Force;
235 extern int AutoAnswer;
238 #endif /* _INST_LIB_LIB_H_ */