Imported Upstream version 2.6.0p1
[debian/amanda] / packaging / deb / amanda-backup-server.postinst
1 #!/bin/sh
2 # Debian recommends this.  Script exits on simple command failure.
3 # set -e
4 LOGDIR="/var/log/amanda/"
5 SYSCONFDIR="/etc"
6 LOCALSTATEDIR="/var"
7 AMHOMEDIR="${LOCALSTATEDIR}/lib/amanda"
8 AMTMP="/tmp/amanda"
9 amanda_user=amandabackup
10 amanda_group=disk
11 xinetd_reload="restart"
12
13 if [ -d /etc/xinetd.d ] ; then
14         if [ ! -f /etc/xinetd.d/amandaserver ] ; then
15                 cp ${AMHOMEDIR}/example/xinetd.amandaserver /etc/xinetd.d/amandaserver || exit 1
16                 chmod 0644 /etc/xinetd.d/amandaserver || exit 1
17                 if [ -f /etc/xinetd.d/amandaclient ] ; then
18                         rm /etc/xinetd.d/amandaclient || exit 1
19                 fi
20                 echo -n "`date +'%b %e %Y %T'`: Reloading xinetd configuration..." 
21                 if [ "${xinetd_reload}" = "reload" ] ; then
22                         /usr/sbin/invoke-rc.d xinetd ${xinetd_reload} # don't exit yet!
23                         if [ $? -ne 0 ] ; then
24                                 echo -n "reload failed.  Attempting restart..." 
25                                 /usr/sbin/invoke-rc.d xinetd restart || exit 1
26                         fi
27                 else
28                         /usr/sbin/invoke-rc.d xinetd ${xinetd_reload} || exit 1
29                 fi
30         fi
31 fi
32
33 echo "`date +'%b %e %Y %T'`: Installing '${LOCALSTATEDIR}/amanda/amandates'." 
34 if [ ! -f ${LOCALSTATEDIR}/amanda/amandates ] ; then
35         touch ${LOCALSTATEDIR}/amanda/amandates || exit 1
36 fi
37 echo "`date +'%b %e %Y %T'`: Ensuring correct permissions for '${LOCALSTATEDIR}/amanda/amandates'." 
38 chown ${amanda_user}:${amanda_group} ${LOCALSTATEDIR}/amanda/amandates || exit 1
39 chmod 0640 ${LOCALSTATEDIR}/amanda/amandates || exit 1
40 if [ -x /sbin/restorecon ] ; then
41       /sbin/restorecon ${LOCALSTATEDIR}/amanda/amandates  || exit 1
42 fi
43
44 # Check for existence of and permissions on ${AMTMP}
45 if [ ! -d ${AMTMP} ]; then
46        mkdir ${AMTMP} || exit 1
47 fi
48 echo "`date +'%b %e %Y %T'`: Ensuring correct permissions for '${AMTMP}'." 
49 chown ${amanda_user}:${amanda_group} ${AMTMP} || exit 1
50 chmod 0640 ${AMTMP} || exit 1
51
52 # Install .gnupg directory
53 echo "`date +'%b %e %Y %T'`: Installing '${AMHOMEDIR}/.gnupg'." 
54 if [ ! -d ${AMHOMEDIR}/.gnupg ] ; then
55         echo "`date +'%b %e %Y %T'`: '${AMHOMEDIR}/.gnupg' will be created." 
56         mkdir ${AMHOMEDIR}/.gnupg || exit 1
57 fi
58 echo "`date +'%b %e %Y %T'`: Ensuring correct permissions for '${AMHOMEDIR}/.gnupg'." 
59 chown ${amanda_user}:${amanda_group} ${AMHOMEDIR}/.gnupg || exit 1
60 chmod 700 ${AMHOMEDIR}/.gnupg || exit 1
61
62 # Install .amandahosts to server
63 echo "`date +'%b %e %Y %T'`: Checking '${AMHOMEDIR}/.amandahosts' file." 
64 if [ ! -f ${AMHOMEDIR}/.amandahosts ] ; then
65         touch ${AMHOMEDIR}/.amandahosts || exit 1
66 fi
67 for host in localhost localhost.localdomain ; do
68         if [ -z "`grep \"^${host}[[:blank:]]\+root[[:blank:]]\+amindexd[[:blank:]]\+amidxtaped\" ${AMHOMEDIR}/.amandahosts`" ] ; then
69                 echo "${host}   root amindexd amidxtaped" >>${AMHOMEDIR}/.amandahosts || exit 1
70         fi
71         if [ -z "`grep \"^${host}[[:blank:]]\+${amanda_user}[[:blank:]]\+amdump\" ${AMHOMEDIR}/.amandahosts`" ] ; then
72                 echo "${host} ${amanda_user} amdump" >>${AMHOMEDIR}/.amandahosts || exit 1
73         fi
74 done
75 chown ${amanda_user}:${amanda_group} ${AMHOMEDIR}/.amandahosts || exit 1
76 chmod 0600 ${AMHOMEDIR}/.amandahosts || exit 1
77
78 # SSH RSA key generation for amdump
79 KEYDIR="${AMHOMEDIR}/.ssh"
80 KEYFILE="id_rsa_amdump"
81 COMMENT="${amanda_user}@server"
82 if [ ! -d ${KEYDIR} ] ; then
83         if [ -f ${KEYDIR} ] ; then
84                 echo "`date +'%b %e %Y %T'`: Directory '${KEYDIR}' exists as a file.  Renaming to '${KEYDIR}.save'." 
85                 mv ${KEYDIR} ${KEYDIR}.save || exit 1
86         fi
87         echo "`date +'%b %e %Y %T'`: Creating directory '${KEYDIR}'." 
88         mkdir ${KEYDIR} || exit 1
89 fi
90 if [ ! -f ${KEYDIR}/${KEYFILE} ] ; then
91         echo "`date +'%b %e %Y %T'`: Creating ssh RSA key in '${KEYDIR}/${KEYFILE}'" 
92         ssh-keygen -q -C $COMMENT -t rsa -f ${KEYDIR}/${KEYFILE} -N '' || exit 1
93 fi
94 echo "`date +'%b %e %Y %T'`: Setting ownership and permissions for '${KEYDIR}' and '${KEYDIR}/${KEYFILE}*'" 
95 chown ${amanda_user}:${amanda_group} ${KEYDIR} ${KEYDIR}/${KEYFILE}* || exit 1
96 chmod 0750 ${KEYDIR} || exit 1
97 chmod 0600 ${KEYDIR}/${KEYFILE}* || exit 1
98
99 # SSH RSA key generation on client for amrecover
100 KEYDIR="${AMHOMEDIR}/.ssh"
101 KEYFILE="id_rsa_amrecover"
102 COMMENT="root@client"
103 if [ ! -d ${KEYDIR} ] ; then
104         if [ -f ${KEYDIR} ] ; then
105                 echo "`date +'%b %e %Y %T'`: Directory '${KEYDIR}' exists as a file.  Renaming to '${KEYDIR}.save'." 
106                 mv ${KEYDIR} ${KEYDIR}.save || exit 1
107         fi
108         echo "`date +'%b %e %Y %T'`: Creating directory '${KEYDIR}'." 
109         mkdir ${KEYDIR} || exit 1
110 fi
111 if [ ! -f ${KEYDIR}/${KEYFILE} ] ; then
112         echo "`date +'%b %e %Y %T'`: Creating ssh RSA key in '${KEYDIR}/${KEYFILE}'" 
113         ssh-keygen -q -C $COMMENT -t rsa -f ${KEYDIR}/${KEYFILE} -N '' || exit 1
114 fi
115 echo "`date +'%b %e %Y %T'`: Setting permissions for '${KEYDIR}'" 
116 chown ${amanda_user}:${amanda_group} ${KEYDIR} || exit 1
117 chmod 0750 ${KEYDIR} || exit 1
118 chmod 0600 ${KEYDIR}/${KEYFILE}* || exit 1
119
120 # environment variables (~amandabackup/.profile)
121 echo "`date +'%b %e %Y %T'`: Checking for '${AMHOMEDIR}/.profile' and ensuring correct environment." 
122 if [ ! -f ${AMHOMEDIR}/.profile ] ; then
123         touch ${AMHOMEDIR}/.profile || exit 1
124 fi
125 if [ -z "`grep PATH ${AMHOMEDIR}/.profile | grep '/usr/sbin'`" ] ; then
126         echo "export PATH=\"\$PATH:/usr/sbin/\"" >> "${AMHOMEDIR}/.profile" || exit 1
127 fi
128 echo "`date +'%b %e %Y %T'`: Setting ownership and permissions for '${AMHOMEDIR}/.profile'" 
129 chown ${amanda_user}:${amanda_group} ${AMHOMEDIR}/.profile || exit 1
130 chmod 0640 ${AMHOMEDIR}/.profile || exit 1
131
132 echo "`date +'%b %e %Y %T'`: === Amanda backup server installation complete. ==="