Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Automatically configure a VM download coursera courses.
- # This script works as a user data file for use with a cloud VM.
- # This script will resume downloading if the VM is restarted.
- # This script works with debian jessie (or possibly ubuntu with systemd).
- # You must enroll in each course and accept the Honor of Code of each course
- # before you can download them.
- # Usage:
- # 1. Enter your coursera login credentials in this script
- # 2. Select the coursera courses you want to download in this script by
- # uncommenting them below, and add any additional courses you want to
- # download that are not listed
- # 3. Create a digital ocean droplet
- # 4. Select Debian 8.5 x64
- # 5. Choose a large enough droplet
- # 6. Check "User Data" and paste this entire script into it
- # 7. Select your ssh key under "Add your SSH keys"
- # 8. Periodically ssh into the VM as root and check journalctl to see if it
- # has finished downloading
- # 9. Copy the downloaded courses from ~coursera/courses or upload them to
- # your cloud backup location of choice
- # Enter your username and password to download courses from coursera
- USERNAME="user@example.com"
- PASSWORD="hunter2"
- # Uncomment the courses you want to download
- COURSES="\
- # algo-009
- # algo2-003
- # algs4partI-010
- # algs4partII-007
- # analyze-003
- # audio-002
- # automata
- # cariesmanagement-003
- # comparch-003
- # compilers-004
- # crypto-010
- # eefun-001
- # experiments-001
- # gametheory-003
- # ggp-003
- # hetero-004
- # hwswinterface-002
- # intrologic-005
- # linearopt-002
- # matrix-002
- # ml-005
- # mmds-002
- # modelthinking-006
- # neuralnets-2012-001
- # organalysis-003
- # pgm
- # recsys-001
- # scicomp-003
- # sna-2012-001-staging
- # spatialcomputing-001
- "
- apt-get update
- apt-get upgrade -y
- apt-get install -y python3 python3-pip
- pip3 install coursera
- useradd coursera -m -s /bin/bash
- if [ -f /root/.ssh/authorized_keys ]; then
- # Copy any authorized ssh keys added to the VM
- mkdir ~coursera/.ssh/
- cp /root/.ssh/authorized_keys ~coursera/.ssh/
- fi
- # Create the .netrc file
- echo "machine coursera-dl login $USERNAME password $PASSWORD" > ~coursera/.netrc
- chmod 600 ~coursera/.netrc
- # Remove commented out courses and whitespace from courses list
- COURSES=$(echo -n "$COURSES" | sed -e '/^#/ d' -e 's/\s//g')
- mkdir ~coursera/courses
- for course in $COURSES; do
- mkdir ~coursera/courses/"$course"
- done
- chown -R coursera:coursera ~coursera
- # Set up a service to download coursera courses on every boot
- cat >/etc/systemd/system/coursera.service <<EOF
- [Unit]
- Description=Download Coursera courses
- Requires=network.target
- [Service]
- User=coursera
- ExecStart=/bin/sh -c "cd ~/courses && coursera-dl --netrc --resume *"
- [Install]
- WantedBy=default.target
- EOF
- chmod 664 /etc/systemd/system/coursera.service
- systemctl daemon-reload
- systemctl enable coursera.service
- systemctl start coursera.service
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement