Skip to content

Instantly share code, notes, and snippets.

@crond-jaist
Last active December 14, 2020 00:37
Show Gist options
  • Save crond-jaist/0f3af8bc31928fc3c03afdbf5c5d3696 to your computer and use it in GitHub Desktop.
Save crond-jaist/0f3af8bc31928fc3c03afdbf5c5d3696 to your computer and use it in GitHub Desktop.
Script to install the entire CyTrONE framework on Ubuntu 16.04 LTS
#!/bin/bash
####################################################################
# Script that installs CyTrONE and the related modules CyRIS, CyLMS,
# and CyPROM on the Ubuntu 16.04 LTS host OS
####################################################################
# CROND-JAIST CyTrONE Install Script Usage
# chmod +x install_cytrone.sh
# ./install_cytrone.sh
# After install, CyTrONE can be launched by:
# ssh -fgL 0.0.0.0:8081:<MOODLE_VM_IP>:443 localhost -N
# cd ~/cytrone/scripts/
# ./start_cytrone.sh
# ./create_training.sh 1
# Wait until create_training.sh fully exit
# Try accessing the Moodle LMS website https://<host_machine_ip>:8081
# CyTrONE can be stopped by:
# cd ~/cytrone/scripts/
# ./end_training.sh 1
# ./stop_cytrone.sh
# lsof -i:8081 # Get SSH tunnel PID <ssh_pid>
# sudo kill <ssh_pid>
# CyTrONE ENV
BASE_VM="basevm.tgz"
MOODLE_VM="moodle.tgz"
SCORM_TEMPLATE="create_scorm_template.sh"
MOODLE_VM_IP="192.168.122.232"
set -e
sudo apt-get update
# Ensure dependencies are installed?
#sudo apt-get install git curl sed openssh-server -y
IP="$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')"
# 1. Enable sudo no password for current user
echo "$USER ALL=NOPASSWD: ALL" | sudo EDITOR='tee -a' visudo
# 2. Generate and copy SSH key.
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" # Remove '-N ""' to provide passphrase
ssh-copy-id localhost
ssh-copy-id 127.0.0.1
ssh-copy-id $IP
# 3. Install kvm and some related packages.
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils -y
# 4. Install virt-manager.
sudo apt-get install virt-manager -y
sudo usermod -aG libvirtd $USER
# 5. Install pip.
sudo apt-get install python-pip -y
# 6. Install python-paramiko.
sudo apt-get install python-paramiko -y
# 7. Install tcpreplay.
sudo apt-get install tcpreplay -y
# 8. Install wireshark.
sudo apt-get install wireshark -y
# 9. Install sshpass.
sudo apt-get install sshpass -y
# 10. Install pssh.
sudo apt-get install pssh -y
# 11. Install yaml for python.
sudo apt-get install python-yaml -y
# 12. Install scapy for python.
sudo apt-get install python-scapy -y
# 13. Install sendemail
sudo apt-get install sendemail -y
# 14. Get CyRIS
cd ~
mkdir ~/images
git clone https://github.com/crond-jaist/cyris.git
cd ~/images
LATEST="$(curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/crond-jaist/cyris/releases/latest)"
wget "${LATEST/tag/download}""/$BASE_VM"
tar zxvf $BASE_VM
# 15. Get CyLMS
cd ~
git clone https://github.com/crond-jaist/cylms.git
sudo apt-get install zip -y
cd ~/images
LATEST="$(curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/crond-jaist/cylms/releases/latest)"
wget "${LATEST/tag/download}""/$MOODLE_VM"
tar zxvf $MOODLE_VM
sudo virsh define moodle.xml
sudo virsh autostart moodle
sudo virsh start moodle
cd ~
wget "${LATEST/tag/download}""/$SCORM_TEMPLATE"
chmod +x $SCORM_TEMPLATE
./$SCORM_TEMPLATE /home/$USER/cylms/
# 16. Get CyPROM
cd ~
git clone https://github.com/crond-jaist/cyprom.git
sudo apt -y install python-msgpack
# 17. Get CyTrONE
cd ~
git clone https://github.com/crond-jaist/cytrone.git
sudo apt -y install python-passlib
cd cytrone/scripts/
cp -a CONFIG.dist CONFIG
sed -i "s/172\.16\.1\.7/$IP/g" CONFIG
sed -i "s/172\.16\.1\.7/$IP/g" ~/cytrone/database/users.yml
# 18. Setup Moodle VM
until ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=no -o KbdInteractiveAuthentication=no -o ChallengeResponseAuthentication=no $MOODLE_VM_IP 2>&1 | grep "Permission denied"; do
echo "Waiting for Moodle VM to come online..."
sleep 1
done # test whether Moodle VM is up
echo "root@$MOODLE_VM_IP (Moodle VM) password can be found in user guide."
ssh-copy-id root@$MOODLE_VM_IP
ssh root@$MOODLE_VM_IP 'sed -i "s/https:\/\/localhost/https:\/\/'"$IP"':8081/g" /var/www/html/moodle/config.php; systemctl restart httpd; exit'
echo "CyTrONE installation completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment