Last active
December 8, 2020 04:33
-
-
Save quadcube/cdb96e3ae33a6151b3cc858aafc7fd41 to your computer and use it in GitHub Desktop.
CROND-JAIST CyTRONE Install Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 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. | |
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils ifupdown -y | |
# 4. Install virt-manager. | |
sudo apt-get install virt-manager -y | |
mkdir -p ~/.config/libvirt/ | |
test -f ~/.config/libvirt/libvirt.conf || echo 'uri_default = "qemu:///system"' >> ~/.config/libvirt/libvirt.conf | |
sudo usermod -aG libvirt $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 | |
read -p "Press enter to continue" | |
# 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 "Setup completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for Ubuntu 18.04 LTS