Skip to content

Commit

Permalink
Merge pull request #631 from jrobeson/cleanup-bootstrap
Browse files Browse the repository at this point in the history
Refactor/cleanup bootstrap.sh
  • Loading branch information
spf13 committed Apr 29, 2015
2 parents 80f430d + 1ceb2ca commit f8ae915
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 132 deletions.
162 changes: 77 additions & 85 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

############################ SETUP PARAMETERS
app_name='spf13-vim'
app_dir="$HOME/.spf13-vim-3"
[ -z "$git_uri" ] && git_uri='https://github.com/spf13/spf13-vim.git'
git_branch='3.0'
[ -z "$APP_PATH" ] && APP_PATH="$HOME/.spf13-vim-3"
[ -z "$REPO_URI" ] && REPO_URI='https://github.com/spf13/spf13-vim.git'
[ -z "$REPO_BRANCH" ] && REPO_BRANCH='3.0'
debug_mode='0'
fork_maintainer='0'
[ -z "$VUNDLE_URI" ] && VUNDLE_URI="https://github.com/gmarik/vundle.git"
Expand All @@ -30,18 +30,18 @@ msg() {

success() {
if [ "$ret" -eq '0' ]; then
msg "\e[32m[✔]\e[0m ${1}${2}"
msg "\33[32m[✔]\33[0m ${1}${2}"
fi
}

error() {
msg "\e[31m[✘]\e[0m ${1}${2}"
msg "\33[31m[✘]\33[0m ${1}${2}"
exit 1
}

debug() {
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
fi
}

Expand All @@ -51,7 +51,7 @@ program_exists() {

# throw error on non-zero return value
if [ ! "$ret" -eq '0' ]; then
error "$2"
error "You must have '$1' installed to continue."
fi
}

Expand All @@ -61,7 +61,6 @@ variable_set() {
fi
}

############################ SETUP FUNCTIONS
lnif() {
if [ -e "$1" ]; then
ln -sf "$1" "$2"
Expand All @@ -70,129 +69,122 @@ lnif() {
debug
}

############################ SETUP FUNCTIONS

do_backup() {
if [ -e "$2" ] || [ -e "$3" ] || [ -e "$4" ]; then
if [ -e "$1" ] || [ -e "$2" ] || [ -e "$3" ]; then
msg "Attempting to back up your original vim configuration."
today=`date +%Y%m%d_%s`
for i in "$2" "$3" "$4"; do
[ -e "$i" ] && [ ! -L "$i" ] && mv "$i" "$i.$today";
for i in "$1" "$2" "$3"; do
[ -e "$i" ] && [ ! -L "$i" ] && mv -v "$i" "$i.$today";
done
ret="$?"
success "$1"
success "Your original vim configuration has been backed up."
debug
fi
}

upgrade_repo() {
msg "trying to update $1"

if [ "$1" = "$app_name" ]; then
cd "$app_dir" &&
git pull origin "$git_branch"
fi

if [ "$1" = "vundle" ]; then
cd "$HOME/.vim/bundle/vundle" &&
git pull origin master
fi

ret="$?"
success "$2"
debug
}
sync_repo() {
local repo_path="$1"
local repo_uri="$2"
local repo_branch="$3"
local repo_name="$4"

clone_repo() {
program_exists "git" "Sorry, we cannot continue without GIT, please install it first."
msg "Trying to update $repo_name"

if [ ! -e "$app_dir" ]; then
git clone --recursive -b "$git_branch" "$git_uri" "$app_dir"
if [ ! -e "$repo_path" ]; then
mkdir -p "$repo_path"
git clone -b "$repo_branch" "$repo_uri" "$repo_path"
ret="$?"
success "$1"
debug
success "Successfully cloned $repo_name."
else
upgrade_repo "$app_name" "Successfully updated $app_name"
cd "$repo_path" && git pull origin "$repo_branch"
ret="$?"
success "Successfully updated $repo_name"
fi
}

clone_vundle() {
if [ ! -e "$HOME/.vim/bundle/vundle" ]; then
git clone $VUNDLE_URI "$HOME/.vim/bundle/vundle"
else
upgrade_repo "vundle" "Successfully updated vundle"
fi
ret="$?"
success "$1"
debug
}

create_symlinks() {
endpath="$app_dir"
local source_path="$1"
local target_path="$2"

if [ ! -d "$endpath/.vim/bundle" ]; then
mkdir -p "$endpath/.vim/bundle"
fi
lnif "$source_path/.vimrc" "$target_path/.vimrc"
lnif "$source_path/.vimrc.bundles" "$target_path/.vimrc.bundles"
lnif "$source_path/.vimrc.before" "$target_path/.vimrc.before"
lnif "$source_path/.vim" "$target_path/.vim"

lnif "$endpath/.vimrc" "$HOME/.vimrc"
lnif "$endpath/.vimrc.bundles" "$HOME/.vimrc.bundles"
lnif "$endpath/.vimrc.before" "$HOME/.vimrc.before"
lnif "$endpath/.vim" "$HOME/.vim"
touch "$target_path/.vimrc.local"

# Useful for fork maintainers
touch "$HOME/.vimrc.local"
ret="$?"
success "Setting up vim symlinks."
debug
}

if [ -e "$endpath/.vimrc.fork" ]; then
ln -sf "$endpath/.vimrc.fork" "$HOME/.vimrc.fork"
elif [ "$fork_maintainer" -eq '1' ]; then
touch "$HOME/.vimrc.fork"
touch "$HOME/.vimrc.bundles.fork"
touch "$HOME/.vimrc.before.fork"
fi
setup_fork_mode() {
local source_path="$2"
local target_path="$3"

if [ -e "$endpath/.vimrc.bundles.fork" ]; then
ln -sf "$endpath/.vimrc.bundles.fork" "$HOME/.vimrc.bundles.fork"
fi
if [ "$1" -eq '1' ]; then
touch "$target_path/.vimrc.fork"
touch "$target_path/.vimrc.bundles.fork"
touch "$target_path/.vimrc.before.fork"

if [ -e "$endpath/.vimrc.before.fork" ]; then
ln -sf "$endpath/.vimrc.before.fork" "$HOME/.vimrc.before.fork"
fi
lnif "$source_path/.vimrc.fork" "$target_path/.vimrc.fork"
lnif "$source_path/.vimrc.bundles.fork" "$target_path/.vimrc.bundles.fork"
lnif "$source_path/.vimrc.before.fork" "$target_path/.vimrc.before.fork"

ret="$?"
success "$1"
debug
ret="$?"
success "Created fork maintainer files."
debug
fi
}

setup_vundle() {
system_shell="$SHELL"
local system_shell="$SHELL"
export SHELL='/bin/sh'

vim \
-u "$app_dir/.vimrc.bundles.default" \
-u "$1" \
"+set nomore" \
"+BundleInstall!" \
"+BundleClean" \
"+qall"

export SHELL="$system_shell"

success "$1"
success "Now updating/installing plugins using Vundle"
debug
}

############################ MAIN()
variable_set "$HOME"
program_exists "vim" "To install $app_name you first need to install Vim."
program_exists "vim"
program_exists "git"

do_backup "$HOME/.vim" \
"$HOME/.vimrc" \
"$HOME/.gvimrc"

do_backup "Your old vim stuff has a suffix now and looks like .vim.`date +%Y%m%d%S`" \
"$HOME/.vim" \
"$HOME/.vimrc" \
"$HOME/.gvimrc"
sync_repo "$APP_PATH" \
"$REPO_URI" \
"$REPO_BRANCH" \
"$app_name"

clone_repo "Successfully cloned $app_name"
create_symlinks "$APP_PATH" \
"$HOME"

create_symlinks "Setting up vim symlinks"
setup_fork_mode "$fork_maintainer" \
"$APP_PATH" \
"$HOME"

clone_vundle "Successfully cloned vundle"
sync_repo "$HOME/.vim/bundle/vundle" \
"$VUNDLE_URI" \
"master" \
"vundle"

setup_vundle "Now updating/installing plugins using Vundle"
setup_vundle "$APP_PATH/.vimrc.bundles.default"

msg "\nThanks for installing $app_name."
msg "© `date +%Y` http://vim.spf13.com/"
38 changes: 19 additions & 19 deletions spf13-vim-windows-install.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@ REM limitations under the License.
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

@set APP_DIR=%HOME%\.spf13-vim-3
IF NOT EXIST "%APP_DIR%" (
call git clone --recursive -b 3.0 https://github.com/spf13/spf13-vim.git "%APP_DIR%"
@set APP_PATH=%HOME%\.spf13-vim-3
IF NOT EXIST "%APP_PATH%" (
call git clone -b 3.0 https://github.com/spf13/spf13-vim.git "%APP_PATH%"
) ELSE (
@set ORIGINAL_DIR=%CD%
@set ORIGINAL_DIR=%CD%
echo updating spf13-vim
chdir /d "%APP_DIR%"
call git pull
chdir /d "%APP_PATH%"
call git pull
chdir /d "%ORIGINAL_DIR%"
call cd "%APP_DIR%"
call cd "%APP_PATH%"
)

call mklink "%HOME%\.vimrc" "%APP_DIR%\.vimrc"
call mklink "%HOME%\_vimrc" "%APP_DIR%\.vimrc"
call mklink "%HOME%\.vimrc.fork" "%APP_DIR%\.vimrc.fork"
call mklink "%HOME%\.vimrc.bundles" "%APP_DIR%\.vimrc.bundles"
call mklink "%HOME%\.vimrc.bundles.fork" "%APP_DIR%\.vimrc.bundles.fork"
call mklink "%HOME%\.vimrc.before" "%APP_DIR%\.vimrc.before"
call mklink "%HOME%\.vimrc.before.fork" "%APP_DIR%\.vimrc.before.fork"
call mklink /J "%HOME%\.vim" "%APP_DIR%\.vim"
call mklink "%HOME%\.vimrc" "%APP_PATH%\.vimrc"
call mklink "%HOME%\_vimrc" "%APP_PATH%\.vimrc"
call mklink "%HOME%\.vimrc.fork" "%APP_PATH%\.vimrc.fork"
call mklink "%HOME%\.vimrc.bundles" "%APP_PATH%\.vimrc.bundles"
call mklink "%HOME%\.vimrc.bundles.fork" "%APP_PATH%\.vimrc.bundles.fork"
call mklink "%HOME%\.vimrc.before" "%APP_PATH%\.vimrc.before"
call mklink "%HOME%\.vimrc.before.fork" "%APP_PATH%\.vimrc.before.fork"
call mklink /J "%HOME%\.vim" "%APP_PATH%\.vim"

IF NOT EXIST "%APP_DIR%\.vim\bundle" (
call mkdir "%APP_DIR%\.vim\bundle"
IF NOT EXIST "%APP_PATH%\.vim\bundle" (
call mkdir "%APP_PATH%\.vim\bundle"
)

IF NOT EXIST "%HOME%/.vim/bundle/vundle" (
call git clone https://github.com/gmarik/vundle.git "%HOME%/.vim/bundle/vundle"
call git clone https://github.com/gmarik/vundle.git "%HOME%/.vim/bundle/vundle"
) ELSE (
call cd "%HOME%/.vim/bundle/vundle"
call git pull
call cd %HOME%
)

call vim -u "%APP_DIR%/.vimrc.bundles" +BundleInstall! +BundleClean +qall
call vim -u "%APP_PATH%/.vimrc.bundles" +BundleInstall! +BundleClean +qall
56 changes: 28 additions & 28 deletions spf13-vim-windows-xp-install.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@ REM limitations under the License.
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

@set APP_DIR=%HOME%\.spf13-vim-3
@set APP_PATH=%HOME%\.spf13-vim-3

@if not exist "%APP_DIR%" (
echo backing up existing vim config
@set today=%DATE%
@if exist "%HOME%\.vim" call xcopy /s/e/h/y/r/q/i "%HOME%\.vim" "%HOME%\.vim.%today%"
@if exist "%HOME%\.vimrc" call copy "%HOME%\.vimrc" "%HOME%\.vimrc.%today%"
@if exist "%HOME%\_vimrc" call copy "%HOME%\_vimrc" "%HOME%\_vimrc.%today%"
@if exist "%HOME%\.gvimrc" call copy "%HOME%\.gvimrc" "%HOME%\.gvimrc.%today%"
)
@if not exist "%APP_PATH%" (
echo backing up existing vim config
@set today=%DATE%
@if exist "%HOME%\.vim" call xcopy /s/e/h/y/r/q/i "%HOME%\.vim" "%HOME%\.vim.%today%"
@if exist "%HOME%\.vimrc" call copy "%HOME%\.vimrc" "%HOME%\.vimrc.%today%"
@if exist "%HOME%\_vimrc" call copy "%HOME%\_vimrc" "%HOME%\_vimrc.%today%"
@if exist "%HOME%\.gvimrc" call copy "%HOME%\.gvimrc" "%HOME%\.gvimrc.%today%"
)

@if exist "%APP_DIR%" (
@set ORIGINAL_DIR=%CD%
echo updating spf13-vim
chdir /d "%APP_DIR%" && git pull
chdir /d "%ORIGINAL_DIR%"
) else (
echo cloning spf13-vim
call git clone --recursive -b 3.0 git://github.com/spf13/spf13-vim.git "%APP_DIR%"
)
@if exist "%APP_PATH%" (
@set ORIGINAL_DIR=%CD%
echo updating spf13-vim
chdir /d "%APP_PATH%" && git pull
chdir /d "%ORIGINAL_DIR%"
) else (
echo cloning spf13-vim
call git clone -b 3.0 git://github.com/spf13/spf13-vim.git "%APP_PATH%"
)

@if not exist "%APP_DIR%\.vim\bundle" call mkdir "%APP_DIR%\.vim\bundle"
call xcopy /s/e/h/y/r/q/i "%APP_DIR%\.vim" "%HOME%\.vim"
call copy "%APP_DIR%\.vimrc" "%HOME%\.vimrc"
call copy "%APP_DIR%\.vimrc" "%HOME%\_vimrc"
call copy "%APP_DIR%\.vimrc.fork" "%HOME%\.vimrc.fork"
call copy "%APP_DIR%\.vimrc.bundles" "%HOME%\.vimrc.bundles"
call copy "%APP_DIR%\.vimrc.bundles.fork" "%HOME%\.vimrc.bundles.fork"
call copy "%APP_DIR%\.vimrc.before" "%HOME%\.vimrc.before"
call copy "%APP_DIR%\.vimrc.before.fork" "%HOME%\.vimrc.before.fork"
@if not exist "%APP_PATH%\.vim\bundle" call mkdir "%APP_PATH%\.vim\bundle"
call xcopy /s/e/h/y/r/q/i "%APP_PATH%\.vim" "%HOME%\.vim"
call copy "%APP_PATH%\.vimrc" "%HOME%\.vimrc"
call copy "%APP_PATH%\.vimrc" "%HOME%\_vimrc"
call copy "%APP_PATH%\.vimrc.fork" "%HOME%\.vimrc.fork"
call copy "%APP_PATH%\.vimrc.bundles" "%HOME%\.vimrc.bundles"
call copy "%APP_PATH%\.vimrc.bundles.fork" "%HOME%\.vimrc.bundles.fork"
call copy "%APP_PATH%\.vimrc.before" "%HOME%\.vimrc.before"
call copy "%APP_PATH%\.vimrc.before.fork" "%HOME%\.vimrc.before.fork"

@if not exist "%HOME%/.vim/bundle/vundle" call git clone https://github.com/gmarik/vundle.git "%HOME%/.vim/bundle/vundle"
call vim -u "%APP_DIR%/.vimrc.bundles" - +BundleInstall! +BundleClean +qall
call vim -u "%APP_PATH%/.vimrc.bundles" - +BundleInstall! +BundleClean +qall

0 comments on commit f8ae915

Please sign in to comment.