From 730d76843b28a72ff453c6a0d5b6e8e6b30bc6a7 Mon Sep 17 00:00:00 2001 From: Tom Staubitz Date: Tue, 27 Dec 2016 00:15:04 +0100 Subject: [PATCH] Added some installer scripts for manual setup of local VBox environment running Debian Jessie --- .../setup_debian_1_install_postgres.sh | 63 ++++++++++ .../setup_debian_2_install_docker.sh | 86 ++++++++++++++ ...up_debian_3_install_depencies_and_utils.sh | 67 +++++++++++ .../setup_debian_4_install_guest_additions.sh | 10 ++ .../setup_debian_5_mount_shared_folder.sh | 7 ++ .../setup_debian_6_setup_codeocean.sh | 28 +++++ .../setup_debian_7_create_tables.sh | 8 ++ debian_installer/setup_debian_vm.sh | 110 ++++++++++++++++++ 8 files changed, 379 insertions(+) create mode 100644 debian_installer/setup_debian_1_install_postgres.sh create mode 100644 debian_installer/setup_debian_2_install_docker.sh create mode 100644 debian_installer/setup_debian_3_install_depencies_and_utils.sh create mode 100644 debian_installer/setup_debian_4_install_guest_additions.sh create mode 100644 debian_installer/setup_debian_5_mount_shared_folder.sh create mode 100644 debian_installer/setup_debian_6_setup_codeocean.sh create mode 100644 debian_installer/setup_debian_7_create_tables.sh create mode 100644 debian_installer/setup_debian_vm.sh diff --git a/debian_installer/setup_debian_1_install_postgres.sh b/debian_installer/setup_debian_1_install_postgres.sh new file mode 100644 index 00000000..f94c7ee0 --- /dev/null +++ b/debian_installer/setup_debian_1_install_postgres.sh @@ -0,0 +1,63 @@ +# update apt-get +echo "Update apt-get..." +sudo apt-get update +# upgrade all packages +echo "Upgrade packages..." +sudo apt-get upgrade + +#install postgres +if [ ! -f /etc/apt/sources.list.d/pgdg.list ] +then + echo "Add Postgres sources..." + cd /etc/apt/sources.list.d + sudo touch pgdg.list + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" > pgdg.list' + sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - + sudo apt-get update + echo "Done" +else + echo "Postgres sources already added" +fi + +sudo apt-get -y --force-yes install postgresql-9.5 + +# drop postgres access control +if [ -f /etc/postgresql/9.5/main/pg_hba.conf ] +then + if ! sudo -u postgres grep -q CodeOcean /etc/postgresql/9.5/main/pg_hba.conf + then + echo "Drop Postgres access control..." + sudo -u postgres sh -c 'cat >/etc/postgresql/9.5/main/pg_hba.conf < backports.list' + sudo apt-get update + echo "Done" + + #just in case there is some old stuff + echo "Remove legacy stuff...Just in case..." + sudo apt-get purge "lxc-docker*" + sudo apt-get purge "docker.io*" + sudo apt-get update + + #install docker dependencies + echo "Install dependencies..." + sudo apt-get install -y --force-yes apt-transport-https ca-certificates gnupg2 + echo "Done" +else + echo "Docker dependencies already added." +fi + +if [ ! -f /etc/apt/sources.list.d/docker.list ] +then + # get docker sources + echo "Add apt-get sources for Docker..." + sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D + cd /etc/apt/sources.list.d + sudo touch docker.list + sudo sh -c 'echo "deb https://apt.dockerproject.org/repo debian-jessie main" > docker.list' + sudo apt-cache policy docker-engine + sudo apt-get update + echo "Done" +else + echo "Docker apt-get sources already added." +fi + +if [ ! -f /etc/systemd/system/docker.service.d/docker.conf ] + then + echo "Install Docker Engine..." + sudo apt-get install -y --force-yes docker-engine + echo "Done" + echo "Start Docker..." + sudo service docker start + echo "Done" + echo "Run Hello World..." + sudo docker run hello-world + echo "Done" + + #set some docker options + echo "Configure Docker..." + sudo mkdir /etc/systemd/system/docker.service.d + cd /etc/systemd/system/docker.service.d + sudo touch docker.conf + sudo sh -c 'cat >>/etc/systemd/system/docker.service.d/docker.conf < nonfree.list' + sudo sh -c 'echo "deb-src http://http.debian.net/debian jessie main non-free contrib" >> nonfree.list' + sudo sh -c 'echo "deb http://http.debian.net/debian jessie-updates main contrib non-free" >> nonfree.list' + sudo sh -c 'echo "deb-src http://http.debian.net/debian jessie-updates main contrib non-free" >> nonfree.list' + sudo apt-get update +else + # install utilities + echo "Additional apt-get sources already added" +fi + +# install utilities +echo "Install some utils..." +sudo apt-get install -y --force-yes screen +sudo apt-get install -y --force-yes htop +echo "Done" + +# install dependencies +echo "Install some libraries..." +sudo apt-get install -y --force-yes git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev +sudo apt-get install -y --force-yes libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev +sudo apt-get install -y --force-yes python-software-properties libffi-dev +sudo apt-get install -y --force-yes libgdbm-dev libncurses5-dev automake libtool bison libffi-dev +sudo apt-get install -y --force-yes libpq-dev +echo "Done" + +# get the clock in sync +echo "Install clock synchronization..." +sudo apt-get install -y --force-yes ntp ntpdate +echo "Done" + +echo "Install NodeJS..." +# install nodejs +sudo apt-get install -y --force-yes nodejs +echo "Done" + +if ! (ruby -v | grep -q 2.3.3) +then + # install rvm + echo "Install RVM..." + gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 + \curl -sSL https://get.rvm.io | bash -s stable --ruby + source /home/debian/.rvm/scripts/rvm + echo "Done" + # install ruby + echo "Install Ruby 2.3.3..." + rvm install 2.3.3 + rvm use 2.3.3 --default + ruby -v + exec bash + echo "Done" +else + echo "RVM and Ruby are already installed" +fi + +# install guest additions - required for sharing a folder +echo "Install prerequisites for guest additions..." +sudo apt-get install -y --force-yes dkms build-essential linux-headers-amd64 +echo "Done" + +echo "Please follow the instructions:" +echo "Insert Guest Additions CD image. VM: Devices=>Insert Guest Additions CD image" +echo "Install Guest Additions" \ No newline at end of file diff --git a/debian_installer/setup_debian_4_install_guest_additions.sh b/debian_installer/setup_debian_4_install_guest_additions.sh new file mode 100644 index 00000000..68f7e552 --- /dev/null +++ b/debian_installer/setup_debian_4_install_guest_additions.sh @@ -0,0 +1,10 @@ +# Mount Guest Additions and run the installer +echo "Mount Guest Additions and run the installer..." +sudo mount /dev/sr0 /media/cdrom +cd /media/cdrom +sudo sh ./VBoxLinuxAdditions.run +echo "Done" +echo "Please follow the instructions:" +echo "Create Shared Folder. VM: Devices=>VM: Devices=>Shared Folders=>Shared Folders Settings" +echo "Name: codeocean, Path: path to your local codeocaen repository on the host machine." + diff --git a/debian_installer/setup_debian_5_mount_shared_folder.sh b/debian_installer/setup_debian_5_mount_shared_folder.sh new file mode 100644 index 00000000..db1f8234 --- /dev/null +++ b/debian_installer/setup_debian_5_mount_shared_folder.sh @@ -0,0 +1,7 @@ +echo "Mount Shared Folder..." +mkdir /home/debian/codeocean_host +sudo mount -t vboxsf -o rw,uid=1000,gid=1000 codeocean /home/debian/codeocean_host + +# Enable automount during startup +sudo sh -c 'echo "sudo mount -t vboxsf -o rw,uid=1000,gid=1000 codeocean /home/debian/codeocean_host" >> /home/debian/.bashrc ' +echo "Done" \ No newline at end of file diff --git a/debian_installer/setup_debian_6_setup_codeocean.sh b/debian_installer/setup_debian_6_setup_codeocean.sh new file mode 100644 index 00000000..6151fb3a --- /dev/null +++ b/debian_installer/setup_debian_6_setup_codeocean.sh @@ -0,0 +1,28 @@ +############# codeocean install ########################### +cd /home/debian/codeocean_host + +#install rails and bundler +echo "Install Rails..." +gem install rails +echo "Done" +echo "Install Bundler..." +gem install bundler +echo "Done" + +# install required gems +bundle install + +# copy config files +for f in action_mailer.yml database.yml secrets.yml sendmail.yml smtp.yml code_ocean.yml +do + if [ ! -f config/$f ] + then + cp config/$f.example config/$f + fi +done + +# Manual Task: +# if necessary adjust db config +echo "Check if settings in database.yml correspond with your database setup." + +cat /home/debian/codeocean_host/config/database.yml \ No newline at end of file diff --git a/debian_installer/setup_debian_7_create_tables.sh b/debian_installer/setup_debian_7_create_tables.sh new file mode 100644 index 00000000..ed7f5990 --- /dev/null +++ b/debian_installer/setup_debian_7_create_tables.sh @@ -0,0 +1,8 @@ +# create, migrate, and seed database tables +cd /home/debian/codeocean_host +export RAILS_ENV=development + +echo "load, seed, migrate" +rake db:schema:load +rake db:seed +rake db:migrate \ No newline at end of file diff --git a/debian_installer/setup_debian_vm.sh b/debian_installer/setup_debian_vm.sh new file mode 100644 index 00000000..1fdb628a --- /dev/null +++ b/debian_installer/setup_debian_vm.sh @@ -0,0 +1,110 @@ +# Prerequisites: +# 1 Download Debian iso image. http://cdimage.debian.org/debian-cd/8.6.0/amd64/iso-cd/debian-8.6.0-amd64-netinst.iso +# 2 Create Debian VM in VirtualBox: +# - without GUI +# - without webserver (we do not want an apache2 but an nginx server) +# - with ssh () +# 2 Create 2 users +# - debian/debian +# - root/root + +# Manual preparation: +# Login as root +su + +# install sudo +apt-get install -y sudo + +# add user debian to sudoers and enable this user to sudo without password (do not do this on a production machine) +# or change the line after finishing the installation +cd /etc/sudoers.d +touch debian +echo "debian ALL=(ALL) NOPASSWD:ALL" >> debian +# echo "debian ALL=(ALL:ALL) ALL" >> debian # production systems +# return to no-root user again +exit + +# Running the following directly on the VM command line is inconvenient +# Therefore enable login via ssh from Host + +# The best way to login to a guest Linux VirtualBox VM is port forwarding. +# By default, you should have one interface already which is using NAT. +# Then go to the Network settings and click the Port Forwarding button. Add a new Rule: + +# Protocol TCP Host port 3022, guest port 22, name ssh, other left blank. +# That's all! Please be sure you don't forget to install an SSH server: + +# To SSH into the guest VM, write: +# ssh -p 3022 user@127.0.0.1 +# http://stackoverflow.com/questions/5906441/how-to-ssh-to-a-virtualbox-guest-externally-through-a-host +#======================================================================================================= + +# Install postgres +# run script: +debian_installer/setup_debian_1_install_postgres.sh + +# Install docker +# run script: +debian_installer/setup_debian_2_install_docker.sh + +# Install dependencies, utils, rvm, ruby, node +# run script: +debian_installer/setup_debian_3_install_depencies_and_utils.sh + +##################################local installation on VirtualBox only################## +# Before running the next script, the Guest Additions CD image needs to be inserted via VBox GUI +# Devices=>Insert Guest Additions CD image" +# When that is done run the next script +debian_installer/setup_debian_4_install_guest_additions.sh + +# Before running the next script, a Shared Folder has to be created via VBox GUI +# Devices=>Shared Folders=>Shared Folders Settings +# Folder Name: codeocean, Folder Path: path to your local codeocean repository on the host machine. +# Automount, Make Permanent +# When that is done run the next script +debian_installer/setup_debian_5_mount_shared_folder.sh +##################################local installation on VirtualBox only################## + +# Install rails and bundler +# run script: +debian_installer/setup_debian_6_setup_codeocean.sh + +# Create, seed, and migrate database tables +# run script: +debian_installer/setup_debian_7_create_tables.sh + +# Add Port Forwarding for Rails server: + +# Protocol TCP Host port 3030, guest port 3000, name CodeOcean, other left blank. +# That's all! +# Start Puma server on VM +# rails s -p 3000 + +# To connect to Ruby app use +#http://127.0.0.1:3030 + + +#TODO production: +# require passwd for sudo again. +# cd /etc/sudoers.d +# echo "debian ALL=(ALL:ALL) ALL" > debian + +#TODO production: Install nginx +# install nginx +# echo "Install NGINX..." +# sudo apt-get install -y --force-yes nginx +# echo "Done" + + + + + + + + + + + + + +