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