-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.sh
78 lines (60 loc) · 2.66 KB
/
init.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
#!/bin/bash
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script will be triggered by Terraform as part of the provisioning process.
# It can also be triggered manually on a VM.
# Run:
# $ sudo ACE_BOX_USER=dtu_training /home/dtu_training/init.sh
# Don't check for cloud init when deploying via DTU
# https://github.com/Dynatrace/ace-box/issues/400
if [[ -z "${DTU_ENVIRONMENT_NAME}" ]]; then
echo "Not deploying via DTU, wait for cloud init to finish if applicable"
# If applicable: Wait for cloud init to finish
# See https://github.com/Dynatrace/ace-box/issues/272
cloud-init status --wait || echo "Skipping cloud-init wait..."
else
echo "Deploying via DTU..."
fi
ACE_BOX_USER="${ACE_BOX_USER:-$USER}"
# Prevent input prompts by specifying frontend is not interactive
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
echo "INIT - Update apt-get and upgrade already install packages..."
apt-get update && apt-get dist-upgrade -y
echo "INIT - Setting up Python..."
apt-get install python3-pip -y
# Upgrade pip
python3 -m pip --version
python3 -m pip install --upgrade pip -q
# Ansible
echo "INIT - Installing Ansible..."
python3 -m pip install ansible
ln -s /home/$ACE_BOX_USER/.local/bin/ansible /usr/bin/ansible
ln -s /home/$ACE_BOX_USER/.local/bin/ansible-galaxy /usr/bin/ansible-galaxy
ln -s /home/$ACE_BOX_USER/.local/bin/ansible-playbook /usr/bin/ansible-playbook
echo "INIT - Installing Ansible requirements..."
sudo -u $ACE_BOX_USER ansible-galaxy install -r /home/$ACE_BOX_USER/.ace/ansible_requirements.yml
# Install ACE-Box collections
sudo -u $ACE_BOX_USER ansible-galaxy collection install /home/$ACE_BOX_USER/ansible_collections/ace_box/ace_box
sudo rm -rf /home/$ACE_BOX_USER/ansible_collections
# Setup ace-cli
echo "INIT - Setting up ACE-CLI..."
# Install as root. Packages will be available for all users
python3 -m pip install -r /home/$ACE_BOX_USER/.ace/requirements.txt
cp /home/$ACE_BOX_USER/.ace/ace /usr/local/bin/ace
chmod 0755 /usr/local/bin/ace
# Remove Windows-style newline characters
sed -i 's/\r$//' /usr/local/bin/ace
# Set up user groups
addgroup --system docker
adduser $ACE_BOX_USER docker