人生シーケンスブレイク

シーケンスブレイク(Sequence breaking、シークエンスブレイクとも)とは、テレビゲームにおいて開発が想定している攻略ルートを逸脱し、ショートカットする行為のことである。

HomeBrewのアップグレードが面倒なのでLaunchAgentsで自動化した

TL;DR

  • 気が向いた時に $ brew upgrade --cleanup してたけど面倒なので LaunchAgents で自動化した。
  • 開発環境は Docker か pyenv / rbenv などで開発しているので、HomeBrewでインストールしているフォーミュラは全自動で勝手にアップデートしても問題なかった。
  • 実際超便利。

LaunchAgentへ登録

まず、BrewUpgrade.plist ファイルを作成する。

<?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>Label</key>
    <string>BrewUpgrade</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/brew</string>
      <string>upgrade</string>
      <string>--cleanup</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
      <key>Hour</key>
      <integer>5</integer>
      <key>Minute</key>
      <integer>0</integer>
    </dict>
    <key>StandardOutPath</key>
    <string>/Users/<user_name>/dotfiles/logs/brew_upgrade.out</string>
    <key>StandardErrorPath</key>
    <string>/Users/<user_name>/dotfiles/logs/brew_upgrade.err</string>
  </dict>
</plist>

上記では、 /usr/local/bin/brew upgrade --cleanup コマンドを毎日05:00に実行する。
スリープ状態だった場合には、スリープから復帰したタイミングで実行される。

つくったファイルを、 ~/Library/LaunchAgents/ 以下へ配置し、$ launchctl load ./BrewUpgrade.plist して完了。

~/Library/LaunchAgents $ ll
total 80
drwxr-xr-x  12 user_name  staff   384B  8 22 16:48 ./
drwx------+ 84 user_name  staff   2.6K  5 15 14:36 ../
-rw-r--r--   1 user_name  staff   768B  8 20 17:36 BrewUpgrade.plist
-rw-r--r--   1 user_name  staff   1.4K  2  7  2018 com.github.facebook.watchman.plist
-rw-r--r--   1 user_name  staff   485B  8 30 14:39 com.jetbrains.AppCode.BridgeService.plist
-rw-r--r--   1 user_name  staff   613B  8 29 11:31 com.jetbrains.toolbox.plist
-rw-r--r--   1 user_name  staff   909B  6 24 20:50 com.valvesoftware.steamclean.plist
-rw-r--r--@  1 user_name  staff   677B  4 26 11:51 org.virtualbox.vboxwebsrv.plist


~/Library/LaunchAgents $ launchctl load ./BrewUpgrade.plist
~/Library/LaunchAgents $ # 何もメッセージは出ない。

--cleanup オプションについて

--cleanup オプションを付けると、古いバージョンのフォーミュラを削除してくれる。
gitやgoなどはかなりサイズが大きく、古いバージョンを残すメリットはほぼないので最近は $ brew upgrade --cleanup にしている。 *1

$ brew upgrade --help
brew upgrade [install-options] [--cleanup] [--fetch-HEAD] [--ignore-pinned] [--display-times] [formulae]:
    Upgrade outdated, unpinned brews (with existing install options).

    Options for the install command are also valid here.

    If --cleanup is specified or HOMEBREW_UPGRADE_CLEANUP is set then remove
    previously installed version(s) of upgraded formulae.

    If --fetch-HEAD is passed, fetch the upstream repository to detect if
    the HEAD installation of the formula is outdated. Otherwise, the
    repository's HEAD will be checked for updates when a new stable or devel
    version has been released.

    If --ignore-pinned is passed, set a 0 exit code even if pinned formulae
    are not upgraded.

    If --display-times is passed, install times for each formula are printed
    at the end of the run.

    If formulae are given, upgrade only the specified brews (unless they
    are pinned; see pin, unpin).

ログファイルについて

    <key>StandardOutPath</key>
    <string>/Users/<user_name>/dotfiles/logs/brew_upgrade.out</string>
    <key>StandardErrorPath</key>
    <string>/Users/<user_name>/dotfiles/logs/brew_upgrade.err</string>

としておくと、実行時の標準出力とエラーが指定ファイルに書き込まれる。
その為、万が一アップグレード後に問題が発生した場合でも、ログを元に発生時期を辿れる。

環境ごとに専用ディレクトリをつくるのが面倒だったので、自分は dotfilse/logs/.gitkeep を配置して .gitignore で除外してそこに吐き出させるようにした。

参考

サッポロ ヱビスビール [ 350ml×24本 ]

サッポロ ヱビスビール [ 350ml×24本 ]

  • 発売日: 2016/03/15
  • メディア: 食品&飲料

*1:個別に実行したい場合には、 $ brew cleanup もアリ