Mercurial > hgrepos > hgweb.cgi > s4
annotate scripts/add-user-csv.sh @ 1013:1ffaa8b2b1bf draft
Modify blog comment form layout
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 11 Jul 2023 10:25:21 +0900 |
parents | 7c78ebd2f39f |
children |
rev | line source |
---|---|
544 | 1 #!/bin/sh |
2 | |
601 | 3 # DISABLED=1 ใในใ |
545
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
4 if [ -z "$1" ]; then |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
5 cat<<-EOF >&2 |
600 | 6 Usage: ./add-user-csv.sh CSVfile |
545
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
7 Csv file should be the form of: |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
8 username(email),notify-email,gecos,IniPassword |
600 | 9 Set \$DISABLED for setting disabled password |
545
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
10 EOF |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
11 exit 1 |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
12 fi |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
13 |
544 | 14 target=$(cd `dirname "$1"`; pwd)/`basename $1` |
563
7ab2ceb1b8dd
$DISABLED controls password disabling
HIROSE Yuuji <yuuji@gentei.org>
parents:
560
diff
changeset
|
15 encp=${DISABLED:+DisabledPassword} |
544 | 16 |
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 | |
22 | |
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 | |
563
7ab2ceb1b8dd
$DISABLED controls password disabling
HIROSE Yuuji <yuuji@gentei.org>
parents:
560
diff
changeset
|
34 encpswd=${encp:-`mycrypt "$inipswd" 'StOpmE'`} |
544 | 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 |