]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/install+setup/libsmooth/main.c
1 /* SmoothWall libsmooth.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Contains library functions.
9 * $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $
13 #include "libsmooth.h"
20 /* reboot(). reboots. */
23 mysystem("/etc/halt");
26 /* stripnl(). Replaces \n with \0 */
29 char *t
= strchr(s
, '\n');
34 int mysystem(char *command
)
36 char mycommand
[STRING_SIZE
];
38 snprintf(mycommand
, STRING_SIZE
, "%s >>%s 2>>%s", command
, mylog
, mylog
);
39 fprintf(flog
, "Running command: %s\n", command
);
40 return system(mycommand
);
43 void errorbox(char *message
)
45 newtWinMessage(ctr
[TR_ERROR
], ctr
[TR_OK
], message
);
48 void statuswindow(int width
, int height
, char *title
, char *text
, ...)
62 i
= vsnprintf(buf
, size
, text
, args
);
67 newtCenteredWindow(width
, height
, title
);
69 t
= newtTextbox(1, 1, width
- 2, height
- 2, NEWT_TEXTBOX_WRAP
);
70 newtTextboxSetText(t
, buf
);
71 f
= newtForm(NULL
, NULL
, 0);
75 newtFormAddComponent(f
, t
);
82 int runcommandwithstatus(char *command
, char *message
)
85 char title
[STRING_SIZE
];
87 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
88 statuswindow(60, 4, title
, message
);
89 rc
= mysystem(command
);
95 int runhiddencommandwithstatus(char *command
, char *message
)
98 char title
[STRING_SIZE
];
99 char mycommand
[STRING_SIZE
];
101 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
102 statuswindow(60, 4, title
, message
);
103 snprintf(mycommand
, STRING_SIZE
, "%s >>%s 2>>%s", command
, mylog
, mylog
);
104 fprintf(flog
, "Running command: ***** HIDDEN *****\n");
105 rc
= system(mycommand
);
111 /* This one borrowed from redhat installer. */
112 int runcommandwithprogress(int width
, int height
, char *title
, char *command
,
113 int lines
, char *text
, ...)
115 newtComponent t
, f
, s
;
122 char buffer
[STRING_SIZE
];
124 char mycommand
[STRING_SIZE
];
126 va_start(args
, text
);
132 i
= vsnprintf(buf
, size
, text
, args
);
137 newtCenteredWindow(width
, height
, title
);
139 t
= newtTextbox(1, 1, width
- 2, height
- 2, NEWT_TEXTBOX_WRAP
);
140 newtTextboxSetText(t
, buf
);
141 f
= newtForm(NULL
, NULL
, 0);
145 newtFormAddComponent(f
, t
);
147 s
= newtScale(1, 3, width
- 2, lines
);
148 newtScaleSet(s
, progress
);
150 newtFormAddComponent(f
, s
);
155 snprintf(mycommand
, STRING_SIZE
, "%s 2>>%s", command
, mylog
);
156 fprintf(flog
, "Running command: %s\n", command
);
158 if (!(p
= popen(command
, "r")))
163 setvbuf(p
, NULL
, _IOLBF
, 255);
165 while (fgets(buffer
, STRING_SIZE
, p
))
167 newtScaleSet(s
, ++progress
);
169 fprintf(flog
, "%s", buffer
);
181 int checkformodule(char *module
)
184 char buffer
[STRING_SIZE
];
187 if (!(file
= fopen("/proc/modules", "r")))
189 fprintf(flog
, "Unable to open /proc/modules in checkformodule()\n");
193 while (fgets(buffer
, STRING_SIZE
, file
))
195 if (strncmp(buffer
, module
, strlen(module
)) == 0)
197 if (buffer
[strlen(module
)] == ' ')
211 int _replace_string(char string
[], char *from
, char *to
)
213 int fromlen
= strlen(from
);
214 int tolen
= strlen(to
);
215 char *start
, *p1
, *p2
;
216 for(start
= string
; *start
!= '\0'; start
++)
231 memmove(start
+ tolen
, start
+ fromlen
,
232 strlen(start
+ fromlen
) + 1);
234 for(p1
= to
; *p1
!= '\0'; p1
++)
242 int replace(char filename1
[], char *from
, char *to
)
245 char filename2
[1000];
249 /* Open the source and destination files */
250 strcpy (filename2
, filename1
);
251 strcat (filename2
, ".new");
252 if (!(file1
= fopen (filename1
, "r"))) return 1;
253 if (!(file2
= fopen (filename2
, "w"))) {
258 /* Start reading in lines */
259 while (fgets (temp
, 1000, file1
) != NULL
) {
261 if (strlen(to
) > 0) {
263 ret
= _replace_string (temp
, from
, to
);
265 /* Write string to new file */
268 /* Remove string when to is NULL */
269 if (!strstr(temp
, from
))
274 /* Close source and destination */
279 rename (filename2
, filename1
);
284 /* Include enabled languages */
292 // returns a pointer to the actual running version number of IPFire.
293 // Successive updates increase effective version but not VERSION !
294 char g_title
[STRING_SIZE
] = "";
295 char* get_version(void) {
297 if ((f_title
= fopen ("/etc/issue", "r"))) {
298 fgets (g_title
, STRING_SIZE
, f_title
);
300 if (g_title
[strlen(g_title
) - 1] == '\n') g_title
[strlen(g_title
) - 1] = '\0';
302 sprintf (g_title
, "%s %s - %s", NAME
, VERSION
, SLOGAN
);