diff options
-rwxr-xr-x | bin/pkg | 123 | ||||
-rwxr-xr-x | include/bootstrap | 14 | ||||
-rwxr-xr-x | include/newpackage | 2 | ||||
-rw-r--r-- | man/5/pkg.conf | 2 | ||||
-rw-r--r-- | man/7/pkg | 14 | ||||
-rwxr-xr-x | test/main | 4 |
6 files changed, 83 insertions, 76 deletions
@@ -58,7 +58,7 @@ function say { } function check_installed { - [[ -n $1 && -d $PDIR/$1 ]] || die "Package not installed: '$1'\n" + [[ -n $1 && -d $PKG_DIR/$1 ]] || die "Package not installed: '$1'\n" } function check_valid { @@ -84,7 +84,7 @@ while [[ $1 == --* ]] { --auto-update) AUTOUPDATE=1 ;; --no-auto-update) AUTOUPDATE=0 ;; --checklinks-options) CL_OPTIONS+=$2; shift ;; - --packagedir) PDIR=$2; shift ;; + --packagedir) PKG_DIR=$2; shift ;; --packageroot) PKG_ROOT=$2; shift ;; *) die "Unknown argument: '$1'\n" ;; esac @@ -96,15 +96,22 @@ shift # Default values... or not [[ -n $PKG_ROOT ]] || die "No PKG_ROOT specified. Please edit ~/.pkg.conf\n" -: ${PDIR:="$HOME/packages"} +: ${PKG_DIR:="$HOME/packages"} : ${CL_OPTIONS:=-q} : ${SILENT=0} : ${DEBUG=0} : ${AUTOUPDATE=1} : ${GIT_USE_ORIGIN=1} -export PDIR +export PKG_DIR export PKG_ROOT +# Legacy crap (XXX remove before 1.0 release) +if [[ -n $PDIR ]] { + warn "LEGACY WARNING: use PKG_DIR instead of PDIR (fix your config)\n" + PKG_DIR=$PDIR + unset PDIR +} + # Avoid calling debug without debug mode... just in case one needs more speed if (( !DEBUG )) { unalias debug @@ -125,8 +132,8 @@ if (( SILENT )) { ## Warn otherwise ## -if [[ ! -d $PDIR ]] { - die "Error: Package directory '$PDIR' not found\n" +if [[ ! -d $PKG_DIR ]] { + die "Error: Package directory '$PKG_DIR' not found\n" } @@ -171,7 +178,7 @@ if ((DEBUG)) { echo " PKG_USER $PKG_USER" echo " PKG_HOST $PKG_HOST" echo " PKGLIST_PATH $PKGLIST_PATH" - echo " PDIR $PDIR" + echo " PKG_DIR $PKG_DIR" echo " CL_OPTIONS $CL_OPTIONS" echo " SILENT $SILENT" echo " AUTOUPDATE $AUTOUPDATE" @@ -232,13 +239,13 @@ function progress { ## VCS Wrappers function vcs_setup { - export GIT_DIR=$PDIR/$1/.git - export GIT_WORK_TREE=$PDIR/$1 + export GIT_DIR=$PKG_DIR/$1/.git + export GIT_WORK_TREE=$PKG_DIR/$1 } function vcs_to_list { vcs_setup $1 - if [[ -d $PDIR/$1/.git ]] { + if [[ -d $PKG_DIR/$1/.git ]] { echo -n "$1 git " echo ${$(git log -n 1 master)[2]} } else { @@ -312,19 +319,19 @@ function vcs_fix_origin { ## List stuff function list_is_installed { - grep "^$1 " $PDIR/.list &> /dev/null + grep "^$1 " $PKG_DIR/.list &> /dev/null } function list_exists { - grep "^$1 " $PDIR/.list-remote &> /dev/null + grep "^$1 " $PKG_DIR/.list-remote &> /dev/null } function list_packages_local { - cut -d ' ' -f 1 $PDIR/.list + cut -d ' ' -f 1 $PKG_DIR/.list } function list_packages_remote { - cut -d ' ' -f 1 $PDIR/.list-remote + cut -d ' ' -f 1 $PKG_DIR/.list-remote } function list_incoming { @@ -332,19 +339,19 @@ function list_incoming { } function list_type { - echo ${$(grep "^$1 " $PDIR/.list-remote)[2]} + echo ${$(grep "^$1 " $PKG_DIR/.list-remote)[2]} } function list_type_local { - echo ${$(grep "^$1 " $PDIR/.list)[2]} + echo ${$(grep "^$1 " $PKG_DIR/.list)[2]} } function list_update_remote { typeset tmpfile=$(mktemp -t pkglist.XXXXXX) typeset -i ret=0 - export PDIR + export PKG_DIR if [[ $PKG_PROTO == 'ssh' ]] { - ssh $PKG_USER@$PKG_HOST "PDIR='$PDIR' $PKGLIST_PATH $PKG_PATH" > $tmpfile + ssh $PKG_USER@$PKG_HOST "PKG_DIR='$PKG_DIR' $PKGLIST_PATH $PKG_PATH" > $tmpfile } elif [[ $PKG_PROTO == 'file' ]] { $PKGLIST_PATH $PKG_PATH > $tmpfile } @@ -354,7 +361,7 @@ function list_update_remote { die "remote list update failed\n" \ "-- note --\n" \ "There were recent changes in pkg involving the package root\n\n" \ - "You might want to copy the pkglist script ($PDIR/core/include/pkglist)\n" \ + "You might want to copy the pkglist script ($PKG_DIR/core/include/pkglist)\n" \ "into the package root, so that it's available as\n" \ "$PKG_HOST:$PKG_PATH/pkglist\n" "alternatively, set PKGLIST_PATH to the correct value (see pkg.conf(5))\n" @@ -363,36 +370,36 @@ function list_update_remote { } function list_update_local { - typeset all=${#$(echo $PDIR/*(/))} + typeset all=${#$(echo $PKG_DIR/*(/))} typeset -i current=0 typeset i - rm -f $PDIR/.list + rm -f $PKG_DIR/.list for package in *(-/); { (( current++ )) progress $current $all 'Updating package list' $package - vcs_to_list $package >> $PDIR/.list + vcs_to_list $package >> $PKG_DIR/.list } } function list_package_update { typeset list - list=$(grep -v "^$1 " $PDIR/.list) - echo $list > $PDIR/.list - vcs_to_list $1 >> $PDIR/.list + list=$(grep -v "^$1 " $PKG_DIR/.list) + echo $list > $PKG_DIR/.list + vcs_to_list $1 >> $PKG_DIR/.list } function list_package_remove { typeset list - list=$(grep -v "^$1 " $PDIR/.list) - echo $list > $PDIR/.list + list=$(grep -v "^$1 " $PKG_DIR/.list) + echo $list > $PKG_DIR/.list } function list_version_local { - echo ${$(grep "^$1 " $PDIR/.list)[3]} + echo ${$(grep "^$1 " $PKG_DIR/.list)[3]} } function list_version_remote { - echo ${$(grep "^$1 " $PDIR/.list-remote)[3]} + echo ${$(grep "^$1 " $PKG_DIR/.list-remote)[3]} } @@ -413,15 +420,15 @@ function real_priority { function exec_hook { typeset package=$1 typeset hook=$2 - if [[ -r $PDIR/$package/hooks/$hook ]] { + if [[ -r $PKG_DIR/$package/hooks/$hook ]] { info "$package: executing hook $hook\n" - cd $PDIR/$package + cd $PKG_DIR/$package (source hooks/$hook) } } function global_hook { - cd $PDIR/$1 + cd $PKG_DIR/$1 case $2 in post-add) exec_hook $1 post-add @@ -460,13 +467,13 @@ function check_prereqs { typeset -a -U install maybe_install typeset warn info i typeset package=$1 - [[ -r $PDIR/$package/prereqs ]] || return 0 - cd $PDIR/$package + [[ -r $PKG_DIR/$package/prereqs ]] || return 0 + cd $PKG_DIR/$package wrap_info $1 info "checking prerequisites\n" function is_installed { - [[ -d $PDIR/$1 ]] + [[ -d $PKG_DIR/$1 ]] } function perlmodule { perl -M$1 < /dev/null 2> /dev/null @@ -540,7 +547,7 @@ function check_prereqs { # Write a package's documentation to .collected # and symlink its binaries from ~/bin function populate_collected { - cd $PDIR/$1 || return + cd $PKG_DIR/$1 || return typeset -i bins=0 bino=0 mans=0 mano=0 typeset i @@ -550,7 +557,7 @@ function populate_collected { section=${man:h:t} manpage=${man:t} if podchecker man/$section/$manpage &> /dev/null; then - pod2man -u -s $section -c "$1 package" -r $HOME man/$section/$manpage > $PDIR/.collected/man/man$section/$manpage.$section + pod2man -u -s $section -c "$1 package" -r $HOME man/$section/$manpage > $PKG_DIR/.collected/man/man$section/$manpage.$section say -n "+" (( mans++ )) else @@ -560,7 +567,7 @@ function populate_collected { } for file in bin/*(N); { if podchecker $file &> /dev/null; then - pod2man -u $file > $PDIR/.collected/man/man1/${file:t}.1 + pod2man -u $file > $PKG_DIR/.collected/man/man1/${file:t}.1 say -n "+" (( bins++ )) else @@ -584,12 +591,12 @@ function populate_collected { } for file in bin/*(-*N); { if [[ -L $HOME/$file || ! -e $HOME/$file ]] { - if [[ $(readlink $HOME/$file) != (../${PDIR//$HOME\/}|$PDIR)/$1/$file ]] { + if [[ $(readlink $HOME/$file) != (../${PKG_DIR//$HOME\/}|$PKG_DIR)/$1/$file ]] { rm -f $HOME/$file - if [[ $PDIR == ${HOME}* ]] { - ln -s ../${PDIR//$HOME\/}/$1/$file $HOME/$file + if [[ $PKG_DIR == ${HOME}* ]] { + ln -s ../${PKG_DIR//$HOME\/}/$1/$file $HOME/$file } else { - ln -s $PDIR/$1/$file $HOME/$file + ln -s $PKG_DIR/$1/$file $HOME/$file } } } else { @@ -602,22 +609,22 @@ function populate_collected { # Assuming there are no packages with colliding files function genocide_collected { typeset i - cd $PDIR/$1 || return + cd $PKG_DIR/$1 || return wrap_info $1 info "Removing documentation" for man in man/*/*(N); { section=${man:h:t} manual=${man:t} - if [[ -e $PDIR/.collected/man/man$section/$manual.$section ]] { - rm $PDIR/.collected/man/man$section/$manual.$section + if [[ -e $PKG_DIR/.collected/man/man$section/$manual.$section ]] { + rm $PKG_DIR/.collected/man/man$section/$manual.$section } } for file in bin/*(N); { - rm -f $PDIR/.collected/man/man1/${file:t}.1 + rm -f $PKG_DIR/.collected/man/man1/${file:t}.1 } clear_line for file in bin/*(-*N); { - if [[ $(readlink $HOME/$file) == (../${PDIR//$HOME\/}|$PDIR)/$1/$file ]] { + if [[ $(readlink $HOME/$file) == (../${PKG_DIR//$HOME\/}|$PKG_DIR)/$1/$file ]] { rm -f $HOME/$file } } @@ -625,8 +632,8 @@ function genocide_collected { function update_provides { typeset package - for package in $PDIR/$1/provides/*(N:t); { - if [[ -d $PDIR/$package ]] { + for package in $PKG_DIR/$1/provides/*(N:t); { + if [[ -d $PKG_DIR/$package ]] { triggers+=$package } } @@ -657,7 +664,7 @@ function wrap { [[ -n $progress ]] && all=$(list_packages_local | wc -l) [[ -n $progress ]] && current=0 for package in *(-/); { - cd $PDIR + cd $PKG_DIR (( current++ )) [[ -n $progress ]] && progress $current $all $progress $package $function $package @@ -671,7 +678,7 @@ function wrap { ## function pkg_add { - if [[ -d $PDIR/$1 ]] { + if [[ -d $PKG_DIR/$1 ]] { info "Package '$1' is already installed!\n" exit 1 } @@ -695,13 +702,13 @@ function pkg_push { function pkg_remove { check_installed $1 - if [[ -r $PDIR/$1/priority ]] { - if (( $(cat $PDIR/$1/priority) > 3 )) { - confirm_no "Package '$1' is $(real_priority $(cat $PDIR/$1/priority)). Really remove?" || return + if [[ -r $PKG_DIR/$1/priority ]] { + if (( $(cat $PKG_DIR/$1/priority) > 3 )) { + confirm_no "Package '$1' is $(real_priority $(cat $PKG_DIR/$1/priority)). Really remove?" || return } } global_hook $1 pre-remove - rm -rf $PDIR/$1 + rm -rf $PKG_DIR/$1 info "Package removed.\n" } @@ -754,8 +761,8 @@ function pkg_status { function pkg_refresh { check_installed $1 global_hook $1 pre-update - if [[ -r $PDIR/$1/Makefile ]] ( - cd $PDIR/$1 + if [[ -r $PKG_DIR/$1/Makefile ]] ( + cd $PKG_DIR/$1 wrap_info $1 info "Cleaning build diroctery\n" make clean @@ -844,7 +851,7 @@ function pkg_log { ## Now what shall we do... ## -cd $PDIR || die "Cannot cd $PDIR" +cd $PKG_DIR || die "Cannot cd $PKG_DIR" # Note: # wrap foobar "$1" <- the "" are neccessary here, since $1 is optional (and therefore may be empty) diff --git a/include/bootstrap b/include/bootstrap index 2dbeb4a..793c6f3 100755 --- a/include/bootstrap +++ b/include/bootstrap @@ -6,17 +6,17 @@ # and also have an excuse for using zsh here :P typeset -i rcempty=0 -typeset PKG_ROOT PDIR default_path='~/packages' +typeset PKG_ROOT PKG_DIR default_path='~/packages' if [[ -n $1 ]] { PKG_ROOT=$1 - PDIR=${~${2-$default_path}} + PKG_DIR=${~${2-$default_path}} } else { cat <<- meow - Usage: ./bootstrap PKG_ROOT [PDIR] + Usage: ./bootstrap PKG_ROOT [PKG_DIR] PKG_ROOT is an URI, either of the form proto://host/path, or just /path Note: The path must be absolute, it may not contain a literal ~ - PDIR is the path where pkg and all further packages will be installed, + PKG_DIR is the path where pkg and all further packages will be installed, by default $default_path meow exit 100 @@ -34,7 +34,7 @@ if ! [[ -e ~/.zshrc ]] { echo 'Creating the basic directory structure' mkdir -p ~/bin path=(~/bin $path) -mkdir -p $PDIR/.collected/man/man{1..8} +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.' @@ -43,13 +43,13 @@ if ! which git &> /dev/null; then fi echo 'Fetching the core package...' -cd $PDIR +cd $PKG_DIR git clone $PKG_ROOT/core cd core || exit 1 echo 'Writing pkg.conf' echo "PKG_ROOT='$PKG_ROOT'" > ~/.pkg.conf -echo "PDIR=\"${PDIR/$HOME/\$HOME}\"" >> ~/.pkg.conf +echo "PKG_DIR=\"${PKG_DIR/$HOME/\$HOME}\"" >> ~/.pkg.conf echo 'Installing core package' rehash diff --git a/include/newpackage b/include/newpackage index ebba174..924da44 100755 --- a/include/newpackage +++ b/include/newpackage @@ -28,7 +28,7 @@ if ((bare)) { git config receive.denyCurrentBranch ignore } -cd ${PDIR-~/packages} +cd ${PKG_DIR-~/packages} mkdir $package cd $package git init diff --git a/man/5/pkg.conf b/man/5/pkg.conf index a9b7b3a..88b3536 100644 --- a/man/5/pkg.conf +++ b/man/5/pkg.conf @@ -30,7 +30,7 @@ I<url> may either be of the form C<ssh://host/path> or C</path>. path to pkglist on the package root, to generate the package list. In the default, $PKG_PATH means the path component of $PKG_ROOT. -=item B<PDIR>=I<path> ($HOME/packages) +=item B<PKG_DIR>=I<path> ($HOME/packages) path for the local package tree @@ -26,29 +26,29 @@ guaranteed, though I will do my best. =head1 THE BASICS pkg requires two directories in you home directory. B<~/bin> contains -symlinks to the executables shipped with your packages, and $PDIR +symlinks to the executables shipped with your packages, and $PKG_DIR (B<~/packages> by default, but *theoretically* configurable) contains the packages themselves. B<~/bin> may also contain normal executables; pkg will not overwrite existing files. =head1 THE PACKAGE DIRECTORY -$PDIR is the core of all this stuff. Its main use is storing the packages. +$PKG_DIR is the core of all this stuff. Its main use is storing the packages. There is one directory for each installed package, as created by B<git clone>. -$PDIR holds two special files: B<.list> and B<.list-remote>. For +$PKG_DIR holds two special files: B<.list> and B<.list-remote>. For an explanation about these files, see L</"THE PACKAGE LIST"> below. It also contains a special directory, F<.collected> - see L</"COLLECTED PACKAGE FILES">. =head2 NOTE -All directories in $PDIR must be valid git repositories which are not in the +All directories in $PKG_DIR must be valid git repositories which are not in the state of 'initial commit'. Dotfiles (directories starting with a .) are exempt from this, they will be ignored by pkg. =head1 THE PACKAGE ROOT The packages_root, in pkg referred to as $PKG_ROOT, is structured just like -the packages directory $PDIR, except that it neither contains .list nor +the packages directory $PKG_DIR, except that it neither contains .list nor .list-remote. The packages root is the central point where pkg fetches packages from and pushes packages to. @@ -190,7 +190,7 @@ B<recommend package>. =head1 HOOKS -Hooks are little zsh-snippets residing in $PDIR/hooks +Hooks are little zsh-snippets residing in $PKG_DIR/hooks which are sourced from within pkg whenever needed. Currently, the following hooks exist: @@ -215,7 +215,7 @@ Sourced before a package is removed (pkg remove/pkg delete) =head1 COLLECTED PACKAGE FILES -These files reside in F<$PDIR/.collected> (subject to change). +These files reside in F<$PKG_DIR/.collected> (subject to change). The directory is somewhat similar to F<~/bin> - it is automatically populated by pkg. However, this one does not contain symlinks. @@ -15,14 +15,14 @@ test_home=$(mktemp -dt pkghome.XXXXXX) cat << meow test directories: - PDIR = $test_pdir + PKG_DIR = $test_pdir PKG_ROOT = $test_proot HOME = $test_home meow source $tests/setup -echo "# bootstrapping PDIR" +echo "# bootstrapping PKG_DIR" cd $test_home export HOME=$test_home $test_proot/core/include/bootstrap $test_proot $test_pdir |