From a4bb9d9a127cd96ff8a4df1a8f68c2fcafed8431 Mon Sep 17 00:00:00 2001 From: utsav Date: Mon, 27 Apr 2015 11:46:57 +0530 Subject: [PATCH] colorize osbash scripts using lib-color.sh It colorizes the output of osbash.sh using the conventions given in lib-color.sh. Implements: blueprint osbash-color-support Closes-Bug: #1443136 Change-Id: I42ca96454fdab47b283222e2deaf3e9b51d03106 --- labs/lib/functions.sh | 2 +- labs/lib/osbash/functions-host.sh | 16 ++++----- labs/lib/osbash/lib.fedora-20-x86_64 | 2 +- .../osbash/lib.ubuntu-12.04.4-server-amd64 | 2 +- labs/lib/osbash/lib.ubuntu-14.04-server-amd64 | 2 +- labs/lib/osbash/virtualbox-functions.sh | 34 +++++++++---------- labs/lib/osbash/virtualbox-install_base.sh | 20 +++++------ labs/lib/osbash/virtualbox-install_nodes.sh | 2 +- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/labs/lib/functions.sh b/labs/lib/functions.sh index 8ce9f4ac..ba53562e 100644 --- a/labs/lib/functions.sh +++ b/labs/lib/functions.sh @@ -50,7 +50,7 @@ function yes_or_no { return 0 ;; *) - echo "Invalid input: $input" + echo -e "${CError:-}Invalid input: ${CData:-}$input${CReset:-}" ;; esac done diff --git a/labs/lib/osbash/functions-host.sh b/labs/lib/osbash/functions-host.sh index d7e6d905..1aa8c499 100644 --- a/labs/lib/osbash/functions-host.sh +++ b/labs/lib/osbash/functions-host.sh @@ -112,7 +112,7 @@ function vm_ssh { function wait_for_ssh { local ssh_port=$1 - echo -n "Waiting for ssh server to respond on local port $ssh_port." + echo -e -n "${CStatus:-}Waiting for ssh server to respond on local port ${CData:-}$ssh_port.${CReset:-}" while [ : ]; do if vm_ssh "$ssh_port" exit ; then break @@ -144,7 +144,7 @@ function ssh_exec_script { > "$log_path" 2>&1 || rc=$? if [ $rc -ne 0 ]; then echo >&2 - echo "ERROR: ssh returned status $rc for $remote_path" | + echo -e "${CError:-}ERROR: ssh returned status ${CData:-}$rc${CError:-} for${CData:-} $remote_path${CReset:-}" | tee >&2 -a "$LOG_DIR/error.log" # kill osbash host scripts kill -- -$$ @@ -219,7 +219,7 @@ function wait_for_autofiles { if [ -f "$STATUS_DIR/done" ]; then rm "$STATUS_DIR/done" else - echo -e >&2 "\nERROR occured. Exiting." + echo -e >&2 "${CError:-}\nERROR occured. Exiting.${CReset:-}" kill -- -$$ fi echo @@ -303,7 +303,7 @@ function get_cmd_options { vm_name=$OPTARG ;; *) - echo >&2 "Error: bad option $OPTARG." + echo -e >&2 "${CError:-}Error: bad option ${CData:-}$OPTARG.${CReset:-}" exit 1 ;; esac @@ -371,7 +371,7 @@ function command_from_config { _autostart_queue "$script_rel_path" ;; *) - echo >&2 "Error: invalid cmd: $cmd" + echo -e >&2 "${CError:-}Error: invalid cmd: ${CData:-}$cmd${CReset:-}" exit 1 ;; esac @@ -383,7 +383,7 @@ function autostart_from_config { local config_path=$CONFIG_DIR/$config_file if [ ! -f "$config_path" ]; then - echo >&2 "Config file not found: $config_file" + echo -e >&2 "${CMissing:-}Config file not found: ${CData:-}$config_file${CReset:-}" return 1 fi @@ -400,7 +400,7 @@ function autostart_from_config { command_from_config $field_2 else # Syntax error - echo -n >&2 "ERROR in $config_file: '$field_1" + echo -e -n >&2 "${CError:-}ERROR in ${CInfo:-}$config_file: ${CData:-}'$field_1${CReset:-}" if [ -n "$field_2" ]; then echo >&2 " $field_2'" else @@ -433,7 +433,7 @@ function download { fi fi if [ $rc -ne 0 ]; then - echo >&2 "Unable to download $url, quitting." + echo -e >&2 "${CError:-}Unable to download ${CData:-}$url${CError:-}, quitting.${CReset:-}" exit 1 fi } diff --git a/labs/lib/osbash/lib.fedora-20-x86_64 b/labs/lib/osbash/lib.fedora-20-x86_64 index 204e96bb..7a38ab24 100644 --- a/labs/lib/osbash/lib.fedora-20-x86_64 +++ b/labs/lib/osbash/lib.fedora-20-x86_64 @@ -33,7 +33,7 @@ function vbox_distro_start_installer { vbox_sleep 1 - echo "Pushing boot command line" + echo -e "${CStatus:-}Pushing boot command line${CReset:-}" vbox_kbd_string_input "$vm_name" "$boot_args" echo "Initiating boot sequence" diff --git a/labs/lib/osbash/lib.ubuntu-12.04.4-server-amd64 b/labs/lib/osbash/lib.ubuntu-12.04.4-server-amd64 index 7e71d586..e751dc3e 100644 --- a/labs/lib/osbash/lib.ubuntu-12.04.4-server-amd64 +++ b/labs/lib/osbash/lib.ubuntu-12.04.4-server-amd64 @@ -43,7 +43,7 @@ function vbox_distro_start_installer { vbox_sleep 1 - echo "Pushing boot command line" + echo -e "${CStatus:-}Pushing boot command line${CReset:-}" vbox_kbd_string_input "$vm_name" "$boot_args" echo "Initiating boot sequence" diff --git a/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 b/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 index dc8ab906..57f303d7 100644 --- a/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 +++ b/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 @@ -43,7 +43,7 @@ function vbox_distro_start_installer { vbox_sleep 1 - echo "Pushing boot command line" + echo -e "${CStatus:-}Pushing boot command line${CReset:-}" vbox_kbd_string_input "$vm_name" "$boot_args" echo "Initiating boot sequence" diff --git a/labs/lib/osbash/virtualbox-functions.sh b/labs/lib/osbash/virtualbox-functions.sh index 07b86060..5e4beccb 100644 --- a/labs/lib/osbash/virtualbox-functions.sh +++ b/labs/lib/osbash/virtualbox-functions.sh @@ -19,7 +19,7 @@ function vbm { local rc=0 "$VBM_EXE" "$@" || rc=$? if [ $rc -ne 0 ]; then - echo >&2 "FAILURE: VBoxManage: $@" + echo -e >&2 "${CError:-}FAILURE: VBoxManage: $@${CReset:-}" return 1 fi else @@ -62,19 +62,19 @@ function vm_wait_for_shutdown { # Return if we are just faking it for wbatch ${OSBASH:+:} return 0 - echo >&2 -n "Machine shutting down" + echo -e >&2 -n "${CStatus:-}Machine shutting down${CReset:-}" until WBATCH= $VBM showvminfo --machinereadable "$vm_name" 2>/dev/null | \ grep -q '="poweroff"'; do echo -n . sleep 1 done - echo >&2 -e "\nMachine powered off." + echo >&2 -e "${CStatus:-}\nMachine powered off.${CReset:-}" } function vm_power_off { local vm_name=$1 if vm_is_running "$vm_name"; then - echo >&2 "Powering off VM \"$vm_name\"" + echo -e >&2 "${CStatus:-}Powering off VM ${CData:-}\"$vm_name\"${CReset:-}" $VBM controlvm "$vm_name" poweroff fi # VirtualBox VM needs a break before taking new commands @@ -121,7 +121,7 @@ function create_hostonlyif { if [[ $out =~ $re ]]; then echo "${BASH_REMATCH[1]}" else - echo >&2 "Host-only interface creation failed" + echo -e >&2 "${CError:-}Host-only interface creation failed${CReset:-}" return 1 fi } @@ -142,11 +142,11 @@ function create_network { "Using it, too." fi else - echo >&2 "Creating host-only interface" + echo -e >&2 "${CStatus:-}Creating host-only interface${CReset:-}" if_name=$(create_hostonlyif) fi - echo >&2 "Configuring host-only network $ip ($if_name)" + echo -e >&2 "${CStatus:-}Configuring host-only network ${CData:-}$ip ($if_name)${CReset:-}" $VBM hostonlyif ipconfig "$if_name" \ --ip "$ip" \ --netmask 255.255.255.0 >/dev/null @@ -170,14 +170,14 @@ function disk_registered { # disk can be either a path or a disk UUID function disk_unregister { local disk=$1 - echo >&2 -e "Unregistering disk\n\t$disk" + echo >&2 -e "${CStatus:-}Unregistering disk\n\t${CData:-}$disk${CReset:-}" $VBM closemedium disk "$disk" } function create_vdi { local hd_path=$1 local size=$2 - echo >&2 -e "Creating disk:\n\t$hd_path" + echo >&2 -e "${CStatus:-}Creating disk:\n\t${CData:-}$hd_path${CReset:-}" $VBM createhd --format VDI --filename "$hd_path" --size "$size" } @@ -353,7 +353,7 @@ function vm_create { # # XXX temporary hack # --groups not supported in VirtualBox 4.1 (Mac OS X 10.5) - echo >&2 "Creating VM \"$vm_name\"" + echo -e >&2 "${CStatus:-}Creating VM ${CData:-}\"$vm_name\"${CReset:-}" local ver=$(get_vb_version) if [[ $ver = 4.1* ]]; then $VBM createvm \ @@ -383,7 +383,7 @@ function vm_create { $VBM storagectl "$vm_name" --name SATA --hostiocache on $VBM storagectl "$vm_name" --name IDE --add ide - echo >&2 "Created VM \"$vm_name\"" + echo -e >&2 "${CStatus:-}Created VM ${CData:-}\"$vm_name\"${CReset:-}" } #------------------------------------------------------------------------------- @@ -471,7 +471,7 @@ function vm_export_dir { function vm_unregister_del { local vm_name=$1 - echo >&2 "Unregistering and deleting VM \"$vm_name\"" + echo -e >&2 "${CStatus:-}Unregistering and deleting VM ${CData:-}\"$vm_name\"${CReset:-}" $VBM unregistervm "$vm_name" --delete } @@ -483,7 +483,7 @@ function vm_delete { vm_power_off "$vm_name" local hd_path="$(vm_get_disk_path "$vm_name")" if [ -n "$hd_path" ]; then - echo >&2 -e "Disk attached: $hd_path" + echo >&2 -e "${CInfo:-}Disk attached: ${CData:-}$hd_path${CReset:-}" vm_detach_disk "$vm_name" disk_unregister "$hd_path" echo >&2 -e "Deleting: $hd_path" @@ -501,7 +501,7 @@ function disk_delete_child_vms { local disk=$1 if ! disk_registered "$disk"; then # VirtualBox doesn't know this disk; we are done - echo >&2 -e "Disk not registered with VirtualBox:\n\t$disk" + echo >&2 -e "${CError:-}Disk not registered with VirtualBox:\n\t${CData:-}$disk${CReset:-}" return 0 fi @@ -527,7 +527,7 @@ function disk_delete_child_vms { echo 2>&1 -e "\tstill attached to VM \"$vm_name\"" vm_delete "$vm_name" else - echo >&2 "Unregistering and deleting: $child_uuid" + echo -e >&2 "${CStatus:-}Unregistering and deleting: ${CData:-}$child_uuid${CReset:-}" disk_unregister "$child_uuid" echo >&2 -e "\t$child_disk" rm -f "$child_disk" @@ -661,7 +661,7 @@ function vm_attach_guestadd-iso { echo >&2 "Attached $GUESTADD_ISO" return 0 else - echo >&2 "Failed to attach $GUESTADD_ISO" + echo -e >&2 "${CError:-}Failed to attach ${CData:-}$GUESTADD_ISO${CReset:-}" return 3 fi } @@ -725,7 +725,7 @@ function vbox_kbd_string_input { function vbox_boot { local vm_name=$1 - echo >&2 "Starting VM \"$vm_name\"" + echo -e >&2 "${CStatus:-}Starting VM ${CData:-}\"$vm_name\"${CReset:-}" if [ -n "${VM_UI:-}" ]; then $VBM startvm "$vm_name" --type "$VM_UI" else diff --git a/labs/lib/osbash/virtualbox-install_base.sh b/labs/lib/osbash/virtualbox-install_base.sh index 2fc7a85e..743d33ea 100644 --- a/labs/lib/osbash/virtualbox-install_base.sh +++ b/labs/lib/osbash/virtualbox-install_base.sh @@ -7,18 +7,18 @@ function check_md5 { if ! md5exe=$(which md5sum); then # On Mac OS X, the tool is called md5 if ! md5exe=$(which md5); then - echo >&2 "Neither md5sum nor md5 found. Aborting." + echo -e >&2 "${CError:-}Neither md5sum nor md5 found. Aborting.${CReset:-}" exit 1 fi fi - echo >&2 -n "Verifying ISO image MD5 checksum: " + echo -e >&2 -n "${CStatus:-}Verifying ISO image MD5 checksum: ${CReset:-}" if $md5exe "$file" | grep -q "$csum"; then echo >&2 "okay." else - echo >&2 "Verification failed. ISO image is corrupt." + echo -e >&2 "${CError:-}Verification failed. ISO image is corrupt.${CReset:-}" echo >&2 "Removing the ISO image." rm "$file" - echo >&2 "Please re-run osbash script." + echo -e >&2 "${CError:-}Please re-run osbash script.${CReset:-}" exit 1 fi } @@ -46,7 +46,7 @@ function vm_install_base { local iso_name="$(get_iso_name)" if [ -z "$iso_name" ]; then - echo >&2 "Either ISO URL or name needed (ISO_URL, INSTALL_ISO)." + echo -e >&2 "${CMissing:-}Either ISO URL or name needed (ISO_URL, INSTALL_ISO).${CReset:-}" exit 1 fi INSTALL_ISO=$ISO_DIR/$iso_name @@ -54,7 +54,7 @@ function vm_install_base { ${OSBASH:-:} find_install-iso "$iso_name" fi - echo >&2 -e "Install ISO:\n\t$INSTALL_ISO" + echo >&2 -e "${CInfo:-}Install ISO:\n\t${CData:-}$INSTALL_ISO${CReset:-}" ${OSBASH:-:} check_md5 "$INSTALL_ISO" "$ISO_MD5" @@ -108,14 +108,14 @@ function vm_install_base { vbox_distro_start_installer "$vm_name" - echo >&2 "Installing operating system; waiting for reboot" + echo -e >&2 "${CStatus:-}Installing operating system; waiting for reboot${CReset:-}" # Wait for ssh connection and execute scripts in autostart directory # (for wbatch, osbashauto does the processing instead) ${WBATCH:+:} ssh_process_autostart "$VM_BASE_SSH_PORT" & # After reboot wait_for_autofiles - echo >&2 "Installation done for VM $vm_name" + echo -e >&2 "${CStatus:-}Installation done for VM ${CData:-}$vm_name${CReset:-}" vm_wait_for_shutdown "$vm_name" @@ -131,7 +131,7 @@ function vm_install_base { # a new disk next time the script runs. disk_unregister "$base_build_disk" - echo >&2 "Base disk created" + echo -e >&2 "${CStatus:-}Base disk created${CReset:-}" echo >&2 "Moving base disk to $base_disk" ${OSBASH:-:} mv -vf "$base_build_disk" "$base_disk" @@ -139,7 +139,7 @@ function vm_install_base { ${WBATCH:-:} wbatch_end_file - echo >&2 -e "$(date) osbash vm_install ends\n" + echo >&2 -e "${CData:-}$(date) ${CStatus:-}osbash vm_install ends\n${CReset:-}" } # vim: set ai ts=4 sw=4 et ft=sh: diff --git a/labs/lib/osbash/virtualbox-install_nodes.sh b/labs/lib/osbash/virtualbox-install_nodes.sh index 6fd72e6e..51ef6581 100644 --- a/labs/lib/osbash/virtualbox-install_nodes.sh +++ b/labs/lib/osbash/virtualbox-install_nodes.sh @@ -73,7 +73,7 @@ function vm_init_node { function vm_build_nodes { CONFIG_NAME=$(get_distro_name "$DISTRO")_$1 - echo "Configuration file: $CONFIG_NAME" + echo -e "${CInfo:-}Configuration file: ${CData:-}$CONFIG_NAME${CReset:-}" ${WBATCH:-:} wbatch_begin_node "$CONFIG_NAME" #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -