From a0185aecc9e7eec34969aa5c59f4af70d05f8071 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Wed, 22 Apr 2015 18:52:02 +0800 Subject: [PATCH] make_dev_ssd: Add '--edit_config' to support in-place editing. The '--save_config' and '--set_config' are found to be very useful for developers but it's sometimes inconvenient that developer must specify a temporary path and to know the implicit rules of how the files are generated. Since most people just want to do in-place editing, we can add a --edit_config so developers can simply invoke "make_dev_ssd --edit_config --partitions 2" to start changing kernel command line without worrying about where to store the temporary files. BRANCH=none BUG=none TEST=./make_dev_ssd.sh --edit_config --partition 2 Change-Id: Ib8f19115df31f3f250b4378201d0f7ea562fec15 Reviewed-on: https://chromium-review.googlesource.com/266814 Tested-by: Hung-Te Lin Reviewed-by: Bill Richardson Reviewed-by: Randall Spangler Commit-Queue: Hung-Te Lin --- scripts/image_signing/make_dev_ssd.sh | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scripts/image_signing/make_dev_ssd.sh b/scripts/image_signing/make_dev_ssd.sh index df8ad46970..28d42a6974 100755 --- a/scripts/image_signing/make_dev_ssd.sh +++ b/scripts/image_signing/make_dev_ssd.sh @@ -35,6 +35,8 @@ DEFINE_string save_config "" \ "Base filename to store kernel configs to, instead of resigning." "" DEFINE_string set_config "" \ "Base filename to load kernel configs from" "" +DEFINE_boolean edit_config "${FLAGS_FALSE}" \ + "Edit kernel config in-place." "" DEFINE_string partitions "" \ "List of partitions to examine (default: $DEFAULT_PARTITIONS)" "" DEFINE_boolean recovery_key "$FLAGS_FALSE" \ @@ -192,6 +194,33 @@ resign_ssd_kernel() { echo "$name: Replaced config from $new_config_file" fi + if [ "${FLAGS_edit_config}" = ${FLAGS_TRUE} ]; then + debug_msg "Editing kernel config file." + local new_config_file="$(make_temp_file)" + echo "${kernel_config}" >"${new_config_file}" + local old_md5sum="$(md5sum "${new_config_file}")" + local editor="${VISUAL:-${EDITOR:-vi}}" + echo "${name}: Editing kernel config:" + # On ChromiumOS, some builds may come with broken EDITOR that refers to + # nano so we want to check again if the editor really exists. + if type "${editor}" >/dev/null 2>&1; then + "${editor}" "${new_config_file}" + else + # This script runs under dash but we want readline in bash to support + # editing in in console. + bash -c "read -e -i '${kernel_config}' && + echo \"\${REPLY}\" >${new_config_file}" || + err_die "Failed to run editor. Please specify editor name by VISUAL." + fi + kernel_config="$(cat "${new_config_file}")" + if [ "$(md5sum "${new_config_file}")" = "${old_md5sum}" ]; then + echo "${name}: Config not changed." + else + debug_msg "New kernel config: ${kernel_config})" + echo "${name}: Config updated" + fi + fi + if [ ${FLAGS_remove_rootfs_verification} = $FLAGS_FALSE ]; then debug_msg "Bypassing rootfs verification check" else