-
Notifications
You must be signed in to change notification settings - Fork 45
/
oci-cloud-init.sh
116 lines (100 loc) · 2.83 KB
/
oci-cloud-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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# Sample cloud-init script for OCI
#
# Copyright (c) 1982-2020 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# https://oss.oracle.com/licenses/upl.
#
# Description: Run by cloud-init at instance provisioning.
# - install lightweight X server (fluxbox) in case we need a GUI
# - install python3
# - install Docker / docker-compose
# - open http/https ports on the firewall
readonly PGM=$(basename $0)
readonly YUM_OPTS="-d1 -y"
readonly USER="opc"
readonly USER_HOME=$(eval echo ~${USER})
readonly VNC_PASSWORD="MySecretVNCPassword"
#######################################
# Print header
# Globals:
# PGM
#######################################
echo_header() {
echo "+++ ${PGM}: $@"
}
#######################################
# Install FluxBox
# Globals:
# USER, YUM_OPTS
#######################################
install_fluxbox() {
echo_header "Install Fluxbox"
yum install ${YUM_OPTS} fluxbox xterm xmessage xorg-x11-fonts-misc
yum install ${YUM_OPTS} tigervnc-server
su - ${USER} -c "\
mkdir .vnc; \
echo \"${VNC_PASSWORD}\" | vncpasswd -f > .vnc/passwd; \
chmod 0600 .vnc/passwd; \
vncserver; \
sleep 5;
vncserver -kill :1; \
sed -i -e 's!/etc/X11/xinit/xinitrc!/usr/bin/fluxbox!' .vnc/xstartup; \
"
}
#######################################
# Install Python 3
# Globals:
# USER, USER_HOME, YUM_OPTS
#######################################
install_python3() {
echo_header "Install Python 3"
yum install ${YUM_OPTS} python3 python3-pip
su - ${USER} -c "pip3 install --user --upgrade pip"
echo 'export PATH=~/.local/bin:"${PATH}"' >> ${USER_HOME}/.bash_profile
su - ${USER} -c "\
pip3 install --user flake8 \
flake8-colors \
flake8-comprehensions \
flake8-docstrings \
flake8-import-order; \
"
}
#######################################
# Install docker
# Globals:
# USER, YUM_OPTS
#######################################
install_docker() {
echo_header "Install Docker"
yum install ${YUM_OPTS} docker-engine
# Add User to docker group
usermod -a -G docker ${USER}
# Enable and start Docker
systemctl enable docker
systemctl start docker
su - ${USER} -c "pip3 install --user docker-compose"
}
#######################################
# Configure Firewall
#######################################
configure_firewall() {
echo_header "Configure Firewall"
local services="http https"
local service
for service in ${services}; do
firewall-cmd --zone=public --add-service=${service}
firewall-cmd --zone=public --add-service=${service} --permanent
done
}
#######################################
# Main
#######################################
main() {
install_python3
install_fluxbox
install_docker # docker-compose depends on python3
configure_firewall
}
main "$@"