diff --git a/.gitignore b/.gitignore index f0329d9..71bd94b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ terraform.tfstate.backup .terraform ips packages +homes account.json .DS_STORE diff --git a/Readme.md b/Readme.md index 407f365..9df8c26 100644 --- a/Readme.md +++ b/Readme.md @@ -39,3 +39,7 @@ Now we can verify everything with the `plan` step: `terraform plan` if everythin ## Clean up In order to clean up everything just run: `terraform destroy` + +### Save Homes + +If you want to save the homes for your students, run the script `save_homes.sh`. This will copy all the contents of `/home/student` from the machines onto your machine. Then zip the files up and place them in `$(pwd)/homes`. diff --git a/save_homes.sh b/save_homes.sh new file mode 100755 index 0000000..10ccf1a --- /dev/null +++ b/save_homes.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -eu + +# Find the script location. Inspired by: https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself +scriptLocation="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +dest=${scriptLocation}/homes +mkdir -p ${dest} + +function ipOf() { + local student=${1} + local node=${2} + cat ${scriptLocation}/ips/${student} | grep ${node} | awk '{ print $2 }' +} + +function download() { + local student=${1} + tmpDir=$(mktemp -d) + mkdir ${tmpDir}/master + scp -q -o StrictHostKeyChecking=no -r -i ${scriptLocation}/keys/${student} student@$(ipOf ${student} master):/home/student ${tmpDir}/master || echo "some files might be missing for ${student} master" + mkdir ${tmpDir}/node + scp -q -o StrictHostKeyChecking=no -r -i ${scriptLocation}/keys/${student} student@$(ipOf ${student} node):/home/student ${tmpDir}/node || echo "some files might be missing for ${student} node" + zip -q -r ${dest}/${student}_home.zip ${tmpDir} + rm -rf ${tmpDir} +} + +for student in $(find ips -type f -exec basename {} \;) ; +do + download ${student} & +done + +wait