From b9f79057a249542eafca96de2a91bf3d883af0d4 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sun, 1 Nov 2020 13:15:32 +0900 Subject: [PATCH] Install `gitea`. --- cookbooks/gitea/attributes.rb | 12 ++++++++ cookbooks/gitea/default.rb | 5 ++++ cookbooks/gitea/install.rb | 55 +++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 cookbooks/gitea/attributes.rb create mode 100644 cookbooks/gitea/default.rb create mode 100644 cookbooks/gitea/install.rb diff --git a/cookbooks/gitea/attributes.rb b/cookbooks/gitea/attributes.rb new file mode 100644 index 0000000..15f3148 --- /dev/null +++ b/cookbooks/gitea/attributes.rb @@ -0,0 +1,12 @@ +# ------------------------------------------- +# Specifying the default settings: +# ------------------------------------------- +node.reverse_merge!({ + 'gitea' => { + 'url' => 'https://github.com/go-gitea/gitea/releases/download/', + 'prefix' => 'gitea-', + 'postfix' => '-linux-amd64', + 'storage' => '/opt/gitea/', + 'location' => '/usr/local/bin/' + }, +}) diff --git a/cookbooks/gitea/default.rb b/cookbooks/gitea/default.rb new file mode 100644 index 0000000..c610d81 --- /dev/null +++ b/cookbooks/gitea/default.rb @@ -0,0 +1,5 @@ +# Loading the attributes: +include_recipe './attributes.rb' + +# Install: +include_recipe './install.rb' diff --git a/cookbooks/gitea/install.rb b/cookbooks/gitea/install.rb new file mode 100644 index 0000000..433914e --- /dev/null +++ b/cookbooks/gitea/install.rb @@ -0,0 +1,55 @@ +gitea_url = '' +gitea_bin = '' + +vtag = '' +tag = '' + +# Calculate the Download URL: +begin + require 'net/http' + + uri = URI.parse('https://github.com/go-gitea/gitea/releases/latest') + + Timeout.timeout(3) do + response = Net::HTTP.get_response(uri) + + vtag = $1 if response.body =~ %r{tag\/(v\d+\.\d+\.\d+)} + tag = vtag.sub(/^v/, '') + + gitea_bin = "#{node['gitea']['prefix']}#{tag}#{node['gitea']['postfix']}" + gitea_url = "#{node['gitea']['url']}/#{vtag}/#{gitea_bin}" + end +rescue + # Abort the chef client process: + raise 'Cannot connect to http://github.com.' +end + +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("gitea --version 2>&1 | grep #{tag}", error: false) +if result.exit_status != 0 + # Download: + TMP = "/tmp/#{gitea_bin}" + + execute "wget #{gitea_url} -O #{TMP}" + + # Install: + directory node['gitea']['storage'] do + owner 'root' + group 'root' + mode '755' + end + + execute "mv #{TMP} #{node['gitea']['storage']}/gitea" + + # Change Owner and Permissions: + file "#{node['gitea']['storage']}/gitea" do + owner 'root' + group 'root' + mode '755' + end + + # Create Link + link "#{node['gitea']['location']}/gitea" do + to "#{node['gitea']['storage']}/gitea" + end +end