summaryrefslogtreecommitdiffstats
path: root/murmur/murmur-config.sh
blob: ebee4a4a9714d029541090e1a4ec205222833140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
#
# -> config.sh 
#
#   version: 1.1
#   author: Massimo Mund
#   date: 21.12.2007
#   description: a script to easily add, remove and edit users from a murmur server
#

#information
version="1.1"

#settings
bin="sqlite3"
dbfile="/var/lib/murmurd/murmurd.sqlite"

function checkforsqlite() {

	if [ ! -f /usr/bin/sqlite3 ]; then
		echo "it seems that there is no sqlite3 installed, which is necessary for this script! "
		echo "install sqlite3 and try it again!"
		exit
	fi

}

function help () {

	echo ""
	echo " usage: config.sh <cmd> | --help | --version"
	echo ""
	echo " commands:"
	echo "   showusers"
	echo "   adduser <username> <pw> [<serverid>] [<email>]"
	echo "   deluser <username> [<serverid>]"
	echo "   setpw <username> <newpw> [<serverid>]"
	echo "   setemail <username> <newemail> [<serverid>]"
	echo ""
	exit

}

function version() {

	echo "config.sh : version: $1"
	exit
}

function invalidoption () {

	echo "config.sh : invalid option -- $*"
	echo "Try 'config.sh --help' for more information."
	exit

}

checkforsqlite

while [ "$#" -gt "0" ]; do
        case $1 in
		showusers)
			$bin $dbfile "select * from players;"
			exit
		;;
                adduser)
			shift
                        username="$1"
                        email="$4"
			pw="$2"
			serverid="$3"
			playerid=$($bin $dbfile "select MAX(player_id)+1 as id from players WHERE player_id < 10000;")

			if [ "$serverid" == "" ]; then
				serverid="1"
			fi

			$bin $dbfile "insert into players (server_id, player_id, name, email, pw) values($serverid, $playerid, '$username', '$email', '$pw');"
			exit
                ;;
		deluser)
			shift
			username="$1"
			serverid="$2"

                        if [ "$serverid" == "" ]; then
                                serverid="1"
                        fi

			$bin $dbfile "delete from players where name='$username';"
			exit
		;;
		setpw)
			shift
			username="$1"
			newpw="$2"
			serverid="$3"

                        if [ "$serverid" == "" ]; then
                                serverid="1"
                        fi
		
			$bin $dbfile "update players set pw='$newpw' where name='$username';"
			exit
		;;
		setemail)
                        shift
                        username="$1"
                        newemail="$2"
                        serverid="$3"

                        if [ "$serverid" == "" ]; then
                                serverid="1"
                        fi

                        $bin $dbfile "update players set email='$newemail' where name='$username';"
			exit
		;;
		--help)
			help
		;;
		--version)
			version $version
		;;
                *)
			invalidoption $*
                    	break
                ;;
        esac
done

invalidoption $*

exit 0