File: selection.sh

package info (click to toggle)
libcdk5 5.0.20050424-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,504 kB
  • ctags: 2,620
  • sloc: ansic: 29,645; sh: 4,283; makefile: 634; cpp: 42; sed: 40
file content (190 lines) | stat: -rw-r--r-- 3,431 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/sh

#
# Description:
#		This demonstrates the CDK command line
# interface to the selection widget.
#

#
# This gets the password file.
#
getPasswordFile()
{
   system=$1
   file=$2

   #
   # Depeding on the system, get the password file
   # using nicat, ypcat, or just plain old /etc/passwd
   #
   if [ "$system" = "NIS" ]; then
      niscat passwd.org_dir > $file
   elif [ "$system" = "YP" ]; then
      ypcat passwd > $file
   else
      cp /etc/passwd $file
   fi
}

#
# This displays account information.
#
displayAccountInformation()
{
   totalSelections=$1
   currentSelection=$2
   userAccount=$3
   passwordFile=$4

   #
   # Get the user account information.
   #
   line=`grep "^${userAccount}" $passwordFile`
   uid=`echo $line | cut -d: -f3`
   gid=`echo $line | cut -d: -f4`
   info=`echo $line | cut -d: -f5`
   home=`echo $line | cut -d: -f6`
   shell=`echo $line | cut -d: -f7`

   #
   # Create the label message information.
   #
   accountMessage="<C></U>Account ${currentSelection}/${totalSelections}
<C><#HL(30)>
Account: </U>${userAccount}
UID    : </U>${uid}
GID    : </U>${gid}
Info   : </U>${info}
Home   : </U>${home}
Shell  : </U>${shell}
<C><#HL(30)>
<C>Hit </R>space<!R> to continue"

   #
   # Create the popup label.
   #
   ${CDK_LABEL} -m "${accountMessage}" -p " "
}

#
# Define where the CDK widgets are.
#
CDK_SELECTION="../cdkselection"
CDK_LABEL="../cdklabel"
TYPE="Other"

#
# Define the output files.
#
accountList="/tmp/accList.$$"
userAccounts="/tmp/userAccList.$$"
output="/tmp/selection_output.$$"
tmpPass="/tmp/ps.$$"
tmp="/tmp/tmp.$$"

#
# Chop up the command line.
#
set -- `getopt nNh $*`
if [ $? != 0 ]
then
   echo $USAGE
   exit 2
fi
for c in $*
do
    case $c in
         -n) TYPE="YP"; shift;;
         -N) TYPE="NIS"; shift;;
         -h) echo "$0 [-n YP] [-N NIS+] [-h]"; exit 0;;
         --) shift; break;;
    esac
done

#
# Create the message for the selection list.
#
title="<C>Pick a user account to view."

#
# Get the password file and stick it into the temp file.
#
getPasswordFile "${TYPE}" "$tmpPass"

#
# Create the user account list.
#
awk 'BEGIN {FS=":"} {printf "%s\n", $1}' $tmpPass | sort > ${userAccounts}
awk '{printf "<C></B>%s\n", $1}' ${userAccounts} > ${accountList}
accounts=`cat ${userAccounts}`

#
# Create the choices list.
#
choices="<C></B>No 
<C></B> Yes "
buttons=" OK 
 Cancel "

#
# Create the selection list.
#
${CDK_SELECTION} -T "${title}" -f "${accountList}" -c "${choices}" -B "${buttons}"  2> $output
if [ $? -lt 0 ]; then
   exit;
fi

#
# Initialize the variables.
#
selection=""
value=""

#
# Count how many were selected.
#
count=`grep -c "^1" ${output}`
current=0

#
# Create the label.
#
for i in `cat ${output}`
do
   #
   # Since every other variable is value/selection, we
   # store every other value in the correct variable.
   #
   if [ "$value" = "" ]; then
      value="$i"
   else
      selection="$i"

      #
      # Only display the selected accounts.
      #
      if [ "$value" -eq 1 ]; then
         #
         # Increment our counter.
         #
         current=`expr $current + 1`

         #
         # Display the account information.
         #
         displayAccountInformation $count $current $selection $tmpPass
      fi

      #
      # Reset the variables.
      #
      value=""
      selection=""
   fi
done

#
# Clean up.
#
#rm -f ${accountList} ${userAccounts} ${output} ${tmpPass} ${tmp}