Browse Source

some changes to templates, fixed it so debconf talking is in postint rather than config

r293
master
David Whedon 23 years ago
parent
commit
7ec48a21da
  1. 2
      Makefile
  2. 4
      debian/netcfg-dhcp.templates
  3. 18
      debian/netcfg-static.templates
  4. 150
      netcfg.c

2
Makefile

@ -16,7 +16,7 @@ all: $(PROGS)
install:
$(foreach PROG, $(PROGS), \
-cp $(PROG) debian/$(PROG).config)
-cp $(PROG) debian/$(PROG).postinst)
netcfg-dhcp: netcfg.c
$(CC) $(CFLAGS) -DDHCP netcfg.c -o $@ $(INCS) $(LDOPTS)

4
debian/netcfg-dhcp.templates

@ -19,11 +19,11 @@ Description: please enter a network interface.
Template: netcfg/get_hostname
Type: string
Default: debian
Description:
Description: Enter the system's hostname.
The hostname is a single word that identifies your system to the
network. If you don't know what your hostname should be, consult
your network administrator. If you are setting up your own home
network, you can make something up here. Don't enter your full
network, you can make something up here.
Template: netcfg/choose_interface
Type: select

18
debian/netcfg-static.templates

@ -1,9 +1,11 @@
Template: netcfg/get_domain
Type: string
Description: Choose the domain name.
As with individual systems, every network has a name. This name is called the
domain name. Please enter your domain name or leave this field empty if you
don't have a domain.
The domain name is the part of your Internet address to the right
of your host name. It is often something that ends in .com, .net,
.edu, or .org. If you are setting up a home network, you can make
something up, but make sure you use the same domain name on all
your computers.
Template: netcfg/get_ipaddress
Type: string
@ -21,9 +23,13 @@ Description: What is your netmask?
Template: netcfg/get_gateway
Type: string
Description: What is your IP gateway address?
A gateway system is one that connects your network to other networks such as
your company wide-area net or the Internet. If there is no gateway in your
subnet just leave this field blank.
This is an IP address (four numbers separated by periods) that
indicates the gateway router, also known as the default router. All
traffic that goes outside your LAN (for instance, to the Internet) is
sent through this router. In rare circumstances, you may have no
router; in that case, you can leave this blank. If you don't know
the proper answer to this question, consult your network
administrator.
Template: netcfg/gateway_unreachable
Type: note

150
netcfg.c

@ -45,9 +45,9 @@ int activate_net ();
void debconf_unseen (char *template);
void debconf_subst (char *template, char *key, char *string);
char *debconf_input (char *priority, char *template);
int do_system(char *);
void write_common(void);
void get_common(void);
int do_system (char *);
void write_common (void);
void get_common (void);
char *dot2num (u_int32_t * num, char *dot);
char *num2dot (u_int32_t num);
@ -64,13 +64,13 @@ main (int argc, char *argv[])
client = debconfclient_new ();
client->command (client, "title", "Network Configuration", NULL);
get_common();
get_common ();
get_interface ();
client->command (client, "input", "high", "netcfg/dhcp_hostname", NULL);
client->command (client, "go", NULL);
client->command (client, "get", "netcfg/dhcp_hostname", NULL);
dhcp_hostname = client->value;
write_common();
write_common ();
write_dhcp_cfg ();
activate_dhcp_net ();
@ -109,7 +109,8 @@ activate_dhcp_net (void)
ptr = buf;
ptr += snprintf (buf, sizeof (buf), "/sbin/dhcpcd-2.2.x");
if (dhcp_hostname)
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " -h %s", dhcp_hostname);
ptr +=
snprintf (ptr, sizeof (buf) - (ptr - buf), " -h %s", dhcp_hostname);
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " %s", interface);
@ -182,7 +183,7 @@ get_static_cfg (void)
ipaddress = network = broadcast = netmask = gateway =
nameservers[0] = 0;
debconf_subst ("netcfg/confirm_static_cfg", "hostname", hostname);
if ((ptr = debconf_input ("high", "netcfg/get_ipaddress")))
dot2num (&ipaddress, ptr);
@ -190,8 +191,8 @@ get_static_cfg (void)
debconf_subst ("netcfg/confirm_static_cfg", "ipaddress",
num2dot (ipaddress));
get_common();
get_common ();
if ((ptr = debconf_input ("high", "netcfg/get_netmask")))
dot2num (&netmask, ptr);
debconf_subst ("netcfg/confirm_static_cfg", "netmask",
@ -236,15 +237,15 @@ write_static_cfg (void)
{
FILE *fp;
if ((fp = file_open (NETWORKS_FILE)))
{
fprintf (fp, "localnet %s\n", num2dot (network));
fclose (fp);
}
write_common();
write_common ();
if ((fp = file_open (INTERFACES_FILE)))
{
fprintf (fp,
@ -269,9 +270,15 @@ activate_static_net ()
do_system ("/sbin/ifconfig lo 127.0.0.1");
ptr = buf;
ptr += snprintf (buf, sizeof (buf), "/sbin/ifconfig %s %s", interface, num2dot (ipaddress));
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " netmask %s", num2dot (netmask));
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " broadcast %s", num2dot (broadcast));
ptr +=
snprintf (buf, sizeof (buf), "/sbin/ifconfig %s %s", interface,
num2dot (ipaddress));
ptr +=
snprintf (ptr, sizeof (buf) - (ptr - buf), " netmask %s",
num2dot (netmask));
ptr +=
snprintf (ptr, sizeof (buf) - (ptr - buf), " broadcast %s",
num2dot (broadcast));
rv = do_system (buf);
if (rv != 0)
@ -286,45 +293,46 @@ activate_static_net ()
#endif /* STATIC */
void
get_common(void){
char *ptr, *ns;
get_common (void)
{
char *ptr, *ns;
hostname = strdup (debconf_input ("high", "netcfg/get_hostname"));
hostname = strdup (debconf_input ("high", "netcfg/get_hostname"));
if ((ptr = debconf_input ("high", "netcfg/get_domain")))
domain = strdup (ptr);
debconf_subst ("netcfg/confirm_static_cfg", "domain", domain);
if ((ptr = debconf_input ("high", "netcfg/get_domain")))
domain = strdup (ptr);
debconf_subst ("netcfg/confirm_static_cfg", "domain", domain);
ptr = debconf_input ("high", "netcfg/get_nameservers");
if (ptr)
{
char *save;
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", ns);
dot2num (&nameservers[0], ns);
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", ns);
dot2num (&nameservers[1], ns);
ptr = debconf_input ("high", "netcfg/get_nameservers");
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", ns);
dot2num (&nameservers[2], ns);
if (ptr)
{
char *save;
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", ns);
dot2num (&nameservers[0], ns);
free (save);
}
else
{
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", NULL);
}
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", ns);
dot2num (&nameservers[1], ns);
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", ns);
dot2num (&nameservers[2], ns);
free (save);
}
else
{
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", NULL);
}
@ -335,11 +343,12 @@ get_common(void){
}
void
write_common(void){
FILE *fp;
int i;
write_common (void)
{
FILE *fp;
int i;
if ((fp = file_open (HOSTS_FILE)))
if ((fp = file_open (HOSTS_FILE)))
{
fprintf (fp, "127.0.0.1\tlocalhost\n");
if (domain)
@ -358,16 +367,16 @@ write_common(void){
if ((fp = file_open (RESOLV_FILE)))
if ((fp = file_open (RESOLV_FILE)))
{
i = 0;
if (domain)
fprintf (fp, "search %s\n", domain);
while (nameservers[i])
i = 0;
if (domain)
fprintf (fp, "search %s\n", domain);
while (nameservers[i])
{
fprintf (fp, "nameserver %s\n", num2dot (nameservers[i++]));
fprintf (fp, "nameserver %s\n", num2dot (nameservers[i++]));
}
fclose (fp);
fclose (fp);
}
}
@ -583,14 +592,15 @@ get_interface ()
if (ptr == buf)
{
debconf_unseen ("netcfg/no_interfaces");
ptr = debconf_input ("critical", "netcfg/no_interfaces");
if (ptr) {
interface = strdup (ptr);
return 0;
debconf_unseen ("netcfg/no_interfaces");
ptr = debconf_input ("critical", "netcfg/no_interfaces");
if (ptr)
{
interface = strdup (ptr);
return 0;
}
else
return -1;
else
return -1;
}
@ -626,16 +636,17 @@ file_open (char *path)
int
do_system (char *s){
int rv;
do_system (char *s)
{
int rv;
#ifdef DEBUG
fprintf(stderr, "executing '%s'\n", s);
fprintf (stderr, "executing '%s'\n", s);
#endif
rv = system(s);
rv = system (s);
#ifdef DEBUG
fprintf(stderr, "rv = %d\n", rv);
fprintf (stderr, "rv = %d\n", rv);
#endif
return rv;
return rv;
}
@ -695,4 +706,3 @@ num2dot (u_int32_t num)
return dot;
}

Loading…
Cancel
Save