# HG changeset patch # User Francisco J Ballesteros # Date 1315951542 -7200 # Node ID b424287b04641b467df7eb2d18686568e819a147 # Parent 2003784194bc63f7bf81d0116547ec38f2e5d478 pminstall ovr: overwrite protection for pm/install includes flag -f, to force overwrite, and makes it refuse to install if it would overwrite anything. Also, it now removes the unpacked root after installing. R=nix-dev, john, nemo CC=nix-dev http://codereview.appspot.com/5008042 diff -r 2003784194bc -r b424287b0464 rc/bin/pm/install --- a/rc/bin/pm/install Tue Sep 13 14:40:58 2011 -0700 +++ b/rc/bin/pm/install Wed Sep 14 00:05:42 2011 +0200 @@ -14,17 +14,40 @@ PKGSERVER=jfloren.net } +USAGE='usage: install [-v] [-f] package' +flagfmt='v,f' + +if(! ifs=() eval `{aux/getflags $*}) { + echo $USAGE + exit usage +} verb='' -if(~ $1 -v){ - verb=-v - shift -} +force=n +if(! ~ $#flagv 0) verb=v +if(! ~ $#flagf 0) force=y if (~ $#* 0) { echo Need at least one package name exit 'invalid arg' } +fn checkoverwrites { + ovw=n + for(f in `{tar ztf root.tgz | grep -v '/$' | sed 's/^root//'}){ + if(test -e $ROOT$f){ + echo $PKGNAME: $f already exists >[1=2] + # copy it to .old? + ovw=y + } + } + if(~ $ovw y){ + echo aborting because of overwritten files. >[1=2] + echo run with -f to force install >[1=2] + exit overwrites + } + +} + if (! test -e $ROOT^/contrib/packages/installed) { touch $ROOT^/contrib/packages/installed } @@ -64,10 +87,15 @@ echo $i^' is already installed, skipping' } } + if(! ~ $force y) + checkoverwrites + echo $PKGNAME^: Unpacking the root archive... tar xzTf root.tgz @{builtin cd root && tar cif /fd/1 .} | @ {builtin cd $ROOT && tar x$verb^Tf /fd/0} - + rm -r root + tar ztf root.tgz > root.lst + rm -f root.tgz # inform the world that this package is now installed echo $PKGNAME >> $ROOT^/contrib/packages/installed sort $ROOT^/contrib/packages/installed > /tmp/installed-sorted