create-site 635 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. if [[ $EUID -ne 0 ]]; then # Force root
  3. exec sudo $0 "$@";
  4. fi;
  5. if [[ "$1" == "" ]];then
  6. echo "Usage: $0 site [target]";
  7. exit 1;
  8. fi;
  9. site=$(basename $1);
  10. ROOT=$(dirname $(realpath $0));
  11. if [[ "$2" == "" ]];then
  12. echo "Creating site directory";
  13. mkdir -p /var/www/$site;
  14. else
  15. echo "Creating site symlink";
  16. ln -s "$2" "/var/www/$site";
  17. fi;
  18. if [[ ! -f /etc/apache2/sites-available/$site.conf ]]; then
  19. echo "Creating site config";
  20. cp $ROOT/default.site.conf /etc/apache2/sites-available/$site.conf;
  21. sed -i "s/__SITE__/$site/" /etc/apache2/sites-available/$site.conf;
  22. fi;
  23. a2ensite $site;
  24. service apache2 reload;