1 /* install-mh.c - initialize the MH environment */
3 static char ident[] = "@(#)$Id: install-mh.c,v 1.8 1992/12/15 00:20:22 jromine Exp $";
17 static char *message[] = {
18 "Prior to using MH, it is necessary to have a file in your login",
19 "directory (%s) named %s which contains information",
20 "to direct certain MH operations. The only item which is required",
21 "is the path to use for all MH folder operations. The suggested MH",
22 "path for you is %s/Mail...",
31 struct passwd *getpwuid ();
33 #endif /* !__STDC__ */
54 setlocale(LC_ALL, "");
56 invo_name = r1bindex (argv[0], '/');
59 if (argc == 2 && strcmp (argv[1], "-compat") == 0) {
60 context = "/dev/null"; /* hack past m_getdefs() */
63 for (np = m_defs; np; np = np -> n_next)
64 if (uleq (pfolder, np -> n_name)
65 || ssequal ("atr-", np -> n_name)
66 || ssequal ("cur-", np -> n_name))
69 ctxpath = getcpy (m_maildir (context = "context"));
73 if ((out = fopen (defpath, "w")) == NULL)
74 adios (defpath, "unable to write");
75 for (np = m_defs; np; np = np -> n_next)
77 fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
84 autof = (argc == 2 && strcmp (argv[1], "-auto") == 0);
85 if (mypath == NULL) { /* straight from m_getdefs... */
86 if (mypath = getenv ("HOME"))
87 mypath = getcpy (mypath);
89 if ((pw = getpwuid (getuid ())) == NULL
90 || pw -> pw_dir == NULL
91 || *pw -> pw_dir == 0)
92 adios (NULLCP, "no HOME envariable");
94 mypath = getcpy (pw -> pw_dir);
95 if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
98 defpath = concat (mypath, "/", mh_profile, NULLCP);
100 if (stat (defpath, &st) != NOTOK)
102 adios (NULLCP, "invocation error");
105 "You already have an MH profile, use an editor to modify it");
107 if (!autof && gans ("Do you want help? ", anoyes)) {
108 (void) putchar ('\n');
109 for (i = 0; message[i]; i++) {
110 printf (message[i], mypath, mh_profile);
111 (void) putchar ('\n');
113 (void) putchar ('\n');
118 cp = concat (mypath, "/", "Mail", NULLCP);
119 if (stat (cp, &st) != NOTOK) {
120 if ((st.st_mode & S_IFMT) == S_IFDIR) {
121 cp = concat ("You already have the standard MH directory \"",
122 cp, "\".\nDo you want to use it for MH? ", NULLCP);
123 if (gans (cp, anoyes))
133 printf ("I'm going to create the standard MH path for you.\n");
135 cp = concat ("Do you want the standard MH path \"",
136 mypath, "/", "Mail\"? ", NULLCP);
137 if (autof || gans (cp, anoyes))
141 if (gans ("Do you want a path below your login directory? ",
143 printf ("What is the path? %s/", mypath);
147 printf ("What is the whole path? /");
148 path = concat ("/", geta (), NULLCP);
153 (void) chdir (mypath);
154 if (chdir (path) == NOTOK) {
155 cp = concat ("\"", path, "\" doesn't exist; Create it? ", NULLCP);
156 if (autof || gans (cp, anoyes))
157 if (makedir (path) == 0)
158 adios (NULLCP, "unable to create %s", path);
161 printf ("[Using existing directory]\n");
165 np = m_defs = (struct node *) malloc (sizeof *np);
167 adios (NULLCP, "unable to allocate profile storage");
168 np -> n_name = getcpy ("Path");
169 np -> n_field = getcpy (path);
173 if (in = fopen (mh_defaults, "r")) {
174 m_readefs (&np -> n_next, in, mh_defaults, 0);
178 ctxpath = getcpy (m_maildir (context = "context"));
179 m_replace (pfolder, defalt);
182 if ((out = fopen (defpath, "w")) == NULL)
183 adios (defpath, "unable to write");
184 for (np = m_defs; np; np = np -> n_next)
185 if (!np -> n_context)
186 fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
194 static char *geta () {
196 static char line[BUFSIZ];
198 (void) fflush (stdout);
199 if (fgets (line, sizeof line, stdin) == NULL)
201 if (cp = index (line, '\n'))