Guest User

Untitled

a guest
Jun 30th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 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. 4dimensions-004
  40. ac-005
  41. ai-001
  42. aiplan-003
  43. algebra-002
  44. algo-003
  45. algo-005
  46. algo-009
  47. algo2-003
  48. algorithms-001
  49. algs4partI-010
  50. algs4partI-012
  51. algs4partII-007
  52. americandisease-001
  53. analyze-003
  54. androidapps101-002
  55. androidcapstone-001
  56. androidpart1-014
  57. androidpart2-013
  58. aofa-006
  59. aoo-002
  60. apcalc-002
  61. apcalcpart1-001
  62. apstat-002
  63. art-001
  64. artificialvision-001
  65. assetpricing-003
  66. astrotech-003
  67. audio-002
  68. automata-004
  69. basicwriting-009
  70. behaviorprinciples-002
  71. bibrain-003
  72. bigdata-004
  73. bigdataanalytics-001
  74. bigdataschool-001
  75. bitcointech-002
  76. braintargeted-001
  77. career-002
  78. cariesmanagement-003
  79. cdt208-002
  80. childliteracy-001
  81. circaclock-002
  82. circuits-005
  83. citizenjournalism-001
  84. clinicaltrials-001
  85. comics-002
  86. comnetworks-003
  87. comparch-003
  88. compartsaudio-001
  89. compartsprocessing-001
  90. compartsvisual-001
  91. compfinance-009
  92. compilers-003
  93. compilers-004
  94. compmethods-005
  95. compneuro-003
  96. compphoto-001
  97. compvision-002
  98. configuringworld-004
  99. cooperativelearning-001
  100. corethink-003
  101. cplusplus4c-002
  102. crypto-010
  103. cs101-selfservice
  104. datasci-002
  105. db
  106. dementiacare-002
  107. democraticdev-002
  108. design-006
  109. designtech4learning-001
  110. digitalstorytelling-004
  111. dino101-006
  112. dsalgo-001
  113. dsp-006
  114. earlychildhood-001
  115. earth-002
  116. eefun-001
  117. eefunlab-001
  118. einstein-001
  119. emergenceoflife-002
  120. energy-001
  121. eqp-004
  122. ethique-001
  123. experiments-001
  124. extrasolarplanets-001
  125. fdubigdata-001
  126. financialmarketszh-002
  127. finiteelementmethods-002
  128. fog-001
  129. functionalanalysis-002
  130. gametheory-003
  131. gametheory-005
  132. gametheory2-003
  133. genomescience-002
  134. ggp-003
  135. ggp-004
  136. globalization-002
  137. globalorder-003
  138. globalsportsbusiness-002
  139. gtcomp-002
  140. healthcaresafety-002
  141. healthimaging-001
  142. healthleadership-001
  143. hetero-004
  144. hetero-005
  145. humanresearch-001
  146. hwswinterface-002
  147. ictinprimary-004
  148. immigration-002
  149. inforiskman-007
  150. informationtheory-003
  151. infosec-005
  152. inquirytechniques-001
  153. interorg-003
  154. introbiology-004
  155. intrologic-005
  156. intrologic-009
  157. intropsych-002
  158. introstats-003
  159. lcl-001
  160. linalg-001
  161. linearopt-002
  162. linearprogramming-002
  163. logic1-002
  164. logic2-002
  165. ltto-003
  166. m2o2c2-001
  167. machlearning-001
  168. maps-003
  169. marriageandmovies-002
  170. mathematicalmethods-005
  171. mathletics-003
  172. mathphil-003
  173. maththink-004
  174. maththink-008
  175. matrix-002
  176. meatweeat-002
  177. medievalspain-002
  178. metaliteracy-001
  179. ml-003
  180. ml-005
  181. mmds-002
  182. mmds-003
  183. mobilecloudsecurity-006
  184. modelsystems-002
  185. modelthinking-006
  186. money-004
  187. money2-004
  188. moralities-002
  189. musichistoryperforms-002
  190. nanotech-001
  191. networks-003
  192. neuraldata-001
  193. neuralnets-2012-001
  194. neurobio-002
  195. neuroethics-002
  196. newtechtools-003
  197. nlangp-001
  198. nlp-002
  199. nlpintro-001
  200. ntuecom-001
  201. ntufsc-004
  202. ntumltwo-002
  203. oldglobe-002
  204. optimization-003
  205. organalysis-003
  206. os-001
  207. pdstatistics-001
  208. pgm-003
  209. philsci-002
  210. phys1-005
  211. physics1-002
  212. pkuic-002
  213. pkupop-002
  214. plantknows-003
  215. poisonings-002
  216. posacommunication-006
  217. posaconcurrency-006
  218. posasoftware-001
  219. practicalethics-001
  220. precalculus-004
  221. prob-001
  222. probability-002
  223. proglang-002
  224. proglang-003
  225. programming1-002
  226. programming2-001
  227. psy-003
  228. reactive-002
  229. recsys-001
  230. religionandtolerance-002
  231. scicomp-003
  232. scicontentsurvey-001
  233. scientificcomp-007
  234. sciframework-001
  235. scistudentinquiry-001
  236. sciwrite-2012-001
  237. sdn1-001
  238. security
  239. sh-001
  240. shaping1landscape-004
  241. shaping2paths-004
  242. sjtufirstaid-001
  243. sjtuma153-001
  244. sleep-005
  245. sna-004
  246. sna-2012-001
  247. socialentrepeneur-002
  248. spatialcomputing-001
  249. staticsofobjects-002
  250. statreasoning-004
  251. stats1-003
  252. succeedincollege-003
  253. sustaininprac-002
  254. techethics-001
  255. tinkering-002
  256. totalleadership-003
  257. ucsfdiabetes-002
  258. uffinancialplanning-002
  259. understandingterror-003
  260. unethicaldecision-002
  261. ushealthcare-002
  262. uvg-002
  263. virology2-001
  264. vlsicad-005
  265. votingfairdiv-002
  266. warandpeace-002
  267. warhol-002
  268. webapplications-003
  269. webgl-001
  270. writing2-002
  271. "
  272.  
  273.  
  274.  
  275.  
  276.  
  277. apt-get update
  278. apt-get upgrade -y
  279. apt-get install -y python3 python3-pip
  280. pip3 install coursera
  281.  
  282. useradd coursera -m -s /bin/bash
  283. if [ -f /root/.ssh/authorized_keys ]; then
  284. # Copy any authorized ssh keys added to the VM
  285. mkdir ~coursera/.ssh/
  286. cp /root/.ssh/authorized_keys ~coursera/.ssh/
  287. fi
  288.  
  289. # Create the .netrc file
  290. echo "machine coursera-dl login $USERNAME password $PASSWORD" > ~coursera/.netrc
  291. chmod 600 ~coursera/.netrc
  292.  
  293. # Remove commented out courses and whitespace from courses list
  294. COURSES=$(echo -n "$COURSES" | sed -e '/^#/ d' -e 's/\s//g')
  295. mkdir ~coursera/courses
  296. for course in $COURSES; do
  297. mkdir ~coursera/courses/"$course"
  298. done
  299. chown -R coursera:coursera ~coursera
  300.  
  301. # Set up a service to download Coursera courses on every boot
  302. cat >/etc/systemd/system/coursera.service <<EOF
  303. [Unit]
  304. Description=Download Coursera courses
  305. Requires=network.target
  306.  
  307. [Service]
  308. User=coursera
  309. ExecStart=/bin/sh -c "cd ~/courses && coursera-dl --netrc --resume *"
  310.  
  311. [Install]
  312. WantedBy=default.target
  313. EOF
  314. chmod 664 /etc/systemd/system/coursera.service
  315. systemctl daemon-reload
  316. systemctl enable coursera.service
  317. systemctl start coursera.service
Advertisement
Add Comment
Please, Sign In to add comment