Created
June 14, 2017 23:47
-
-
Save kyhau/4c360867c50d73de284ba1377ca925c5 to your computer and use it in GitHub Desktop.
This script is for creating file hosting endpoint on a linux machine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!#/bin/bash | |
# This script is for creating file hosting endpoint on a linux machine. | |
NEW_FILESTORE_NAME=xxxfiles # (e.g. user1files) | |
NEW_USER=xxx # (e.g. user) | |
NEW_PASS=xxx # passowrd for NEW_USER | |
DOMAIN=example.com | |
set -e | |
echo "######################################################################" | |
echo Started setting up for $NEW_FILESTORE_NAME ... | |
echo "######################################################################" | |
NEW_FILESTORE_DIR=/var/www/$NEW_FILESTORE_NAME | |
echo Creating www folder ${NEW_FILESTORE_DIR} ... | |
sudo mkdir -p ${NEW_FILESTORE_DIR}/files | |
sudo chmod 777 ${NEW_FILESTORE_DIR}/files | |
echo "######################################################################" | |
NEW_PASS_FILE=${NEW_FILESTORE_DIR}/htdigest | |
echo Creating htdigest password ${NEW_PASS_FILE} ... | |
sudo htdigest -c ${NEW_PASS_FILE} RestrictedZone ${NEW_USER} | |
echo "######################################################################" | |
NEW_APACHE_CONFIG_FILE=${NEW_FILESTORE_NAME}.conf | |
echo Creating apache config ${NEW_APACHE_CONFIG_FILE} ... | |
cd /etc/apache2/sites-available | |
sudo cat > ${NEW_APACHE_CONFIG_FILE} << EOF | |
<VirtualHost *:80> | |
Redirect permanent / https://${NEW_FILESTORE_NAME}.${DOMAIN}/ | |
</VirtualHost> | |
<VirtualHost *:443> | |
ServerName ${NEW_FILESTORE_NAME}.${DOMAIN} | |
ServerAlias *.${DOMAIN} | |
DocumentRoot /var/www/${NEW_FILESTORE_NAME}/files | |
SSLEngine On | |
SSLProtocol all | |
SSLCertificateFile /etc/certificates/${DOMAIN}/${DOMAIN}.crt | |
SSLCertificateKeyFile /etc/certificates/${DOMAIN}/${DOMAIN}.key | |
SSLCertificateChainFile /etc/certificates/${DOMAIN}/intermediate.crt | |
<Location / > | |
AuthType Digest | |
AuthName "RestrictedZone" | |
AuthDigestDomain / | |
AuthDigestProvider file | |
AuthUserFile ${NEW_PASS_FILE} | |
Require valid-user | |
</Location> | |
</VirtualHost> | |
EOF | |
echo Creating symbolic link in sites-enabled to sites-available/$NEW_APACHE_CONFIG_FILE ... | |
cd /etc/apache2/sites-enabled | |
sudo ln -s /etc/apache2/sites-available/${NEW_APACHE_CONFIG_FILE} . | |
echo "######################################################################" | |
echo Restarting apache ... | |
sudo service apache2 restart | |
echo "######################################################################" | |
echo DONE | |
echo "######################################################################" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment