#!/bin/rc # pkginit - set up pkg # usage: pkginit instdir=/rc/bin/pkg fn die{ >[1=2] echo !! $* >[1=2] echo !! exiting... exit $"* } fn fin{ say installation successful say use pkg/add to install packages exit '' } fn say{ >[1=2] echo :: $* } >[1=2] echo -n '|| package store location? [/sys/pkg] ' pkgdir=`{read} switch($pkgdir){ case '' pkgdir=/sys/pkg case /* pkgdir=$pkgdir(1) case * die please use an absolute path } say initializing pkg... if(! test -d $pkgdir){ say creating $pkgdir... mkdir -p $pkgdir || die failed to create $pkgdir } if not say $pkgdir already exists if(! test -d $instdir){ say creating $instdir... mkdir -p $instdir || die failed to create $instdir } if not say $instdir already exists say adding pkg/env to $instdir... >$instdir/env cat <<'...' | >[2=] sed -e 's!REPLACE!'$pkgdir'!g' || die failed to install $instdir/env pkgdir=REPLACE pkglist=$pkgdir/.pkglist pkgs=(`{>[2=] sed -e '/^#/d;/^$/d;s/.*pkg=//g;s/\ .*//g' $pkglist}) t=/tmp/pkg.$pid fn checklist{ if(! test -s $pkglist) die no pkglist found } fn die{ rm -f $t >[1=2] echo !! $* >[1=2] echo !! exiting... exit $"* } fn say{ >[1=2] echo :: $* } fn sighup sigint sigterm{ rm -f $t exit interrupt } ... say adding pkg/add to $instdir... >$instdir/add cat <<'...' || die failed to install $instdir/add #!/bin/rc rfork en . pkg/env flagfmt=''; args='url ...' if(! eval `''{aux/getflags $*} || ~ $#* 0) exec aux/usage for(repo in $*){ pkg=`{echo $repo | awk -F'/' '{print $NF}'} say pulling $pkg... git/clone $repo $pkgdir/$pkg || die failed to clone $pkg cd $pkgdir/$pkg if(~ $pkg 'nsport'){ fetch clone http || die failed to fetch $pkg say building $pkg... mk || die failed to build $pkg } say installing $pkg... mk install || die failed to install $pkg say $pkg installed, cleaning... mk clean || die failed to clean $pkg >>$pkglist echo 'pkg='$pkg' url='$repo say $pkg successfully added to pkglist } || exit say all packages successfully installed exit '' ... chmod +x $instdir/add || die failed to chmod $instdir/add say adding pkg/del to $instdir... >$instdir/del cat <<'...' || die failed to install $instdir/del #!/bin/rc rfork en . pkg/env checklist flagfmt=''; args='name ...' if(! eval `''{aux/getflags $*} || ~ $#* 0) exec aux/usage for(pkg in $*){ cp $pkglist $t if(test -d $pkgdir/$pkg){ cd $pkgdir/$pkg say uninstalling $pkg... mk uninstall || die failed to uninstall $pkg cd $pkgdir say removing $pkg sources... rm -rf $pkg || die failed to remove $pkg say removing $pkg from pkglist... >$t.x grep -ve 'pkg='$pkg $t mv $t.x $t mv $t $pkglist } if not die $pkg not installed } || exit say all packages successfully removed exit '' ... chmod +x $instdir/del || die failed to chmod $instdir/del say adding pkg/ls to $instdir... >$instdir/ls cat <<'...' || die failed to install $instdir/ls #!/bin/rc rfork en . pkg/env checklist flagfmt='c:c' eval `''{aux/getflags $*} || exec aux/usage if(~ $c 1) >[1=2] echo $#pkgs if not{ say managed packages: >[1=2] echo $pkgs | tr ' ' '\x0A' | sort | mc } exit '' ... chmod +x $instdir/ls || die failed to chmod $instdir/ls say adding pkg/up to $instdir... >$instdir/up cat <<'...' || die failed to install $instdir/up #!/bin/rc rfork en . pkg/env checklist flagfmt=''; args='[name ...]' eval `''{aux/getflags $*} || exec aux/usage if(~ $#* 0) name=$pkgs if not name=$* for(pkg in $name){ if(test -d $pkgdir/$pkg){ cd $pkgdir/$pkg say updating $pkg... if(~ $pkg 'nsport'){ fetch pull || die failed to fetch $pkg say building $pkg... mk || die failed to build $pkg } if not git/pull || die failed to fetch $pkg } if not if(grep -se 'pkg='$pkg $pkglist){ sel=($pkg `{grep -e 'pkg='$pkg $pkglist | sed -ne '/^#/d;s/.*url=//g;s/\ .*//g;1p'}) if(test $#sel -lt 2) die $pkg not in pkglist say pulling $pkg... git/clone $sel(2) $pkgdir/$sel(1) || die failed to clone $pkg cd $pkgdir/$pkg if(~ $pkg 'nsport'){ fetch clone http || die failed to fetch $pkg say building $pkg... mk || die failed to build $pkg } } if not die $pkg not in pkglist say installing $pkg... mk install || die failed to install $pkg say $pkg installed, cleaning... mk clean || die failed to clean $pkg } || exit say all updates successfully completed exit '' ... chmod +x $instdir/up || die failed to chmod $instdir/up say installing manual... >/sys/man/1/pkg cat <<'...' | >[2=] sed -e 's!REPLACE!'$pkgdir'!g' || die failed to install manual .TH PKG 1 .SH NAME pkg, pkg/add, pkg/del, pkg/ls, pkg/up \- manage third-party packages .SH SYNOPSIS .B pkg/add .I url ... .PP .B pkg/del .I name ... .PP .B pkg/ls [ .B -c ] .PP .B pkg/up [ .I name ... ] .SH DESCRIPTION Pkg is a simple package manager. It uses .IR git (1) and .IR mk (1) to automatically clone, install, remove, and update third-party source repositories from a text database. .SS Commands .I Add clones new packages from the specified URLs via .I git followed by building, installing, and finally cleaning with .IR mk . Entries are then added to the list of managed packages. .PP .I Del purges the specified packages by uninstalling them with .I mk and removing their source directories from the store. Associated entries are then removed from the list of managed packages. .PP .I Ls displays a columnated list of all packages currently being managed. Passing the .B -c option will instead display a count of managed packages. .PP .I Up fetches updates for the specified packages followed by the build steps described above for .IR pkg/add . If no package is specified, all packages are updated. .SH FILES .TP .B REPLACE/.pkglist The list of managed packages. .SH NOTES There are no automatic dependency management triggers and packages are updated in the order in which they were installed. .PP Packages without an .B uninstall target in their mkfile will cause .I pkg/del to terminate without removing their source directories or purging the associated entries from the list of packages. .PP List entries without a corresponding source directory in the store will be cloned automatically when running .IR pkg/up . This means a pre-generated list can be supplied to quickly install a large group of packages. .SH SEE ALSO .IR git (1), .IR mk (1) .PP .I http://9p.sdf.org/who/bubstance/lib/example_pkglist.txt .SH BUGS Probably. ... fin