Advertisement
Guest User

Untitled

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