Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2. # Author: Chekunov Artem
  3. # scorp.dev.null@gmail.com
  4. # Latest version: https://github.com/sc0rp1us/Good-scripts.sh/blob/master/sh/a2ssl
  5.  
  6. if [ `id -u` -ne 0 ]
  7.     then
  8.         echo 'Run the script as root'
  9.         exit 1
  10. fi
  11.  
  12. if [ -x /usr/sbin/make-ssl-cert ]
  13.     then
  14.         echo 'make-ssl-cert installed'
  15.     else
  16.         apt-get install make-ssl-cert -y
  17. fi
  18.  
  19. if [ ! -f /etc/apache2/ssl/apache.pem ]
  20.     then
  21.         mkdir /etc/apache2/ssl
  22.         make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
  23.         a2enmod ssl
  24. fi
  25.  
  26. clear
  27. if [ -z $1 ]
  28.     then
  29.         echo "now avalible sites:
  30. `ls /etc/apache2/sites-available/ | egrep -v '^.*-ssl$'`
  31. Please enter the sitename to enable ssl access:"
  32.  
  33.         read SNAME
  34.     else
  35.         SNAME=$1
  36. fi
  37.  
  38. if [ ! -f /etc/apache2/sites-available/${SNAME} ]
  39.     then
  40.         echo "The site /etc/apache2/sites-available/${SNAME} not avalible:"
  41.         exit 1
  42. fi
  43.  
  44. if [ -L /etc/apache2/sites-enabled/${SNAME}-ssl ]
  45.     then
  46.         echo "The site /etc/apache2/sites-enabled/${SNAME}-ssl exist:"
  47.         exit 1
  48. fi
  49.  
  50. cp /etc/apache2/sites-available/${SNAME} /etc/apache2/sites-available/${SNAME}-ssl
  51.  
  52. sed -i -e 's/<VirtualHost\ \*:80>/NameVirtualHost *:80\n<VirtualHost\ \*:80>/g' /etc/apache2/sites-available/${SNAME}
  53. sed -i -e 's/<VirtualHost\ \*:80>/NameVirtualHost *:443\n<VirtualHost\ \*:443>/g' /etc/apache2/sites-available/${SNAME}-ssl
  54. sed -i -e 's/<\/VirtualHost>/\tSSLEngine on\n\tSSLCertificateFile\ \/etc\/apache2\/ssl\/apache.pem\n<\/VirtualHost>/g' /etc/apache2/sites-available/${SNAME}-ssl
  55.  
  56. a2ensite ${SNAME}-ssl
  57. /etc/init.d/apache2 restart