scriptamanent/bin/scriptamanent

90 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
set -e -u
git=`command -v git`
SCRIPT=`readlink -m \`type -p "${0}"\``
SCRIPTNAME=`basename "${SCRIPT}"`
SCRIPTDIR=`dirname "${SCRIPT}"`
REPODIR=`realpath ${SCRIPTDIR}/..`
refere() {
echo "`tput bold`${*}`tput sgr0`"
}
indica() {
echo "[`tput bold``tput setaf 2`INFO`tput sgr0`] `refere ${*}`"
}
admone() {
echo "[`tput bold``tput setaf 3`WARN`tput sgr0`] `refere ${*}`"
}
erra() {
echo "[`tput bold``tput setaf 1`ERROR`tput sgr0`] `refere ${*}`"
}
persiste() {
src="${1}"
dst="${2}"
if [ ! -e "${dst}" ] ; then
mkdir -p "`dirname ${dst}`"
ln -s "${src}" "${dst}"
elif [ -h "${dst}" ] && [ `realpath "${src}"` == `realpath "$dst"` ] ; then
indica "=> `basename ${src}` already installed, skipping"
else
admone "=> ${dst} is already present but it is not managed by `basename "${0}"`, skipping"
fi
}
inspice() {
url="${1}"
dst="${2}"
if [ ! -e "${dst}" ] ; then
mkdir -p "`echo \`realpath "${dst}"\` | sed 's|/[^/]\+/\?$|/|'`"
${git} clone "${url}" "$dst"
else
indica "${dst} already present, skipping"
fi
}
# basic
indica "Initializing new submodules"
"${git}" -C "${REPODIR}" submodule init
# scripts
indica "Deploying scripts to ~/bin"
for script in `find "${SCRIPTDIR}" -mindepth 1 -maxdepth 1 -type f` ; do
scriptname="`basename "${script}"`"
persiste "${script}" "${HOME}/bin/${scriptname}"
done
unset scriptname
# bash
indica "Deploying bash configuration"
persiste "${REPODIR}/.bashrc" "${HOME}/.bashrc"
# terminal colors
indica "Configuring terminal colors"
inspice https://github.com/chriskempson/base16-shell.git "${HOME}/.config/base16-shell"
# tmux
indica "Configuring tmux"
persiste "${REPODIR}/.tmux.conf" "${HOME}/.tmux.conf"
inspice https://github.com/tmux-plugins/tpm "${HOME}/.tmux/plugins/tpm"
# git
indica "Configuring git"
persiste "${REPODIR}/.gitconfig" "${HOME}/.gitconfig"
# vim
indica "Configuring vim"
persiste "${REPODIR}/.vim" "${HOME}/.vim"
persiste "${REPODIR}/.vimrc" "${HOME}/.vimrc"
# Update submodules
indica "Updating all submodules"
"${git}" -C "${REPODIR}" submodule update --init --recursive --merge --remote
indica "Factum est: verba volant, scripta manent"