freebsd-dev/usr.sbin/pkg_install/add/futil.c
Oliver Eikemeier b9ba84598d - pkg_add spawns itself as argv[0] when installing dependent packages, to
enable the use as a port on older systems

- use absolute paths in all calls to external programs, to account for strange
  PATH settings

- use INDEX or INDEX-5 depending on FreeBSD version, to enable the use on
  FreeBSD 4.x as a port.

- conditionalize all 4.x/5.x differences on __FreeBSD_version, so that the
  pkg_install tools can be kept in sync on 4.x and 5.x

- Bump PKG_INSTALL_VERSION

Reviewed by:	portmgr (bento run)
MFC after:	4 weeks
2004-06-29 19:06:42 +00:00

98 lines
2.3 KiB
C

/*
* FreeBSD install - a package for the installation and maintainance
* of non-core utilities.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Jordan K. Hubbard
* 18 July 1993
*
* Miscellaneous file access utilities.
*
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <err.h>
#include "lib.h"
#include "add.h"
/*
* Assuming dir is a desired directory name, make it and all intervening
* directories necessary.
*/
int
make_hierarchy(char *dir)
{
char *cp1, *cp2;
if (dir[0] == '/')
cp1 = cp2 = dir + 1;
else
cp1 = cp2 = dir;
while (cp2) {
if ((cp2 = strchr(cp1, '/')) !=NULL )
*cp2 = '\0';
if (fexists(dir)) {
if (!isdir(dir)) {
if (cp2)
*cp2 = '/';
return FAIL;
}
}
else {
if (vsystem("/bin/mkdir %s", dir)) {
if (cp2)
*cp2 = '/';
return FAIL;
}
apply_perms(NULL, dir);
}
/* Put it back */
if (cp2) {
*cp2 = '/';
cp1 = cp2 + 1;
}
}
return SUCCESS;
}
/* Using permission defaults, apply them as necessary */
void
apply_perms(const char *dir, const char *arg)
{
const char *cd_to;
if (!dir || *arg == '/') /* absolute path? */
cd_to = "/";
else
cd_to = dir;
if (Mode)
if (vsystem("cd %s && /bin/chmod -R %s %s", cd_to, Mode, arg))
warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
if (Owner && Group) {
if (vsystem("cd %s && /usr/sbin/chown -R %s:%s %s", cd_to, Owner, Group, arg))
warnx("couldn't change owner/group of '%s' to '%s:%s'",
arg, Owner, Group);
return;
}
if (Owner) {
if (vsystem("cd %s && /usr/sbin/chown -R %s %s", cd_to, Owner, arg))
warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
return;
} else if (Group)
if (vsystem("cd %s && /usr/bin/chgrp -R %s %s", cd_to, Group, arg))
warnx("couldn't change group of '%s' to '%s'", arg, Group);
}