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