📄 main.c
字号:
/* SmoothWall install program. * * This program is distributed under the terms of the GNU General Public * Licence. See the file COPYING for details. * * (c) Lawrence Manning, 2001 * Contains main entry point, and misc functions. * * $Id: main.c,v 1.63.2.57 2005/09/25 19:57:46 gespinasse Exp $ * */#include "install.h"#define CDROM_INSTALL 0#define URL_INSTALL 1int raid_disk = 0;FILE *flog = NULL;char *mylog;char **ctr;char *pcmcia = NULL;extern char url[STRING_SIZE];extern char *bz_tr[];extern char *cs_tr[];extern char *da_tr[];extern char *en_tr[];extern char *es_tr[];extern char *fi_tr[];extern char *fr_tr[];extern char *hu_tr[];extern char *la_tr[];extern char *nl_tr[];extern char *de_tr[];extern char *tr_tr[];extern char *it_tr[];extern char *el_tr[];extern char *pl_tr[];extern char *pt_tr[];extern char *so_tr[];extern char *sv_tr[];extern char *no_tr[];extern char *vi_tr[];int main(int argc, char *argv[]){#ifdef LANG_EN_ONLY char *langnames[] = { "English", NULL }; char *shortlangnames[] = { "en", NULL }; char **langtrs[] = { en_tr, NULL };#else char *langnames[] = { "Brasil", "Cestina", "Dansk", "Deutsch", "English", "Español", "Français", "Hellenic", "Italiano", "Spanish Latino", "Magyar", "Nederlands", "Norsk", "Polski", "Português", "Soomali", "Suomi", "Svenska", "Türkçe", "Tieng Viet", NULL }; char *shortlangnames[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "so", "fi", "sv", "tr", "vi", NULL }; char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL };#endif char hdletter, cdletter; char harddrive[5], cdromdrive[5]; /* Device holder. */ struct devparams hdparams, cdromparams; /* Params for CDROM and HD */ int cdmounted = 0; /* Loop flag for inserting a cd. */ int rc; char commandstring[STRING_SIZE]; char *installtypes[] = { "CDROM", "HTTP/FTP", NULL }; int installtype = CDROM_INSTALL; char insertmessage[STRING_SIZE]; char insertdevnode[STRING_SIZE]; int choice; char shortlangname[10]; char message[1000]; char title[STRING_SIZE]; int allok = 0; int allok_fastexit=0; int unmount_before=0; struct keyvalue *ethernetkv = initkeyvalues(); FILE *handle, *cmdfile; char line[STRING_SIZE]; char string[STRING_SIZE]; int maximum_free = 0, current_free; int memory = 0; int log_partition, boot_partition, root_partition, swap_file; int scsi_disk = 0; int pcmcia_disk = 0; int pcmcia_cdrom = 0; int scsi_cdrom = 0; int ide_cdrom = 0; int fdisk = 0; setlocale (LC_ALL, ""); sethostname( SNAME , 10); memset(&hdparams, 0, sizeof(struct devparams)); memset(&cdromparams, 0, sizeof(struct devparams)); /* Log file/terminal stuff. */ if (argc >= 2) { if (!(flog = fopen(argv[1], "w+"))) return 0; } else return 0; mylog = argv[1]; fprintf(flog, "Install program started.\n"); newtInit(); newtCls(); /* Do usb detection first for usb keyboard */ if (! (cmdfile = fopen("/proc/cmdline", "r"))) { fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); } else { fgets(line, STRING_SIZE, cmdfile); if (strstr (line, "fdisk") != NULL) { fprintf(flog, "Manual FDISK selected.\n"); fdisk = 1; } if (strstr (line, "nopcmcia") == NULL) { fprintf(flog, "Initializing PCMCIA controllers.\n"); pcmcia = initialize_pcmcia(); if (pcmcia) { fprintf (flog, "Detected PCMCIA Controller: %s.\n", pcmcia); sprintf(commandstring, "/sbin/modprobe %s", pcmcia); mysystem("/sbin/modprobe pcmcia_core"); mysystem(commandstring); mysystem("/sbin/modprobe ds"); /* pcmcia netcard drivers are not available from Boot floppy, * they will be loaded from Drivers floppy later */ } else { fprintf (flog, "Detected No PCMCIA Controller.\n"); } } else { fprintf(flog, "Skipping PCMCIA detection.\n"); } if (strstr (line, "nousb") == NULL) { fprintf(flog, "Initializing USB controllers.\n"); initialize_usb(); } else { fprintf(flog, "Skipping USB detection.\n"); } } /* English is the default */ for (choice = 0; langnames[choice]; choice++) { if (strcmp(langnames[choice], "English") == 0) break; } if (!langnames[choice]) goto EXIT;#ifdef LANG_EN_ONLY /* No need to ask. "choice" already has the index for English */#else rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, langnames, &choice, "Ok", NULL);#endif ctr = langtrs[choice]; strcpy(shortlangname, shortlangnames[choice]); if (strcmp(shortlangname, "el") == 0) mysystem("/bin/setfont iso07u-16"); else if (strcmp(shortlangname, "pt") == 0) mysystem("/bin/setfont lat1-16"); else if (strcmp(shortlangname, "bz") == 0) mysystem("/bin/setfont lat1-16"); else if (strcmp(shortlangname, "cs") == 0) mysystem("/bin/setfont lat2-16"); else if (strcmp(shortlangname, "hu") == 0) mysystem("/bin/setfont lat2-16"); else if (strcmp(shortlangname, "pl") == 0) mysystem("/bin/setfont lat2-16"); else if (strcmp(shortlangname, "tr") == 0) mysystem("/bin/setfont lat5-16"); else if (strcmp(shortlangname, "vi") == 0) mysystem("/bin/setfont viscii10-8x16"); else mysystem("/bin/setfont lat0-16"); newtDrawRootText(14, 0, NAME " v" VERSION " - " SLOGAN ); newtPushHelpLine(ctr[TR_HELPLINE]); sprintf(message, ctr[TR_WELCOME], NAME); sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); newtWinMessage(title, ctr[TR_OK], message); sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME); rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message, 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 2) goto EXIT; if (installtype == CDROM_INSTALL) { /* First look for an IDE CDROM. */ if (!(cdletter = findidetype(IDE_CDROM))) { /* If we have a USB attached CDROM then it will * have already appeared at /dev/scd0, so we * try to access it first, before asking for the * SCSI drivers disk. */ if (!(try_scsi("scd0"))) { sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME" SCSI"); rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); if (rc != 1) { errorbox(ctr[TR_INSTALLATION_CANCELED]); goto EXIT; } if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr[TR_EXTRACTING_MODULES])) { errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); goto EXIT; } if (pcmcia) { /* trying to support SCSI pcmcia :-) */ runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi", ctr[TR_LOADING_PCMCIA]); if (try_scsi("scd0")) pcmcia_cdrom = 1; } /* try loading all SCSI modules with default options */ /* Should expand this to allow options later though */ if (!pcmcia_cdrom) runcommandwithstatus("/bin/probescsi.sh", ctr[TR_PROBING_SCSI]); /* If it fails, give up. */ if (!(try_scsi("scd0"))) { errorbox(ctr[TR_NO_CDROM]); goto EXIT; } } sprintf(cdromdrive, "scd0"); scsi_cdrom = 1; } else { sprintf(cdromdrive, "hd%c", cdletter); ide_cdrom = 1; } snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", cdromdrive); cdromparams.module = 0; sprintf(insertmessage, ctr[TR_INSERT_CDROM], NAME); strcpy (insertdevnode, cdromparams.devnode); } else { /* If we've done a PXE boot, we can skip the Drivers floppy, * as we've already got the modules in our instroot.gz */ if (!(handle = fopen("/CDROMBOOT", "r"))) { sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME); strcpy (insertdevnode , "/dev/floppy"); } else { fclose(handle); cdmounted = 1; unmount_before = 1; } } if (scsi_cdrom || ide_cdrom) { /* Try to mount /cdrom in a loop. */ snprintf(commandstring, STRING_SIZE, "/bin/mount -o ro %s /cdrom", insertdevnode); while (!cdmounted) { rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); if (rc != 1) { errorbox(ctr[TR_INSTALLATION_CANCELED]); goto EXIT; } if (!(mysystem(commandstring))) { handle = fopen ("/cdrom/" SNAME "-" VERSION ".tgz", "r"); if (handle != NULL) { fclose (handle); cdmounted = 1; /* If we've booted from CDROM, then * we've already got the drivers, * so we can skip this unpack. */ if (!(handle = fopen("/CDROMBOOT", "r"))) { sprintf(string, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION); if (runcommandwithprogress(60, 4, title, string, 175, ctr[TR_EXTRACTING_MODULES])) { errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); goto EXIT; } } else fclose(handle); } else { mysystem ("/bin/umount /cdrom"); } } } } else { snprintf(commandstring, STRING_SIZE, "/bin/tar -C / -xvzf /dev/floppy"); while (!cdmounted) { rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); if (rc != 1) { errorbox(ctr[TR_INSTALLATION_CANCELED]); goto EXIT; } if (runcommandwithprogress(60, 4, title, commandstring, 175, ctr[TR_EXTRACTING_MODULES])) {#if 0 /* disable this, so we allow for people putting in the wrong disk */ errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); goto EXIT;#endif } else { handle = fopen ("/bin/mke2fs", "r"); if (handle != NULL) { fclose (handle); cdmounted = 1; } } } } /* PCMCIA controller is already detected
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -