configure-sudoers 1.15 KB
Newer Older
1
#!/bin/bash
2
mkdir -p /etc/sudoers.d
3
COMMAND_LIST=("rm-tmp-lte" "init-enb" "init-mme" "init-sdr" "get-sdr-info")
4 5 6 7 8 9 10 11 12 13 14 15
PARTITION_AMOUNT="$(sed -n 's/partition_amount = \(.*\)/\1/gp' /etc/opt/slapos/slapos.cfg)"
for c in "${COMMAND_LIST[@]}"; do
  SLAPUSER_LINES="$(cat /etc/sudoers.d/slapuser-$c 2> /dev/null | wc -l)"
  if [ "$SLAPUSER_LINES" != "$PARTITION_AMOUNT" ]; then
    echo "Configuring /etc/sudoers.d/slapuser-$c..."
    for i in $(seq 0 $(($PARTITION_AMOUNT-1))); do
      echo "slapuser$i ALL=NOPASSWD:/opt/amarisoft/$c" >> slapuser-$c
    done
    mv slapuser-$c /etc/sudoers.d/
    chmod 440 /etc/sudoers.d/slapuser-$c
  fi
done
16 17 18 19 20 21 22 23 24 25 26
c="sdr-util"
SLAPUSER_LINES="$(cat /etc/sudoers.d/slapuser-$c 2> /dev/null | wc -l)"
AMARISOFT_PATH="/opt/amarisoft/$(ls -1 /opt/amarisoft | grep "^v[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$" | sort | tail -n1)"
if [ "$SLAPUSER_LINES" != "$PARTITION_AMOUNT" ]; then
  echo "Configuring /etc/sudoers.d/slapuser-$c..."
  for i in $(seq 0 $(($PARTITION_AMOUNT-1))); do
    echo "slapuser$i ALL=NOPASSWD:$AMARISOFT_PATH/trx_sdr/sdr_util -c 0 version" >> slapuser-$c
  done
  mv slapuser-$c /etc/sudoers.d/
  chmod 440 /etc/sudoers.d/slapuser-$c
fi