]> git.sven.stormbind.net Git - sven/java-package.git/blob - make-jpkg
Suggest openjdk-8-jre instead of openjdk-7-jre
[sven/java-package.git] / make-jpkg
1 #! /bin/bash -e
2
3 shopt -s nullglob
4
5 ### global variables
6
7 # version of this package
8 version="@VERSION@"
9
10 working_dir="$( pwd )"
11 program_name="$( basename "$0" )"
12 program_dir="$( cd "$( dirname "$( type -p "$0" )" )" ; pwd )"
13
14 lib_dir="/usr/share/java-package"
15 [ "$J2SE_PACKAGE_LIBDIR" ] && lib_dir="$J2SE_PACKAGE_LIBDIR"
16
17 # If a default has been set for either of the
18 # environment variables, use it; otherwise,
19 # default to the name and email used by the
20 # Debian Java Maintainers project.
21 if [ -z "$J2SE_PACKAGE_FULL_NAME" ]; then
22     maintainer_name="Debian Java Maintainers"
23 else
24     maintainer_name="$J2SE_PACKAGE_FULL_NAME"
25 fi
26
27 if [ -z "$J2SE_PACKAGE_EMAIL" ]; then
28     maintainer_email="pkg-java-maintainers@lists.alioth.debian.org"
29 else
30     maintainer_email="$J2SE_PACKAGE_EMAIL"
31 fi
32
33 genchanges=""
34 build_source=""
35 jce_archive=""
36
37 ### check for run in fakeroot
38
39 # are we running as fakeroot
40 if ! dh_testroot >/dev/null 2>&1; then
41     if [ -n "$FAKEROOTKEY" ]; then
42         echo "Internal error, fakeroot seems to fail faking root" >&2
43         exit 1
44     fi
45     exec fakeroot "$0" "$@"
46 fi
47
48 # check whether I'm real root, and bail out if so... ugly, but needed
49 if touch /lib/.test 2>/dev/null; then
50     rm -f /lib/.test
51     echo "You are real root -- unfortunately, some Java distributions have" >&2
52     echo "install scripts that directly manipulate /etc, and may cause some" >&2
53     echo "inconsistencies on your system. Instead, you should become a" >&2
54     echo "non-root user and run:" >&2
55     echo >&2
56     echo "fakeroot make-jpkg $@" >&2
57     echo >&2
58     echo "which will allow no damage to be done to your system files and" >&2
59     echo "still permit the Java distribution to successfully extract." >&2
60     echo >&2
61     echo "Aborting." >&2
62     exit 1
63 fi
64
65
66 ### Parse options
67
68 print_usage() {
69     cat << EOF
70 Usage: $program_name [OPTION]... FILE
71
72 $program_name builds a Debian package from the given Java binary distribution FILE
73
74 Supported java binary distributions currently include:
75   * Oracle (http://www.oracle.com/technetwork/java/javase/downloads) :
76     - The Java Development Kit (JDK), version 6, 7 and 8
77     - The Java Runtime Environment (JRE), version 6, 7 and 8
78     - The Java API Javadoc, version 6, 7 and 8
79   (Choose tar.gz archives or self-extracting archives, do _not_ choose the RPM!)
80
81 The following options are recognized:
82
83   --full-name NAME     full name used in the maintainer field of the package
84   --email EMAIL        email address used in the maintainer field of the package
85   --distribution DIST  Define the distribution to use in the changelog
86   --priority PRIORITY  Override default package priority
87   --changes            create a .changes file
88   --revision           add debian revision
89   --source             build a source package instead of a binary deb package
90   --with-system-certs  integrate with the system's keystore
91   --jce-policy FILE    Replace cryptography files with versions from FILE
92
93   --help               display this help and exit
94   --version            output version information and exit
95
96 EOF
97 }
98
99 unrecognized_option() {
100     cat >&2 << EOF
101 $program_name: unrecognized option \`$1'
102 Try \`$program_name --help' for more information.
103 EOF
104     exit 1
105 }
106
107 missing_argument() {
108     cat >&2 << EOF
109 $program_name: missing argument for option \`$1'
110 Try \`$program_name --help' for more information.
111 EOF
112     exit 1
113 }
114
115 # options
116 while [[ $# -gt 0 && "x$1" == x--* ]]; do
117     if [[ "x$1" == x--version ]]; then
118     echo "make-jpkg $version"
119     exit 0
120     elif [[ "x$1" == x--help ]]; then
121     print_usage
122     exit 0
123     elif [[ "x$1" == x--jce-policy ]]; then
124     [ $# -le 1 ] && missing_argument "$1"
125     shift
126     jce_archive="$1"
127     elif [[ "x$1" == x--full-name ]]; then
128     [ $# -le 1 ] && missing_argument "$1"
129     shift
130     maintainer_name="$1"
131     elif [[ "x$1" == x--email ]]; then
132     [ $# -le 1 ] && missing_argument "$1"
133     shift
134     maintainer_email="$1"
135     elif [[ "x$1" == x--distribution ]]; then
136     [ $# -le 1 ] && missing_argument "$1"
137     shift
138     distribution="$1"
139     elif [[ "x$1" == x--priority ]]; then
140     [ $# -le 1 ] && missing_argument "$1"
141     shift
142     priority_override="$1"
143     elif [[ "x$1" == x--revision ]]; then
144     [ $# -le 1 ] && missing_argument "$1"
145     shift
146     revision="-${1}"
147     elif [[ "x$1" == x--changes ]]; then
148     genchanges="true"
149     elif [[ "x$1" == x--source ]]; then
150     build_source="true"
151     elif [[ "x$1" == x--with-system-certs ]]; then
152     create_cert_softlinks="true"
153     else
154     unrecognized_option "$1"
155     fi
156     shift
157 done
158
159 # last argument
160 if [[ $# -ne 1 ]]; then
161     cat >&2 << EOF
162 $program_name: missing pathname
163 Try \`$program_name --help' for more information.
164 EOF
165     exit 1
166 fi
167 archive="$1"
168
169 if [[ ! -e "$archive" ]]; then
170     echo "Error: The file \"$archive\" does not exist."
171     exit 1
172 elif [[ ! -r "$archive" ]]; then
173     echo "Error: The file \"$archive\" is not readable."
174     exit 1
175 fi
176
177 archive_name="$( basename "$archive" )"
178 archive_dir="$( cd "$( dirname "$archive" )" ; pwd )"
179 archive_path="$archive_dir/$archive_name"
180
181 jce_name="$( basename "$jce_archive" )"
182 jce_dir="$( cd "$( dirname "$jce_archive" )" ; pwd )"
183 jce_path="$jce_dir/$jce_name"
184
185 # error handling
186
187 success=
188 failed=
189 tmp=
190
191 # function is called when script terminates
192 on_exit() {
193     lastcmd="$_"
194     if [[ -z "$success" && -z "$failed" ]]; then
195     cat >&2 << EOF
196
197 Aborted ($lastcmd).
198
199 EOF
200     fi
201     # remove temporary directory
202     if [ -n "$tmp" -a -d "$tmp" ]; then
203     echo -n "Removing temporary directory: "
204     rm -rf "$tmp"
205     echo "done"
206     fi
207 }
208 trap on_exit EXIT
209
210 # print error message and terminate
211 error_exit() {
212     cat >&2 << EOF
213
214 Aborted.
215
216 EOF
217     failed=true
218     exit 1
219 }
220
221
222
223 # The environment variable tmp points to a secure temporary directory.
224 # There should be enough free disk space.
225 echo -n "Creating temporary directory: "
226 tmp="$( mktemp -d -t "$program_name.XXXXXXXXXX" )"
227 echo "$tmp"
228
229 package_dir="$tmp/package"
230 install -d -m 755 "$package_dir"
231
232 debian_dir="$package_dir/debian"
233 install -d -m 755 "$debian_dir"
234
235 # load and execute plugins
236 echo -n "Loading plugins:"
237 files=($lib_dir/*.sh)
238 for file in "${files[@]}"; do
239     echo -n " $file"
240     source "$file"
241 done
242
243 echo
244
245 # get architecture information
246 get_architecture
247
248 # get browser plugin directories
249 get_browser_plugin_dirs
250
251 jvm_base="/usr/lib/jvm/"
252 javadoc_base="/usr/share/doc/"
253
254 j2se_found=
255 for var in ${!j2se_detect_*}; do
256     eval "\$$var"
257     if [[ "$j2se_found" == "true" ]]; then
258     break;
259     fi
260 done
261 echo
262
263 if [[ -z "$j2se_found" ]]; then
264     echo "No matching packaging method was found for $archive_name."
265     echo "Please make sure you are using a tar.gz or a self-extracting archive"
266 fi
267
268
269
270 ### exit
271 success=true
272 exit 0