Bash script to update common JavaScript libraries (jQuery, headjs, modernizr, etc.)


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. # ------------------------------------------------------------
  4. # Bash script I run on my web server thats updates commonly
  5. # used JavaScript libs. Easy enough to follow and customize if
  6. # need be.
  7. #
  8. # * Be sure to modify JS_LIBS_DIR (Root save path).
  9. #
  10. # - /jquery/jquery.js|jquery.min.js
  11. # - /headjs/headjs.js|head.min.js|head.load.min.js
  12. # - /misc/css_browser_selector.js
  13. # - /misc/modernizr.js
  14. # - /mobile/redirection_mobile.js|redirection_mobile.min.js|redirection_mobile_self.js|redirection_mobile_self.min.js
  15. # - /jquery/plugins/jquery.cookie.js
  16. # - /misc/respond.src.js|respond.min.js
  17. #
  18. # @author Jon LaBelle, jonlabelle.com
  19. # @date May 8, 2011
  20. #
  21. # CRON SCHEDULE (Weekly on Sunday at 1:55 AM)
  22. # 55 1 * * 0 /home/cronjobs/weekly/get-latest-javascript-libs.sh
  23. # ------------------------------------------------------------
  24.  
  25. CURL_USER_AGENT="Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)" # user agent for curl = Windows OS, MS Internet Explorer 7
  26. JS_LIBS_DIR="/home/content/html/js/libs" # Root save path
  27.  
  28. function download_file() {
  29. # curl ops: silent, insecure, redirects, file output
  30. curl -s -k -l -o $1 -A '$CURL_USER_AGENT' $2;
  31. echo "`pwd`/$1 - UPDATED!"
  32. }
  33.  
  34. function unzip_file() {
  35. # unzip ops: overwrite without prompting, quiet mode
  36. unzip -o -q $1;
  37. }
  38.  
  39. function update_jquery() {
  40.  
  41. JQUERY_LATEST_URL="http://code.jquery.com/jquery-latest.js"
  42. JQUERY_LATEST_MIN_URL="http://code.jquery.com/jquery-latest.min.js"
  43.  
  44. cd $JS_LIBS_DIR/jquery;
  45. download_file jquery.js $JQUERY_LATEST_URL;
  46. download_file jquery.min.js $JQUERY_LATEST_MIN_URL;
  47. }
  48.  
  49. function update_headjs() {
  50.  
  51. HEADJS_LATEST_URL="https://github.com/headjs/headjs/raw/master/dist/head.js"
  52. HEADJS_MIN_URL="https://github.com/headjs/headjs/raw/master/dist/head.min.js"
  53. HEADJS_LOAD_MIN_URL="https://github.com/headjs/headjs/raw/master/dist/head.load.min.js"
  54.  
  55. cd $JS_LIBS_DIR/headjs;
  56. download_file head.js $HEADJS_LATEST_URL;
  57. download_file head.min.js $HEADJS_MIN_URL;
  58. download_file head.load.min.js $HEADJS_LOAD_MIN_URL;
  59. }
  60.  
  61. function update_css_browser_selector() {
  62.  
  63. CSS_BROWSER_SELECTOR_LATEST_URL="https://github.com/rafaelp/css_browser_selector/raw/master/css_browser_selector.js"
  64.  
  65. cd $JS_LIBS_DIR/misc;
  66. download_file css_browser_selector.js $CSS_BROWSER_SELECTOR_LATEST_URL;
  67. }
  68.  
  69. function update_modernizr() {
  70.  
  71. MODERNIZR_LATEST_URL="https://github.com/Modernizr/Modernizr/raw/master/modernizr.js"
  72.  
  73. cd $JS_LIBS_DIR/misc;
  74. download_file modernizr.js $MODERNIZR_LATEST_URL;
  75. }
  76.  
  77. function update_redirection_mobile() {
  78.  
  79. REDIRECTION_MOBILE_LATEST_URL="https://github.com/sebarmeli/JS-Redirection-Mobile-Site/raw/master/redirection_mobile.js"
  80. REDIRECTION_MOBILE_MIN_URL="https://github.com/sebarmeli/JS-Redirection-Mobile-Site/raw/master/redirection_mobile.min.js"
  81. REDIRECTION_MOBILE_SELF_URL="https://github.com/sebarmeli/JS-Redirection-Mobile-Site/raw/master/redirection_mobile_self.js"
  82. REDIRECTION_MOBILE_SELF_MIN_URL="https://github.com/sebarmeli/JS-Redirection-Mobile-Site/raw/master/redirection_mobile_self.min.js"
  83.  
  84. cd $JS_LIBS_DIR/mobile;
  85. download_file redirection_mobile.js $REDIRECTION_MOBILE_LATEST_URL;
  86. download_file redirection_mobile.min.js $REDIRECTION_MOBILE_MIN_URL;
  87. download_file redirection_mobile_self.js $REDIRECTION_MOBILE_SELF_URL;
  88. download_file redirection_mobile_self.min.js $REDIRECTION_MOBILE_SELF_MIN_URL;
  89. }
  90.  
  91. function update_jquery_cookie() {
  92.  
  93. JQUERY_COOKIE_LATEST_URL="https://github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js"
  94.  
  95. cd $JS_LIBS_DIR/jquery/plugins;
  96. download_file jquery.cookie.js $JQUERY_COOKIE_LATEST_URL;
  97. }
  98.  
  99. function update_respond() {
  100.  
  101. RESPOND_LATEST_URL="https://github.com/scottjehl/Respond/raw/master/respond.src.js"
  102. RESPOND_MIN_URL="https://github.com/scottjehl/Respond/raw/master/respond.min.js"
  103.  
  104. cd $JS_LIBS_DIR/misc;
  105. download_file respond.js $RESPOND_LATEST_URL;
  106. download_file respond.min.js $RESPOND_MIN_URL;
  107. }
  108.  
  109. update_jquery
  110. update_headjs
  111. update_css_browser_selector
  112. update_modernizr
  113. update_redirection_mobile
  114. update_jquery_cookie
  115. update_respond
  116.  
  117. exit

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.