1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

117 lines
2.3 KiB

#!/bin/sh
CFG_PATH="$HOME/.config"
CACHE_PATH="$HOME/.cache"
BIN_PATH="$HOME/.local/bin"
# TODO:
# - Change this to a makefile that updates all the relevant files?
# - Precompile stuff
backup_nonlink() {
if ! test -e "$1"; then
return
elif ! test -L "$1"; then
echo " [BUP] $1"
mv -v -n -- "$1" "$1.dotfiles_bak" || exit 1
fi
}
# $1 desired file path (the symlink)
# $2 actual path in dotfiles
set_link() {
if test -L "$1"; then
local curpath=$(readlink -- "$1")
if [ "$curpath" = "$2" ]; then
return
fi
echo " [LINK] $1 -> $2 (was: $curpath)"
rm -f -- "$1"
elif test -e "$1"; then
echo "$1 exists, but is not a symlink" > /dev/stderr
exit 666
else
echo " [LINK] $1 -> $2"
fi
ln -sT -- "$2" "$1"
}
link_home() {
backup_nonlink "$HOME/$@"
echo " [CFG] $@"
set_link "$HOME/$@" "$PWD/home/$@"
}
rm_link_home() {
test -L "$HOME/$@" && \
echo " [RM] $@" && \
rm -f -- "$HOME/$@"
}
link_config() {
# XXX: we probably want to move existing configs into our dir automatically
backup_nonlink "$CFG_PATH"
echo " [CFG] $CFG_PATH"
set_link "$CFG_PATH" "$PWD/config"
}
link_bin() {
local bin_name=${BIN_PATH}/$(basename "$@")
backup_nonlink "$bin_name"
echo " [BIN] $@"
set_link "$bin_name" "$PWD/$@"
}
migrate() {
test -e "$1" && mv -nv "$1" "$2"
}
if [ ! -f deploy.sh ]
then
echo "Probably not what you want!"
exit
fi
mkdir -vp $BIN_PATH $CACHE_PATH
mkdir -pv "$HOME/.cache/vim"
rm_link_home .vimrc
rm_link_home .vim
link_config
# Configuration files
link_home .Xdefaults
link_home .XCompose
link_home .inputrc
link_home .profile
link_home .bash_profile
link_home .bashrc
link_home .zshrc
link_home .gitconfig
link_home .gitignore
link_home .hgrc
link_home .screenrc
link_home .tmux.conf
migrate "$CFG_PATH/shell_history" "$CACHE_PATH/shell_history"
# Tools
link_bin bin/add_paths
link_bin bin/acme-status
link_bin bin/pgen
link_bin tools/unpack/unpack
if [ ! -e ~/.ssh ]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# TOOD: force options
(echo 'HashKnownHosts no'
echo 'AddKeysToAgent yes') >> ~/.ssh/config
fi
./bin/set_sshconfig_entry ben@mus.awoo.nl mus
./bin/set_sshconfig_entry ben@valk.awoo.nl valk
./bin/set_sshconfig_entry ben@das.awoo.nl das