Added client work scripts
[clearscm.git] / clients / HP / bin / pdl-new-passwd
1 #!/bin/ksh
2 ################################################################################
3 #
4 # File:         newpasswd
5 # Description:  Change the root passwd entry in /etc/passwd
6 # Author:       Kevin Lister kel@cup.hp.com
7 # Language:     Korn Shell
8 #
9 # (c) Copyright 1999, Hewlett-Packard Company, all rights reserved.
10 #
11 ################################################################################
12 #
13 ##
14 ### Variables
15 ##
16 #
17
18 ADMIN=pdl-support@cup.hp.com
19 PWFILE=/etc/passwd
20 PWFILENEW=/etc/passwd-new
21 PWFILEOLD=/etc/passwd-old
22 SYSNAME=$(uname -n)
23 BASE=${0##*/}
24 WHOAMI=$(id -u)
25 NULL=/dev/null
26
27 #
28 ##
29 ### Functions
30 ##
31 #
32
33 # Functions
34 function error {
35   print -u2 "$BASE: Error: $1"
36 }
37
38 #
39 ##
40 ### Main
41 ##
42 #
43
44 # Must be root to run this
45 if [ $WHOAMI -ne 0 ]; then
46         error "Must be root to execute this command... Exiting."
47         exit 0
48 fi
49
50 # Create the new passwd file
51 /bin/cat >> $PWFILENEW <<:NEWPW
52 root:u4/rTgJX35zHg:0:1:Root@$SYSNAME:/:/sbin/sh
53 :NEWPW
54 /bin/grep -v "^root" $PWFILE >> $PWFILENEW
55
56 # Save the old passwd file, install the new one
57 /bin/mv $PWFILE $PWFILEOLD
58 /bin/mv $PWFILENEW $PWFILE
59 /bin/chmod 444 $PWFILE
60 /bin/chown root:other $PWFILE
61
62 # Email us that a machine was updated
63 /usr/bin/mailx -s "$SYSNAME: Root passwd changed!" $ADMIN < $NULL