📄 main.c
字号:
/* Either use tarball from cdrom or download. */ if (installtype == CDROM_INSTALL) snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME "-" VERSION ".tgz"); else snprintf(commandstring, STRING_SIZE, "/bin/wget -O - %s/" SNAME "-" VERSION ".tgz | /bin/tar -C /harddisk -xvzf -", url); if (runcommandwithprogress(60, 4, title, commandstring, 4600, ctr[TR_INSTALLING_FILES])) { errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); goto EXIT; } /* Save USB controller type to modules.conf */ write_usb_modules_conf(); /* touch the modules.dep files */ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep", KERNEL_VERSION); mysystem(commandstring);#ifdef __i386__ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep", KERNEL_VERSION); mysystem(commandstring);#endif /* Rename uname */ rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname"); /* Write PCMCIA Config */ if (pcmcia) { handle = fopen("/harddisk/etc/modules.conf", "a"); if (handle != NULL) { fprintf (handle, "# PCMCIA Settings\n"); fprintf (handle, "alias pcmcia-controller %s\n", pcmcia); fclose(handle); } } handle = fopen("/harddisk/etc/pcmcia.conf", "w"); if (handle != NULL) { if (pcmcia) { fprintf (handle, "PCMCIA=yes\n"); fprintf (handle, "PCIC=%s\n", pcmcia); } else { fprintf (handle, "PCMCIA=no\n"); fprintf (handle, "PCIC=\n"); } fprintf (handle, "CARDMGR_OPTS=\n"); fprintf (handle, "SCHEME=\n"); fclose(handle); } /* *always* write disk configuration */ if (!(write_disk_configs(&hdparams))){ errorbox(ctr[TR_ERROR_WRITING_CONFIG]); goto EXIT; } /* Allow the user to restore their configuration from a floppy. It uses tar. If the tar fails for any reason, show user an error and go back to the restore/skip question. This gives the user the chance to have another go. */RESTORE: /* set status variables to nonsense values */ allok_fastexit = 0; /* loop until floppy succeeds or user skips out */ while (1) { sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME); if (newtWinChoice(title, ctr[TR_RESTORE], ctr[TR_SKIP], message) == 1) { /* Temporarily mount /proc under /harddisk/proc, * run updfstab to locate the floppy, and unmount /harddisk/proc * again. This should be run each time the user tries to restore * so it can properly detect removable devices */ if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) { errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]); goto EXIT; } if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) { errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]); goto EXIT; } mysystem("/bin/umount /harddisk/proc"); mkdir("/harddisk/tmp/ipcop", S_IRWXU|S_IRWXG|S_IRWXO); /* Always extract to /tmp/ipcop for temporary extraction * just in case floppy fails */ /* try a compressed backup first because it's quicker to fail. * In exclude.system, files name must be without leading / or * on extraction, name will never match */ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog); statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]); rc = system(commandstring); if (rc) { /* if it's not compressed, try uncompressed first before failing*/ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog); rc = system(commandstring); if (rc) { newtPopWindow(); /* command failed trying to read from floppy */ errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); /* remove badly restored files */ mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); goto RESTORE; } else { /* Now copy to correct location */ mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /"); mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); newtPopWindow(); allok_fastexit=1; /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ upgrade_v12_v13(); upgrade_v130_v140(); break; /* out of loop at this point because floppy has successfully restored */ } } else { /* success */ /* Now copy to correct location */ mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /"); mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); newtPopWindow(); allok_fastexit=1; /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ upgrade_v12_v13(); upgrade_v130_v140(); break; /* out of loop at this point because floppy has successfully restored */ } } else{ /* user chose to skip install from floppy */ if (installtype == CDROM_INSTALL){ /* if we installed from CD ROM then we didn't set up the network interface yet. Therefore, set up Network driver and params just before we need them. */ if (!(networkmenu(ethernetkv))){ /* network setup failed, tell the world */ errorbox(ctr[TR_NETWORK_SETUP_FAILED]); goto EXIT; } } break; /* out of loop because we succeeded with ethernet set up and user is notrestarting from floppy*/ } } /* Check the SQUID acl file exists, if not use our 1.4 copy */ { FILE *aclreadfile; if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) { rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4", "/harddisk" CONFIG_ROOT "/proxy/acl"); } else { unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4"); fclose(aclreadfile); } chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99); } /* Build cache lang file */ mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); if (!allok_fastexit){ /* write ethernet and lang configs only if they have not been restored from floppy already. */ if (!(write_ethernet_configs( ethernetkv))|| !(write_lang_configs(shortlangname))){ errorbox(ctr[TR_ERROR_WRITING_CONFIG]); goto EXIT; } } /* if we detected SCSI then fixup */ if ((handle = fopen("/scsidriver", "r"))) { char *driver; fgets(line, STRING_SIZE-1, handle); fclose(handle); line[strlen(line) - 1] = 0; driver = strtok(line, "."); fprintf(flog, "Detected SCSI driver %s\n",driver); if (strlen(driver) > 1) { fprintf(flog, "Fixing up ipcoprd.img\n"); mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipcoprd.img %s", driver, KERNEL_VERSION); runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);#ifdef __i386__ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipcoprd-smp.img %s-smp", driver, KERNEL_VERSION); runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");#endif#ifdef __alpha__ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf"); runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);#endif } }#if 0 /* not yet */ if (pcmcia_disk) { fprintf(flog, "Detected SCSI driver PCMCIA\n"); fprintf(flog, "Fixing up ipcoprd.img\n"); mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipcoprd.img", KERNEL_VERSION); mysystem(commandstring);#ifdef __i386__ mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");#endif#ifdef __alpha__ mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");#endif }#endif#ifdef __i386__ replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode); /* restore permissions */ chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); if (raid_disk) sprintf(string, "root=%sp4", hdparams.devnode); else sprintf(string, "root=%s4", hdparams.devnode); replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string); mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc"); snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /boot/grub/grubbatch"); if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); goto EXIT; } mysystem("/bin/chroot /harddisk /bin/umount -n /proc");#endif#ifdef __alpha__ snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams.devnode); mysystem(commandstring); snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams.devnode); mysystem(commandstring); if (raid_disk) sprintf(string, "root=%sp4", hdparams.devnode); else sprintf(string, "root=%s4", hdparams.devnode); replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string);#endif /* unmounting happens everywhere because there are places which require device is to be unmounted under certain circumstances. This is the last place we can unmount anything and still succeed. */ if (!unmount_before && installtype == CDROM_INSTALL){ if (mysystem("/sbin/umount /cdrom")) { errorbox(ctr[TR_UNABLE_TO_UNMOUNT_CDROM]); goto EXIT; } } if (installtype == CDROM_INSTALL) { if (!(ejectcdrom(cdromparams.devnode))) { errorbox(ctr[TR_UNABLE_TO_EJECT_CDROM]); // goto EXIT; } } sprintf(message, ctr[TR_CONGRATULATIONS_LONG], NAME, SNAME, SNAME, NAME, NAME, NAME); newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message); allok = 1; EXIT: fprintf(flog, "Install program ended.\n"); fflush(flog); fclose(flog); if (!(allok)) newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); newtFinished(); freekeyvalues(ethernetkv); if (allok && !allok_fastexit) { /* /proc is needed by the module checker. We have to mount it * so it can be seen by setup, which is run chrooted. */ if (system("/sbin/mount proc -t proc /harddisk/proc")) printf("Unable to mount proc in /harddisk."); else { if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) printf("Unable to run setup.\n"); if (system("/sbin/umount /harddisk/proc")) printf("Unable to umount /harddisk/proc.\n"); } } fcloseall(); system("/bin/swapoff /harddisk/swapfile"); system("/sbin/umount /harddisk/var/log"); system("/sbin/umount /harddisk/boot"); system("/sbin/umount /harddisk"); system("/etc/halt"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -