Skip to content

Instantly share code, notes, and snippets.

@ozym4nd145
Created October 1, 2017 05:24
Show Gist options
  • Save ozym4nd145/65fe181b19463b6b71aa88637f6c5e16 to your computer and use it in GitHub Desktop.
Save ozym4nd145/65fe181b19463b6b71aa88637f6c5e16 to your computer and use it in GitHub Desktop.
Add users directly to sqlite3 database of ghost 1.10
#!/bin/bash
if [ -z "$1" ]; then
echo "USAGE: $0 <username> <email>"
exit 1
fi
#DB=/var/www/ghost/content/data/ghost.db
DB=$PWD/ghost.db
ID=`echo "select count(*) from users;"|sqlite3 $DB`
EXITCODE=$?
if [ $EXITCODE == 0 ]; then
MOD_ID=$(echo $(echo $ID | cut -d' ' -f2) + 1 | bc)
USER="insert into users (id,
name,
slug,
ghost_auth_access_token,
ghost_auth_id,
password,
email,
profile_image,
cover_image,
bio,
website,
location,
facebook,
twitter,
accessibility,
status,
locale,
visibility,
meta_title,
meta_description,
tour,
last_seen,
created_at,
created_by,
updated_at,
updated_by)
values ('$MOD_ID',
'$1',
'$1',
NULL,
NULL,
'\$2a\$10\$uftpNa3w3xuQikyfXW9PW.c6ixKJM53fT7JIlTJG7lllmQ0FwICmy',
'$2',
NULL,
NULL,
'',
'',
'',
NULL,
NULL,
'',
'active',
NULL,
'public',
NULL,
NULL,
'',
'2017-10-01 00:40:00',
'2017-10-01 00:40:00',
'1',
'2017-10-01 00:40:00',
'1');"
RAND_UUID=`cat /proc/sys/kernel/random/uuid`
RAND_UUID=${RAND_UUID:13:35}
ROLE="insert into roles_users (id,role_id, user_id)
values ('$RAND_UUID','59cffaca3d9a2e038eaf8b72', '$MOD_ID');"
echo $USER|sqlite3 $DB
USER_CREATED=$?
echo $ROLE|sqlite3 $DB
ROLE_CREATED=$?
if [ $USER_CREATED == 0 ] && [ $ROLE_CREATED == 0 ]; then
echo "--------------------------------------------------------------------------------"
echo "Login details"
echo "--------------------------------------------------------------------------------"
echo "E-mail for user: $2"
echo "Default passord: password"
echo "--------------------------------------------------------------------------------"
exit 0
fi
exit 1
fi
echo "Unable to connect to DB located in: $DB"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment