|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Constants |
| 4 | + |
| 5 | +VERSION="1.0.0" |
| 6 | + |
| 7 | +# Install Lamp Stack |
| 8 | + |
| 9 | +function install_lamp() |
| 10 | +{ |
| 11 | + echo ' -> Installing Lamp Stack'; |
| 12 | + sudo apt-get install lamp-server^ &> /dev/null |
| 13 | + echo ' -> Lamp Stack Installed!'; |
| 14 | +} |
| 15 | + |
| 16 | +# Enable Mod Rewrite |
| 17 | + |
| 18 | +function enable_mod_rewrite() |
| 19 | +{ |
| 20 | + echo ' -> Enabling Mod Rewrite'; |
| 21 | + sudo a2enmod rewrite &> /dev/null |
| 22 | + echo ' -> Mod Rewrite Enabled!'; |
| 23 | +} |
| 24 | + |
| 25 | +# Secure MySQL Installation |
| 26 | + |
| 27 | +function secure_mysql() |
| 28 | +{ |
| 29 | + echo ' -> Securing MySQL Installation'; |
| 30 | + mysql_secure_installation &> /dev/null |
| 31 | + echo ' -> MySQL Installation Secured!'; |
| 32 | +} |
| 33 | + |
| 34 | +# Install PHPMyAdmin |
| 35 | + |
| 36 | +function install_phpmyadmin() |
| 37 | +{ |
| 38 | + echo ' -> Installing PHPMyAdmin'; |
| 39 | + sudo apt-get install phpmyadmin |
| 40 | + sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf |
| 41 | + sudo apachectl restart &> /dev/null |
| 42 | + echo ' -> PHPMyAdmin Installed!'; |
| 43 | +} |
| 44 | + |
| 45 | +# Install FTP Package |
| 46 | + |
| 47 | +function install_ftp() |
| 48 | +{ |
| 49 | + echo ' -> Installing FTP'; |
| 50 | + sudo apt-get install proftp &> /dev/null |
| 51 | + echo ' -> FTP Installed!'; |
| 52 | +} |
| 53 | + |
| 54 | +# Update Server |
| 55 | + |
| 56 | +function update_server() |
| 57 | +{ |
| 58 | + echo ' -> Updating Server'; |
| 59 | + sudo aptitude update &> /dev/null && sudo aptitude safe-upgrade &> /dev/null |
| 60 | + echo ' -> Update Complete!'; |
| 61 | +} |
| 62 | + |
| 63 | +# Change ownership of site directory |
| 64 | + |
| 65 | +function change_site_ownership() |
| 66 | +{ |
| 67 | + echo ' -> Changing ownership of site directory'; |
| 68 | + sudo chown www-data:www-data /var/www |
| 69 | + echo ' -> Ownership Changed!'; |
| 70 | +} |
| 71 | + |
| 72 | +# Configure Firewall |
| 73 | + |
| 74 | +function configure_firewall() |
| 75 | +{ |
| 76 | + echo ' -> Configuring Firewall'; |
| 77 | + echo ' -> Setting defaults to deny'; |
| 78 | + sudo ufw default deny |
| 79 | + echo ' -> Enabling ufw'; |
| 80 | + sudo ufw enable |
| 81 | + echo ' -> Allow SSH Traffic'; |
| 82 | + sudo ufw allow 22 |
| 83 | + echo ' -> Allow Regular Traffic'; |
| 84 | + sudo ufw allow 80 |
| 85 | + echo ' -> Allow HTTPS Traffic'; |
| 86 | + sudo ufw allow 443 |
| 87 | + echo ' -> Firewall Configured!'; |
| 88 | +} |
| 89 | + |
| 90 | +# Set Permissions |
| 91 | +function set_permissions() |
| 92 | +{ |
| 93 | + echo ' -> Setting Permissions'; |
| 94 | + sudo usermod -a -G www-data mike |
| 95 | + sudo chgrp -R www-data /var/www |
| 96 | + sudo chmod -R g+w /var/www |
| 97 | + sudo find /var/www -type d -exec chmod 2775 {} \; |
| 98 | + sudo find /var/www -type f -exec chmod ug+rw {} \; |
| 99 | + echo ' -> Permissions Set!'; |
| 100 | +} |
| 101 | + |
| 102 | +function usage() { |
| 103 | + cat <<-EOF |
| 104 | +
|
| 105 | + Usage: deploy [options] <env> [command] |
| 106 | +
|
| 107 | + Options: |
| 108 | +
|
| 109 | + -C, --chdir <path> change the working directory to <path> |
| 110 | + -c, --config <path> set config path. defaults to ./deploy.conf |
| 111 | + -T, --no-tests ignore test hook |
| 112 | + -V, --version output program version |
| 113 | + -h, --help output help information |
| 114 | +
|
| 115 | + Commands: |
| 116 | +
|
| 117 | + setup run remote setup commands |
| 118 | + update update deploy to the latest release |
| 119 | + revert [n] revert to [n]th last deployment or 1 |
| 120 | + config [key] output config file or [key] |
| 121 | + curr[ent] output current release commit |
| 122 | + prev[ious] output previous release commit |
| 123 | + exec|run <cmd> execute the given <cmd> |
| 124 | + console open an ssh session to the host |
| 125 | + list list previous deploy commits |
| 126 | + [ref] deploy to [ref], the 'ref' setting, or latest tag |
| 127 | +
|
| 128 | +EOF |
| 129 | +} |
| 130 | + |
| 131 | +# |
| 132 | +# Output version. |
| 133 | +# |
| 134 | + |
| 135 | +function version |
| 136 | +{ |
| 137 | + echo $VERSION |
| 138 | +} |
| 139 | + |
| 140 | +# |
| 141 | +# Log <msg>. |
| 142 | +# |
| 143 | + |
| 144 | +function log |
| 145 | +{ |
| 146 | + echo " > $@" |
| 147 | +} |
| 148 | + |
| 149 | + |
| 150 | +# |
| 151 | +# Basic Web Server |
| 152 | +# |
| 153 | + |
| 154 | +#install_lamp |
| 155 | +#enable_mod_rewrite |
| 156 | +#secure_mysql |
| 157 | +#install_phpmyadmin |
| 158 | +#update_server |
| 159 | + |
| 160 | +# |
| 161 | +# Configure Web Server |
| 162 | +# |
| 163 | + |
| 164 | +#change_site_ownership |
| 165 | + |
| 166 | +# |
| 167 | +# Configure Firewall |
| 168 | +# |
| 169 | + |
| 170 | +configure_firewall |
| 171 | + |
| 172 | +# |
| 173 | +# Set Permissions |
| 174 | +# |
| 175 | + |
| 176 | +set_permissions |
0 commit comments