-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathVagrantfile
238 lines (203 loc) · 8.65 KB
/
Vagrantfile
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/focal64"
config.vm.define "tester-ubuntu-v4"
config.disksize.size = '120GB'
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
#config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# do not share a folder between local machine and VM
config.vm.allow_fstab_modification = false
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
vb.memory = "8092"
vb.name = "tester-ubuntu-20.04"
vb.customize ['modifyvm', :id, '--accelerate3d', 'on']
vb.customize ["modifyvm", :id, "--vram", "128"]
vb.customize ['modifyvm', :id, '--graphicscontroller', 'vboxsvga']
vb.customize ['modifyvm', :id, '--clipboard', 'bidirectional']
vb.customize ["modifyvm", :id, "--uart1", "off" ]
vb.customize ["modifyvm", :id, "--uart2", "off" ]
vb.customize ["modifyvm", :id, "--uart3", "off" ]
vb.customize ["modifyvm", :id, "--uart4", "off" ]
end
config.vm.hostname = "tester-m"
# View the documentation for the provider you are using for more
# information on available options.
TESTER_USER="tester"
TESTER_PASSWORD="tester"
tester_dir = <<-SHELL
mkdir -p /var/opt/tester
SHELL
update_apt_update_upgrade = <<-SHELL
sudo apt-get update && \
sudo apt-get upgrade -y
SHELL
install_desktop = <<-SHELL
sudo apt-get install -y --no-install-recommends ubuntu-desktop
sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends gdm3
sudo bash -c "echo '/usr/sbin/gdm3' > /etc/X11/default-display-manage"
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure gdm3
sudo bash -c "echo set shared/default-x-display-manager gdm3 | debconf-communicate"
sudo usermod -a -G sudo vagrant
# Ubuntu fonts
sudo apt-get install -y ttf-ubuntu-font-family
# VirtualBox guest extensions --no-install-recommends
sudo apt-get install -y virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
# Network management
sudo apt-get install -y network-manager network-manager-gnome
SHELL
install_xserver_drivers = <<-SHELL
sudo apt install -y xserver-xorg \
xserver-xorg-core \
xserver-xorg-input-all \
xserver-xorg-input-libinput \
xserver-xorg-input-wacom \
xserver-xorg-legacy \
xserver-xorg-video-all \
xserver-xorg-video-amdgpu \
xserver-xorg-video-ati \
xserver-xorg-video-fbdev \
xserver-xorg-video-intel \
xserver-xorg-video-nouveau \
xserver-xorg-video-qxl \
xserver-xorg-video-radeon \
xserver-xorg-video-vesa \
xserver-xorg-video-vmware
SHELL
add_tester_user = <<-SHELL
if [ ! -f /var/opt/tester/FLAG_#{TESTER_USER}_CREATED ]; then
adduser #{TESTER_USER} --disabled-password --gecos 'student'
usermod -a -G sudo #{TESTER_USER}
echo "#{TESTER_USER}:#{TESTER_PASSWORD}" | chpasswd
touch /var/opt/tester/FLAG_#{TESTER_USER}_CREATED
fi
SHELL
install_pip = <<-SHELL
if [ ! -f /var/opt/tester/FLAG_PIP_INSTALLED ]; then
apt-get install python3-pip -qq && \
pip3 install -U pip;
touch /var/opt/tester/FLAG_PIP_INSTALLED
fi
SHELL
# gitg is the simplest gui for learnig
# gitk is more advanced
install_git_gui = <<-SHELL
if [ ! -f /var/opt/tester/FLAG_GIT_GUI_INSTALLED ]; then
apt-get install gitg -qq && \
apt-get install gitk -qq && \
touch /var/opt/tester/FLAG_GIT_GUI_INSTALLED
fi
SHELL
install_dockerce = <<-SHELL
if [ ! -f /var/opt/tester/FLAG_DOCKER_INSTALLED ]; then
apt-get update ;
apt-get install -qq apt-transport-https ca-certificates curl software-properties-common ;
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - ;
add-apt-repository 'deb [arch=amd64] https://download.docker.com/linux/ubuntu '$(lsb_release -cs)' stable' ;
apt-get update ;
apt-get install -qq docker-ce ;
touch /var/opt/tester/FLAG_DOCKER_INSTALLED
fi
SHELL
install_atom = <<-SHELL
if [ ! -f /var/opt/tester/FLAG_ATOM_INSTALLED ]; then
snap install atom --classic
touch /var/opt/tester/FLAG_ATOM_INSTALLED
fi;
SHELL
install_chrome = <<-SHELL
if [ ! -f /var/opt/tester/FLAG_CHROME_INSTALLED ]; then
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
apt-get -f install -qq
rm google-chrome-stable_current_amd64.deb
touch /var/opt/tester/FLAG_CHROME_INSTALLED
fi;
SHELL
install_postman = <<-SHELL
if [ ! -f /usr/bin/postman ]; then
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz && \
tar -xzf postman.tar.gz -C /opt && \
ln -s /opt/Postman/Postman /usr/bin/postman && \
rm -f postman.tar.gz
fi;
SHELL
# better when the students do it by hand
# notice: the url is incorrect, check the android-studio version on their website
install_android_studio = <<-SHELL
if [ ! -d /home/#{TESTER_USER}/android-studio ]; then
sudo snap install android-studio --classic
fi;
SHELL
disable_desktop_autologin = <<-SHELL
sed -i -e'' 's/AutomaticLoginEnable = [tT]rue/AutomaticLoginEnable = False/g' /etc/gdm3/custom.conf
sed -i -e'' 's/AutomaticLogin = vagrant/AutomaticLogin = #{TESTER_USER}/g' /etc/gdm3/custom.conf
SHELL
do_manage_network_dev = <<-SHELL
nmcli dev set ens3 managed yes
touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
SHELL
cleanup_cache = <<-SHELL
apt-get autoremove -yqq --purge && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
SHELL
for s in [tester_dir,
update_apt_update_upgrade,
install_desktop,
install_xserver_drivers,
add_tester_user,
install_pip,
install_git_gui,
install_dockerce,
install_atom,
install_chrome,
install_postman,
# install_postman_shortcut,
# install_android_studio, # check ^
"apt-get remove -y apport", # disable error reports
disable_desktop_autologin,
do_manage_network_dev,
cleanup_cache
]
config.vm.provision "shell", inline: s
end
end