Skip to content
Snippets Groups Projects

debugged shellcheck comlpaints

Merged Julian Steiner requested to merge patch-issue#26#27#28#30#31 into master
2 files
+ 214
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 100
0
@@ -125,6 +125,25 @@ cfg_get_file() {
done
}
cfg_get_vars() {
for base in ${loc_sys_rev} "${loc_home}"
do
local path="${base}/default.vars"
if [[ -e "${path}" ]]
then
grep -P '^_\S+' "${path}"
fi
done
for base in ${loc_sys_rev} "${loc_home}"
do
local path="${base}/repo${sub_base}/pod.vars"
if [[ -e "${path}" ]]
then
grep -P '^_\S+' "${path}"
fi
done
}
cfg_all() {
# the container conf itself
cfg_get_file || exit $?
@@ -169,12 +188,33 @@ render_podman_cmdline() {
declare -A opt+=([${key#_}]="${val}")
continue
fi
# access any registered (_var value) variable via ${var} like
# _myvar myval
# option ${myvar}
if [[ "${val}" = *\$\{*\}* ]]
then
optkeyArray=$(echo "${val}" | grep -o -P '\$\{.*?\}')
for optkey in $optkeyArray
do
optkey=${optkey:2:-1}
optval="${opt[${optkey}]}"
filterstring="s/\${${optkey}}/${optval}/"
val=$( echo "${val}" | sed "${filterstring}" )
done
unset optkeyArray optkey optval
fi
echo -n " --${key} ${val}"
done
echo " ${opt[image]} ${opt[cmd]}"
}
create_cntnr() {
[[ $d_flag -eq 1 ]] && {
echo "podman container create $(cfg_all | render_podman_cmdline)" || exit $?
return 0
}
if podman container exists "${name}"
then
echo "The container ${name} already exists, cant create"
@@ -214,6 +254,66 @@ rm_cntnr() {
fi
}
#################################
# ARGUMENT HANDLING AND GLOBALS #
#################################
# filtering out options and setting flags before actual program runs, in
# in order to retain function of positional arguments
newArgString=""
for (( iter=1; iter<=$#; iter++ ))
do
case $(eval echo \$"$iter") in
-h)
print_usage_and_exit
;;
-d)
d_flag=1
continue
;;
*)
newArgString=$newArgString$(eval echo \$"$iter")" "
;;
esac
done
# shellcheck disable=SC2086
set $newArgString
unset newArgString
action="${1}"
pod="${3}"
# number of imaged to rotate
rotate_count=3
# home directory and system locations are separated as one could do spaces in $HOME
loc_home="${HOME}/.local/share/containers/tool"
loc_sys="/etc/containers/tool /var/lib/containers/tool"
# we need this one to produce reverse order of search directories for env files
loc_sys_rev="/var/lib/containers/tool /etc/containers/tool"
# we add the pods name to the containers name as we might have another container
# with the same name running standalone
if [[ -z "${pod}" ]]
then
name="${2}"
relative_name="${2}"
# if we have a pod we add sub_base to
# our container search dir
sub_base=""
else
name="${pod}_${2}"
relative_name="${2}"
# we also want to have a shared pod socket dir
sub_base="/${pod}.pod"
fi
#################
# MAIN PROGRAM #
#################
case "${action}" in
create)
rm_cntnr
Loading