+# do the sync
+
+#zpm shell $ZPMDB 'select * from install_status' 1>&2
+if [ $dryrun -gt 0 ]; then
+ syncopts="$syncopts -n"
+fi
+
+if [ $verbose -gt 0 ]; then
+ syncopts="$syncopts -v"
+fi
+
+if [ "$pkgfile" != "$ZPMDB" ]; then
+ syncopts="$syncopts -f $pkgfile"
+fi
+
+zpm syncfs $syncopts
+
+syncrv=$?
+
+for pkgid in $pkglist; do
+ zpm pkg $pkgid status=dryrun
+done
+
+if [ $syncrv -ne 0 ]; then
+ zpm pkg $pkgid status=failed
+ die 'zpm-syncfs failed';
+fi
+
+if [ $(id -u) -eq 0 ]; then
+ if [ ! -d $rootdir/etc ]; then
+ warn "no etc directory in $rootdir, skipping ldconfig"
+ elif [ -f $rootdir/sbin/ldconfig ]; then
+ $rootdir/sbin/ldconfig -r ${rootdir:-/}
+ elif [ -f /sbin/ldconfig ]; then
+ /sbin/ldconfig -r ${rootdir:-/}
+ else
+ true
+ fi
+fi
+
+for pkgid in $pkglist; do
+ package=$(zpm parse -n $pkgid)
+ current=$(zpm list -s installed "$package")
+
+ if [ $runscripts -gt 0 ]; then
+ zpm script -f $pkgfile -p post-install $pkgid $current
+ else
+ if zpm script -f $pkgfile -Fql -p post-install $pkgid; then
+ zpm note -p $pkgid -m 'post-install script not run'
+ fi
+ fi
+
+ if [ -n "$current" ]; then
+ zpm pkg $pkgid status=installed :$current status=updated
+ else
+ zpm pkg $pkgid status=installed
+ fi
+
+ # TODO skip configure if not on a terminal, regardless of settings
+ # TODO will need force option
+ if [ $runconfigure -gt 0 ]; then
+ zpm script -f $pkgfile -p configure $pkgid
+ else
+ if zpm script -f $pkgfile -Fql -p configure $pkgid; then
+ zpm note -p $pkgid -m 'configure script not run'
+ fi
+ fi
+
+done