Okay, this is a simple script, but should do what you want. If you use LMDE, delete the two notify-send commands as those are not supported on LMDE (these just pop-up a small feedback balloon to you, showing what it is doing). Might also not work on Linux Mint 9, please test. The rest of the script will do what you want without these two lines
Start Gedit (Text Editor) from the Menu, and copy the following text into it:
- Code: Select all
#!/bin/bash
# check running as root
if [[ $(id -un) != root ]]; then
zenity --error --text="$0 must be run as effective root user." --title=$(basename $0)
exit 1
fi
# toggle LAMPP
if [[ -f /var/run/lampp-toggle ]]; then
notify-send --expire-time=3 $(basename $0) "Stopping LAMPP"
/opt/lampp/lampp stop
rm -f /var/run/lampp-toggle
else
notify-send --expire-time=3 $(basename $0) "Starting LAMPP"
/opt/lampp/lampp start
touch /var/run/lampp-toggle
fi
Save the file as "lampp-toggle" at a location of your choosing (for example to your home folder), then close it. Now right-click the file > Properties > Permissions, and mark "Allow executing file as a program".
You have to start the script with "gksudo ~/lampp-toggle" or "sudo ~/lampp-toggle". To make this easier, you can right-click the Menu > Edit menu and add a menu item for this.
Now, to avoid having to type a password for this each time, you can change that the script can be run with sudo without requiring a password. Run the following command to start editing:
- Code: Select all
sudo EDITOR=nano visudo
Then add a line at the end:
- Code: Select all
sagirfahmid3 ALL=NOPASSWD:/home/sagirfahmid3/lampp-toggle
Where you replace, twice, sagirfahmid3 with your username. And make sure the path at the end then matches the location of where you saved the script. Save the file with Ctrl+O (letter O) and exit with Ctrl+X. Now starting "gksudo ~/lampp-toggle" or "sudo ~/lampp-toggle" will do so without asking for a password.
The only caveat of this script is that if you stop or start LAMPP without this script, and then use the script--it doesn't know what you did, so it might do the other action than you want (trying to start, while you want it to stop and vice versa). Just run it another time to get it to do what you wanted.
Edit: corrected how to edit the /etc/sudoers file.