Created
July 30, 2019 09:51
-
-
Save misaka/594fc32e34b1e53270664e8c3f34a9ad to your computer and use it in GitHub Desktop.
Homedirectory installer thing.
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 | |
while [ -n "$*" ] | |
do | |
opt=$1 | |
shift | |
case $opt in | |
-f|--force) | |
force=1 | |
;; | |
-v|--verbose) | |
verbose_mode=1 | |
;; | |
-q|--quiet) | |
quiet_mode=1 | |
;; | |
-h|--help) | |
echo "Usage: install.sh [-f] [-v] [-q]" | |
exit 0 | |
;; | |
esac | |
done | |
verbose() { | |
if [ -n "$verbose_mode" ] | |
then | |
echo $* | |
fi | |
} | |
say() { | |
if [ -z "$quiet_mode" ] | |
then | |
echo "$*" | |
fi | |
} | |
original_dir=`pwd` | |
cd `dirname $0` | |
dothome_full_dir=`pwd` | |
dothome_dir=${dothome_full_dir#$HOME/} | |
# Make sure other submodules and sub-submodules are up-to-date | |
git submodule update --init --recursive | |
cd $HOME | |
if [ -d "$dothome_dir/dotfiles/" ] | |
then | |
for dotfile in $dothome_dir/dotfiles/* | |
do | |
[[ $dotfile == *~ ]] && continue | |
dotfile_base=${dotfile##$dothome_dir/dotfiles/} | |
if [[ $dotfile == *.no-dot ]] | |
then | |
dotfile_home=~/${dotfile_base%.no-dot} | |
else | |
dotfile_home=~/.$dotfile_base | |
fi | |
if [[ -e "$dotfile_home" ]] && [[ -n "$force" ]] | |
then | |
if [[ $dotfile_base == *.local ]] | |
then | |
verbose "not removing local file $dotfile_base" | |
continue | |
elif [[ -L $dotfile_home ]] | |
then | |
verbose "rm $dotfile_home" | |
rm $dotfile_home | |
else | |
verbose "cowardly refusing to touch file/dir: $dotfile_home" | |
continue | |
fi | |
fi | |
if [[ ! -e "$dotfile_home" ]] | |
then | |
if [ -L $dotfile_home ] | |
then | |
verbose "replacing broken symlink: $dotfile_home" | |
rm $dotfile_home | |
fi | |
case $dotfile_base in | |
*.local) | |
say "cp $dotfile $dotfile_home" | |
cp $dotfile $dotfile_home | |
;; | |
*) | |
say "ln -s $dotfile $dotfile_home" | |
ln -s $dotfile $dotfile_home | |
;; | |
esac | |
else | |
say "file exists, skipping $dotfile_home" | |
fi | |
done | |
fi | |
say "" | |
say "Done. To install brew packages in ~/Brewfile run:" | |
say "" | |
say " cd ~" | |
say " brew tap homebrew/bundle" | |
say " brew bundle" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment