updated on Thu Jan 12 08:01:00 UTC 2012
[aur-mirror.git] / flexibee-last / flexibee
blobc257825404f998d104f80dd6c378d5aff706380d
1 #!/bin/bash
2 # Created by Max Devaine <maxdevaine@gmail.com>
3 # Last update : 4.1.2012
5 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/java/jre/bin
6 FLEXIBEE_PID=/var/run/flexibee.pid
7 FLEXIBEE_USER="flexibee"
8 MYLANG=`echo $LANG | cut -c 1-2`
9 CONFIGFILE=/etc/flexibee/flexibee-server.xml
12 case "$1" in
13 start)
15 ### detect flexibee default configuration file
16 if [ -f /etc/default/flexibee ]; then
17 . /etc/default/flexibee
20 ### detect flexibee server mode (if is define)
21 if [ x"$FLEXIBEE_CFG" = x"client" ]; then
23 if [ x"$MYLANG" = x"cs" ]; then
24 echo "FlexiBee je vypnutý. Změňte hodnotu FLEXIBEE_CFG z 'client' na 'local' nebo 'server' v /etc/default/flexibee"
25 else if [ x"$MYLANG" = x"sk" ]; then
26 echo "FlexiBee je vypnutý. Zmeňte hodnotu FLEXIBEE_CFG z 'client' na 'local' alebo 'server' v /etc/default/flexibee"
27 else
28 echo "FlexiBee is disabled. Change FLEXIBEE_CFG from 'client' to 'local' or 'server' in /etc/default/flexibee"
31 exit 0
35 ### detect postgresql server runing
36 if [ ! -e /var/run/daemons/postgresql ]; then
38 if [ x"$MYLANG" = x"cs" ]; then
39 echo "Neběží postgresql databáze. Spustě jí pomocí /etc/rc.d/postgresql start"
40 else
41 echo "Postgresql database not running, run the database : /etc/rc.d/postgresql start "
43 exit 0
47 ### detect flexibee running
48 if [ -e $FLEXIBEE_PID ]; then
50 if [ x"$MYLANG" = x"cs" ]; then
51 echo "Flexibee server je už spuštěn!"
52 else
53 echo "Flexibee server is running!"
55 exit 0
58 ### run flexibee server
59 /usr/sbin/flexibee-server
61 ### detect running flexibee server
62 if [ -e $FLEXIBEE_PID ]; then
64 if [ x"$MYLANG" = x"cs" ]; then
65 echo "Flexibee server byl úspěšně spuštěn."
66 else
67 echo "Flexibee server successfully started"
69 exit 0
70 else
71 if [ x"$MYLANG" = x"cs" ]; then
72 echo "Chyba při spouštění flexibee serveru!"
73 else
74 echo "Error when starting flexibee server!"
81 stop)
83 if [ ! -e $FLEXIBEE_PID ]; then
85 if [ x"$MYLANG" = x"cs" ]; then
86 echo "Chyba : Flexibee server není spuštěn."
87 else
88 echo "Error : Flexibee server is not running"
90 exit 0
93 kill `cat $FLEXIBEE_PID`
94 rm -f $FLEXIBEE_PID
97 restart)
98 $0 stop
99 sleep 2
100 $0 start
102 install)
104 echo "---> 1) Create system user and group : flexibee"
105 echo " useradd --system --home-dir /tmp --no-create-home --user-group --shell /bin/false flexibee"
106 useradd --system --home-dir /tmp --no-create-home --user-group --shell /bin/false flexibee
108 echo "---> 2) Change flexibee connection port from default 5435 to arch linux postgresql port 5432"
109 echo " cat $CONFIGFILE | sed '/port/s/5435/5432/g' > $CONFIGFILE.new"
110 echo " mv $CONFIGFILE.new $CONFIGFILE"
111 cat $CONFIGFILE | sed '/"port"/s/5435/5432/g' > $CONFIGFILE.new
112 mv $CONFIGFILE.new $CONFIGFILE
114 echo "---> 3) Create database role with random secret password : "
115 echo " su - postgres -c CREATE ROLE dba PASSWORD '********' CREATEDB SUPERUSER CREATEROLE INHERIT LOGIN;"
117 ### generate random password
118 pass=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 23)`
120 ### create database role
121 su - postgres -c "psql -c \"CREATE ROLE dba PASSWORD '$pass' CREATEDB SUPERUSER CREATEROLE INHERIT LOGIN;\""
124 echo "---> 4) The database role password adding to flexibee configuration file $CONFIGFILE"
125 echo " cat $CONFIGFILE | sed '/password/s/7971/**********/g' > $CONFIGFILE.new"
126 echo " mv $CONFIGFILE.new $CONFIGFILE"
127 cat $CONFIGFILE | sed '/password/s/7971/'$pass'/g' > $CONFIGFILE.new
128 mv $CONFIGFILE.new $CONFIGFILE
129 pass=0
131 echo "---> 4) Change file permission to flexibee configiration file"
132 echo " chmod 600 $CONFIGFILE"
133 echo " chown flexibee $CONFIGFILE"
134 chmod 600 $CONFIGFILE
135 chown flexibee $CONFIGFILE
140 echo "usage: $0 {start|stop|restart|install}"
141 esac
142 exit 0