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.