Skip to content

Instantly share code, notes, and snippets.

@debxp
Last active November 3, 2019 15:53
Show Gist options
  • Save debxp/f9084a9cc1016942bbd4cf48cad2829d to your computer and use it in GitHub Desktop.
Save debxp/f9084a9cc1016942bbd4cf48cad2829d to your computer and use it in GitHub Desktop.
Xampp CLI Menu
Para criar páginas e projetos do Xampp na sua própria pasta pessoal:
1 - Na sua pasta pessoal, crie uma pasta chamada "public_html":
mkdir ~/public_html
2 - Crie um link simbólico da sua pasta "~/public_html" na pasta "/opt/lampp/htdocs/seu_nome_de_usuario":
sudo ln -s ~/public_html /opt/lampp/htdocs/$USER
3 - Inicie (ou reinicie) o Apache e entre com a URL abaixo no navegador para testar:
localhost/seu_nome_de_usuario
#!/usr/bin/env bash
# ---------------------------------------------------------------
# Author : Blau Araujo <debxp.linux@gmail.com>
# Last rev. : Nov 3, 2019
# Descripttion : A CLI replacement for Xampp's Control Panel
# Optional : Add this to your aliases...
# : alias xamppmenu="sudo ~/your/bin/path/xamppmenu"
# ---------------------------------------------------------------
# Check if user is root/sudo...
if [[ $EUID -ne 0 ]]; then
echo -e "\nUse 'sudo' to run this script!\n" 1>&2
exit 1
fi
# Messages...
msg_off="Off"
msg_running="Running"
msg_not_running="Stopped"
msg_start="Run"
msg_stop="Stop"
msg_prompt="Type your option:"
msg_quit="Quit"
msg_exit="Quiting..."
# Messages pt-BR...
# msg_off="Desligado"
# msg_running="Em execução"
# msg_not_running="Parado"
#
# msg_start="Executar"
# msg_stop="Parar"
#
# msg_prompt="Tecle a sua opção:"
# msg_quit="Sair"
# msg_exit="Saindo..."
# About Xampp...
xampp_root="/opt/lampp"
xampp_version=$(grep "base_stack_version" $xampp_root/properties.ini)
xampp_command=$xampp_root/xampp
# Apache pid data...
apache_file=$xampp_root/logs/httpd.pid
apache_proc=httpd
# MySQL pid data...
mysql_file=$xampp_root/var/mysql/$(hostname).pid
mysql_proc=mysqld
# ProFTPD pid data...
proftpd_file1=$xampp_root/etc/xampp/startftp
proftpd_file2=$xampp_root/var/proftpd.pid
proftpd_proc=proftpd
# Check Xampp component pid and process.
# Arguments: $1=pid_file and $2=ps_search
# Returns : 0=found or 1=not found
check_status() {
if test -f $1; then
pid=$(cat $1)
if [ "x$pid" != "x" ] && ps ax 2>/dev/null | egrep "^ *$pid.*$2" > /dev/null; then
return 0
else
return 1
fi
else
return 1
fi
}
# Perform Apache status check...
check_apache() {
if check_status $apache_file $apache_proc; then
apache_status=$msg_running
action_apache="$msg_stop Apache"
command_apache="$xampp_command stopapache"
else
apache_status=$msg_not_running
action_apache="$msg_start Apache"
command_apache="$xampp_command startapache"
fi
}
# Perform MySQL status check...
check_mysql() {
if check_status $mysql_file $mysql_proc; then
mysql_status=$msg_running
action_mysql="$msg_stop MySQL"
command_mysql="$xampp_command stopmysql"
else
mysql_status=$msg_not_running
action_mysql="$msg_start MySQL"
command_mysql="$xampp_command startmysql"
fi
}
# Perform ProFTPD status check...
check_proftpd() {
if [[ -f $proftpd_file1 ]]; then
if check_status $proftpd_file2 $proftpd_proc; then
proftpd_status=$msg_running
action_proftpd="$msg_stop ProFTPD"
command_proftpd="$xampp_command stopftp"
else
proftpd_status=$msg_not_running
action_proftpd="$msg_start ProFTPD"
command_proftpd="$xampp_command startftp"
fi
else
proftpd_status=$msg_off
action_proftpd="$msg_start ProFTPD"
command_proftpd="$xampp_command startftp"
fi
}
# Main loop...
while true; do
clear
check_apache
check_mysql
check_proftpd
echo "
Xampp ${xampp_version#*=} - CLI Menu
1. Apache : $apache_status ( $action_apache )
2. MySQL : $mysql_status ( $action_mysql )
3. ProFTPD: $proftpd_status ( $action_proftpd )
Q. $msg_quit
"
read -N 1 -p " $msg_prompt " action
case $action in
1) echo -e "\n"; $command_apache && echo ""; sleep 2;;
2) echo -e "\n"; $command_mysql && echo ""; sleep 2;;
3) echo -e "\n"; $command_proftpd && echo ""; sleep 2;;
[qQ]) break;;
*) ;;
esac
done
# Quit...
echo -e "\n\n $msg_exit\n"
exit 0
[Desktop Entry]
Encoding=UTF-8
Name=Xampp CLI Menu
Comment=Start and Stop XAMPP services
Exec=sh -c "sudo ~/bin/xamppmenu"
Icon=/home/seu_nome_de_usuario/Imagens/icons/xampp.svg
Categories=Development
Type=Application
Terminal=true
#
# Link para baixar a imagem do atalho:
# https://www.apachefriends.org/images/xampp-logo-ac950edf.svg
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment