diff options
Diffstat (limited to 'contrib/solaris/postinstall.in')
-rw-r--r-- | contrib/solaris/postinstall.in | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/contrib/solaris/postinstall.in b/contrib/solaris/postinstall.in new file mode 100644 index 000000000..58d773f87 --- /dev/null +++ b/contrib/solaris/postinstall.in | |||
@@ -0,0 +1,198 @@ | |||
1 | # PostInstall script for OPENssh | ||
2 | INSTALLF="/usr/sbin/installf" | ||
3 | |||
4 | instbackup() { | ||
5 | _DIRECTORY=$1 | ||
6 | _FILEBASE=$2 | ||
7 | $INSTALLF $PKGINST ${_DIRECTORY}/${_FILEBASE} | ||
8 | _SUFFIX=`/usr/bin/date +%Y-%m-%d-%H%M` | ||
9 | if [ -f ${_DIRECTORY}/${_FILEBASE} ]; then | ||
10 | echo " Backing up file ${_FILEBASE}..." | ||
11 | if [ -f ${_DIRECTORY}/${_FILEBASE}.orig ]; then | ||
12 | $INSTALLF $PKGINST ${_DIRECTORY}/${_FILEBASE}.orig.${_SUFFIX} | ||
13 | cp -p ${_DIRECTORY}/${_FILEBASE} ${_DIRECTORY}/${_FILEBASE}.orig.${_SUFFIX} | ||
14 | echo " Saved as ${_DIRECTORY}/${_FILEBASE}.orig.${_SUFFIX}." | ||
15 | else | ||
16 | $INSTALLF $PKGINST ${_DIRECTORY}/${_FILEBASE}.orig | ||
17 | cp -p ${_DIRECTORY}/${_FILEBASE} ${_DIRECTORY}/${_FILEBASE}.orig | ||
18 | echo " Saved as ${_DIRECTORY}/${_FILEBASE}.orig." | ||
19 | fi | ||
20 | fi | ||
21 | cp -p ${_DIRECTORY}/${_FILEBASE}.default ${_DIRECTORY}/${_FILEBASE} | ||
22 | echo "Installed new ${_DIRECTORY}/${_FILEBASE} configuration file." | ||
23 | } | ||
24 | |||
25 | ### Main body of script | ||
26 | |||
27 | echo "" | ||
28 | echo "Beginning postinstall script--this script should leave you with a" | ||
29 | echo "functional and operational configuration of OpenSSH." | ||
30 | echo "" | ||
31 | |||
32 | if [ ! "${UPDATE}" = "1" ]; then | ||
33 | echo "Performing a \"fresh\" installation of OpenSSH." | ||
34 | ### Install init script and create symlinks | ||
35 | $INSTALLF $PKGINST ${PKG_INSTALL_ROOT}/etc/init.d/sshd f 0500 root sys || exit 2 | ||
36 | cp -p ${CONFDIR}/sshd-initscript ${PKG_INSTALL_ROOT}/etc/init.d/sshd | ||
37 | $INSTALLF $PKGINST ${PKG_INSTALL_ROOT}/etc/rc2.d/S72local_sshd=/etc/init.d/sshd s || exit 2 | ||
38 | $INSTALLF $PKGINST ${PKG_INSTALL_ROOT}/etc/rc1.d/K30local_sshd=/etc/init.d/sshd s || exit 2 | ||
39 | $INSTALLF $PKGINST ${PKG_INSTALL_ROOT}/etc/rc0.d/K30local_sshd=/etc/init.d/sshd s || exit 2 | ||
40 | |||
41 | ### The initial package installation leaves default versions of | ||
42 | ### ssh_prng_cmds, ssh_config, and sshd_config in ${CONFDIR}. Now | ||
43 | ### we need to decide whether to install them. Since this is *not* | ||
44 | ### an update install, we don't ask, but simply back up the old ones | ||
45 | ### and put the new ones in their place. | ||
46 | instbackup ${CONFDIR} ssh_prng_cmds | ||
47 | instbackup ${CONFDIR} ssh_config | ||
48 | instbackup ${CONFDIR} sshd_config | ||
49 | |||
50 | ### If no existing sshd_config and host key, then create | ||
51 | if [ ! -f "${CONFDIR}/ssh_host_key" ]; then | ||
52 | echo "Creating new RSA public/private host key pair for SSH-1." | ||
53 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_key | ||
54 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_key.pub | ||
55 | ### If there is *anything* there then leave it, otherwise look | ||
56 | ### in some reasonable alternate locations before giving up. | ||
57 | ### It's worth spending some extra time looking for the old one | ||
58 | ### to avoid a bunch of "host identification has changed" warnings. | ||
59 | ### Note that some old keys from the commercial SSH might not | ||
60 | ### be compatible, but we don't test for that. | ||
61 | if [ -f "${PKG_INSTALL_ROOT}/etc/ssh_host_key" ]; then | ||
62 | mv ${PKG_INSTALL_ROOT}/etc/ssh_host_key ${CONFDIR} | ||
63 | elif [ -f "${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_key" ]; then | ||
64 | mv ${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_key ${CONFDIR} | ||
65 | else | ||
66 | ${DESTBIN}/ssh-keygen -b 1024 -f ${CONFDIR}/ssh_host_key -N '' | ||
67 | fi | ||
68 | else | ||
69 | echo "Using existing RSA public/private host key pair for SSH-1." | ||
70 | fi | ||
71 | if [ ! -f "${CONFDIR}/ssh_host_dsa_key" ]; then | ||
72 | echo "Creating new DSA public/private host key pair for SSH-2." | ||
73 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_dsa_key | ||
74 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_dsa_key.pub | ||
75 | ### If there is *anything* there then leave it, otherwise look | ||
76 | ### in some reasonable alternate locations before giving up. | ||
77 | ### It's worth spending some extra time looking for the old one | ||
78 | ### to avoid a bunch of "host identification has changed" warnings. | ||
79 | ### Note that some old keys from the commercial SSH2 might not | ||
80 | ### be compatible, but we don't test for that. | ||
81 | if [ -f "${PKG_INSTALL_ROOT}/etc/ssh_host_dsa_key" ]; then | ||
82 | mv ${PKG_INSTALL_ROOT}/etc/ssh_host_dsa_key ${CONFDIR} | ||
83 | elif [ -f "${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_dsa_key" ]; then | ||
84 | mv ${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_dsa_key ${CONFDIR} | ||
85 | else | ||
86 | ${DESTBIN}/ssh-keygen -d -f ${CONFDIR}/ssh_host_dsa_key -N '' | ||
87 | fi | ||
88 | else | ||
89 | echo "Using existing DSA public/private host key pair for SSH-2." | ||
90 | fi | ||
91 | else | ||
92 | echo "Performing an \"update\" installation of OpenSSH." | ||
93 | ### Okay, this part *is* an update install...so we need to ensure | ||
94 | ### we don't overwrite any of the existing files. | ||
95 | |||
96 | ### Install init script and create symlinks | ||
97 | if [ ! -f ${PKG_INSTALL_ROOT}/etc/init.d/sshd ]; then | ||
98 | echo "Installing init script in ${PKG_INSTALL_ROOT}/etc/init.d/sshd" | ||
99 | $INSTALLF $PKGINST ${PKG_INSTALL_ROOT}/etc/init.d/sshd || exit 2 | ||
100 | cp -p ${CONFDIR}/sshd-initscript ${PKG_INSTALL_ROOT}/etc/init.d/sshd | ||
101 | chown root:root ${PKG_INSTALL_ROOT}/etc/init.d/sshd | ||
102 | chmod 500 ${PKG_INSTALL_ROOT}/etc/init.d/sshd | ||
103 | fi | ||
104 | if [ ! -r ${PKG_INSTALL_ROOT}/etc/rc2.d/S72local_sshd ]; then | ||
105 | $INSTALLF $PKGINST ${PKG_INSTALL_ROOT}/etc/rc2.d/S72local_sshd=/etc/init.d/sshd s || exit 2 | ||
106 | fi | ||
107 | if [ ! -r ${PKG_INSTALL_ROOT}/etc/rc2.d/K30local_sshd ]; then | ||
108 | $INSTALLF $PKGINST /etc/rc0.d/K30local_sshd=/etc/init.d/sshd s || exit 2 | ||
109 | fi | ||
110 | |||
111 | ### The initial package installation leaves default versions of | ||
112 | ### ssh_prng_cmds, ssh_config, and sshd_config in ${CONFDIR}. Now | ||
113 | ### we need to decide whether to install them. Since this is | ||
114 | ### an update install, we only install the new files if the old | ||
115 | ### files somehow don't exist. | ||
116 | NEWCONF=0 | ||
117 | if [ ! -r "${CONFDIR}/ssh_prng_cmds" ]; then | ||
118 | instbackup ${CONFDIR} ssh_prng_cmds | ||
119 | NEWCONF=1 | ||
120 | fi | ||
121 | if [ ! -r "${CONFDIR}/ssh_config" ]; then | ||
122 | instbackup ${CONFDIR} ssh_config | ||
123 | NEWCONF=1 | ||
124 | fi | ||
125 | if [ ! -r "${CONFDIR}/ssh_config" ]; then | ||
126 | instbackup ${CONFDIR} sshd_config | ||
127 | NEWCONF=1 | ||
128 | fi | ||
129 | if [ $NEWCONF -eq 0 ]; then | ||
130 | echo "Your existing SSH configuration files have not been altered." | ||
131 | else | ||
132 | echo "Your other existing SSH configuration files have not been altered." | ||
133 | fi | ||
134 | |||
135 | ### If no existing sshd_config and host key, then create | ||
136 | if [ ! -f "${CONFDIR}/ssh_host_key" ]; then | ||
137 | echo "Creating new RSA public/private host key pair for SSH-1." | ||
138 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_key | ||
139 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_key.pub | ||
140 | ### If there is *anything* there then leave it, otherwise look | ||
141 | ### in some reasonable alternate locations before giving up. | ||
142 | ### It's worth spending some extra time looking for the old one | ||
143 | ### to avoid a bunch of "host identification has changed" warnings. | ||
144 | ### Note that some old keys from the commercial SSH might not | ||
145 | ### be compatible, but we don't test for that. | ||
146 | if [ -f "${PKG_INSTALL_ROOT}/etc/ssh_host_key" ]; then | ||
147 | mv ${PKG_INSTALL_ROOT}/etc/ssh_host_key ${CONFDIR} | ||
148 | elif [ -f "${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_key" ]; then | ||
149 | mv ${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_key ${CONFDIR} | ||
150 | else | ||
151 | ${DESTBIN}/ssh-keygen -b 1024 -f ${CONFDIR}/ssh_host_key -N '' | ||
152 | fi | ||
153 | else | ||
154 | echo "Using existing RSA public/private host key pair for SSH-1." | ||
155 | fi | ||
156 | if [ ! -f "${CONFDIR}/ssh_host_dsa_key" ]; then | ||
157 | echo "Creating new DSA public/private host key pair for SSH-2." | ||
158 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_dsa_key | ||
159 | $INSTALLF $PKGINST ${CONFDIR}/ssh_host_dsa_key.pub | ||
160 | ### If there is *anything* there then leave it, otherwise look | ||
161 | ### in some reasonable alternate locations before giving up. | ||
162 | ### It's worth spending some extra time looking for the old one | ||
163 | ### to avoid a bunch of "host identification has changed" warnings. | ||
164 | ### Note that some old keys from the commercial SSH2 might not | ||
165 | ### be compatible, but we don't test for that. | ||
166 | if [ -f "${PKG_INSTALL_ROOT}/etc/ssh_host_dsa_key" ]; then | ||
167 | mv ${PKG_INSTALL_ROOT}/etc/ssh_host_dsa_key ${CONFDIR} | ||
168 | elif [ -f "${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_dsa_key" ]; then | ||
169 | mv ${PKG_INSTALL_ROOT}/usr/local/etc/ssh_host_dsa_key ${CONFDIR} | ||
170 | else | ||
171 | ${DESTBIN}/ssh-keygen -d -f ${CONFDIR}/ssh_host_dsa_key -N '' | ||
172 | fi | ||
173 | else | ||
174 | echo "Using existing DSA public/private host key pair for SSH-2." | ||
175 | fi | ||
176 | fi | ||
177 | |||
178 | if [ ! -d %%PIDDIR%% ]; then | ||
179 | $INSTALLF $PKGINST %%PIDDIR%% | ||
180 | mkdir -p %%PIDDIR%% | ||
181 | chown root:sys %%PIDDIR%% | ||
182 | chmod 755 %%PIDDIR%% | ||
183 | fi | ||
184 | |||
185 | $INSTALLF -f $PKGINST || exit 2 | ||
186 | |||
187 | if [ "X${PKG_INSTALL_ROOT}" = "X" ]; then | ||
188 | ### We're doing a local install, rather than an install for | ||
189 | ### old-style diskless clients. | ||
190 | echo "Stopping any current sshd process, and then starting the new sshd." | ||
191 | /etc/init.d/sshd stop | ||
192 | /etc/init.d/sshd start | ||
193 | else | ||
194 | echo "Not restarting sshd, since this appears to be a remote install" | ||
195 | echo "for support of diskless clients." | ||
196 | fi | ||
197 | |||
198 | exit 0 | ||