Make the rbutil page a bit smarter.
[rockboxthemes.git] / private / adduser.sh
blobfec94221e7e517fc0800c14c5546ee3fe1a0eae9
1 #!/bin/sh
2 if [ -z "$1" -o ! -f "$1" ]; then
3 printf "Usage: %s dbfile\n" `basename "$0"`
4 exit 1
5 elif [ ! -w "$1" ]; then
6 printf "Error: You need write permissions for %s\n" "$1" 1>&2
7 exit 2
8 else
9 dbfile=$1
11 for util in md5sum sqlite; do
12 if [ ! -x "`which $util 2>/dev/null`" ]; then
13 echo "We need the $util utility"
14 exit 3
16 done
18 echo "Add a user to the admin table"
19 echo ""
21 printf "Username: "
22 read user
23 printf "Password: "
24 read pass
25 md5pass=`printf "$pass"|md5sum|cut -c 1-32`
26 sql=`printf "INSERT INTO admins (name, pass) VALUES ('%s', '%s')" "$user" "$md5pass"`
27 sqlite "$dbfile" "$sql"