mirroring: add individual foreign vcs mirror control
[girocco.git] / toolbox / edit-user-email.sh
blob15306a26c90727bb734e1f9b8108dca07db40086
1 #!/bin/sh
3 set -e
5 . @basedir@/shlib.sh
7 if [ -z "$1" -o -z "$2" -o -z "$3" ]; then
8 echo "Syntax: ./edit-user-email.sh <username> <old e-mail> <new e-mail>"
9 exit 1
11 ETC="$cfg_chroot/etc"
12 COUNT=`grep -E -c "^$1:" "$ETC/passwd"`
13 if [ "$COUNT" -ne "1" ]; then
14 echo "fatal: user '$1' doesn't appear to exist (or exists multiple times, or contains regexpy characters)."
15 exit 1
17 if echo "$2" | grep -q '[,:]'; then
18 echo "fatal: e-mail '$2' has illegal characters ([,:])."
19 exit 1
21 if ! echo "$3" | grep -E -q '^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+$'; then
22 echo "fatal: e-mail '$3' is not valid (^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+$)."
23 exit 1
25 sed -i.$$ \
26 -e "s/^$1\(:[^:]*:[^:]*:[^:]*:\)$2\([,:]\)/$1\\1$3\\2/" \
27 -e "t show" \
28 -e "b" \
29 -e ": show" \
30 -e "w /dev/stderr" \
31 "$ETC/passwd"
32 rm -f "$ETC/passwd.$$"
33 if [ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ]; then
34 "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$1"
36 echo "All changed lines listed above."