Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 41 lines (34 sloc) 737 Bytes
#! /bin/sh
if [ $# = 0 ]; then
echo "Aufruf: $0 {id}"
exit 1
fi
DB=./local-db
function random_tag() {
head -c 12 /dev/random | base64 | tr /+ _-
}
emails=$(
echo "
SELECT DISTINCT email
FROM riders
WHERE id = $1 AND email IS NOT NULL AND email <> '' AND email NOT IN (SELECT email FROM users);
" | $DB -N)
user=$(
echo '
SELECT COALESCE(MAX(user), 0)+1
FROM users;
' | $DB -N)
for email in $emails; do
user_tag=$(random_tag)
echo -n "
INSERT INTO users (user, email, user_tag)
VALUES ($user, '$email', '$user_tag');
"
echo -n "
UPDATE riders
SET user_tag = '$user_tag'
WHERE email = '$email';
"
((user++))
done \
| $DB