1994-10-20 02:51:55 +00:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
1994-10-24 03:55:25 +00:00
|
|
|
* $Id: utils.c,v 1.10 1994/10/22 02:37:24 ache Exp $
|
1994-10-20 02:51:55 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
1994-10-20 02:51:55 +00:00
|
|
|
#include <dialog.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
1994-10-21 18:08:33 +00:00
|
|
|
#include <sys/reboot.h>
|
1994-10-20 02:51:55 +00:00
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
TellEm(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
dialog_msgbox("Progress", p, 3, 75, 0);
|
1994-10-21 18:08:33 +00:00
|
|
|
dialog_clear();
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Fatal(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
1994-10-22 02:37:24 +00:00
|
|
|
if (dialog_active)
|
1994-10-21 04:43:07 +00:00
|
|
|
dialog_msgbox("Fatal", p, 12, 75, 1);
|
1994-10-22 02:37:24 +00:00
|
|
|
else
|
1994-10-21 04:43:07 +00:00
|
|
|
fprintf(stderr, "Fatal -- %s", p);
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
1994-10-21 18:08:33 +00:00
|
|
|
ExitSysinstall();
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
1994-10-21 18:08:33 +00:00
|
|
|
void
|
1994-10-20 05:00:00 +00:00
|
|
|
AskAbort(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
1994-10-21 18:08:33 +00:00
|
|
|
strcat(p, "\n\nDo you wish to abort the installation?");
|
|
|
|
if (!dialog_yesno("Abort", p, 15, 60)) {
|
|
|
|
dialog_clear();
|
|
|
|
Abort();
|
|
|
|
}
|
|
|
|
dialog_clear();
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
1994-10-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Abort()
|
|
|
|
{
|
|
|
|
if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?",
|
|
|
|
10, 40)) {
|
|
|
|
dialog_clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ExitSysinstall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ExitSysinstall()
|
|
|
|
{
|
1994-10-24 03:55:25 +00:00
|
|
|
if (dialog_active) {
|
|
|
|
clear();
|
|
|
|
dialog_update();
|
|
|
|
}
|
1994-10-21 18:08:33 +00:00
|
|
|
if (getpid() == 1) {
|
|
|
|
if (reboot(RB_AUTOBOOT) == -1)
|
|
|
|
if (dialog_active) {
|
1994-10-22 02:32:16 +00:00
|
|
|
clear();
|
1994-10-21 18:08:33 +00:00
|
|
|
dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button",
|
|
|
|
5,30,0);
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "Can't reboot the machine -- hit the reset button");
|
|
|
|
while(1);
|
1994-10-22 02:32:16 +00:00
|
|
|
} else {
|
|
|
|
if (dialog_active) {
|
1994-10-22 02:35:09 +00:00
|
|
|
end_dialog();
|
1994-10-24 03:55:25 +00:00
|
|
|
dialog_active = 0;
|
1994-10-22 02:32:16 +00:00
|
|
|
}
|
1994-10-21 18:08:33 +00:00
|
|
|
exit(0);
|
1994-10-22 02:32:16 +00:00
|
|
|
}
|
1994-10-20 02:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
Malloc(size_t size)
|
|
|
|
{
|
|
|
|
void *p = malloc(size);
|
|
|
|
if (!p) {
|
|
|
|
exit(7); /* XXX longjmp bad */
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
1994-10-20 05:00:00 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
StrAlloc(char *str)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = (char *)Malloc(strlen(str) + 1);
|
|
|
|
strcpy(p,str);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
|
|
|
|
{
|
|
|
|
struct ufs_args ufsargs;
|
|
|
|
char dbuf[90];
|
|
|
|
char pbuf[90];
|
|
|
|
|
1994-10-20 06:48:40 +00:00
|
|
|
memset(&ufsargs,0,sizeof ufsargs);
|
|
|
|
|
1994-10-20 05:00:00 +00:00
|
|
|
if (prefix)
|
|
|
|
strcpy(pbuf,prefix);
|
|
|
|
else
|
|
|
|
strcpy(pbuf,"");
|
|
|
|
|
|
|
|
strcat(pbuf,mountpoint);
|
|
|
|
|
|
|
|
if(do_mkdir && access(pbuf,R_OK)) {
|
1994-10-21 02:14:54 +00:00
|
|
|
Mkdir(pbuf);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(dbuf,"/dev/");
|
|
|
|
strcat(dbuf,device);
|
|
|
|
|
|
|
|
TellEm("mount /dev/%s /mnt%s",dbuf,pbuf);
|
|
|
|
ufsargs.fspec = dbuf;
|
|
|
|
if (mount(MOUNT_UFS,pbuf, 0, (caddr_t) &ufsargs) == -1) {
|
1994-10-21 18:08:33 +00:00
|
|
|
Fatal("Error mounting %s on %s : %s\n",
|
1994-10-20 05:00:00 +00:00
|
|
|
dbuf, pbuf, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
1994-10-21 02:14:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Mkdir(char *path)
|
|
|
|
{
|
|
|
|
TellEm("mkdir %s",path);
|
|
|
|
if (mkdir(path, S_IRWXU) == -1) {
|
|
|
|
Fatal("Couldn't create directory %s: %s\n",
|
|
|
|
path,strerror(errno));
|
|
|
|
}
|
|
|
|
}
|