-
Notifications
You must be signed in to change notification settings - Fork 4
/
bootstrap.sh
executable file
·50 lines (38 loc) · 1.36 KB
/
bootstrap.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
#!/bin/bash
if [ $(id -u) -ne 0 ]; then
echo "Please run $0 as root or using sudo!"
exit 2
fi
cd "$(dirname $0)" || { echo "Can't cd to boostrap" >&2; exit 2; }
if ! [ -f configuration.yaml ]; then
echo "Have you forgotten to copy and edit configuration.yaml?"
exit 2
fi
ADIR=/usr/local/owntracks/ansible
if ! [ -x $ADIR/bin/ansible-playbook ]; then
echo "Attempting to install ansible and prerequisites for bootstrapping"
sudo apt update
sudo NEEDRESTART_MODE=a apt -qq install -y python3-pip python3-venv
# create a dedicated user for Ansible (without login capabilities)
#
# ansible:x:998:998:Ansible:/usr/local/owntracks/ansible:/bin/false
#
useradd --home-dir $ADIR \
--create-home \
--comment Ansible \
--system \
--shell /bin/false \
ansible
# install ansible core into a python venv
sudo -u ansible python3 -mvenv $ADIR
sudo -u ansible $ADIR/bin/pip install ansible-core
sudo -u ansible $ADIR/bin/ansible-galaxy collection install \
community.general \
community.crypto
fi
# people who know Ansible might be questioning some of the practices
# here such as why not use ansible.cfg right here, or templates in
# templates/ directory; the intention is to hide as much of the
# stuff users require to know as possible.
export ANSIBLE_CONFIG=files/ansible/ansible.cfg
/usr/local/owntracks/ansible/bin/ansible-playbook owntracks-setup.yml "$@"