Add install_file and checkout_repo functions
This commit is contained in:
parent
760d0fb81b
commit
80bf80d416
@ -1,56 +1,87 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -u
|
set -e -u
|
||||||
|
|
||||||
SCRIPTDIR=`dirname \`realpath "${0}"\``
|
|
||||||
REPODIR=`realpath ${SCRIPTDIR}/..`
|
|
||||||
|
|
||||||
git=`command -v git`
|
git=`command -v git`
|
||||||
|
|
||||||
|
SCRIPT=`readlink -m \`type -p "${0}"\``
|
||||||
|
SCRIPTNAME=`basename "${SCRIPT}"`
|
||||||
|
SCRIPTDIR=`dirname "${SCRIPT}"`
|
||||||
|
REPODIR=`realpath ${SCRIPTDIR}/..`
|
||||||
|
|
||||||
msg() {
|
msg() {
|
||||||
echo "`tput bold`${*}`tput sgr0`"
|
echo "`tput bold`${*}`tput sgr0`"
|
||||||
}
|
}
|
||||||
|
|
||||||
info() {
|
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() {
|
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
|
# basic
|
||||||
info "Initializing submodules"
|
info "Initializing new submodules"
|
||||||
"${git}" -C "${REPODIR}" submodule init
|
"${git}" -C "${REPODIR}" submodule init
|
||||||
|
|
||||||
# scripts
|
# scripts
|
||||||
info "Deploying scripts to ~/bin"
|
info "Deploying scripts to ~/bin"
|
||||||
mkdir -p "${HOME}/bin"
|
for script in `find "${SCRIPTDIR}" -mindepth 1 -maxdepth 1 -type f` ; do
|
||||||
for script in `ls "${SCRIPTDIR}"` ; do
|
scriptname="`basename "${script}"`"
|
||||||
ln -s "${SCRIPTDIR}/${script}" "${HOME}/bin/`basename \"${script}\"`"
|
install_file "${script}" "${HOME}/bin/${scriptname}"
|
||||||
done
|
done
|
||||||
|
unset scriptname
|
||||||
|
|
||||||
# bash
|
# bash
|
||||||
info "Deploying bash configuration"
|
info "Deploying bash configuration"
|
||||||
ln -s "${REPODIR}/.bashrc" "${HOME}"
|
install_file "${REPODIR}/.bashrc" "${HOME}"
|
||||||
|
|
||||||
# terminal colors
|
# terminal colors
|
||||||
info "Configuring terminal colors"
|
info "Configuring terminal colors"
|
||||||
mkdir -p "${HOME}/.config"
|
checkout_repo https://github.com/chriskempson/base16-shell.git "${HOME}/.config/base16-shell"
|
||||||
ln -s "${REPODIR}/.config/base16" "${HOME}/.config/"
|
|
||||||
|
|
||||||
# tmux
|
# tmux
|
||||||
info "Configuring tmux"
|
info "Configuring tmux"
|
||||||
ln -s "${REPODIR}/.tmux.conf" "${HOME}"
|
install_file "${REPODIR}/.tmux.conf" "${HOME}/.tmux.conf"
|
||||||
mkdir -p "${HOME}/tmux/plugins"
|
checkout_repo https://github.com/tmux-plugins/tpm "${HOME}/.tmux/plugins/tpm"
|
||||||
"${git}" clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
|
|
||||||
|
|
||||||
# vim
|
# vim
|
||||||
info "Configuring vim"
|
info "Configuring vim"
|
||||||
ln -s "${REPODIR}/.vim/" "${HOME}"
|
ln -s "${REPODIR}/.vim/" "${HOME}/.vim/"
|
||||||
ln -s "${REPODIR}/.vimrc" "${HOME}"
|
install_file "${REPODIR}/.vimrc" "${HOME}/.vimrc"
|
||||||
|
|
||||||
# Update submodules
|
# Update submodules
|
||||||
info "Updating submodules"
|
info "Updating all submodules"
|
||||||
"${git}" -C "${REPODIR}" submodule update --init --recursive --merge --remote
|
"${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