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