4 * Across-the-wire migration utility for Citadel
6 * Copyright (c) 2009 citadel.org
8 * This program is licensed to you under the terms of the GNU General Public License v3
18 #include <sys/types.h>
20 #include <sys/utsname.h>
28 #include <libcitadel.h>
33 #include "citadel_dirs.h"
41 int main(int argc, char *argv[])
45 char relhome[PATH_MAX]="";
46 char ctdldir[PATH_MAX]=CTDLDIR;
48 char sendcommand[PATH_MAX];
51 char socket_path[PATH_MAX];
52 char remote_user[256];
53 char remote_host[256];
55 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
56 CtdlMakeTempFileName(socket_path, sizeof socket_path);
59 printf( "-------------------------------------------\n"
60 "Over-the-wire migration utility for Citadel\n"
61 "-------------------------------------------\n"
63 "This utility is designed to migrate your Citadel installation\n"
64 "to a new host system via a network connection, without disturbing\n"
65 "the source system. The target may be a different CPU architecture\n"
66 "and/or operating system. The source system should be running\n"
67 "Citadel %d.%02d or newer, and the target system should be running\n"
68 "either the same version or a newer version. You will also need\n"
69 "the 'rsync' utility, and OpenSSH v4 or newer.\n"
71 "You must run this utility on the TARGET SYSTEM. Any existing data\n"
72 "on this system will be ERASED.\n"
74 "Do you wish to continue? "
80 if ((fgets(yesno, sizeof yesno, stdin) == NULL) || (tolower(yesno[0]) != 'y')) {
84 printf("\n\nGreat! First we will check some things out here on our target\n"
85 "system to make sure it is ready to receive data.\n\n");
87 printf("Locating 'sendcommand' and checking connectivity to Citadel...\n");
88 snprintf(sendcommand, sizeof sendcommand, "%s/sendcommand", ctdl_utilbin_dir);
89 snprintf(cmd, sizeof cmd, "%s 'NOOP'", sendcommand);
90 exitcode = system(cmd);
92 printf("\nctdlmigrate was unable to attach to the Citadel server\n"
93 "here on the target system. Is Citadel running?\n\n");
96 printf("\nOK, this side is ready to go. Now we must connect to the source system.\n\n");
98 printf("Enter the host name or IP address of the source system\n"
99 "(example: ctdl.foo.org)\n"
102 printf("\nEnter the name of a user on %s who has full access to Citadel files\n"
103 "(usually root)\n--> ",
107 printf("\nEstablishing an SSH connection to the source system...\n\n");
109 snprintf(cmd, sizeof cmd, "ssh -MNf -S %s %s@%s", socket_path, remote_user, remote_host);
110 exitcode = system(cmd);
112 printf("\nctdlmigrate was unable to establish an SSH connection to the\n"
113 "source system, and cannot continue.\n\n");
117 printf("\nTesting a command over the connection...\n\n");
118 snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s 'echo Remote commands are executing successfully.'",
119 socket_path, remote_user, remote_host);
120 exitcode = system(cmd);
123 printf("Remote commands are not succeeding.\n\n");
129 // FIXME kill the master ssh session
130 printf("If this program was finished we would do more. FIXME\n");