-RUNLEVEL=`/sbin/runlevel`
-
-if [ "$1" -ge 1 ]; then
- chkconfig --add pl_sshd
-
- if [[ "$RUNLEVEL" != "unknown" ]]; then
- /etc/init.d/pl_sshd restart
- fi
+# 1 = install, 2 = upgrade/reinstall
+if [ $1 -ge 1 ]; then
+ # link sshd pam config to pl_sshd so that we can actually login
+ pam_pl_sshd=/etc/pam.d/pl_sshd
+ [ -r $pam_pl_sshd ] || ln -s sshd $pam_pl_sshd
+
+ chkconfig --add pl_sshd
+
+ if [ "$1" -gt "1" ]; then # upgrading
+ #
+ # remove funky config options for sshd (so that when we restart
+ # things will operate normally i.e., without automount magic)
+ #
+ rm -f /etc/sysconfig/sshd
+
+ #
+ # stop automounter, remove entry from auto.master, restart if
+ # necessary
+ #
+ [ "$PL_BOOTCD" != "1" ] && /etc/init.d/autofs stop
+ auto_master=/etc/auto.master
+ orig=$auto_master
+ backup=$auto_master.pl_sshd.post
+ mv $orig $backup
+ sed -e '\,^/var/pl_sshd/keys,d' $backup > $orig && rm $backup || \
+ mv $backup $orig
+
+ [ "$PL_BOOTCD" != "1" ] && /etc/init.d/autofs start
+ fi
+
+ if [[ "$PL_BOOTCD" != "1" ]]; then
+ #
+ # don't try to start/restart various things automatically,
+ # it's too ugly (particularly if we're upgrading while
+ # connected over ssh)
+ #
+ echo
+ echo "You need to manually restart autofs and sshd, and"
+ echo "start the pl_sshd (ssh on port 806) service."
+ echo "Make sure you know what you're doing, particularly"
+ echo "if you're making this change over an ssh connection."
+ echo
+ fi