From e70fa4c2f85a52975b948e80079774069eb10138 Mon Sep 17 00:00:00 2001 From: Georg Kahest Date: Tue, 8 Oct 2019 00:56:30 +0300 Subject: [PATCH] split setup to setup and deps, bump rubocop channel to 0-74 --- .codeclimate.yml | 2 +- bin/setup | 56 ++++++------------------------------------------ bin/setup.deps | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 50 deletions(-) create mode 100755 bin/setup.deps diff --git a/.codeclimate.yml b/.codeclimate.yml index 5a9b41ea73..66c860c1b1 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -20,7 +20,7 @@ plugins: enabled: true rubocop: enabled: true - channel: rubocop-0-58 + channel: rubocop-0-74 exclude_patterns: - "app/models/legacy/" - "app/models/version/" diff --git a/bin/setup b/bin/setup index c0fbd95ff0..ea95b5dc2b 100755 --- a/bin/setup +++ b/bin/setup @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require 'pathname' require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) @@ -12,59 +11,18 @@ def system!(*args) end Dir.chdir APP_ROOT do - puts "== Installing gem build deps ==" - uid = `id -u` - uid.delete!("\n") - SUDO_PREFIX="" - unless (uid == "0") - #puts uid - SUDO_PREFIX="sudo" - end - system! "#{SUDO_PREFIX} apt-get update && #{SUDO_PREFIX} apt-get -y --no-install-recommends install libxml2 libxml2-dev postgresql-client postgresql-client-common libpq-dev" - - puts "== Installing rbenv ruby manager to #{ENV['HOME']} ==" - unless Dir.exists?("#{ENV['HOME']}/.rbenv/") - system! "git clone https://github.com/sstephenson/rbenv.git $HOME/.rbenv" - system! 'echo export PATH="$HOME/.rbenv/bin:$PATH" >> ~/.bashrc' - system! "echo "'eval $(rbenv init -)'" >> ~/.bashrc" - end - - unless Dir.exists?("#{ENV['HOME']}/.rbenv/plugins/ruby-build/") - system! "git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build" - system! 'echo export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH" >> ~/.bashrc' - end - unless Dir.exists?("#{ENV['HOME']}/.rbenv/plugins/rbenv-default-gems/") - system! "git clone https://github.com/rbenv/rbenv-default-gems.git $HOME/.rbenv/plugins/rbenv-default-gems" - unless File.exists?("#{ENV['HOME']}/.rbenv/default-gems") - system! 'echo "bundler" > ~/.rbenv/default-gems' - end - end - - - # include rbenv in path - ENV['PATH'] = ENV['HOME'] + "/.rbenv/bin:" + ENV['HOME'] + "/.rbenv/plugins/ruby-build/bin:" + ENV['PATH'] - NEEDED_RUBY = `cat .ruby-version` - if ('!bundle check') == false - system! "#{SUDO_PREFIX} apt-get -y --no-install-recommends install libreadline-dev" - puts "Installing Ruby: " + NEEDED_RUBY - system!("rbenv install " + NEEDED_RUBY) - system!("rbenv rehash") - else - puts "Ruby " + NEEDED_RUBY + "already installed" - end - - puts "== Installing dependencies ==" - system! "gem install bundler --conservative" + puts '== Installing dependencies with bundler ==' + system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') - #puts "\n== Copying sample development config files ==" - # unless File.exist?("config/database.yml") - # system! "cp config/database-example-development.yml config/database.yml" - # end + puts "\n== Copying sample development database config files ==" + unless File.exist?('config/database.yml') + system! 'cp config/database-example-development.yml config/database.yml' + end puts "\n== Preparing database ==" - system! "bin/rake db:setup" + system! 'bin/rake db:setup' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/bin/setup.deps b/bin/setup.deps new file mode 100755 index 0000000000..a16a52ff08 --- /dev/null +++ b/bin/setup.deps @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +def get_uid() + uid = `id -u` + uid.delete!("\n") +end + +Dir.chdir APP_ROOT do + puts '== Installing application build deps ==' + sudo_prefix = '' + sudo_prefix = "sudo" unless get_uid == '0' + system! "#{sudo_prefix} apt-get update && #{sudo_prefix} apt-get -y --no-install-recommends install libxml2 libxml2-dev postgresql-client postgresql-client-common libpq-dev" + + puts "== Installing rbenv ruby manager to #{ENV['HOME']} ==" + unless Dir.exist?("#{ENV['HOME']}/.rbenv/") + system! 'git clone https://github.com/sstephenson/rbenv.git $HOME/.rbenv' + system! 'echo export PATH="$HOME/.rbenv/bin:$PATH" >> ~/.bashrc' + system! "echo 'eval $(rbenv init -)' >> ~/.bashrc" + end + + unless Dir.exist?("#{ENV['HOME']}/.rbenv/plugins/ruby-build/") + system! 'git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build' + system! 'echo export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH" >> ~/.bashrc' + end + unless Dir.exist?("#{ENV['HOME']}/.rbenv/plugins/rbenv-default-gems/") + system! 'git clone https://github.com/rbenv/rbenv-default-gems.git $HOME/.rbenv/plugins/rbenv-default-gems' + unless File.exist?("#{ENV['HOME']}/.rbenv/default-gems") + system! 'echo "bundler" > ~/.rbenv/default-gems' + end + end + + # Include RBENV in path + ENV['PATH'] = ENV['HOME'] + "/.rbenv/bin:" + ENV['HOME'] + "/.rbenv/plugins/ruby-build/bin:" + ENV['PATH'] + NEEDED_RUBY = `cat .ruby-version`.freeze + + if '!bundle check' == false + system! "#{SUDO_PREFIX} apt-get -y --no-install-recommends install libreadline-dev" + puts 'Installing Ruby: ' + NEEDED_RUBY + system!('rbenv install ' + NEEDED_RUBY) + system!('rbenv rehash') + else + puts 'Ruby ' + NEEDED_RUBY + 'already installed' + end + puts 'Now running setup' + exec('./bin/setup') +end