From 6257e7ec94ae9010906882b01654a72fb5d6f5e6 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 10 Sep 2022 22:18:51 +0100 Subject: [PATCH] add create-user.sh script. This script adds a user to the database based on it's inputs (prompted for the person running the script). The intention is to add a user to the database easier (especially on a live production server with just the CLI). --- scripts/create-user.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 scripts/create-user.sh diff --git a/scripts/create-user.sh b/scripts/create-user.sh new file mode 100755 index 0000000..c0efaee --- /dev/null +++ b/scripts/create-user.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Create account so user can log-in to the website. Assumes you're using +# SQLilte3 as the database. + +# Moves to the location of the script (regardless of where the script +# was called from). +cd "$(dirname "$0")" +DATABASE="ritherdon-archive.db" + +read -p "Username: " USERNAME +read -p "Display Name: " DISPLAY_NAME +read -sp "Password: " USER_PASSWORD +echo +read -sp "Confirm Password: " PASSWORD_TEST +echo + +if [[ $USERNAME == "" ]] + || [[ $DISPLAY_NAME == "" ]] + || [[ $USER_PASSWORD == "" ]]; then + echo "[ERROR] Empty string used." +else + if [[ $USER_PASSWORD == $PASSWORD_TEST ]]; then + echo "[SUCCESS] Password verified." + if [ -e "../$DATABASE" ]; then + echo "[INFO] Database found. Adding user to it..." + SQL="INSERT INTO user (username,display_name,password,created_at,updated_at) \ + VALUES (\"$USERNAME\",\"$DISPLAY_NAME\",\"$USER_PASSWORD\",(datetime(\"now\")),NULL);" + cd ../ + sqlite3 $DATABASE "$SQL" + + else + echo "[ERROR] Cannot find database. Make sure you've ran make build." + exit + fi + else + echo "[ERROR] Passwords do not match." + fi +fi