Start sshd on alternate port before killing regular sshd; gives us a
[pl_sshd.git] / pl_sshd.spec
1 Summary: SSH server config for PlanetLab
2 Name: pl_sshd
3 Version: 1.0
4 Release: 2
5 Requires: autofs, openssh-server
6 Copyright: GPL
7 URL: http://www.planet-lab.org
8 Group: System Environment/Base
9 Source: %{_fullname}.tar.gz
10
11 %description 
12 SSH server configuration for PlanetLab nodes.  Configures an automounted
13 directory as source for authorized_keys files and points sshd to that
14 directory.
15
16 $Header: /cvs/pl_sshd/pl_sshd.spec,v 1.5 2003/12/02 00:22:03 sjm-pl_sshd Exp $
17 %prep
18 %setup
19
20 %build
21
22
23 %install
24 mkdir -p $RPM_BUILD_ROOT/usr/local/sbin
25 mkdir -p $RPM_BUILD_ROOT/etc/{sysconfig,init.d}
26 mkdir -p $RPM_BUILD_ROOT/var/pl_sshd/keys
27 install -m 0755 pl_sshd.sh $RPM_BUILD_ROOT/usr/local/sbin
28 install -m 0755 pl_sshd $RPM_BUILD_ROOT/etc/init.d
29 install -m 0755 auto.pl_sshd $RPM_BUILD_ROOT/etc
30
31 %clean
32 rm -rf $RPM_BUILD_ROOT
33
34 %files
35 %defattr(-,root,root)
36 %attr(0755,root,root) /usr/local/sbin/pl_sshd.sh
37 %attr(0755,root,root) /etc/init.d/pl_sshd
38 %attr(0755,root,root) /etc/auto.pl_sshd
39
40 %pre
41
42
43 %post
44 RUNLEVEL=`/sbin/runlevel`
45
46 if [ "$1" -ge 1 ]; then
47         # create the magic directory for automount
48         keydir=/var/pl_sshd/keys
49         [ -d $keydir ] || mkdir -p $keydir
50
51         # add appropriate entry to auto.master
52         auto_master=/etc/auto.master
53         auto_master_entry="$keydir /etc/auto.pl_sshd"
54         grep -qF "$auto_master_entry" $auto_master || \
55             echo $auto_master_entry >>$auto_master
56
57         #
58         # use the sysconfig file to tell our system sshd to look in the
59         # magic location for authorized_keys files
60         #
61         sysconfig_sshd=/etc/sysconfig/sshd
62         [ -r $sysconfig_sshd ] && \
63             mv $sysconfig_sshd $sysconfig_sshd.pl_sshd
64         echo "OPTIONS='-o \"AuthorizedKeysFile $keydir/%u/authorized_keys\"'" \
65             >$sysconfig_sshd
66
67         # link sshd pam config to pl_sshd so that we can actually login
68         pam_pl_sshd=/etc/pam.d/pl_sshd
69         [ -r $pam_pl_sshd ] || ln -s sshd $pam_pl_sshd
70
71         chkconfig --add pl_sshd
72
73         if [[ "$RUNLEVEL" != "unknown" ]]; then
74                 #
75                 # starting pl_sshd before restarting sshd gives us a
76                 # chance of recovery if stopping sshd aborts the
77                 # update process e.g., because we're logged in using
78                 # ssh.
79                 #
80                 /etc/init.d/autofs restart
81                 /etc/init.d/pl_sshd start
82                 /etc/init.d/sshd restart
83         fi
84 fi
85
86 %preun
87 RUNLEVEL=`/sbin/runlevel`
88
89 if [ "$1" -ge "0" ]; then
90         #
91         # stop pl_sshd, remove it from rcX.d init dirs, remove link
92         # to sshd's pam config
93         #
94         [ "$RUNLEVEL" != "unknown" ] && /etc/init.d/pl_sshd stop
95         chkconfig --del pl_sshd
96         rm -f /etc/pam.d/pl_sshd
97
98         #
99         # remove funky config options for sshd (so that when we restart
100         # things will operate normally i.e., without automount magic),
101         # then restart
102         #
103         rm /etc/sysconfig/sshd
104         [ "$RUNLEVEL" != "unknown" ] && /etc/init.d/sshd restart
105
106         #
107         # stop automounter, remove entry from auto.master, restart if
108         # necessary
109         #
110         [ "$RUNLEVEL" != "unknown" ] && /etc/init.d/autofs stop
111         auto_master=/etc/auto.master
112         mv $auto_master $auto_master.pl_sshd.preun
113         sed -e '\,^/var/pl_sshd/keys,d' $auto_master.pl_sshd.preun \
114             >$auto_master
115
116         [ "$RUNLEVEL" != "unknown" ] && /etc/init.d/autofs start
117 fi
118
119
120 %postun
121
122
123 %changelog
124 * Mon Dec  1 2003 Steve Muir <smuir@cs.princeton.edu>
125 - initial creation from files in sidewinder repository
126