File: suite_action.c

package info (click to toggle)
cdebootstrap 0.3.4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 816 kB
  • ctags: 308
  • sloc: sh: 3,408; ansic: 2,522; makefile: 243
file content (233 lines) | stat: -rw-r--r-- 7,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * suite.c
 *
 * Copyright (C) 2003 Bastian Blank <waldi@debian.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * $LastChangedBy: bastian $
 * $LastChangedDate: 2005-01-14 22:34:27 +0100 (Fr, 14 Jan 2005) $
 * $LastChangedRevision: 806 $
 */

#include <config.h>

#include "execute.h"
#include "frontend.h"
#include "install.h"
#include "packages.h"
#include "suite.h"
#include "suite_action.h"
#include "suite_config.h"

#include <debian-installer.h>

static di_slist *cur_list;
static di_package_priority cur_list_priority;

typedef int suite_install_action (suite_config_action *action, int data, di_packages *packages, di_packages_allocator *allocator, di_slist *install);

static int action_execute (suite_config_action *action, int data __attribute__ ((unused)), di_packages *packages __attribute__ ((unused)), di_packages_allocator *allocator __attribute__ ((unused)), di_slist *install __attribute__ ((unused)))
{
  return install_helper_execute (action->what);
}

static di_package_priority action_check_priority (const char *text)
{
  if (text)
    return di_package_priority_text_from (text);
  return 0;
}

static void action_check_priority_list (di_package_priority priority, di_packages *packages, di_packages_allocator *allocator, di_slist *install)
{
  if (cur_list_priority != priority)
  {
    if (cur_list)
      di_slist_free (cur_list);
    cur_list = install_list (packages, allocator, install, priority, di_package_status_installed);
    cur_list_priority = priority;
  }
}

enum action_install
{
  ACTION_INSTALL_APT_INSTALL,
  ACTION_INSTALL_DPKG_CONFIGURE,
  ACTION_INSTALL_DPKG_INSTALL,
  ACTION_INSTALL_DPKG_UNPACK,
  ACTION_INSTALL_EXTRACT,
};

static int action_install (suite_config_action *action, int _data, di_packages *packages, di_packages_allocator *allocator, di_slist *install)
{
  enum action_install data = _data;

  int force = action->flags && SUITE_CONFIG_ACTION_FLAG_FORCE;
  int only = action->flags && SUITE_CONFIG_ACTION_FLAG_ONLY;
  di_package_priority priority;
  di_slist *list;
  int cleanup = 0;

  if (data == ACTION_INSTALL_EXTRACT)
    priority = di_package_priority_required;
  else if (action->what)
    priority = action_check_priority (action->what);
  else
    priority = di_package_priority_extra;
  action_check_priority_list (priority, packages, allocator, install);

  if (priority)
    list = cur_list;
  else if (action->what)
  {
    if (only)
      list = install_list_package_only (packages, action->what, di_package_status_installed);
    else
      list = install_list_package (packages, allocator, action->what, di_package_status_installed);
    cleanup = 1;
  }
  else if (data == ACTION_INSTALL_DPKG_CONFIGURE)
    list = NULL;
  else
    return 0;

  switch (data)
  {
    case ACTION_INSTALL_APT_INSTALL:
      return install_apt_install (packages, list);

    case ACTION_INSTALL_DPKG_CONFIGURE:
      return install_dpkg_configure (packages, force);

    case ACTION_INSTALL_DPKG_INSTALL:
      return install_dpkg_install (packages, list, force);

    case ACTION_INSTALL_DPKG_UNPACK:
      return install_dpkg_unpack (packages, list);

    case ACTION_INSTALL_EXTRACT:
      return install_extract (list);
  }
  
  if (cleanup)
    di_slist_free (list);

  return 0;
}

enum action_helper
{
  ACTION_HELPER_INSTALL,
  ACTION_HELPER_REMOVE,
};

static int action_helper (suite_config_action *action __attribute__ ((unused)), int data, di_packages *packages __attribute__ ((unused)), di_packages_allocator *allocator __attribute__ ((unused)), di_slist *install __attribute__ ((unused)))
{
  switch (data)
  {
    case ACTION_HELPER_INSTALL:
      return install_helper_install (action->what);
    case ACTION_HELPER_REMOVE:
      return install_helper_remove (action->what);
  };
  return 0;
}

static int action_mount (suite_config_action *action __attribute__ ((unused)), int data __attribute__ ((unused)), di_packages *packages __attribute__ ((unused)), di_packages_allocator *allocator __attribute__ ((unused)), di_slist *install __attribute__ ((unused)))
{
  if (install_mount_proc ())
    log_text (DI_LOG_LEVEL_ERROR, "can't mount proc");
  return 0;
}

enum action_prepare
{
  ACTION_PREPARE_APT_PREPARE,
  ACTION_PREPARE_DEV_PREPARE,
  ACTION_PREPARE_APT_CLEANUP,
  ACTION_PREPARE_DEV_CLEANUP,
};


static int action_prepare (suite_config_action *action __attribute__ ((unused)), int data, di_packages *packages __attribute__ ((unused)), di_packages_allocator *allocator __attribute__ ((unused)), di_slist *install __attribute__ ((unused)))
{
  switch (data)
  {
    case ACTION_PREPARE_APT_PREPARE:
      return install_apt_prepare ();
    case ACTION_PREPARE_DEV_PREPARE:
      return install_dev_prepare ();
    case ACTION_PREPARE_APT_CLEANUP:
      return install_apt_cleanup ();
    case ACTION_PREPARE_DEV_CLEANUP:
      return install_dev_cleanup ();
  };
  return 0;
}

static struct suite_install_actions
{
  char *name;
  suite_install_action *action;
  int data;
}
suite_install_actions[] =
{
  { "apt-cleanup", action_prepare, ACTION_PREPARE_APT_CLEANUP },
  { "apt-install", action_install, ACTION_INSTALL_APT_INSTALL },
  { "apt-prepare", action_prepare, ACTION_PREPARE_APT_PREPARE },
  { "dev-cleanup", action_prepare, ACTION_PREPARE_DEV_CLEANUP },
  { "dev-prepare", action_prepare, ACTION_PREPARE_DEV_PREPARE },
  { "dpkg-configure", action_install, ACTION_INSTALL_DPKG_CONFIGURE },
  { "dpkg-install", action_install, ACTION_INSTALL_DPKG_INSTALL },
  { "dpkg-unpack", action_install, ACTION_INSTALL_DPKG_UNPACK },
  { "execute", action_execute, 0 },
  { "extract", action_install, ACTION_INSTALL_EXTRACT },
  { "helper-install", action_helper, ACTION_HELPER_INSTALL },
  { "helper-remove", action_helper, ACTION_HELPER_REMOVE },
  { "mount", action_mount, 0 },
  { NULL, NULL, 0 },
};

int suite_action (di_packages *packages, di_packages_allocator *allocator, di_slist *install)
{
  di_slist_node *node;
  struct suite_install_actions *action;

  for (node = suite->actions.head; node; node = node->next)
  {
    suite_config_action *e = node->data;

    if (!e->activate)
      continue;

    for (action = suite_install_actions; action->name; action++)
      if (!strcasecmp (action->name, e->action))
        break;

    if (action->name)
    {
      log_text (DI_LOG_LEVEL_DEBUG, "call action: %s", e->action);
      if (action->action (e, action->data, packages, allocator, install))
        return 1;
    }
    else
      log_text (DI_LOG_LEVEL_WARNING, "unknown action: %s", e->action);
  }

  return 0;
}