Advertisement
Guest User

Untitled

a guest
Jun 11th, 2016
142
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. USERNAME="user@example.com"
  36. PASSWORD="hunter2"
  37.  
  38. # Uncomment or add additional courses you want to download
  39. COURSES="\
  40. # algo-009
  41. # algo2-003
  42. # algs4partI-010
  43. # algs4partII-007
  44. # analyze-003
  45. # audio-002
  46. # automata
  47. # cariesmanagement-003
  48. # comparch-003
  49. # compilers-004
  50. # crypto-010
  51. # eefun-001
  52. # experiments-001
  53. # gametheory-003
  54. # ggp-003
  55. # hetero-004
  56. # hwswinterface-002
  57. # intrologic-005
  58. # linearopt-002
  59. # matrix-002
  60. # ml-005
  61. # mmds-002
  62. # modelthinking-006
  63. # neuralnets-2012-001
  64. # organalysis-003
  65. # pgm
  66. # recsys-001
  67. # scicomp-003
  68. # sna-2012-001-staging
  69. # spatialcomputing-001
  70. "
  71.  
  72.  
  73.  
  74.  
  75.  
  76. apt-get update
  77. apt-get upgrade -y
  78. apt-get install -y python3 python3-pip
  79. pip3 install coursera
  80.  
  81. useradd coursera -m -s /bin/bash
  82. if [ -f /root/.ssh/authorized_keys ]; then
  83. # Copy any authorized ssh keys added to the VM
  84. mkdir ~coursera/.ssh/
  85. cp /root/.ssh/authorized_keys ~coursera/.ssh/
  86. fi
  87.  
  88. # Create the .netrc file
  89. echo "machine coursera-dl login $USERNAME password $PASSWORD" > ~coursera/.netrc
  90. chmod 600 ~coursera/.netrc
  91.  
  92. # Remove commented out courses and whitespace from courses list
  93. COURSES=$(echo -n "$COURSES" | sed -e '/^#/ d' -e 's/\s//g')
  94. mkdir ~coursera/courses
  95. for course in $COURSES; do
  96. mkdir ~coursera/courses/"$course"
  97. done
  98. chown -R coursera:coursera ~coursera
  99.  
  100. # Set up a service to download Coursera courses on every boot
  101. cat >/etc/systemd/system/coursera.service <<EOF
  102. [Unit]
  103. Description=Download Coursera courses
  104. Requires=network.target
  105.  
  106. [Service]
  107. User=coursera
  108. ExecStart=/bin/sh -c "cd ~/courses && coursera-dl --netrc --resume *"
  109.  
  110. [Install]
  111. WantedBy=default.target
  112. EOF
  113. chmod 664 /etc/systemd/system/coursera.service
  114. systemctl daemon-reload
  115. systemctl enable coursera.service
  116. systemctl start coursera.service
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement