Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 40 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