date -R is a linux-only option, switch to POSIX equivalent
[girocco.git] / toolbox / edit-user-email.sh
blobc2e3cbab1eab0c8f2d13e9bbe6fb8d103013ca91
1 #!/bin/sh
3 if [ -z "$1" -o -z "$2" -o -z "$3" ]; then
4 echo "Syntax: ./edit-user-email.sh <username> <old e-mail> <new e-mail>"
5 exit 1
6 fi
7 ETC=$HOME/j/etc
8 COUNT=`grep -E -c "^$1:" $ETC/passwd`
9 if [ "$COUNT" -ne "1" ]; then
10 echo "fatal: user '$1' doesn't appear to exist (or exist multiple times, or contain regexpy characters)."
11 exit 1
13 sed -i "s/^$1\(:[^:]*:[^:]*:[^:]*:\)$2:/$1\\1$3:/; t show; b; : show; w /dev/stderr" $ETC/passwd
14 echo "All changed lines listed above."