Go up to the main directory page (md)
For those who are interested, this is how the VirtualBox image was created.
These directions are duplicated in multiple repositories, as they all use the same image. Those are:
This page has a number of different sections, and the sections you need to install will vary depending on what you are using this image for. The image provided with the class has only two sections not installed: Dropbox configuration (in "Image completion") and Turning of the Internet access (in "Programming Contest configuration").
The top of each section describes which of the sub-sections need to be installed for what.
Software Versions
This installation document installs the following versions:
Newer versions of the above may have since come out, but at the time of the writing of this document (August 2017), they were either the versions installed via apt-get (Clang, Python), or the latest versions installed manually (Django, Ruby, and Rails).
Notes
VBoxManage internalcommands sethduuid disk.vdi
(changing disk.vdi
appropriately) will change the UUID, and allow you to proceedAll installations need to run through this, as it sets up the default Kubuntu installation.
Basic installation
sudo apt-get update
then sudo apt-get dist-upgrade
apt-get autoremove
(which didn't have to remove anything)autorun.sh
from /media/student/VBOXADDITIONS_4.3.36_105129
(or similar), and follow the prompts. Alternatively, if that does not work, try running sudo bash VBoxLinuxAdditions.run
from that same directory.The "Program and Data Representation configuration" section is for the Program and Data Representation course, and it includes all of the compilers and editors needed. The "Python/Django" section installs the files needed to run Python 3 and the Django framework. The "Ruby on Rails configuration" section is for developing Ruby on Rails software.
Program and Data Representation configuration
sudo apt-get install clang emacs24 vim nasm astyle tofrodos source-highlight gdb lldb doxygen doxygen-doc graphviz ddd git g++ python-gpgme gobjc gnustep gnustep-make gnustep-common libgnustep-base-dev evince g++-multilib libc6-dev-i386 libc6-dev:i386 flex
apt-get install
lines to be run, belowRan the following two commands to change the default C/C++ compiler to clang:
sudo update-alternatives --set cc /usr/bin/clang
sudo update-alternatives --set c++ /usr/bin/clang++
sudo dpkg -i google-chrome-stable_current_i386.deb
sudo apt-get -f install
Added a few aliases were added (the last 4 lines of .bashrc) to help prevent people from accidentally removing files (adding -i for rm, mv, and cp; and aliasing xemacs to emacs). This was done both in /home/student/.bashrc and /etc/skel/.bashrc.
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'
alias xemacs='emacs'
git clone https://github.com/markfloryan/pdr
; note that a git pull
will still have to be executed each time to update itPlasmashell, which is part of the graphical window system, was crashing repeatedly. The reason seems to be tooltip previews of application windows, so these should be disabled: right click taskbar -> Task Manager Settings -> General -> Uncheck "show tooltips"
LAMP configuration (with both PHP and Python 3)
sudo apt-get install apache2 php php-cli netbeans phpmyadmin phpunit libmysqlclient-dev mysql-server mysql-client php-mysql default-jdk openssh-server tk-dev python-mysqldb php-mcrypt php-intl python3-pip composer libapache2-mod-php sqlite3 postgresql postgresql-contrib
sudo -H pip3 install --upgrade pip
sudo apt-get remove openjdk-8-doc
, since that takes up a lot of space and can be accessed on the Internetsudo a2enmod userdir
sudo a2enmod rewrite
sudo phpenmod intl
and sudo phpenmod mcrypt
/etc/apache2/mods-available/php7.0.conf
, and change the Off
in the php_admin_value engine Off
line to On
sudo service apache2 restart
usermod -a -G adm student
, but this requires logging out and logging in for the group change to take effect)sudo -H pip install Django==1.11
composer create-project --prefer-dist cakephp/app test
. The directory created was then deletedsudo -H pip install virtualenv
Ruby on Rails configuration
First, switch the C/C++ compiler back to gcc/g++:
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --set c++ /usr/bin/g++
--no-ri --no-rdoc
flags were added to each gem
commandTo start rails application, execute the following commands (the edit to be done in emacs is listed below):
cd
rails new myapp -d mysql
cd myapp
emacs config/database.yml
rake db:create
rails server
Changed the C/C++ compiler back over to clang/clang++:
sudo update-alternatives --set cc /usr/bin/clang
sudo update-alternatives --set c++ /usr/bin/clang++
These sections are for configuring the image to run a programming contest using PC^2, and are not needed if you are not running (or participating in) such a contest. One of the sections below will detail how to turn off the Internet for use in the actual contest, and that should only be completed for the final contest image.
Programming Contest configuration
sudo apt-get update
and then sudo apt-get dist-upgrade
sudo apt-get install emacs24 vim eclipse g++ git gdb openjdk-8-jdk gedit
/usr/local/pc2-9.3.2
sudo ln -s pc2-9.3.2 pc2
localhost
on the server
line (likely line 12) with the full server name of the primary submission serverCreate a script to restore the Internet access after the contest (this does not hurt anything to have it ready, as it won't do anything if the Internet is not turned off). This can be /usr/local/bin/restore-internet
-- the commands therein need sudo, so only the student
user can run them. This is typically executed at the end of the contest if the contestants want to save their work. All that has to be done is to modify the default policy for the chains. Be sure to also run chmod 755 /usr/local/bin/restore-internet
.
#!/bin/bash
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
Create a /usr/local/bin/pc2team
shell script, and chmod that to 755 (chmod 755 /usr/local/bin/pc2team
):
#!/bin/bash
cd
/bin/cp -f /usr/local/pc2/pc2v9.ini .
/usr/local/pc2/bin/pc2team &
User account configuration
chmod 700 /home/*
to prevent the second user from accessing any other user accounts (if there is only one user account on the system, then this is not necessary)Turning off Internet access (and other things)
sudo apt-get install eclipse
); put that icon in the tool barEdit /etc/hosts to allow that to resolve domain names to IP addresses. Put in the course servers, their aliases, and their IP addresses:
1.2.3.4 server1.university.edu server1
5.6.7.8 server2.university.edu server2
9.10.11.12 server3.university.edu server3
These directions based on the ones here and here. We want to allow access to the submission servers, but deny everything else. We set the policy to all three chains to DROP, and add ACCEPT lines for localhost and the course servers for the INPUT and OUTPUT chains (we don’t do anything, other than changing the default policy, to the FORWARD chain). For example, the following commands will work (assuming the servers are server1.cs.univeristy.edu through server3.cs.university.edu):
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -j ACCEPT -s server1.cs.university.edu
iptables -A INPUT -j ACCEPT -s server2.cs.university.edu
iptables -A INPUT -j ACCEPT -s server3.cs.university.edu
iptables -A OUTPUT -j ACCEPT -d server1.cs.university.edu
iptables -A OUTPUT -j ACCEPT -d server2.cs.university.edu
iptables -A OUTPUT -j ACCEPT -d server3.cs.university.edu
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables-save > /etc/iptables.rules
iface lo inet loopback
line, put in the following line (indented): pre-up iptables-restore < /etc/iptables.rules
student
is problematic, as that is the user that can restore the Internet access (with the password and via sudo
). So either create another user, or change the password to something else and have the contest staff log the students in.
Let's assume that the second user is hspcteam
; once this account is all set up, create an hspcteam backup to allow resetting: from /home/student, run sudo /bin/cp -a /home/hspcteam .
; then enter the following script (and make it executable) as /usr/local/bin/reset-hspcteam
:
#!/bin/bash
cd
sudo rsync -a --del hspcteam/ /home/hspcteam/
The "Installing Dropbox" section is not installed by default. The "Image finalization" section should be run on every image. The other sections largely deal with maintenance.
Image finalization
composer create-project --prefer-dist cakephp/app cakephp
rails new railshw -d mysql
django-admin startproject mysite
apt-get autoremove
and apt-get clean
sudo cat /dev/zero > zero; sudo /bin/rm -f zero
. This creates a large file of all 0's until it runs out of space, then removes that file.history -c
to remove the history of the commands entered on the command lineVBoxManage modifyhd disk.vdi --compact
(using the real image file name instead of "disk.vdi"). A better way would be to load up into recovery mode and run zerofill, but the grub menu does not seem to be easily available to load into recovery mode, so I didn't pursue it any further.Installing Dropbox (optional)
NOTE: these instructions have not been tested for a few years, so they may no longer work properly...
sudo dpkg -i dropbox_2015.02.12_i386.deb
(adjust the package name to match what you just downloaded)sudo apt-get install python-gpgme
), but that was installed already on the virtual box imagesudo apt-get -f install
-- the -f
part tells apt-get to install the packages needed to fix an installationdropbox start -i
. This will download and install the rest of the dropbox files neededdropbox start
. This first time it will provide a link -- once you go to that link, and log in, it will know which account to link the computer to, and it will start downloading your files.Increasing the disk size
The hard drive size was set at 20 Gb, and about 9.9 Gb is available; the rest is used by the operating system (and the swap partition). If you need more space than this, you will have to expand the hard drive. Be careful -- it is easy to accidentally erase the entire hard drive while doing this!
VBoxManage modifyhd <imagefile> --resize 20480
<imagefile>
is the .vdi disk image, and should be the absolute path including the name and extensionUpgrading from a previous version
Because previous versions of this image were a different version of Ubuntu (specifically, 14.04), we are not providing upgrade information, as it is too extensive to properly check those instructions.
Changes for the future