github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/cookbooks/swift/recipes/setup.rb (about)

     1  # Copyright (c) 2015-2021, NVIDIA CORPORATION.
     2  # SPDX-License-Identifier: Apache-2.0
     3  
     4  
     5  execute "clean-up" do
     6    command "rm /home/#{node['swift_user']}/postinstall.sh || true"
     7  end
     8  
     9  if node['extra_key'] then
    10    keys_file = "~#{node['swift_user']}/.ssh/authorized_keys"
    11    execute "add_extra_key" do
    12      command "echo '#{node['extra_key']}' >> #{keys_file}"
    13      not_if "grep -q '#{node['extra_key']}' #{keys_file}"
    14    end
    15  end
    16  
    17  if node[:platform_family].include?("rhel")
    18  
    19    # TODO: make the next two commands idempotent
    20    # TODO: make them work for other centos versions
    21    execute "enable epel" do
    22      command "yum -y install epel-release"
    23      action :run
    24    end
    25  
    26    required_packages = [
    27      "openssl-devel", # libssl-dev for swift; is this the same thing?
    28      "curl", "gcc", "memcached", "rsync", "make", "wget", 
    29      "sqlite", # is this the same as sqlite3?
    30      "xfsprogs", "git-core", 
    31      # "build-essential",  subsumed by gcc*, libxml*, make, openssl-devel
    32      "python-devel", "libffi-devel", 
    33      "libxml2-devel", "libxml2", "libxslt", "libxslt-devel",
    34    ]
    35   
    36    # TODO:  confirm package names for centos for these
    37    # no-no packages (PIP is the bomb, system packages are OLD SKOOL)
    38    unrequired_packages = [
    39      "python-requests",  "python-six", "python-urllib3",
    40      "python-pbr", "python-pip",
    41    ]
    42  
    43  else # debian, we assume
    44  
    45    # deadsnakes for py2.6
    46    execute "deadsnakes key" do
    47      command "sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DB82666C"
    48      action :run
    49      not_if "sudo apt-key list | grep 'Launchpad Old Python Versions'"
    50    end
    51  
    52    cookbook_file "/etc/apt/sources.list.d/fkrull-deadsnakes-trusty.list" do
    53      source "etc/apt/sources.list.d/fkrull-deadsnakes-trusty.list"
    54      mode 0644
    55    end
    56  
    57    execute "enable backports" do
    58      command "sudo sed -ie 's/# deb http:\\/\\/archive.ubuntu.com\\/ubuntu trusty-backports/deb http:\\/\\/archive.ubuntu.com\\/ubuntu trusty-backports/' /etc/apt/sources.list"
    59      action :run
    60      not_if "sudo grep -q '^deb .* trusty-backports' /etc/apt/sources.list"
    61    end
    62  
    63    execute "apt-get-update" do
    64      command "apt-get update && touch /tmp/.apt-get-update"
    65      if not node['full_reprovision']
    66        creates "/tmp/.apt-get-update"
    67      end
    68      action :run
    69    end
    70  
    71    # packages
    72    # pythons 2.6 and 3.4 removed; unneeded for proxyfs development
    73    required_packages = [
    74      "liberasurecode-dev",  # required for the EC biz
    75      "libssl-dev", # libssl-dev is required for building wheels from the cryptography package in swift.
    76      "curl", "gcc", "memcached", "rsync", "sqlite3", "xfsprogs", "git-core", "build-essential",
    77      "python-dev", "libffi-dev", 
    78      "libxml2-dev", "libxml2", "libxslt1-dev",
    79    ]
    80  
    81    # no-no packages (PIP is the bomb, system packages are OLD SKOOL)
    82    unrequired_packages = [
    83      "python-requests",  "python-six", "python-urllib3",
    84      "python-pbr", "python-pip",
    85    ]
    86  end
    87  
    88  extra_packages = node['extra_packages']
    89  (required_packages + extra_packages).each do |pkg|
    90    package pkg do
    91      action :install
    92    end
    93  end
    94  
    95  unrequired_packages.each do |pkg|
    96    package pkg do
    97      action :purge
    98    end
    99  end
   100  
   101  # TODO: figure out how to install liberasurecode from a repo
   102  # Down here because wget must be installed first; when we get real package
   103  # install, move it up into rhel block above
   104  if node[:platform_family].include?("rhel")
   105    execute "retrieve liberasurecode" do
   106      command "wget https://rpmfind.net/linux/fedora/linux/releases/29/Everything/x86_64/os/Packages/l/liberasurecode-1.5.0-6.fc29.x86_64.rpm -O /tmp/liberasurecode.rpm"
   107      action :run
   108    end
   109  
   110    execute "retrieve liberasurecode-devel" do
   111      command "wget https://rpmfind.net/linux/fedora/linux/releases/29/Everything/x86_64/os/Packages/l/liberasurecode-devel-1.5.0-6.fc29.x86_64.rpm -O /tmp/liberasurecode-devel.rpm"
   112      action :run
   113    end
   114  
   115    # NOTE:  These are suboptimal, but we'll move to real package install soon
   116    execute "install liberasurecode" do
   117      command "rpm -ivh /tmp/liberasurecode.rpm"
   118      not_if "rpm -qa | grep -q 'liberasurecode-[0-9]'"
   119      action :run
   120    end
   121  
   122    execute "install liberasurecode-devel" do
   123      command "rpm -ivh /tmp/liberasurecode-devel.rpm"
   124      not_if "rpm -qa | grep -q 'liberasurecode-devel'"
   125      action :run
   126    end
   127  end
   128  
   129  # it's a brave new world
   130  execute "install pip" do
   131    command "curl https://bootstrap.pypa.io/get-pip.py | python"
   132    not_if "which pip"
   133  end
   134  
   135  # pip 8.0 is more or less broken on trusty -> https://github.com/pypa/pip/issues/3384
   136  execute "upgrade pip" do
   137    command "pip install --upgrade 'pip>=8.0.2'"
   138  end
   139  
   140  execute "fix pip warning 1" do
   141    command "sed '/env_reset/a Defaults\talways_set_home' -i /etc/sudoers"
   142    not_if "grep always_set_home /etc/sudoers"
   143  end
   144  
   145  execute "fix pip warning 2" do
   146    command "pip install --upgrade ndg-httpsclient"
   147  end
   148  
   149  # setup environment
   150  
   151  execute "update-path" do
   152    command "echo 'export PATH=/#{node['swift_user']}/bin:$PATH' >> /home/#{node['swift_user']}/.profile"
   153    not_if "grep /#{node['swift_user']}/bin /home/#{node['swift_user']}/.profile"
   154    action :run
   155  end
   156  
   157  # swift command line env setup
   158  
   159  {
   160    "ST_AUTH" => "http://#{node['hostname']}:8080/auth/v1.0",
   161    "ST_USER" => "test:tester",
   162    "ST_KEY" => "testing",
   163  }.each do |var, value|
   164    execute "swift-env-#{var}" do
   165      command "echo 'export #{var}=#{value}' >> /home/#{node['swift_user']}/.profile"
   166      not_if "grep #{var} /home/#{node['swift_user']}/.profile"
   167      action :run
   168    end
   169  end
   170  
   171  ruby_block "swift2 alias" do
   172    block do
   173      dot_profile = "/home/#{node['swift_user']}/.profile"
   174  
   175      editor = Chef::Util::FileEdit.new(dot_profile)
   176      editor.insert_line_if_no_match(
   177        /function swift2/,
   178        "function swift2 () { env ST_USER=\"test2:tester2\" ST_KEY=\"testing2\" swift $* ; }")
   179      editor.write_file
   180    end
   181  end
   182  
   183  
   184  # other useful env vars
   185  
   186  {
   187    "NOSE_INCLUDE_EXE" => "true",
   188  }.each do |var, value|
   189    execute "swift-env-#{var}" do
   190      command "echo 'export #{var}=#{value}' >> /home/#{node['swift_user']}/.profile"
   191      not_if "grep #{var} /home/#{node['swift_user']}/.profile"
   192      action :run
   193    end
   194  end