This file is indexed.

/usr/bin/cloud-publish-tarball is in cloud-utils 0.25-0ubuntu5.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/sh
# vi: ts=4 noexpandtab
#
#    cloud-publish-tarball - wrapper for publishing cloud tarballs
#
#    Copyright (C) 2010 Canonical Ltd.
#
#    Authors: Scott Moser <smoser@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


EC2PRE=${EC2PRE:-euca-}
TMPD=""
VERBOSITY=1
error() { echo "$@" 1>&2; }
debug() { 
	[ ${VERBOSITY} -ge $1 ] || return 0; 
	shift
	error "$@"
}
log() { debug "$1" "$(date): ====== $2 ======" ; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
cleanup() {
	[ -n "${TMPD}" -a -d "${TMPD}" ] || return 0;
	debug 2 "cleaning up ${TMPD}"
	rm -Rf "${TMPD}";
}
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; }
Usage() {
	cat <<EOF
Usage: ${0##*/} [ options ] tarfile bucket [arch]

   register a UEC tarball (ie, per http://cloud-images.ubuntu.com)
   if arch is not provided, a name-based attempt is made to guess
   tarfile may be a url

   options:
      -k | --kernel  k        use previously registered kernel with id 'k'
                              specify 'none' for no kernel
      -K | --kernel-file f    bundle, upload, use file 'f' as kernel
           --rename-kernel k  rename kernel to 'k' (applies to loader)
      -r | --ramdisk r        use previously registered ramdisk with id 'r'
                              specify 'none' for no ramdisk
      -R | --ramdisk-file f   bundle, upload, use file 'f' as ramdisk
           --rename-ramdisk r rename ramdisk to 'r'
           --resize  s        resize the partition image before uploading
                              's' must be valid input to cloud-resize-image
           --save-downloaded  if the image is a url, save it to '.'
      -q | --quiet            be quiet, only output published ids
      -l | --use-loader       use the loader kernel rather than linux kernel
           --rename-image f   rename image to 'f' before publishing

   Example:
   - ${0##*/} lucid-cloud-i386.tar.gz my-lucid-bucket i386
EOF
}

upload_register() {
	local out="" ret=0
	out=$(cloud-publish-image "${@}") || {
		ret=$?
		printf "%s" "${out}"
		return $ret
	}
	set -- ${out}
	_RET=${1}
}

dl() {
	# dl url, target, quiet
	local url=${1} target=${2} quiet=${3:-1}
	if [ -f "${url}" ]; then
		[ "${target}" = "-" ] && { cat "$url"; return; }
		cp "$url" "$target"
		return
	fi
	local qflag="-q"
	[ "$quiet" = "0" ] && qflag=""

	wget $qflag --progress=dot:mega "$url" -O "$target" ||
		return 1
}

dl_input_image() {
	# this downloads an image if necessary and sets _RET to location of image
	local input="$1" save_dir="${2:-.}" ret="" quiet=0
	[ $VERBOSITY -eq 0 ] && quiet=1 # this differs from cloud-publish-image
	case "$input" in
		file://*)
			ret="$save_dir/${input##*/}"
			dl "${input#file://}" "$ret" $quiet || return $?;;
		http://*|ftp://*|https://*)
			ret="$save_dir/${input##*/}"
			dl "$input" "$ret" $quiet || return $?
			;;
		*) ret="$input";;
	esac
	_RET="$ret"
}

[ "${CLOUD_UTILS_WARN_UEC:-0}" = "0" ] && _n="${0##*/}" && [ "${_n#uec}" != "${_n}" ] &&
	error "WARNING: '${0##*/}' is now to 'cloud${_n#uec}'. Please update your tools or docs" &&
	export CLOUD_UTILS_WARN_UEC=1

short_opts="hlk:K:qr:R:"
long_opts="help,kernel:,kernel-file:,quiet,use-loader,ramdisk:,ramdisk-file:,rename-image:,rename-kernel:,rename-ramdisk:,resize:,save-downloaded"
getopt_out=$(getopt --name "${0##*/}" --shell sh \
	--options "${short_opts}" --long "${long_opts}" -- "$@") &&
	eval set -- "${getopt_out}" ||
	bad_Usage

ramdisk=""
kernel=""
loader=""
eki=""
eri=""
image=""
emi=""
resize=""
use_loader=0
rename_image=""
rename_kernel=""
rename_ramdisk=""
save_dl=0

while [ $# -ne 0 ]; do
	cur=${1}; next=${2};
	case "$cur" in
		--) shift; break;;
		-h|--help) Usage; exit 0;;
		-k|--kernel) eki=${next}; shift;;
		-K|--kernel-file)
			[ -f "${next}" ] && kernel=$(readlink -f "${next}") ||
				fail "failed to get path to ${next}"
			shift;;
		-q|--quiet) VERBOSITY=0;;
		-r|--ramdisk) eri=${next}; shift;;
		-R|--ramdisk-file)
			[ -f "${next}" ] && ramdisk=$(readlink -f "${next}") ||
				fail "failed to get path to ${next}"
			shift;;
           --rename-image) rename_image=${next}; shift;;
           --rename-kernel) rename_kernel=${next}; shift;;
           --rename-ramdisk) rename_ramdisk=${next}; shift;;
           --save-downloaded) save_dl=1;;
		--use-loader) use_loader=1;;
		--resize) resize=${next}; shift;;
	esac
	shift;
done

tarball=${1}
bucket=${2}
arch=${3}

[ $# -eq 3 -o $# -eq 2 ] || bad_Usage

[ -n "${eki}" -a ${use_loader} -ne 0 ] &&
	bad_Usage "--use-loader is incompatible with --kernel"

if [ -z "${arch}" ]; then
	case "${tarball}" in
		*i386*) arch=i386;;
		*amd64*|*x86_64*) arch=amd64;;
		*) fail "unable to guess arch by tarball name. give 3rd arg";;
	esac
fi

[ "$arch" = "amd64" ] && iarch="x86_64" || iarch="${arch}"

# before extracting the tarball, try to verify that the environment
# is set up, by invoking another euca command (LP: #526504)
${EC2PRE}describe-images >/dev/null ||
	fail "Unable to run ${EC2PRE}-describe-images.  Is environment for ${EC2PRE} set up?"

utmp=${TEMPDIR:-${TMPDIR:-/tmp}}
TMPD=$(mktemp -d "${utmp}/${0##*/}.XXXXXX") || fail "failed make temp"
trap cleanup EXIT

save_dir="${TMPD}"
[ $save_dl -eq 1 ] && save_dir=$PWD

dl_input_image "$tarball" "$save_dir" && tarball="$_RET" ||
	fail "failed to download image $image to $save_dir"

[ -f "${tarball}" ] && tbf=$(readlink -f "${tarball}") ||
	fail "bad tarball: ${tarball}";

start=$PWD

cd "${TMPD}"

log 1 "extracting image"
tar -S -xvzf "${tbf}" >list.out || fail "failed extract ${tarball}";

while read x; do
	[ -f "${x}" ] || continue
	case "$x" in
		*vmlinuz*)
			[ -z "${kernel}" -a -z "${eki}" ] && kernel=${x};;
		*initrd*)
			[ -z "${ramdisk}" -a -z "${eri}" ] && ramdisk=${x};;
		*.img) image=${x};;
		*-loader) [ -z "${loader}" ] && loader=${x};;
	esac
done < list.out

[ -z "${image}" ] && fail "can't find image";

[ -z "${loader}" -a ${use_loader} -eq 1 ] &&
	fail "--use-loader specified, but no loader found in tarball"

# if loader was found, and no kernel given (or found)
# then set kernel to loader
if [ -n "${loader}" ] &&
   { [ ${use_loader} -eq 1 ] || [ -z "${kernel}" -a -z "${eki}" ]; } ; then
	debug 1 "using loader ${loader##*/} as kernel"
	kernel=${loader}
fi

[ -n "${kernel}" -o -n "${eki}" ] ||
	bad_Usage "can't find kernel. specify '--kernel none' to register none";
[ -n "${ramdisk}" -o -n "${eri}" ] || {
	debug 1 "Warning: no ramdisk found, assuming '--ramdisk none'"
	eri="none";
}

debug 1 "kernel : ${eki:-${kernel}}"
debug 1 "ramdisk: ${eri:-${ramdisk}}"
debug 1 "image  : ${image##*/}"

if [ -n "${resize}" ]; then
	log 1 "resizing ${image##*/} to ${resize}"
	out=$(resize-part-image "${image}" "${resize}" 2>&1) || {
		error "${out}";
		fail "failed to resize image file to ${resize}";
	}
fi

if [ -n "${kernel}" ]; then
	log 1 "bundle/upload kernel"
	upload_register --type kernel \
		${rename_kernel:+"--rename=${rename_kernel}"} \
		"${iarch}" "${kernel}" "${bucket}" ||
		fail "failed to upload kernel"
	eki=${_RET}
fi

if [ -n "${ramdisk}" ]; then
	log 1 "bundle/upload ramdisk"
	upload_register --type ramdisk \
		${rename_ramdisk:+"--rename=${rename_ramdisk}"} \
		"${iarch}" "${ramdisk}" "${bucket}" ||
		fail "failed ramdisk bundle/upload"
	eri=${_RET}
fi

log 1 "bundle/upload image"
upload_register --type image \
	${rename_image:+"--rename=${rename_image}"} \
	"${iarch}" "${image}" "${bucket}" \
	--kernel "${eki}" --ramdisk "${eri}" ||
		fail "failed bundle/upload/register of image"
emi=${_RET}

log 1 "done"
printf 'emi="%s"; eri="%s"; eki="%s";\n' "${emi}" "${eri}" "${eki}"