File: common.sh

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 (179 lines) | stat: -rw-r--r-- 3,939 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
# read_yn <prompt>
function read_yn() {
    local prompt="$1"
    while true; do
	read -e -n 1 -p "$prompt" reply
	case "$reply" in
	    "" | "y" | "Y")
		return 0
		;;
	    "N" | "n")
		return 1
		;;
	esac
    done
}


# diskusage <path>: prints size in MB
function diskusage() {
    local path="$1"
    read size dummy < <( du -sm "$path" )
    echo "$size"
}


# diskfree <minimum size in MB>
function diskfree() {
    local size="$1"
    echo -n "Checking free diskspace:"
	(( free = `stat -f -c '%a / 2048 * ( %s / 512 )' $tmp ` ))

    if [ "$free" -ge "$size" ]; then
	echo " done."
    else
	cat >&2 << EOF


WARNING: Possibly not enough free disk space in "$tmp".

You need at least $size MB, but only $free MB seems free. Note: You
can specify an alternate directory by setting the environment variable

Press Ctrl+C to interrupt, or return to try to continue anyway.

TMPDIR.

EOF
	read
    fi
}


# extract_bin <file> <expected_min_size> <dest>
function extract_bin() {
    local file="$1"
    local expected_min_size="$2"
    local dest="$3"
    cat << EOF

In the next step, the binary file will be extracted. Probably a
license agreement will be displayed. Please read this agreement
carefully. If you do not agree to the displayed license terms, the
package will not be built.

EOF
    read -e -p "Press [Return] to continue: " dummy
    echo
    local extract_dir="$tmp/extract"
    mkdir "$extract_dir"
    cd "$extract_dir"
    echo

    local extract_cmd
    case "$archive_path" in
	*.tar)
	    extract_cmd="tar xf";;
	*.tar.bz2)
	    extract_cmd="tar --bzip2 -xf";;
	*.tgz|*.tar.gz)
	    extract_cmd="tar xfz";;
	*)
	    extract_cmd=sh
    esac

    if ! $extract_cmd "$archive_path"; then
	cat << EOF

WARNING: The package installation script exited with an error
value. Usually, this means, that the installation failed for some
reason. But in some cases there is no problem and you can continue
creating the Debian package.

Please check if there are any error messages. Press [Return] to
continue or Ctrl-C to abort.

EOF
	read
    fi
    echo
    echo -n "Testing extracted archive..."
    local size="$( diskusage "$extract_dir" )"
    if [ "$size" -lt "$expected_min_size" ]; then
	cat << EOF

Invalid size ($size MB) of extracted archive. Probably you have not
enough free disc space in the temporary directory. Note: You can
specify an alternate directory by setting the environment variable
TMPDIR.

EOF
	error_exit
    else
	cd "$extract_dir"
	files=(*)
	if [ "${#files[*]}" -ne 1 ]; then
	    cat << EOF

Exptected one file, but found the following ${#files[*]} files:
    ${files[*]}

EOF
	    error_exit
	fi
	mv "$files" "$dest"
	echo -e " okay.\n"
    fi
}


function read_maintainer_info() {
    if [ -z "$maintainer_name" ]; then
	if [ -n "$DEBFULLNAME" ]; then
		maintainer_name="$DEBFULLNAME"
	elif [ -n "$DEBNAME" ]; then
		maintainer_name="$DEBNAME"
	else
		default_name="$(getent passwd $(id -run) | cut -d: -f5| cut -d, -f1)"
	
	cat << EOF

Please enter your full name. This value will be used in the maintainer
field of the created package.

EOF

	# gecos can be null
	while [ -z "$maintainer_name" ]; do
		read -e -p "Full name [$default_name]:" maintainer_name
		if [ -z "$maintainer_name" ] && [ -n "$default_name" ]; then
			maintainer_name="$default_name"
		fi
	done
	fi
    fi
 
    if [ -z "$maintainer_email" ]; then
	local default_email=
	if [ -n "$DEBEMAIL" ]; then
	    maintainer_email="$DEBEMAIL"
	else 
	if [ -r "/etc/mailname" ]; then
	    default_email="$( id -run )@$( cat /etc/mailname )"
	else
	    default_email="$( id -run )@$( hostname --fqdn )"
	fi
	cat << EOF

Please enter a valid email address or press return to accept the
default value. This address will be used in the maintainer field of
the created package.

EOF
	read -e -p "Email [$default_email]: " maintainer_email
	if [ -z "$maintainer_email" ]; then
	    maintainer_email="$default_email"
	fi
	fi
    fi
}