Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 magnus 1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 25_pmksetup.dpatch by Magnus Holmgren <magnus@kibibyte.se>
3
##
4
## DP: Adds -s parameter to pmksetup, which outputs config to standard
5
## DP: output, as well as -g, which forces data gathering to take place
6
## DP: immediately.
7
 
8
@DPATCH@
9
 
10
--- pmk-0.10.1.orig/pmksetup.h
11
+++ pmk-0.10.1/pmksetup.h
12
@@ -85,7 +85,7 @@
13
 #define	ECHO_NL		"\\n"
14
 #define	ECHO_HT		"\\t"
15
 
16
-#define PMKSTP_OPT_STR	"hr:u:vV"	/* "a:hr:u:vV" */
17
+#define PMKSTP_OPT_STR	"ghr:su:vV"	/* "a:hr:u:vV" */
18
 
19
 #define EMSG_PRIV_FMT	"Failed to change privilege (%s)"
20
 
21
--- pmk-0.10.1.orig/pmksetup.c
22
+++ pmk-0.10.1/pmksetup.c
23
@@ -66,6 +66,7 @@
24
 extern int	 optind;
25
 
26
 FILE		*sfp;			/* scratch file pointer */
27
+bool		 tostdout = false;
28
 char		 sfn[MAXPATHLEN];	/* scratch file name */
29
 
30
 htable		*ht;
31
@@ -154,7 +155,7 @@
32
  ***********************************************************************/
33
 
34
 bool gather_data(htable *pht) {
35
-	printf("==> Looking for default parameters...\n");
36
+	fprintf(stderr, "==> Looking for default parameters...\n");
37
 
38
 	/* gather env variables */
39
 	if (get_env_vars(pht) == false) {
40
@@ -850,7 +851,7 @@
41
 		vsnprintf(buf, sizeof(buf), fmt, plst);
42
 		va_end(plst);
43
 
44
-		printf("%s\n", buf);
45
+		fprintf(stderr, "%s\n", buf);
46
 	}
47
 }
48
 
49
@@ -883,6 +884,13 @@
50
 	optind = 1;
51
 	while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) {
52
 		switch(ch) {
53
+			case 'g' :
54
+				if (gather_data(ht) == false)
55
+					return(false);
56
+
57
+				process_clopts = true;
58
+				break;
59
+
60
 			case 'r' :
61
 				/* mark to be deleted in hash */
62
 				if (record_data(ht, optarg, PMKSTP_REC_REMV, NULL) == false) {
63
@@ -932,6 +940,7 @@
64
 				process_clopts = true;
65
 				break;
66
 
67
+			case 's' :
68
 			case 'v' :
69
 			case 'V' :
70
 				/*
71
@@ -949,11 +958,11 @@
72
 	argc -= optind;
73
 	argv += optind;
74
 
75
-	printf("PMKSETUP version %s", PREMAKE_VERSION);
76
+	fprintf(stderr, "PMKSETUP version %s", PREMAKE_VERSION);
77
 #ifdef DEBUG
78
-	printf(" [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP);
79
+	fprintf(stderr, " [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP);
80
 #endif /* DEBUG */
81
-	printf("\n\n");
82
+	fprintf(stderr, "\n\n");
83
 
84
 	if (process_clopts == false) {
85
 		/* standard behavior, gathering data */
86
@@ -967,7 +976,7 @@
87
 		/* switch backup flag */
88
 		cfg_backup = true;
89
 
90
-		printf("==> Configuration file found: %s\n",
91
+		fprintf(stderr, "==> Configuration file found: %s\n",
92
 						PREMAKE_CONFIG_PATH);
93
 		if (parse_pmkconf(config, ht, PRS_PMKCONF_SEP,
94
 						check_opt) == false) {
95
@@ -978,10 +987,10 @@
96
 			fclose(config);
97
 		}
98
 	} else {
99
-		printf("==> Configuration file not found.\n");
100
+		fprintf(stderr, "==> Configuration file not found.\n");
101
 	}
102
 
103
-	printf("==> Merging remaining data...\n");
104
+	fprintf(stderr, "==> Merging remaining data...\n");
105
 	/* writing the remaining data stored in the hash */
106
 	if (write_new_data(ht) == false)
107
 		return(false);
108
@@ -1099,6 +1108,9 @@
109
 	/* if child status is ok, writing changes */
110
 	if (status == 0) {
111
 #endif
112
+		if (tostdout) {
113
+			return;
114
+	  	}
115
 		/*
116
 		 * check if pmk.conf already exists
117
 		 * NOTE: no race condition here for access(), BUT
118
@@ -1106,7 +1118,7 @@
119
 		 */
120
 		if (access(PREMAKE_CONFIG_PATH, F_OK) == 0) { /* see above */
121
 			/* backup configuration file */
122
-			printf("==> Backing up configuration file: %s\n",
123
+			fprintf(stderr, "==> Backing up configuration file: %s\n",
124
 						PREMAKE_CONFIG_PATH_BAK);
125
 
126
 			if (rename(PREMAKE_CONFIG_PATH,
127
@@ -1118,7 +1130,7 @@
128
 		}
129
 
130
 		/* copying the temporary config to the system one */
131
-		printf("==> Saving configuration file: %s\n",
132
+		fprintf(stderr, "==> Saving configuration file: %s\n",
133
 						PREMAKE_CONFIG_PATH);
134
 		if (fcopy(sfn, PREMAKE_CONFIG_PATH,
135
 					PREMAKE_CONFIG_MODE) == false) {
136
@@ -1165,7 +1177,7 @@
137
  ***********************************************************************/
138
 
139
 void usage(void) {
140
-	fprintf(stderr, "usage: pmksetup [-hVv] "
141
+	fprintf(stderr, "usage: pmksetup [-hsVv] "
142
 		"[-r variable] [-u variable=value]\n");
143
 	exit(EXIT_FAILURE);
144
 }
145
@@ -1188,6 +1200,7 @@
146
 	optind = 1;
147
 	while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) {
148
 		switch(ch) {
149
+			case 'g' :
150
 			case 'r' :
151
 			case 'u' :
152
 				/*
153
@@ -1206,6 +1219,10 @@
154
 					verbose_flag = 1;
155
 				break;
156
 
157
+			case 's':
158
+				tostdout = true;
159
+				break;
160
+
161
 			case '?' :
162
 			default :
163
 				usage();
164
@@ -1213,7 +1230,6 @@
165
 		}
166
 	}
167
 
168
-
169
 	if (getuid() == 0) {
170
 #ifdef PMKSETUP_DEBUG
171
 		debugf("PRIVSEP_USER = '%s'", PRIVSEP_USER);
172
@@ -1227,22 +1243,27 @@
173
 		gid = pw->pw_gid;
174
 	}
175
 
176
-	/* check if syconfdir exists */
177
-	if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */
178
-		verbosef("==> Creating '%s' directory.", CONFDIR);
179
-		if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP |
180
-						S_IROTH | S_IXOTH) != 0) {
181
-			errorf("cannot create '%s' directory : %s.",
182
-						CONFDIR, strerror(errno));
183
-			exit(EXIT_FAILURE);
184
-		}
185
+	if (tostdout) {
186
+		sfp = stdout;
187
 	}
188
+	else {
189
+		/* check if syconfdir exists */
190
+		if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */
191
+			verbosef("==> Creating '%s' directory.", CONFDIR);
192
+			if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP |
193
+							   S_IROTH | S_IXOTH) != 0) {
194
+				errorf("cannot create '%s' directory : %s.",
195
+							CONFDIR, strerror(errno));
196
+				exit(EXIT_FAILURE);
197
+			}
198
+		}
199
 
200
-	sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn));
201
-	if (sfp == NULL) {
202
-		errorf("cannot open temporary file '%s' : %s.",
203
-				sfn, strerror(errno));
204
-		exit(EXIT_FAILURE);
205
+		sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn));
206
+		if (sfp == NULL) {
207
+			errorf("cannot open temporary file '%s' : %s.",
208
+					sfn, strerror(errno));
209
+			exit(EXIT_FAILURE);
210
+		}
211
 	}
212
 
213
 #ifndef WITHOUT_FORK