IBM / ibmichroot

A set of scripts to facilitate the use of chroot-based containers for IBM i
MIT License
21 stars 9 forks source link

Allow $CHROOT_xxxx variables in xxxx.lst #9

Closed abmusse closed 9 years ago

abmusse commented 9 years ago

Original report by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


There will be some cases where having variables in xxxx.lst files will be important. For example:

:system
CHGAUT OBJ('$CHROOT_DIR/home/$CHROOT_USER') USER($CHROOT_USER) DTAAUT(*RWX) OBJAUT(*ALL) SUBTREE(*ALL)
:chown
$CHROOT_USER:0 $CHROOT_DIR

We'd also need to alter the chroot_setup.sh parms to include an optional user profile, and if passed it would be used to occupy $CHROOT_USER.

Thoughts?

abmusse commented 9 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Can we close this now?

abmusse commented 9 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Ok, here is variable arguments ...

#!shell

#
# run system command
# (system "CHGAUT OBJ('/QOpenSys/ranger/home/ranger') USER(RANGER) DTAAUT(*RWX) OBJAUT(*ALL) SUBTREE(*ALL)")
# -- variable substitution example (mydir and myuser) --
# > ./chroot_setup.sh chroot_system.lst /QOpenSys/ranger mydir=/QOpenSys/ranger myuser=RANGER
#
:system
CHGAUT OBJ('mydir/home/myuser') USER(myuser) DTAAUT(*RWX) OBJAUT(*ALL) SUBTREE(*ALL)

run ...

#!shell

bash-4.3$ ./chroot_setup.sh chroot_system.lst /QOpenSys/ranger mydir=/QOpenSys/ranger myuser=RANGER
system -i "CHGAUT OBJ('/QOpenSys/ranger/home/RANGER') USER(RANGER) DTAAUT(*RWX) OBJAUT(*ALL) SUBTREE(*ALL)"
CPC221C: 2 objects successfully changed.
abmusse commented 9 years ago

Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


Looks good to me.

abmusse commented 9 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Oh forgot to include run ...

As you can see we could invent a method for variable length parms, 1st parms are positional, followed key=value substitutions.

#!shell

[adc@oc7083008330 trials]$ ./manyargs.sh nsnns.lst /QOpenSys/ranger name=frog buddy=toad ride=zipper
name buddy ride
frog toad zipper
key  : name
value: frog
key  : ride
value: zipper
key  : buddy
value: toad
abmusse commented 9 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


I try to rely on generic "all have" things for script ...

something like this ...

#!shell

#
# main
#
opr="-g"
lst=0
qsys=0
req=0
declare -A array
varkey=""
varval=""
for arg in "$@"
{
  if ([ $CHROOT_LIST ] && [ $CHROOT_DIR ]); then
    # split by equals sign
    IFS="=" read ARGL ARGR <<< "$arg"
    varkey="$varkey $ARGL"
    varval="$varval $ARGR"
    array[$ARGL]=$ARGR
  elif ([ $CHROOT_LIST ]); then
    CHROOT_DIR=$arg
  else
    CHROOT_LIST=$arg
  fi
}
# check input
lst=$(echo $CHROOT_LIST | grep -c '.lst')
if (($lst==0)); then
  echo "Error: 1st paramter missing *.lst ($CHROOT_LIST)"
  opr="error"
fi
qopen=$(echo $CHROOT_DIR | grep -c '/QOpenSys')
if (($qopen==0)); then
  echo "Error: 2nd paramter must start /QOpenSys ($CHROOT_DIR)"
  opr="error"
fi

echo $varkey
echo $varval
for i in "${!array[@]}"
do
  echo "key  : $i"
  echo "value: ${array[$i]}"
done
abmusse commented 9 years ago

Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


Is there a something like getopts that is universal to the shells we are working with? (i.e. bsh and bash). Or are we better off spinning our own wool?

abmusse commented 9 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Well, i understand, but not 100% sure 'one more' parameter to chroot_setup.sh will be right model. Instead we may need some endless args way of doing things, so, still thinking.