Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Side by Side Diff: user_tools/linux/recovery.sh

Issue 5535010: Use latest format config file. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/sh 1 #!/bin/sh
2 # 2 #
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # This attempts to guide linux users through the process of putting a recovery 7 # This attempts to guide linux users through the process of putting a recovery
8 # image onto a removeable USB drive. 8 # image onto a removeable USB drive.
9 # 9 #
10 # We may not need root privileges if we have the right permissions. 10 # We may not need root privileges if we have the right permissions.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 # CHECK = command to invoke to generate checksums on a file 106 # CHECK = command to invoke to generate checksums on a file
107 # CHECKTYPE = type of checksum generated 107 # CHECKTYPE = type of checksum generated
108 # DISKUTIL = set if we have 'diskutil' (for Macs) 108 # DISKUTIL = set if we have 'diskutil' (for Macs)
109 # 109 #
110 require_utils() { 110 require_utils() {
111 local external 111 local external
112 local errors 112 local errors
113 local tool 113 local tool
114 local tmp 114 local tmp
115 115
116 external='cat cut dd grep ls mkdir mount readlink sed sync tr umount unzip wc' 116 external='cat cut dd grep ls mkdir mount readlink sed sync umount unzip wc'
scottz 2010/12/09 01:47:25 md5sum openssl sha1sum I assume you leave wget/cu
Bill Richardson 2010/12/09 17:34:29 Yes, just below.
scottz 2010/12/09 18:04:27 Ahh I missed that :) On 2010/12/09 17:34:29, Bil
117 if [ -z "$WORKDIR" ]; then 117 if [ -z "$WORKDIR" ]; then
118 external="$external mktemp" 118 external="$external mktemp"
119 fi 119 fi
120 errors= 120 errors=
121 121
122 for tool in $external ; do 122 for tool in $external ; do
123 if ! type "$tool" >/dev/null 2>&1 ; then 123 if ! type "$tool" >/dev/null 2>&1 ; then
124 warn "ERROR: need \"$tool\"" 124 warn "ERROR: need \"$tool\""
125 errors=yes 125 errors=yes
126 fi 126 fi
(...skipping 28 matching lines...) Expand all
155 if [ -z "$CHECK" ] && tmp=$(type openssl 2>/dev/null) ; then 155 if [ -z "$CHECK" ] && tmp=$(type openssl 2>/dev/null) ; then
156 CHECK="openssl" 156 CHECK="openssl"
157 CHECKTYPE="md5" 157 CHECKTYPE="md5"
158 fi 158 fi
159 if [ -z "$CHECK" ]; then 159 if [ -z "$CHECK" ]; then
160 warn "ERROR: need \"md5sum\" or \"sha1sum\" or \"openssl\"" 160 warn "ERROR: need \"md5sum\" or \"sha1sum\" or \"openssl\""
161 errors=yes 161 errors=yes
162 fi 162 fi
163 163
164 # FIXME: If we're on a Mac, we need this too. Is there a way to tell we're on 164 # FIXME: If we're on a Mac, we need this too. Is there a way to tell we're on
165 # a Mac other than by having this executable? 165 # a Mac other than by having this executable?
scottz 2010/12/09 01:47:25 uname == "Darwin" will tell you you are on a mac.
Bill Richardson 2010/12/09 17:34:29 Okay. I'm not sure it matters, though. If we've go
scottz 2010/12/09 18:04:27 Sure we can assume that, I was just answering your
166 DISKUTIL= 166 DISKUTIL=
167 if type diskutil >/dev/null 2>&1; then 167 if type diskutil >/dev/null 2>&1; then
168 DISKUTIL=diskutil 168 DISKUTIL=diskutil
169 fi 169 fi
170 170
171 if [ -n "$errors" ]; then 171 if [ -n "$errors" ]; then
172 ufatal "Some required utilities are missing." 172 ufatal "Some required utilities are missing."
173 fi 173 fi
174 } 174 }
175 175
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 compute_checksum() { 224 compute_checksum() {
225 local filename 225 local filename
226 226
227 filename="$1" 227 filename="$1"
228 228
229 DEBUG "CHECK=($CHECK) CHECKTYPE=($CHECKTYPE)" 229 DEBUG "CHECK=($CHECK) CHECKTYPE=($CHECKTYPE)"
230 230
231 if [ "$CHECK" = "openssl" ]; then 231 if [ "$CHECK" = "openssl" ]; then
232 openssl md5 < "$filename" 232 openssl md5 < "$filename"
233 else 233 else
234 $CHECK "$tarball" | cut -d' ' -f1 234 $CHECK "$zipfile" | cut -d' ' -f1
235 fi 235 fi
236 } 236 }
237 237
238 238
239 ############################################################################## 239 ##############################################################################
240 # Helper functions to handle the config file and image tarball. 240 # Helper functions to handle the config file and image zipfile.
241 241
242 # Each paragraph in the config file should describe a new image. Let's make 242 # Each paragraph in the config file should describe a new image. Let's make
243 # sure it follows all the rules. This scans the config file and returns success 243 # sure it follows all the rules. This scans the config file and returns success
244 # if it looks valid. As a side-effect, it lists the line numbers of the start 244 # if it looks valid. As a side-effect, it lists the line numbers of the start
245 # and end of each stanza in the global variables 'start_lines' and 'end_lines' 245 # and end of each stanza in the global variables 'start_lines' and 'end_lines'
246 # and saves the total number of images in the global variable 'num_images'. 246 # and saves the total number of images in the global variable 'num_images'.
247 good_config() { 247 good_config() {
248 local line 248 local line
249 local key 249 local key
250 local val 250 local val
251 local display_name 251 local name
252 local file 252 local file
253 local size 253 local zipfilesize
254 local filesize
254 local url 255 local url
255 local md5 256 local md5
256 local sha1 257 local sha1
257 local skipping 258 local skipping
258 local errors 259 local errors
259 local count 260 local count
260 local line_num 261 local line_num
261 262
262 display_name= 263 name=
263 file= 264 file=
264 size= 265 zipfilesize=
266 filesize=
265 url= 267 url=
266 md5= 268 md5=
267 sha1= 269 sha1=
268 skipping=yes 270 skipping=yes
269 errors= 271 errors=
270 count=0 272 count=0
271 line_num=0 273 line_num=0
272 274
273 # global 275 # global
274 start_lines= 276 start_lines=
(...skipping 16 matching lines...) Expand all
291 continue 293 continue
292 fi 294 fi
293 295
294 # right, looks good 296 # right, looks good
295 if [ -n "$skipping" ]; then 297 if [ -n "$skipping" ]; then
296 skipping= 298 skipping=
297 start_lines="$start_lines $line_num" 299 start_lines="$start_lines $line_num"
298 fi 300 fi
299 301
300 case $key in 302 case $key in
301 display_name) 303 name)
302 if [ -n "$display_name" ]; then 304 if [ -n "$name" ]; then
303 DEBUG "duplicate $key" 305 DEBUG "duplicate $key"
304 errors=yes 306 errors=yes
305 fi 307 fi
306 display_name="$val" 308 name="$val"
307 ;; 309 ;;
308 file) 310 file)
309 if [ -n "$file" ]; then 311 if [ -n "$file" ]; then
310 DEBUG "duplicate $key" 312 DEBUG "duplicate $key"
311 errors=yes 313 errors=yes
312 fi 314 fi
313 file="$val" 315 file="$val"
314 ;; 316 ;;
315 size) 317 zipfilesize)
316 if [ -n "$size" ]; then 318 if [ -n "$zipfilesize" ]; then
317 DEBUG "duplicate $key" 319 DEBUG "duplicate $key"
318 errors=yes 320 errors=yes
319 fi 321 fi
320 size="$val" 322 zipfilesize="$val"
323 ;;
324 filesize)
325 if [ -n "$filesize" ]; then
326 DEBUG "duplicate $key"
327 errors=yes
328 fi
329 filesize="$val"
321 ;; 330 ;;
322 url) 331 url)
323 url="$val" 332 url="$val"
324 ;; 333 ;;
325 md5) 334 md5)
326 md5="$val" 335 md5="$val"
327 ;; 336 ;;
328 sha1) 337 sha1)
329 sha1="$val" 338 sha1="$val"
330 ;; 339 ;;
331 esac 340 esac
332 else 341 else
333 # Between paragraphs. Time to check what we've found so far. 342 # Between paragraphs. Time to check what we've found so far.
334 end_lines="$end_lines $line_num" 343 end_lines="$end_lines $line_num"
335 count=$(( count + 1)) 344 count=$(( count + 1))
336 345
337 if [ -z "$display_name" ]; then 346 if [ -z "$name" ]; then
338 DEBUG "image $count is missing display_name" 347 DEBUG "image $count is missing name"
339 errors=yes 348 errors=yes
340 fi 349 fi
341 if [ -z "$file" ]; then 350 if [ -z "$file" ]; then
342 DEBUG "image $count is missing file" 351 DEBUG "image $count is missing file"
343 errors=yes 352 errors=yes
344 fi 353 fi
345 if [ -z "$size" ]; then 354 if [ -z "$zipfilesize" ]; then
346 DEBUG "image $count is missing size" 355 DEBUG "image $count is missing zipfilesize"
356 errors=yes
357 fi
358 if [ -z "$filesize" ]; then
359 DEBUG "image $count is missing filesize"
347 errors=yes 360 errors=yes
348 fi 361 fi
349 if [ -z "$url" ]; then 362 if [ -z "$url" ]; then
350 DEBUG "image $count is missing url" 363 DEBUG "image $count is missing url"
351 errors=yes 364 errors=yes
352 fi 365 fi
353 if [ "$CHECKTYPE" = "md5" ] && [ -z "$md5" ]; then 366 if [ "$CHECKTYPE" = "md5" ] && [ -z "$md5" ]; then
354 DEBUG "image $count is missing required md5" 367 DEBUG "image $count is missing required md5"
355 errors=yes 368 errors=yes
356 fi 369 fi
357 if [ "$CHECKTYPE" = "sha1" ] && [ -z "$sha1" ]; then 370 if [ "$CHECKTYPE" = "sha1" ] && [ -z "$sha1" ]; then
358 DEBUG "image $count is missing required sha1" 371 DEBUG "image $count is missing required sha1"
359 errors=yes 372 errors=yes
360 fi 373 fi
361 374
362 # Prepare for next stanza 375 # Prepare for next stanza
363 display_name= 376 name=
364 file= 377 file=
365 size= 378 zipfilesize=
379 filesize=
366 url= 380 url=
367 md5= 381 md5=
368 sha1= 382 sha1=
369 skipping=yes 383 skipping=yes
370 fi 384 fi
371 done < "$config" 385 done < "$config"
372 386
373 DEBUG "$count images found" 387 DEBUG "$count images found"
374 num_images="$count" 388 num_images="$count"
375 389
(...skipping 20 matching lines...) Expand all
396 if [ "$num_images" -gt 1 ]; then 410 if [ "$num_images" -gt 1 ]; then
397 echo "There are $num_images recovery images to choose from:" 411 echo "There are $num_images recovery images to choose from:"
398 else 412 else
399 echo "There is $num_images recovery image to choose from:" 413 echo "There is $num_images recovery image to choose from:"
400 fi 414 fi
401 echo 415 echo
402 count=0 416 count=0
403 echo "0 - <quit>" 417 echo "0 - <quit>"
404 # NOTE: making assumptions about the order of lines in each stanza! 418 # NOTE: making assumptions about the order of lines in each stanza!
405 while read line; do 419 while read line; do
406 if echo "$line" | grep -q '^display_name='; then 420 if echo "$line" | grep -q '^name='; then
407 echo 421 echo
408 count=$(( count + 1 )) 422 count=$(( count + 1 ))
409 echo "$line" | sed "s/display_name=/$count - /" 423 echo "$line" | sed "s/name=/$count - /"
410 elif echo "$line" | grep -q '^channel='; then 424 elif echo "$line" | grep -q '^channel='; then
411 echo "$line" | sed 's/channel=/ channel: /' 425 echo "$line" | sed 's/channel=/ channel: /'
412 elif echo "$line" | grep -q '^hwid=[^*]'; then 426 elif echo "$line" | grep -q '^hwid='; then
413 echo "$line" | sed 's/hwid=/ HWID: /' 427 echo "$line" | sed 's/hwid=/ HWID: /'
414 fi 428 fi
415 done < "$config" 429 done < "$config"
416 echo 430 echo
417 show= 431 show=
418 fi 432 fi
419 prompt "Please select a recovery image to download: " 433 prompt "Please select a recovery image to download: "
420 read num 434 read num
421 if [ -z "$num" ] || [ "$num" = "?" ]; then 435 if [ -z "$num" ] || [ "$num" = "?" ]; then
422 show=yes 436 show=yes
(...skipping 18 matching lines...) Expand all
441 # Fetch and verify the user's chosen image. On success, it sets the global 455 # Fetch and verify the user's chosen image. On success, it sets the global
442 # variable 'image_file' to indicate the local name of the unpacked binary that 456 # variable 'image_file' to indicate the local name of the unpacked binary that
443 # should be written to the USB drive. 457 # should be written to the USB drive.
444 fetch_image() { 458 fetch_image() {
445 local start 459 local start
446 local end 460 local end
447 local line 461 local line
448 local key 462 local key
449 local val 463 local val
450 local file 464 local file
451 local size 465 local zipfilesize
466 local filesize
452 local url 467 local url
453 local md5 468 local md5
454 local sha1 469 local sha1
455 local line_num 470 local line_num
456 local tarball 471 local zipfile
457 local err 472 local err
458 local sum 473 local sum
459 474
460 file= 475 file=
461 size= 476 zipfilesize=
477 filesize=
462 url= 478 url=
463 md5= 479 md5=
464 sha1= 480 sha1=
465 line_num="0" 481 line_num="0"
466 482
467 # Convert image number to line numbers within config file. 483 # Convert image number to line numbers within config file.
468 start=$(echo $start_lines | cut -d' ' -f$1) 484 start=$(echo $start_lines | cut -d' ' -f$1)
469 end=$(echo $end_lines | cut -d' ' -f$1) 485 end=$(echo $end_lines | cut -d' ' -f$1)
470 486
471 while read line; do 487 while read line; do
(...skipping 10 matching lines...) Expand all
482 if [ -z "$key" ] || [ -z "$val" ] || [ "$key=$val" != "$line" ]; then 498 if [ -z "$key" ] || [ -z "$val" ] || [ "$key=$val" != "$line" ]; then
483 DEBUG "ignoring $line" 499 DEBUG "ignoring $line"
484 continue 500 continue
485 fi 501 fi
486 502
487 case $key in 503 case $key in
488 # The descriptive stuff we'll just save for later. 504 # The descriptive stuff we'll just save for later.
489 file) 505 file)
490 file="$val" 506 file="$val"
491 ;; 507 ;;
492 size) 508 zipfilesize)
493 size="$val" 509 zipfilesize="$val"
510 ;;
511 filesize)
512 filesize="$val"
494 ;; 513 ;;
495 md5) 514 md5)
496 md5="$val" 515 md5="$val"
497 ;; 516 ;;
498 sha1) 517 sha1)
499 sha1="$val" 518 sha1="$val"
500 ;; 519 ;;
501 url) 520 url)
502 # Try to download each url until one works. 521 # Try to download each url until one works.
503 if [ -n "$url" ]; then 522 if [ -n "$url" ]; then
504 # We've already got one (it's very nice). 523 # We've already got one (it's very nice).
505 continue; 524 continue;
506 fi 525 fi
507 warn "Downloading image tarball from $val" 526 warn "Downloading image zipfile from $val"
508 warn "" 527 warn ""
509 tarball=${val##*/} 528 zipfile=${val##*/}
510 if fetch_url "$val" "$tarball" "resumeok"; then 529 if fetch_url "$val" "$zipfile" "resumeok"; then
511 # Got it. 530 # Got it.
512 url="$val" 531 url="$val"
513 fi 532 fi
514 ;; 533 ;;
515 esac 534 esac
516 fi 535 fi
517 done < "$config" 536 done < "$config"
518 537
519 if [ -z "$url" ]; then 538 if [ -z "$url" ]; then
520 DEBUG "couldn't fetch tarball" 539 DEBUG "couldn't fetch zipfile"
521 return 1 540 return 1
522 fi 541 fi
523 542
524 # Verify the tarball 543 # Verify the zipfile
525 if ! ls -l "$tarball" | grep -q "$size"; then 544 if ! ls -l "$zipfile" | grep -q "$zipfilesize"; then
526 DEBUG "size is wrong" 545 DEBUG "zipfilesize is wrong"
527 return 1 546 return 1
528 fi 547 fi
529 sum=$(compute_checksum "$tarball") 548 sum=$(compute_checksum "$zipfile")
530 DEBUG "checksum is $sum" 549 DEBUG "checksum is $sum"
531 if [ "$CHECKTYPE" = "md5" ] && [ "$sum" != "$md5" ]; then 550 if [ "$CHECKTYPE" = "md5" ] && [ "$sum" != "$md5" ]; then
532 DEBUG "wrong $CHECK" 551 DEBUG "wrong $CHECK"
533 return 1 552 return 1
534 elif [ "$CHECKTYPE" = "sha1" ] && [ "$sum" != "$sha1" ]; then 553 elif [ "$CHECKTYPE" = "sha1" ] && [ "$sum" != "$sha1" ]; then
535 DEBUG "wrong $CHECK" 554 DEBUG "wrong $CHECK"
536 return 1 555 return 1
537 fi 556 fi
538 557
539 # Unpack the file 558 # Unpack the file
540 warn "Unpacking the tarball" 559 warn "Unpacking the zipfile"
541 rm -f "$file" 560 rm -f "$file"
542 if ! unzip "$tarball" "$file"; then 561 if ! unzip "$zipfile" "$file"; then
543 DEBUG "Can't unpack the tarball" 562 DEBUG "Can't unpack the zipfile"
544 return 1 563 return 1
545 fi 564 fi
546 565
566 if ! ls -l "$file" | grep -q "$filesize"; then
567 DEBUG "unpacked filesize is wrong"
568 return 1
569 fi
570
547 # global 571 # global
548 image_file="$file" 572 image_file="$file"
549 } 573 }
550 574
551 ############################################################################## 575 ##############################################################################
552 # Helper functions to manage USB drives. 576 # Helper functions to manage USB drives.
553 577
554 # Return a list of base device names ("sda sdb ...") for all USB drives 578 # Return a list of base device names ("sda sdb ...") for all USB drives
555 get_devlist() { 579 get_devlist() {
556 local dev 580 local dev
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 736
713 cd "$WORKDIR" 737 cd "$WORKDIR"
714 warn "Working in $WORKDIR/" 738 warn "Working in $WORKDIR/"
715 rm -f "$debug" 739 rm -f "$debug"
716 740
717 # Download the config file to see what choices we have. 741 # Download the config file to see what choices we have.
718 warn "Downloading config file from $CONFIGURL" 742 warn "Downloading config file from $CONFIGURL"
719 fetch_url "$CONFIGURL" "$tmpfile" || \ 743 fetch_url "$CONFIGURL" "$tmpfile" || \
720 gfatal "Unable to download the config file" 744 gfatal "Unable to download the config file"
721 745
722 # Un-DOS-ify the config file and separate the version info from the images 746 # Separate the version info from the images
723 tr -d '\015' < "$tmpfile" | grep '^recovery_tool' > "$version" 747 grep '^recovery_tool' "$tmpfile" > "$version"
724 tr -d '\015' < "$tmpfile" | grep -v '^#' | grep -v '^recovery_tool' > "$config" 748 grep -v '^#' "$tmpfile" | grep -v '^recovery_tool' > "$config"
725 # Add one empty line to the config file to terminate the last stanza 749 # Add one empty line to the config file to terminate the last stanza
726 echo >> "$config" 750 echo >> "$config"
scottz 2010/12/09 01:47:25 Is there a reason to not make this be part of the
Bill Richardson 2010/12/09 17:34:29 No. The first example didn't have it, and here at
727 751
728 # Make sure that the config file version matches this script version. 752 # Make sure that the config file version matches this script version.
729 # FIXME: Prefer linux or use linux only? What about macs? 753 # FIXME: Prefer linux or use linux only? What about macs?
730 tmp=$(grep '^recovery_tool_linux_version=' "$version") || \ 754 tmp=$(grep '^recovery_tool_linux_version=' "$version") || \
731 tmp=$(grep '^recovery_tool_version=' "$version") || \ 755 tmp=$(grep '^recovery_tool_version=' "$version") || \
732 gfatal "The config file doesn't contain a version string." 756 gfatal "The config file doesn't contain a version string."
733 filevers=${tmp#*=} 757 filevers=${tmp#*=}
734 if [ "$filevers" != "$MYVERSION" ]; then 758 if [ "$filevers" != "$MYVERSION" ]; then
735 tmp=$(grep '^recovery_tool_update=' "$version"); 759 tmp=$(grep '^recovery_tool_update=' "$version");
736 msg=${tmp#*=} 760 msg=${tmp#*=}
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 prompt "Shall I remove the temporary files now? [y/n] " 837 prompt "Shall I remove the temporary files now? [y/n] "
814 read tmp 838 read tmp
815 case $tmp in 839 case $tmp in
816 [Yy]*) 840 [Yy]*)
817 cd 841 cd
818 \rm -rf ${WORKDIR} 842 \rm -rf ${WORKDIR}
819 ;; 843 ;;
820 esac 844 esac
821 845
822 exit 0 846 exit 0
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698