144 lines
2.7 KiB
Bash
Executable file
144 lines
2.7 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# .$ install joshtronic/dotfiles-test
|
|
# Pulls down dotfiles and installs them
|
|
|
|
# .$ merge joshtronic/dotfiles-test [components]
|
|
# Merges from dotfiles to local, pushes back to repository
|
|
# Components - packages (all packages), apt, brew, gem, npm
|
|
|
|
# .$ pull
|
|
# Pulls remote changes for the installed dotfiles and reruns installation
|
|
|
|
# .$ push
|
|
# Commits and pushes local changes for the installed dotfiles
|
|
|
|
dotmoney=~/.dotmoney
|
|
|
|
# Checks that our directory exists, if not creates it
|
|
if [ ! -d $dotmoney ];
|
|
then
|
|
mkdir $dotmoney
|
|
fi
|
|
|
|
# Checks that a repository is present on install or merge
|
|
if [ $1 == 'install' -o $1 == 'merge' ];
|
|
then
|
|
if [ -z $2 ];
|
|
then
|
|
echo 'Error: Missing repository.'
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
install_dotfiles()
|
|
{
|
|
# Checks if we have a packages.yml
|
|
dotfiles=`cat $dotmoney/installed`
|
|
packages=$dotfiles/packages.yml
|
|
|
|
if [ -e $packages ];
|
|
then
|
|
cat $packages | while read package
|
|
do
|
|
if [[ $package =~ :$ ]];
|
|
then
|
|
manager=`echo $package | tr -d ':'`
|
|
|
|
# Installs `brew` if on OSX and it's not installed
|
|
if [[ `uname` == 'Darwin' && `which brew` == '' ]];
|
|
then
|
|
echo 'Installing `brew`...'
|
|
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
|
|
mkdir -p ~/Library/LaunchAgents
|
|
fi
|
|
|
|
echo "Installing \`$manager\` packages..."
|
|
else
|
|
package=`echo $package | sed -e 's/-//'`
|
|
|
|
case $manager in
|
|
'apt')
|
|
if [ -e /etc/debian_version ];
|
|
then
|
|
sudo aptitude install $package
|
|
fi
|
|
;;
|
|
|
|
'brew')
|
|
brew install $package
|
|
;;
|
|
|
|
# TODO
|
|
# 'composer')
|
|
# ;;
|
|
|
|
'gem')
|
|
sudo gem install $package
|
|
;;
|
|
|
|
'npm')
|
|
npm install -g $package
|
|
;;
|
|
|
|
*)
|
|
echo "Error: Unsupported package manager - $manager"
|
|
exit;
|
|
;;
|
|
esac
|
|
fi
|
|
done
|
|
fi
|
|
|
|
}
|
|
|
|
case $1 in
|
|
'install')
|
|
clone=$dotmoney/$2
|
|
|
|
if [ -d $clone ];
|
|
then
|
|
echo "Updating $2...";
|
|
cd $clone
|
|
git pull origin master
|
|
cd - > /dev/null
|
|
else
|
|
echo "Cloning $2...";
|
|
git clone git@github.com:$2.git $CLONE
|
|
fi
|
|
|
|
echo $clone > $dotmoney/installed
|
|
|
|
install_dotfiles
|
|
;;
|
|
|
|
'merge')
|
|
# Checks that we're not trying to merge our installed repo
|
|
;;
|
|
|
|
'pull')
|
|
echo "Updating $2...";
|
|
cd $clone
|
|
git pull origin master
|
|
cd -
|
|
|
|
install_dotfiles
|
|
;;
|
|
|
|
'push')
|
|
echo "Pushing $2...";
|
|
cd $clone
|
|
git push origin master
|
|
cd -
|
|
;;
|
|
|
|
*)
|
|
echo 'Usage: .$ [action] [repo] [options]'
|
|
echo
|
|
echo 'Examples:'
|
|
echo ' install [repo] - clones the repo and runs an installation'
|
|
echo ' merge [repo] [componet] - merges a repo with the installed repo'
|
|
echo ' pull - pulls changes for the installed repo and re-runs installation'
|
|
echo ' push - pushes changes for the installed repo'
|
|
;;
|
|
esac
|