From cff962b5e7a6bd336d664f8bc0e1ea9668e01f6d Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Tue, 26 Apr 2011 08:19:16 +0000 Subject: [PATCH] fixed chance for false deletions via variable naming --- inxi | 85 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/inxi b/inxi index 7462d31..d1ca747 100755 --- a/inxi +++ b/inxi @@ -1,7 +1,7 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 1.4.82-b7 +#### version: 1.4.82-b8 #### Date: April 25 2011 ######################################################################## #### SPECIAL THANKS @@ -306,9 +306,11 @@ DEBUG_BUFFER_INDEX=0 DEFAULT_COLOR_SCHEME=2 # Always leave this blank, this is only going to be set in inxi.conf files, that makes testing # for user changes easier after sourcing the files -DEFAULT_GLOBAL_COLOR_SCHEME='' -DEFAULT_IRC_COLOR_SCHEME='' -DEFAULT_TERM_COLOR_SCHEME='' +GLOBAL_COLOR_SCHEME='' +IRC_COLOR_SCHEME='' +CONSOLE_IRC_COLOR_SCHEME='' +CONSOLE_COLOR_SCHEME='' +VIRT_TERMINAL_COLOR_SCHEME='' # Default indentation level INDENT=10 @@ -465,6 +467,8 @@ main() { eval $LOGFS + local color_scheme='' + # This function just initializes variables initialize_script_data @@ -549,21 +553,25 @@ main() # The override value only will occur in user config files if [[ $B_RUNNING_IN_SHELL == 'true' ]];then # note, leaving this iff as a first run default for now, too many possible glitches could happen - # if [[ -z $DEFAULT_TERM_COLOR_SCHEME || $B_RUN_COLOR_SELECTOR == 'true' ]];then + # if [[ -z $CONSOLE_COLOR_SCHEME || $B_RUN_COLOR_SELECTOR == 'true' ]];then if [[ $B_RUN_COLOR_SELECTOR == 'true' ]];then select_default_color_scheme - elif [[ -n $DEFAULT_TERM_COLOR_SCHEME ]];then - set_color_scheme $DEFAULT_TERM_COLOR_SCHEME - elif [[ -n $DEFAULT_GLOBAL_COLOR_SCHEME ]];then - set_color_scheme $DEFAULT_GLOBAL_COLOR_SCHEME + elif [[ -n $GLOBAL_COLOR_SCHEME ]];then + set_color_scheme $GLOBAL_COLOR_SCHEME + elif [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then + set_color_scheme $CONSOLE_COLOR_SCHEME + elif [[ -n $VIRT_TERMINAL_COLOR_SCHEME ]];then + set_color_scheme $VIRT_TERMINAL_COLOR_SCHEME else set_color_scheme "$DEFAULT_COLOR_SCHEME" fi else - if [[ -n $DEFAULT_IRC_COLOR_SCHEME ]];then - set_color_scheme $DEFAULT_IRC_COLOR_SCHEME - elif [[ -n $DEFAULT_GLOBAL_COLOR_SCHEME ]];then - set_color_scheme $DEFAULT_GLOBAL_COLOR_SCHEME + if [[ -n $GLOBAL_COLOR_SCHEME ]];then + set_color_scheme $GLOBAL_COLOR_SCHEME + elif [[ -n $CONSOLE_IRC_COLOR_SCHEME && -z $DISPLAY ]];then + set_color_scheme $CONSOLE_IRC_COLOR_SCHEME + elif [[ -n $IRC_COLOR_SCHEME ]];then + set_color_scheme $IRC_COLOR_SCHEME else set_color_scheme "$DEFAULT_COLOR_SCHEME" fi @@ -852,22 +860,28 @@ select_default_color_scheme() print_screen_output " $(($i+2)))$spacer Exit, use another terminal, or set manually." print_screen_output "------------------------------------------------------------------------------" print_screen_output "Simply type the number for the color scheme that looks best to your eyes for your $COLOR_SELECTION settings" - print_screen_output "and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c 97 (global)," - print_screen_output "98 (irc), 99 (terminal). Your selection(s) will be stored here: $config_file" - print_screen_output "Setting global value overrides terminal and irc. Setting irc or terminal remove the global." + print_screen_output "and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c 95 (terminal)," + print_screen_output "96 (virtual-terminal), 97 (irc), 98 (irc-terminal), 99 (global). Your selection(s) will be stored here: $config_file" + print_screen_output "Global overrides virtual-terminal/terminal/irc/irc-terminal. Irc/irc-terminal/virtual-terminal/terminal removes global." print_screen_output "------------------------------------------------------------------------------" echo -n "" read user_selection if [[ -n $( grep -Es '^([0-9]+)$' <<< "$user_selection" ) && $user_selection -lt $i ]];then case $COLOR_SELECTION in irc) - config_variable='DEFAULT_IRC_COLOR_SCHEME' + config_variable='IRC_COLOR_SCHEME' + ;; + irc-terminal) + config_variable='CONSOLE_IRC_COLOR_SCHEME' ;; terminal) - config_variable='DEFAULT_TERM_COLOR_SCHEME' + config_variable='CONSOLE_COLOR_SCHEME' + ;; + virtual-terminal) + config_variable='VIRT_TERMINAL_COLOR_SCHEME' ;; global) - config_variable='DEFAULT_GLOBAL_COLOR_SCHEME' + config_variable='GLOBAL_COLOR_SCHEME' ;; esac set_color_scheme $user_selection @@ -884,21 +898,23 @@ select_default_color_scheme() fi # file exists now so we can go on to cleanup case $COLOR_SELECTION in - irc|terminal) - sed -i '/DEFAULT_GLOBAL_COLOR_SCHEME=/d' $config_file + irc|irc-terminal|terminal|virtual-terminal) + sed -i '/GLOBAL_COLOR_SCHEME=/d' $config_file ;; global) - sed -i -e '/DEFAULT_TERM_COLOR_SCHEME=/d' -e '/DEFAULT_IRC_COLOR_SCHEME=/d' $config_file + sed -i -e '/VIRT_TERMINAL_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' -e '/IRC_COLOR_SCHEME=/d' \ + -e '/CONSOLE_IRC_COLOR_SCHEME=/d' $config_file ;; esac elif [[ $user_selection == $i ]];then print_screen_output "Removing all color settings from config file now..." - sed -i -e '/DEFAULT_GLOBAL_COLOR_SCHEME=/d' -e '/DEFAULT_TERM_COLOR_SCHEME=/d' -e '/DEFAULT_IRC_COLOR_SCHEME=/d' $config_file + sed -i -e '/VIRT_TERMINAL_COLOR_SCHEME=/d' -e '/GLOBAL_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' \ + -e '/IRC_COLOR_SCHEME=/d' -e '/CONSOLE_IRC_COLOR_SCHEME=/d' $config_file set_color_scheme $DEFAULT_COLOR_SCHEME elif [[ $user_selection == $(( $i+1 )) ]];then - print_screen_output "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 97, 98, or 99" - if [[ -n $DEFAULT_TERM_COLOR_SCHEME ]];then - set_color_scheme $DEFAULT_TERM_COLOR_SCHEME + print_screen_output "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 96 to 99" + if [[ -n $CONSOLE_COLOR_SCHEME ]];then + set_color_scheme $CONSOLE_COLOR_SCHEME else set_color_scheme $DEFAULT_COLOR_SCHEME fi @@ -1224,15 +1240,23 @@ get_parameters() case $OPTARG in 99) B_RUN_COLOR_SELECTOR='true' - COLOR_SELECTION='terminal' + COLOR_SELECTION='global' ;; 98) B_RUN_COLOR_SELECTOR='true' - COLOR_SELECTION='irc' + COLOR_SELECTION='irc-terminal' ;; 97) B_RUN_COLOR_SELECTOR='true' - COLOR_SELECTION='global' + COLOR_SELECTION='irc' + ;; + 96) + B_RUN_COLOR_SELECTOR='true' + COLOR_SELECTION='virtual-terminal' + ;; + 95) + B_RUN_COLOR_SELECTOR='true' + COLOR_SELECTION='terminal' ;; *) B_COLOR_SCHEME_SET='true' @@ -1442,7 +1466,8 @@ show_options() print_screen_output "-c Available color schemes. Scheme number is required. Color selectors run a color selector option" print_screen_output " prior to $SCRIPT_NAME starting which lets you set the config file value for the selection." print_screen_output " Supported color schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11" - print_screen_output " Supported color selectors: -c 97 global colors; -c 98 IRC colors; -c 99 Terminal colors" + print_screen_output " Supported color selectors: -c 95 (Terminal - No X); 96 (Virtual Terminal - in X); 97 (IRC);" + print_screen_output " 98 (Irc Terminal - no X); 99 (Global)" print_screen_output "-C Show full CPU output, including per CPU clockspeed." print_screen_output "-d Default output verbosity level, same as: $SCRIPT_NAME -v 1" print_screen_output "-D Show full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB."