summaryrefslogtreecommitdiff
path: root/deploy.sh
blob: ad31a42101b5140a22c40235338b89be24778b38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

SITE_NAME="codegolf"
CONF_NAME="${SITE_NAME}.nginx.conf"

WWW_DIR="/var/www/${SITE_NAME}"

ENABLED_DIR="/etc/nginx/sites-enabled"
AVAILABLE_DIR="/etc/nginx/sites-available"

function deploy_site {
    sudo mkdir -p $WWW_DIR
    sudo cp -r "static/." $WWW_DIR
    sudo cp $CONF_NAME $AVAILABLE_DIR
}

function enable_site {

    local AVAILABLE_CONF="$AVAILABLE_DIR/$CONF_NAME"
    local ENABLED_CONF="$ENABLED_DIR/$CONF_NAME"

    # enable site by linking available conf into enabled directory
    if [[ -h $ENABLED_CONF ]]; then
        sudo rm $ENABLED_CONF
        sudo ln -s $AVAILABLE_CONF $ENABLED_CONF
    elif [[ ! -e $ENABLED_CONF ]]; then
        sudo ln -s $AVAILABLE_CONF $ENABLED_CONF
    else
        echo "$ENABLED_CONF already exists and is not a symlink"
        exit 1
    fi
    

    # reload the nginx config
    sudo nginx -s reload
}

deploy_site
enable_site