* Long description removed
[sven/java-package.git] / lib / j2se.sh
1 j2se_readme() {
2     cat << EOF
3 Package for $j2se_title
4 ---
5
6 This package has been automatically created with java-package ($version). 
7 All files from the original distribution should have been installed in
8 the directory $jvm_base$j2se_name. Please take a look at this directory for
9 further information.
10
11 EOF
12 }
13
14 j2se_changelog() {
15     cat << EOF
16 $j2se_package ($j2se_version) unstable; urgency=low
17
18   * This package was created with java-package ($version).
19
20  -- $maintainer_name <$maintainer_email>  $( date -R )
21
22 EOF
23 }
24
25 j2se_control() {
26     cat << EOF
27 Source: $j2se_package
28 Section: non-free/devel
29 Priority: optional
30 Maintainer: $maintainer_name <$maintainer_email>
31 Build-Depends: debhelper (>= 4.0.0)
32 Standards-Version: 3.7.2
33
34 EOF
35 }
36
37 j2se_copyright() {
38     cat << EOF
39 ----------------------------------------------------------------------
40
41 This file contains a copy of all copyright files found in the original
42 distribution. The original copyright files and further information can
43 be found in the directory $jvm_base$j2se_name and its
44 subdirectories.
45
46 ----------------------------------------------------------------------
47 EOF
48     ( 
49     cd "$install_dir"
50     find * -type f -iname copyright |
51     while read file; do
52         cat << EOF
53
54 File: /$file
55
56 ----------------------------------------------------------------------
57
58 EOF
59         cat "$file"
60         cat << EOF
61
62 ----------------------------------------------------------------------
63 EOF
64     done
65     )
66 }
67
68 j2se_install_scripts() {
69     cat > "$debian_dir/postinst" << EOF
70 #!/bin/bash
71
72 set -e
73
74 if [ "\$1" = configure ]; then
75
76     # Common functions for all install scripts
77
78     # install_alternatives program_base programs
79     install_alternatives() {
80         program_base="\$1"
81         shift
82         for program in \$*; do
83           update-alternatives \\
84               --install "/usr/bin/\$program" "\$program" "\$program_base/\$program" $j2se_priority \\
85               --slave "/usr/share/man/man1/\$program.1.gz" "\$program.1.gz" "$jvm_base$j2se_name/man/man1/\$program.1.gz"
86         done
87     }
88
89     # install_alternatives_no_man program_base programs
90     install_no_man_alternatives() {
91         program_base="\$1"
92         shift
93         for program in \$*; do
94           update-alternatives --install "/usr/bin/\$program" "\$program" "\$program_base/\$program" $j2se_priority
95         done
96     }
97
98     # install_browser_plugin link_path link_name plugin_name plugin
99     install_browser_plugin() {
100         local link_path="\$1"
101         local link_name="\$2"
102         local plugin_name="\$3"
103         local plugin="\$4"
104         [ -d "\$link_path" ] || install -d -m 755 "\$link_path"
105         update-alternatives --install "\$link_path/\$link_name" "\$plugin_name" "\$plugin" $j2se_priority
106     }
107
108 EOF
109     eval "$j2se_install" >> "$debian_dir/postinst"
110
111     cat >> "$debian_dir/postinst" << EOF
112 fi
113
114 #DEBHELPER#
115
116 exit 0
117 EOF
118     chmod 755 "$debian_dir/postinst"
119     
120     cat > "$debian_dir/prerm" << EOF
121 #!/bin/bash
122
123 set -e
124
125 case "\$1" in
126     remove | deconfigure)
127
128     # Common functions for all remove scripts
129
130     # remove_alternatives program_base programs
131     remove_alternatives() {
132         program_base="\$1"
133         shift
134         for program in \$*; do
135           update-alternatives --remove "\$program" "\$program_base/\$program"
136         done
137     }
138
139     # remove_browser_plugin plugin_name plugin
140     remove_browser_plugin() {
141         local plugin_name="\$1"
142         local plugin="\$2"
143         update-alternatives --remove "\$plugin_name" "\$plugin"
144     }
145
146 EOF
147     eval "$j2se_remove" >> "$debian_dir/prerm"
148
149     cat >> "$debian_dir/prerm" << EOF
150     ;;
151 esac
152
153 #DEBHELPER#
154
155 exit 0
156 EOF
157     chmod 755 "$debian_dir/prerm"
158 }
159
160 j2se_info() {
161     cat << EOF
162 version="$version"
163 j2se_version="$j2se_version"
164 maintainer_name="$maintainer_name"
165 maintainer_email="$maintainer_email"
166 date="$( date +%Y/%m/%d )"
167 EOF
168 }
169
170 # jinfos prefix program_base programs
171 jinfos() {
172     prefix="$1"
173     program_base="$2"
174     shift ; shift
175     for program in $*; do
176       echo "$prefix $program $program_base$program" 
177     done
178 }
179
180 j2se_build() {
181     cd "$tmp"
182     echo "Create debian package:"
183     
184     #export DH_VERBOSE=1
185     export DH_COMPAT=7
186     export DH_OPTIONS=--tmpdir="$install_dir"
187
188     echo "    dh_testdir"
189     dh_testdir
190     echo "    dh_testroot"
191     dh_testroot
192     echo "    dh_installchangelogs"
193     dh_installchangelogs
194     # Problem: dh_installchangelogs thinks this is a native package.
195     echo "    dh_installdocs"
196     dh_installdocs
197     # dh_install
198     # dh_link
199     # Conditionally wrapping this as not all JRE/JDKs have man directories
200     if [ -e "$install_dir/$jvm_base$j2se_name/man" ]; then
201         echo "    dh_compress"
202         dh_compress $( find "$install_dir/$jvm_base$j2se_name/man" -type f ! -name "*.gz" )
203     fi
204     echo "    dh_fixperms"
205     dh_fixperms
206     echo "    dh_installdeb"
207     dh_installdeb
208     echo "    dh_shlibdeps"
209     ldpath=
210     for dir in $( find "$install_dir" -type f -name "*.so*" -printf "%h\n" | sort -u ); do
211         if [[ -z "$ldpath" ]]; then
212             ldpath="$dir"
213         else
214             ldpath="$ldpath:$dir"
215         fi
216     done
217     # suppress some warnings
218     dh_shlibdeps -l"$ldpath" 2>&1 | 
219     { grep -v "warning: format of \`NEEDED lib.*\.so' not recognized" >&2 || true; }
220     echo "    dh_gencontrol"
221     dh_gencontrol
222     echo "    dh_md5sums"
223     dh_md5sums
224     echo "    dh_builddeb"
225     dh_builddeb --destdir="$tmp"
226     local deb_filename="$( echo "${j2se_package}_"*.deb )"
227     echo "    copy $deb_filename into directory $working_dir/"
228     cp "$deb_filename" "$working_dir/"
229     if [ -n "$genchanges" ]; then 
230         echo "    dpkg-genchanges"
231         local changes_filename="${deb_filename%.deb}.changes"
232         dpkg-genchanges -b -u. > "$changes_filename"
233         echo "    copy $changes_filename into directory $working_dir/"
234         cp "$changes_filename" "$working_dir/"
235     fi
236     cat << EOF
237
238 The Debian package has been created in the current directory. You can
239 install the package as root (e.g. dpkg -i $deb_filename). 
240
241 EOF
242 }