Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 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 # Abort on error. | 7 # Abort on error. |
| 8 set -e | 8 set -e |
| 9 | 9 |
| 10 # Load common constants and variables. | 10 # Load common constants and variables. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 } | 25 } |
| 26 | 26 |
| 27 # Given a dm param string which includes a long and unpredictable | 27 # Given a dm param string which includes a long and unpredictable |
| 28 # sha1 hash, return the same string with the sha1 hash replaced | 28 # sha1 hash, return the same string with the sha1 hash replaced |
| 29 # with a magic placeholder. This same magic placeholder is used | 29 # with a magic placeholder. This same magic placeholder is used |
| 30 # in the config file, for comparison purposes. | 30 # in the config file, for comparison purposes. |
| 31 dmparams_mangle_sha1() { | 31 dmparams_mangle_sha1() { |
| 32 echo "$1" | sed 's/sha1 [0-9a-fA-F]*/sha1 MAGIC_HASH/' | 32 echo "$1" | sed 's/sha1 [0-9a-fA-F]*/sha1 MAGIC_HASH/' |
| 33 } | 33 } |
| 34 | 34 |
| 35 escape_regexmetas() { | |
|
gauravsh
2011/02/18 00:11:56
add comment saying this escapes non-alphanumeric c
| |
| 36 echo "$1" | sed 's/\([^a-zA-Z0-9]\)/\\\1/g' | |
| 37 } | |
| 38 | |
| 35 usage() { | 39 usage() { |
| 36 echo "Usage $PROG image [config]" | 40 echo "Usage $PROG image [config]" |
| 37 } | 41 } |
| 38 | 42 |
| 39 main() { | 43 main() { |
| 40 # We want to catch all the discrepancies, not just the first one. | 44 # We want to catch all the discrepancies, not just the first one. |
| 41 # So, any time we find one, we set testfail=1 and continue. | 45 # So, any time we find one, we set testfail=1 and continue. |
| 42 # When finished we will use testfail to determine our exit value. | 46 # When finished we will use testfail to determine our exit value. |
| 43 local testfail=0 | 47 local testfail=0 |
| 44 | 48 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 83 |
| 80 # Special-case handling of the dm= param: | 84 # Special-case handling of the dm= param: |
| 81 if [[ "$dmparams" != "$required_dmparams" ]]; then | 85 if [[ "$dmparams" != "$required_dmparams" ]]; then |
| 82 echo "Kernel dm= parameter does not match expected value!" | 86 echo "Kernel dm= parameter does not match expected value!" |
| 83 echo "Expected: $required_dmparams" | 87 echo "Expected: $required_dmparams" |
| 84 echo "Actual: $dmparams" | 88 echo "Actual: $dmparams" |
| 85 testfail=1 | 89 testfail=1 |
| 86 fi | 90 fi |
| 87 | 91 |
| 88 # Ensure all other required params are present. | 92 # Ensure all other required params are present. |
| 89 for param in ${required_kparams[@]}; do : | 93 for param in ${required_kparams[@]}; do : |
|
gauravsh
2011/02/18 00:11:56
remove unnecessary colon at the end
| |
| 90 if [[ "$kparams_nodm" != *$param* ]]; then | 94 if [[ "$kparams_nodm" != *$param* ]]; then |
| 91 echo "Kernel parameters missing required value: $param" | 95 echo "Kernel parameters missing required value: $param" |
| 92 testfail=1 | 96 testfail=1 |
| 93 else | 97 else |
| 94 # Remove matched params as we go. If all goes well, kparams_nodm | 98 # Remove matched params as we go. If all goes well, kparams_nodm |
| 95 # will be nothing left but whitespace by the end. | 99 # will be nothing left but whitespace by the end. |
| 96 kparams_nodm=${kparams_nodm/$param/} | 100 param=$(escape_regexmetas "$param") |
| 101 kparams_nodm=$(echo "$kparams_nodm" | sed "s/\b$param\b//") | |
| 97 fi | 102 fi |
| 98 done | 103 done |
| 99 | 104 |
| 100 # Check-off each of the allowed-but-optional params that were present. | 105 # Check-off each of the allowed-but-optional params that were present. |
| 101 for param in ${optional_kparams[@]}; do : | 106 for param in ${optional_kparams[@]}; do : |
|
gauravsh
2011/02/18 00:11:56
remove unnecessary colon at the end
| |
| 102 kparams_nodm=${kparams_nodm/$param/} | 107 param=$(escape_regexmetas "$param") |
| 108 kparams_nodm=$(echo "$kparams_nodm" | sed "s/\b$param\b//") | |
| 103 done | 109 done |
| 104 | 110 |
| 105 # This section enforces the default-deny for any unexpected params | 111 # This section enforces the default-deny for any unexpected params |
| 106 # not already processed by one of the above loops. | 112 # not already processed by one of the above loops. |
| 107 if [[ ! -z ${kparams_nodm// /} ]]; then | 113 if [[ ! -z ${kparams_nodm// /} ]]; then |
| 108 echo "Unexpected kernel parameters found: $kparams_nodm" | 114 echo "Unexpected kernel parameters found: $kparams_nodm" |
| 109 testfail=1 | 115 testfail=1 |
| 110 fi | 116 fi |
| 111 | 117 |
| 112 exit $testfail | 118 exit $testfail |
| 113 } | 119 } |
| 114 | 120 |
| 115 main $@ | 121 main $@ |
| OLD | NEW |