File: scroll.sh

package info (click to toggle)
libcdk5 5.0.20251014-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,544 kB
  • sloc: ansic: 32,708; sh: 5,317; makefile: 1,203; awk: 55; sed: 49; cpp: 41
file content (136 lines) | stat: -rwxr-xr-x 2,566 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
# $Id: scroll.sh,v 1.5 2022/10/18 23:47:13 tom Exp $

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

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

   #
   # Depending 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()
{
   userAccount=$1
   passwordFile=$2

   #
   # 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
<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 " "
}

#
# Create some global variables.
#
CDK_SCROLL="${CDK_BINDIR=..}/cdkscroll"
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"

tmpPass="${TMPDIR=/tmp}/sl.$$"
output="${TMPDIR=/tmp}/output.$$"
userAccounts="${TMPDIR=/tmp}/ua.$$"

TYPE="Other"

#
# Chop up the command line.
#
if set -- `getopt nNh "$@"`
then
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
else
   echo "Usage: $0 [-n] [-N] [-h]"
   exit 2
fi

#
# Create the message for the scrolling list.
#
title="<C><#HL(30)>
<C>Pick an account you want to view.
<C><#HL(30)>"
buttons=" OK 
 Cancel "

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

#
# Get the user account from the password file.
#
awk 'BEGIN {FS=":"} {printf "%s\n", $1}' "$tmpPass" | sort > "${userAccounts}"

#
# Create the scrolling list.
#
${CDK_SCROLL} -T "${title}" -f "${userAccounts}" -n -B "${buttons}" 2> "${output}"
selected=$?
test $selected = 255 && exit 1

answer=`cat "${output}"`

#
# Display the account information.
#
displayAccountInformation "$answer" "$tmpPass"

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