blob: cff8fc6d17bb9a70c1c89c327a5d04e7fbeae157 [file] [log] [blame]
Jason Kusumabe998f42015-09-03 15:53:13 -07001#!/bin/bash
2
3# Copyright 2015 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Script to generate a Brillo update for use by the update engine.
8#
9# usage: brillo_update_payload COMMAND [ARGS]
10# The following commands are supported:
11# generate generate an unsigned payload
12# hash generate a payload or metadata hash
13# sign generate a signed payload
14#
15# Generate command arguments:
Jason Kusuma9a4cae22015-10-08 18:17:57 -070016# --payload generated unsigned payload output file
17# --source_image if defined, generate a delta payload from the specified
18# image to the target_image
19# --target_image the target image that should be sent to clients
20# --metadata_size_file if defined, generate a file containing the size of the payload
21# metadata in bytes to the specified file
Jason Kusumabe998f42015-09-03 15:53:13 -070022#
23# Hash command arguments:
24# --unsigned_payload the input unsigned payload to generate the hash from
25# --signature_size signature sizes in bytes in the following format:
Alex Deymo89ff9e32015-09-15 19:29:01 -070026# "size1:size2[:...]"
Jason Kusumabe998f42015-09-03 15:53:13 -070027# --payload_hash_file if defined, generate a payload hash and output to the
28# specified file
29# --metadata_hash_file if defined, generate a metadata hash and output to the
30# specified file
31#
32# Sign command arguments:
Alex Deymo89ff9e32015-09-15 19:29:01 -070033# --unsigned_payload the input unsigned payload to insert the signatures
34# --payload the output signed payload
35# --signature_size signature sizes in bytes in the following format:
36# "size1:size2[:...]"
37# --payload_signature_file the payload signature files in the following
38# format:
39# "payload_signature1:payload_signature2[:...]"
40# --metadata_signature_file the metadata signature files in the following
41# format:
42# "metadata_signature1:metadata_signature2[:...]"
Jason Kusuma9a4cae22015-10-08 18:17:57 -070043# --metadata_size_file if defined, generate a file containing the size of
44# the signed payload metadata in bytes to the
45# specified file
Jason Kusumabe998f42015-09-03 15:53:13 -070046# Note that the number of signature sizes and payload signatures have to match.
47
Gilad Arnold957ce122015-10-14 16:02:55 -070048die() {
49 echo "brillo_update_payload: error: $*" >&2
50 exit 1
Jason Kusumabe998f42015-09-03 15:53:13 -070051}
52
Gilad Arnold957ce122015-10-14 16:02:55 -070053# Loads shflags. We first look at the default install location; then look for
54# crosutils (chroot); finally check our own directory (au-generator zipfile).
55load_shflags() {
56 local my_dir="$(dirname "$(readlink -f "$0")")"
57 local path
58 for path in /usr/share/misc {/usr/lib/crosutils,"${my_dir}"}/lib/shflags; do
59 if [[ -r "${path}/shflags" ]]; then
60 . "${path}/shflags" || die "Could not load ${path}/shflags."
61 return
62 fi
63 done
64 die "Could not find shflags."
65}
66
67load_shflags
Jason Kusumabe998f42015-09-03 15:53:13 -070068
Alex Deymoc64ffd52015-09-25 18:10:07 -070069HELP_GENERATE="generate: Generate an unsigned update payload."
70HELP_HASH="hash: Generate the hashes of the unsigned payload and metadata used \
71for signing."
72HELP_SIGN="sign: Insert the signatures into the unsigned payload."
73
74usage() {
75 echo "Supported commands:"
76 echo
77 echo "${HELP_GENERATE}"
78 echo "${HELP_HASH}"
79 echo "${HELP_SIGN}"
80 echo
81 echo "Use: \"$0 <command> --help\" for more options."
82}
83
84# Check that a command is specified.
Jason Kusumabe998f42015-09-03 15:53:13 -070085if [[ $# -lt 1 ]]; then
86 echo "Please specify a command [generate|hash|sign]"
87 exit 1
88fi
89
Alex Deymoc64ffd52015-09-25 18:10:07 -070090# Parse command.
91COMMAND="${1:-}"
92shift
93
94case "${COMMAND}" in
95 generate)
96 FLAGS_HELP="${HELP_GENERATE}"
97 ;;
98
99 hash)
100 FLAGS_HELP="${HELP_HASH}"
101 ;;
102
103 sign)
104 FLAGS_HELP="${HELP_SIGN}"
Jason Kusumabe998f42015-09-03 15:53:13 -0700105 ;;
106 *)
Alex Deymoc64ffd52015-09-25 18:10:07 -0700107 echo "Unrecognized command: \"${COMMAND}\"" >&2
108 usage >&2
Jason Kusumabe998f42015-09-03 15:53:13 -0700109 exit 1
110 ;;
111esac
112
Jason Kusumabe998f42015-09-03 15:53:13 -0700113# Flags
Alex Deymoc64ffd52015-09-25 18:10:07 -0700114FLAGS_HELP="Usage: $0 ${COMMAND} [flags]
115${FLAGS_HELP}"
116
117if [[ "${COMMAND}" == "generate" ]]; then
118 DEFINE_string payload "" \
119 "Path to output the generated unsigned payload file."
120 DEFINE_string target_image "" \
121 "Path to the target image that should be sent to clients."
122 DEFINE_string source_image "" \
123 "Optional: Path to a source image. If specified, this makes a delta update."
Jason Kusuma9a4cae22015-10-08 18:17:57 -0700124 DEFINE_string metadata_size_file "" \
125 "Optional: Path to output metadata size."
Alex Deymoc64ffd52015-09-25 18:10:07 -0700126fi
127if [[ "${COMMAND}" == "hash" || "${COMMAND}" == "sign" ]]; then
128 DEFINE_string unsigned_payload "" "Path to the input unsigned payload."
129 DEFINE_string signature_size "" \
130 "Signature sizes in bytes in the following format: size1:size2[:...]"
131fi
132if [[ "${COMMAND}" == "hash" ]]; then
133 DEFINE_string metadata_hash_file "" \
134 "Optional: Path to output metadata hash file."
135 DEFINE_string payload_hash_file "" \
136 "Optional: Path to output payload hash file."
137fi
138if [[ "${COMMAND}" == "sign" ]]; then
139 DEFINE_string payload "" \
140 "Path to output the generated unsigned payload file."
141 DEFINE_string metadata_signature_file "" \
142 "The metatada signatures in the following format: \
143metadata_signature1:metadata_signature2[:...]"
144 DEFINE_string payload_signature_file "" \
145 "The payload signatures in the following format: \
146payload_signature1:payload_signature2[:...]"
Jason Kusuma9a4cae22015-10-08 18:17:57 -0700147 DEFINE_string metadata_size_file "" \
148 "Optional: Path to output metadata size."
Alex Deymoc64ffd52015-09-25 18:10:07 -0700149fi
Jason Kusumabe998f42015-09-03 15:53:13 -0700150DEFINE_string work_dir "/tmp" "Where to dump temporary files."
151
152# Parse command line flag arguments
153FLAGS "$@" || exit 1
154eval set -- "${FLAGS_ARGV}"
Alex Deymo89ff9e32015-09-15 19:29:01 -0700155set -e
Jason Kusumabe998f42015-09-03 15:53:13 -0700156
Alex Deymo89ff9e32015-09-15 19:29:01 -0700157# Associative arrays from partition name to file in the source and target
158# images. The size of the updated area must be the size of the file.
159declare -A SRC_PARTITIONS
160declare -A DST_PARTITIONS
161
162# A list of temporary files to remove during cleanup.
163CLEANUP_FILES=()
164
Alex Deymo48b502a2015-09-17 19:00:18 -0700165# Global options to force the version of the payload.
166FORCE_MAJOR_VERSION=""
167FORCE_MINOR_VERSION=""
168
Alex Deymoc97df432015-09-25 17:23:52 -0700169# read_option_int <file.txt> <option_key> [default_value]
170#
171# Reads the unsigned integer value associated with |option_key| in a key=value
172# file |file.txt|. Prints the read value if found and valid, otherwise prints
173# the |default_value|.
174read_option_uint() {
175 local file_txt="$1"
176 local option_key="$2"
177 local default_value="${3:-}"
178 local value
179 if value=$(look "${option_key}=" "${file_txt}" | tail -n 1); then
180 if value=$(echo "${value}" | cut -f 2- -d "=" | grep -E "^[0-9]+$"); then
181 echo "${value}"
182 return
183 fi
184 fi
185 echo "${default_value}"
186}
187
Alex Deymo89ff9e32015-09-15 19:29:01 -0700188# Create a temporary file in the work_dir with an optional pattern name.
189# Prints the name of the newly created file.
190create_tempfile() {
191 local pattern="${1:-tempfile.XXXXXX}"
192 mktemp --tmpdir="${FLAGS_work_dir}" "${pattern}"
193}
Jason Kusumabe998f42015-09-03 15:53:13 -0700194
195cleanup() {
196 local err=""
Alex Deymo89ff9e32015-09-15 19:29:01 -0700197 rm -f "${CLEANUP_FILES[@]}" || err=1
Jason Kusumabe998f42015-09-03 15:53:13 -0700198
199 # If we are cleaning up after an error, or if we got an error during
200 # cleanup (even if we eventually succeeded) return a non-zero exit
201 # code. This triggers additional logging in most environments that call
202 # this script.
203 if [[ -n "${err}" ]]; then
204 die "Cleanup encountered an error."
205 fi
206}
207
208cleanup_on_error() {
209 trap - INT TERM ERR EXIT
210 cleanup
211 die "Cleanup success after an error."
212}
213
214cleanup_on_exit() {
215 trap - INT TERM ERR EXIT
216 cleanup
217}
218
219trap cleanup_on_error INT TERM ERR
220trap cleanup_on_exit EXIT
221
Alex Deymo48b502a2015-09-17 19:00:18 -0700222
223# extract_image <image> <partitions_array>
224#
225# Detect the format of the |image| file and extract its updatable partitions
226# into new temporary files. Add the list of partition names and its files to the
227# associative array passed in |partitions_array|.
228extract_image() {
229 local image="$1"
230
231 # Brillo images are zip files. We detect the 4-byte magic header of the zip
232 # file.
233 local magic=$(head --bytes=4 "${image}" | hexdump -e '1/1 "%.2x"')
234 if [[ "${magic}" == "504b0304" ]]; then
235 echo "Detected .zip file, extracting Brillo image."
236 extract_image_brillo "$@"
237 return
238 fi
239
240 # Chrome OS images are GPT partitioned disks. We should have the cgpt binary
241 # bundled here and we will use it to extract the partitions, so the GPT
242 # headers must be valid.
243 if cgpt show -q -n "${image}" >/dev/null; then
244 echo "Detected GPT image, extracting Chrome OS image."
245 extract_image_cros "$@"
246 return
247 fi
248
249 die "Couldn't detect the image format of ${image}"
250}
251
Alex Deymo89ff9e32015-09-15 19:29:01 -0700252# extract_image_cros <image.bin> <partitions_array>
253#
Alex Deymo48b502a2015-09-17 19:00:18 -0700254# Extract Chromium OS recovery images into new temporary files.
Alex Deymo89ff9e32015-09-15 19:29:01 -0700255extract_image_cros() {
256 local image="$1"
257 local partitions_array="$2"
258
259 local kernel root
260 kernel=$(create_tempfile "kernel.bin.XXXXXX")
261 CLEANUP_FILES+=("${kernel}")
262 root=$(create_tempfile "root.bin.XXXXXX")
263 CLEANUP_FILES+=("${root}")
264
265 cros_generate_update_payload --extract \
266 --image "${image}" \
267 --kern_path "${kernel}" --root_path "${root}" \
268 --work_dir "${FLAGS_work_dir}" --outside_chroot
269
Alex Deymo83f2f702015-10-14 14:49:33 -0700270 # Chrome OS uses major_version 1 payloads for all versions, even if the
271 # updater supports a newer major version.
272 FORCE_MAJOR_VERSION="1"
273
Alex Deymo48b502a2015-09-17 19:00:18 -0700274 # When generating legacy Chrome OS images, we need to use "boot" and "system"
275 # for the partition names to be compatible with updating Brillo devices with
276 # Chrome OS images.
277 eval ${partitions_array}[boot]=\""${kernel}"\"
278 eval ${partitions_array}[system]=\""${root}"\"
Alex Deymo89ff9e32015-09-15 19:29:01 -0700279
280 local part varname
Alex Deymo48b502a2015-09-17 19:00:18 -0700281 for part in boot system; do
Alex Deymo89ff9e32015-09-15 19:29:01 -0700282 varname="${partitions_array}[${part}]"
283 printf "md5sum of %s: " "${varname}"
284 md5sum "${!varname}"
285 done
286}
287
Alex Deymo48b502a2015-09-17 19:00:18 -0700288# extract_image_brillo <target_files.zip> <partitions_array>
289#
290# Extract the A/B updated partitions from a Brillo target_files zip file into
291# new temporary files.
292extract_image_brillo() {
293 local image="$1"
294 local partitions_array="$2"
295
Alex Deymo48b502a2015-09-17 19:00:18 -0700296 local partitions=( "boot" "system" )
Alex Deymo168b5352015-11-04 13:51:52 -0800297 local ab_partitions_list
298 ab_partitions_list=$(create_tempfile "ab_partitions_list.XXXXXX")
299 CLEANUP_FILES+=("${ab_partitions_list}")
300 if unzip -p "${image}" "META/ab_partitions.txt" >"${ab_partitions_list}"; then
301 if grep -v -E '^[a-zA-Z0-9_-]*$' "${ab_partitions_list}" >&2; then
302 die "Invalid partition names found in the partition list."
303 fi
304 partitions=($(cat "${ab_partitions_list}"))
305 if [[ ${#partitions[@]} -eq 0 ]]; then
306 die "The list of partitions is empty. Can't generate a payload."
307 fi
308 else
309 warn "No ab_partitions.txt found. Using default."
310 fi
311 echo "List of A/B partitions: ${partitions[@]}"
Alex Deymo48b502a2015-09-17 19:00:18 -0700312
Alex Deymo83f2f702015-10-14 14:49:33 -0700313 # All Brillo updaters support major version 2.
314 FORCE_MAJOR_VERSION="2"
315
Alex Deymo48b502a2015-09-17 19:00:18 -0700316 if [[ "${partitions_array}" == "SRC_PARTITIONS" ]]; then
Alex Deymoc97df432015-09-25 17:23:52 -0700317 ue_config=$(create_tempfile "ue_config.XXXXXX")
318 CLEANUP_FILES+=("${ue_config}")
319 if ! unzip -p "${image}" "META/update_engine_config.txt" \
320 >"${ue_config}"; then
321 warn "No update_engine_config.txt found. Assuming pre-release image, \
322using payload minor version 2"
323 fi
Alex Deymo83f2f702015-10-14 14:49:33 -0700324 # For delta payloads, we use the major and minor version supported by the
325 # old updater.
Alex Deymoc97df432015-09-25 17:23:52 -0700326 FORCE_MINOR_VERSION=$(read_option_uint "${ue_config}" \
327 "PAYLOAD_MINOR_VERSION" 2)
Alex Deymo83f2f702015-10-14 14:49:33 -0700328 FORCE_MAJOR_VERSION=$(read_option_uint "${ue_config}" \
329 "PAYLOAD_MAJOR_VERSION" 2)
Alex Deymo48b502a2015-09-17 19:00:18 -0700330 fi
331
332 local part part_file temp_raw filesize
333 for part in "${partitions[@]}"; do
334 part_file=$(create_tempfile "${part}.img.XXXXXX")
335 CLEANUP_FILES+=("${part_file}")
336 unzip -p "${image}" "IMAGES/${part}.img" >"${part_file}"
337
338 # If the partition is stored as an Android sparse image file, we need to
339 # convert them to a raw image for the update.
340 local magic=$(head --bytes=4 "${part_file}" | hexdump -e '1/1 "%.2x"')
341 if [[ "${magic}" == "3aff26ed" ]]; then
342 temp_raw=$(create_tempfile "${part}.raw.XXXXXX")
343 CLEANUP_FILES+=("${temp_raw}")
344 echo "Converting Android sparse image ${part}.img to RAW."
345 simg2img "${part_file}" "${temp_raw}"
346 # At this point, we can drop the contents of the old part_file file, but
347 # we can't delete the file because it will be deleted in cleanup.
348 true >"${part_file}"
349 part_file="${temp_raw}"
350 fi
351
352 # delta_generator only supports images multiple of 4 KiB, so we pad with
353 # zeros if needed.
354 filesize=$(stat -c%s "${part_file}")
355 if [[ $(( filesize % 4096 )) -ne 0 ]]; then
356 echo "Rounding up partition ${part}.img to multiple of 4 KiB."
357 : $(( filesize = (filesize + 4095) & -4096 ))
358 truncate --size="${filesize}" "${part_file}"
359 fi
360
361 eval "${partitions_array}[\"${part}\"]=\"${part_file}\""
362 echo "Extracted ${partitions_array}[${part}]: ${filesize} bytes"
363 done
364}
365
Jason Kusumabe998f42015-09-03 15:53:13 -0700366validate_generate() {
367 [[ -n "${FLAGS_payload}" ]] ||
368 die "Error: you must specify an output filename with --payload FILENAME"
369
370 [[ -n "${FLAGS_target_image}" ]] ||
371 die "Error: you must specify a target image with --target_image FILENAME"
372}
373
374cmd_generate() {
Alex Deymo89ff9e32015-09-15 19:29:01 -0700375 local payload_type="delta"
Jason Kusumabe998f42015-09-03 15:53:13 -0700376 if [[ -z "${FLAGS_source_image}" ]]; then
Alex Deymo89ff9e32015-09-15 19:29:01 -0700377 payload_type="full"
Jason Kusumabe998f42015-09-03 15:53:13 -0700378 fi
379
Alex Deymo48b502a2015-09-17 19:00:18 -0700380 echo "Extracting images for ${payload_type} update."
Jason Kusumabe998f42015-09-03 15:53:13 -0700381
Alex Deymo48b502a2015-09-17 19:00:18 -0700382 extract_image "${FLAGS_target_image}" DST_PARTITIONS
Alex Deymo89ff9e32015-09-15 19:29:01 -0700383 if [[ "${payload_type}" == "delta" ]]; then
Alex Deymo48b502a2015-09-17 19:00:18 -0700384 extract_image "${FLAGS_source_image}" SRC_PARTITIONS
Jason Kusumabe998f42015-09-03 15:53:13 -0700385 fi
386
Alex Deymo48b502a2015-09-17 19:00:18 -0700387 echo "Generating ${payload_type} update."
Alex Deymo168b5352015-11-04 13:51:52 -0800388 # Common payload args:
389 GENERATOR_ARGS=( -out_file="${FLAGS_payload}" )
390
391 local part old_partitions="" new_partitions="" partition_names=""
392 for part in "${!DST_PARTITIONS[@]}"; do
393 if [[ -n "${partition_names}" ]]; then
394 partition_names+=":"
395 new_partitions+=":"
396 old_partitions+=":"
397 fi
398 partition_names+="${part}"
399 new_partitions+="${DST_PARTITIONS[${part}]}"
400 old_partitions+="${SRC_PARTITIONS[${part}]:-}"
401 done
402
403 # Target image args:
404 GENERATOR_ARGS+=(
405 -partition_names="${partition_names}"
406 -new_partitions="${new_partitions}"
Jason Kusumabe998f42015-09-03 15:53:13 -0700407 )
408
Alex Deymo89ff9e32015-09-15 19:29:01 -0700409 if [[ "${payload_type}" == "delta" ]]; then
Alex Deymo168b5352015-11-04 13:51:52 -0800410 # Source image args:
Jason Kusumabe998f42015-09-03 15:53:13 -0700411 GENERATOR_ARGS+=(
Alex Deymo168b5352015-11-04 13:51:52 -0800412 -old_partitions="${old_partitions}"
Jason Kusumabe998f42015-09-03 15:53:13 -0700413 )
Alex Deymo48b502a2015-09-17 19:00:18 -0700414 if [[ -n "${FORCE_MINOR_VERSION}" ]]; then
415 GENERATOR_ARGS+=( --minor_version="${FORCE_MINOR_VERSION}" )
416 fi
417 fi
418
419 if [[ -n "${FORCE_MAJOR_VERSION}" ]]; then
420 GENERATOR_ARGS+=( --major_version="${FORCE_MAJOR_VERSION}" )
Jason Kusumabe998f42015-09-03 15:53:13 -0700421 fi
422
Jason Kusuma9a4cae22015-10-08 18:17:57 -0700423 if [[ -n "${FLAGS_metadata_size_file}" ]]; then
424 GENERATOR_ARGS+=( --out_metadata_size_file="${FLAGS_metadata_size_file}" )
425 fi
426
Jason Kusumabe998f42015-09-03 15:53:13 -0700427 echo "Running delta_generator with args: ${GENERATOR_ARGS[@]}"
Jason Kusuma9a4cae22015-10-08 18:17:57 -0700428 "${GENERATOR}" "${GENERATOR_ARGS[@]}"
Jason Kusumabe998f42015-09-03 15:53:13 -0700429
Alex Deymo89ff9e32015-09-15 19:29:01 -0700430 echo "Done generating ${payload_type} update."
Jason Kusumabe998f42015-09-03 15:53:13 -0700431}
432
433validate_hash() {
434 [[ -n "${FLAGS_signature_size}" ]] ||
435 die "Error: you must specify signature size with --signature_size SIZES"
436
437 [[ -n "${FLAGS_unsigned_payload}" ]] ||
438 die "Error: you must specify the input unsigned payload with \
439--unsigned_payload FILENAME"
440
Jason Kusumabe998f42015-09-03 15:53:13 -0700441 [[ -n "${FLAGS_payload_hash_file}" ]] ||
Sen Jiangbf1266f2015-10-26 11:29:24 -0700442 die "Error: you must specify --payload_hash_file FILENAME"
Jason Kusumabe998f42015-09-03 15:53:13 -0700443}
444
445cmd_hash() {
Sen Jiangbf1266f2015-10-26 11:29:24 -0700446 "${GENERATOR}" \
447 -in_file="${FLAGS_unsigned_payload}" \
448 -signature_size="${FLAGS_signature_size}" \
449 -out_hash_file="${FLAGS_payload_hash_file}" \
450 -out_metadata_hash_file="${FLAGS_metadata_hash_file}"
Jason Kusumabe998f42015-09-03 15:53:13 -0700451
Jason Kusumabe998f42015-09-03 15:53:13 -0700452 echo "Done generating hash."
453}
454
455validate_sign() {
456 [[ -n "${FLAGS_signature_size}" ]] ||
457 die "Error: you must specify signature size with --signature_size SIZES"
458
459 [[ -n "${FLAGS_unsigned_payload}" ]] ||
460 die "Error: you must specify the input unsigned payload with \
461--unsigned_payload FILENAME"
462
463 [[ -n "${FLAGS_payload}" ]] ||
464 die "Error: you must specify the output signed payload with \
465--payload FILENAME"
466
467 [[ -n "${FLAGS_payload_signature_file}" ]] ||
468 die "Error: you must specify the payload signature file with \
469--payload_signature_file SIGNATURES"
Alex Deymo89ff9e32015-09-15 19:29:01 -0700470
471 [[ -n "${FLAGS_metadata_signature_file}" ]] ||
472 die "Error: you must specify the metadata signature file with \
473--metadata_signature_file SIGNATURES"
Jason Kusumabe998f42015-09-03 15:53:13 -0700474}
475
476cmd_sign() {
Jason Kusuma9a4cae22015-10-08 18:17:57 -0700477 GENERATOR_ARGS=(
478 -in_file="${FLAGS_unsigned_payload}"
479 -signature_size="${FLAGS_signature_size}"
480 -signature_file="${FLAGS_payload_signature_file}"
481 -metadata_signature_file="${FLAGS_metadata_signature_file}"
482 -out_file="${FLAGS_payload}"
483 )
484
485 if [[ -n "${FLAGS_metadata_size_file}" ]]; then
486 GENERATOR_ARGS+=( --out_metadata_size_file="${FLAGS_metadata_size_file}" )
487 fi
488
489 "${GENERATOR}" "${GENERATOR_ARGS[@]}"
Jason Kusumabe998f42015-09-03 15:53:13 -0700490 echo "Done signing payload."
491}
492
Jason Kusumabe998f42015-09-03 15:53:13 -0700493# Sanity check that the real generator exists:
494GENERATOR="$(which delta_generator)"
495[[ -x "${GENERATOR}" ]] || die "can't find delta_generator"
496
497case "$COMMAND" in
498 generate) validate_generate
499 cmd_generate
500 ;;
501 hash) validate_hash
502 cmd_hash
503 ;;
504 sign) validate_sign
505 cmd_sign
506 ;;
507esac