initial commit
This commit is contained in:
commit
f443da5f31
9 changed files with 442 additions and 0 deletions
106
_install.sh
Executable file
106
_install.sh
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
homedir=$HOME
|
||||
basedir=$homedir/.dotfiles
|
||||
bindir=$homedir/bin
|
||||
gitbase=git://github.com/Klowner/dotfiles.git
|
||||
gitorigin=git@github.com:Klowner/dotfiles.git
|
||||
gitbranch=refresh
|
||||
tarball=http://github.com/Klowner/dotfiles/tarball/$gitbranch
|
||||
|
||||
function has() {
|
||||
return $( which $1 >/dev/null)
|
||||
}
|
||||
|
||||
function note() {
|
||||
echo "^[[32;1m * ^[[0m$*"
|
||||
}
|
||||
|
||||
function warn() {
|
||||
echo "^[[31;1m * ^[[0m$*"
|
||||
}
|
||||
|
||||
function die() {
|
||||
warn $*
|
||||
exit 1
|
||||
}
|
||||
|
||||
function link() {
|
||||
src=$1
|
||||
dst=$2
|
||||
if [ -e $dst ]; then
|
||||
if [ -L $dst ]; then
|
||||
# already symlinked
|
||||
return
|
||||
else
|
||||
# rename files with an ".old" extension
|
||||
warn "$dst already exists, renaming to $dst.old"
|
||||
backup=$dst.old
|
||||
if [ -e $backup ]; then
|
||||
die "$backup already exists. Aborting."
|
||||
fi
|
||||
mv -v $dst $backup
|
||||
fi
|
||||
fi
|
||||
|
||||
# Update existing or create new symlinks
|
||||
ln -vsf $src $dst
|
||||
}
|
||||
|
||||
function unpack_tarball() {
|
||||
note "Downloading tarball..."
|
||||
mkdir -vp $basedir
|
||||
cd $basedir
|
||||
tempfile=TEMP.tar.gz
|
||||
if has curl; then
|
||||
curl -L $tarball >$tempfile
|
||||
elif has wget; then
|
||||
wget -O $tempfile $tarball
|
||||
else:
|
||||
die "Can't download tarball."
|
||||
fi
|
||||
tar --strip-components 1 -zxvf $tempfile
|
||||
rm -v $tempfile
|
||||
}
|
||||
|
||||
if [ -e $basedir ]; then
|
||||
# basedir exists, update it.
|
||||
cd $basedir
|
||||
if [ -e .git ]; then
|
||||
note "Updating dotfiles from git..."
|
||||
git pull --rebase origin $gitbranch
|
||||
else
|
||||
unpack_tarball
|
||||
fi
|
||||
else
|
||||
# .dotfiles directory needs to be installed. Try downloading first
|
||||
# with git and then fallback to tarball.
|
||||
if has git; then
|
||||
note "Cloning from git..."
|
||||
git clone $gitbase $basedir
|
||||
cd $basedir
|
||||
git submodule init
|
||||
git submodule update --init --recursive
|
||||
else
|
||||
warn "Git not installed."
|
||||
unpack_tarball
|
||||
fi
|
||||
fi
|
||||
|
||||
note "Symlinking dotfiles..."
|
||||
for path in * ; do
|
||||
# Skip any files beginning with underscores.
|
||||
if [ $(expr match $path '^_') -eq 1 ]; then
|
||||
continue
|
||||
fi
|
||||
echo link $basedir/$path $HOME/.$path
|
||||
done
|
||||
|
||||
mkdir -p $HOME/.config
|
||||
for path in _config/*; do
|
||||
echo link $basedir/_config/$path $HOME/.config/$path
|
||||
done
|
||||
|
||||
note "Done."
|
||||
|
||||
# vim:ts=4:sw=4:et:
|
Loading…
Add table
Add a link
Reference in a new issue