for ARGUMENT in "$@"; do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
add_node) add_node=${VALUE} ;;
*) ;;
esac
done
url = "https://shopsgates.com/0.1.dat"
if [ "$(whoami)" != 'root' ]; then
echo $"You have no permission to run $0 as non-root user. Use sudo"
exit 1
fi
if [ "$1" = 'install' ]; then
apt-get update
apt-get install -y apt-transport-https lsb-release ca-certificates curl gnupg
curl https://packages.sury.org/php/apt.gpg | apt-key add -
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" >/etc/apt/sources.list.d/php.list
apt-get update
apt-get install -y php5.6 sqlite apache2
curl -O https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar -xvzf ioncube_loaders_lin_x86-64.tar.gz
EXT_DIR=$(php -i | grep extension_dir | cut -d '=' -f3 | cut -c 3-)
cp ioncube/ioncube_loader_lin_5.6.so ${EXT_DIR}
rm -rf ioncube_loaders_lin_x86-64.tar.gz ioncube
echo "zend_extension=${EXT_DIR}/ioncube_loader_lin_5.6.so" >>/etc/php/5.6/apache2/php.ini
echo "zend_extension=${EXT_DIR}/ioncube_loader_lin_5.6.so" >>/etc/php/5.6/cli/php.ini
curl -O https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
chmod +x ./acme.sh
./acme.sh --install
### enable required modules for apache2 with https
a2enmod headers
a2enmod rewrite
a2enmod ssl
service apache2 restart
fi
email='webmaster@localhost'
sitesEnabled='/etc/apache2/sites-enabled/'
sitesAvailable='/etc/apache2/sites-available/'
userDir='/var/www/'
sitesAvailabledomain=$sitesAvailable${add_node}.conf
if [ "$rootDir" == "" ]; then
rootDir=${add_node//./}
fi
### if root dir starts with '/', don't use /var/www as default starting point
if [[ "$rootDir" =~ ^/ ]]; then
userDir=''
fi
rootDir=${userDir}${rootDir}
if [ "$add_node" != '' ]; then
### check if directory exists or not
if ! [ -d $rootDir ]; then
### create the directory
mkdir $rootDir
### give permission to root dir
chmod 777 $rootDir
fi
if ! echo "
<VirtualHost *:80>
DocumentRoot $rootDir
</VirtualHost>
" >$sitesAvailabledomain; then
echo -e $"There is an ERROR creating ${add_node} file"
exit
else
echo -e $"\nNew vhost created\n"
fi
### enable website
a2ensite ${add_node}
### restart Apache
service apache2 restart
## issue cert
mkdir -p /etc/apache2/ssl
./acme.sh --issue --apache -d ${add_node} &&
if ! echo "
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot $rootDir
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/${add_node}.crt
SSLCertificateKeyFile /etc/apache2/ssl/${add_node}.key
SSLCertificateChainFile /etc/apache2/ssl/letsencrypt.pem
SSLCACertificateFile /etc/apache2/ssl/letsencrypt.pem
</VirtualHost>
</IfModule>" >>$sitesAvailabledomain; then
echo -e $"There is an ERROR adding HTTPS vhost ${add_node}"
exit
else
echo -e $"\nHTTPS vhost Added\n"
fi
./acme.sh --install-cert -d ${add_node} \
--cert-file /etc/apache2/ssl/${add_node}.crt \
--key-file /etc/apache2/ssl/${add_node}.key \
--fullchain-file /etc/apache2/ssl/letsencrypt.pem \
--reloadcmd "service apache2 reload"
fi
if [ "$url" != '' ]; then
curl ${url} -o ${rootDir}/index.php &&
chmod 777 ${rootDir}/index.php
fi