changeset 967:27eacef6470b draft

Initial entry of account removing script
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 20 Feb 2022 17:11:34 +0900
parents 679f621de4b5
children edd96c59c8a2
files scripts/remove-user-csv.sh
diffstat 1 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/remove-user-csv.sh	Sun Feb 20 17:11:34 2022 +0900
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+if [ -z "$1" ]; then
+  cat<<-EOF >&2
+	Usage: ./remove-user-csv.sh CSVfile
+	Csv file should be the form of:
+	   username(email)
+	EOF
+  exit 1
+fi
+outdelim() echo "------------------------------------------------"
+
+   
+target=$(cd `dirname "$1"`; pwd)/`basename $1`
+
+cd `dirname $0`/..
+if ! . ./s4-funcs.sh; then
+  echo "Cannot find s4-funcs.sh, which should be located in $mydir/.."
+  exit 1
+fi
+
+outdelim
+query<<-EOF
+	CREATE TEMPORARY TABLE _rmuser(user);
+	.import $target _rmuser
+	.mode list
+	.head 1
+	SELECT name,
+	       max(CASE key WHEN 'gecos' THEN val END) gecos,
+	       max(CASE key WHEN 'login' THEN val END) login
+	FROM   user_s
+	WHERE name IN (SELECT * FROM _rmuser)
+	GROUP by name;
+	SELECT count(name) || ' users' "To be removed"
+	FROM user WHERE name IN (SELECT * FROM _rmuser);
+	EOF
+
+outdelim
+echo "Remove them? (Type C-c to abort)" >&2
+read ans
+
+# Remove users in Base World
+query "DELETE FROM user WHERE name IN (SELECT * FROM _rmuser);"
+
+# Remove users in Extra World
+for world in $S4WORLDLIST; do
+  case "$world" in			# tag:shortname:desc
+    *:*:*:*) continue ;;
+    *:*:*)
+      t_s=${world%:*}			# tag:shortname
+      d=${world##*:}			# desc
+      w=${t_s#*:}			# shortname
+      ;;
+    *) continue ;;
+  esac
+  wdb=`(unset DB; . ./s4-config-$w.sh; echo $DB)`
+  echo "Operate on world $d($wdb)" >&2
+  query <<-EOF
+	ATTACH DATABASE "$wdb" AS w;
+	DELETE FROM w.user WHERE name IN (SELECT * FROM _rmuser);
+	DETACH DATABASE w;
+	EOF
+done

yatex.org