ref: f3afdf563f784c0a5703496f48c1a72dff4617f4
dir: /pkginit/
#!/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 .PP .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 .PP .I Pkg is a simple package manager. It uses .IR git (1) and .IR mk (1) to automatically clone, install, and update third-party source repositories from a database. .SH COMMANDS .PP .B Pkg/add is used to install new packages. Packages are fetched via .IR git , after which they are built, installed, and finally cleaned with .IR mk . An entry is then added to the database of managed packages. .PP .B Pkg/del is used to purge packages. Selected packages are uninstalled with .I mk and their sources are removed from the store, after which their entry is removed from the database of managed packages. .PP .B Pkg/ls displays a columnated list of packages currently being managed by .IR pkg . Passing the .B -c option will instead display a .I count of managed packages. .PP .B Pkg/up is used to update packages to their latest versions followed by the build steps described above for .BR pkg/add . If no package is specified, all packages are updated. .SH FILES .TP REPLACE/.pkglist The database of managed packages. .SH NOTES .PP There are no automatic dependency management triggers and packages are updated in the order in which they were installed. .PP Packages without an .I uninstall target in their .I mkfile will cause .B pkg/del to exit without removing sources or purging the entry from the database. .PP Entries without a corresponding source directory in the store will be pulled automatically when running .BR pkg/up . This means a pre-generated .I .pkglist can be supplied to quickly install a large selection of packages. .SH BUGS .PP Probably. .SH SEE ALSO .IR git (1), .IR mk (1) ... fin