From 3d6e1202853dbb798d6a63fab878d7c09a1f650e Mon Sep 17 00:00:00 2001 From: ms Date: Wed, 8 Nov 2006 22:30:51 +0000 Subject: [PATCH] Bootvorgang des Installers weitergebracht. git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@343 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8 --- config/install/fstab | 3 + config/install/halt | 23 +- config/install/inittab | 1 + config/install/rc | 35 +- config/install/udev/rules.d/25-lfs.rules | 141 +++++ config/install/udev/rules.d/50-udev.rules | 47 ++ config/install/udev/udev.conf | 3 + src/install+setup/install/ide.c | 2 - src/install+setup/install/main.c | 48 +- src/install+setup/install/usb.c | 21 +- src/install+setup/libsmooth/main.c | 654 +++++++++++----------- 11 files changed, 577 insertions(+), 401 deletions(-) create mode 100644 config/install/udev/rules.d/25-lfs.rules create mode 100644 config/install/udev/rules.d/50-udev.rules create mode 100644 config/install/udev/udev.conf diff --git a/config/install/fstab b/config/install/fstab index 7399c0c1f5..ea05c008c2 100644 --- a/config/install/fstab +++ b/config/install/fstab @@ -1,3 +1,6 @@ /dev/ram0 / ext2 /dev/fd0 / ext2 /proc /proc proc +none /sys sysfs +none /tmp tmpfs +none /dev tmpfs diff --git a/config/install/halt b/config/install/halt index 22a170e9ec..ecfe93c974 100644 --- a/config/install/halt +++ b/config/install/halt @@ -1,19 +1,18 @@ #!/bin/sh echo "Shutting down..." echo "Sending all processes the TERM signal..." -/sbin/killall5 -15 +/bin/killall5 -15 sleep 3 echo "Sending all processes the KILL signal..." -/sbin/killall5 -9 +/bin/killall5 -9 sleep 3 -echo "Unmounting /cdrom, /harddisk/boot, /harddisk/var/log and /harddisk" -/sbin/umount /cdrom -/sbin/umount /harddisk/boot -/sbin/umount /harddisk/var/log -/sbin/umount /harddisk -echo "Unmounting /proc" -/sbin/umount /proc/bus/usb -/sbin/umount /proc +echo "Unmounting filesystems" +/bin/umount /tmp +/bin/umount /sys +/bin/umount /dev/pts +/bin/umount /dev +/bin/umount /root +/bin/umount /proc echo "Unmounting root" -/sbin/mount -n -o remount,ro / -/sbin/reboot -i -d -p +/bin/mount -n -o remount,ro / +/bin/reboot diff --git a/config/install/inittab b/config/install/inittab index 5eb074c8a6..af94321c4f 100644 --- a/config/install/inittab +++ b/config/install/inittab @@ -3,6 +3,7 @@ # Run gettys in standard runlevels tty1::respawn:/bin/iowrap /dev/tty1 /bin/ash --login -c "/bin/install /dev/tty2" +tty2::respawn:/bin/iowrap /dev/tty2 /bin/ash --login tty3::respawn:/bin/iowrap /dev/tty3 /bin/ash --login # Stuff to do before rebooting diff --git a/config/install/rc b/config/install/rc index 20dcdff76c..ae0a00b0e8 100644 --- a/config/install/rc +++ b/config/install/rc @@ -1,12 +1,39 @@ #!/bin/ash -echo "Mounting proc" -mount /proc -echo "Starting syslogd" -syslogd -L -O /dev/tty2 +echo "Mounting /tmp" +mount -n -t tmpfs tmpfs /tmp -o mode=1777 + +echo "Mounting /proc" +mount -n -t proc none /proc + +echo "Mounting /sys" +mount -n -t sysfs sysfs /sys echo "Silencing kernel" echo >/proc/sys/kernel/printk "1 4 1 7" echo "Disabling screen blanking" echo -n -e "\033[9;0]" + +echo "Mounting /dev" +mount -n -t tmpfs tmpfs /dev -o mode=755 + +ln -snf /proc/self/fd /dev/fd +ln -snf /proc/self/fd/0 /dev/stdin +ln -snf /proc/self/fd/1 /dev/stdout +ln -snf /proc/self/fd/2 /dev/stderr +ln -s /proc/kcore /dev/core +mkdir -p -m 0755 /dev/pts +mkdir -p -m 0755 /dev/shm + +echo "Mounting /dev/pts" +mount -n -t devpts devpts /dev/pts + +echo "Mounting /root" +mount -n -t ramfs none /root + +echo "Starting syslogd" +syslogd -O /dev/tty4 + +echo "Starting udev" +/sbin/udevstart diff --git a/config/install/udev/rules.d/25-lfs.rules b/config/install/udev/rules.d/25-lfs.rules new file mode 100644 index 0000000000..7c45be1370 --- /dev/null +++ b/config/install/udev/rules.d/25-lfs.rules @@ -0,0 +1,141 @@ +# /etc/udev/rules.d/25-lfs.rules: Rule definitions for LFS. + +# Create the /dev/cdrom symlink. + +BUS="ide", KERNEL="*[!0-9]", PROGRAM="/bin/cat /proc/ide/%k/media", RESULT="cdrom", NAME="%k", SYMLINK="cdrom" + +# Core kernel devices + +KERNEL="ptmx", GROUP="tty", MODE="0666" +KERNEL="random", MODE="0444" +KERNEL="urandom", MODE="0444" +KERNEL="kmem", GROUP="kmem", MODE="0640" +KERNEL="mem", GROUP="kmem", MODE="0640" +KERNEL="port", GROUP="kmem", MODE="0640" +KERNEL="null", MODE="0666" +KERNEL="zero", MODE="0666" +KERNEL="full", MODE="0666" +KERNEL="aio", MODE="0444" +KERNEL="kmsg", MODE="0600" +KERNEL="rtc", MODE="0666" + +# Comms devices + +KERNEL="ttyS[0-9]*", GROUP="dialout" +KERNEL="ttyUSB[0-9]*", GROUP="dialout" +KERNEL="rfcomm[0-9]*", GROUP="dialout" +KERNEL="tty[BCDEFHILMPRSTUVWX][0-9]*", GROUP="dialout" +KERNEL="ttyS[ACIR][0-9]*", GROUP="dialout" +KERNEL="ttyUSB[0-9]*", GROUP="dialout" +KERNEL="ttyACM[0-9]*", GROUP="dialout" +KERNEL="ippp[0-9]*", GROUP="dialout" +KERNEL="isdn[0-9]*", GROUP="dialout" +KERNEL="isdnctrl[0-9]*", GROUP="dialout" +KERNEL="capi", NAME="capi20", SYMLINK="isdn/capi20" +KERNEL="capi*", NAME="capi/%n", GROUP="dialout" +KERNEL="dcbri[0-9]*", GROUP="dialout" +KERNEL="ircomm[0-9]*", GROUP="dialout" + +# TTY's + +KERNEL="tty", GROUP="tty", MODE="0666" +KERNEL="tty[0-9]*", GROUP="tty", MODE="0666" +KERNEL="vcs*", MODE="0600" +KERNEL="console", GROUP="tty", MODE="0622" + +# ALSA devices go in their own subdirectory + +KERNEL="controlC[0-9]*", NAME="snd/%k", GROUP="audio" +KERNEL="hw[CD0-9]*", NAME="snd/%k", GROUP="audio" +KERNEL="pcm[CD0-9cp]*", NAME="snd/%k", GROUP="audio" +KERNEL="midiC[D0-9]*", NAME="snd/%k", GROUP="audio" +KERNEL="timer", NAME="snd/%k", GROUP="audio" +KERNEL="seq", NAME="snd/%k", GROUP="audio" + +# Sound devices + +KERNEL="admmidi*", GROUP="audio" +KERNEL="adsp*", GROUP="audio" +KERNEL="aload*", GROUP="audio" +KERNEL="amidi*", GROUP="audio" +KERNEL="amixer*", GROUP="audio" +KERNEL="audio*", GROUP="audio" +KERNEL="dmfm*", GROUP="audio" +KERNEL="dmmidi*", GROUP="audio" +KERNEL="dsp*", GROUP="audio" +KERNEL="midi*", GROUP="audio" +KERNEL="mixer*", GROUP="audio" +KERNEL="music", GROUP="audio" +KERNEL="sequencer*", GROUP="audio" + +# Printing devices + +KERNEL="lp[0-9]*", GROUP="lp" +KERNEL="parport[0-9]*", GROUP="lp" +KERNEL="irlpt[0-9]*", GROUP="lp" + +# Input devices go in their own subdirectory + +KERNEL="mice", NAME="input/%k", MODE="0644" +KERNEL="mouse*", NAME="input/%k", MODE="0644", SYMLINK="mouse" +KERNEL="event*", NAME="input/%k", MODE="0644" +KERNEL="js*", NAME="input/%k", MODE="0644" +KERNEL="ts*", NAME="input/%k", MODE="0644" + +KERNEL="psaux", MODE="0644" +KERNEL="js", MODE="0644" +KERNEL="djs", MODE="0644" + +# USB devices go in their own subdirectory + +KERNEL="hiddev*", NAME="usb/%k" +KERNEL="auer*", NAME="usb/%k" +KERNEL="legousbtower*", NAME="usb/%k" +KERNEL="dabusb*", NAME="usb/%k" +BUS="usb", KERNEL="lp[0-9]*", NAME="usb/%k", GROUP="lp" + +# DRI devices go in their own subdirectory for FHS compliance + +KERNEL="card*", NAME="dri/card%n", GROUP="video" + +# Video devices + +KERNEL="fb[0-9]*", GROUP="video", MODE="0620" +KERNEL="agpgart", GROUP="video" +KERNEL="nvidia[0-9]*", GROUP="video" +KERNEL="nvidiactl", GROUP="video" +KERNEL="video[0-9]*", GROUP="video" +KERNEL="radio[0-9]*", GROUP="video" +KERNEL="vbi[0-9]*", GROUP="video" +KERNEL="vtx[0-9]*", GROUP="video" + +# Storage/memory devices + +KERNEL="fd[0-9]*", GROUP="disk" SYMLINK="floppy" +KERNEL="ram[0-9]*", GROUP="disk" +KERNEL="raw[0-9]*", NAME="raw/%k", GROUP="disk" +KERNEL="hd*", GROUP="disk" +KERNEL="sd[a-z]", GROUP="disk" +KERNEL="sd[a-z][0-9]*", GROUP="disk" +KERNEL="sd[a-i][a-z]", GROUP="disk" +KERNEL="sd[a-i][a-z][0-9]*", GROUP="disk" +KERNEL="sr[0-9]*", GROUP="burning" MODE="0664" +KERNEL="s[gt][0-9]*", GROUP="disk" +KERNEL="scd[0-9]*", GROUP="cdrom" +KERNEL="dasd[0-9]*", GROUP="disk" +KERNEL="ataraid[0-9]*", GROUP="disk" +KERNEL="loop[0-9]*", GROUP="disk" +KERNEL="md[0-9]*", GROUP="disk" +KERNEL="dm-*", GROUP="disk", MODE="0640" +KERNEL="ht[0-9]*", GROUP="tape" +KERNEL="nht[0-9]*", GROUP="tape" +KERNEL="pt[0-9]*", GROUP="tape" +KERNEL="npt[0-9]*", GROUP="tape" +KERNEL="st[0-9]*", GROUP="tape" +KERNEL="nst[0-9]*", GROUP="tape" +KERNEL="iseries/vcd*", GROUP="disk" +KERNEL="iseries/vd*", GROUP="disk" + +# Network devices + +KERNEL="tun", NAME="net/%k" diff --git a/config/install/udev/rules.d/50-udev.rules b/config/install/udev/rules.d/50-udev.rules new file mode 100644 index 0000000000..bc8c8bdd6c --- /dev/null +++ b/config/install/udev/rules.d/50-udev.rules @@ -0,0 +1,47 @@ +# There are a number of modifiers that are allowed to be used in some of the +# fields. See the udev man page for a full description of them. +# +# See the udev.rules.examples file for more examples of how to create rules +# + +# if this is a ide cdrom, name it the default name, and create a symlink to cdrom +BUS="ide", KERNEL="*[!0-9]", PROGRAM="/bin/cat /proc/ide/%k/media", RESULT="cdrom", NAME="%k", SYMLINK="cdrom" + +# create a symlink named after the device map name +# note devmap_name comes with extras/multipath +KERNEL="dm-[0-9]*", PROGRAM="/sbin/devmap_name %M %m", NAME="%k", SYMLINK="%c" + +# DRI devices always go into a subdirectory (as per the LSB spec) +KERNEL="card*", NAME="dri/card%n" + +# alsa devices +KERNEL="controlC[0-9]*", NAME="snd/%k" +KERNEL="hw[CD0-9]*", NAME="snd/%k" +KERNEL="pcm[CD0-9cp]*", NAME="snd/%k" +KERNEL="midiC[D0-9]*", NAME="snd/%k" +KERNEL="timer", NAME="snd/%k" +KERNEL="seq", NAME="snd/%k" + +# input devices +KERNEL="mice", NAME="input/%k" +KERNEL="mouse*", NAME="input/%k" +KERNEL="event*", NAME="input/%k" +KERNEL="js*", NAME="input/%k" +KERNEL="ts*", NAME="input/%k" + +# USB devices +KERNEL="hiddev*", NAME="usb/%k" +KERNEL="auer*", NAME="usb/%k" +KERNEL="legousbtower*", NAME="usb/%k" +KERNEL="dabusb*", NAME="usb/%k" +BUS="usb", KERNEL="lp[0-9]*", NAME="usb/%k" + +# CAPI devices +KERNEL="capi", NAME="capi20", SYMLINK="isdn/capi20" +KERNEL="capi*", NAME="capi/%n" + +# Network devices +KERNEL="tun", NAME="net/%k" + +# raw devices +KERNEL="raw[0-9]*", NAME="raw/%k" diff --git a/config/install/udev/udev.conf b/config/install/udev/udev.conf new file mode 100644 index 0000000000..c986894c82 --- /dev/null +++ b/config/install/udev/udev.conf @@ -0,0 +1,3 @@ +udev_root="/dev" +udev_db="/dev/.udevdb" +udev_rules="/etc/udev/rules.d/" diff --git a/src/install+setup/install/ide.c b/src/install+setup/install/ide.c index dfde3a983f..f995438b02 100644 --- a/src/install+setup/install/ide.c +++ b/src/install+setup/install/ide.c @@ -7,8 +7,6 @@ * Contains some functs for scanning /proc for ide info on CDROMS and * harddisks. * - * $Id: ide.c,v 1.4 2003/12/11 11:25:53 riddles Exp $ - * */ #include "install.h" diff --git a/src/install+setup/install/main.c b/src/install+setup/install/main.c index dcf47926c2..fa0b849e55 100644 --- a/src/install+setup/install/main.c +++ b/src/install+setup/install/main.c @@ -6,8 +6,6 @@ * (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" @@ -24,26 +22,8 @@ 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[]) { @@ -51,10 +31,6 @@ int main(int argc, char *argv[]) char *langnames[] = { "English", NULL }; char *shortlangnames[] = { "en", NULL }; char **langtrs[] = { en_tr, NULL }; -#elifdef LANG_ALL - 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 }; #else char *langnames[] = { "Deutsch", "English", NULL }; char *shortlangnames[] = { "de", "en", NULL }; @@ -162,29 +138,13 @@ int main(int argc, char *argv[]) /* 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); + "Select the language you wish to use for your " 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"); + + mysystem("/bin/setfont lat0-16"); newtDrawRootText(14, 0, NAME " v" VERSION " - " SLOGAN ); newtPushHelpLine(ctr[TR_HELPLINE]); diff --git a/src/install+setup/install/usb.c b/src/install+setup/install/usb.c index ce6f01118b..444309e9ab 100644 --- a/src/install+setup/install/usb.c +++ b/src/install+setup/install/usb.c @@ -17,8 +17,6 @@ * * Copyright 2002: Mark Wormgoor * - * $Id: usb.c,v 1.9.2.3 2004/11/16 22:48:43 alanh Exp $ - * */ #include "install.h" @@ -37,23 +35,22 @@ int initialize_usb() { ehcihcd = 0; } if (usbohci) { - mysystem("/sbin/rmmod usb-ohci"); + mysystem("/sbin/rmmod ohci-hcd"); usbohci = 0; } if (usbuhci) { - mysystem("/sbin/rmmod usb-uhci"); + mysystem("/sbin/rmmod uhci-hcd"); usbuhci = 0; } if (mysystem("/sbin/modprobe ehci-hcd") == 0) ehcihcd = 1; - if (mysystem("/sbin/modprobe usb-ohci") == 0) + if (mysystem("/sbin/modprobe ohci-hcd") == 0) usbohci = 1; - if (mysystem("/sbin/modprobe usb-uhci") == 0) + if (mysystem("/sbin/modprobe uhci-hcd") == 0) usbuhci = 1; - mysystem("/sbin/modprobe hid"); - mysystem("/sbin/modprobe keybdev"); + mysystem("/sbin/modprobe usbhid"); return 0; } @@ -79,17 +76,17 @@ int write_usb_modules_conf() { if (usbohci) { if (index) - fprintf(handle,"alias usb-controller%d usb-ohci\n",index); + fprintf(handle,"alias usb-controller%d ohci-hcd\n",index); else - fprintf(handle,"alias usb-controller usb-ohci\n"); + fprintf(handle,"alias usb-controller ohci-hcd\n"); index++; } if (usbuhci) { if (index) - fprintf(handle,"alias usb-controller%d usb-uhci\n",index); + fprintf(handle,"alias usb-controller%d uhci-hcd\n",index); else - fprintf(handle,"alias usb-controller usb-uhci\n"); + fprintf(handle,"alias usb-controller uhci-hcd\n"); index++; } fclose(handle); diff --git a/src/install+setup/libsmooth/main.c b/src/install+setup/libsmooth/main.c index e2d6d70a5d..d54a89c60e 100644 --- a/src/install+setup/libsmooth/main.c +++ b/src/install+setup/libsmooth/main.c @@ -1,327 +1,327 @@ -/* SmoothWall libsmooth. - * - * This program is distributed under the terms of the GNU General Public - * Licence. See the file COPYING for details. - * - * (c) Lawrence Manning, 2001 - * Contains library functions. - * - * $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $ - * - */ - -#include "libsmooth.h" - -extern FILE *flog; -extern char *mylog; - -extern char **ctr; - -/* reboot(). reboots. */ -void reboot(void) -{ - mysystem("/etc/halt"); -} - -/* stripnl(). Replaces \n with \0 */ -void stripnl(char *s) -{ - char *t = strchr(s, '\n'); - if (t) *t = '\0'; -} - -/* Little wrapper. */ -int mysystem(char *command) -{ - char mycommand[STRING_SIZE]; - - snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog); - fprintf(flog, "Running command: %s\n", command); - return system(mycommand); -} - -void errorbox(char *message) -{ - newtWinMessage(ctr[TR_ERROR], ctr[TR_OK], message); -} - -void statuswindow(int width, int height, char *title, char *text, ...) -{ - newtComponent t, f; - char *buf = NULL; - int size = 0; - int i = 0; - va_list args; - - va_start(args, text); - - do { - size += 1000; - if (buf) free(buf); - buf = malloc(size); - i = vsnprintf(buf, size, text, args); - } while (i == size); - - va_end(args); - - newtCenteredWindow(width, height, title); - - t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP); - newtTextboxSetText(t, buf); - f = newtForm(NULL, NULL, 0); - - free(buf); - - newtFormAddComponent(f, t); - - newtDrawForm(f); - newtRefresh(); - newtFormDestroy(f); -} - -int runcommandwithstatus(char *command, char *message) -{ - int rc; - char title[STRING_SIZE]; - - sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); - statuswindow(60, 4, title, message); - rc = mysystem(command); - newtPopWindow(); - - return rc; -} - -int runhiddencommandwithstatus(char *command, char *message) -{ - int rc; - char title[STRING_SIZE]; - char mycommand[STRING_SIZE]; - - sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); - statuswindow(60, 4, title, message); - snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog); - fprintf(flog, "Running command: ***** HIDDEN *****\n"); - rc = system(mycommand); - newtPopWindow(); - - return rc; -} - -/* This one borrowed from redhat installer. */ -int runcommandwithprogress(int width, int height, char *title, char *command, - int lines, char *text, ...) -{ - newtComponent t, f, s; - char *buf = NULL; - int size = 0; - int i = 0; - va_list args; - int rc = 0; - FILE *p; - char buffer[STRING_SIZE]; - int progress = 0; - char mycommand[STRING_SIZE]; - - va_start(args, text); - - do { - size += 1000; - if (buf) free(buf); - buf = malloc(size); - i = vsnprintf(buf, size, text, args); - } while (i == size); - - va_end(args); - - newtCenteredWindow(width, height, title); - - t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP); - newtTextboxSetText(t, buf); - f = newtForm(NULL, NULL, 0); - - free(buf); - - newtFormAddComponent(f, t); - - s = newtScale(1, 3, width - 2, lines); - newtScaleSet(s, progress); - - newtFormAddComponent(f, s); - - newtDrawForm(f); - newtRefresh(); - - snprintf(mycommand, STRING_SIZE, "%s 2>>%s", command, mylog); - fprintf(flog, "Running command: %s\n", command); - - if (!(p = popen(command, "r"))) - { - rc = 1; - goto EXIT; - } - setvbuf(p, NULL, _IOLBF, 255); - - while (fgets(buffer, STRING_SIZE, p)) - { - newtScaleSet(s, ++progress); - newtRefresh(); - fprintf(flog, "%s", buffer); - } - - rc = pclose(p); - -EXIT: - newtFormDestroy(f); - newtPopWindow(); - - return rc; -} - -int checkformodule(char *module) -{ - FILE *file; - char buffer[STRING_SIZE]; - int result = 0; - - if (!(file = fopen("/proc/modules", "r"))) - { - fprintf(flog, "Unable to open /proc/modules in checkformodule()\n"); - return 0; - } - - while (fgets(buffer, STRING_SIZE, file)) - { - if (strncmp(buffer, module, strlen(module)) == 0) - { - if (buffer[strlen(module)] == ' ') - { - result = 1; - goto EXIT; - } - } - } - -EXIT: - fclose(file); - - return result; -} - -int _replace_string(char string[], char *from, char *to) -{ - int fromlen = strlen(from); - int tolen = strlen(to); - char *start, *p1, *p2; - for(start = string; *start != '\0'; start++) - { - p1 = from; - p2 = start; - while(*p1 != '\0') - { - if(*p1 != *p2) - break; - p1++; - p2++; - } - if(*p1 == '\0') - { - if(fromlen != tolen) - { - memmove(start + tolen, start + fromlen, - strlen(start + fromlen) + 1); - } - for(p1 = to; *p1 != '\0'; p1++) - *start++ = *p1; - return 1; - } - } - return 0; -} - -int replace(char filename1[], char *from, char *to) -{ - FILE *file1, *file2; - char filename2[1000]; - char temp[1000]; - int ret = 0; - - /* Open the source and destination files */ - strcpy (filename2, filename1); - strcat (filename2, ".new"); - if (!(file1 = fopen (filename1, "r"))) return 1; - if (!(file2 = fopen (filename2, "w"))) { - fclose(file1); - return -1; - } - - /* Start reading in lines */ - while (fgets (temp, 1000, file1) != NULL) { - - if (strlen(to) > 0) { - /* Replace string */ - ret = _replace_string (temp, from, to); - - /* Write string to new file */ - fputs(temp, file2); - } else { - /* Remove string when to is NULL */ - if (!strstr(temp, from)) - fputs(temp, file2); - } - } - - /* Close source and destination */ - fclose (file1); - fclose (file2); - - /* Move the file */ - rename (filename2, filename1); - - return (ret); -} - -/* Include enabled languages */ -#ifdef LANG_EN_ONLY - #include "lang_en.c" -#elifdef LANG_ALL - #include "lang_bz.c" - #include "lang_cs.c" - #include "lang_da.c" - #include "lang_de.c" - #include "lang_en.c" - #include "lang_es.c" - #include "lang_fi.c" - #include "lang_fr.c" - #include "lang_el.c" - #include "lang_it.c" - #include "lang_hu.c" - #include "lang_la.c" - #include "lang_nl.c" - #include "lang_no.c" - #include "lang_pl.c" - #include "lang_pt.c" - #include "lang_sk.c" - #include "lang_so.c" - #include "lang_sv.c" - #include "lang_tr.c" - #include "lang_vi.c" -#else - #include "lang_de.c" - #include "lang_en.c" - -#endif -// returns a pointer to the actual running version number of IPCop. -// Successive updates increase effective version but not VERSION ! -char g_title[STRING_SIZE] = ""; -char* get_version(void) { - FILE *f_title; - if ((f_title = fopen ("/etc/issue", "r"))) { - fgets (g_title, STRING_SIZE, f_title); - fclose (f_title); - if (g_title[strlen(g_title) - 1] == '\n') g_title[strlen(g_title) - 1] = '\0'; - } else { - sprintf (g_title, "%s v%s - %s", NAME, VERSION, SLOGAN); - } - return g_title; -} +/* SmoothWall libsmooth. + * + * This program is distributed under the terms of the GNU General Public + * Licence. See the file COPYING for details. + * + * (c) Lawrence Manning, 2001 + * Contains library functions. + * + * $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $ + * + */ + +#include "libsmooth.h" + +extern FILE *flog; +extern char *mylog; + +extern char **ctr; + +/* reboot(). reboots. */ +void reboot(void) +{ + mysystem("/etc/halt"); +} + +/* stripnl(). Replaces \n with \0 */ +void stripnl(char *s) +{ + char *t = strchr(s, '\n'); + if (t) *t = '\0'; +} + +/* Little wrapper. */ +int mysystem(char *command) +{ + char mycommand[STRING_SIZE]; + + snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog); + fprintf(flog, "Running command: %s\n", command); + return system(mycommand); +} + +void errorbox(char *message) +{ + newtWinMessage(ctr[TR_ERROR], ctr[TR_OK], message); +} + +void statuswindow(int width, int height, char *title, char *text, ...) +{ + newtComponent t, f; + char *buf = NULL; + int size = 0; + int i = 0; + va_list args; + + va_start(args, text); + + do { + size += 1000; + if (buf) free(buf); + buf = malloc(size); + i = vsnprintf(buf, size, text, args); + } while (i == size); + + va_end(args); + + newtCenteredWindow(width, height, title); + + t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP); + newtTextboxSetText(t, buf); + f = newtForm(NULL, NULL, 0); + + free(buf); + + newtFormAddComponent(f, t); + + newtDrawForm(f); + newtRefresh(); + newtFormDestroy(f); +} + +int runcommandwithstatus(char *command, char *message) +{ + int rc; + char title[STRING_SIZE]; + + sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); + statuswindow(60, 4, title, message); + rc = mysystem(command); + newtPopWindow(); + + return rc; +} + +int runhiddencommandwithstatus(char *command, char *message) +{ + int rc; + char title[STRING_SIZE]; + char mycommand[STRING_SIZE]; + + sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); + statuswindow(60, 4, title, message); + snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog); + fprintf(flog, "Running command: ***** HIDDEN *****\n"); + rc = system(mycommand); + newtPopWindow(); + + return rc; +} + +/* This one borrowed from redhat installer. */ +int runcommandwithprogress(int width, int height, char *title, char *command, + int lines, char *text, ...) +{ + newtComponent t, f, s; + char *buf = NULL; + int size = 0; + int i = 0; + va_list args; + int rc = 0; + FILE *p; + char buffer[STRING_SIZE]; + int progress = 0; + char mycommand[STRING_SIZE]; + + va_start(args, text); + + do { + size += 1000; + if (buf) free(buf); + buf = malloc(size); + i = vsnprintf(buf, size, text, args); + } while (i == size); + + va_end(args); + + newtCenteredWindow(width, height, title); + + t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP); + newtTextboxSetText(t, buf); + f = newtForm(NULL, NULL, 0); + + free(buf); + + newtFormAddComponent(f, t); + + s = newtScale(1, 3, width - 2, lines); + newtScaleSet(s, progress); + + newtFormAddComponent(f, s); + + newtDrawForm(f); + newtRefresh(); + + snprintf(mycommand, STRING_SIZE, "%s 2>>%s", command, mylog); + fprintf(flog, "Running command: %s\n", command); + + if (!(p = popen(command, "r"))) + { + rc = 1; + goto EXIT; + } + setvbuf(p, NULL, _IOLBF, 255); + + while (fgets(buffer, STRING_SIZE, p)) + { + newtScaleSet(s, ++progress); + newtRefresh(); + fprintf(flog, "%s", buffer); + } + + rc = pclose(p); + +EXIT: + newtFormDestroy(f); + newtPopWindow(); + + return rc; +} + +int checkformodule(char *module) +{ + FILE *file; + char buffer[STRING_SIZE]; + int result = 0; + + if (!(file = fopen("/proc/modules", "r"))) + { + fprintf(flog, "Unable to open /proc/modules in checkformodule()\n"); + return 0; + } + + while (fgets(buffer, STRING_SIZE, file)) + { + if (strncmp(buffer, module, strlen(module)) == 0) + { + if (buffer[strlen(module)] == ' ') + { + result = 1; + goto EXIT; + } + } + } + +EXIT: + fclose(file); + + return result; +} + +int _replace_string(char string[], char *from, char *to) +{ + int fromlen = strlen(from); + int tolen = strlen(to); + char *start, *p1, *p2; + for(start = string; *start != '\0'; start++) + { + p1 = from; + p2 = start; + while(*p1 != '\0') + { + if(*p1 != *p2) + break; + p1++; + p2++; + } + if(*p1 == '\0') + { + if(fromlen != tolen) + { + memmove(start + tolen, start + fromlen, + strlen(start + fromlen) + 1); + } + for(p1 = to; *p1 != '\0'; p1++) + *start++ = *p1; + return 1; + } + } + return 0; +} + +int replace(char filename1[], char *from, char *to) +{ + FILE *file1, *file2; + char filename2[1000]; + char temp[1000]; + int ret = 0; + + /* Open the source and destination files */ + strcpy (filename2, filename1); + strcat (filename2, ".new"); + if (!(file1 = fopen (filename1, "r"))) return 1; + if (!(file2 = fopen (filename2, "w"))) { + fclose(file1); + return -1; + } + + /* Start reading in lines */ + while (fgets (temp, 1000, file1) != NULL) { + + if (strlen(to) > 0) { + /* Replace string */ + ret = _replace_string (temp, from, to); + + /* Write string to new file */ + fputs(temp, file2); + } else { + /* Remove string when to is NULL */ + if (!strstr(temp, from)) + fputs(temp, file2); + } + } + + /* Close source and destination */ + fclose (file1); + fclose (file2); + + /* Move the file */ + rename (filename2, filename1); + + return (ret); +} + +/* Include enabled languages */ +#ifdef LANG_EN_ONLY + #include "lang_en.c" +#elifdef LANG_ALL + #include "lang_bz.c" + #include "lang_cs.c" + #include "lang_da.c" + #include "lang_de.c" + #include "lang_en.c" + #include "lang_es.c" + #include "lang_fi.c" + #include "lang_fr.c" + #include "lang_el.c" + #include "lang_it.c" + #include "lang_hu.c" + #include "lang_la.c" + #include "lang_nl.c" + #include "lang_no.c" + #include "lang_pl.c" + #include "lang_pt.c" + #include "lang_sk.c" + #include "lang_so.c" + #include "lang_sv.c" + #include "lang_tr.c" + #include "lang_vi.c" +#else + #include "lang_de.c" + #include "lang_en.c" + +#endif +// returns a pointer to the actual running version number of IPFire. +// Successive updates increase effective version but not VERSION ! +char g_title[STRING_SIZE] = ""; +char* get_version(void) { + FILE *f_title; + if ((f_title = fopen ("/etc/issue", "r"))) { + fgets (g_title, STRING_SIZE, f_title); + fclose (f_title); + if (g_title[strlen(g_title) - 1] == '\n') g_title[strlen(g_title) - 1] = '\0'; + } else { + sprintf (g_title, "%s v%s - %s", NAME, VERSION, SLOGAN); + } + return g_title; +} -- 2.39.2