Browse Source

Copy configuration to /target and make it work

r1807
master
Matt Kraai 20 years ago
parent
commit
10ed940e29
  1. 2
      debian/changelog
  2. 6
      debian/rules
  3. 10
      netcfg-dhcp.c
  4. 12
      netcfg-static.c
  5. 50
      netcfg.c
  6. 7
      netcfg.h
  7. 1
      prebaseconfig

2
debian/changelog

@ -6,7 +6,7 @@ netcfg (0.22) UNRELEASED; urgency=low
* Tollef Fog Heen
- Reinstate netcfg-dhcp.templates which got lost in a branch
* Matt Kraai
- Print "<none>" for an unspecified hostname
- Copy configuration to /target and make it work (closes: #177666)
-- Tollef Fog Heen <tfheen@debian.org> Tue, 17 Dec 2002 00:01:34 +0100

6
debian/rules

@ -49,6 +49,12 @@ install: build
cp netcfg-static debian/netcfg-static.postinst
mkdir -p debian/netcfg-dhcp/etc/dhcp debian/netcfg-dhcp/var/dhcp
mkdir -p debian/netcfg-static/etc/network
mkdir -p debian/netcfg-dhcp/usr/lib/prebaseconfig.d
install -m 755 prebaseconfig \
debian/netcfg-dhcp/usr/lib/prebaseconfig.d/40netcfg-dhcp
mkdir -p debian/netcfg-static/usr/lib/prebaseconfig.d
install -m 755 prebaseconfig \
debian/netcfg-static/usr/lib/prebaseconfig.d/40netcfg-static
# Build architecture-independent files here.
binary-indep: build install

10
netcfg-dhcp.c

@ -85,9 +85,10 @@ static void netcfg_write_dhcp()
FILE *fp;
if ((fp = file_open(INTERFACES_FILE))) {
if ((fp = file_open(INTERFACES_FILE, "a"))) {
fprintf(fp,
"\n# This entry was created during the Debian installation\n");
fprintf(fp, "auto %s\n", interface);
fprintf(fp, "iface %s inet dhcp\n", interface);
if (dhcp_hostname)
fprintf(fp, "\thostname %s\n", dhcp_hostname);
@ -154,13 +155,13 @@ int main(int argc, char *argv[])
do {
netcfg_get_interface(client, &interface);
netcfg_get_hostname(client, &hostname);
client->command(client, "subst", "netcfg/confirm_dhcp",
"interface", interface, NULL);
client->command(client, "subst", "netcfg/confirm_dhcp",
"hostname", (hostname ? hostname : _("<none>")),
NULL);
"hostname", hostname, NULL);
client->command(client, "subst", "netcfg/confirm_dhcp",
"domain", (domain ? domain : _("<none>")),
@ -182,8 +183,9 @@ int main(int argc, char *argv[])
}
while (!finished);
netcfg_write_common("40netcfg-dhcp", ipaddress, domain, hostname,
nameserver_array);
netcfg_write_dhcp();
netcfg_write_common(ipaddress, domain, hostname, nameserver_array);
my_debconf_input("medium", "netcfg/do_dhcp");
netcfg_activate_dhcp();

12
netcfg-static.c

@ -122,17 +122,22 @@ static int netcfg_write_static()
{
FILE *fp;
if ((fp = file_open(NETWORKS_FILE))) {
if ((fp = file_open(NETWORKS_FILE, "w"))) {
fprintf(fp, "localnet %s\n", num2dot(network));
fclose(fp);
di_prebaseconfig_append("40netcfg-static", "cp %s %s\n",
NETWORKS_FILE,
"/target" NETWORKS_FILE);
} else
goto error;
if ((fp = file_open(INTERFACES_FILE))) {
if ((fp = file_open(INTERFACES_FILE, "a"))) {
fprintf(fp,
"\n# This entry was created during the Debian installation\n");
fprintf(fp,
"# (network, broadcast and gateway are optional)\n");
fprintf(fp, "auto %s\n", interface);
fprintf(fp, "iface %s inet static\n", interface);
fprintf(fp, "\taddress %s\n", num2dot(ipaddress));
fprintf(fp, "\tnetmask %s\n", num2dot(netmask));
@ -245,7 +250,8 @@ int main(int argc, char *argv[])
}
while (!finished);
netcfg_write_common(ipaddress, domain, hostname, nameserver_array);
netcfg_write_common("40netcfg-static", ipaddress, domain, hostname,
nameserver_array);
netcfg_write_static();
netcfg_activate_static();

50
netcfg.c

@ -181,10 +181,10 @@ char *get_ifdsc(const char *ifp)
}
FILE *file_open(char *path)
FILE *file_open(char *path, const char *opentype)
{
FILE *fp;
if ((fp = fopen(path, "w")))
if ((fp = fopen(path, opentype)))
return fp;
else {
fprintf(stderr, "%s\n", path);
@ -325,18 +325,13 @@ netcfg_get_interface(struct debconfclient *client, char **interface)
netcfg_die(client);
}
void
netcfg_get_common(struct debconfclient *client, char **interface,
char **hostname, char **domain, char **nameservers)
netcfg_get_hostname(struct debconfclient *client, char **hostname)
{
char *ptr;
static const char *valid_chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
size_t len;
netcfg_get_interface(client, interface);
do {
free(*hostname);
@ -364,7 +359,17 @@ netcfg_get_common(struct debconfclient *client, char **interface,
}
} while (!*hostname);
}
void
netcfg_get_common(struct debconfclient *client, char **interface,
char **hostname, char **domain, char **nameservers)
{
char *ptr;
netcfg_get_interface(client, interface);
netcfg_get_hostname(client, hostname);
free(*domain);
@ -409,15 +414,24 @@ void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[])
void
netcfg_write_common(u_int32_t ipaddress, char *domain, char *hostname,
u_int32_t nameservers[])
netcfg_write_common(const char *prebaseconfig, u_int32_t ipaddress,
char *domain, char *hostname, u_int32_t nameservers[])
{
FILE *fp;
if ((fp = file_open(INTERFACES_FILE, "w"))) {
fprintf(fp, "auto lo\n");
fprintf(fp, "iface lo inet loopback\n");
fclose(fp);
if ((fp = file_open(HOSTS_FILE))) {
fprintf(fp, "127.0.0.1\tlocalhost\n");
di_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
INTERFACES_FILE,
"/target" INTERFACES_FILE);
}
if ((fp = file_open(HOSTS_FILE, "w"))) {
if (ipaddress) {
fprintf(fp, "127.0.0.1\tlocalhost\n");
if (domain)
fprintf(fp, "%s\t%s.%s\t%s\n",
num2dot(ipaddress), hostname,
@ -425,12 +439,17 @@ netcfg_write_common(u_int32_t ipaddress, char *domain, char *hostname,
else
fprintf(fp, "%s\t%s\n", num2dot(ipaddress),
hostname);
}
} else {
fprintf(fp, "127.0.0.1\t%s\tlocalhost\n", hostname);
}
fclose(fp);
di_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
HOSTS_FILE, "/target" HOSTS_FILE);
}
if ((fp = file_open(RESOLV_FILE))) {
if ((fp = file_open(RESOLV_FILE, "w"))) {
int i = 0;
if (domain)
fprintf(fp, "search %s\n", domain);
@ -440,5 +459,8 @@ netcfg_write_common(u_int32_t ipaddress, char *domain, char *hostname,
num2dot(nameservers[i++]));
fclose(fp);
di_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
RESOLV_FILE, "/target" RESOLV_FILE);
}
}

7
netcfg.h

@ -31,7 +31,7 @@ extern void getif_end ();
extern char *get_ifdsc (const char *ifp);
extern FILE *file_open (char *path);
extern FILE *file_open (char *path, const char *opentype);
extern void dot2num (u_int32_t * num, char *dot);
@ -41,11 +41,14 @@ extern void netcfg_die (struct debconfclient *client);
extern void netcfg_get_interface(struct debconfclient *client, char **interface);
extern void netcfg_get_hostname(struct debconfclient *client, char **hostname);
extern void netcfg_get_common (struct debconfclient *client, char **interface,
char **hostname, char **domain,
char **nameservers);
extern void netcfg_write_common (u_int32_t ipaddress, char *domain,
extern void netcfg_write_common (const char *prebaseconfig,
u_int32_t ipaddress, char *domain,
char *hostname, u_int32_t nameservers[]);
void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[]);

1
prebaseconfig

@ -0,0 +1 @@
#!/bin/sh -e
Loading…
Cancel
Save