make-jpkg 5.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#! /bin/bash -e

shopt -s nullglob

### global variables

# version of this package
version="@VERSION@"

working_dir="$( pwd )"
program_name="$( basename "$0" )"
program_dir="$( cd "$( dirname "$( type -p "$0" )" )" ; pwd )"

lib_dir="/usr/share/java-package"
[ "$J2SE_PACKAGE_LIBDIR" ] && lib_dir="$J2SE_PACKAGE_LIBDIR"

# If a default has been set for either of the
Emmanuel Bourg's avatar
Emmanuel Bourg committed
18 19
# environment variables, use it; otherwise,
# default to the name and email used by the
20 21 22 23 24 25 26 27 28 29 30 31 32 33
# Debian Java Maintainers project.
if [ -z "$J2SE_PACKAGE_FULL_NAME" ]; then
    maintainer_name="Debian Java Maintainers"
else
    maintainer_name="$J2SE_PACKAGE_FULL_NAME"
fi

if [ -z "$J2SE_PACKAGE_EMAIL" ]; then
    maintainer_email="pkg-java-maintainers@lists.alioth.debian.org"
else
    maintainer_email="$J2SE_PACKAGE_EMAIL"
fi

genchanges=""
34
build_source=""
35 36 37 38 39 40 41 42 43

### check for run in fakeroot

# are we running as fakeroot
if ! dh_testroot >/dev/null 2>&1; then
    if [ -n "$FAKEROOTKEY" ]; then
        echo "Internal error, fakeroot seems to fail faking root" >&2
        exit 1
    fi
44
    exec fakeroot "$0" "$@"
45 46 47 48
fi

# check whether I'm real root, and bail out if so... ugly, but needed
if touch /lib/.test 2>/dev/null; then
49 50 51 52 53 54 55 56 57 58 59 60 61
    rm -f /lib/.test
    echo "You are real root -- unfortunately, some Java distributions have" >&2
    echo "install scripts that directly manipulate /etc, and may cause some" >&2
    echo "inconsistencies on your system. Instead, you should become a" >&2
    echo "non-root user and run:" >&2
    echo >&2
    echo "fakeroot make-jpkg $@" >&2
    echo >&2
    echo "which will allow no damage to be done to your system files and" >&2
    echo "still permit the Java distribution to successfully extract." >&2
    echo >&2
    echo "Aborting." >&2
    exit 1
62 63 64 65 66
fi


### Parse options

67
print_usage() {
68
    cat << EOF
69 70
Usage: $program_name [OPTION]... FILE

71 72 73 74
$program_name builds a Debian package from the given Java binary distribution FILE

Supported java binary distributions currently include:
  * Oracle (http://www.oracle.com/technetwork/java/javase/downloads) :
75 76 77
    - The Java Development Kit (JDK), version 6, 7 and 8
    - The Java Runtime Environment (JRE), version 6, 7 and 8
    - The Java API Javadoc, version 6, 7 and 8
78 79 80
  (Choose tar.gz archives or self-extracting archives, do _not_ choose the RPM!)

The following options are recognized:
81

82 83 84 85 86 87
  --full-name NAME     full name used in the maintainer field of the package
  --email EMAIL        email address used in the maintainer field of the package
  --changes            create a .changes file
  --revision           add debian revision
  --source             build a source package instead of a binary deb package
  --with-system-certs  integrate with the system's keystore
88

89 90
  --help               display this help and exit
  --version            output version information and exit
91 92 93 94

EOF
}

95
unrecognized_option() {
96 97 98 99 100 101 102
    cat >&2 << EOF
$program_name: unrecognized option \`$1'
Try \`$program_name --help' for more information.
EOF
    exit 1
}

103
missing_argument() {
104 105 106 107 108 109 110 111 112 113
    cat >&2 << EOF
$program_name: missing argument for option \`$1'
Try \`$program_name --help' for more information.
EOF
    exit 1
}

# options
while [[ $# -gt 0 && "x$1" == x--* ]]; do
    if [[ "x$1" == x--version ]]; then
114 115
    echo "make-jpkg $version"
    exit 0
116
    elif [[ "x$1" == x--help ]]; then
117 118
    print_usage
    exit 0
119
    elif [[ "x$1" == x--full-name ]]; then
120 121 122
    [ $# -le 1 ] && missing_argument "$1"
    shift
    maintainer_name="$1"
123
    elif [[ "x$1" == x--email ]]; then
124 125 126
    [ $# -le 1 ] && missing_argument "$1"
    shift
    maintainer_email="$1"
127
    elif [[ "x$1" == x--revision ]]; then
128 129 130
    [ $# -le 1 ] && missing_argument "$1"
    shift
    revision="-${1}"
131
    elif [[ "x$1" == x--changes ]]; then
132
    genchanges="true"
133 134
    elif [[ "x$1" == x--source ]]; then
    build_source="true"
135 136
    elif [[ "x$1" == x--with-system-certs ]]; then
    create_cert_softlinks="true"
137
    else
138
    unrecognized_option "$1"
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    fi
    shift
done

# last argument
if [[ $# -ne 1 ]]; then
    cat >&2 << EOF
$program_name: missing pathname
Try \`$program_name --help' for more information.
EOF
    exit 1
fi
archive="$1"

if [[ ! -e "$archive" ]]; then
    echo "Error: The file \"$archive\" does not exist."
    exit 1
elif [[ ! -r "$archive" ]]; then
    echo "Error: The file \"$archive\" is not readable."
    exit 1
fi

archive_name="$( basename "$archive" )"
archive_dir="$( cd "$( dirname "$archive" )" ; pwd )"
archive_path="$archive_dir/$archive_name"


# error handling

success=
failed=
tmp=

# function is called when script terminates
173
on_exit() {
174 175
    lastcmd="$_"
    if [[ -z "$success" && -z "$failed" ]]; then
176
    cat >&2 << EOF
177 178 179 180 181 182 183

Aborted ($lastcmd).

EOF
    fi
    # remove temporary directory
    if [ -n "$tmp" -a -d "$tmp" ]; then
184 185 186
    echo -n "Removing temporary directory: "
    rm -rf "$tmp"
    echo "done"
187 188 189 190 191
    fi
}
trap on_exit EXIT

# print error message and terminate
192
error_exit() {
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    cat >&2 << EOF

Aborted.

EOF
    failed=true
    exit 1
}



# The environment variable tmp points to a secure temporary directory.
# There should be enough free disk space.
echo -n "Creating temporary directory: "
tmp="$( mktemp -d -t "$program_name.XXXXXXXXXX" )"
echo "$tmp"

210 211
package_dir="$tmp/package"
install -d -m 755 "$package_dir"
212

213 214
debian_dir="$package_dir/debian"
install -d -m 755 "$debian_dir"
215 216 217

# load and execute plugins
echo -n "Loading plugins:"
218
files=($lib_dir/*.sh)
219 220
for file in "${files[@]}"; do
    echo -n " $file"
221
    source "$file"
222 223 224 225 226 227 228
done

echo

# get architecture information
get_architecture

229 230 231
# get browser plugin directories
get_browser_plugin_dirs

232 233 234
jvm_base="/usr/lib/jvm/"
javadoc_base="/usr/share/doc/"

235
j2se_found=
Emmanuel Bourg's avatar
Emmanuel Bourg committed
236
for var in ${!j2se_detect_*}; do
237 238
    eval "\$$var"
    if [[ "$j2se_found" == "true" ]]; then
239
    break;
240 241 242 243 244
    fi
done
echo

if [[ -z "$j2se_found" ]]; then
245 246
    echo "No matching packaging method was found for $archive_name."
    echo "Please make sure you are using a tar.gz or a self-extracting archive"
247 248 249 250 251 252 253
fi



### exit
success=true
exit 0