0

I am using an old machine as a webserver to host a static, code-generated site (the site serves HTML documentation, JS, PDFs and images). The old machine, along with development PC are on a home network, and connected to a single modem.

General advice that addresses the questions below would be appreciated:

1. How can the bash script below be extended deploy to the old machine on my network?

2. Do any iptables rules need to created? (especially wrt. to #3)

3. How can the script be extended in future to be used in a production environment and/or allow access to the site outside the home network?


#! /bin/bash
# deploy.sh

# Note: This script must be run as root or sudo, assumes the user 
# $WEBSERVER is created, and that thttpd is installed.

DEVELOP_ENV="/home/me/www"             # localhost www dir
STAGING_ENV="half_broken_server/www"   # target host www dir to deploy to
WEBSERVER="thttpd"                     # webserver user

function usage {
    printf "deploy [options...] [STAGING|DEVELOP]\n"
}

if [[ "$1" == "STAGING" ]]; then
    # prompt before deploying to staging
    read -p "Deploy to staging server?" -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo "Abort"
        exit 1
    fi
    echo "TODO: Ask StackExchange for help with this part"
elif [[ "$1" == "DEVELOP" ]]; then
    if [ -d dist ]; then
        # make www directory if it does not exist
        if [ ! -d `dirname $DEV_ENV` ]; then 
           mkdir -p $DEVELOP_ENV
        fi
        # copy all files to be served from dist
        cp -rf dist/* $DEVELOP_ENV 
    fi
    # grant read-only perms to local network users
    chmod -R 744 $DEVELOP_ENV 
    # restart the thttpd webserver process (if it is running)
    killall thttpd         
    $WEBSERVER -u $WEBSERVER -d $DEVELOP_ENV

    echo "Deployment sucessful!"
else
    usage
fi

The bash script copies files from a dir called dist to one of DEVELOP or STAGING environments so that on a local network content will be served from this dir and accessed at myuser@hostname or just hostname/ per /etc/host config.

Additional Details

  • The files being served are entirely code-generated (HTML/CSS/JS) from C, Lua and Bash, and Make and are constantly changing during builds

  • The webserver is thttpd, running on a base installation of Debian Wheezy

  • Preferred: standard Unix utilities (e.g. scp, rsync) over other deployment frameworks (e.g. Fabric, Chef, Vagrant) or standard libraries from one of the languages mentioned above

  • The webserver is for personal project work, and is not expected to be used by others

GoofyBall
  • 101
  • 1
  • Have you considered using git? – TheFiddlerWins Jan 06 '16 at 20:35
  • @TheFiddlerWins no, but I am open to ideas like this. Could you please elaborate? – GoofyBall Jan 06 '16 at 20:36
  • Were you thinking of something like this? https://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html – GoofyBall Jan 06 '16 at 20:39
  • More creating a repository with 3 (or more) branches, one for dev, one for staging and one for prod etc. This would let you promote changes, back out issues etc. Git is very thrifty (similar to Rsync that's resyncable except git will also track what's changed when) – TheFiddlerWins Jan 06 '16 at 20:45

0 Answers0