3 * install-mh.c -- initialize the nmh environment of a new user
11 static struct swit switches[] = {
21 static char *message[] = {
22 "Prior to using nmh, it is necessary to have a file in your login",
23 "directory (%s) named %s which contains information",
24 "to direct certain nmh operations. The only item which is required",
25 "is the path to use for all nmh folder operations. The suggested nmh",
26 "path for you is %s/Mail...",
33 static char *geta(void);
37 main (int argc, char **argv)
40 char *cp, *path, buf[BUFSIZ];
41 char *dp, **arguments, **argp;
48 setlocale(LC_ALL, "");
50 invo_name = r1bindex (argv[0], '/');
51 arguments = getarguments (invo_name, argc, argv, 0);
54 while ((dp = *argp++)) {
56 switch (smatch (++dp, switches)) {
58 ambigsw (dp, switches);
61 adios (NULL, "-%s unknown\n", dp);
64 snprintf (buf, sizeof(buf), "%s [switches]", invo_name);
65 print_help (buf, switches, 0);
68 print_version(invo_name);
76 adios (NULL, "%s is invalid argument", dp);
80 /* straight from context_read ... */
82 if ((mypath = getenv ("HOME"))) {
83 mypath = getcpy (mypath);
85 if ((pw = getpwuid (getuid ())) == NULL
88 adios (NULL, "no HOME envariable");
90 mypath = getcpy (pw->pw_dir);
92 if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
95 defpath = concat (mypath, "/", mh_profile, NULL);
97 if (stat (defpath, &st) != NOTOK) {
99 adios (NULL, "invocation error");
102 "You already have an nmh profile, use an editor to modify it");
105 if (!autof && gans ("Do you want help? ", anoyes)) {
107 for (i = 0; message[i]; i++) {
108 printf (message[i], mypath, mh_profile);
114 cp = concat (mypath, "/", "Mail", NULL);
115 if (stat (cp, &st) != NOTOK) {
116 if (S_ISDIR(st.st_mode)) {
117 cp = concat ("You already have the standard nmh directory \"",
118 cp, "\".\nDo you want to use it for nmh? ", NULL);
119 if (gans (cp, anoyes))
128 printf ("I'm going to create the standard nmh path for you.\n");
130 cp = concat ("Do you want the standard nmh path \"",
131 mypath, "/", "Mail\"? ", NULL);
132 if (autof || gans (cp, anoyes))
136 if (gans ("Do you want a path below your login directory? ",
138 printf ("What is the path? %s/", mypath);
141 printf ("What is the whole path? /");
142 path = concat ("/", geta (), NULL);
148 if (chdir (path) == NOTOK) {
149 cp = concat ("\"", path, "\" doesn't exist; Create it? ", NULL);
150 if (autof || gans (cp, anoyes))
151 if (makedir (path) == 0)
152 adios (NULL, "unable to create %s", path);
154 printf ("[Using existing directory]\n");
158 * Add some initial elements to the profile/context list
160 if (!(m_defs = (struct node *) malloc (sizeof *np)))
161 adios (NULL, "unable to allocate profile storage");
163 np->n_name = getcpy ("Path");
164 np->n_field = getcpy (path);
169 * If there is a default profile file in the
170 * nmh `etc' directory, then read it also.
172 if ((in = fopen (mh_defaults, "r"))) {
173 readconfig (&np->n_next, in, mh_defaults, 0);
177 ctxpath = getcpy (m_maildir (context = "context"));
179 /* Initialize current folder to default */
180 context_replace (pfolder, defaultfolder);
184 * Now write out the initial .mh_profile
186 if ((out = fopen (defpath, "w")) == NULL)
187 adios (defpath, "unable to write");
188 for (np = m_defs; np; np = np->n_next) {
190 fprintf (out, "%s: %s\n", np->n_name, np->n_field);
201 static char line[BUFSIZ];
204 if (fgets(line, sizeof(line), stdin) == NULL)
206 if ((cp = strchr(line, '\n')))