s4

changeset 544:6039630ea2f5

add add-user-csv.sh
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 06 Apr 2019 19:56:15 +0900
parents 29dcfb436600
children 7cd9e895fa09
files scripts/add-user-csv.sh
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/add-user-csv.sh	Sat Apr 06 19:56:15 2019 +0900
     1.3 @@ -0,0 +1,37 @@
     1.4 +#!/bin/sh
     1.5 +# Usage: ./add-user-csv.sh CSVfile
     1.6 +
     1.7 +target=$(cd `dirname "$1"`; pwd)/`basename $1`
     1.8 +
     1.9 +cd `dirname $0`/..
    1.10 +if ! . ./s4-funcs.sh; then
    1.11 +  echo "Cannot find s4-funcs.sh, which should be located in $mydir/.."
    1.12 +  exit 1
    1.13 +fi
    1.14 +
    1.15 +sq $db<<-EOF |
    1.16 +	.mode csv
    1.17 +	CREATE TEMPORARY TABLE _newuser(user,email,gecos,inipswd);
    1.18 +	.import $target _newuser
    1.19 +	.mode list
    1.20 +	.sepa ,
    1.21 +	SELECT * FROM _newuser n
    1.22 +	WHERE NOT EXISTS (SELECT * FROM user WHERE name=n.user);
    1.23 +	EOF
    1.24 +while IFS=, read user email gecos inipswd
    1.25 +do
    1.26 +  encpswd=`echo $inipswd|mypwhash`
    1.27 +  case "$user" in
    1.28 +    *\'*)	echo "Skipping [$user]"
    1.29 +		continue ;;
    1.30 +    *@*)	;;		# OK
    1.31 +    *)		echo "Skipping [$user] because of lacking email pattern" >&2
    1.32 +		continue ;;
    1.33 +  esac
    1.34 +  # echo "$user" "$user" "$inipswd" "$encpswd"
    1.35 +  query "INSERT INTO user VALUES('$user');" &&
    1.36 +    echo Adding $user
    1.37 +  dbsetbyid user "$user" email "$email"
    1.38 +  dbsetbyid user "$user" gecos "$gecos"
    1.39 +  dbsetbyid user "$user" pswd "$encpswd"
    1.40 +done