Allow $CHROOT_xxxx variables in xxxx.lst

Issue #9 resolved
Aaron Bartell created an issue

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?

Comments (8)

  1. Former user Account Deleted

    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.

  2. Aaron Bartell reporter

    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?

  3. Former user Account Deleted

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

    something like this ...

    #
    # 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
    
  4. Former user Account Deleted

    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.

    [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
    
  5. Former user Account Deleted

    Ok, here is variable arguments ...

    #
    # 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 ...

    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.
    
  6. Log in to comment