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