]> git.sven.stormbind.net Git - sven/java-package.git/blob - lib/common.sh
Add Java 10 Server JRE support now that it's released.
[sven/java-package.git] / lib / common.sh
1 # read_yn <prompt>
2 read_yn() {
3     local prompt="$1"
4     while true; do
5     read -e -n 1 -p "$prompt" reply
6     case "$reply" in
7         "" | "y" | "Y")
8         return 0
9         ;;
10         "N" | "n")
11         return 1
12         ;;
13     esac
14     done
15 }
16
17
18 # diskusage <path>: prints size in MB
19 diskusage() {
20     local path="$1"
21     read size dummy < <( du -sm --apparent-size "$path" )
22     echo "$size"
23 }
24
25
26 # diskfree <minimum size in MB>
27 diskfree() {
28     local size="$1"
29     echo -n "Checking free diskspace:"
30     (( free = `stat -f -c '%a / 2048 * ( %s / 512 )' $tmp ` ))
31
32     if [ "$free" -ge "$size" ]; then
33     echo " done."
34     else
35     cat >&2 << EOF
36
37
38 WARNING: Possibly not enough free disk space in "$tmp".
39
40 You need at least $size MB, but only $free MB seems free. Note: You
41 can specify an alternate directory by setting the environment variable
42
43 Press Ctrl+C to interrupt, or return to try to continue anyway.
44
45 TMPDIR.
46
47 EOF
48     read
49     fi
50 }
51
52
53 # extract_bin <file> <expected_min_size> <dest>
54 extract_bin() {
55     local file="$1"
56     local expected_min_size="$2"
57     local dest="$3"
58     cat << EOF
59
60 In the next step, the binary file will be extracted. Probably a
61 license agreement will be displayed. Please read this agreement
62 carefully. If you do not agree to the displayed license terms, the
63 package will not be built.
64
65 EOF
66     read -e -p "Press [Return] to continue: " dummy
67     echo
68     local extract_dir="$tmp/extract"
69     mkdir "$extract_dir"
70     cd "$extract_dir"
71     echo
72
73     local extract_cmd
74     case "$archive_path" in
75     *.tar)
76         extract_cmd="tar xf";;
77     *.tar.bz2)
78         extract_cmd="tar --bzip2 -xf";;
79     *.tgz|*.tar.gz)
80         extract_cmd="tar xfz";;
81     *.zip)
82         extract_cmd="unzip -q";;
83     *)
84         extract_cmd=sh
85     esac
86
87     if ! $extract_cmd "$archive_path"; then
88     cat << EOF
89
90 WARNING: The package installation script exited with an error
91 value. Usually, this means, that the installation failed for some
92 reason. But in some cases there is no problem and you can continue
93 creating the Debian package.
94
95 Please check if there are any error messages. Press [Return] to
96 continue or Ctrl-C to abort.
97
98 EOF
99     read
100     fi
101     echo
102     echo -n "Testing extracted archive..."
103     local size="$( diskusage "$extract_dir" )"
104     if [ "$size" -lt "$expected_min_size" ]; then
105     cat << EOF
106
107 Invalid size ($size MB) of extracted archive. Probably you have not
108 enough free disc space in the temporary directory. Note: You can
109 specify an alternate directory by setting the environment variable
110 TMPDIR.
111
112 EOF
113     error_exit
114     else
115     cd "$extract_dir"
116     files=(*)
117     if [ "${#files[*]}" -ne 1 ]; then
118         cat << EOF
119
120 Expected one file, but found the following ${#files[*]} files:
121     ${files[*]}
122
123 EOF
124         error_exit
125     fi
126     mv "$files" "$dest"
127     echo -e " okay.\n"
128     fi
129 }
130
131 extract_jce() {
132   local zip_file="$1"
133   local dest_dir="$2"
134
135   echo "Installing unlimited strength cryptography files using $zip_file"
136   for f in {US_export,local}_policy.jar; do
137     unzip -o -j -d "$dest_dir" "$zip_file" "*/$f"
138   done
139 }
140
141 read_maintainer_info() {
142     if [ -z "$maintainer_name" ]; then
143     if [ -n "$DEBFULLNAME" ]; then
144         maintainer_name="$DEBFULLNAME"
145     elif [ -n "$DEBNAME" ]; then
146         maintainer_name="$DEBNAME"
147     else
148         default_name="$(getent passwd $(id -run) | cut -d: -f5| cut -d, -f1)"
149
150     cat << EOF
151
152 Please enter your full name. This value will be used in the maintainer
153 field of the created package.
154
155 EOF
156
157     # gecos can be null
158     while [ -z "$maintainer_name" ]; do
159         read -e -p "Full name [$default_name]:" maintainer_name
160         if [ -z "$maintainer_name" ] && [ -n "$default_name" ]; then
161             maintainer_name="$default_name"
162         fi
163     done
164     fi
165     fi
166
167     if [ -z "$maintainer_email" ]; then
168     local default_email=
169     if [ -n "$DEBEMAIL" ]; then
170         maintainer_email="$DEBEMAIL"
171     else
172     if [ -r "/etc/mailname" ]; then
173         default_email="$( id -run )@$( cat /etc/mailname )"
174     else
175         default_email="$( id -run )@$( hostname --fqdn )"
176     fi
177     cat << EOF
178
179 Please enter a valid email address or press return to accept the
180 default value. This address will be used in the maintainer field of
181 the created package.
182
183 EOF
184     read -e -p "Email [$default_email]: " maintainer_email
185     if [ -z "$maintainer_email" ]; then
186         maintainer_email="$default_email"
187     fi
188     fi
189     fi
190 }
191
192 # provide the architecture for evaluation by plugins
193 get_architecture() {
194     echo
195
196     export DEB_BUILD_ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
197
198     export DEB_BUILD_GNU_TYPE=$(dpkg-architecture -qDEB_BUILD_GNU_TYPE)
199
200     echo "Detected Debian build architecture: ${DEB_BUILD_ARCH:-N/A}"
201
202     echo "Detected Debian GNU type: ${DEB_BUILD_GNU_TYPE:-N/A}"
203 }
204
205 # get browser plugin directories
206 get_browser_plugin_dirs() {
207     if dpkg-vendor --derives-from Ubuntu; then
208         export browser_plugin_dirs="xulrunner-addons firefox iceape iceweasel mozilla midbrowser xulrunner"
209     else
210         export browser_plugin_dirs=mozilla
211     fi
212 }
213
214 get_distribution() {
215     if [ -n "$distribution" ]; then
216       target_distribution="$distribution"
217     else
218       target_distribution="unstable"
219     fi
220 }