forked from magnet-cl/django-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.sh
executable file
·79 lines (67 loc) · 2.46 KB
/
quickstart.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
#!/bin/bash
set -e
green="\033[0;32m"
cyan="\033[0;36m"
yellow="\033[0;33m"
red="\033[0;31m"
default="\033[0m"
### Install Ansible
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! [[ -f ~/.ansible.cfg ]]; then
blank_cfg=1
fi
else
if ! [[ -f /etc/ansible/ansible.cfg ]]; then
blank_cfg=1
fi
fi
if ! command -v ansible >/dev/null; then
echo -e "${green}Installing Ansible${default}"
# https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! command -v brew >/dev/null; then
echo -e "${red}Error: Homebrew is not installed (https://brew.sh/#install)${default}"
exit 1
fi
# Install with Homebrew instead of pip because:
# - pip could not be installed
# - pip could install Ansible somewhere not in PATH
brew install ansible
else
sudo apt update
sudo apt install -y software-properties-common
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt install -y ansible
fi
fi
# Improvement: upgrade if version is too old
### Mac OS X warning
if [[ "$OSTYPE" == "darwin"* ]]; then
echo
echo -e "${yellow}Note: quickstart support on Mac OS X is incomplete, because we don't use it too much, and Python configuration is a mess (https://xkcd.com/1987). So you must manually:"
# - Install Homebrew -- already checked above
# shellcheck disable=SC2016
echo -e ' - install and configure PostgreSQL. This worked for me: brew install postgresql && brew services start postgresql && createdb $USER'
echo -e " - create the Poetry virtualenv: poetry env use 3.8 (suggestion: use pyenv)"
echo -e "$default"
fi
### Install roles and run Ansible
cd "$(dirname "$0")/ansible"
# Without --force it never updates (just warns), but with --force it downloads every time...
ansible-galaxy install -r requirements.yaml
if sudo --non-interactive true 2>/dev/null; then
# sudo worked without password!
# Let's hope it will last until Ansible finishes, so don't show the hint.
: # noop
else
ask_become_pass="--ask-become-pass"
echo -e "${green}In ${cyan}BECOME password${green} you have to type your sudo password${default}"
fi
if [[ -n "$blank_cfg" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
ansible-playbook playbooks/human-readable-output.yaml
else
ansible-playbook $ask_become_pass playbooks/human-readable-output.yaml
fi
fi
ansible-playbook --inventory inventory.yaml --limit localhost --tags quickstart $ask_become_pass playbooks/deploy.yaml