Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 114 lines (97 sloc) 3.07 KB
#!/usr/bin/env zsh
# bootstrap - populate a home with the most necessary scripts
# After running this, other packages can be installed using 'ct'
# Note: Since caretaker is written in zsh, this script also is.
# This way, I don't have to check for zsh somewhere in the script,
# and also have an excuse for using zsh here :P
setopt err_exit
trap "print -P '\n%N:%i: bootstrap failed (${?})'" ZERR
typeset -i rcempty=0
typeset PKG_ROOT PKG_DIR default_path='~/packages'
: ${XDG_CONFIG_HOME=${HOME}/.config}
if ! which git &> /dev/null; then
echo - 'It appears that git is not available on this system.'
echo - '-Installation aborted-'
exit 200
fi
if [[ ${#} -ge 4 ]] {
PKG_PROTO=${1}
PKG_USER=${2}
PKG_HOST=${3}
PKG_PATH=${4}
PKG_DIR=${~${5-${default_path}}}
PKGLIST_PATH=""
if [[ $PKG_PROTO == "gitolite" ]]; then
pkglist_type="$PKG_PROTO"
PKG_PROTO="ssh"
PKGLIST_PATH="\${PKG_DIR}/caretaker/examples/pkglist-${pkglist_type}"
fi
} else {
cat <<- meow
Usage: ./bootstrap PKG_PROTO PKG_USER PKG_HOST PKG_PATH [PKG_DIR]
PKG_PROTO : the protocol type, e.g. ssh, file or git.
PKG_USER : user on the package root host. May be left out if it
is identical to the local user name.
PKG_HOST : remote host to connect to
PKG_PATH : package root path on the remote host
PKG_DIR : the path where caretaker and all further packages will be installed,
by default ${default_path}
Examples: ./bootstrap ssh '' aneurysm /home/derf/var/packages_root
./bootstrap file '' '' /home/derf/var/packages_root
./bootstrap ssh derf derf.homelinux.org /home/derf/var/packages_root
etc.
meow
exit 100
}
if [[ -n ${PKG_USER} ]] {
PKG_UAH="${PKG_USER}@${PKG_HOST}"
} else {
PKG_UAH=${PKG_HOST}
}
# zsh keeps complaining about not having a configuration,
# so let's be kind and give it an empty one.
if ! [[ -e ~/.zshrc ]] {
echo 'Creating empty zshrc'
rcempty=1
touch ~/.zshrc
}
echo 'Creating the basic directory structure'
mkdir -p ~/bin
path=(~/bin ${path})
mkdir -p ${PKG_DIR}/.collected/man/man{1..8}
echo 'Fetching the caretaker package...'
cd ${PKG_DIR}
git clone "${PKG_PROTO}://${PKG_UAH}/${PKG_PATH}/caretaker" caretaker
cd caretaker
echo "Writing ${XDG_CONFIG_HOME}/caretaker/caretaker.conf"
mkdir -p ${XDG_CONFIG_HOME}/caretaker
cat > ${XDG_CONFIG_HOME}/caretaker/caretaker.conf <<- flurbl
PKG_DIR="${PKG_DIR/${HOME}/\${HOME\}}"
PKG_ROOTS=(default)
function pkgroot_default {
PKG_PROTO='${PKG_PROTO}'
PKG_USER='${PKG_USER}'
PKG_HOST='${PKG_HOST}'
PKG_PATH='${PKG_PATH}'
flurbl
if [[ $PKGLIST_PATH != "" ]]; then
cat >> ${XDG_CONFIG_HOME}/caretaker/caretaker.conf <<- flurbl
PKGLIST_LOCAL=1
PKGLIST_PATH="${PKGLIST_PATH}"
flurbl
fi
echo '}' >>${XDG_CONFIG_HOME}/caretaker/caretaker.conf
echo 'Installing caretaker package'
rehash
bin/ct eval update_collected caretaker
bin/ct eval exec_hook caretaker post-add
bin/ct update
if (( rcempty )) {
echo 'Removing empty zshrc'
rm ~/.zshrc
}
cat <<- tac
bootstrap finished.
Package directory: ${PKG_DIR}
config path : ${XDG_CONFIG_HOME}/caretaker/caretaker.conf
tac