diff options
-rwxr-xr-x | bin/ct | 95 | ||||
-rwxr-xr-x | examples/bootstrap | 96 | ||||
-rwxr-xr-x | examples/pkglist | 16 | ||||
-rwxr-xr-x | test/main | 9 | ||||
-rw-r--r-- | test/setup | 2 |
5 files changed, 92 insertions, 126 deletions
@@ -84,17 +84,21 @@ while [[ $1 == --* ]] { action=$1 ((#)) && shift +# If we already break BC we can at least give a warning ;) + if [[ -n $PKG_ROOT ]] { - PKG_ROOTS+=($PKG_ROOT) - unset PKG_ROOT + warn "There were major, BC-breaking changes to the format of caretaker.conf\n" + warn "Please read caretaker.conf(5) and update it accordingly\n\n" + warn "You'll probably also need to update your pkglist script, see\n" \ + "examples/pkglist in your caretaker repo\n" + exit 1 } if (( $#PKG_ROOTS == 0 )) { die "No package root(s) specified.\n" \ - "Please edit the PKG_ROOTS value in your config file\n" + "Please edit the PKG_ROOTS value in your config file\n" } : ${PKG_DIR:="$HOME/packages"} -: ${PKGLIST_LOCAL=0} : ${CL_OPTIONS:=--quiet} : ${SILENT=0} : ${AUTOUPDATE=1} @@ -104,7 +108,7 @@ if (( $#PKG_ROOTS == 0 )) { : ${MAGIC_ETC=1} : ${PROGRESS=1} export PKG_DIR -export PKG_ROOT +export PKG_PROTO PKG_USER PKG_HOST PKG_UAH PKG_PATH if (( SILENT )) { GIT_SILENT_ARG=--quiet @@ -131,48 +135,30 @@ if [[ ! -d $PKG_DIR ]] { die "Error: Package directory '$PKG_DIR' does not exist\n" } +function pkgroot_setup { + PKGLIST_LOCAL=0 -## -## Setup some additional variables related to PKG_ROOT -## - -function pkgroot_parse { - PKG_ROOT=$1 - - # Protocol - case $PKG_ROOT in - ssh://*) PKG_PROTO='ssh' ;; - git://*) PKG_PROTO='git' ;; - /*) PKG_PROTO='file' ;; - *) die "Error: Unknown protocol in PKG_ROOT '$PKG_ROOT'\n" ;; - esac - - # user, host, path - if [[ $PKG_PROTO == (git|ssh) ]] { - PKG_HOST=${${PKG_ROOT#"${PKG_PROTO}://"}%%/*} - PKG_PATH=${PKG_ROOT#"${PKG_PROTO}://$PKG_HOST"} + if [[ -n ${functions[pkgroot_${1}]} ]] { + pkgroot_${1} + } else { + die "function pkgroot_${1} not defined in caretaker.conf\n" \ + "The config format was changed recently, please consult your" \ + "documentation ;-)\n" + } - if [[ $PKG_HOST == *@* ]] { - PKG_USER=${PKG_HOST%%@*} - PKG_HOST=${PKG_HOST#*@} - PKG_UAH=${PKG_USER}@${PKG_HOST} - } else { - PKG_USER=$USERNAME - PKG_UAH=${PKG_HOST} - } + : ${PKGLIST_PATH:=$PKG_PATH/pkglist} - } elif [[ $PKG_PROTO == 'file' ]] { - PKG_PATH=$PKG_ROOT + if [[ -n ${PKG_USER} ]] { + PKG_UAH="${PKG_USER}@${PKG_HOST}" + } else { + PKG_UAH=${PKG_HOST} } - : ${PKGLIST_PATH:=$PKG_PATH/pkglist} } function pkgroot_clean { - unset PKG_ROOT PKG_PROTO PKG_HOST PKG_PATH PKG_USER PKG_UAH - (( PKGLIST_LOCAL )) || unset PKGLIST_PATH + unset PKG_PROTO PKG_HOST PKG_PATH PKG_USER PKG_UAH PKGLIST_PATH } - function check_installed { if [[ -z $1 || ! -d $PKG_DIR/$1 ]] { die "Package is not installed: '$1'\n" @@ -236,11 +222,10 @@ function progress { ## VCS Wrappers function vcs_add ( - pkgroot_parse $(list_get_root $1) cd $PKG_DIR if [[ $(list_get_type $1) == git ]] { - git clone "$PKG_ROOT/$1" + git clone $(list_get_uri $1) vcs_setup $1 git config push.default matching } else { @@ -280,9 +265,7 @@ function vcs_pull ( if (( GIT_USE_ORIGIN )) { git pull $GIT_SILENT_ARG } else { - pkgroot_parse $(list_get_root $1) - vcs_branch_is_master $1 && git pull $PKG_ROOT/${PWD:t} master - pkgroot_clean + vcs_branch_is_master $1 && git pull $(list_get_uri $1) master } ) @@ -291,8 +274,7 @@ function vcs_push ( if (( GIT_USE_ORIGIN )) { git push } else { - pkgroot_parse $(list_get_root $1) - vcs_branch_is_master $1 && git push $PKG_ROOT/${PWD:t} master + vcs_branch_is_master $1 && git push $(list_get_uri $1) master } ) @@ -322,7 +304,7 @@ function list_exists { grep -q "^$1 " $PKG_DIR/.list-remote } -function list_get_root { +function list_get_uri { echo - ${$(grep "^$1 " $PKG_DIR/.list-remote)[4]} } @@ -391,12 +373,15 @@ function list_update_remote { typeset tmpfile=$(mktemp -t pkglist.XXXXXX) PKG_ROOT for PKG_ROOT in $PKG_ROOTS; { - pkgroot_parse $PKG_ROOT + pkgroot_setup $PKG_ROOT if [[ $PKGLIST_LOCAL == 1 || $PKG_PROTO == 'file' ]] { - $PKGLIST_PATH $PKG_PATH $PKG_ROOT >> $tmpfile + $PKGLIST_PATH >> $tmpfile } elif [[ $PKG_PROTO == 'ssh' ]] { - ssh $PKG_UAH "$PKGLIST_PATH $PKG_PATH $PKG_ROOT" >> $tmpfile + ssh $PKG_UAH \ + "PKG_PATH=\"${PKG_PATH}\" PKG_UAH=\"${PKG_UAH}\"" \ + "PKG_PROTO=\"${PKG_PROTO}\"" \ + "$PKGLIST_PATH" >> $tmpfile } pkgroot_clean @@ -753,16 +738,16 @@ function pkg_debug { echo " git "${$(git --version)[3]} echo " caretaker "${$(git --git-dir=$self_path/.git/ log -n 1)[2]} echo "--- settings ---" - echo " PKGLIST_LOCAL $PKGLIST_LOCAL" for PKG_ROOT in $PKG_ROOTS; { - pkgroot_parse $PKG_ROOT + pkgroot_setup $PKG_ROOT echo " PKG_ROOT $PKG_ROOT" echo " PKG_PROTO $PKG_PROTO" echo " PKG_USER $PKG_USER" echo " PKG_HOST $PKG_HOST" echo " PKG_UAH $PKG_UAH" - echo " PKGLIST_PATH $PKGLIST_PATH" + echo " PKGLIST_PATH ${PKGLIST_PATH}" + echo " PKGLIST_LOCAL ${PKGLIST_LOCAL}" pkgroot_clean } @@ -782,14 +767,14 @@ function pkg_help { function pkg_info { list_is_installed $1 || list_exists $1 || die "No such package: $1\n" - list_exists $1 && pkgroot_parse $(list_get_root $1) typeset name=$1 package_root=$PKG_ROOT typeset repo_type=$(list_get_type $1) typeset priority priority_name typeset hooks makefile description state + typeset uri - pkgroot_clean + list_exists $1 && uri=$(list_get_uri $1) if [[ -d $1 ]] { cd $1 @@ -831,7 +816,7 @@ function pkg_info { } show_info 'Package' $name - show_info 'Source' $package_root + show_info 'Source' $uri show_info 'State' $state [[ -n $priority ]] && show_info 'Priority' "$priority ($priority_name)" diff --git a/examples/bootstrap b/examples/bootstrap index 68289ee..5c03803 100755 --- a/examples/bootstrap +++ b/examples/bootstrap @@ -7,42 +7,47 @@ setopt err_exit trap "print -P '\n%N:%i: bootstrap failed ($?)'" ZERR -typeset -i rcempty=0 pkglist_cgi=0 +typeset -i rcempty=0 typeset PKG_ROOT PKG_DIR default_path='~/packages' : ${XDG_CONFIG_HOME=$HOME/.config} -while [[ $1 == --* ]] { - case $1 in - --pkglist-cgi) - pkglist_cgi=1 - pkglist_cgi_url=$2 - shift - ;; - esac - shift -} +if ! which git &> /dev/null; then + echo - 'It appears that git is not available on this system.' + echo - '-Installation aborted-' + exit 200 +fi -if [[ -n $1 ]] { - PKG_ROOT=$1 - PKG_DIR=${~${2-$default_path}} +if [[ $# -ge 4 ]] { + PKG_PROTO=$1 + PKG_USER=$2 + PKG_HOST=$3 + PKG_PATH=$4 + PKG_DIR=${~${5-$default_path}} } else { cat <<- meow - Usage: ./bootstrap [options] PKG_ROOT [PKG_DIR] - PKG_ROOT is an URI, either of the form proto://host/path (if the package root is - on a remote machine), or just /path for a local package root. - Note: The path must be absolute, it may not contain a literal ~ - Also note: proto must be either 'ssh' or 'git' - PKG_DIR is the path where caretaker and all further packages will be installed, + 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 - Options: - - --pkglist-cgi URL - Get the package list from URL (http://...) - most useful with a git:// PKG_ROOT + 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 ]] { @@ -56,49 +61,26 @@ mkdir -p ~/bin path=(~/bin $path) mkdir -p $PKG_DIR/.collected/man/man{1..8} -if ! which git &> /dev/null; then - echo 'It appears that git is not available on this system.' - echo '-Installation aborted-' - exit 200 -fi - echo 'Fetching the caretaker package...' cd $PKG_DIR -git clone $PKG_ROOT/caretaker caretaker +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_ROOT=($PKG_ROOT) - PKG_DIR="${PKG_DIR/$HOME/\$HOME}" + 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_cgi )) { - - if which curl &> /dev/null; then - getcmd='curl -s' - elif which wget &> /dev/null; then - getcmd='wget -q -O -' - else - print STDERR "Unable to find a proper download program, fix $PKG_DIR/.pkglist\n" - getcmd='echo fixme >&2; exit 1;' - fi - - cat >> $XDG_CONFIG_HOME/caretaker/caretaker.conf <<-flurbl - PKGLIST_LOCAL=1 - PKGLIST_PATH=$PKG_DIR/.pkglist - flurbl - - cat > $PKG_DIR/.pkglist <<-flurbl - #!/bin/sh - $getcmd $pkglist_cgi_url - flurbl - - chmod +x $PKG_DIR/.pkglist -} - echo 'Installing caretaker package' rehash diff --git a/examples/pkglist b/examples/pkglist index 7e6747f..5faf3a8 100755 --- a/examples/pkglist +++ b/examples/pkglist @@ -1,22 +1,20 @@ #!/usr/bin/env zsh ## on the PKG_HOST: list available packages ## used by ct update remote -## the PKG_PATH (package root path) is given as first argument ($1) -if [[ -z $1 ]] { - echo "Usage: $0 <package root path>" >&2 +if [[ -z ${PKG_PATH} || -z ${PKG_PROTO} ]] { + echo "PKG_PATH and PKG_PROTO must be set while running $0" >&2 exit 1 } -if [[ ! -d $1 ]] { - echo "$0: package root directory '$1' does not exist!" >&2 +if [[ ! -d ${PKG_PATH} ]] { + echo "$0: package root directory '$PKG_PATH' does not exist!" >&2 exit 1 } setopt err_exit -cd $1 -shift +cd $PKG_PATH for dir in *(-/); { @@ -24,13 +22,13 @@ for dir in *(-/); { if [[ -d $dir/.git ]] { echo -n "$dir git " echo -n ${$(git --git-dir=$dir/.git log -n 1)[2]} - echo " $*" + echo " ${PKG_PROTO}://${PKG_UAH}/${PKG_PATH}/${dir}/.git" # bare git repo } elif [[ -d $dir/objects && -d $dir/refs ]] { echo -n "$dir git " echo -n ${$(git --git-dir=$dir log -n 1)[2]} - echo " $*" + echo " ${PKG_PROTO}://${PKG_UAH}/${PKG_PATH}/${dir}" # unknown } else { @@ -11,10 +11,11 @@ function stringcmp { diff -u <(echo $1) <(echo $2) } +mkdir -p /tmp/cttest tests=$PWD/test -test_pdir=$(mktemp -dt pkgdir.XXXXXX) -test_proot=$(mktemp -dt pkgroot.XXXXXX) -test_home=$(mktemp -dt pkghome.XXXXXX) +test_pdir=$(mktemp -d /tmp/cttest/pkgdir.XXXXXX) +test_proot=$(mktemp -d /tmp/cttest/pkgroot.XXXXXX) +test_home=$(mktemp -d /tmp/cttest/pkghome.XXXXXX) export PATH=$PWD/bin:$PATH @@ -31,7 +32,7 @@ source $tests/checklinks (source $tests/setup) echo "# bootstrapping PKG_DIR" -$test_proot/caretaker/examples/bootstrap $test_proot $test_pdir +$test_proot/caretaker/examples/bootstrap file '' '' $test_proot $test_pdir echo "# checking for success" [[ -e $test_home/.config/caretaker/caretaker.conf ]] @@ -1,7 +1,7 @@ ## vim:ft=zsh echo "# setting up PKG_ROOT" cd $test_proot -git clone --quiet ${1-git://git.tabularazor.org/~derf/caretaker} caretaker +git clone --quiet ${1-git://derf.homelinux.org/caretaker} caretaker cp caretaker/examples/pkglist pkglist for repo in ra rb rc; ( mkdir $repo |