Skip to content

Commit

Permalink
brew: improve formula to remove deprecated syntax
Browse files Browse the repository at this point in the history
Updates the formula to no longer rely on deprecated plist functionality.
Fixes the issue with the service failing due to hardcoded PATH variable
for the service. Generates the service manifest dynamically instead of
embedding it into the formula.

Signed-off-by: Ismayil Mirzali <ismayilmirzeli@gmail.com>
  • Loading branch information
Volatus committed Apr 7, 2023
1 parent ee688a6 commit 59eefe2
Showing 1 changed file with 12 additions and 44 deletions.
56 changes: 12 additions & 44 deletions aws-rotate-iam-keys.template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ class AwsRotateIamKeys < Formula
homepage "https://aws-rotate-iam-keys.com"
url "${HOMEBREW_URL}"
sha256 "${HOMEBREW_SHA}"
depends_on "awscli" => :recommended
depends_on "gnu-getopt"
depends_on "jq"

head do
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '../'))) do
url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git
end
end
depends_on "awscli" => :recommended

def install
bin.install "src/bin/aws-rotate-iam-keys"
Expand All @@ -27,7 +21,7 @@ def install
end

def caveats
s = <<~EOS
<<~EOS
We've installed a default/global configuration file to:
#{etc}/aws-rotate-iam-keys
Expand All @@ -50,42 +44,16 @@ def caveats
EOS
end

plist_options :startup => false

def plist; <<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>if ! curl -s www.google.com > /dev/null; then sleep 60; fi; cp /dev/null /tmp/#{plist_name}.log ; ( egrep '^[[:space:]]*-' ~/.aws-rotate-iam-keys 2>/dev/null || cat #{etc}/aws-rotate-iam-keys ) | while read line; do aws-rotate-iam-keys §line; done</string>
</array>
<key>StandardOutPath</key>
<string>/tmp/#{plist_name}.log</string>
<key>StandardErrorPath</key>
<string>/tmp/#{plist_name}.log</string>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>23</integer>
</dict>
</dict>
</plist>
EOS
def log_path
var/"log/#{name}.log"
end
service do
run opt_bin/"aws-rotate-iam-keys"
run_type :cron
cron "0 10 * * *"
environment_variables PATH: std_service_path_env
log_path f.log_path
error_log_path f.log_path
end

test do
Expand Down

0 comments on commit 59eefe2

Please sign in to comment.