2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macの環境構築を簡単にするためにdotfileとスクリプトで解決するためのメモ

Posted at

やること

1.初期化とアップデート

OSが最新かAppstoreを見た 最新だったのでOK

2.環境構築の準備

masを使うためにApp storeにログインしておく

Appstoreで管理されているアプリを一括でインストールするためmas-cli/masを利用する
mas signin --dialog mas@example.comコマンドでログインさせようとしたが、下記のエラーが返ってきたのであえなく手動でログインすることにした

Error: The 'signin' command has been disabled on this macOS version.
 Please sign into the Mac App Store app manually.

sshでGitHubとやり取りする

.sshファイルを作って、下記の参考文献のようにGitHubとつなげておく

参考文献

GitHubでssh接続する手順~公開鍵・秘密鍵の生成から~

dotfileを用意する

githubにdotfile(~/下にある不可視ファイル)を集めておいた物を作っておく

dotfileを落として、自分のmacに入れておく

dotfileをGitHubから落として自分のホームディレクトリに不可視ファイルを移す。
dotfile以下には.Brewfile.gitconfig.gitignore_globalを置いておく

.Brewfilehomebrewで入れるアプリ、caskで入れるアプリ、masで入れるアプリの一覧表みたいな物だと認識している

ちなみに自分が用意した.Brewfileはこんな感じになっている

tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/core"
tap "mono0926/license-plist"

brew "mas"
brew "git"
brew "git-lfs"
brew "tig"
brew "fish"
brew "fzf"
brew "nodebrew"
brew "pipenv"
brew "rbenv"
brew "go"
brew "pngquant"

cask "google-chrome"
cask "google-japanese-ime"
cask "authy"
cask "iterm2"
cask "dash"
cask "charles"
cask "visual-studio-code"
cask "sketch"
cask "docker"
cask "clipy"
cask "postman"
cask "adobe-creative-cloud"

mas "co.nimbusweb.nimbuscapture", id: 1125725441
mas "com.apple.iWork.Keynote", id: 409183694
mas "com.pearlmountainsoft.PicGIFLite", id: 844918735
mas "Slack", id: 803453959
mas "com.apple.dt.Xcode", id: 497799835

不可視ファイルを適切な位置に移動させるスクリプトを実行する

dotfile以下にinstall.shというスクリプトを用意しておく。これは参考文献を見ながら、必要最低限のものに書き直した。

下記がinstall.shの中身だ。

# !/bin/bash

set -u

# 実行場所のディレクトリを取得
THIS_DIR=$(cd $(dirname $0); pwd)

cd $THIS_DIR
git submodule init
git submodule update

echo "start setup..."
for f in .??*; do
    [ "$f" = ".git" ] && continue
    ln -snfv ~/dotfiles/"$f" ~/
done

cat << END

**************************************************
DOTFILES SETUP FINISHED! bye.
**************************************************

END

これを実行すると

$ cd dotfiles
$ sh install.sh

dotfilesにあった不可視ファイルを、適切なホームディレクトリにシンボリックリンクを貼ることができていることが確認できています。

スクリーンショット 2019-10-20 18.07.31.png スクリーンショット 2019-10-20 18.07.46.png

参考文献

『GitHub+dotfiles』は環境構築を一瞬で終わらせるすごいやつ

homebrewの導入から.Brewfileに書かれているアプリの導入を一コマンド終わらせる

homebrew_install.shというファイルを用意して、下記のように内容をかいた。

# !/bin/bash

### メモ
# さきにApp storeにログインしておく
# install.shを実行しておく

### 不可視ファイルを可視化する(再起動したら見える)
defaults write com.apple.finder AppleShowAllFiles TRUE

### Command Line Tools
echo "Command Line Tools for Xcodeのインストール"
xcode-select --install


### homebrew
echo "installing homebrew...homebrewをインストールしています"
which brew >/dev/null 2>&1 || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

echo "run brew doctor..."
which brew >/dev/null 2>&1 && brew doctor

echo "run brew update..."
which brew >/dev/null 2>&1 && brew update

echo "ok. run brew upgrade..."

### .Brewfileに記載されているアプリをインストール
brew bundle --global --verbose

そして実行をする

$sh homebrew_install.sh

あとは待っていれば、アプリが入ってくれるはず。

遭遇した問題など

caskでアプリを入れようとすると下記のようなエラーが出てくる

Installing clipy cask. It is not currently installed.
==> Satisfying dependencies
==> Downloading https://github.com/Clipy/Clipy/releases/download/1.2.1/Clipy_1.2
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws
######################################################################    97.9%
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: Download failed on Cask 'clipy' with message: Download failed: https://github.com/Clipy/Clipy/releases/download/1.2.1/Clipy_1.2.1.dmg
Installing clipy has failed!

原因

gitのバッファが少ないことが原因らしい・・・?

解決策

.gitconfigに下記の設定を書き加えた
落とすアプリによって、この部分で詰まるアプリと詰まらないアプリが存在していた。authyだとなぜか、やたら止まっていた。何度かコマンドを実行させて徐々に徐々に進めた

[http]
        postBuffer = 100M

参考文献

git clone時にbufferが足りなくてエラーになった話

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?