]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/install+setup/install/unattended.c
2 * This file is part of the IPFire Firewall.
4 * IPFire is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * IPFire is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with IPFire; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Copyright 2007: Michael Tremer for www.ipfire.org
25 int unattended_setup(struct keyvalue
*unattendedkv
) {
27 struct keyvalue
*mainsettings
= initkeyvalues();
28 struct keyvalue
*ethernetkv
= initkeyvalues();
30 char commandstring
[STRING_SIZE
];
32 char domainname
[STRING_SIZE
];
33 char hostname
[STRING_SIZE
];
34 char keymap
[STRING_SIZE
];
35 char language
[STRING_SIZE
];
36 char timezone
[STRING_SIZE
];
37 char theme
[STRING_SIZE
];
38 char green_address
[STRING_SIZE
];
39 char green_netmask
[STRING_SIZE
];
40 char green_netaddress
[STRING_SIZE
];
41 char green_broadcast
[STRING_SIZE
];
42 char root_password
[STRING_SIZE
];
43 char admin_password
[STRING_SIZE
];
45 findkey(unattendedkv
, "DOMAINNAME", domainname
);
46 findkey(unattendedkv
, "HOSTNAME", hostname
);
47 findkey(unattendedkv
, "KEYMAP", keymap
);
48 findkey(unattendedkv
, "LANGUAGE", language
);
49 findkey(unattendedkv
, "TIMEZONE", timezone
);
50 findkey(unattendedkv
, "THEME", theme
);
51 findkey(unattendedkv
, "GREEN_ADDRESS", green_address
);
52 findkey(unattendedkv
, "GREEN_NETMASK", green_netmask
);
53 findkey(unattendedkv
, "GREEN_NETADDRESS", green_netaddress
);
54 findkey(unattendedkv
, "GREEN_BROADCAST", green_broadcast
);
55 findkey(unattendedkv
, "ROOT_PASSWORD", root_password
);
56 findkey(unattendedkv
, "ADMIN_PASSWORD", admin_password
);
58 /* write main/settings. */
59 replacekeyvalue(mainsettings
, "DOMAINNAME", domainname
);
60 replacekeyvalue(mainsettings
, "HOSTNAME", hostname
);
61 replacekeyvalue(mainsettings
, "KEYMAP", keymap
);
62 replacekeyvalue(mainsettings
, "LANGUAGE", language
);
63 replacekeyvalue(mainsettings
, "TIMEZONE", timezone
);
64 replacekeyvalue(mainsettings
, "THEME", theme
);
65 writekeyvalues(mainsettings
, "/harddisk" CONFIG_ROOT
"/main/settings");
66 freekeyvalues(mainsettings
);
69 fprintf(flog
, "unattended: Starting setup\n");
72 fprintf(flog
, "unattended: setting up network configuration\n");
74 (void) readkeyvalues(ethernetkv
, "/harddisk" CONFIG_ROOT
"/ethernet/settings");
75 replacekeyvalue(ethernetkv
, "GREEN_ADDRESS", green_address
);
76 replacekeyvalue(ethernetkv
, "GREEN_NETMASK", green_netmask
);
77 replacekeyvalue(ethernetkv
, "GREEN_NETADDRESS", green_netaddress
);
78 replacekeyvalue(ethernetkv
, "GREEN_BROADCAST", green_broadcast
);
79 replacekeyvalue(ethernetkv
, "CONFIG_TYPE", "0");
80 replacekeyvalue(ethernetkv
, "GREEN_DEV", "eth0");
81 write_ethernet_configs(ethernetkv
);
82 freekeyvalues(ethernetkv
);
85 unlink("/harddisk/etc/localtime");
86 snprintf(commandstring
, STRING_SIZE
, "/harddisk/%s", timezone
);
87 link(commandstring
, "/harddisk/etc/localtime");
90 fprintf(flog
, "unattended: writing hostname.conf\n");
91 if (!(file
= fopen("/harddisk" CONFIG_ROOT
"/main/hostname.conf", "w")))
93 errorbox("unattended: ERROR writing hostname.conf");
96 fprintf(file
, "ServerName %s.%s\n", hostname
,domainname
);
99 fprintf(flog
, "unattended: writing hosts\n");
100 if (!(hosts
= fopen("/harddisk/etc/hosts", "w")))
102 errorbox("unattended: ERROR writing hosts");
105 fprintf(hosts
, "127.0.0.1\tlocalhost\n");
106 fprintf(hosts
, "%s\t%s.%s\t%s\n", green_address
, hostname
, domainname
, hostname
);
109 fprintf(flog
, "unattended: writing hosts.allow\n");
110 if (!(file
= fopen("/harddisk/etc/hosts.allow", "w")))
112 errorbox("unattended: ERROR writing hosts.allow");
115 fprintf(file
, "sshd : ALL\n");
116 fprintf(file
, "ALL : localhost\n");
117 fprintf(file
, "ALL : %s/%s\n", green_netaddress
, green_netmask
);
120 fprintf(flog
, "unattended: writing hosts.deny\n");
121 if (!(file
= fopen("/harddisk/etc/hosts.deny", "w")))
123 errorbox("unattended: ERROR writing hosts.deny");
126 fprintf(file
, "ALL : ALL\n");
129 /* set root password */
130 fprintf(flog
, "unattended: setting root password\n");
131 snprintf(commandstring
, STRING_SIZE
,
132 "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password
);
133 if (mysystem(commandstring
)) {
134 errorbox("unattended: ERROR setting root password");
138 /* set admin password */
139 fprintf(flog
, "unattended: setting admin password\n");
140 snprintf(commandstring
, STRING_SIZE
,
141 "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT
"/auth/users admin '%s'", admin_password
);
142 if (mysystem(commandstring
)) {
143 errorbox("unattended: ERROR setting admin password");
147 fprintf(flog
, "unattended: Setup ended\n");