Advertisement
Guest User

Untitled

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