Guest User

Untitled

a guest
Aug 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #!/bin/bash
  2. # mjk235 [at] nyu [dot] edu --2018.17.2018
  3. # v.0.1
  4.  
  5. # auto-magically install Office 2016 in OS X
  6.  
  7. LOCAL_WEB="128.122.112.23"
  8.  
  9. OFFICE=(
  10. Office2016
  11. "www.cns.nyu.edu/mac/.local/office2016.tgz"
  12. )
  13.  
  14. #######################
  15. #### Sanity Checks ####
  16. #######################
  17.  
  18. # Is current UID 0? If not, exit.
  19.  
  20. root_check () {
  21. if [ "$EUID" -ne "0" ] ; then
  22. printf "%s\\n" "ERROR: ROOT PRIVILEGES ARE REQUIRED TO CONTINUE. EXITING." >&2
  23. exit 1
  24. fi
  25. }
  26.  
  27. # Is there adequate disk space in "/Applications"? If not, exit.
  28.  
  29. check_disk_space () {
  30. if [ $(df -lk /Applications |awk 'FNR == 2 {print $4}' |sed 's/G//') -le "77175193" ]; then
  31. printf "%s\\n" "ERROR: NOT ENOUGH FREE DISK SPACE. EXITING." >&2
  32. exit 1
  33. fi
  34. }
  35.  
  36. # Is curl installed? If not, exit. (Curl ships with OS X, but let's check).
  37.  
  38. curl_check () {
  39. if ! [ -x "$(command -v curl 2>/dev/null)" ]; then
  40. printf "%s\\n" "ERROR: CURL IS NOT INSTALLED. EXITING." >&2
  41. exit 1
  42. fi
  43. }
  44.  
  45. # Is CNS local web available? If not, exit.
  46.  
  47. ping_local_web() {
  48. printf "%s\\n" "PINGING CNS LOCAL WEB..."
  49.  
  50. if ping -c 1 "$LOCAL_WEB" &> /dev/null; then
  51. printf "%s\\n" "CNS LOCAL WEB IS REACHABLE. CONTINUING..."
  52. else
  53. printf "%s\\n" "ERROR: CNS LOCAL WEB IS NOT REACHABLE. EXITING." >&2
  54. exit 1
  55. fi
  56. }
  57.  
  58. sanity_checks() {
  59. root_check
  60. check_disk_space
  61. curl_check
  62. ping_local_web
  63. }
  64.  
  65. sanity_checks
  66.  
  67. ##########################
  68. #### Office Install-r ####
  69. ##########################
  70.  
  71. # Download tarball to /Applications.
  72.  
  73. get_office () {
  74. printf "%s\\n" "RETRIEVING ${OFFICE[0]} INSTALLER..."
  75.  
  76. curl --progress-bar --retry 3 --retry-delay 5 --keepalive-time 60 --continue-at - "${OFFICE[1]}" --output /Applications/office.app.tgz
  77. }
  78.  
  79. # Unpack tarball to /Applications, which installs Office.
  80.  
  81. untar_office () {
  82. printf "%s\\n" "UNTARRING ${OFFIE[0]} PACKAGE TO /Applications..."
  83.  
  84. tar --extract --gzip -v --file=/Applications/office.app.tgz --directory=/Applications
  85. }
  86.  
  87. # Remove tarball from /Applications.
  88.  
  89. remove_office_tar () {
  90. printf "%s\\n" "REMOVING ${OFFICE[0]} TARBALL..."
  91.  
  92. rm -rv /Applications/office.app.tgz
  93. }
  94.  
  95. office_installer () {
  96. get_office
  97. untar_office
  98. remove_office_tar
  99. }
  100.  
  101. ##############
  102. #### Main ####
  103. ##############
  104.  
  105. main () {
  106. sanity_checks
  107. office_installer
  108. }
  109.  
  110. main "$@"
Add Comment
Please, Sign In to add comment