Advertisement
Guest User

Untitled

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