Skip to content

Commit

Permalink
feat(backup): retain backups and avoid manipulating .ssh folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Deavon McCaffery committed Aug 19, 2016
1 parent 1362289 commit 132af0a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 51 deletions.
113 changes: 65 additions & 48 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,82 +1,88 @@
echo "Removing old backup..."
rm -rf backup 1>/dev/null 2>&1
CLR_SUCCESS="\033[1;32m" # BRIGHT GREEN
CLR_CLEAR="\033[0m" # DEFAULT COLOR

if test -d ~/.ssh; then
echo "Creating backup path..."
mkdir -p backup/ssh 1>/dev/null 2>&1
now=$(date +"%Y%m%d_%H%M%S")

echo "Backing up ~/.ssh..."
cp -R ~/.ssh/* backup/ssh 1>/dev/null 2>&1
success "Creating backup path : $pwd/backup/$now..."
mkdir -p "backup/$now" 1>/dev/null

function success() {
echo -e "${CLR_SUCCESS}$1${CLR_CLEAR}"
}

if test -d ~/.uber; then
success "Backing up ~/.uber..."
cp -R ~/.uber/* "backup/$now" 1>/dev/null

echo "Removing ~/.ssh..."
rm -rf ~/.ssh 1>/dev/null 2>&1
success "Removing ~/.uber..."
rm -rf ~/.uber 1>/dev/null
fi

echo "Creating ~/.ssh..."
mkdir -p ~/.ssh 1>/dev/null 2>&1
success "Creating ~/.uber..."
mkdir -p ~/.uber 1>/dev/null

echo "Installing uber to ~/.ssh..."
cp -Rf src/* ~/.ssh 1>/dev/null 2>&1
success "Installing uber to ~/.uber..."
cp -Rf src/* ~/.uber 1>/dev/null

if test -f backup/ssh/scripts/bookmarks.sh; then
echo "Restoring bookmarks..."
cp -R backup/ssh/scripts/bookmarks.sh ~/.ssh/scripts 1>/dev/null 2>&1
if test -f backup/uber/scripts/bookmarks.sh; then
success "Restoring bookmarks..."
cp -R backup/uber/scripts/bookmarks.sh ~/.uber/scripts 1>/dev/null
fi

if test -f ~/.bash_profile; then
echo "Backing up bash profile..."
success "Backing up bash profile..."
cp ~/.bash_profile backup/bash_profile

if ! $(grep -q "~/.ssh/bashrc" ~/.bash_profile); then
echo "Sourcing uber in bash profile..."
if ! $(grep -q "~/.uber/bashrc" ~/.bash_profile); then
success "Sourcing uber in bash profile..."
cat template >> ~/.bash_profile
fi
else
echo "Sourcing uber in bash profile..."
success "Sourcing uber in bash profile..."
cat template > ~/.bash_profile
fi

LOCAL_PREFIX=/usr/local

if test "$(uname)" = "Darwin"; then
if ! type brew 2>/dev/null; then
echo "Installing Homebrew..."
success "Installing Homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

LOCAL_PREFIX=$(brew --prefix)

echo "Updating Homebrew..."
brew update 1>/dev/null 2>&1
success "Updating Homebrew..."
brew update 1>/dev/null

for pkg in git-flow; do
if brew list -1 | grep -q "^${pkg}\$"; then
echo "Uninstalling $pkg..."
success "Uninstalling $pkg..."
brew uninstall ${pkg}
fi
done

rm -rf "$LOCAL_PREFIX/etc/bash_completion.d/git-prompt.sh" 1>/dev/null 2>&1
rm -rf "$LOCAL_PREFIX/etc/bash_completion.d/git-prompt.sh" 1>/dev/null

for pkg in git git-extras git-flow-avh gnu-getopt mono homebrew/versions/node5 openssl; do
if brew list -1 | grep -q "^${pkg}\$"; then
echo "Upgrading $pkg..."
brew upgrade ${pkg} 1>/dev/null 2>&1
success "Upgrading $pkg..."
brew upgrade ${pkg} 1>/dev/null
else
echo "Installing $pkg..."
success "Installing $pkg..."
brew install ${pkg}
fi
done

git config --system credential.helper osxkeychain

echo "Tapping extended versions for caskroom..."
brew tap caskroom/versions 1>/dev/null 2>&1
success "Tapping extended versions for caskroom..."
brew tap caskroom/versions 1>/dev/null

elif test "$(uname)" = "MINGW64_NT-10.0"; then
LOCAL_PREFIX=$LOCALAPPDATA/git

mkdir -p "$LOCAL_PREFIX" 1>/dev/null 2>&1
mkdir -p "$LOCAL_PREFIX" 1>/dev/null
fi

gitpromptname=git-prompt.sh
Expand All @@ -86,28 +92,39 @@ gitprompturi=https://raw.githubusercontent.com/lyze/posh-git-sh/master/$gitpromp
gitcompleteuri=https://raw.githubusercontent.com/petervanderdoes/git-flow-completion/develop/$gitcompletename

if test -f "$gitprompt/$gitcompletename"; then
echo "Removing git flow bash completion..."
rm -rf "$gitprompt/$gitcompletename" 1>/dev/null 2>&1
success "Removing git flow bash completion..."
rm -rf "$gitprompt/$gitcompletename" 1>/dev/null
fi

if test -f "$gitprompt/$gitpromptname"; then
echo "Removing crappy git-prompt..."
rm -rf "$gitprompt/$gitpromptname" 1>/dev/null 2>&1
success "Removing crappy git-prompt..."
rm -rf "$gitprompt/$gitpromptname" 1>/dev/null
else
mkdir -p "$gitprompt" 1>/dev/null 2>&1
mkdir -p "$gitprompt" 1>/dev/null
fi

success "Downloading better git-prompt..."
result=$(curl -s -L -D - "$gitprompturi" -o "$gitpromptname" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if test "$result" = "200"; then
success "Installing successfully downloaded git-prompt..."
cp $gitpromptname "$gitprompt" 1>/dev/null
rm -rf $gitpromptname 1>/dev/null
fi

echo "Downloading better git-prompt..."
result=$(curl -L -D - "$gitprompturi" -o "$gitpromptname" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
test "$result" = "200" && cp $gitpromptname "$gitprompt" && rm -rf $gitpromptname
success "Downloading git-flow completion..."
result=$(curl -s -L -D - "$gitcompleteuri" -o "$gitcompletename" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

echo "Downloading git-flow completion..."
result=$(curl -L -D - "$gitcompleteuri" -o "$gitcompletename" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
test "$result" = "200" && cp $gitcompletename "$gitprompt" && rm -rf $gitcompletename
if test "$result" = "200"; then
success "Installing successfully downloaded git-flow completion..."
cp $gitcompletename "$gitprompt" 1>/dev/null
rm -rf $gitcompletename 1>/dev/null
fi

echo
echo '######################################'
echo '######################################'
echo 'PLEASE OPEN A NEW TERMINAL WINDOW...'
echo '######################################'
echo '######################################'
echo -e "${CLR_SUCCESS}"
echo "#######################################"
echo "#######################################"
echo " PLEASE OPEN A NEW TERMINAL WINDOW"
echo "#######################################"
echo "#######################################"
echo -e "${CLR_CLEAR}"
6 changes: 5 additions & 1 deletion src/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export CLR_BRIGHT_MAGENTA='\033[1;35m' # BRIGHT MAGENTA (PURPLE)
export CLR_BRIGHT_CYAN='\033[1;36m' # BRIGHT CYAN
export CLR_BRIGHT_WHITE='\033[1;37m' # BRIGHT WHITE

export CLR_SUCCESS=$CLR_BRIGHT_GREEN # COLOR FOR SUCCESS MESSAGES
export CLR_FAIL=$CLR_RED # COLOR FOR ERROR MESSAGES
export CLR_RESET=$CLR_CLEAR # ALIAS FOR CLEAR COLOR

export CLR_ROOT_PROMPT=$CLR_BRIGHT_RED # COLOR OF THE PROMPT FOR ROOT
export CLR_STAFF_PROMPT=$CLR_BRIGHT_GREEN # COLOR OF THE PROMPT FOR STAFF
export CLR_USER_PROMPT=$CLR_BRIGHT_BLUE # COLOR OF THE PROMPT FOR USERS
Expand Down Expand Up @@ -58,7 +62,7 @@ if test -f /etc/bash_completion; then
fi

# source scripts
for script in ~/.ssh/scripts/*.sh; do
for script in ~/.uber/scripts/*.sh; do
source $script
done

Expand Down
4 changes: 2 additions & 2 deletions template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

if test -f ~/.ssh/bashrc; then
. ~/.ssh/bashrc
if test -f ~/.uber/bashrc; then
. ~/.uber/bashrc
fi

0 comments on commit 132af0a

Please sign in to comment.