-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpeppermint-deploy.sh
99 lines (78 loc) · 2.8 KB
/
peppermint-deploy.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -e
trap "cleanup $? $LINENO" EXIT
## Linode/SSH security settings
#<UDF name="user_name" label="The limited sudo user to be created for the Linode: *No Capital Letters or Special Characters*">
#<UDF name="disable_root" label="Disable root access over SSH?" oneOf="Yes,No" default="No">
## Domain Settings
#<UDF name="token_password" label="Your Linode API token. This is needed to create your server's DNS records" default="">
#<UDF name="subdomain" label="Subdomain" example="The subdomain for the DNS record: www (Requires Domain)" default="">
#<UDF name="domain" label="Domain" example="The domain for the DNS record: example.com (Requires API token)" default="">
## Peppermint setup
#<UDF name="soa_email_address" label="Email address (for the Let's Encrypt SSL certificate)" example="user@domain.tld">
# git repo
export GIT_REPO="https://github.com/akamai-compute-marketplace/marketplace-apps.git"
export WORK_DIR="/tmp/marketplace-apps"
export MARKETPLACE_APP="apps/linode-marketplace-peppermint"
# enable logging
exec > >(tee /dev/ttyS0 /var/log/stackscript.log) 2>&1
function cleanup {
if [ -d "${WORK_DIR}" ]; then
rm -rf ${WORK_DIR}
fi
}
function udf {
local group_vars="${WORK_DIR}/${MARKETPLACE_APP}/group_vars/linode/vars"
sed 's/ //g' <<EOF > ${group_vars}
# sudo username
username: ${USER_NAME}
webserver_stack: lemp
EOF
if [ "$DISABLE_ROOT" = "Yes" ]; then
echo "disable_root: yes" >> ${group_vars};
else echo "Leaving root login enabled";
fi
if [[ -n ${SOA_EMAIL_ADDRESS} ]]; then
echo "soa_email_address: ${SOA_EMAIL_ADDRESS}" >> ${group_vars};
fi
if [[ -n ${DOMAIN} ]]; then
echo "domain: ${DOMAIN}" >> ${group_vars};
else
echo "default_dns: $(hostname -I | awk '{print $1}'| tr '.' '-' | awk {'print $1 ".ip.linodeusercontent.com"'})" >> ${group_vars};
fi
if [[ -n ${SUBDOMAIN} ]]; then
echo "subdomain: ${SUBDOMAIN}" >> ${group_vars};
else echo "subdomain: www" >> ${group_vars};
fi
if [[ -n ${TOKEN_PASSWORD} ]]; then
echo "token_password: ${TOKEN_PASSWORD}" >> ${group_vars};
else echo "No API token entered";
fi
}
function run {
# install dependancies
apt-get update
apt-get install -y git python3 python3-pip
# clone repo and set up ansible environment
git -C /tmp clone ${GIT_REPO}
# for a single testing branch
# git -C /tmp clone -b ${BRANCH} ${GIT_REPO}
# venv
cd ${WORK_DIR}/${MARKETPLACE_APP}
pip3 install virtualenv
python3 -m virtualenv env
source env/bin/activate
pip install pip --upgrade
pip install -r requirements.txt
ansible-galaxy install -r collections.yml
# populate group_vars
udf
# run playbooks
ansible-playbook -v provision.yml && ansible-playbook -v site.yml
}
function installation_complete {
echo "Installation Complete"
}
# main
run && installation_complete
cleanup