アプリインストール(Slack) - M1 MacBook Air インストール覚書(16)

はじめに

VScode が使えるようになったのは楽ですね。こんな感じで intel_brew/Brewfile と arm_view/Brewfile を見比べながら、下で結果を確認できます。

f:id:hkob:20201218070942p:plain
VScode での編集

ここまでやっていて、App Store のアプリのインストールをやっていないことに気づきました。mas のテストのために一つインストールしてみます。

Slack (arm_brew)

mas は Mac App Store のアプリを自動インストールできるアプリです。最初に入れていたのにテストをしていませんでした。mas の最初の引数は人間がわかるように書いているだけで意味はありません。重要なのは id です。この id は Mac App Store の URL から取得できます。

mas "slack", id: 803453959

実行してみました。Signal KILL されています。 調べたら 🐛 [BUG] Cannot run mas on ARM-based CPU · Issue #308 · mas-cli/mas · GitHub ということで、Apple Silicon で mas が動かないみたいです。 Homebrew でコンパイルできるのだが、動作はしないとのことで、Intel 版は動作するようです。

Using mackup
sh: line 1: 20957 Killed: 9               mas list 2> /dev/null
sh: line 1: 20963 Killed: 9               mas account >&/dev/null
Error: Unable to install slack app. mas not signed in to Mac App Store.

環境設定が終わったらバグ確認することにして、今回は Rosetta2 の方でインストールし直すことにします。 復旧作業ということで、まずインストールされた mas を削除します。

brew uninstall mas

いずれ直ることを期待して、arm_brew/Brewfile の mas をコメントアウトしておきます。

#brew "mas", args: ["build-from-source"]

いよいよ rosetta2_brew/Brewfile の登場です。こちらの mas は bottle でインストールされると思うので、単に "mas" だけにします。

brew "mas"

実行したら mas がインストールされていないと怒られました。そういえば、rosetta2_brew は arm_brew の後に実行するように設定していたためでした。

Error: mas: no bottle available!
You can try to install from source with e.g.
  brew install --build-from-source mas
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.
Error: Unable to install slack app. mas installation failed.

ということで、bootstrap.sh の順序を入れ替えます。

# homebrew, cask and mas
if is_arm; then
  echo "brew bundle in Rosetta2 ..."
  cd rosetta2_brew
  brew_x86 bundle
  echo "brew bundle in Arm native ..."
  cd ../arm_brew
  brew bundle
  cd ..
else
  echo "brew bundle in Intel ..."
  cd intel_brew
  brew bundle
  cd ..
fi
echo

やはり駄目でした。brew bundle だと、中から brew コマンドを呼び出すので、M1 版の brew が呼ばれてしまうようです。 ということで、すでに /opt/homebrew/bin が登録されている時に、それを一時的に取り除く形にしてみました。 パスを外したので、brew bundle と書いても大丈夫ですね。Rosetta2 で動かすために arch コマンドも必要でした。

# homebrew, cask and mas
if is_arm; then
  # すでに存在する場合、/opt/homebrew/bin のバスを取り除く
  PATH=$(echo -n $PATH | tr ':' '\n' | sed "/\/opt\/homebrew\/bin/d" | tr '\n' ':')

  echo "brew bundle in Rosetta2 ..."
  cd rosetta2_brew
  arch --arch x86_64 brew bundle

  # /opt/homebrew/bin のバスを取り除く
  PATH=/opt/homebrew/bin:$PATH
  echo "brew bundle in Arm native ..."
  cd ../arm_brew
  brew bundle
  cd ..
else
  echo "brew bundle in Intel ..."
  cd intel_brew
  brew bundle
  cd ..
fi
echo

最終的にこんな感じで mas も Rosetta2 経由で動作しました。

hkob@hM1Air dotfiles % ./bootstrap.sh
/Users/hkob/dotfiles already downloaded.
Deploying dotfiles ...
/Users/hkob/.gitignore -> /Users/hkob/dotfiles/.gitignore
/Users/hkob/.mackup.cfg -> /Users/hkob/dotfiles/.mackup.cfg
/Users/hkob/.vim -> /Users/hkob/dotfiles/.vim
/Users/hkob/.vimrc -> /Users/hkob/dotfiles/.vimrc
/Users/hkob/.vimrc.org -> /Users/hkob/dotfiles/.vimrc.org
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/texlive/2020/bin/custom:/Library/Apple/usr/bin
brew bundle in Rosetta2 ...
Using homebrew/bundle
Installing mas
Homebrew Bundle complete! 2 Brewfile dependencies now installed.
/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/texlive/2020/bin/custom:/Library/Apple/usr/bin
brew bundle in Arm native ...
Using homebrew/bundle
Using homebrew/cask
Using homebrew/services
Using hkob/m1-beta-cask
Using 1password
Using carthage
Using xquartz
Using google-chrome
Using ghostscript
Using mactex-no-gui
Using alfred
Using visual-studio-code-insiders-arm64
Using mackup
Installing slack
Homebrew Bundle complete! 14 Brewfile dependencies now installed.

せっかく頑張ってインストールしたのですが、Slack は Intel binary でした。Visual Studio Code と同じで Electron アプリなので、Universal にはできないんですね。

f:id:hkob:20201218091430p:plain
Slack info

ここまで M1 に拘っているので、ここで妥協はしたくありません。 そこで、Slack はアンインストールし、Visual Studio Code - Insiders と同じ要領で、m1-beta-cask に slack-arm64 の Cask を作りました。 以下の行を arm_brew/Brewfile に登録して、インストール完了です。

cask "slack-arm64"

今度こそ Apple シリコン版です。

f:id:hkob:20201218093623p:plain
Slack-arm64 info

これで大体ほとんどのパターンのインストールが設定できたでしょうか。 記事にするのはこれくらいにして、インストールを一気にやらないと仕事が間に合わない気がしてきました。

意外と長くなってしまったのでここまでにします。 新規の項目があれば記事にすることにして、アプリ一覧表でも作りましょうか。

次の記事: アプリインストール(gnuplot) - M1 MacBook Air インストール覚書(17) - hkob’s blog

前の記事: アプリインストール(Alfred, Visual Studio Code - Insiders) - M1 MacBook Air インストール覚書(15) - hkob’s blog

hkob.hatenablog.com