1995-05-23 03:41:18 +01:00
/*
* The new sysinstall program .
*
* This is probably the last program in the ` sysinstall ' line - the next
* generation being essentially a complete rewrite .
*
1995-06-11 20:33:05 +01:00
* $ Id : config . c , v 1.15 .2 .28 1995 / 06 / 10 08 : 24 : 28 jkh Exp $
1995-05-23 03:41:18 +01:00
*
* Copyright ( c ) 1995
* Jordan Hubbard . All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
1995-05-30 09:29:07 +01:00
* notice , this list of conditions and the following disclaimer ,
* verbatim and that no modifications are made prior to this
1995-05-23 03:41:18 +01:00
* point in the file .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement :
* This product includes software developed by Jordan Hubbard
* for the FreeBSD Project .
* 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
* endorse or promote products derived from this software without specific
* prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ` ` AS IS ' ' AND
* ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
* FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL
* DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES ; LOSS OF USE , DATA , LIFE OR PROFITS ; OR BUSINESS INTERRUPTION )
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT
* LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE .
*
*/
# include "sysinstall.h"
# include <sys/disklabel.h>
1995-05-26 20:28:06 +01:00
# include <sys/wait.h>
1995-05-23 03:41:18 +01:00
static Chunk * chunk_list [ MAX_CHUNKS ] ;
static int nchunks ;
/* arg to sort */
static int
chunk_compare ( const void * p1 , const void * p2 )
{
Chunk * c1 , * c2 ;
c1 = ( Chunk * ) p1 ;
c2 = ( Chunk * ) p2 ;
if ( ! c1 - > private & & ! c2 - > private )
return 0 ;
else if ( c1 - > private & & ! c2 - > private )
return - 1 ;
else if ( ! c1 - > private & & c2 - > private )
return 1 ;
else
return strcmp ( ( ( PartInfo * ) c1 - > private ) - > mountpoint , ( ( PartInfo * ) c2 - > private ) - > mountpoint ) ;
}
1995-05-25 19:48:33 +01:00
static char *
nameof ( Chunk * c1 )
{
static char rootname [ 64 ] ;
/* Our boot blocks can't deal with root partitions on slices - need the compatbility name */
if ( c1 - > type = = part & & c1 - > flags & CHUNK_IS_ROOT ) {
sprintf ( rootname , " %sa " , c1 - > disk - > name ) ;
return rootname ;
}
else
return c1 - > name ;
}
1995-05-23 03:41:18 +01:00
static char *
mount_point ( Chunk * c1 )
{
1995-06-11 20:33:05 +01:00
if ( c1 - > type = = part & & c1 - > subtype = = FS_SWAP )
1995-05-23 03:41:18 +01:00
return " none " ;
1995-06-11 20:33:05 +01:00
else if ( c1 - > type = = part | | c1 - > type = = fat )
return ( ( PartInfo * ) c1 - > private ) - > mountpoint ;
1995-05-23 03:41:18 +01:00
return " /bogus " ;
}
static char *
fstype ( Chunk * c1 )
{
1995-05-26 09:41:52 +01:00
if ( c1 - > type = = fat )
1995-05-23 03:41:18 +01:00
return " msdos " ;
else if ( c1 - > type = = part ) {
if ( c1 - > subtype ! = FS_SWAP )
return " ufs " ;
else
return " swap " ;
}
1995-06-11 20:33:05 +01:00
return " bogus " ;
1995-05-23 03:41:18 +01:00
}
static char *
fstype_short ( Chunk * c1 )
{
if ( c1 - > type = = part ) {
if ( c1 - > subtype ! = FS_SWAP )
return " rw " ;
else
return " sw " ;
}
1995-05-28 21:28:15 +01:00
else if ( c1 - > type = = fat )
return " rw " ;
1995-05-23 03:41:18 +01:00
return " bog " ;
}
static int
seq_num ( Chunk * c1 )
{
1995-06-11 20:33:05 +01:00
if ( c1 - > type = = part & & c1 - > subtype ! = FS_SWAP )
return 1 ;
return 0 ;
1995-05-23 03:41:18 +01:00
}
void
1995-05-24 10:00:58 +01:00
configFstab ( void )
1995-05-23 03:41:18 +01:00
{
Device * * devs ;
Disk * disk ;
FILE * fstab ;
int i , cnt ;
Chunk * c1 , * c2 ;
1995-06-11 20:33:05 +01:00
if ( ! RunningAsInit ) {
if ( file_readable ( " /etc/fstab " ) )
return ;
else
msgConfirm ( " Attempting to rebuild your /etc/fstab file. \n Warning: If you had any CD devices in use before running \n sysinstall then they may NOT be found in this run! " ) ;
}
1995-05-23 03:41:18 +01:00
devs = deviceFind ( NULL , DEVICE_TYPE_DISK ) ;
if ( ! devs ) {
msgConfirm ( " No disks found! " ) ;
return ;
}
/* Record all the chunks */
1995-06-11 20:33:05 +01:00
nchunks = 0 ;
1995-05-23 03:41:18 +01:00
for ( i = 0 ; devs [ i ] ; i + + ) {
if ( ! devs [ i ] - > enabled )
continue ;
disk = ( Disk * ) devs [ i ] - > private ;
if ( ! disk - > chunks )
msgFatal ( " No chunk list found for %s! " , disk - > name ) ;
1995-05-25 19:48:33 +01:00
for ( c1 = disk - > chunks - > part ; c1 ; c1 = c1 - > next ) {
if ( c1 - > type = = freebsd ) {
for ( c2 = c1 - > part ; c2 ; c2 = c2 - > next ) {
1995-06-11 20:33:05 +01:00
if ( c2 - > type = = part & & ( c2 - > subtype = = FS_SWAP | | c2 - > private ) )
1995-05-23 03:41:18 +01:00
chunk_list [ nchunks + + ] = c2 ;
1995-05-25 19:48:33 +01:00
}
}
1995-06-11 20:33:05 +01:00
else if ( c1 - > type = = fat & & c1 - > private )
1995-05-25 19:48:33 +01:00
chunk_list [ nchunks + + ] = c1 ;
}
1995-05-23 03:41:18 +01:00
}
/* Sort them puppies! */
qsort ( chunk_list , nchunks , sizeof ( Chunk * ) , chunk_compare ) ;
fstab = fopen ( " /etc/fstab " , " w " ) ;
if ( ! fstab ) {
msgConfirm ( " Unable to create a new /etc/fstab file! \n Manual intervention will be required. " ) ;
return ;
}
/* Go for the burn */
1995-05-29 12:01:42 +01:00
msgDebug ( " Generating /etc/fstab file \n " ) ;
1995-06-11 20:33:05 +01:00
for ( i = 0 ; i < nchunks ; i + + )
fprintf ( fstab , " /dev/%s \t \t \t %s \t \t %s \t %s %d %d \n " , nameof ( chunk_list [ i ] ) , mount_point ( chunk_list [ i ] ) ,
fstype ( chunk_list [ i ] ) , fstype_short ( chunk_list [ i ] ) , seq_num ( chunk_list [ i ] ) , seq_num ( chunk_list [ i ] ) ) ;
1995-05-23 03:41:18 +01:00
Mkdir ( " /proc " , NULL ) ;
1995-06-11 20:33:05 +01:00
fprintf ( fstab , " proc \t \t \t \t /proc \t \t procfs \t rw 0 0 \n " ) ;
1995-05-23 03:41:18 +01:00
/* Now look for the CDROMs */
devs = deviceFind ( NULL , DEVICE_TYPE_CDROM ) ;
cnt = deviceCount ( devs ) ;
/* Write the first one out as /cdrom */
if ( cnt ) {
Mkdir ( " /cdrom " , NULL ) ;
1995-06-11 20:33:05 +01:00
fprintf ( fstab , " /dev/%s \t \t \t /cdrom \t \t cd9660 \t ro 0 0 \n " , devs [ 0 ] - > name ) ;
1995-05-23 03:41:18 +01:00
}
/* Write the others out as /cdrom<n> */
for ( i = 1 ; i < cnt ; i + + ) {
char cdname [ 10 ] ;
sprintf ( cdname , " /cdrom%d " , i ) ;
Mkdir ( cdname , NULL ) ;
1995-06-11 20:33:05 +01:00
fprintf ( fstab , " /dev/%s \t \t \t %s \t \t cd9660 \t ro 0 0 \n " , devs [ i ] - > name , cdname ) ;
1995-05-23 03:41:18 +01:00
}
fclose ( fstab ) ;
1995-06-11 20:33:05 +01:00
if ( isDebug ( ) )
msgDebug ( " Wrote out /etc/fstab file \n " ) ;
1995-05-23 03:41:18 +01:00
}
1995-05-24 10:00:58 +01:00
/*
* This sucks in / etc / sysconfig , substitutes anything needing substitution , then
* writes it all back out . It ' s pretty gross and needs re - writing at some point .
*/
1995-05-23 03:41:18 +01:00
void
1995-05-24 10:00:58 +01:00
configSysconfig ( void )
1995-05-23 03:41:18 +01:00
{
1995-05-24 10:00:58 +01:00
FILE * fp ;
char * lines [ 5001 ] ; /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
char line [ 256 ] ;
Variable * v ;
int i , nlines = 0 ;
fp = fopen ( " /etc/sysconfig " , " r " ) ;
if ( ! fp ) {
msgConfirm ( " Unable to open /etc/sysconfig file! Things may work \n rather strangely as a result of this. " ) ;
return ;
}
for ( i = 0 ; i < 5000 ; i + + ) {
1995-05-26 09:41:52 +01:00
if ( ! fgets ( line , 255 , fp ) )
1995-05-24 10:00:58 +01:00
break ;
lines [ nlines + + ] = strdup ( line ) ;
}
lines [ nlines ] = NULL ;
1995-05-26 09:41:52 +01:00
fclose ( fp ) ;
1995-05-24 10:00:58 +01:00
for ( v = VarHead ; v ; v = v - > next ) {
for ( i = 0 ; i < nlines ; i + + ) {
1995-05-26 09:41:52 +01:00
char modify [ 256 ] , * cp ;
if ( lines [ i ] [ 0 ] = = ' # ' | | lines [ i ] [ 0 ] = = ' ; ' )
continue ;
strncpy ( modify , lines [ i ] , 255 ) ;
cp = index ( modify , ' = ' ) ;
if ( ! cp )
continue ;
* ( cp + + ) = ' \0 ' ;
if ( ! strcmp ( modify , v - > name ) ) {
free ( lines [ i ] ) ;
lines [ i ] = ( char * ) malloc ( strlen ( v - > name ) + strlen ( v - > value ) + 3 ) ;
1995-05-26 21:55:11 +01:00
sprintf ( lines [ i ] , " %s= \" %s \" \n " , v - > name , v - > value ) ;
1995-05-26 09:41:52 +01:00
}
1995-05-30 09:29:07 +01:00
1995-05-24 10:00:58 +01:00
}
}
1995-05-26 09:41:52 +01:00
fp = fopen ( " /etc/sysconfig " , " w " ) ;
if ( ! fp ) {
msgConfirm ( " Unable to re-write /etc/sysconfig file! Things may work \n rather strangely as a result of this. " ) ;
return ;
}
1995-05-26 20:28:06 +01:00
for ( i = 0 ; i < nlines ; i + + ) {
1995-05-26 09:41:52 +01:00
fprintf ( fp , lines [ i ] ) ;
1995-05-26 20:28:06 +01:00
free ( lines [ i ] ) ;
/* Stand by for bogus special case handling - we try to dump the interface specs here */
if ( ! strncmp ( lines [ i ] , VAR_INTERFACES , strlen ( VAR_INTERFACES ) ) ) {
Device * * devp ;
int j , cnt ;
devp = deviceFind ( NULL , DEVICE_TYPE_NETWORK ) ;
cnt = deviceCount ( devp ) ;
for ( j = 0 ; j < cnt ; j + + ) {
1995-06-11 20:33:05 +01:00
if ( devp [ j ] - > private & & strncmp ( devp [ j ] - > name , " cuaa " , 4 ) ) {
1995-05-26 20:28:06 +01:00
char iname [ 64 ] ;
snprintf ( iname , 64 , " %s%s " , VAR_IFCONFIG , devp [ j ] - > name ) ;
if ( getenv ( iname ) )
1995-05-26 21:55:11 +01:00
fprintf ( fp , " %s= \" %s \" \n " , iname , getenv ( iname ) ) ;
1995-05-26 20:28:06 +01:00
}
}
}
}
1995-05-26 09:41:52 +01:00
fclose ( fp ) ;
1995-06-11 20:33:05 +01:00
/* If we're an NFS server, we need an exports file */
if ( getenv ( " nfs_server " ) & & ! file_readable ( " /etc/exports " ) ) {
msgConfirm ( " You have chosen to be an NFS server but have not yet configured \n the /etc/exports file. The format for an exports entry is: \n <mountpoint> <opts> <host [..host]> \n Where <mounpoint> is the name of a filesystem as specified \n in the Label editor, <opts> is a list of special options we \n won't concern ourselves with here (``man exports'' when the \n system is fully installed) and <host> is one or more host \n names who are allowed to mount this file system. Press \n [ENTER] now to invoke the editor on /etc/exports " ) ;
systemExecute ( " vi /etc/exports " ) ;
}
1995-05-24 10:00:58 +01:00
}
int
configSaverTimeout ( char * str )
{
char * val ;
val = msgGetInput ( " 60 " , " Enter time-out period in seconds for screen saver " ) ;
if ( val )
variable_set2 ( " blanktime " , val ) ;
return 0 ;
1995-05-23 03:41:18 +01:00
}
1995-06-11 20:33:05 +01:00
int
configNTP ( char * str )
{
char * val ;
val = msgGetInput ( NULL , " Enter the name of an NTP server " ) ;
if ( val )
variable_set2 ( " ntpdate " , val ) ;
return 0 ;
}
1995-05-23 03:41:18 +01:00
void
1995-05-24 10:00:58 +01:00
configResolv ( void )
1995-05-23 03:41:18 +01:00
{
1995-05-23 19:06:16 +01:00
FILE * fp ;
1995-06-11 20:33:05 +01:00
char * cp ;
1995-05-23 19:06:16 +01:00
1995-06-11 20:33:05 +01:00
if ( ! RunningAsInit & & file_readable ( " /etc/resolv.conf " ) )
1995-05-23 19:06:16 +01:00
return ;
1995-06-11 20:33:05 +01:00
if ( ! getenv ( VAR_NAMESERVER ) ) {
if ( mediaDevice & & ( mediaDevice - > type = = DEVICE_TYPE_NFS | | mediaDevice - > type = = DEVICE_TYPE_FTP ) )
msgConfirm ( " Warning: Missing name server value - network operations \n may fail as a result! " ) ;
goto skip ;
1995-05-23 19:06:16 +01:00
}
Mkdir ( " /etc " , NULL ) ;
fp = fopen ( " /etc/resolv.conf " , " w " ) ;
if ( ! fp ) {
msgConfirm ( " Unable to open /etc/resolv.conf! You will need to do this manually. " ) ;
return ;
}
1995-06-11 20:33:05 +01:00
if ( getenv ( VAR_DOMAINNAME ) )
fprintf ( fp , " domain \t %s \n " , getenv ( VAR_DOMAINNAME ) ) ;
1995-05-23 19:06:16 +01:00
fprintf ( fp , " nameserver \t %s \n " , getenv ( VAR_NAMESERVER ) ) ;
fclose ( fp ) ;
1995-06-11 20:33:05 +01:00
if ( isDebug ( ) )
msgDebug ( " Wrote out /etc/resolv.conf \n " ) ;
skip :
/* Tack ourselves at the end of /etc/hosts */
cp = getenv ( VAR_IPADDR ) ;
if ( cp & & * cp ! = ' 0 ' & & getenv ( VAR_HOSTNAME ) ) {
fp = fopen ( " /etc/hosts " , " a " ) ;
fprintf ( fp , " %s \t \t %s \n " , cp , getenv ( VAR_HOSTNAME ) ) ;
fclose ( fp ) ;
if ( isDebug ( ) )
msgDebug ( " Appended entry for %s to /etc/hosts \n " , cp ) ;
}
}
int
configRoutedFlags ( char * str )
{
char * val ;
val = msgGetInput ( " -q " , " Specify the flags for routed; -q is the default, -s is \n a good choice for gateway machines. " ) ;
if ( val )
variable_set2 ( " routedflags " , val ) ;
return 0 ;
1995-05-23 19:06:16 +01:00
}
1995-05-24 02:27:15 +01:00
int
1995-05-24 10:00:58 +01:00
configPackages ( char * str )
1995-05-24 02:27:15 +01:00
{
1995-05-26 20:28:06 +01:00
int i , pstat ;
pid_t pid ;
Boolean onCD ;
1995-06-11 20:33:05 +01:00
msgConfirm ( " Warning: This utility (pkg_manage) is still somewhat experimental \n and may not function for all packages. If it fails to load the \n packages you want, try running it directly once the system is up or use the \n pkg_add, pkg_info and pkg_delete utilities directly. " ) ;
1995-05-26 20:28:06 +01:00
i = - 1 ;
1995-06-11 20:33:05 +01:00
/* If we're running as init, we know that a CD in the drive is probably ours */
onCD = file_readable ( " /cdrom/packages " ) ;
if ( ! onCD & & RunningAsInit ) {
if ( mediaSetCDROM ( NULL ) ) {
if ( ( * mediaDevice - > init ) ( mediaDevice ) )
1995-05-26 20:28:06 +01:00
onCD = TRUE ;
}
}
1995-06-11 20:33:05 +01:00
if ( ! ( pid = fork ( ) ) ) {
if ( onCD & & chdir ( " /cdrom/packages/All " ) )
1995-05-26 20:28:06 +01:00
exit ( 1 ) ;
1995-06-11 20:33:05 +01:00
execl ( " /usr/sbin/pkg_manage " , " /usr/sbin/pkg_manage " , ( char * ) NULL ) ;
exit ( 1 ) ;
1995-05-26 20:28:06 +01:00
}
else {
1995-06-11 20:33:05 +01:00
pid = waitpid ( pid , ( int * ) & pstat , 0 ) ;
i = ( pid = = - 1 ) ? - 1 : WEXITSTATUS ( pstat ) ;
1995-05-24 10:00:58 +01:00
}
1995-05-29 12:01:42 +01:00
if ( i ! = 0 & & isDebug ( ) )
1995-05-26 20:28:06 +01:00
msgDebug ( " pkg_manage returns status of %d \n " , i ) ;
1995-05-24 02:27:15 +01:00
return 0 ;
}
int
1995-05-24 10:00:58 +01:00
configPorts ( char * str )
1995-05-24 02:27:15 +01:00
{
return 0 ;
}