install_cmake.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import sys
  2. import os
  3. import os.path
  4. import sh
  5. from sh import git, cd, make, rm, sudo, cp, chmod, mkdir
  6. def write_output(line):
  7. sys.stdout.write(line)
  8. curl = sh.Command("curl")
  9. tar = sh.Command("tar")
  10. install_env = os.environ.copy()
  11. install_env['CC'] = "gcc"
  12. directory = os.path.dirname(os.path.realpath(__file__))
  13. # Download it
  14. cd(directory)
  15. curl(
  16. "-L",
  17. "http://www.cmake.org/files/v3.2/cmake-3.2.2-Linux-x86_64.sh",
  18. _out="cmake_installer.sh"
  19. )
  20. # Set up the installer
  21. installer_path = os.path.join(directory, "cmake_installer.sh")
  22. chmod("a+x", installer_path)
  23. cmake_installer = sh.Command(installer_path)
  24. # Verify the download
  25. sum_str = sh.Command("openssl").sha1(installer_path)
  26. expected_sum = "925e6185e94b717760453427b857fc4f2a4c2149"
  27. if sum_str.split()[1] != expected_sum:
  28. raise Exception
  29. # Install it
  30. print("Installing...")
  31. if os.environ.get("ZMAP_TRAVIS_BUILD", None):
  32. print("Travis CI build, installing to /opt")
  33. with sudo:
  34. cmake_installer(prefix="/opt", exclude_subdir=True)
  35. else:
  36. prefix = os.path.join(directory, "cmake")
  37. mkdir(prefix)
  38. print("Installing to {}".format(prefix))
  39. cmake_installer(prefix=prefix, exclude_subdir=True)
  40. print("Done.")