-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated setup script to give more friendly handling of different &
unsupported platforms.
- Loading branch information
Showing
1 changed file
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
|
||
# project vars | ||
hostName=ping.example.com | ||
httpRoot=$(pwd)/httpdocs | ||
temp=$(pwd)/tmp | ||
|
||
# platform vars | ||
platform=$(uname | tr [:upper:] [:lower:]) | ||
|
||
function TODO { | ||
log TODO $@ | ||
} | ||
|
@@ -12,6 +18,15 @@ function log { | |
echo "# $@" | ||
} | ||
|
||
if [[ "$platform" == "darwin" ]]; then | ||
apacheRoot=/private/etc/apache2 | ||
elif [[ "$platform" == "linux" ]]; then | ||
apacheRoot=/etc/apache2 | ||
else | ||
log "Your platform ($platform) is not supported by this script. Please follow the manual setup instructions in README.md" | ||
exit 1 | ||
fi | ||
|
||
function mysql_create_db { | ||
local db_name=$1 | ||
local db_username=$2 | ||
|
@@ -31,23 +46,25 @@ function makedir { | |
} | ||
|
||
function confirm { | ||
if ! optional $@; then | ||
log "Please follow the manual setup steps in the README file." | ||
exit 1 | ||
fi | ||
} | ||
|
||
function optional { | ||
local prompt=$@ | ||
local confirmed=false | ||
while ! $confirmed; do | ||
while true; do | ||
read -p "# $prompt [Y/n] " r | ||
if [[ $r == 'y' || $r == 'Y' || $r == '' ]]; then | ||
confirmed=true | ||
return 0 | ||
elif [[ $r == 'n' || $r == 'N' ]]; then | ||
log "Please follow the manual setup steps in the README file." | ||
exit 1 | ||
return 1 | ||
fi | ||
done | ||
} | ||
|
||
log "Starting ping setup..." | ||
|
||
confirm This setup script is currently configured only for linux with apache2. Does this match your system? | ||
|
||
makedir $temp | ||
|
||
log "Updating submodules..." | ||
|
@@ -74,11 +91,11 @@ sudo chown www-data application/cache | |
makedir application/logs | ||
sudo chown www-data application/logs | ||
|
||
log "Setting up Apache site..." | ||
apacheRoot=/etc/apache2 | ||
siteAvailable=$apacheRoot/sites-available/pingapp | ||
siteAvailableTmp=$temp/site-enabled | ||
cat > $siteAvailableTmp << EOF | ||
if optional "Do you want to set up apache sites at $apacheRoot?"; then | ||
log "Setting up Apache site..." | ||
siteAvailable=$apacheRoot/sites-available/pingapp | ||
siteAvailableTmp=$temp/site-enabled | ||
cat > $siteAvailableTmp << EOF | ||
<VirtualHost *:80> | ||
ServerAdmin [email protected] | ||
DocumentRoot "$httpRoot" | ||
|
@@ -90,9 +107,12 @@ cat > $siteAvailableTmp << EOF | |
</Directory> | ||
</VirtualHost> | ||
EOF | ||
log "Configuring apache; you may need to enter your user password..." | ||
sudo mv $siteAvailableTmp $siteAvailable | ||
a2ensite pingapp | ||
log "Configuring apache; you may need to enter your user password..." | ||
sudo mv $siteAvailableTmp $siteAvailable | ||
a2ensite pingapp | ||
else | ||
log "Please set up your apache site manually to point $hostName to $httpRoot." | ||
fi | ||
|
||
log "Setting up host redirect to $hostName..." | ||
hostFile=/etc/hosts | ||
|
@@ -104,7 +124,11 @@ log "Enabling apache2 mod_rewrite..." | |
sudo a2enmod rewrite | ||
|
||
log "Restarting apache; this may require your user password..." | ||
sudo service apache2 restart | ||
if [[ platform == "darwin" ]]; then | ||
sudo apache2ctl -k restart | ||
else | ||
sudo service apache2 restart | ||
fi | ||
|
||
log "Making your user directory executable to allow apache2 to serve files..." | ||
chmod 751 ~ | ||
|