В эти выходные я написал сценарий (gdm-greeter). Он хорошо работает на CentOS 6.2, интересно, будет ли это полезно для Ubuntu?
#!/bin/bash
#
# $LastChangedDate: 2012-02-17 09:13:10 +0100 (Fri, 17 Feb 2012) $
# $Revision: 1627 $
#
# Get the default exlude list
DefaultExclude=`sed 's,</schema>,#,' /etc/gdm/gdm.schemas | \
tr '\n#' '#\n' | \
grep '>greeter/Exclude<' | tr '\n#' '#\n' | \
grep '<default>' | \
sed -e 's,.*<default>,,' -e 's,</default>.*,,'`
# Get the Exclude list from the config
eval `grep '^Exclude=' /etc/gdm/custom.conf 2> /dev/null`
# If empty copy the default
if [ "$Exclude" = "" ]
then
Exclude=$DefaultExclude
fi
# Collect all user accounts with a shell
Users="`grep 'sh$' /etc/passwd | awk -F: '{print $1}' | \
sort | tr '\n' ',' | sed 's/,$//'`"
#------------------------------------------------------------------------------
# The functions area
PlaceExclude() # $1 new exclude string
{
# Create a .bak file
if [ ! -f /etc/gdm/custom.conf.bak ]
then
cp /etc/gdm/custom.conf /etc/gdm/custom.conf.bak
fi
# Create a tmp file without the Exclude string
cat /etc/gdm/custom.conf | tr '[\n' '\n[' | \
sed -e 's/^\(greeter[]].*\)[[]Exclude=[^[]*\([[].*\)/\1\2/' | \
tr '[\n' '\n[' > /tmp/custom.conf.$$
# If the tmp file is there and we have non default Exclude
if [ -f /tmp/custom.conf.$$ ]
then
if [ "$1" = "$DefaultExclude" ]
then
cat /tmp/custom.conf.$$ > /etc/gdm/custom.conf
else
# Place the new Exclude string
cat /tmp/custom.conf.$$ | tr '[\n' '\n[' | \
sed -e "s/^greeter[]][[][[]/greeter][Exclude=$1[[/" | \
tr '[\n' '\n[' > /etc/gdm/custom.conf
fi
fi
rm -f cat /tmp/custom.conf.$$
}
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Command area
add() # Cmd (Add a user to the greeter {<user>
{
UserFilter=`echo $Users | sed 's/,/|/g'`
if ! echo $1 | egrep -w $UserFilter &> /dev/null
then
echo "Error: user $1 unknown"
echo
return 1
fi
# Only work with the users not in the default exclude list
Filter=`echo $DefaultExclude | sed 's/,/|/g'`
Hidden=`echo $Exclude | tr ',' '\n' | egrep -vw "$Filter" | tr '\n' ','`
# Check if we need to do something
if ! echo $Hidden | tr ',' '\n' | grep -w $1 &> /dev/null
then
echo
echo "User $1 is not hidden"
echo
else
# Remove the user from the exclude
PlaceExclude "`echo $Exclude | tr ',' '\n' | grep -vw $1 | \
tr '\n' ',' | sed 's/,$//'`"
# Tell the action
echo "User $1 added to the greeter"
echo
fi
}
del() # Cmd (Delete/hide a user from the greeter {<user>
{
UserFilter=`echo $Users | sed 's/,/|/g'`
if ! echo $1 | egrep -w $UserFilter &> /dev/null
then
echo "Error: user $1 unknown"
echo
return 1
fi
# Check if we need to do something
if echo $Exclude | tr ',' '\n' | grep -w $1 &> /dev/null
then
echo
echo "User $1 is already excluded from the greeter"
echo
else
# Exclude the user
PlaceExclude "$1,$Exclude"
# Tell the action
echo "User $1 hidden from the greeter"
echo
fi
}
hide() # CMD (Delete/hide a user from the greeter {<user>
{
del $1
}
hidden() # Cmd (List the hidden users {
{
Filter=`echo $DefaultExclude | sed 's/,/|/g'`
Hidden=`echo $Exclude | tr ',' '\n' | egrep -vw "$Filter" | tr '\n' ','`
if [ ${#Hidden} -eq 0 ]
then
echo "No hidden users"
echo
else
echo
echo "Users hidden from the greeter:"
echo
echo $Hidden | tr ',' '\n' | sed 's/^/ /'
fi
}
users() # Cmd (List the users in the greeter {
{
Filter=`echo $Exclude | sed 's/,/|/g'`
Greeters=`echo $Users | tr ',' '\n' | egrep -vw "$Filter" | tr '\n' ','`
if [ ${#Greeters} -eq 0 ]
then
echo "No users in the greeter"
echo
else
echo
echo "Users in the greeter:"
echo
echo $Greeters | tr ',' '\n' | sed 's/^/ /'
fi
}
list() # CMD (List the users in the greeter {
{
users
}
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Framework area
help() # Cmd (Command help {[command]
{
if [ "$1" = "" ]
then
CMD=help
else
CMD=$1
fi
if ! grep \^${CMD}*\(\).*#.*Cmd $0 > /dev/null 2>&1
then
(
echo
echo "Error: unknown cmd"
echo
) >&2
else
(
echo
echo "Usage: `basename $0` $CMD `grep \^${CMD}*\(\).*#.*Cmd $0 | \
sed 's/.* {//g'`"
echo
) >&2
fi
}
#
# Main
#
if [ "$1" != "" ] && grep -i $1\(\).*#.*Cmd $0 > /dev/null 2>&1
then
$*
else
echo
echo "Usage: `basename $0` command [parm1] [parm2] [..]"
echo
echo " Available Commands:"
echo
grep \^[0-9a-z_A-Z]*\(\).*#.*Cmd $0 | \
awk -F\( '{printf "%-16s %s\n",$1,$3}' | sed 's/ {.*//g' | sort
echo
fi