]>
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
];
44 char restore_file
[STRING_SIZE
] = "";
46 findkey(unattendedkv
, "DOMAINNAME", domainname
);
47 findkey(unattendedkv
, "HOSTNAME", hostname
);
48 findkey(unattendedkv
, "KEYMAP", keymap
);
49 findkey(unattendedkv
, "LANGUAGE", language
);
50 findkey(unattendedkv
, "TIMEZONE", timezone
);
51 findkey(unattendedkv
, "THEME", theme
);
52 findkey(unattendedkv
, "GREEN_ADDRESS", green_address
);
53 findkey(unattendedkv
, "GREEN_NETMASK", green_netmask
);
54 findkey(unattendedkv
, "GREEN_NETADDRESS", green_netaddress
);
55 findkey(unattendedkv
, "GREEN_BROADCAST", green_broadcast
);
56 findkey(unattendedkv
, "ROOT_PASSWORD", root_password
);
57 findkey(unattendedkv
, "ADMIN_PASSWORD", admin_password
);
58 findkey(unattendedkv
, "RESTORE_FILE", restore_file
);
60 /* write main/settings. */
61 replacekeyvalue(mainsettings
, "DOMAINNAME", domainname
);
62 replacekeyvalue(mainsettings
, "HOSTNAME", hostname
);
63 replacekeyvalue(mainsettings
, "KEYMAP", keymap
);
64 replacekeyvalue(mainsettings
, "LANGUAGE", language
);
65 replacekeyvalue(mainsettings
, "TIMEZONE", timezone
);
66 replacekeyvalue(mainsettings
, "THEME", theme
);
67 writekeyvalues(mainsettings
, "/harddisk" CONFIG_ROOT
"/main/settings");
68 freekeyvalues(mainsettings
);
71 fprintf(flog
, "unattended: Starting setup\n");
74 fprintf(flog
, "unattended: setting up network configuration\n");
76 (void) readkeyvalues(ethernetkv
, "/harddisk" CONFIG_ROOT
"/ethernet/settings");
77 replacekeyvalue(ethernetkv
, "GREEN_ADDRESS", green_address
);
78 replacekeyvalue(ethernetkv
, "GREEN_NETMASK", green_netmask
);
79 replacekeyvalue(ethernetkv
, "GREEN_NETADDRESS", green_netaddress
);
80 replacekeyvalue(ethernetkv
, "GREEN_BROADCAST", green_broadcast
);
81 replacekeyvalue(ethernetkv
, "CONFIG_TYPE", "0");
82 replacekeyvalue(ethernetkv
, "GREEN_DEV", "eth0");
83 write_ethernet_configs(ethernetkv
);
84 freekeyvalues(ethernetkv
);
87 unlink("/harddisk/etc/localtime");
88 snprintf(commandstring
, STRING_SIZE
, "/harddisk/%s", timezone
);
89 link(commandstring
, "/harddisk/etc/localtime");
92 fprintf(flog
, "unattended: writing hostname.conf\n");
93 if (!(file
= fopen("/harddisk" CONFIG_ROOT
"/main/hostname.conf", "w")))
95 errorbox("unattended: ERROR writing hostname.conf");
98 fprintf(file
, "ServerName %s.%s\n", hostname
,domainname
);
101 fprintf(flog
, "unattended: writing hosts\n");
102 if (!(hosts
= fopen("/harddisk/etc/hosts", "w")))
104 errorbox("unattended: ERROR writing hosts");
107 fprintf(hosts
, "127.0.0.1\tlocalhost\n");
108 fprintf(hosts
, "%s\t%s.%s\t%s\n", green_address
, hostname
, domainname
, hostname
);
111 fprintf(flog
, "unattended: writing hosts.allow\n");
112 if (!(file
= fopen("/harddisk/etc/hosts.allow", "w")))
114 errorbox("unattended: ERROR writing hosts.allow");
117 fprintf(file
, "sshd : ALL\n");
118 fprintf(file
, "ALL : localhost\n");
119 fprintf(file
, "ALL : %s/%s\n", green_netaddress
, green_netmask
);
122 fprintf(flog
, "unattended: writing hosts.deny\n");
123 if (!(file
= fopen("/harddisk/etc/hosts.deny", "w")))
125 errorbox("unattended: ERROR writing hosts.deny");
128 fprintf(file
, "ALL : ALL\n");
131 /* set root password */
132 fprintf(flog
, "unattended: setting root password\n");
133 snprintf(commandstring
, STRING_SIZE
,
134 "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password
);
135 if (mysystem(commandstring
)) {
136 errorbox("unattended: ERROR setting root password");
140 /* set admin password */
141 fprintf(flog
, "unattended: setting admin password\n");
142 snprintf(commandstring
, STRING_SIZE
,
143 "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT
"/auth/users admin '%s'", admin_password
);
144 if (mysystem(commandstring
)) {
145 errorbox("unattended: ERROR setting admin password");
150 if (strlen(restore_file
) > 0) {
151 fprintf(flog
, "unattended: Restoring Backup\n");
152 snprintf(commandstring
, STRING_SIZE
,
153 "cd /harddisk && /bin/tar -xvz --preserve -f /harddisk/var/ipfire/%s", restore_file
);
154 if (mysystem(commandstring
)) {
155 errorbox("unattended: ERROR restoring backup");
159 fprintf(flog
, "unattended: Setup ended\n");