+#
+# install second package
+#
+require ln bin/true bin/sh
+pkgid=second-1.0-1
+newpkg $pkgid bin/sh
+okexit setup package $pkgid
+require rm bin/sh
+PF=$pkgid.zpm
+zpm install -R. -d local.db -f $PF $pkgid 2>&1 | diagstdin
+okexit installed $pkgid
+oktest -f bin/sh
+
+#
+# update a file
+#
+ohash=$(zpm hash bin/true)
+require mv bin/true bin/save
+require sh -c 'echo false > bin/true'
+nhash=$(zpm hash bin/true)
+pkgid=itest-4.0-1
+newpkg $pkgid bin/true
+okexit setup package $pkgid
+require mv bin/save bin/true
+PF=$pkgid.zpm
+zpm install -R. -d local.db -f $PF $pkgid 2>&1 | diagstdin
+okexit installed $pkgid
+rhash=$(zpm hash bin/true)
+okstreq "$rhash" "$nhash" "updated bin/true"
+
+skiponfail() {
+ rv=$?
+ if [ $rv -ne 0 ]; then
+ skip "$1" "$2"
+ return 0
+ fi
+ return 1
+}
+
+#
+# package with passing pre-script
+#
+pkgid=third-1.0-1
+PF=$pkgid.zpm
+newpkg $pkgid /bin/echo
+skiponfail 3 "can't create $pkgid" || {
+ zpm script -s -f $PF -p pre-install $pkgid /bin/true
+ okexit "add true pre-install script to $pkgid"
+ skiponfail 2 "can't set $pkgid pre-install script" || {
+ tryrun zpm install -v -R. -d local.db -f $PF $pkgid
+ okexit installed $pkgid
+ oktest -f bin/echo
+ }
+}
+
+#
+# package with failing pre-script
+#
+pkgid=fourth-1.0-1
+PF=$pkgid.zpm
+newpkg $pkgid /bin/head
+skiponfail 3 "can't create $pkgid" || {
+ zpm script -s -f $PF -p pre-install $pkgid /bin/false
+ okexit "add false pre-install script to $pkgid"
+ skiponfail 1 "can't set $pkgid pre-install script" || {
+ zpm install -R. -d local.db -f $PF $pkgid 2>/dev/null
+ failsok failed to install $pkgid
+ }
+}
+
+tryrun zpm uninstall -R. -d local.db third-1.0-1
+test -f bin/echo
+failsok bin/echo removed
+
+pkgid=fifth-1.0-1
+PF=$pkgid.zpm
+newpkg $pkgid /bin/head
+#zpm list -f $PF 2>&1 | diagstdin
+skiponfail 1 "can't create $pkgid" || {
+ tryrun zpm install -R. -d local.db -f $PF 2>/dev/null
+ okexit "install with implicit package id"
+}
+