File: postinst

package info (click to toggle)
lshell 2.01-11
  • links: PTS
  • area: main
  • in suites: woody
  • size: 116 kB
  • ctags: 9
  • sloc: sh: 155; ansic: 141; makefile: 39
file content (120 lines) | stat: -rw-r--r-- 2,459 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /bin/sh
set -e

# Make sure we should be running...
case "$1" in
    configure)
        # continue below
        ;;
    abort-upgrade|abort-remove|abort-deconfigure)
        exit 0
        ;;
    *)
        echo "postinst called with unknown argument \$1" >&2
        exit 0
        ;;
esac

#DEBHELPER#

grep '^[[:space:]]*/' /etc/shells |
while read shell
do
	dirname $shell
done |
sort -u |
while read dir
do
#
#	cd to lshells directory, note that /lshell may already be present in
#	/etc/shells
#
	if [ "x`basename $dir`" = "xlshells" ]
	then
		# just in case
		mkdir $dir/lshells 2>/dev/null || true
		cd $dir
	else
		# can't assume to have all lshell dirs installed!
		mkdir $dir/lshells 2>/dev/null || true
		cd $dir/lshells
	fi
	grep '^[[:space:]]*/' /etc/shells |
	grep "^[[:space:]]*$dir" |
	while read shell
	do
#
#		finally create the link
#
		ln -sf /usr/bin/lshell `basename $shell`
	done
done

cat << EOF
To enable lshell you have to add lshell to the path of the login shells in
\`/etc/passwd'. You should also change the path in \`/etc/shells' to make
sure the user does not switch back to an unprotected shell.

Note, that each user with a protected shell will have set his resource
limits according to /etc/lshell.conf.

EOF

while true
do
  echo -n "Shall I make these adjustments for you? [y/N] "
  read input
  if [ $input = "n" -o $input = "N" ]
  then
    exit 0
  elif [ ! $input ]
  then
    exit 0
  elif [ $input = "y" -o $input = "Y" ]
  then
    break
  else
    echo "Please answer \`Y' or \`N'."
  fi 2>/dev/null
done

echo "Changing all login shells (except for uids 0-99) that are listed in /etc/shells"

sed -n '/^\//q;1,/^\//p' /etc/shells > /etc/shells.tmp
grep '^[[:space:]]*/' /etc/shells | 
while read shell; do
	dir=`dirname $shell`
	if [ "x`basename $dir`" != "xlshells" ]
	then
	echo "`dirname $shell`/lshells/`basename $shell`" >> /etc/shells.tmp
	else
	echo $shell >> /etc/shells.tmp
	fi
done

cp /etc/shells /etc/shells.old
cp /etc/shells.tmp /etc/shells
rm /etc/shells.tmp

cat /etc/passwd |
awk '{	FS=":"
	if ( $3 < 100 ) next
	if ( $7 == "" || $7 == "/bin/false" || $7 == "/bin/sync" ) next
	print $1,$7
     }' |
while read user shell
do
	if grep $shell /etc/shells.old >/dev/null 2>&1
	then
		dir=`dirname $shell`
	        if [ "x`basename $dir`" != "xlshells" ]
	        then
			shell="`dirname $shell`/lshells/`basename $shell`"
			chsh -s $shell $user
		fi
	fi
done

/bin/rm -f /etc/shells.old

exit 0