merge with 0.30.213
[util-vserver.git] / src / vcopy-init.hc
1 // $Id: vcopy-init.hc 1921 2005-03-18 00:24:27Z ensc $    --*- c -*--
2
3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program 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.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19 static void
20 createSkeleton(char const *name)
21 {
22   char const *  app_dir;
23
24   app_dir = vc_getVserverAppDir(name, vcCFG_AUTO, "vunify");
25   if (app_dir==0 &&
26       vc_createSkeleton(name, vcCFG_AUTO, vcSKEL_FILESYSTEM|vcSKEL_PKGMGMT)==-1) {
27     perror("vc_createSkeleton()");
28     exit(1);
29   }
30
31   if (app_dir==0) {
32     app_dir = vc_getVserverAppDir(name, vcCFG_AUTO, "");
33       
34     PathInfo            path = {
35       .d = app_dir,
36       .l = strlen(app_dir),
37     };
38     PathInfo            rhs_path = {
39       .d = "vunify",
40       .l = sizeof("vunify")-1
41     };
42       
43     char                p_buf[ENSC_PI_APPSZ(path, rhs_path)];
44     PathInfo_append(&path, &rhs_path, p_buf);
45
46     Emkdir(path.d, 0755);
47   }
48
49   free(const_cast(char *)(app_dir));
50 }
51
52
53 static void
54 initModeManually(int argc, char *argv[])
55 {
56   int           count=argc/2;
57
58   if (count!=2) {
59     WRITE_MSG(2, "Bad arguments; try '--help' for more information\n");
60     exit(1);
61   }
62
63   MatchList_initManually(&global_info.dst_list, 0, strdup(argv[0]), argv[1]);
64   MatchList_initManually(&global_info.src_list, 0, strdup(argv[2]), argv[3]);
65 }
66
67
68 static void
69 initModeVserver(int argc, char *argv[])
70 {
71   int                                   count       = argc;
72   struct MatchVserverInfo               src_vserver = {
73     .name        = argv[1],
74     .use_pkgmgmt = true
75   };
76
77   if (!MatchVserverInfo_init(&src_vserver)) {
78     WRITE_MSG(2, "Failed to initialize unification for source-vserver\n");
79     exit(1);
80   }
81
82   if (count!=2) {
83     WRITE_MSG(2, "Bad arguments; try '--help' for more information\n");
84     exit(1);
85   }
86
87   if (!MatchList_initByVserver(&global_info.src_list, &src_vserver)) {
88     WRITE_MSG(2, "unification not configured for source vserver\n");
89     exit(1);
90   }
91
92   MatchVserverInfo_free(&src_vserver);
93
94
95   
96   struct MatchVserverInfo               dst_vserver = {
97     .name        = argv[0],
98     .use_pkgmgmt = false
99   };
100   
101   if (!global_args->is_strict)
102     createSkeleton(dst_vserver.name);
103   
104   if (!MatchVserverInfo_init(&dst_vserver)) {
105     WRITE_MSG(2, "Failed to initialize unification for destination-vserver\n");
106     exit(1);
107   }
108   
109   if (!MatchList_initByVserver(&global_info.dst_list, &dst_vserver)) {
110     WRITE_MSG(2, "unification not configured for destination vserver\n");
111     exit(1);
112   }
113
114   MatchVserverInfo_free(&dst_vserver);
115 }