Last active
May 1, 2019 13:46
-
-
Save gmolveau/8ff92a8f5032abbcb512b744478be25e to your computer and use it in GitHub Desktop.
macbook management script
This file contains hidden or 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 gcc); then | |
echo "Installing xcode..." | |
xcode-select --install | |
fi | |
if test ! "$(which brew)"; then | |
echo "Installing homebrew..." | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
else | |
brew update | |
fi | |
read -e -p "Enter the full-path of the backup folder location: " BACKUP_PATH | |
eval BACKUP_PATH=$BACKUP_PATH | |
#------ Brew Install ------# | |
echo "Installing : brew apps" | |
brew bundle install --file=$BACKUP_PATH/brew.list.txt | |
echo "Cleaning up homebrew" | |
brew cleanup | |
#------ Pip Install ------# | |
echo "Installing : pip apps" | |
pip3 install -r $BACKUP_PATH/pip3.list.txt --user | |
#------ 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 | |
# brew | |
echo "listing : brew apps" | |
brew bundle dump --force --describe --file=$BACKUP_PATH/brew.list.txt | |
# pip | |
echo "listing : pip apps" | |
pip3 freeze > $BACKUP_PATH/pip3.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" | |
pip3 install --upgrade pip | |
pip3 freeze | grep -v ‘^\-e’ | cut -d = -f 1 | xargs pip3 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