summaryrefslogtreecommitdiff
path: root/scripts/vyatta-boot-config-loader
blob: 38729746b3095f54665a065507ee5a047f158e85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

BOOT_FILE=$1
shift

CAPI=/bin/cli-shell-api
CLOG=/tmp/vyatta-config-loader.log
COMMIT=/opt/vyatta/sbin/my_commit
COMMIT_LOG=/tmp/vyatta-commit.log

do_log () {
  local level=$1
  shift
  logger -t 'boot-config-loader' -p "local0.$level" -- "$*"
}

do_commit () {
  $COMMIT "$@" >>$COMMIT_LOG
}

trace () {
  echo "$(date +'%F %T')  $*"
}

umask 0002

(
  trace '== begin boot-config-loader'
  # set up config session
  SID=$$
  SENV=$($CAPI getSessionEnv $SID)
  eval "$SENV"
  if ! $CAPI setupSession; then
    do_log err 'Cannot set up configuration session.'
    trace 'Cannot set up configuration session.'
    exit 1
  fi

  # do load
  trace '-- begin load'
  if ! $CAPI loadFile $BOOT_FILE; then
    do_log warn "Failure(s) encountered during load. See $CLOG for details."
    trace '-- load finished with failure(s)'
  else
    trace '-- load finished successfully'
  fi

  # do commit
  trace '-- begin commit'
  ret=0
  export COMMIT_VIA=boot-config-loader
  do_commit -a
  do_commit -s
  if ! do_commit -e -d; then
    do_log err 'Commit failed at boot.'
    trace '-- commit failed'
    ret=1
  else
    trace '-- commit succeeded'
  fi

  # clean up
  if ! $CAPI teardownSession; then
    do_log warn 'Failed to tear down configuration session.'
    trace '-- teardown failed'
  else
    trace '-- teardown succeeded'
  fi
  trace '-- exiting'
  exit $ret
) </dev/null >>$CLOG 2>&1

exit $?