s4

view scripts/add-user-csv.sh @ 870:a7ae0d67edff

XXX: Lead password resetting to base world
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 07 Oct 2020 13:01:29 +0859
parents f68f13fb226b
children
line source
1 #!/bin/sh
3 # DISABLED=1 ใ™ในใ
4 if [ -z "$1" ]; then
5 cat<<-EOF >&2
6 Usage: ./add-user-csv.sh CSVfile
7 Csv file should be the form of:
8 username(email),notify-email,gecos,IniPassword
9 Set \$DISABLED for setting disabled password
10 EOF
11 exit 1
12 fi
14 target=$(cd `dirname "$1"`; pwd)/`basename $1`
15 encp=${DISABLED:+DisabledPassword}
17 cd `dirname $0`/..
18 if ! . ./s4-funcs.sh; then
19 echo "Cannot find s4-funcs.sh, which should be located in $mydir/.."
20 exit 1
21 fi
23 sq $db<<-EOF |
24 .mode csv
25 CREATE TEMPORARY TABLE _newuser(user,email,gecos,inipswd);
26 .import $target _newuser
27 .mode list
28 .sepa ,
29 SELECT * FROM _newuser n
30 WHERE NOT EXISTS (SELECT * FROM user WHERE name=n.user);
31 EOF
32 while IFS=, read user email gecos inipswd
33 do
34 encpswd=${encp:-`mycrypt "$inipswd" 'StOpmE'`}
35 case "$user" in
36 *\'*) echo "Skipping [$user]"
37 continue ;;
38 *@*) ;; # OK
39 *) echo "Skipping [$user] because of lacking email pattern" >&2
40 continue ;;
41 esac
42 # echo "$user" "$user" "$inipswd" "$encpswd"
43 query "INSERT INTO user VALUES('$user');" &&
44 echo Adding $user
45 dbsetbyid user "$user" email "$email"
46 dbsetbyid user "$user" gecos "$gecos"
47 dbsetbyid user "$user" pswd "$encpswd"
48 done