fixed chance for false deletions via variable naming

This commit is contained in:
inxi-svn 2011-04-26 08:19:16 +00:00
parent 5e5f24d76a
commit cff962b5e7

85
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 1.4.82-b7 #### version: 1.4.82-b8
#### Date: April 25 2011 #### Date: April 25 2011
######################################################################## ########################################################################
#### SPECIAL THANKS #### SPECIAL THANKS
@ -306,9 +306,11 @@ DEBUG_BUFFER_INDEX=0
DEFAULT_COLOR_SCHEME=2 DEFAULT_COLOR_SCHEME=2
# Always leave this blank, this is only going to be set in inxi.conf files, that makes testing # 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 # for user changes easier after sourcing the files
DEFAULT_GLOBAL_COLOR_SCHEME='' GLOBAL_COLOR_SCHEME=''
DEFAULT_IRC_COLOR_SCHEME='' IRC_COLOR_SCHEME=''
DEFAULT_TERM_COLOR_SCHEME='' CONSOLE_IRC_COLOR_SCHEME=''
CONSOLE_COLOR_SCHEME=''
VIRT_TERMINAL_COLOR_SCHEME=''
# Default indentation level # Default indentation level
INDENT=10 INDENT=10
@ -465,6 +467,8 @@ main()
{ {
eval $LOGFS eval $LOGFS
local color_scheme=''
# This function just initializes variables # This function just initializes variables
initialize_script_data initialize_script_data
@ -549,21 +553,25 @@ main()
# The override value only will occur in user config files # The override value only will occur in user config files
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
# note, leaving this iff as a first run default for now, too many possible glitches could happen # 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 if [[ $B_RUN_COLOR_SELECTOR == 'true' ]];then
select_default_color_scheme select_default_color_scheme
elif [[ -n $DEFAULT_TERM_COLOR_SCHEME ]];then elif [[ -n $GLOBAL_COLOR_SCHEME ]];then
set_color_scheme $DEFAULT_TERM_COLOR_SCHEME set_color_scheme $GLOBAL_COLOR_SCHEME
elif [[ -n $DEFAULT_GLOBAL_COLOR_SCHEME ]];then elif [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
set_color_scheme $DEFAULT_GLOBAL_COLOR_SCHEME set_color_scheme $CONSOLE_COLOR_SCHEME
elif [[ -n $VIRT_TERMINAL_COLOR_SCHEME ]];then
set_color_scheme $VIRT_TERMINAL_COLOR_SCHEME
else else
set_color_scheme "$DEFAULT_COLOR_SCHEME" set_color_scheme "$DEFAULT_COLOR_SCHEME"
fi fi
else else
if [[ -n $DEFAULT_IRC_COLOR_SCHEME ]];then if [[ -n $GLOBAL_COLOR_SCHEME ]];then
set_color_scheme $DEFAULT_IRC_COLOR_SCHEME set_color_scheme $GLOBAL_COLOR_SCHEME
elif [[ -n $DEFAULT_GLOBAL_COLOR_SCHEME ]];then elif [[ -n $CONSOLE_IRC_COLOR_SCHEME && -z $DISPLAY ]];then
set_color_scheme $DEFAULT_GLOBAL_COLOR_SCHEME set_color_scheme $CONSOLE_IRC_COLOR_SCHEME
elif [[ -n $IRC_COLOR_SCHEME ]];then
set_color_scheme $IRC_COLOR_SCHEME
else else
set_color_scheme "$DEFAULT_COLOR_SCHEME" set_color_scheme "$DEFAULT_COLOR_SCHEME"
fi 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 " $(($i+2)))$spacer Exit, use another terminal, or set manually."
print_screen_output "------------------------------------------------------------------------------" 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 "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 "and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c 95 (terminal),"
print_screen_output "98 (irc), 99 (terminal). Your selection(s) will be stored here: $config_file" 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 "Setting global value overrides terminal and irc. Setting irc or terminal remove the global." print_screen_output "Global overrides virtual-terminal/terminal/irc/irc-terminal. Irc/irc-terminal/virtual-terminal/terminal removes global."
print_screen_output "------------------------------------------------------------------------------" print_screen_output "------------------------------------------------------------------------------"
echo -n "" echo -n ""
read user_selection read user_selection
if [[ -n $( grep -Es '^([0-9]+)$' <<< "$user_selection" ) && $user_selection -lt $i ]];then if [[ -n $( grep -Es '^([0-9]+)$' <<< "$user_selection" ) && $user_selection -lt $i ]];then
case $COLOR_SELECTION in case $COLOR_SELECTION in
irc) irc)
config_variable='DEFAULT_IRC_COLOR_SCHEME' config_variable='IRC_COLOR_SCHEME'
;;
irc-terminal)
config_variable='CONSOLE_IRC_COLOR_SCHEME'
;; ;;
terminal) terminal)
config_variable='DEFAULT_TERM_COLOR_SCHEME' config_variable='CONSOLE_COLOR_SCHEME'
;;
virtual-terminal)
config_variable='VIRT_TERMINAL_COLOR_SCHEME'
;; ;;
global) global)
config_variable='DEFAULT_GLOBAL_COLOR_SCHEME' config_variable='GLOBAL_COLOR_SCHEME'
;; ;;
esac esac
set_color_scheme $user_selection set_color_scheme $user_selection
@ -884,21 +898,23 @@ select_default_color_scheme()
fi fi
# file exists now so we can go on to cleanup # file exists now so we can go on to cleanup
case $COLOR_SELECTION in case $COLOR_SELECTION in
irc|terminal) irc|irc-terminal|terminal|virtual-terminal)
sed -i '/DEFAULT_GLOBAL_COLOR_SCHEME=/d' $config_file sed -i '/GLOBAL_COLOR_SCHEME=/d' $config_file
;; ;;
global) 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 esac
elif [[ $user_selection == $i ]];then elif [[ $user_selection == $i ]];then
print_screen_output "Removing all color settings from config file now..." 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 set_color_scheme $DEFAULT_COLOR_SCHEME
elif [[ $user_selection == $(( $i+1 )) ]];then 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" print_screen_output "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 96 to 99"
if [[ -n $DEFAULT_TERM_COLOR_SCHEME ]];then if [[ -n $CONSOLE_COLOR_SCHEME ]];then
set_color_scheme $DEFAULT_TERM_COLOR_SCHEME set_color_scheme $CONSOLE_COLOR_SCHEME
else else
set_color_scheme $DEFAULT_COLOR_SCHEME set_color_scheme $DEFAULT_COLOR_SCHEME
fi fi
@ -1224,15 +1240,23 @@ get_parameters()
case $OPTARG in case $OPTARG in
99) 99)
B_RUN_COLOR_SELECTOR='true' B_RUN_COLOR_SELECTOR='true'
COLOR_SELECTION='terminal' COLOR_SELECTION='global'
;; ;;
98) 98)
B_RUN_COLOR_SELECTOR='true' B_RUN_COLOR_SELECTOR='true'
COLOR_SELECTION='irc' COLOR_SELECTION='irc-terminal'
;; ;;
97) 97)
B_RUN_COLOR_SELECTOR='true' 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' 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 "-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 " 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 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 "-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 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." print_screen_output "-D Show full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB."