pm

A pack manager
git clone git://iotek.org/pm
Log | Files | Refs | README

commit e0cbde4461e7bc7ac54e63ae9d695960a6c173c4
parent 2d71b9badf0ab941550001f59271aafe774fe02f
Author: dcat <dcat@iotek.org>
Date:   Tue May  3 01:04:38 +12000

added pm script

Diffstat:
pack.5 | 14+++++++-------
pm | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 127 insertions(+), 7 deletions(-)
diff --git a/pack.5 b/pack.5 @@ -20,10 +20,10 @@ compressed .Em tar file containing all the files and sub directories meant to be extracted under the .Ev $ROOT -directory (See +directory (See .Xr pm 1 ) . For example: -.Bd -literal -width Ds -offset indent +.Bd -literal -offset indent bin/ bin/pm share/ @@ -39,20 +39,20 @@ In order to create a pack suitable for use with you can use external tools to first install your pack into a specific directory, change to this directory and archive its content. The typical workflow to create packs would be the following: -.Bd -literal -width Ds -offset indent +.Bd -literal -offset indent make make DESTDIR=/tmp/rootfs install cd /tmp/rootfs -tar -c $(ls) | bzip2 > /tmp/pm#0.0.tar.bz2 +tar -c $(ls -1) | bzip2 > /tmp/pm#0.0.tar.bz2 .Ed .Pp You can check the content of this pack with: -.Bd -literal -width Ds -offset indent +.Bd -literal -offset indent bzip2 -cd < /tmp/pm#0.0.tar.bz2 | tar -t .Ed .Sh SEE ALSO -.Xr pm 1 , -.Xr tar 1 , .Xr bzip2 1 , +.Xr pm 1 , +.Xr tar 1 .Sh AUTHORS .An Willy Goiffon Aq Mt willy@mailoo.org diff --git a/pm b/pm @@ -0,0 +1,120 @@ +#!/bin/sh + +ROOT=/var/pm + +# +# the directory structure should be as; +# /var/pm +# |___ repo +# |___ name.of.server +# (contains list of all available packages, and their dependencies) +# |___ packages +# |___ <installed package> +# (contains the contents of the installed package) +# + +pkg_usage() { + # TODO someone needs to make this pretty. + echo ' in[stall] <packages...>' + echo ' rm|remove <packages...>' + echo ' se[arch] <regex>' + echo ' av[ail]' + echo + + exit 0 +} + +pkg_search() { + # loop through all repositories + RET=0 + for DB in `/bin/ls -1 $ROOT/repo/*` + do + # find all matches + cut -d: -f1 <$DB | grep -q "${1}" && { + # output all matches, and their repository + for RESULT in `cut -d: -f1 <$DB | grep "${1}"` + do + printf '%s/%s\n' "`basename $DB`" "$RESULT" + done + + RET=$(($RET-1)) + } || RET=$(($RET+1)) + done + + [ $RET -lt 0 ] && RET=0 + return $RET +} + +pkg_link() { + printf "https://%s.pkg\n" "`pkg_search \"^${1}$\"`" +} + +pkg_deps() { + # gets first level dependencies for packageA + # recursion shall be handled elsewhere. + for PKG in $1 + do + for DB in `/bin/ls -1 $ROOT/repo/*` + do + grep "^${PKG}:" <$DB | cut -d: -f2 + done + done +} + +pkg_exists() { + pkg_search "^${1}$" >/dev/null +} + +pkg_remove() { + echo mock uninstall $1 +} + +pkg_install() { + # install all dependencies first + for DEP in `pkg_deps $1` + do + $0 in $DEP + done + + echo mock installing $1 +} + +case "$1" in +in|install) + shift + [ -z "$1" ] && pkg_usage + for PKG in $@ + do + pkg_exists $PKG || { + echo package $PKG does not exist 1>&2 + break + } + pkg_install $PKG + done + ;; +rm|remove) + shift + [ -z "$1" ] && pkg_usage + for PKG in $@ + do + pkg_exists $PKG || { + echo package $PKG does not exist 1>&2 + break + } + pkg_remove $PKG + done + ;; +se|search) + shift + [ -z "$1" ] && pkg_usage + pkg_search $@ + ;; +av|avail) + # run a search matching everything + pkg_search . + ;; +*) + pkg_usage + ;; +esac +