summarylogtreecommitdiffstats
path: root/amanda.install
blob: 649bba07e0e1ed79b08ee1e213545c6502649b6b (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Can't customize .install scripts so we use an external script

# The PKGBUILD will stop if these vars don't match what's in the PKGBUILD

_amlibexec='/usr/lib'
_amsecurity='/etc/amanda-security.conf'
_amhome='/var/lib/amanda'

pre_install() {
  # During pre_install the settings file amanda-install.sh isn't available yet
  # During pre_upgrade the settings file exists with only the old settings.
  # During the pre_upgrade from the old package, there are no old settings.
  # Here in install we always have the new vars and can guess the old vars.

  # Move file before pacman can remove it
  local _amsother=''
  case "${_amsecurity}" in
  '/etc/amanda-security.conf') _amsother='/etc/amanda/amanda-security.conf';;
  '/etc/amanda/amanda-security.conf') _amsother='/etc/amanda-security.conf';;
  esac
  if [ ! -z "${_amsother}" ] && [ -s "${_amsother}" ] && [ ! -s "${_amsecurity}" ]; then
    echo "amanda mv ${_amsother} ${_amsecurity}"
    mv "${_amsother}" "${_amsecurity}"
  fi

  # Move home folder before pacman can remove it
  _amsother=''
  case "${_amhome}" in
  '/var/lib/amanda') _amsother='/var/amanda';;
  '/var/amanda') _amsother='/var/lib/amanda';;
  esac
  if [ ! -z "${_amsother}" ] && [ -d "${_amsother}" ] && [ ! -d "${_amhome}" ]; then
    echo "amanda mv ${_amsother} ${_amhome}"
    mv "${_amsother}" "${_amhome}"
  fi
}

_post_upins() {
  _GetOVars= _GetOLocal= bash -e -u "${_amlibexec}/amanda/amanda-install.sh" 'post_upins' 'chown_PKGBUILD' 'chown_makefile'
  if [ -s '/etc/xinetd.d/amanda' ]; then
    if ! systemctl -q is-enabled 'xinetd.service' || ! systemctl -q is-active 'xinetd.service'; then
      echo 'amanda: Service xinetd must be running for bsd support, Try'
      if ! systemctl -q is-enabled 'xinetd.service'; then
        echo '  sudo systemctl enable xinetd.service'
      fi
      if ! systemctl -q is-active 'xinetd.service'; then
        echo '  sudo systemctl start xinetd.service'
      fi
    fi
  fi
}

post_install() {
  _post_upins "$1"
  echo 'amanda: Visit the Amanda wiki to configure your backup sets:'
  echo 'amanda:   http://wiki.zmanda.com/index.php/Getting_Started_With_Amanda'
  echo 'amanda: Examples are in /etc/amanda/examples/'
  if [ -s '/etc/xinetd.d/amanda' ]; then
    echo ''
    echo 'amanda: Restart xinetd to start the daemon listening for connections.'
  fi
  _GetOVars= _GetOLocal= bash -e -u "${_amlibexec}/amanda/amanda-install.sh" 'post_install'
}

# During an upgrade the new version's pre_upgrade() is run
pre_upgrade() {
  pre_install
  # Copy the file so we can get to the old vars after the upgrade
  if [ -s "${_amlibexec}/amanda/amanda-install.sh" ]; then
    (umask 077; cp --remove-destination "${_amlibexec}/amanda/amanda-install.sh" '/tmp/amanda-install.sh') # as close to atomic as I can get. -p not allowed here
  fi
}

pre_remove() {
  _GetOVars= _GetOLocal= bash -e -u "${_amlibexec}/amanda/amanda-install.sh" 'pre_remove'
  pre_upgrade
}

post_upgrade() {
  set -u
  if [ -s '/tmp/amanda-install.sh' ]; then
    local _GetOLocal='local'
    local _GetOVars=1
    source '/tmp/amanda-install.sh'
    unset _GetOVars
    rm '/tmp/amanda-install.sh'

    local _GetVars=1
    source "${_amlibexec}/amanda/amanda-install.sh"
    unset _GetVars

    if [ "${_Oamandauser}"  != "${_amandauser}"  ]; then
      echo 'amanda warning: changing username will likely invalidate all cron jobs and crash running jobs'
    fi
    # Copy and delete home if not already moved above
    if [ "${_Oamhome}" != "${_amhome}" ] && [ -d "${_Oamhome}" ] ; then
      if cp --no-target-directory -pr "${_Oamhome}/" "${_amhome}/"; then
        rm -rf "${_Oamhome}"
      fi
    fi
    if [ "${_Oamandauser}"  != "${_amandauser}"  ] ||
       [ "${_Oamandagroup}" != "${_amandagroup}" ] ||
       [ "${_Oamandauid}"   != "${_amandauid}"   ] ||
       [ "${_Oamandagid}"   != "${_amandagid}"   ] ||
       [ "${_Oamhome}"      != "${_amhome}"      ] ||
       [ "$(getent passwd "${_amandauser}" | cut -d':' -f6)" != "${_amhome}" ]; then
      echo 'amanda: Updating user/group info'
      if ! userdel --force "${_Oamandauser}"; then
        echo 'amanda: install package again after backup completes to fix'
      else
        echo "amanda: User ${_Oamandauser} deleted"
      fi
      groupdel "${_Oamandagroup}" 2>/dev/null || :
      echo "amanda: Group ${_Oamandagroup} deleted"
      if grep --color=auto -lr "${_Oamhome}" "${_ametc}"; then
        echo "amanda warning: Some backups reference the old home dir ${_Oamhome}"
      fi
    fi
  fi
  set +u
  _post_upins "$1"
}

post_remove() {
  set -u
  if [ -s '/tmp/amanda-install.sh' ]; then
    _GetOVars= _GetOLocal= bash -e -u '/tmp/amanda-install.sh' 'post_remove'
    rm '/tmp/amanda-install.sh'
  fi
  set +u
}