File: make-jpkg

package info (click to toggle)
java-package 0.24
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 224 kB
  • ctags: 42
  • sloc: sh: 1,149; makefile: 71
file content (205 lines) | stat: -rwxr-xr-x 4,233 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#! /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"

maintainer_name="$J2SE_PACKAGE_FULL_NAME"
maintainer_email="$J2SE_PACKAGE_EMAIL"
genchanges=""


### Parse options

function print_usage() {
	cat << EOF
Usage: $program_name [OPTION]... FILE

$program_name builds Debian packages from Java(TM) 2 binary distributions.

  --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

  --help             display this help and exit
  --version          output version information and exit

EOF
}

function unrecognized_option() {
    cat >&2 << EOF
$program_name: unrecognized option \`$1'
Try \`$program_name --help' for more information.
EOF
    exit 1
}

function missing_argument() {
    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
	echo "make-jpkg $version"
	exit 0
    elif [[ "x$1" == x--help ]]; then
	print_usage
	exit 0
    elif [[ "x$1" == x--full-name ]]; then
	[ $# -le 1 ] && missing_argument "$1"
	shift
	maintainer_name="$1"
    elif [[ "x$1" == x--email ]]; then
	[ $# -le 1 ] && missing_argument "$1"
	shift
	maintainer_email="$1"
    elif [[ "x$1" == x--changes ]]; then
	genchanges="true"
    else
	unrecognized_option "$1"
    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"


# must be run as root
if ! dh_testroot; then
    exit 1
fi

# check whether I'm real root, and bail out if so... ugly, but needed
if touch /lib/.test 2>/dev/null; then
	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
fi


### Error handling

success=
failed=
tmp=

# function is called when script terminates
function on_exit() {
    lastcmd="$_"
    if [[ -z "$success" && -z "$failed" ]]; then
	cat >&2 << EOF

Aborted ($lastcmd).

EOF
    fi
    # remove temporary directory
    if [ -n "$tmp" -a -d "$tmp" ]; then
	echo -n "Removing temporary directory: "
	rm -rf "$tmp"
	echo "done"
    fi
}
trap on_exit EXIT

# print error message and terminate
function error_exit() {
    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"

debian_dir="$tmp/debian"
install -d -m 755 "$debian_dir"

install_dir="$tmp/install"
install -d -m 755 "$install_dir"



### load and execute plugins
echo -n "Loading plugins:"
cd "$lib_dir"
files=(*.sh)
for file in "${files[@]}"; do
    echo -n " $file"
    source "$lib_dir/$file"
done
echo

j2se_found=
for var in ${!j2se_detect_*}; do 
    eval "\$$var"
    if [[ "$j2se_found" == "true" ]]; then
	break;
    fi
done
echo

if [[ -z "$j2se_found" ]]; then
    echo "No matching plugin was found."
fi



### exit
success=true
exit 0