summaryrefslogtreecommitdiff
path: root/test/tinstall.c
blob: 8fd26fa5f53dc339ba223a48342908647fd19bba (plain)
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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include "initd.h"

static void print_sk_list(const initd_list_t *list, initd_sk_t sk);

int main(int argc, char *argv[])
{
	initd_list_t *all, *startlist, *stoplist;
	dep_t *need = dep_new();

	if (argc <= 1)
		dep_add(need, "foo");

	while (argc > 1) {
		dep_add(need, argv[1]);
		argv++;
		argc--;
	}

	all = initd_list_from_dir("init.d");

	initd_recurse_set_verbose(true);
	initd_installrm_set_verbose(true);

	startlist = initd_add_recurse_deps(all, SK_START, need);
	if (startlist) {
		print_sk_list(startlist, SK_START);
	} else {
		fprintf(stderr, "Failed recursing start scripts\n");
		return 1;
	}

	stoplist = initd_add_recurse_deps(all, SK_STOP, need);
	if (stoplist) {
		print_sk_list(stoplist, SK_STOP);
	} else {
		fprintf(stderr, "Failed recursing stop scripts\n");
		return 1;
	}

	initd_installrm_links(startlist, "init.d", SK_START);
	initd_installrm_links(stoplist, "init.d", SK_STOP);

	return 0;
}

static void print_sk_list(const initd_list_t *list, initd_sk_t sk)
{
	char *startstop;
	initd_t *ip;

	switch (sk) {
	case SK_START:
		startstop = "start";
		break;
	case SK_STOP:
		startstop = "stop";
		break;
	default:
		startstop = "";
	}

	if (list && list->first) {
		printf("All deps for %s\n", startstop);
		printf("Ordered:");
		for (ip = list->first; ip; ip = ip->next)
			printf(" %s", ip->name);
		printf("\n");
	} else {
		printf("%s list is empty\n", startstop);
	}
}