X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Futils%2Fsetup.c;h=bf6ea963429b907ca9665d7b955a48d254ddadd8;hb=0f7b8c91ca57eba48ff548bcbefcaacf9038384b;hp=8f9cd5867ae9949064fb48201479dbc57fca1e19;hpb=1f6877630b975698550c84e1f7f47a761316097b;p=citadel.git diff --git a/citadel/utils/setup.c b/citadel/utils/setup.c index 8f9cd5867..bf6ea9634 100644 --- a/citadel/utils/setup.c +++ b/citadel/utils/setup.c @@ -1,5 +1,15 @@ /* * Citadel setup utility + * + * Copyright (c) 1987-2012 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #define SHOW_ME_VAPPEND_PRINTF @@ -102,7 +112,6 @@ const char *setup_text[eMaxQuestions]; void SetTitles(void) { - char *locale; int have_run_dir; #ifndef HAVE_RUN_DIR have_run_dir = 1; @@ -110,11 +119,13 @@ void SetTitles(void) have_run_dir = 0; #endif - locale = setlocale(LC_MESSAGES, getenv("LANG")); +#ifdef ENABLE_NLS + setlocale(LC_MESSAGES, getenv("LANG")); bindtextdomain("citadel-setup", LOCALEDIR"/locale"); textdomain("citadel-setup"); bind_textdomain_codeset("citadel-setup","UTF8"); +#endif setup_titles[eCitadelHomeDir] = _("Citadel Home Directory"); if (have_run_dir) @@ -350,6 +361,8 @@ void important_message(const char *title, const char *msgtext) getenv("CTDL_DIALOG"), msgtext); rv = system(buf); + if (rv != 0) + fprintf(stderr, _("failed to run the dialog command\n")); break; case UI_SILENT: fprintf(stderr, "%s\n", msgtext); @@ -522,9 +535,21 @@ void delete_inittab_entry(void) while (fgets(buf, sizeof buf, infp) != NULL) { if (strstr(buf, looking_for) != NULL) { rv = fwrite("#", 1, 1, outfp); + if (rv == -1) + { + display_error("%s %s\n", + _("failed to modify inittab"), + strerror(errno)); + } ++changes_made; } rv = fwrite(buf, strlen(buf), 1, outfp); + if (rv == -1) + { + display_error("%s %s\n", + _("failed to modify inittab"), + strerror(errno)); + } } fclose(infp); @@ -640,11 +665,18 @@ void install_init_scripts(void) /* Set up the run levels. */ rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null"); + if (rv != 0) + display_error(_("failed to remove system V init links \n")); + snprintf(command, sizeof(command), "for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/S79citadel ; done 2>/dev/null", initfile); rv = system(command); + if (rv != 0) + display_error(_("failed to set system V init links \n")); + snprintf(command, sizeof(command),"for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/K30citadel ; done 2>/dev/null", initfile); rv = system(command); - + if (rv != 0) + display_error(_("failed to set system V init links \n")); } @@ -705,6 +737,8 @@ void check_xinetd_entry(void) { /* Now try to restart the service */ rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1"); + if (rv != 0) + display_error(_("failed to restart xinetd.\n")); } @@ -758,8 +792,13 @@ void disable_other_mta(const char *mta) { sprintf(buf, "for x in /etc/rc*.d/S*%s; do mv $x `echo $x |sed s/S/K/g`; done >/dev/null 2>&1", mta); rv = system(buf); + if (rv != 0) + display_error("%s %s.\n", _("failed to disable other mta"), mta); + sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta); rv = system(buf); + if (rv != 0) + display_error(" %s.\n", _("failed to disable other mta"), mta); } const char *other_mtas[] = { @@ -875,6 +914,9 @@ void strprompt(const char *prompt_title, const char *prompt_text, char *Target, Target, dialog_result); rv = system(buf); + if (rv != 0) + fprintf(stderr, "failed to run Dialog.\n"); + fp = fopen(dialog_result, "r"); if (fp != NULL) { if (fgets(Target, sizeof buf, fp)) { @@ -887,7 +929,8 @@ void strprompt(const char *prompt_title, const char *prompt_text, char *Target, } break; case UI_SILENT: - strcpy(Target, DefValue); + if (*DefValue != '\0') + strcpy(Target, DefValue); break; } } @@ -1069,8 +1112,13 @@ void write_config_to_disk(void) if (fp == NULL) { display_error("%s citadel.config [%s][%s]\n", _("setup: cannot open"), file_citadel_config, strerror(errno)); cleanup(1); + return; } rv = fwrite((char *) &config, sizeof(struct config), 1, fp); + + if (rv == -1) + display_error("%s citadel.config [%s][%s]\n", _("setup: cannot write"), file_citadel_config, strerror(errno)); + fclose(fp); } @@ -1093,15 +1141,6 @@ int discover_ui(void) -void migrate_old_installs(void) -{ - int rv; - rv = system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null"); - unlink("citadel.log"); - unlink("weekly"); -} - - /* * Strip "db" entries out of /etc/nsswitch.conf */ @@ -1112,7 +1151,6 @@ void fixnss(void) { char buf_nc[256]; char question[512]; int i; - int changed = 0; int file_changed = 0; char new_filename[64]; int rv; @@ -1130,7 +1168,6 @@ void fixnss(void) { } while (fgets(buf, sizeof buf, fp_read) != NULL) { - changed = 0; strcpy(buf_nc, buf); for (i=0; i 0) { if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) { - changed = 1; file_changed = 1; strcpy(&buf_nc[i], &buf_nc[i+2]); strcpy(&buf[i], &buf[i+2]); @@ -1184,6 +1220,9 @@ void fixnss(void) { if (yesno(question, 1)) { sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF); rv = system(buf); + if (rv != 0) + fprintf(stderr, "failed to edit %s.\n", NSSCONF); + chmod(NSSCONF, 0644); } unlink(new_filename); @@ -1205,6 +1244,8 @@ void check_init_script (char *relhome) if (!access("/etc/init.d/citadel", X_OK)) { rv = system("/etc/init.d/citadel start"); + if (rv != 0) + fprintf(stderr, "failed to call our initscript."); sleep(3); } @@ -1414,8 +1455,11 @@ void get_config (void) if (fp == NULL) { display_error("%s citadel.config [%s][%s]\n", _("setup: cannot open"), file_citadel_config, strerror(errno)); cleanup(errno); + return; } rv = fread((char *) &config, sizeof(struct config), 1, fp); + if (rv == -1) + display_error("%s citadel.config [%s][%s]\n", _("setup: cannot write"), file_citadel_config, strerror(errno)); fclose(fp); } @@ -1496,6 +1540,8 @@ int main(int argc, char *argv[]) /* Try to stop Citadel if we can */ if (!access("/etc/init.d/citadel", X_OK)) { rv = system("/etc/init.d/citadel stop"); + if (rv != 0) + fprintf(stderr, _("failed to stop us using the initscript.\n")); } /* Make sure Citadel is not running. */ @@ -1564,8 +1610,6 @@ NEW_INST: write_config_to_disk(); - migrate_old_installs(); /* Delete files and directories used by older Citadel versions */ - if ( ((setup_type == UI_SILENT) && (getenv("ALTER_ETC_SERVICES")!=NULL)) || (setup_type != UI_SILENT)