forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenRPM.java
More file actions
117 lines (106 loc) · 3.18 KB
/
Copy pathGenRPM.java
File metadata and controls
117 lines (106 loc) · 3.18 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package javaforce.utils;
/** GenRPM
*
* Generates RedHat .rpm files.
*
* @author pquiring
*/
import java.io.*;
import javaforce.*;
public class GenRPM {
private BuildTools tools;
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage:GenRPM build.xml");
System.exit(1);
}
try {
new GenRPM().run(args[0]);
} catch (Exception e) {
JFLog.log(e);
}
}
public void run(String buildfile) throws Exception {
tools = new BuildTools();
if (!tools.loadXML(buildfile)) throw new Exception("error loading " + buildfile);
String files = "files.lst";
if (new File("files-fedora.lst").exists()) {
files = "files-fedora.lst";
}
if (!BuildTools.checkFiles(files)) {
System.exit(1);
}
String arch = getArch();
String archext = getArchExt();
String app = tools.getProperty("app");
String apptype = tools.getProperty("apptype");
String version = tools.getProperty("version");
String home = tools.getProperty("home");
switch (apptype) {
case "client":
case "server":
apptype = "-" + apptype;
break;
default:
apptype = "";
break;
}
String out = app + apptype + "-" + version + "-1." + archext + ".rpm";
String data = "data.tar.bz2";
String tmpdir = "/tmp/jfrpm.tmp";
Runtime rt = Runtime.getRuntime();
Process p;
boolean debug = System.getenv("DEBUG") != null;
try {
GenPkgInfo.main(new String[] {"fedora", arch, files});
JF.copyAllAppend(files, "rpm.spec");
if (new File(data).exists()) {
new File(data).delete();
}
rt.exec(new String[] {"tar", "cjf", data, "-T", files}).waitFor();
if (new File(out).exists()) {
new File(out).delete();
}
new File(tmpdir).mkdir();
rt.exec(new String[] {"tar", "xjf", data, "-C", tmpdir}).waitFor();
new File(data).delete();
//Warning : rpmbuild nukes the buildroot
p = rt.exec(new String[] {"rpmbuild", "-bb", "rpm.spec", "--buildroot", tmpdir});
p.waitFor();
if (debug) {
System.out.println(new String(JF.readAll(p.getInputStream())));
}
if (!debug) {
JF.deletePathEx(tmpdir);
new File("rpm.spec").delete();
}
rt.exec(new String[] {"mv", JF.getUserPath() + "/rpmbuild/RPMS/" + archext + "/" + out, "."}).waitFor();
System.out.println(out + " created!");
if (new File(home + "/repo/fedora/readme.txt").exists()) {
if (!JF.moveFile(out, home + "/repo/fedora/" + archext + "/" + out)) throw new Exception("move failed");
}
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public static String getArch() {
String arch = System.getenv("HOSTTYPE");
if (arch == null) {
arch = System.getProperty("os.arch");
if (arch == null) {
JFLog.log("Error:Unable to detect CPU from env:HOSTTYPE or property:os.arch");
}
}
//fedora uses GNU names
switch (arch) {
case "amd64": return "x86_64";
case "arm64": return "aarch64";
}
return arch;
}
public static String getArchExt() {
return getArch();
}
}