mac用 初期設定シェル

```
touch setup setup_osx.sh; chmod u+x setup_osx.sh; vi setup_osx.sh
```

```
#!/bin/bash
BREWFILE_DIR="/Users/kurosawa/setup/OTHER_OS/mac"

ask() {
  printf "$* [y/n] "
  local answer
  read answer

  case $answer in
    "yes" ) return 0 ;;
    "y" )   return 0 ;;
    * )     return 1 ;;
  esac
}

set -e

# usually
if ask 'execute brew brewdler(Brewfile)?'; then
  sudo chown -R root /usr/local
  brew tap Homebrew/brewdler
  pushd $BREWFILE_DIR
  sudo brew brewdler
  popd
fi

# init
if ask 'init?'; then
    if ask 'sudoers?'; then
        sudo cp -fp /etc/sudoers /etc/sudoers.`date "+%Y%m%d_%H%M%S"`_org
        sudo sh -c "echo 'kurosawa ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
    fi

    if ask 'make directory?'; then
      mkdir -p ~/myFolder/
      mkdir -p ~/myFolder/file_setup
      mkdir -p ~/myFolder/develop
      mkdir -p ~/myFolder/develop/git
      mkdir -p ~/myFolder/develop/vagrant
      mkdir -p ~/myFolder/develop/VirtualBox
      mkdir -p ~/myFolder/develop/docker
      mkdir -p ~/myFolder/develop/otto
      mkdir -p ~/myFolder/develop/project1
      mkdir -p ~/myFolder/develop/project1/iOS
      mkdir -p ~/myFolder/develop/project1/iOS/sample
      mkdir -p ~/myFolder/develop/project1/server
      mkdir -p ~/myFolder/develop/project2
      mkdir -p ~/myFolder/develop/project3
      mkdir -p ~/myFolder/develop
      mkdir -p ~/myFolder/BU
    fi

    if ask 'change root password?'; then
      sudo passwd root
    fi

    if ask 'unlock rootless?'; then
      sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
      sudo nvram boot-args="rootless=0"
    fi

    if ask 'Homebrew?'; then
        if ask 'Homebrew install?'; then
          ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

          brew doctor
          brew install caskroom/cask/brew-cask
        fi

        if ask 'install git?'; then
          brew install git
        fi
    fi

    if ask 'osx-for-hackers?'; then
      rm -rf ~/osx-for-hackers
      mkdir ~/osx-for-hackers

      git clone https://gist.github.com/e22d9840f9ea2fee4716.git ~/osx-for-hackers

      cd ~/osx-for-hackers
      chmod u+x osx-for-hackers.sh
      ./osx-for-hackers.sh
      rm -rf ~/osx-for-hackers
    fi

    if ask 'font ricty?'; then
        curl -L 'https://gist.github.com/ysaotome/7286145/raw/installing_ricty_on_MacOSX.sh' | bash
    fi
fi

# Xcode
if ask 'xcode?'; then
    if ask 'xcode install?'; then
      xcode-select --install
    fi

    if ask 'xcode build -license synx cocoapods?'; then
      sudo xcodebuild -license
      sudo gem install synx
      sudo gem install cocoapods
      rbenv rehash
    fi
fi

if ask 'gem update?'; then
  sudo gem update --system
fi

if ask 'Nodebrew install?'; then
  curl -L git.io/nodebrew | perl - setup
fi

if ask 'install bower?'; then
  npm install -g bower
fi

if ask 'clone bitbucket/setup?'; then
  git clone https://prgkurojp@bitbucket.org/prgkurojp/setup.git ~/
fi

if ask "Do you want to install ruby by rbenv-rubybuild?"; then
  INSTALL_RUBY_VERSION="$( rbenv install -l | peco)"
  brew link readline --force
  MAKE_OPTS="-j 4" RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)" rbenv install $INSTALL_RUBY_VERSION
fi

## mac setting
if ask "set 'locate' command?"; then
  sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
fi

if ask 'set visible dotfiles in finder?'; then
  defaults write com.apple.finder AppleShowAllFiles TRUE
  killall Finder
fi

if ask 'set fullpath title at finder?'; then
  defaults write com.apple.finder _FXShowPosixPathInTitle -bool yes
  killall Finder
fi

if ask 'set always expand save dialog?'; then
  defaults write -g NSNavPanelExpandedStateForSaveMode -bool yes
fi

if ask 'set mute in mac booting sound?'; then
  sudo nvram SystemAudioVolume=%80
fi

# @see https://discussionsjapan.apple.com/thread/10153604
if ask 'set clamshell mode off? (for multi display sleep)'; then
  sudo nvram boot-args="niog=1"
fi
```


```:Brewfile
## update
'update'
'upgrade'

tap 'caskroom/cask'
tap 'homebrew/brewdler'
tap 'homebrew/dupes'
tap 'homebrew/services'
tap 'homebrew/versions'

### CUI Aplication ###############
cask 'java'
cask 'xquartz'
# brew 'autoconf'
brew 'autossh'
# brew 'awscli'
# brew 'icu4c'
brew 'boost'
# brew 'bsdmake'
brew 'carthage'
brew 'cmake'
brew 'colordiff'
brew 'csshx'
brew 'go'
brew 'direnv'
# brew 'xz'
# brew 'gettext'
brew 'dwdiff'
# brew 'elasticsearch'
brew 'exiftool'
# brew 'pkg-config'
brew 'x264'
brew 'lame'
brew 'libvo-aacenc'
brew 'xvid'
brew 'libpng'
brew 'freetype'
brew 'openssl'
brew 'ffmpeg'
brew 'fortune'
brew 'gdbm'
brew 'ghi'
brew 'jpeg'
brew 'libtiff'
brew 'little-cms2'
brew 'ghostscript'
brew 'ghq'
brew 'gnu-getopt'
brew 'git-now'
brew 'heroku-toolbelt'
brew 'hub'
brew 'libtool'
brew 'imagemagick'
brew 'jbig2dec'
brew 'oniguruma'
brew 'jq'
brew 'libevent'
brew 'libffi'
brew 'libyaml'
brew 'mackup'
# brew 'mecab'
# brew 'mecab-ipadic'
# brew 'memcached'
brew 'pcre'
# brew 'nginx'
# brew 'nodebrew'
brew 'packer'
brew 'peco'
brew 'readline'
# brew 'postgresql'
brew 'proctools'
brew 'q'
brew 'ruby-build'
brew 'rbenv'
brew 'rbenv-binstubs'
brew 'reattach-to-user-namespace'
# brew 'redis'
brew 'rmtrash'
brew 'source-highlight'
# brew 'spark'
brew 'swiftlint'
brew 'terminal-notifier'
brew 'terraform'
brew 'the_silver_searcher'
brew 'tig'
brew 'tree'
brew 'watch'
brew 'wget'
brew 'youtube-dl'
# brew 'z'
# brew 'zsh'
brew 'caskroom/cask/brew-cask'
brew 'homebrew/dupes/apple-gcc42'
brew 'homebrew/versions/mysql56'
brew 'homebrew/versions/node012'

### GUI Aplication ###############
cask '1password'
cask 'alfred'
cask 'android-studio'
cask 'atom'
cask 'bathyscaphe'
cask 'caffeine'
cask 'cheatsheet'
cask 'chefdk'
cask 'clipy'
cask 'datagrip'
cask 'disk-inventory-x'
cask 'diskwave'
cask 'dockertoolbox'
cask 'dropbox'
cask 'evernote'
cask 'firefox'
cask 'fraise'
cask 'github-desktop'
cask 'google-chrome'
cask 'google-drive'
cask 'google-japanese-ime'
cask 'haroopad'
cask 'hosts'
cask 'hyperdock'
cask 'hyperswitch'
cask 'iterm2'
cask 'karabiner'
cask 'kindle'
cask 'kobo'
cask 'macs-fan-control'
cask 'mamp'
cask 'netbeans-php'
cask 'phpstorm'
cask 'rubymine'
cask 'seil'
cask 'sequel-pro'
cask 'skitch'
cask 'skype'
cask 'slack'
cask 'smartgit'
cask 'sublime-text'
cask 'teamviewer'
cask 'thunderbird'
cask 'vagrant'
cask 'virtualbox'
cask 'vivaldi'
cask 'vlc'
cask 'webstorm'
cask 'xtrafinder'
# cask 'adobe-creative-cloud'
# cask 'bartender'
# cask 'burn'
# cask 'cyberduck'
# cask 'flickr-uploadr'
# cask 'flux'
# cask 'google-photos-backup'
# cask 'handbrake'
# cask 'imageoptim'
# cask 'istat-menus'
# cask 'licecap'
# cask 'maczip4win'
# cask 'mou'
# cask 'shiftit'
# cask 'zoomus'

'clean up'
```