You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

114 lines
3.5 KiB

  1. /*
  2. netcfg-static.c - Configure a static network for debian-installer
  3. Copyright (C) 2000-2002 David Kimdon <dwhedon@debian.org>
  4. This program 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.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. #include "netcfg.h"
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <sys/types.h>
  22. #include <cdebconf/debconfclient.h>
  23. #include <debian-installer.h>
  24. int main(int argc, char** argv)
  25. {
  26. int num_interfaces = 0;
  27. static struct debconfclient *client;
  28. static int requested_wireless_tools = 0;
  29. struct netcfg_interface interface;
  30. enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT} state = GET_INTERFACE;
  31. /* initialize libd-i */
  32. di_system_init("netcfg-static");
  33. netcfg_interface_init(&interface);
  34. if (strcmp(basename(argv[0]), "ptom") != 0)
  35. di_info("Starting netcfg v.%s", NETCFG_VERSION);
  36. parse_args(argc, argv);
  37. reap_old_files();
  38. open_sockets();
  39. /* initialize debconf */
  40. client = debconfclient_new();
  41. debconf_capb(client, "backup");
  42. while (1) {
  43. switch(state) {
  44. case BACKUP:
  45. return RETURN_TO_MAIN;
  46. case GET_INTERFACE:
  47. if (netcfg_get_interface(client, &(interface.name), &num_interfaces, NULL))
  48. state = BACKUP;
  49. else if (! interface.name || ! num_interfaces)
  50. state = GET_HOSTNAME_ONLY;
  51. else {
  52. if (is_wireless_iface(interface.name))
  53. state = WCONFIG;
  54. else
  55. state = GET_STATIC;
  56. }
  57. break;
  58. case GET_HOSTNAME_ONLY:
  59. if(netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0))
  60. state = BACKUP;
  61. else {
  62. netcfg_write_common("", hostname, NULL);
  63. return 0;
  64. }
  65. break;
  66. case GET_STATIC:
  67. if (netcfg_get_static(client, &interface))
  68. state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;
  69. else
  70. state = QUIT;
  71. break;
  72. case WCONFIG:
  73. if (requested_wireless_tools == 0) {
  74. requested_wireless_tools = 1;
  75. di_exec_shell("apt-install iw wireless-tools");
  76. }
  77. state = WCONFIG_ESSID;
  78. break;
  79. case WCONFIG_ESSID:
  80. if (netcfg_wireless_set_essid (client, &interface))
  81. state = BACKUP;
  82. else
  83. state = WCONFIG_WEP;
  84. break;
  85. case WCONFIG_WEP:
  86. if (netcfg_wireless_set_wep (client, &interface))
  87. state = WCONFIG_ESSID;
  88. else
  89. state = GET_STATIC;
  90. break;
  91. case QUIT:
  92. netcfg_update_entropy();
  93. return 0;
  94. }
  95. }
  96. return 0;
  97. }