home *** CD-ROM | disk | FTP | other *** search
- /* $Revision:$
- ** Install
- */
-
- /*
- ** Configuration section. This is all done in the Makefile.
- */
- /* #define SYS_WAIT /* Have <sys/wait.h>? */
- /* #define FORK vfork /* If you have this use it... */
- /* #define FORK fork /* ...else use this */
- /* #define EXIT /* Needed to avoid stdio? */
- /* #define CHOWN_F_FLAG /* Have "chown -f"? */
- /* #define CHGRP_F_FLAG /* Have "chgrp -f"? */
- /* #define STDERR 2 /* Guess what this is */
- /* #define DEF_OWNER "root" /* Defalt owner of new files */
- /* #define DEF_GROUP "system" /* Default group for new files */
-
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #ifdef SYS_WAIT
- #include <sys/wait.h>
- #define WAITER union wait
- #else
- #define WAITER int
- #endif /* SYS_WAIT */
-
-
- char Source[BUFSIZ];
- char Destination[BUFSIZ];
- char *Pname;
-
- char *RMvec[] = {
- "/bin/rm", "-f", Destination, NULL
- };
-
- char *STRIPvec[] = {
- "/bin/strip", Destination, NULL
- };
-
- char *MOVEvec[] = {
- "/bin/mv", Source, Destination, NULL
- #define MV_CP MOVEvec[0]
- };
-
-
- char *CHMODvec[] = {
- "/bin/chmod", "755", Destination, NULL
- #define MODE CHMODvec[1]
- };
-
- char *CHOWNvec[] = {
- #ifdef CHOWN_F_FLAG
- "/etc/chown", "-f", DEF_OWNER, Destination, NULL
- #define OWNER CHOWNvec[2]
- #else
- "/etc/chown", DEF_OWNER, Destination, NULL
- #define OWNER CHOWNvec[1]
- #endif /* CHOWN_F_FLAG */
- };
-
- char *CHGRPvec[] = {
- #ifdef CHGRP_F_FLAG
- "/bin/chgrp", "-f", "system", Destination, NULL
- #define GROUP CHGRPvec[3]
- #else
- "/bin/chgrp", "system", Destination, NULL
- #define GROUP CHGRPvec[2]
- #endif /* CHGRP_F_FLAG */
- };
-
- /*
- ** Externals.
- */
- extern char **environ;
- extern char *optarg;
- extern int optind;
- extern char *IDX();
- extern char *strcpy();
- extern char *strcat();
-
- #ifdef lint
- char **environ;
- char *optarg;
- int optind;
- #endif /* lint */
-
-
-
- #ifndef lint
- #ifdef EXIT
- /*
- ** Avoid standard I/O crufties. Not needed on systems with a proper
- ** C library.
- */
- exit(X)
- int X;
- {
- _exit(X);
- }
- #endif /* EXIT */
- #endif /* lint */
-
-
- /*
- ** Print error message and die. No standard I/O.
- */
- void
- Err(s)
- char *s;
- {
- (void)write(STDERR, Pname, strlen(Pname));
- (void)write(STDERR, ": ", 3);
- (void)write(STDERR, s, strlen(s));
- (void)write(STDERR, ".\n", 2);
- exit(1);
- }
-
-
- /*
- ** Spin off an argv[] command, and wait for it.
- */
- void
- Doit(av)
- char *av[];
- {
- WAITER W;
- int i;
- int j;
-
- for (i = 0; av[i]; i++) printf("%d. %s\n", i, av[i]);
- /* Spin until we can fork. */
- while ((i = FORK()) < 0) {
- perror("fork");
- (void)sleep(1);
- }
-
- /* Kid becomes the program. */
- if (i == 0) {
- execve(av[0], av, environ);
- perror(av[0]);
- _exit(1);
- }
-
- /* Parent waits for kid, and probably loops on error. */
- while ((j = wait(&W)) != i)
- if (j < 0)
- perror("wait");
- }
-
-
- main(ac, av)
- register int ac;
- register char *av[];
- {
- register int c;
- int Strip;
- struct stat Sb;
-
- Pname = (Pname = IDX(av[0], '/')) ? Pname + 1 : av[0];
- for (Strip = 0; (c = getopt(ac, av, "scm:o:g:")) != EOF; )
- switch (c) {
- case 's':
- Strip++;
- break;
- case 'c':
- MV_CP = "/bin/cp";
- break;
- case 'm':
- MODE = optarg;
- break;
- case 'o':
- OWNER = optarg;
- break;
- case 'g':
- GROUP = optarg;
- break;
- }
-
- /* Check number of files specified. */
- switch (ac -= optind) {
- case 1:
- Err("No destination specified");
- case 3:
- Err("Too many files specified");
- }
- av += optind;
-
- /* Is the source an existing, standard file? */
- if (stat(av[0], &Sb) < 0)
- Err("Source file doesn't exist");
- if ((Sb.st_mode & S_IFMT) != S_IFREG)
- Err("Source isn't a regular file");
-
- /* Is the destination the same as the source? */
- if (strcmp(av[0], av[1]) == 0 || strcmp(av[1], ".") == 0)
- Err("Can't move file onto itself");
- (void)strcpy(Source, av[0]);
-
- /* If the destination is a directory, make a file. */
- if (stat(av[1], &Sb) >= 0 && (Sb.st_mode & S_IFMT) == S_IFDIR)
- (void)strcat(strcat(strcpy(Destination, av[0]), "/"), av[1]);
- else
- (void)strcpy(Destination, av[1]);
-
- Doit(RMvec);
- Doit(MOVEvec);
- if (Strip)
- Doit(STRIPvec);
- Doit(CHOWNvec);
- Doit(CHGRPvec);
- Doit(CHMODvec);
-
- exit(0);
- }
-