2015年前半版：Macでターミナルで色々やるように諸々をインストールするシェルスクリプト

MacのCommand Line Toolsに始まり、vimのNeoBundle, Homebrew, Apache, MySQL, phpMyAdmin, nodebrew, PHP, Coda2のマークダウンプラグイン, gulpとそのプラグイン (gulp-sass, gulp-ruby-sass, sassdoc, gulp-minify-css, gulp-uglify, gulp-rename, gulp-concat, browser-sync, gulp-plumber, gulp-imagemin, imagemin-pngquant, gulp-jshint, gulp-notify, gulp-cache, gulp-util, vinyl-ftp, gulp-git, gulp-yuidoc), webpack, Yeomanとgenerator (angularJS, React, aurelia), Ruby, Railsあたりまで一気にインストールするシェルスクリプトです。gulpのプラグインはホームディレクトリにインストールするようにしています。

```sh
#!/ bin/bash

echo ""
echo ""
echo "##############################################################################################################"
echo ""
echo "  -- 参考サイト（全般） --"
echo ""
echo " @see   http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/"
echo "        http://qiita.com/livejam_db/items/b70caccdeece036a3797"
echo "        http://furudate.hatenablog.com/entry/2015/01/16/064610"
echo "        http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/"
echo ""
echo ""
echo "  -- NeoBundle --"
echo ""
echo "@see    https://github.com/Shougo/neobundle.vim"
echo "        http://qiita.com/muran001/items/3080c4816b7c2e65e40b"
echo ""
echo ""
echo "  -- plugins for Coda2 --"
echo ""
echo "@see    https://github.com/Ibmurai/Markdown.codaplugin"
echo ""
echo ""
echo "  -- nodebrew --"
echo ""
echo "@see    http://qiita.com/kiarina/items/dee17fddefe79f362020"
echo ""
echo ""
echo "  -- npm packages --"
echo ""
echo "@see    https://www.npmjs.com/package/gulp"
echo "        http://qiita.com/cortyuming/items/ba4c4d61fdf262bc2303"
echo ""
echo ""
echo "  -- plugins for gulp --"
echo ""
echo "@see    https://www.npmjs.com/package/gulp-sass"
echo "        https://www.npmjs.com/package/sassdoc"
echo "        https://www.npmjs.com/package/gulp-minify-css"
echo "        https://www.npmjs.com/package/gulp-autoprefixer"
echo "        https://www.npmjs.com/package/gulp-uglify"
echo "        https://www.npmjs.com/package/gulp-rename"
echo "        https://www.npmjs.com/package/gulp-concat"
echo "        https://www.npmjs.com/package/browser-sync"
echo "        https://www.npmjs.com/package/gulp-plumber"
echo "        https://www.npmjs.com/package/gulp-babel"
echo "        https://www.npmjs.com/package/gulp-imagemin"
echo "        https://www.npmjs.com/package/imagemin-pngquant"
echo "        https://www.npmjs.com/package/gulp-jshint"
echo "        https://www.npmjs.com/package/gulp-notify"
echo "        https://www.npmjs.com/package/gulp-cache"
echo "        https://www.npmjs.com/package/gulp-util"
echo "        https://www.npmjs.com/package/gulp-if"
echo "        https://www.npmjs.com/package/vinyl-ftp"
echo "        https://www.npmjs.com/package/gulp-git"
echo "        https://www.npmjs.com/package/gulp-docco"
echo "        https://www.npmjs.com/package/gulp-doxx"
echo "        https://www.npmjs.com/package/gulp-stylestats"
echo "        https://www.npmjs.com/package/gulp-html-validator"
echo ""
echo ""
echo ""
echo "  -- Yeoman generators --"
echo ""
echo "@see    https://www.npmjs.com/package/generator-angular"
echo "        https://www.npmjs.com/package/react-tools"
echo "        https://www.npmjs.com/package/generator-react-webpack"
echo "        https://www.npmjs.com/package/generator-aurelia"
echo ""
echo ""
echo "  -- brew cask --"
echo ""
echo "@see    http://blog.nanapi.co.jp/tech/2014/03/05/homebrew-cask/"
echo ""
echo "##############################################################################################################"
echo ""
echo "                コマンドラインで色々するための諸々をインストールするよ"
echo "   　   人      各パッケージとかの情報は上に表示されてるURLを参照してね"
echo "    (　ﾟーﾟ)"
echo "   　 ￣￣      なんかキー押したらインストール開始しま〜す"
echo ""
echo "##############################################################################################################"
echo ""
echo ""
read start_install

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install Xcode Command Line Tools             #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""
echo "=================================================="
echo ""
echo "installing Xcode Command Line Tools ..."
echo ""
echo "=================================================="
echo ""
xcode-select --install
echo ""
echo "************************************************************"
echo ""
echo "Hit any key if the Command Line Tools are installed"
echo ""
echo "************************************************************"
echo ""
read is_xcode_installed
echo ""
echo "finished installing Xcode Command Line Tools"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install NeoBundle                            #"
echo "#                                                #"
echo "#   vimのプラグイン管理ツール                    #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

if [ ! -e ~/.vim/bundle/neobundle.vim ]; then
    echo ""
    echo "=================================================="
    echo ""
    echo "installing NeoBundle ..."
    echo ""
    echo "=================================================="
    echo ""
    curl -o- https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh | bash
fi

echo ""
echo "finished installing NeoBundle"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install homebrew                             #"
echo "#                                                #"
echo "#   とりあえず                                   #"
echo "#   /usr/local/Cellar                            #"
echo "#   にインストールされることだけは覚えとこう     #"
echo "#                                                #"
echo "#   @see http://brew.sh                          #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

### install homebrew if not installed
if ! type -P brew > /dev/null ; then
    echo ""
    echo "=================================================="
    echo ""
    echo "installing homebrew ..."
    echo ""
    echo "=================================================="
    echo ""
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

echo ""
echo "finished installing homebrew"
echo ""

### update and upgrade homebrew and packages
echo ""
echo "=================================================="
echo ""
echo "updating homebrew ..."
echo ""
echo "=================================================="
echo ""
echo ""
echo "＿人 人 人 人＿"
echo " ＞突然の死 ＜"
echo "￣Ｙ^Ｙ^Ｙ^Ｙ￣"
echo ""
echo ""

brew doctor
brew prune
brew update
brew outdated
brew upgrade

echo ""
echo "finished updating homebrew"
echo ""

echo ""
echo "----------------------------------------------------------------------"
echo ""
echo "brewでパッケージのインストールがなんかうまくいかないなぁ〜ってときは"
echo "/Library/Cache/Homebrew を消してみるといいかもしれませんよ"
echo ""
echo "あとbrewはsudoしなくてもいいからね^^"
echo ""
echo "----------------------------------------------------------------------"
echo ""

### add repositories
repositories="dupes apache versions homebrew-php x11"
for repository in ${repositories} ; do
    if [ "`brew tap | grep ${repository}`" != "homebrew/${repository}" ] ; then
        echo ""
        echo "=================================================="
        echo ""
        echo "brew tapping ${repository} ..."
        echo ""
        echo "=================================================="
        echo ""
        brew tap homebrew/${repository}
    fi
done

echo ""
echo "finished brew tap"
echo ""

### install packages
package_list="git
              curl
              tree
              wget
              w3m
              colordiff
              gnu-sed
              unrar
              nasm
              links
              md5sha1sum
              httpd24
              mysql
              phpmyadmin
              nginx
              readline
              openssl
              ruby-build
              rbenv
              imagemagick
              nkf
              gnuplot
              grace"

for package in ${package_list} ; do
    if [ "`brew list | grep ${package}`" != "${package}" ] ; then
        echo ""
        echo "=================================================="
        echo ""
        echo "installing ${package} ..."
        echo ""
        echo "=================================================="
        echo ""
        brew install ${package}
    fi
done

echo ""
echo "finished installing packages"
echo ""

### install PHP5.4
echo ""
echo "=================================================="
echo ""
echo "installing PHP5.4 ..."
echo ""
echo "=================================================="
echo ""
if [ "`brew list | grep php54`" != "php54" ] ; then
  brew install php54 --with-apache --without-pear
fi

echo ""
echo "finished installing PHP5.4"
echo ""

###  check installed packages  ###
echo "=================================================="
echo ""
echo "installed package list is as follows:"
echo ""
echo "--------------------------------------------------"
brew -v list
echo ""
echo "=================================================="

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install Coda2 plugins                        #"
echo "#                                                #"
echo "#   なんだかんだで使ってしまってるCoda2          #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

### install Coda2 Markdown plugin
echo ""
echo "=================================================="
echo ""
echo "installing Coda2 plugins ..."
echo ""
echo "=================================================="
echo ""
if [ ! -e ~/Library/Application\ Support/Coda\ 2/Plug-ins/Markdown.codaplugin ]; then
    pushd ~/Library/Application\ Support/Coda\ 2/Plug-ins
    git clone git://github.com/Ibmurai/Markdown.codaplugin.git
    popd
fi

echo ""
echo "finished installing Coda2 plugins"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install nodebrew (node.js and npm)           #"
echo "#                                                #"
echo "#   nodeの管理はnvmじゃなくてnodebrewで          #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

echo ""
echo "=================================================="
echo ""
echo "installing node.js and npm using nodebrew ..."
echo ""
echo "=================================================="
echo ""

if [ "`echo $PATH | grep '.nodebrew/current'`" = "" ]; then
  curl -L git.io/nodebrew | perl - setup
  echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> .profile
  source ~/.profile
  nodebrew install latest
  nodebrew use latest
else
  nodebrew selfupdate
fi
node -v
npm -v

nodebrew clean all

echo ""
echo "finished installing nodebrew"
echo ""

echo ""
echo "=================================================="
echo ""
echo "updating npm ..."
echo ""
echo "=================================================="
echo ""
npm update -g npm
echo ""
echo "finished updating npm"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install npm packages in                      #"
echo "#      ~/.nodebrew/current/lib/node_modules      #"
echo "#                                                #"
echo "#   まずはグローバルにインストールしま〜す       #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

package_list="gulp
              webpack
              grunt-cli
              yo
              karma
              jspm
              hexo
              bower
              npm-check-updates
              electron-prebuilt
              asar
              electron-packager
              electron-connect"

for package in ${package_list} ; do
    if [ ! -e ~/.nodebrew/current/lib/node_modules/${package} ]; then
        echo ""
        echo "======================================================================"
        echo ""
        echo "installing ${package} in ~/.nodebrew/current/lib/node_modules ..."
        echo ""
        echo "======================================================================"
        echo ""
        npm install -g ${package}
    else
        echo ""
        echo "======================================================================"
        echo ""
        echo "updating ${package} in ~/.nodebrew/current/lib/node_modules ..."
        echo ""
        echo "======================================================================"
        echo ""
        npm update -g ${package}
    fi
done

echo ""
echo "finished installing npm packages (global)"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install npm packages in                      #"
echo "#      /Users/username/                          #"
echo "#                                                #"
echo "#   gulp関連はホームディレクトリに               #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

### ホームディレクトリに移動
pushd ~/

package_list="gulp
              gulp-sass
              sassdoc
              gulp-minify-html
              gulp-file-include
              gulp-minify-css
              gulp-autoprefixer
              gulp-webpack
              gulp-uglify
              gulp-rename
              gulp-concat
              gulp-sourcemaps
              gulp-plumber
              browser-sync
              browserify
              babelify
              babel-preset-es2015
              babel-preset-react
              jsx-loader
              vinyl-source-stream
              vinyl-buffer
              gulp-imagemin
              imagemin-pngquant
              jshint
              gulp-jshint
              gulp-notify
              gulp-cache
              gulp-util
              gulp-if
              gulp-shell
              vinyl-ftp
              gulp-git
              gulp-docco
              gulp-doxx
              gulp-stylestats
              gulp-html-validator
              cli-usage
              bower
              angular
              angular-aria
              angular-touch
              angular-animate
              angular-cookies
              angular-route
              angular-sanitize
              angulartics
              react
              react-dom
              react-desktop
              moment
              lodash
              string
              decimal
              mathjs
              jquery
              bebel
              babel-core
              babel-runtime
              babel-loader"

for package in ${package_list} ; do
    if [ ! -e ~/node_modules/${package} ]; then
        echo ""
        echo "=================================================="
        echo ""
        echo "installing ${package} in /Users/username/ ..."
        echo ""
        echo "=================================================="
        echo ""
        npm install --save-dev ${package}
    else
        echo ""
        echo "=================================================="
        echo ""
        echo "updating ${package} in /Users/username/ ..."
        echo ""
        echo "=================================================="
        echo ""
        npm update --save-dev ${package}
    fi
done

### もといたディレクトリに戻る
popd

echo ""
echo "finished installing npm packages (local)"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "# install composer                               #"
echo "#                                                #"
echo "# PHPあんま好きじゃないんですが一応...           #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""
echo ""
echo "=================================================="
echo ""
echo "installing composer ..."
echo ""
echo "=================================================="
echo ""

if [ ! -e /usr/local/bin/composer ]; then
  curl -sS https://getcomposer.org/installer | php

  ## Yosemite以上では/usr/local/binがないらしい...
  if [ `ls /usr/local/bin | wc -l` == '0' ]; then
    sudo mkdir /usr/local/bin
  fi

  mv composer.phar /usr/local/bin/composer

  composer --version

fi

echo ""
echo "finished installing composer"
echo ""

echo ""
echo ""
echo "##################################################"
echo "#                                                #"
echo "#   install gem packages (using default gem)     #"
echo "#                                                #"
echo "#   ruby関連のパッケージのインストールです       #"
echo "#                                                #"
echo "##################################################"
echo ""
echo ""

echo ""
echo "=================================================="
echo ""
echo "installing Ruby 2.2.2 ..."
echo ""
echo "=================================================="
echo ""
if [ ! -e /usr/local/bin/rbenv ]; then
  rbenv install 2.2.2
  rbenv global 2.2.2
  ruby -v
fi

### echo ""
### echo "--------------------------------------------------"
### echo ""
### echo "powが走ってるとApacheの邪魔をしてくれるので"
### echo "$ powder down"
### echo "でpowを停止しておきましょうね"
### echo ""
### echo "--------------------------------------------------"
### echo ""
### if [ "`gem list | grep powder`" = "" ]; then
### sudo gem install powder
###     echo ""
###     echo "=================================================="
###     echo ""
###     echo "installing powder ..."
###     echo ""
###     echo "=================================================="
###     echo ""
###     rbenv rehash
###     powder install
### fi

package_list="rails bundler"
for package in ${package_list} ; do
    if [ "`gem list | grep ${package}`" = "" ]; then
        echo ""
        echo "=================================================="
        echo ""
        echo "installing ${package} ..."
        echo ""
        echo "=================================================="
        echo ""
        sudo gem install ${package}
    fi
    ### settings aafter installation
    rbenv rehash
    source ~/.profile
done

echo ""
echo "finished installing Ruby and corresponding packages"
echo ""

echo ""
echo "cleaning brew up..."
echo ""

brew prune
brew cleanup -s

echo ""
echo "finished cleaning brew up"
echo ""


echo ""
echo ""
echo "#################################################"
echo "                                                #"
echo "   Settings installed packages                  #"
echo "                                                #"
echo "#################################################"
echo ""
echo ""

echo ""
echo "=================================================="
echo ""
echo "To have launchd start homebrew/apache/httpd24 at login"
echo ""
echo "=================================================="
echo ""

ln -sfv /usr/local/opt/httpd24/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.httpd24.plist

echo ""
echo "=================================================="
echo ""
echo "※ これをしておかないと"
echo "$ jspm install -y"
echo "でエラーが出るっぽい"
echo ""
echo "set up the GitHub credential:"
echo "enter your username and password"

echo "=================================================="
echo ""

# jspm registry config github

#  echo ""
#  echo "=================================================="
#  echo ""
#  echo "setting MySQL ..."
#  echo ""
#  echo "=================================================="
#  echo ""
#  mysqladmin -u root password
#  
#  echo ""
#  echo "finished settings MySQL"
#  echo ""
```