alternate gui controller

Problems with the Linux version of XAMPP, questions, comments, and anything related.

alternate gui controller

Postby meter » 18. February 2010 18:11

I got bored and wrote a GUI wrapper for lampp. This one offers control over more processes than the packaged python version and requires only zenity and bash. But it's also not as pretty and is a little stupid: it's won't tell you if something is running or not. I hope to fix the stupid part in future, but first I need to get bored again.

To use, copy the code below to a file (best place is probably /usr/local/sbin/glamp), make it executable by root, and invoke with
Code: Select all
gksudo glamp
.

file: glampp
Code: Select all
#!/bin/bash

# GUI wrapper for common lampp commands
# Copyright (C) 2010 Mithat Konar
# 2010-02-18

#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

### Constants
uiTitle="LAMPP control"

uiStart="Start"
uiStop="Stop"

uiStartApache="Start Apache"
uiStartMySQL="Start MySQL"
uiStartFTP="Start ProFTP"

uiStopApache="Stop Apache"
uiStopMySQL="Stop MySQL"
uiStopFTP="Stop ProFTP"

uiCancel="Cancel"
uiQuit="Quit"

uiDone="
Done!"

kDialogHeight=400
kDialogWidth=400

LAMPP_SCRIPT="/opt/lampp/lampp"      # path to actual lampp script.

### Functions

function getOption()
# Show a GUI that asks the user what they want to do.
# Return the resired action in the global 'gDoThis'
# Return the value 1 if the user canceled.
{
   local retval=0
   
   # TODO: do some fancy stuff to check which XAMPP processes are running and
   # show in uiText instead of the message below.
   local uiText="For more options, run '$LAMPP_SCRIPT' in a terminal."
   
   gDoThis=`zenity --list \
         --height $kDialogHeight \
         --width $kDialogWidth \
          --title "$uiTitle" \
          --text "$uiText" \
          --radiolist \
          --column "" \
          --column "Option" \
          FALSE "$uiStart" \
          FALSE "$uiStartApache" \
          FALSE "$uiStartMySQL" \
          FALSE "$uiStartFTP" \
          FALSE "$uiStop" \
          FALSE "$uiStopApache" \
          FALSE "$uiStopMySQL" \
          FALSE "$uiStopFTP" \
          FALSE "$uiQuit"`
   retval=$?
      
   if [ $retval -eq 1 ]; then      # cancel
      gDoThis=$uiCancel
      return 1
   fi
}

function doLampp()
# Execute the lampp command with argument specified in gOption in its own window.
{
   #~ urxvt -title LAMPP -bg orangered -fg white -e bash -c \
      #~ "$LAMPP_SCRIPT $gOption; echo ; read -sn 1 -p \"Press any key to continue...\""
   
   ($LAMPP_SCRIPT $gOption; echo "$uiDone") | \
    zenity --text-info \
           --title "$uiTitle" \
           --width $kDialogWidth \
           --height $kDialogHeight
}

### "MAIN"

rv=0
gOption=""

while [ $rv -eq 0 ] ; do
   getOption
   rv=$?

   case $gDoThis in
      $uiStart)
         gOption=start
         doLampp
         ;;
      $uiStartApache)
         gOption=startapache
         doLampp
         ;;
      $uiStartMySQL)
         gOption=startmysql
         doLampp
         ;;
      $uiStartFTP)
         gOption=startftp
         doLampp
         ;;
      $uiStop)
         gOption=stop
         doLampp
         ;;
      $uiStopApache)
         gOption=stopapache
         doLampp
         ;;
      $uiStopMySQL)
         gOption=stopmysql
         doLampp
         ;;
      $uiStopFTP)
         gOption=stopftp
         doLampp
         ;;
      $uiCancel)
         #~ echo "User cancelled" >&2
         break
         ;;
      $uiQuit)
         break
         ;;
      *)
         echo "Error: unactionable program state" >&2
         exit 1
         ;;
   esac
done
exit


Comments appreciated.
Last edited by meter on 18. February 2010 20:59, edited 1 time in total.
meter
 
Posts: 3
Joined: 18. February 2010 17:52

Re: alternate gui controller

Postby meter » 18. February 2010 20:34

Right ... my boredom continued. Here's a version that reports what processes are running:

Code: Select all
#!/bin/bash

# GUI wrapper for common lampp commands
# Copyright (C) 2010 Mithat Konar
# 2010-02-18

#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

### Constants
uiTitle="LAMPP Control"

uiStart="Start"
uiStop="Stop"

uiStartApache="Start Apache"
uiStartMySQL="Start MySQL"
uiStartFTP="Start ProFTP"

uiStopApache="Stop Apache"
uiStopMySQL="Stop MySQL"
uiStopFTP="Stop ProFTP"

uiCancel="Cancel"
uiQuit="Close $uiTitle"

uiDone="
Done!"

uiRunningProcs="Running processes:"

kDialogHeight=400
kDialogWidth=400

LAMPP_SCRIPT="/opt/lampp/lampp"      # path to actual lampp script.

### Functions

function getOption()
# Show a GUI that asks the user what they want to do.
# Return the resired action in the global 'gDoThis'
# Return the value 1 if the user canceled.
{
   local retval=0
   
   # TODO: do some fancy stuff to check which XAMPP processes are running and
   # show in uiText instead of the message below.
   #~ local uiText="For more options, run '$LAMPP_SCRIPT' in a terminal."
   local uiText="$uiRunningProcs"
   local runningProcs=""
   
   if isFTP; then   
      runningProcs="ProFTPD $runningProcs "
   fi   
   if isMySQL ; then
      runningProcs="MySQL $runningProcs "
   fi
   if isApache ; then
      runningProcs="Apache $runningProcs "
   fi
   if [ "$runningProcs" = "" ] ; then
      runningProcs="(none)"
   fi
   
   uiText="${uiText}\n${runningProcs}"
   
   gDoThis=`zenity --list \
         --height $kDialogHeight \
         --width $kDialogWidth \
         --title "$uiTitle" \
         --text "$uiText" \
         --radiolist \
         --column "" \
         --column "Option" \
         FALSE "$uiStart" \
         FALSE "$uiStartApache" \
         FALSE "$uiStartMySQL" \
         FALSE "$uiStartFTP" \
         FALSE "$uiStop" \
         FALSE "$uiStopApache" \
         FALSE "$uiStopMySQL" \
         FALSE "$uiStopFTP" \
         FALSE "$uiQuit"`
   retval=$?
      
   if [ $retval -eq 1 ]; then      # cancel
      gDoThis=$uiCancel
      return 1
   fi
}

function doLampp()
# Execute the lampp command with argument specified in gOption in its own window.
{
   #~ urxvt -title LAMPP -bg orangered -fg white -e bash -c \
      #~ "$LAMPP_SCRIPT $gOption; echo ; read -sn 1 -p \"Press any key to continue...\""
   
   ($LAMPP_SCRIPT $gOption; echo "$uiDone") | \
    zenity --text-info \
           --title "$uiTitle" \
           --width $kDialogWidth \
           --height $kDialogHeight
}

function isApache()
# Return true iff Apache is running
{
   if testrun /opt/lampp/logs/httpd.pid httpd
      then return 0
      else return 1
   fi
}

function isMySQL()
# Return true iff MySQL is running
{
   if testrun /opt/lampp/var/mysql/`/bin/hostname`.pid mysqld
      then return 0
      else return 1
   fi
}

function isFTP()
# Return true iff ProFTP is running
{
   if testrun /opt/lampp/var/proftpd.pid proftpd
      then return 0
      else return 1
   fi
}

# The following is from the XAMPP for Linux's /opt/lampp/lampp script
function testrun() {
   if test -f $1
   then
      pid=`cat $1`
      if ps ax 2>/dev/null | egrep "^ *$pid.*$2" > /dev/null
      then
         return 0
      else
         rm $1
         return 1
      fi
   else
      return 1
   fi
}

### "MAIN"

rv=0
gOption=""      # used to get user option from GUI

while [ $rv -eq 0 ] ; do
   getOption
   rv=$?

   case $gDoThis in
      $uiStart)
         gOption=start
         doLampp
         ;;
      $uiStartApache)
         gOption=startapache
         doLampp
         ;;
      $uiStartMySQL)
         gOption=startmysql
         doLampp
         ;;
      $uiStartFTP)
         gOption=startftp
         doLampp
         ;;
      $uiStop)
         gOption=stop
         doLampp
         ;;
      $uiStopApache)
         gOption=stopapache
         doLampp
         ;;
      $uiStopMySQL)
         gOption=stopmysql
         doLampp
         ;;
      $uiStopFTP)
         gOption=stopftp
         doLampp
         ;;
      $uiCancel)
         #~ echo "User cancelled" >&2
         break
         ;;
      $uiQuit)
         break
         ;;
      *)
         echo "Error: unactionable program state" >&2
         exit 1
         ;;
   esac
done
exit


Also, I lied. This script doesn't really offer more options than the the packaged python version, but adding more stuff if you need/want it is really simple.

-M
meter
 
Posts: 3
Joined: 18. February 2010 17:52

Re: alternate gui controller

Postby meter » 19. February 2010 13:01

An even more better version, this one using gxmessage and zenity. It uses buttons and is generally more clever than the pure zenity version above. Also, it should work when called as user as well as root (no need to call it with gksudo), so you can place it in /usr/local/bin or even in /home/you/<wherever>.

I'll stop now.

Code: Select all
#!/bin/bash

# GUI wrapper for common lampp commands
# This version uses gxmessage and zenity and is a little more clever.
# Copyright (C) 2010 Mithat Konar
# 2010-02-19

#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

### Constants
uiTitle="XAMPP Control"

uiStart="Start all"      # button text
uiStop="Stop all"      # button text
kStart=100            # integer ID for button
kStop=101            # integer ID for button

uiStartApache="Start Apache"
uiStopApache="Stop Apache"
kStartApache=110
kStopApache=111

uiStartMySQL="Start MySQL"
uiStopMySQL="Stop MySQL"
kStartMySQL=120
kStopMySQL=121

uiStartFTP="Start ProFTP"
uiStopFTP="Stop ProFTP"
kStartFTP=130
kStopFTP=131

uiStartSSL="Enable SSL"
uiStopSSL="Disable SSL"
kStartSSL=140
kStopSSL=141

uiClose=GTK_STOCK_CLOSE
kClose=1

uiRunningProcs="Currently running:"

uiDone="
Done!"

INSTALL_DIR="/opt/lampp"            # path in lampp install dir
LAMPP_SCRIPT="$INSTALL_DIR/lampp"      # path to actual lampp script.

### Functions

function getOption()
# Show a GUI that asks the user what they want to do.
# Return the desired action as an integer value coded as k[Start|Stop]<processname>
# Return the value kClose if the user canceled.
# Above values should be defined globally.
{
   local retval=0
   
   # Figure out which processes are running and concat strings for dialog text
   # and visible buttons.
   local uiText="$uiRunningProcs"   # for assembling dialog text list
   local buttonsStr="$uiStart:$kStart,$uiStop:$kStop"         # for aggregating list of valid buttons
   local runningProcs=""         # for aggregating list of running procs
   
   if isApache ; then
      runningProcs="$runningProcs Apache"
      buttonsStr="$buttonsStr,$uiStopApache:$kStopApache"
   else
      #~ runningProcs="$runningProcs --"
      buttonsStr="$buttonsStr,$uiStartApache:$kStartApache"
   fi

   if isMySQL ; then
      runningProcs="$runningProcs MySQL"
      buttonsStr="$buttonsStr,$uiStopMySQL:$kStopMySQL"
   else
      #~ runningProcs="$runningProcs --"
      buttonsStr="$buttonsStr,$uiStartMySQL:$kStartMySQL"
   fi

   if isFTP; then   
      runningProcs="$runningProcs ProFTPD"
      buttonsStr="$buttonsStr,$uiStopFTP:$kStopFTP"
   else
      #~ runningProcs="$runningProcs --"
      buttonsStr="$buttonsStr,$uiStartFTP:$kStartFTP"
   fi

   if isSSL ; then
      runningProcs="$runningProcs SSL"
      buttonsStr="$buttonsStr,$uiStopSSL:$kStopSSL"
   else
      #~ runningProcs="$runningProcs --"
      buttonsStr="$buttonsStr,$uiStartSSL:$kStartSSL"
   fi

   if [ "$runningProcs" = "" ] ; then
      runningProcs="(none)"
   fi
   
   buttonsStr="$buttonsStr,$uiClose:$kClose"
   
   uiText="${uiText}

${runningProcs}"
   
   gxmessage -title "$uiTitle" \
             -font "bold" \
             -center \
             -default $uiClose \
             -buttons "$buttonsStr" \
             "$uiText"
   
   retval=$?
   return $retval
}

function doLampp()
# Execute the lampp command with argument specified in gOption in its own window.
{
   #~ urxvt -title LAMPP -bg orangered -fg white -e bash -c \
      #~ "$LAMPP_SCRIPT $gOption; echo ; read -sn 1 -p \"Press any key to continue...\""
   
   ($LAMPP_SCRIPT $gOption; echo "$uiDone") | \
    zenity --text-info \
           --title "$uiTitle"
}

function isApache()
# Return true iff Apache is running
{
   if testrun $INSTALL_DIR/logs/httpd.pid httpd
      then return 0
      else return 1
   fi
}

function isMySQL()
# Return true iff MySQL is running
{
   if testrun $INSTALL_DIR/var/mysql/`/bin/hostname`.pid mysqld
      then return 0
      else return 1
   fi
}

function isSSL()
# Return true iff SSL is running
{
   if testrun $INSTALL_DIR/logs/httpd.pid httpd ; then
      if test -f $INSTALL_DIR/etc/lampp/startssl ; then
         return 0
      fi      
   fi
   return 1
}

function isFTP()
# Return true iff ProFTP is running
{
   if testrun $INSTALL_DIR/var/proftpd.pid proftpd
      then return 0
      else return 1
   fi
}

# The following is from the XAMPP for Linux's /opt/lampp/lampp script
function testrun() {
   if test -f $1
   then
      pid=`cat $1`
      if ps ax 2>/dev/null | egrep "^ *$pid.*$2" > /dev/null
      then
         return 0
      else
         rm $1
         return 1
      fi
   else
      return 1
   fi
}

### "MAIN"

# if user is not root then run this script as root
if [[ $EUID -ne 0 ]]; then
   gksudo $0 &
   exit
fi

rv=0
while [ $rv -ne $kClose ] ; do
   getOption
   rv=$?

   case $rv in
      $kStart)
         gOption=start
         doLampp
         ;;
      $kStartApache)
         gOption=startapache
         doLampp
         ;;
      $kStartMySQL)
         gOption=startmysql
         doLampp
         ;;
      $kStartSSL)
         gOption=startssl
         doLampp
         ;;
      $kStartFTP)
         gOption=startftp
         doLampp
         ;;
      $kStop)
         gOption=stop
         doLampp
         ;;
      $kStopApache)
         gOption=stopapache
         doLampp
         ;;
      $kStopMySQL)
         gOption=stopmysql
         doLampp
         ;;
      $kStopSSL)
         gOption=stopssl
         doLampp
         ;;
      $kStopFTP)
         gOption=stopftp
         doLampp
         ;;
      $kClose)
         ;;
      *)
         echo "Error: unactionable program state" >&2
         exit 1
         ;;
   esac
done
exit


screenshots:
Image
Image

-M

edit: bugfix
edit: screenshots
meter
 
Posts: 3
Joined: 18. February 2010 17:52

Re: alternate gui controller

Postby al! » 19. April 2010 00:38

Thank you!!
p. s. before running this script be sure "gxmessage" is installed on your system
al!
 
Posts: 3
Joined: 08. April 2009 00:28


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 4 guests