Deleted some trailing whitespace, added some explicit return values, fixed formatting in exec_com

This commit is contained in:
Jesse Gardner 2021-03-17 09:54:03 -07:00
parent 7e033f0089
commit 0a8a045b29
1 changed files with 39 additions and 41 deletions

View File

@ -62,7 +62,7 @@ return 0
}
#=========================================================================#
read_pipe ()
# DESCRIPTION: Flushes the contents of the named pipe to stdout,
# DESCRIPTION: Flushes the contents of the named pipe to stdout,
# nonblocking
# INPUT: None
# OUTPUT: Contents of named pipe on fd3
@ -94,9 +94,9 @@ write_pipe ()
# INPUT: Tell write_pipe whether information is coming on stdin or from
# a parameter, then pass information
# OUTPUT: None
# PARAMETERS: $1: '0' if passing another parameter(s), '1' if writing to
# PARAMETERS: $1: '0' if passing another parameter(s), '1' if writing to
# stdin instead.
# $2 and on: If $1 is 0, this is the information write_pipe will
# $2 and on: If $1 is 0, this is the information write_pipe will
# write as "$*"
#=========================================================================#
{
@ -119,7 +119,7 @@ return 0
#---GET/ALTER CONFIGURATION, CHECK SYSTEM---#
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#-------------------------------------------#
#=========================================================================#
check_config ()
#= DESCRIPTION: Given a name or name/value pair, check if it is a
@ -144,7 +144,7 @@ def_opt[STORAGE]="^/.*"
(( $# == 1 )) &&
{ [[ " ${!def_opt[*]} " =~ [[:space:]]${1}[[:space:]] ]];
return $?; }
local patt="${def_opt["${1}"]}"
[[ -n "$patt" ]] || return 1
[[ "$2" =~ $patt ]] || return 1
@ -187,7 +187,7 @@ done
((missing)) &&
{ echo "This script won't run until you install the listed software" >&2;
exit "$E_depends"; }
return 0
}
#=========================================================================#
@ -260,7 +260,7 @@ fi
return 0
}
first_run_setup ()
# DESCRIPTION: Generate a new database with default config values,
# DESCRIPTION: Generate a new database with default config values,
# create subdirectories of QQ2_DIR
# INPUT: None
# OUTPUT: None
@ -305,10 +305,10 @@ fi
sqlite3 <<EOF
create table CLONES(uuid TEXT, id INTEGER, template TEXT, disks TEXT);
create table TEMPLATES(name TEXT, md5sum TEXT, disks TEXT,\
valid INTEGER);
create table CONFIG(name TEXT, value TEXT);
insert into CONFIG values('TEMPLATE_DIR', '${TEMPLATE_DIR}');
insert into CONFIG values('USE_SPICE', '${use_spice}');
@ -415,7 +415,7 @@ return 0
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#-----------------------------------#
#=========================================================================#
prompt_num ()
# DESCRIPTION: Prompt user for a number between $1 and $2
@ -461,7 +461,7 @@ prompt_yes_no ()
# OUTPUT: Prompts for input, returns 1 for N/n or 0 for Y/y
# PARAMETERS: None
#=========================================================================
#
#
{
local char
until [[ "$char" =~ ^[YyNn]$ ]]; do
@ -496,8 +496,7 @@ xml="$(virt-xml "$@" <<<"$(read_pipe)" 2>/dev/null)" ||
write_pipe 1 <<<"$xml"
return 0
}
}
#=========================================================================#
find_tag ()
# DESCRIPTION: Use xmllint to do an xpath search of xml and write_pipe
@ -522,7 +521,7 @@ xmllint --xpath "$1" --auto |& grep -qi 'xpath error' &&
xmllint --noblanks --dropdtd --nowarning --xpath "$1" \
2>/dev/null <(read_pipe) | write_pipe 1
return 0
}
#=========================================================================#
@ -911,7 +910,7 @@ if (( ${#CL_MAP[@]} + ${#BAD_CL[@]} )); then
read -rs
echo ; } >&2
fi
local id uuid cl_name
while read -r id; do
read -r uuid
@ -967,7 +966,7 @@ fi
#---ERROR MESSAGES AND CHECKS---#
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#-------------------------------#
#=========================================================================#
arg_error ()
# DESCRIPTION: If args are too few, too many, or simply wrong, this
@ -1024,10 +1023,10 @@ if [[ "$1" == "-r" ]]; then
else
redir=0
fi
while (($#)); do
if { chmod +rw "$1" || { [[ -w "$1" ]] && [[ -r "$1" ]]; } ||
readlink "$1" ; } &>/dev/null;
if { chmod +rw "$1" || { [[ -w "$1" ]] && [[ -r "$1" ]]; } ||
readlink "$1" ; } &>/dev/null;
then
shift
elif [[ -e "$1" ]]; then
@ -1041,7 +1040,7 @@ then
local type line
type="$(file -b "$1")"
if [[ "$type" =~ directory ]] && ((redir)); then
while read -r line; do
while read -r line; do
check_rw -r "$line"
done < <(find "$1" 2>/dev/null)
fi
@ -1416,7 +1415,7 @@ prompt_delete_orphans ()
# I am leaving it as-is.
hr
echo
echo "qq2clone will look in its default storage pool:"
echo "qq2clone will look in its default storage pool:"
echo
echo " ${OPT[STORAGE]}"
echo
@ -1592,7 +1591,7 @@ clone ()
# PARAMETERS: $1: (Optional) If '0', create clone intended for staging
# changes to a base template image
#=========================================================================#
{
{
local base_mach_name line check i
local txml="${OPT[TEMPLATE_DIR]}/${OPT[TEMPLATE]}.xml"
@ -2084,6 +2083,7 @@ else
echo -n "all crashed idle in-shutdown off paused pmsuspended running"
echo " saved"
fi
return 0
}
#=========================================================================#
load_template ()
@ -2138,7 +2138,7 @@ local prompt="virsh #" # In the virsh shell, input lines start with this
while read -r uuid <&4; do
{ [[ "$uuid" =~ ^$prompt ]] || [[ -z "$uuid" ]] ; } && continue
[[ "$uuid" == "EOF" ]] && break
[[ -n "${uuid_map["$uuid"]}" ]] &&
CL_MAP["${uuid_map["$uuid"]}"]="$uuid"
done
@ -2347,8 +2347,8 @@ for ((i=0;i<${#parts[@]};i++)); do
else
return 1
fi
if ((not)); then
if ((not)); then
minus=" $minus $p "
else
plus="$plus $p"
@ -2388,10 +2388,7 @@ shift
local verbose_coms
verbose_coms="config|check|list|list-templates|exec|edit|modify-template"
if (( OPT[QUIET] == 2)) &&
[[ ! "$com" =~ ^($verbose_coms)$
]];
then
if (( OPT[QUIET] == 2)) && [[ ! "$com" =~ ^($verbose_coms)$ ]]; then
exec &>/dev/null
fi
@ -2536,9 +2533,9 @@ for t in "${templates[@]}"; do
fi
fi
echo
local n sum
sum="$(( ${#BAD_CL[@]} + ${#CL_MAP[@]} ))"
echo "TOTAL CLONES: $sum"
if (( ${#BAD_CL[@]} )); then
@ -2601,7 +2598,7 @@ if ((OPT[QUIET] == 2)); then
fi
(( $# )) || arg_error 0 config
if [[ "$1" == "list" ]]; then
[[ -n "$2" ]] && arg_error 1 "config list"
disp_conf_names
@ -2621,8 +2618,8 @@ fi
if [[ "$1" == "edit" ]]; then
[[ -n "$2" ]] || arg_error 0 "config edit"
[[ -n "$4" ]] && arg_error 1 "config edit"
check_config "$option" || { echo "Unknown option: $option";
exit "$E_args"; }
check_config "$option" || { echo "Unknown option: $option";
exit "$E_args"; }
local line
if (($#==3));then
line="$3"
@ -2833,7 +2830,7 @@ exec_com_list ()
# qq2clone's overall state
#=========================================================================#
{
(( $# > 1)) && arg_error 1 "list"
(( $# > 1)) && arg_error 1 "list"
if (($#)); then
local line
if [[ "$1" == "all" ]]; then
@ -2846,7 +2843,7 @@ if (($#)); then
done < <(get_template_list)
elif [[ "$1" == "xml" ]]; then
echo "<qq2clone directory=\"${QQ2_DIR}\">"
local name value
local name value
while read -r name; do
read -r value
echo " <config name=\"$name\" value=\"$value\" />"
@ -2855,7 +2852,7 @@ if (($#)); then
while read -r line; do
OPT[TEMPLATE]="$line"
load_template
list_display 1
list_display 1
done < <(get_template_list)
echo "</qq2clone>"
else
@ -2920,7 +2917,7 @@ if [[ "$2" == "prepare-image" ]]; then
((is_staging == 2)) && stage_error
((is_staging)) || { clone 0; load_template; }
connect 0
elif [[ "$2" == "commit-image" ]]; then
((is_staging == 2)) && stage_error
if (($#==3)); then
@ -2929,7 +2926,7 @@ elif [[ "$2" == "commit-image" ]]; then
((is_staging)) ||
{ echo "No changes are staged" >&2; exit "$E_args"; }
commit_image "$@"
elif [[ "$2" == "destroy-image" ]]; then
((is_staging == 2)) && stage_error
local state uuid
@ -2938,14 +2935,14 @@ elif [[ "$2" == "destroy-image" ]]; then
{ echo "Domain is not running" >&2; exit "$E_args"; }
uuid="${CL_MAP[0]}"
virsh destroy "$uuid" &>/dev/null
elif [[ "$2" == "discard-image" ]]; then
((is_staging == 2)) && stage_error
((is_staging)) ||
{ echo "No image to discard" >&2; exit "$E_args"; }
delete_machine 0 0
((OPT[QUIET])) || echo "Image discarded"
elif [[ "$2" == rename ]]; then
(( $#==3)) || arg_error 0 "modify-template $1 $2"
rename_template "$@"
@ -2997,6 +2994,7 @@ hr ()
#=========================================================================#
{
echo ----------------------------------------------------------------------
return 0
}
#=========================================================================#
parse_flags ()