Add install_file and checkout_repo functions
This commit is contained in:
parent
760d0fb81b
commit
80bf80d416
@ -1,56 +1,87 @@
|
||||
#!/bin/sh
|
||||
set -u
|
||||
|
||||
SCRIPTDIR=`dirname \`realpath "${0}"\``
|
||||
REPODIR=`realpath ${SCRIPTDIR}/..`
|
||||
set -e -u
|
||||
|
||||
git=`command -v git`
|
||||
|
||||
SCRIPT=`readlink -m \`type -p "${0}"\``
|
||||
SCRIPTNAME=`basename "${SCRIPT}"`
|
||||
SCRIPTDIR=`dirname "${SCRIPT}"`
|
||||
REPODIR=`realpath ${SCRIPTDIR}/..`
|
||||
|
||||
msg() {
|
||||
echo "`tput bold`${*}`tput sgr0`"
|
||||
echo "`tput bold`${*}`tput sgr0`"
|
||||
}
|
||||
|
||||
info() {
|
||||
echo "`tput bold``tput setaf 2`[INFO]`tput sgr0` `msg ${*}`"
|
||||
echo "[`tput bold``tput setaf 2`INFO`tput sgr0`] `msg ${*}`"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo "[`tput bold``tput setaf 3`WARN`tput sgr0`] `msg ${*}`"
|
||||
}
|
||||
|
||||
err() {
|
||||
echo "`tput bold``tput setaf 1`[ERROR]`tput sgr0` `msg ${*}`"
|
||||
echo "[`tput bold``tput setaf 1`ERROR`tput sgr0`] `msg ${*}`"
|
||||
}
|
||||
|
||||
install_file() {
|
||||
src="${1}"
|
||||
dst="${2}"
|
||||
if [ ! -e "${dst}" ] ; then
|
||||
mkdir -p "`dirname ${dst}`"
|
||||
ln -s "${src}" "${dst}"
|
||||
elif [ -d "${dst}" ] ; then
|
||||
err "${dst} is a directory, expected a file, skipping"
|
||||
elif [ -h "${dst}" ] && [ `realpath "${src}"` == `realpath "$dst"` ] ; then
|
||||
info "`basename ${src}` already installed, skipping"
|
||||
else
|
||||
warn "${dst} is already present but it is not managed by `basename "${0}"`, skipping"
|
||||
fi
|
||||
}
|
||||
|
||||
checkout_repo() {
|
||||
url="${1}"
|
||||
dst="${2}"
|
||||
if [ ! -e "${dst}" ] ; then
|
||||
mkdir -p "`realpath ${dst}/..`"
|
||||
${git} clone "${url}" "$dst"
|
||||
else
|
||||
info "${dst} already present, skipping"
|
||||
fi
|
||||
}
|
||||
|
||||
# basic
|
||||
info "Initializing submodules"
|
||||
info "Initializing new submodules"
|
||||
"${git}" -C "${REPODIR}" submodule init
|
||||
|
||||
# scripts
|
||||
info "Deploying scripts to ~/bin"
|
||||
mkdir -p "${HOME}/bin"
|
||||
for script in `ls "${SCRIPTDIR}"` ; do
|
||||
ln -s "${SCRIPTDIR}/${script}" "${HOME}/bin/`basename \"${script}\"`"
|
||||
for script in `find "${SCRIPTDIR}" -mindepth 1 -maxdepth 1 -type f` ; do
|
||||
scriptname="`basename "${script}"`"
|
||||
install_file "${script}" "${HOME}/bin/${scriptname}"
|
||||
done
|
||||
unset scriptname
|
||||
|
||||
# bash
|
||||
info "Deploying bash configuration"
|
||||
ln -s "${REPODIR}/.bashrc" "${HOME}"
|
||||
install_file "${REPODIR}/.bashrc" "${HOME}"
|
||||
|
||||
# terminal colors
|
||||
info "Configuring terminal colors"
|
||||
mkdir -p "${HOME}/.config"
|
||||
ln -s "${REPODIR}/.config/base16" "${HOME}/.config/"
|
||||
checkout_repo https://github.com/chriskempson/base16-shell.git "${HOME}/.config/base16-shell"
|
||||
|
||||
# tmux
|
||||
info "Configuring tmux"
|
||||
ln -s "${REPODIR}/.tmux.conf" "${HOME}"
|
||||
mkdir -p "${HOME}/tmux/plugins"
|
||||
"${git}" clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
|
||||
install_file "${REPODIR}/.tmux.conf" "${HOME}/.tmux.conf"
|
||||
checkout_repo https://github.com/tmux-plugins/tpm "${HOME}/.tmux/plugins/tpm"
|
||||
|
||||
# vim
|
||||
info "Configuring vim"
|
||||
ln -s "${REPODIR}/.vim/" "${HOME}"
|
||||
ln -s "${REPODIR}/.vimrc" "${HOME}"
|
||||
ln -s "${REPODIR}/.vim/" "${HOME}/.vim/"
|
||||
install_file "${REPODIR}/.vimrc" "${HOME}/.vimrc"
|
||||
|
||||
# Update submodules
|
||||
info "Updating submodules"
|
||||
info "Updating all submodules"
|
||||
"${git}" -C "${REPODIR}" submodule update --init --recursive --merge --remote
|
||||
|
||||
info "Verba volant, scripta manent"
|
||||
info "Done: verba volant, scripta manent"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user