|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # vim: set filetype=sh ts=2 sw=2 sts=2 expandtab : |
3 | 3 |
|
4 | | -echo "Inflating Auth DB." |
5 | | -sqlite3 lemon.db "Create table if not exists users (uid text,name text,mail text,mobile text,password text);" |
6 | | -[[ "$?" == '0' ]] && echo "Done." |
7 | | - |
8 | | - # nickname # Full Name # mail # mobile # password |
9 | | -./create-user.sh 'dwho' 'Doctor Who' '[email protected]' '+33612345678' 'dwho' |
10 | | -./create-user.sh 'rtyler' 'R. Tyler' '[email protected]' '+11234567890' 'rtyler' |
11 | | -./create-user.sh 'jbinks' 'Jar Jar Binks' '[email protected]' '+84123456789' 'jbinks' |
| 4 | +echo "Inflating Authentication Database (lemon.db)." |
| 5 | + |
| 6 | +# Create the users table if it doesn't already exist |
| 7 | +sqlite3 lemon.db "CREATE TABLE IF NOT EXISTS users ( |
| 8 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 9 | + username TEXT, |
| 10 | + password TEXT, |
| 11 | + sn TEXT, |
| 12 | + mail TEXT, |
| 13 | + givenname TEXT, |
| 14 | + mobile TEXT, |
| 15 | + isadmin INTEGER DEFAULT 0, |
| 16 | + isblocked INTEGER DEFAULT 0 |
| 17 | +);" |
| 18 | +[[ "$?" == '0' ]] && echo "Table 'users' created or already exists." || { echo "Error creating table 'users'. Exiting."; exit 1; } |
| 19 | + |
| 20 | +# Create unique indexes for frequently searched fields |
| 21 | +# Note: The UNIQUE constraint on 'mail' above handles its uniqueness. |
| 22 | +sqlite3 lemon.db "CREATE UNIQUE INDEX IF NOT EXISTS u__username ON users (username);" |
| 23 | +[[ "$?" == '0' ]] && echo "Index 'u__username' created or already exists." || { echo "Error creating index 'u__username'. Exiting."; exit 1; } |
| 24 | + |
| 25 | +sqlite3 lemon.db "CREATE UNIQUE INDEX IF NOT EXISTS u__mail ON users (mail);" |
| 26 | +[[ "$?" == '0' ]] && echo "Index 'u__mail' created or already exists." || { echo "Error creating index 'u__mail'. Exiting."; exit 1; } |
| 27 | + |
| 28 | +sqlite3 lemon.db "CREATE UNIQUE INDEX IF NOT EXISTS u__mobile ON users (mobile);" |
| 29 | +[[ "$?" == '0' ]] && echo "Index 'u__mobile' created or already exists." || { echo "Error creating index 'u__mobile'. Exiting."; exit 1; } |
| 30 | + |
| 31 | +echo "Inserting user data..." |
| 32 | + |
| 33 | +# Insert user data matching the PostgreSQL schema |
| 34 | +# Using INSERT OR IGNORE to skip rows that would violate unique constraints (e.g., duplicate emails) |
| 35 | +# Derivation Logic: |
| 36 | +# givenname: Use 'givenName' from LDIF if present. Otherwise, use the first word of 'cn'. |
| 37 | +# sn: If 'cn' has multiple words, use the last word of 'cn'. Otherwise, use 'sn' from LDIF if present, else NULL. |
| 38 | +sqlite3 lemon.db "INSERT OR IGNORE INTO users (username, password, givenname, sn, mail, mobile) VALUES |
| 39 | +('dwho', 'dwho', 'Doctor', 'Who', '[email protected]', '+33612345678'), |
| 40 | +('rtyler', 'rtyler', 'R.', 'Tyler', '[email protected]', '+11234567890'), |
| 41 | +('jbinks', 'jbinks', 'Jar Jar', 'Binks', '[email protected]', '+84123456789'), |
| 42 | +('msmith', 'msmith', 'Mr', 'Smith', '[email protected]', NULL), |
| 43 | +('okenobi', 'okenobi', 'Obi-Wan', 'Kenobi', '[email protected]', NULL), |
| 44 | +('qjinn', 'qjinn', 'Qui-Gon', 'Jinn', '[email protected]', NULL), |
| 45 | +('chewbacca', 'chewbacca', 'Chewbacca', 'Chewbacca', '[email protected]', NULL), |
| 46 | +('lorgana', 'lorgana', 'Leia', 'Organa', '[email protected]', NULL), |
| 47 | +('pamidala', 'pamidala', 'Padme', 'Amidala', '[email protected]', NULL), |
| 48 | +('cdooku', 'cdooku', 'Comte', 'Dooku', '[email protected]', NULL), |
| 49 | +('kren', 'kren', 'Kylo', 'Ren', '[email protected]', NULL), |
| 50 | +('dmaul', 'dmaul', 'Dark', 'Maul', '[email protected]', NULL), |
| 51 | +('askywalker', 'askywalker', 'Anakin', 'Skywalker', '[email protected]', NULL), |
| 52 | +('bfett', 'bfett', 'Boba', 'Fett', '[email protected]', NULL), |
| 53 | +('jfett', 'jfett', 'Jango', 'Ffett', '[email protected]', NULL), |
| 54 | +('lskywalker', 'lskywalker', 'Luc', 'Skywalker', '[email protected]', NULL), |
| 55 | +('myoda', 'myoda', 'Master', 'Yoda', '[email protected]', NULL), |
| 56 | +('hsolo', 'hsolo', 'Han', 'Solo', '[email protected]', NULL), |
| 57 | +('r2d2', 'r2d2', 'R2D2', 'R2D2', '[email protected]', NULL), |
| 58 | +('c3po', 'c3po', 'C3PO', 'C3po', '[email protected]', NULL), |
| 59 | +('synapseadmin', 'synapseadmin', 'Synapse', 'Syadmin', '[email protected]', NULL), |
| 60 | +('annasmith', 'annasmith', 'Anna', 'Smith', '[email protected]', NULL), |
| 61 | +('johnjohnson', 'johnjohnson', 'John', 'Johnson', '[email protected]', NULL), |
| 62 | +('emilybrown', 'emilybrown', 'Emily', 'Brown', '[email protected]', NULL), |
| 63 | +('daviddavis', 'daviddavis', 'David', 'Davis', '[email protected]', NULL), |
| 64 | +('sarahwilson', 'sarahwilson', 'Sarah', 'Wilson', '[email protected]', NULL), |
| 65 | +('miketaylor', 'miketaylor', 'Mike', 'Taylor', '[email protected]', NULL), |
| 66 | +('graceadams', 'graceadams', 'Grace', 'Adams', '[email protected]', NULL), |
| 67 | +('mattmoore', 'mattmoore', 'Matt', 'Moore', '[email protected]', NULL), |
| 68 | +('lilyparker', 'lilyparker', 'Lily', 'Parker', '[email protected]', NULL), |
| 69 | +('danieldixon', 'danieldixon', 'Daniel', 'Dixon', '[email protected]', NULL), |
| 70 | +('mialopez', 'mialopez', 'Mia', 'Lopez', '[email protected]', NULL), |
| 71 | +('ethanjackson', 'ethanjackson', 'Ethan', 'Jackson', '[email protected]', NULL), |
| 72 | +('oliviaroberts', 'oliviaroberts', 'Olivia', 'Roberts', '[email protected]', NULL), |
| 73 | +('jamessmith', 'jamessmith', 'James', 'Smith', '[email protected]', NULL), |
| 74 | +('sophiathomas', 'sophiathomas', 'Sophia', 'Thomas', '[email protected]', NULL), |
| 75 | +('benjaminclark', 'benjaminclark', 'Benjamin', 'Clark', '[email protected]', NULL), |
| 76 | +('avamartin', 'avamartin', 'Ava', 'Martin', '[email protected]', NULL), |
| 77 | +('williamrogers', 'williamrogers', 'William', 'Rogers', '[email protected]', NULL), |
| 78 | +('emmawright', 'emmawright', 'Emma', 'Wright', '[email protected]', NULL), |
| 79 | +('chloescott', 'chloescott', 'Chloe', 'Scott', '[email protected]', NULL), |
| 80 | +('danieltaylor', 'danieltaylor', 'Daniel', 'Taylor', '[email protected]', NULL), |
| 81 | +('sophiarichardson', 'sophiarichardson', 'Sophia', 'Richardson', '[email protected]', NULL), |
| 82 | +('henryjones', 'henryjones', 'Henry', 'Jones', '[email protected]', NULL), |
| 83 | +('gracelewis', 'gracelewis', 'Lewis', '[email protected]', 'Grace', NULL), |
| 84 | +('samuelharris', 'samuelharris', 'Harris', '[email protected]', 'Samuel', NULL), |
| 85 | +('ameliahall', 'ameliahall', 'Amelia', 'Hall', '[email protected]', NULL), |
| 86 | +('lucyedwards', 'lucyedwards', 'Edwards', '[email protected]', 'Lucy', NULL), |
| 87 | +('christophermiller', 'christophermiller', 'Miller', '[email protected]', 'Christopher', NULL), |
| 88 | +('emilyperez', 'emilyperez', 'Perez', '[email protected]', 'Emily', NULL), |
| 89 | +('andrewcook', 'andrewcook', 'Andrew', 'Cook', '[email protected]', NULL), |
| 90 | +('oliviaparker', 'oliviaparker', 'Parker', '[email protected]', 'Olivia', NULL), |
| 91 | +('josephmartin', 'josephmartin', 'Joseph', 'Martin', '[email protected]', NULL), |
| 92 | +('lilybrown', 'lilybrown', 'Brown', '[email protected]', 'Lily', NULL), |
| 93 | +('elizabethlee', 'elizabethlee', 'Lee', '[email protected]', 'Elizabeth', NULL), |
| 94 | +('ethangreen', 'ethangreen', 'Green', '[email protected]', 'Ethan', NULL), |
| 95 | +('noahroberts', 'noahroberts', 'Noah', 'Roberts', '[email protected]', NULL), |
| 96 | +('gracegarcia', 'gracegarcia', 'Garcia', '[email protected]', 'Grace', NULL), |
| 97 | +('avaclark', 'avaclark', 'Clark', '[email protected]', 'Ava', NULL), |
| 98 | +('sophiedavis', 'sophiedavis', 'Davis', '[email protected]', 'Sophie', NULL), |
| 99 | +('benjaminharrison', 'benjaminharrison', 'Harrison', '[email protected]', 'Benjamin', NULL); |
| 100 | +" |
| 101 | +[[ "$?" == '0' ]] && echo "All user data inserted successfully (or ignored if duplicates existed)." || { echo "Error inserting user data. Exiting."; exit 1; } |
| 102 | + |
| 103 | +echo "Database setup complete: lemon.db" |
0 commit comments