configshell 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. c_bold="\033[1m";
  3. c_norm="\033[0m";
  4. help(){
  5. if [[ "$1" != "" ]];then
  6. case "$1" in
  7. addsite)
  8. echo "Addsite Usage:";
  9. echo "addsite <name> <host> [<path>] - adds a site to apache and enables it";
  10. ;;
  11. help)
  12. echo "Help Usage:";
  13. echo "help - displays this message";
  14. echo "help <command> - displays help for a command";
  15. ;;
  16. *)
  17. help;
  18. esac;
  19. else
  20. echo "Commands:";
  21. echo " help";
  22. echo " addsite";
  23. fi;
  24. }
  25. addsite(){
  26. if [ -f /etc/apache2/sites-available/$1.conf ];then
  27. echo "Site already exists";
  28. else
  29. if [[ "$3" != "" ]];then
  30. path="$3";
  31. else
  32. path="/var/www/$1";
  33. fi;
  34. mkdir -p "$path";
  35. echo "<VirtualHost *:80>
  36. ServerName $2
  37. DocumentRoot $path
  38. <Directory $path>
  39. Options +ExecCGI +Indexes +FollowSymLinks +MultiViews
  40. AllowOverride All
  41. RewriteEngine On
  42. Order allow,deny
  43. allow from all
  44. </Directory>
  45. ErrorLog ${APACHE_LOG_DIR}/error.log
  46. CustomLog ${APACHE_LOG_DIR}/access.log combined
  47. ServerAdmin [email protected]
  48. </VirtualHost>" > /etc/apache2/sites-available/$1.conf;
  49. echo "Created site $1 ($2) at $path";
  50. a2ensite $1;
  51. sudo service apache2 reload;
  52. fi;
  53. }
  54. while true; do
  55. if [[ "$@" == "" ]];then
  56. echo -ne "$c_bold$(whoami)@$(pwd)>$c_norm ";
  57. read input;
  58. else
  59. input="$@";
  60. fi;
  61. case "$input" in
  62. *)
  63. eval "$input";
  64. esac;
  65. if [[ "$@" != "" ]];then
  66. exit;
  67. fi;
  68. done;