sh 在新机器上设置环境

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在新机器上设置环境相关的知识,希望对你有一定的参考价值。

#!/bin/bash     #Explicitly tell shell this is a bash script
set -e          #Exit as soon as any line in the bash script fails
set -x          #Prints each command executed (prefix with ++)
#set -ex         #Do both (for good practice)

brews=(
  #caskroom/cask/brew-cask #for some casks like sublime-text3 - doesnt work
  bash
  #git
  git-extras
  #go
  #gpg
  hh #zsh and bash history suggestbox
  htop
  httpie #CLI HTTP client, user-friendly curl replacement with intuitive UI, JSON support, syntax highlighting
  iftop #iftop does for network usage what top(1) does for CPU usage. listens to nw traffic on a named interface and displays a table of current bandwidth usage by pairs of hosts. 
  lnav #log file navigator
  gpg #http://blog.ghostinthemachines.com/2015/03/01/how-to-use-gpg-command-line/
  #macvim
  nmap
  node #npm is install along
  #python
  python3
  #stormssh
  #tmux
  tree
  #wget
  watchman #react-native setup
)

casks=(
  adobe-reader
  #totalfinder
  commander-one #dual pane file management
  #atom
  teamviewer
  #cakebrew #ui for homebrew
  cleanmymac
  caffeine
  #datagrip
  dockertoolbox
  #docker-for-mac #doesnt work
  dropbox
  evernote
  firefox
  #franz #messaging client for all
  hipchat
  google-chrome
  google-drive
  #github-desktop
  #hosts
  #handbrake #The open source video transcoder
  #intellij-idea
  webstorm
  #blocs #fails
# istat-menus #paid
  #istat-server
  #licecap #LICEcap can capture an area of your desktop and save it directly to .GIF
  iterm2
  qlcolorcode #quick look syntax highlighting
  #qlmarkdown #QuickLook generator for Markdown files
  #qlstephen # view plain text files without a file extension
  quicklook-json # view json and expand collapse nodes
  #quicklook-csv
  launchrocket # Mac PreferencePane for managing services with launchd
  #sublime-text3 #doesnt work
  sublime-text
  visual-studio-code
  #microsoft-office
  private-eye #When an app makes a network connection, you see it instantly on your screen.
  #satellite-eyes #utomatically changes your desktop wallpaper to the satellite view of where you are, right now.
  skype
  slack
  shiftit
  #steam
  #tunnelbear
  vlc
  #sketch #via helpdesk
  #volumemixer #app specific volume control
)

pips=(
  #glances
)

pips3=(
  stups
  awscli
  zmon-cli
)

gems=(
  bundle
)

npms=(
  kill-tabs # Chrome tab processes are killed
  #n # node version management
  react-native-cli
  react-native-ignite
)

git_configs=(
  #"branch.autoSetupRebase always"
  "color.ui auto"
  #"core.autocrlf input"
  #"core.pager ''"
  #"credential.helper osxkeychain"
  #"merge.ff false"
  #"pull.rebase true"
  #"push.default simple"
  #"rebase.autostash true"
  #"rerere.autoUpdate true"
  #"rerere.enabled true"
  "user.name julianusti"
  "user.email julian.ustiyanovych@gmail.com"
)

if test ! $(which brew); then
  echo "Installing Xcode ..."
  xcode-select --install #note: check first xcode-select -p

  echo "Installing Homebrew ..."
  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
  echo "Updating Homebrew ..."
  brew update
  brew upgrade
fi
export HOMEBREW_NO_ANALYTICS=1 #disable anon analytics
brew doctor
brew tap homebrew/dupes

fails=()

function print_red {
  red='\x1B[0;31m'
  NC='\x1B[0m' # no color
  echo -e "${red}$1${NC}"
}

function install {
  cmd=$1
  shift
  for pkg in $@;
  do
    exec="$cmd $pkg"
    echo "Executing: $exec"
    if $exec ; then
      echo "Installed $pkg"
    else
      fails+=($pkg)
      print_red "Failed to execute: $exec"
    fi
  done
}

# echo "Installing ruby ..."
# brew install ruby-install chruby
# ruby-install ruby
# chruby ruby-2.3.0
# ruby -v

echo "Installing Java ..."
brew cask install java

echo "Installing packages ..."
brew info ${brews[@]}
install 'brew install' ${brews[@]}

echo "Tapping casks ..."
brew tap caskroom/fonts
brew tap caskroom/versions

echo "Installing software ..."
brew cask info ${casks[@]}
install 'brew cask install --appdir=/Applications' ${casks[@]}


echo "Installing secondary packages ..."
# TODO: add info part of install or do reinstall?
install 'pip install --upgrade' ${pips[@]}
install 'gem install' ${gems[@]}
install 'npm install --global' ${npms[@]}
#install 'brew cask install' ${fonts[@]}
install 'pip3 install --upgrade' ${pips3[@]}

echo "Upgrading bash ..."
sudo bash -c "echo $(brew --prefix)/bin/bash >> /private/etc/shells"
cd; curl -#L https://github.com/barryclark/bashstrap/tarball/master | tar -xzv --strip-components 1 --exclude={README.md,screenshot.png}
source ~/.bash_profile


if [ ! -s ~/.zshrc ] #Check if file has size not greater than 0.
then
    #such and such
  echo ""
  echo "Would you like to install oh-my-zsh?  (y/n)"
  read -r response
  if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    source ~/.zshrc
    git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
    grep -F 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' ~/.zshrc || echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> ~/.zshrc
  fi
fi

echo ""
echo "Would you like to set ~/.aws/config for stups/awscli?  (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
mkdir -p ~/.aws
sudo cat >~/.aws/config <<EOL
[default]
region=eu-central-1
output=json
EOL

grep -F 'export LC_ALL=en_US.utf-8' ~/.zshrc || echo 'export LC_ALL=en_US.utf-8' >> ~/.zshrc
grep -F 'export LANG=en_US.utf-8' ~/.zshrc || echo 'export LANG=en_US.utf-8' >> ~/.zshrc
fi


echo "Setting git defaults ..."
for config in "${git_configs[@]}"
do
  git config --global ${config}
done
#gpg --keyserver hkp://pgp.mit.edu --recv ${gpg_key}
#git config --global user.signingkey ${gpg_key}

# echo "Setting up go ..."
# mkdir -p /usr/libs/go
# echo "export GOPATH=/usr/libs/go" >> ~/.bashrc
# echo "export PATH=$PATH:$GOPATH/bin" >> ~/.bashrc

echo "Upgrading ..."
pip3 install --upgrade setuptools
pip3 install --upgrade pip
sudo gem update --system

echo "Cleaning up ..."
brew cleanup
brew cask cleanup
brew linkapps

for fail in ${fails[@]}
do
  echo "Failed to install: $fail"
done

echo "If you have macup, Run `mackup restore` after DropBox has done syncing"

echo "install Sip color picker for mac manually"

#read -p "Hit enter to run [OSX for Hackers] script..." c
#sh -c "$(curl -sL https://gist.githubusercontent.com/brandonb927/3195465/raw/osx-for-hackers.sh)"

以上是关于sh 在新机器上设置环境的主要内容,如果未能解决你的问题,请参考以下文章

sh 在新的OSX机器上安装我想要的东西的脚本

sh 在新的OSX机器上安装我想要的东西的脚本

sh 在新的macOS上设置/安装的事情

sh 在新的macOS上设置/安装的事情

在新机器上设置现有 Heroku 应用程序

如何配置 Chef Solo 以在新的 Vagrant 机器上安装 Nginx?