]> andersk Git - moira.git/blame_incremental - update/update_test.c
Changes from dtanner.
[moira.git] / update / update_test.c
... / ...
CommitLineData
1/* $Id$
2 *
3 * Test client for update_server protocol.
4 *
5 * Copyright 1992-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 */
9
10#include <mit-copyright.h>
11#include <moira.h>
12#include <update.h>
13
14#include <errno.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18
19void usage(void);
20
21char *whoami;
22
23int main(int argc, char **argv)
24{
25 char *host, *file, *rfile, *ibuf = NULL;
26 int code, i, count = 0, conn;
27
28 whoami = argv[0];
29 mr_init();
30
31 if (argc < 2)
32 usage();
33 host = argv[1];
34
35 conn = mr_connect_internal(host, SERVICE_NAME);
36 if (!conn)
37 {
38 com_err(whoami, errno, ": can't connect to %s:%s", host, SERVICE_NAME);
39 exit(1);
40 }
41
42 code = mr_send_auth(conn, host);
43 if (code)
44 com_err(whoami, code, "attempting authorization");
45
46 for (i = 2; i < argc; i++)
47 {
48 if (argv[i][0] != '-')
49 usage();
50 switch (argv[i][1])
51 {
52 case 's':
53 if (i + 2 >= argc)
54 usage();
55 file = argv[++i];
56 rfile = argv[++i];
57 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
58 mr_send_file(conn, file, rfile, 0);
59 break;
60 case 'S':
61 if (i + 2 >= argc)
62 usage();
63 file = argv[++i];
64 rfile = argv[++i];
65 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
66 file, host, rfile);
67 mr_send_file(conn, file, rfile, 1);
68 break;
69 case 'i':
70 if (i + 1 >= argc)
71 usage();
72 file = argv[++i];
73 ibuf = strdup("/tmp/moira-updateXXXXX");
74 if (!ibuf)
75 {
76 com_err(whoami, ENOMEM, "sending instructions");
77 exit(1);
78 }
79 mktemp(ibuf);
80 fprintf(stderr, "Sending instructions %s to %s as %s\n",
81 file, host, ibuf);
82 mr_send_file(conn, file, ibuf, 0);
83 break;
84 case 'I':
85 if (i + 2 >= argc)
86 usage();
87 file = argv[++i];
88 ibuf = argv[++i];
89 strcpy(ibuf, rfile);
90 fprintf(stderr, "Sending instructions %s to %s as %s\n",
91 file, host, ibuf);
92 mr_send_file(conn, file, ibuf, 0);
93 break;
94 case 'x':
95 if (!ibuf)
96 {
97 fprintf(stderr, "No instructions sent.");
98 usage();
99 }
100 fprintf(stderr, "Executing instructions %s on %s\n", ibuf, host);
101 code = mr_execute(conn, ibuf);
102 if (code)
103 com_err(whoami, code, "executing");
104 break;
105 case 'X':
106 if (i + 1 >= argc)
107 usage();
108 file = argv[++i];
109 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
110 code = mr_execute(conn, file);
111 if (code)
112 com_err(whoami, code, "executing");
113 break;
114 case 'n':
115 break;
116 default:
117 usage();
118 }
119 }
120 mr_send_quit(conn);
121 close(conn);
122 exit(code);
123}
124
125void usage(void)
126{
127 fprintf(stderr, "Usage: test host [commands...]\n");
128 fprintf(stderr, " Commands are:\n");
129 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
130 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
131 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
132 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
133 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
134 fprintf(stderr, "\t-X file\t\texecutes file\n");
135 exit(1);
136}
This page took 0.032081 seconds and 5 git commands to generate.