LoginSignup
34
34

More than 5 years have passed since last update.

Macbookクリーンインストールでやった事(Homebrew+Ansible)

Posted at

クリーンインストールでやった事のメモです。

クリーンインストール

必要なファイル等はDropboxなどに退避する。

  1. 電源起動時に、command + Rを押しっぱなしにする
  2. OS X ユーティリティからディスクユーティリティを選択
  3. ディスクを消去する
  4. OS X ユーティリティからOS Xを再インストールするを選択
  5. ソフトウェア使用許諾契約に同意する
  6. インストール先のディスクを選択してインストール
  7. AppleIDとパスワードを入力
  8. OSダウンロードが始まり、その後インストールが開始されるので放置
  9. キーボード入力環境はUSなのでUSを選択
  10. 今は情報の転送はしないを選択
  11. Macを探すは許可する
  12. コンピュータアカウントを作成(iCloudアカウントは使わなかった)
  13. iCloudキーチェーンを設定するを選択
  14. FileVaultディスク暗号化を有効にする
  15. 診断と使用状況はチェックしてない

クリーンインストールが終わったらApp storeからシステムアップデートをかける。

システム環境設定

Dock

  • サイズを小さくする
  • 拡大にチェック。まんなかぐらい
  • 画面上の位置を左に変える
  • Dockを自動的に隠す/表示にチェック

セキュリティとプライバシー

  • スリープとスクリーンセーバの解除を15分後に

キーボード

  • キーのリピートを速く
  • リピート入力時間を短く
  • F1,F2などのすべてのキーを標準のファンクション キーとして使用にチェック
  • 修飾キーからCaps Lockキーを変える→Controlキーにした
  • 入力ソースはUSと日本語で
  • メニューバーに入力メニューを表示にチェック

トラックパッド

  • タップでクリックにチェック
  • 軌跡の速さを速くする

サウンド

  • メニューバーに音量を表示にチェック

iCloud

  • iCloud、キーチェーン、Macを探すにチェックのみ

共有

  • コンピュータ名をかわいいのに変える

日付のオプション

  • 曜日を表示
  • 日付を表示

Xcodeをインストール

App storeからXcodeをインストール。結構時間がかかる。

Homebrewのインストール

以下の手順は下記を参考にさせていただきました。
Mac の開発環境構築を自動化する (2015 年初旬編) - t-wadaのブログ
HomebrewとAnsibleでMacの開発環境構築を自動化する | mawatari.jp

Xcodeのライセンス認証。

sudo xcodebuild -license

Homebrewをインストールする

xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

するとGithubへのSSLで失敗。

fatal: unable to access 'https://github.com/Homebrew/homebrew/': Server aborted the SSL handshake
Failed during: git fetch origin master:refs/remotes/origin/master -n

Githubに繋いでいなかったので、ブラウザからhttps接続して証明書もらう。
そのあと再トライ・・・が失敗。

It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

言われた通り.gitを消してもう一回。

==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 239353, done.
Receiving objects:  21% (52392/239353), 12.41 MiB | 3.00 KiB/s     
error: RPC failed; result=18, HTTP code = 200 MiB | 1024 bytes/s   
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Failed during: git fetch origin master:refs/remotes/origin/master -n

何故か途中で止まる。ちょうどGithubが不調という話があり、その影響か?
何回か繰り返し実行する事でできました。

事前に入れるやつをHomebrewでインストール。

brew install python
brew install ansible
brew install caskroom/cask/brew-cask

Ansibleの実行

プロビジョニング用のディレクトリ作成。

mkdir .macbook-provisioning
cd .macbook-provisioning/

ansible用のinventoryファイル作成

echo 'localhost' > hosts

AnsibleのPlaybookを作成(名前は習ってlocalhost.ymlにしました)

- hosts: localhost
  connection: local
  gather_facts: no
  sudo: no
  vars:
    homebrew_taps:
      - homebrew/binary
      - homebrew/dupes
      - caskroom/cask
      - sanemat/font
    homebrew_packages:
      - { name: readline }
      - { name: openssl }
      - { name: openssl, state: linked, install_options: force }
      - { name: python }
      - { name: ansible }
      - { name: git }
      - { name: zsh, install_options: disable-etcdir } #
      - { name: wget }
      - { name: curl }
      - { name: tree }
      - { name: go }
      - { name: rbenv }
      - { name: ruby-build }
      - { name: vim }
    homebrew_cask_packages:
      - { name: iterm2 }
      - { name: dropbox }
      - { name: firefox }
      - { name: google-chrome }
      - { name: adobe-reader }
      - { name: skype }
      - { name: slack }
      - { name: kobito }
      - { name: vagrant }
      - { name: virtualbox }

  tasks:
    - name: homebrew の tap リポジトリを追加
      homebrew_tap: tap={{ item }} state=present
      with_items: homebrew_taps

    - name: homebrew をアップデート
      homebrew: update_homebrew=yes

    # brew
    - name: brew パッケージをインストール
      homebrew: >
        name={{ item.name }}
        state={{ item.state | default('latest') }}
        install_options={{
          item.install_options | default() | join(',')
          if item.install_options is not string
          else item.install_options
        }}
      with_items: homebrew_packages
      register: brew_result
    - name: brew パッケージの情報保存先ディレクトリを作成
      file: path=brew_info state=directory
    - name: brew パッケージの情報を保存
      shell: brew info {{ item }} > brew_info/{{ item }}
      with_items: brew_result.results | selectattr('changed') | map(attribute='item') | map(attribute='name') | list

    # cask
    - name: homebrew-cask のインストール
      homebrew: name=brew-cask state=latest
    - name: cask パッケージをインストール
      homebrew_cask: name={{ item.name }} state={{ item.state|default('installed') }}
      with_items: homebrew_cask_packages
      register: cask_result
    - name: cask パッケージの情報保存先ディレクトリを作成
      file: path=cask_info state=directory
    - name: cask パッケージの情報を保存
      shell: brew cask info {{ item }} > cask_info/{{ item }}
      with_items: cask_result.results | selectattr('changed') | map(attribute='item') | map(attribute='name') | list

    # oh-my-zsh
    - name: oh-my-zsh のインストール
      shell: curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
      args:
        creates: ~/.oh-my-zsh/

    # Ricty
    - name: xquartz のインストール (for Ricty)
      homebrew_cask: name=xquartz
    - name: fontforge のインストール (for Ricty)
      homebrew: name=fontforge
    - name: Ricty のインストール
      homebrew: name=ricty
    - name: 生成されたフォントファイルをコピー
      shell: cp -f $(brew --cellar ricty)/*/share/fonts/Ricty*.ttf ~/Library/Fonts/
      args:
        creates: ~/Library/Fonts/Ricty-Bold.ttf
      notify: run fc-cache

  handlers:
    - name: run fc-cache
      shell: fc-cache -vf

Homebrew Caskオプションを設定

echo 'export HOMEBREW_CASK_OPTS="--appdir=/Applications"' >> ~/.bash_profile
source ~/.bash_profile

作成したPlaybookを実行する

ansible-playbook -i hosts -vv localhost.yml

bashからzshへの変更
HomeBrew経由のzshパスを追加。

sudo vi /etc/shells

/usr/local/bin/zshを追記したらchshでログインシェルを変更する

chsh -s /usr/local/bin/zsh

これで取り敢えず完了。
細かい所は抜けてる気がするので、いじりながら直していきます。

春がきました。

34
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
34