]> git.sven.stormbind.net Git - sven/java-package.git/blob - make-jpkg
5a788db11f5795e0300956ddd6d62b6c6d64032b
[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 Debian packages from Java binary distributions.
71
72   --full-name NAME   full name used in the maintainer field of the package
73   --email EMAIL      email address used in the maintainer field of the package
74   --changes          create a .changes file
75   --revision         add debian revision
76
77   --help             display this help and exit
78   --version          output version information and exit
79
80 EOF
81 }
82
83 unrecognized_option() {
84     cat >&2 << EOF
85 $program_name: unrecognized option \`$1'
86 Try \`$program_name --help' for more information.
87 EOF
88     exit 1
89 }
90
91 missing_argument() {
92     cat >&2 << EOF
93 $program_name: missing argument for option \`$1'
94 Try \`$program_name --help' for more information.
95 EOF
96     exit 1
97 }
98
99 # options
100 while [[ $# -gt 0 && "x$1" == x--* ]]; do
101     if [[ "x$1" == x--version ]]; then
102         echo "make-jpkg $version"
103         exit 0
104     elif [[ "x$1" == x--help ]]; then
105         print_usage
106         exit 0
107     elif [[ "x$1" == x--full-name ]]; then
108         [ $# -le 1 ] && missing_argument "$1"
109         shift
110         maintainer_name="$1"
111     elif [[ "x$1" == x--email ]]; then
112         [ $# -le 1 ] && missing_argument "$1"
113         shift
114         maintainer_email="$1"
115     elif [[ "x$1" == x--revision ]]; then
116         [ $# -le 1 ] && missing_argument "$1"
117         shift
118         revision="-${1}"
119     elif [[ "x$1" == x--changes ]]; then
120         genchanges="true"
121     else
122         unrecognized_option "$1"
123     fi
124     shift
125 done
126
127 # last argument
128 if [[ $# -ne 1 ]]; then
129     cat >&2 << EOF
130 $program_name: missing pathname
131 Try \`$program_name --help' for more information.
132 EOF
133     exit 1
134 fi
135 archive="$1"
136
137 if [[ ! -e "$archive" ]]; then
138     echo "Error: The file \"$archive\" does not exist."
139     exit 1
140 elif [[ ! -r "$archive" ]]; then
141     echo "Error: The file \"$archive\" is not readable."
142     exit 1
143 fi
144
145 archive_name="$( basename "$archive" )"
146 archive_dir="$( cd "$( dirname "$archive" )" ; pwd )"
147 archive_path="$archive_dir/$archive_name"
148
149
150 # error handling
151
152 success=
153 failed=
154 tmp=
155
156 # function is called when script terminates
157 on_exit() {
158     lastcmd="$_"
159     if [[ -z "$success" && -z "$failed" ]]; then
160         cat >&2 << EOF
161
162 Aborted ($lastcmd).
163
164 EOF
165     fi
166     # remove temporary directory
167     if [ -n "$tmp" -a -d "$tmp" ]; then
168         echo -n "Removing temporary directory: "
169         rm -rf "$tmp"
170         echo "done"
171     fi
172 }
173 trap on_exit EXIT
174
175 # print error message and terminate
176 error_exit() {
177     cat >&2 << EOF
178
179 Aborted.
180
181 EOF
182     failed=true
183     exit 1
184 }
185
186
187
188 # The environment variable tmp points to a secure temporary directory.
189 # There should be enough free disk space.
190 echo -n "Creating temporary directory: "
191 tmp="$( mktemp -d -t "$program_name.XXXXXXXXXX" )"
192 echo "$tmp"
193
194 debian_dir="$tmp/debian"
195 install -d -m 755 "$debian_dir"
196
197 install_dir="$tmp/install"
198 install -d -m 755 "$install_dir"
199
200 # load and execute plugins
201 echo -n "Loading plugins:"
202 files=($lib_dir/*.sh)
203 for file in "${files[@]}"; do
204     echo -n " $file"
205     source "$file"
206 done
207
208 echo
209
210 # get architecture information
211 get_architecture
212
213 jvm_base="/usr/lib/jvm/"
214 javadoc_base="/usr/share/doc/"
215
216 j2se_found=
217 for var in ${!j2se_detect_*}; do 
218     eval "\$$var"
219     if [[ "$j2se_found" == "true" ]]; then
220         break;
221     fi
222 done
223 echo
224
225 if [[ -z "$j2se_found" ]]; then
226     echo "No matching plugin was found."
227 fi
228
229
230
231 ### exit
232 success=true
233 exit 0