Guest User

Untitled

a guest
Jun 11th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Automatically configure a VM download Coursera courses.
  4.  
  5. # This script works as a user data file for use with a cloud VM.
  6. # This script will resume downloading if the VM is restarted.
  7. # This script works with Debian jessie (or possibly Ubuntu with systemd).
  8.  
  9. # You must enroll in each course and accept the Honor of Code of each course
  10. # before you can download them.
  11.  
  12. # Usage:
  13. # 1. Enter your Coursera login credentials in this script
  14. # 2. Select the Coursera courses you want to download in this script by
  15. # uncommenting them below, and add any additional courses you want to
  16. # download that are not listed
  17. # 3. Create a digital ocean droplet
  18. # 4. Select Debian 8.5 x64
  19. # 5. Choose a large enough droplet
  20. # 6. Check "User Data" and paste this entire script into it
  21. # 7. Select your ssh key under "Add your SSH keys"
  22. # 8. Periodically ssh into the VM as root and check journalctl to see if it
  23. # has finished downloading
  24. # 9. Copy the downloaded courses from ~coursera/courses or upload them to
  25. # your cloud backup location of choice
  26.  
  27. # If coursera-dl stops because of an error you can run the command
  28. # `systemctl start coursera.service` to restart downloading or simply reboot
  29. # the VM.
  30.  
  31. # You can add additional courses to download later by creating directories under
  32. # ~/coursera/courses and restart downloading.
  33.  
  34. # Enter your Coursera username and password to download courses
  35. PASSWORD="hunter2"
  36.  
  37. # Uncomment or add additional courses you want to download
  38. COURSES="\
  39. # algo-009
  40. # algo2-003
  41. # algs4partI-010
  42. # algs4partII-007
  43. # analyze-003
  44. # audio-002
  45. # automata
  46. # cariesmanagement-003
  47. # comparch-003
  48. # compilers-004
  49. # crypto-010
  50. # eefun-001
  51. # experiments-001
  52. # gametheory-003
  53. # ggp-003
  54. # hetero-004
  55. # hwswinterface-002
  56. # intrologic-005
  57. # linearopt-002
  58. # matrix-002
  59. # ml-005
  60. # mmds-002
  61. # modelthinking-006
  62. # neuralnets-2012-001
  63. # organalysis-003
  64. # pgm
  65. # recsys-001
  66. # scicomp-003
  67. # sna-2012-001-staging
  68. # spatialcomputing-001
  69. "
  70.  
  71.  
  72.  
  73.  
  74.  
  75. apt-get update
  76. apt-get upgrade -y
  77. apt-get install -y python3 python3-pip
  78. pip3 install coursera
  79.  
  80. useradd coursera -m -s /bin/bash
  81. if [ -f /root/.ssh/authorized_keys ]; then
  82. # Copy any authorized ssh keys added to the VM
  83. mkdir ~coursera/.ssh/
  84. cp /root/.ssh/authorized_keys ~coursera/.ssh/
  85. fi
  86.  
  87. # Create the .netrc file
  88. echo "machine coursera-dl login $USERNAME password $PASSWORD" > ~coursera/.netrc
  89. chmod 600 ~coursera/.netrc
  90.  
  91. # Remove commented out courses and whitespace from courses list
  92. COURSES=$(echo -n "$COURSES" | sed -e '/^#/ d' -e 's/\s//g')
  93. mkdir ~coursera/courses
  94. for course in $COURSES; do
  95. mkdir ~coursera/courses/"$course"
  96. done
  97. chown -R coursera:coursera ~coursera
  98.  
  99. # Set up a service to download Coursera courses on every boot
  100. cat >/etc/systemd/system/coursera.service <<EOF
  101. [Unit]
  102. Description=Download Coursera courses
  103. Requires=network.target
  104.  
  105. [Service]
  106. User=coursera
  107. ExecStart=/bin/sh -c "cd ~/courses && coursera-dl --netrc --resume *"
  108.  
  109. [Install]
  110. WantedBy=default.target
  111. EOF
  112. chmod 664 /etc/systemd/system/coursera.service
  113. systemctl daemon-reload
  114. systemctl enable coursera.service
  115. systemctl start coursera.service
Advertisement
Add Comment
Please, Sign In to add comment