Last active
January 13, 2019 21:31
-
-
Save gmolveau/9ddc2359e154144a516f665e67032440 to your computer and use it in GitHub Desktop.
Macbook management script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
restore() { | |
if test ! $(which brew); then | |
echo "Installing homebrew" | |
ruby -e "$(curl -fsSl https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
fi | |
read -e -p "Enter the full-path of the backup folder location: " BACKUP_PATH | |
eval BACKUP_PATH=$BACKUP_PATH | |
#------ Brew Install ------# | |
echo "Updating homebrew" | |
brew update | |
echo "Installing homebrew cask" | |
brew cask | |
echo "Cleaning up homebrew" | |
brew cleanup | |
echo "Installing : brew apps" | |
xargs brew install < $BACKUP_PATH/brew.list.txt | |
xargs brew cask install < $BACKUP_PATH/brew.cask.list.txt | |
echo "Cleaning up homebrew" | |
brew cleanup | |
#------ Pip Install ------# | |
echo "Installing : pip apps" | |
pip install -r $BACKUP_PATH/pip.list.txt --user | |
echo "Installing apps from the mac app store" | |
xargs mas install < $BACKUP_PATH/macappstore.list.txt | |
#------ Dev folders ------# | |
echo "Installing oh-my-zsh" | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
mkdir -p ~/dev | |
mkdir -p ~/go | |
#------ ZSH Plugins ------# | |
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh | |
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting | |
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions | |
# ssh | |
echo "backing up : ssh keys" | |
cp -R $BACKUP_PATH/ssh ~/.ssh | |
# zsh | |
echo "backing up : .zshrc" | |
cp $BACKUP_PATH/zshrc ~/.zshrc | |
# home | |
echo "backing up : scripts" | |
cp $BACKUP_PATH/manage.sh ~/manage.sh | |
# screenshot | |
cp $BACKUP_PATH/screenshot.png ~/Pictures/screenshot.png | |
} | |
backup() { | |
TODAY=`date +%Y_%m_%d` | |
BACKUP_NAME="backup_$TODAY" | |
read -e -p "Enter full-path where you want your backup stored: " BACKUP_FOLDER | |
eval BACKUP_FOLDER=$BACKUP_FOLDER | |
BACKUP_PATH=$BACKUP_FOLDER/$BACKUP_NAME | |
# pre cleaning | |
rm -rf $BACKUP_PATH 2> /dev/null | |
mkdir $BACKUP_PATH | |
# dev | |
echo "listing : dev" | |
ls ~/dev > $BACKUP_PATH/dev.list.txt | |
# applications | |
echo "listing : applications" | |
ls /Applications > $BACKUP_PATH/applications_system.list.txt | |
mas list | sed 's/ / #/' > $BACKUP_PATH/macappstore.list.txt | |
# brew | |
echo "listing : brew apps" | |
brew list > $BACKUP_PATH/brew.list.txt | |
brew cask list > $BACKUP_PATH/brew.cask.list.txt | |
# pip | |
echo "listing : pip apps" | |
pip freeze > $BACKUP_PATH/pip.list.txt | |
# go | |
echo "listing : personal go projects - github.com/gmolveau" | |
ls ~/go/src/github.com/gmolveau > $BACKUP_PATH/go.list.txt | |
# ssh | |
echo "backing up : ssh keys" | |
cp -R ~/.ssh $BACKUP_PATH/ssh | |
# zsh | |
echo "backing up : .zshrc" | |
cp ~/.zshrc $BACKUP_PATH/zshrc | |
# home | |
echo "backing up : scripts" | |
cp ~/manage.sh $BACKUP_PATH/manage.sh | |
# Personal Files | |
echo "backing up : Documents - Pictures" | |
cp -R ~/Documents $BACKUP_PATH/Documents | |
cp -R ~/Pictures $BACKUP_PATH/Pictures | |
# checking git repositories | |
find ~ -name .git -type d -prune 2> /dev/null | while read d; do | |
cd $d/.. | |
[[ -z $(git status -s) ]] || echo "$PWD:" repo is not clean | |
cd $OLDPWD | |
done | |
# screen | |
echo "taking screenshot" | |
screencapture $BACKUP_PATH/screenshot.png | |
} | |
update() { | |
echo "updating brew ..." | |
brew update | |
echo "upgrading brew ..." | |
brew upgrade | |
brew cask upgrade | |
echo "cleaning brew ..." | |
brew cleanup -s | |
#now diagnotic | |
brew doctor | |
brew missing | |
brew prune | |
if brew ls --versions mas > /dev/null; then | |
mas upgrade | |
else | |
brew install mas | |
mas upgrade | |
fi | |
echo "updating npm ..." | |
npm update -g | |
echo "updating gem ..." | |
gem update | |
echo "updating pip" | |
pip install --upgrade pip | |
pip freeze | grep -v ‘^\-e’ | cut -d = -f 1 | xargs pip install -U | |
} | |
case "$1" in | |
"backup") | |
backup | |
;; | |
"update") | |
update | |
;; | |
"restore") | |
restore | |
;; | |
*) | |
echo "unknown command" | |
echo "Syntax : \n" | |
echo " manage.sh [options]\n" | |
echo "Options : \n" | |
echo " restore" | |
echo " backup" | |
echo " update" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment