Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. require 'io/console'
  2. begin
  3. require "colored"
  4. require "octokit"
  5. rescue LoadError
  6. puts "Could not find all needed gems. Please run `bundle install` and retry"
  7. exit
  8. end
  9.  
  10. require "json"
  11. require "open-uri"
  12.  
  13. REQUIRED_RUBY_VERSION = "2.4.5"
  14. REQUIRED_GIT_VERSION = "2.0"
  15. MINIMUM_AVATAR_SIZE = 2 * 1024
  16. GITHUB_AUTHORIZATION_NOTE = 'Le Wagon setup check'.freeze
  17.  
  18. $all_good = true
  19.  
  20. def check(label, &block)
  21. puts "Checking #{label}..."
  22. result, message = yield
  23. $all_good = $all_good && result
  24. puts result ? "[OK] #{message}".green : "[KO] #{message}".red
  25. end
  26.  
  27. def check_all
  28. check("shell") do
  29. if ENV["SHELL"].match(/zsh/)
  30. [ true, "Your default shell is zsh"]
  31. else
  32. [ false, "Your default shell is #{ENV["SHELL"]}, but should be zsh"]
  33. end
  34. end
  35. check("ruby version") do
  36. if RUBY_VERSION == REQUIRED_RUBY_VERSION
  37. [ true, "Your default ruby version is #{RUBY_VERSION}" ]
  38. else
  39. details = `type -a ruby`
  40. [ false, "Your default ruby version is #{RUBY_VERSION}, but should be #{REQUIRED_RUBY_VERSION}. Did you run `rbenv global #{REQUIRED_RUBY_VERSION}`?\n#{details}---" ]
  41. end
  42. end
  43. check("git version") do
  44. version_tokens = `git --version`.gsub("git version", "").strip.split(".").map(&:to_i)
  45. required_version_tokens = REQUIRED_GIT_VERSION.split(".").map(&:to_i)
  46. if version_tokens.first == required_version_tokens.first && version_tokens[1] >= required_version_tokens[1]
  47. [ true, "Your default git version is #{version_tokens.join(".")}"]
  48. else
  49. [ false, "Your default git version is outdated: #{version_tokens.join(".")}"]
  50. end
  51. end
  52. check("GitHub setup") do
  53. begin
  54. groups = `ssh -T git@github.com 2>&1`.match(/Hi (?<nickname>.*)! You've successfully authenticated/)
  55. git_email = (`git config --global user.email`).chomp
  56. nickname = groups["nickname"]
  57.  
  58. client = Octokit::Client.new
  59. client.login = nickname
  60. puts "Please type in your GitHub password (login: '#{nickname}'):"
  61. print "> "
  62. client.password = STDIN.noecho { |stdin| stdin.gets.chomp }
  63. puts "\nThanks. Asking some infos to GitHub..."
  64. # TODO(ssaunier): https://github.com/octokit/octokit.rb#two-factor-authentication
  65.  
  66. authorization =
  67. client.authorizations.find { |a| a[:note] == GITHUB_AUTHORIZATION_NOTE } ||
  68. client.create_authorization(
  69. scopes: ['user:email'],
  70. note: GITHUB_AUTHORIZATION_NOTE)
  71. client.access_token = authorization["token"]
  72.  
  73. avatar_url = client.user[:avatar_url]
  74. emails = client.emails.map { |email| email[:email] }
  75. client.delete_authorization(authorization[:id])
  76.  
  77. if emails.include?(git_email)
  78. content_length = `curl -s -I #{avatar_url} | grep 'Content-Length:'`.strip.gsub("Content-Length: ", "").to_i
  79. if content_length >= MINIMUM_AVATAR_SIZE
  80. [ true, "GitHub email config is OK. And you have a profile picture 📸"]
  81. else
  82. [ false, "You don't have any profile picture set.\nIt's important, go to github.com/settings/profile and upload a picture right now."]
  83. end
  84. else
  85. [ false,
  86. "Your git email is '#{git_email}' and is not listed in https://github.com/settings/emails\n" +
  87. "Run `git config --global user.email george@abitbol.com` to set your git email address. With your own!"]
  88. end
  89. rescue Octokit::Unauthorized => e
  90. puts "Wrong GitHub password, please try again 🙏 Details: #{e.message}"
  91. exit 1
  92. end
  93. end
  94. check("git editor setup") do
  95. editor = `git config --global core.editor`
  96. if editor.match(/subl/i)
  97. [ true, "Sublime Text is your default git editor"]
  98. else
  99. [ false, "Ask a teacher to check your ~/.gitconfig editor setup. Right now, it's `#{editor.chomp}`"]
  100. end
  101. end
  102. check("ruby gems") do
  103. if (`which rspec`) != "" && (`which rubocop`) != ""
  104. [ true, "Everything's fine"]
  105. else
  106. [ false, "Rspec and Rubocop gems aren't there. Did you run the `gem install ...` command?"]
  107. end
  108. end
  109. end
  110.  
  111. def outro
  112. if $all_good
  113. puts ""
  114. puts "🚀 Awesome! Your laptop is now ready for 9 weeks of hard work :)".green
  115. puts "Now it's time to onboard on the Alumni platform 👉 kitt.lewagon.com/onboarding"
  116. else
  117. puts ""
  118. puts "😥 Bummer! Something's wrong, if you're stuck, ask a teacher.".red
  119. end
  120. end
  121.  
  122. check_all
  123. outro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement