I was thinking the same thing to use a temp work dir. But at this point, I just
want to add support for symbolic link and empty directory backups.
So 'freshen' is to be used for automated, multi package updates? Does anyone
actually use this?
I don't see how this could work since one modified .local config file will
cause the function to abort. And that's after it has possibly deleted many
files, which at this point, will probably render the package broken.
Therefore is seems, the -f option is intended to be used when you *don't* make
changes to .local files? This doesn't make sense, what kind of system would
this be, one that utilizes an alternative config setup? If someone has used
this option, I'd like to know.
The -u option, on the other hand does makes sense.
Below are changes that I've made to updgrade() to support symlink/empty dir
backups and make it do what I believe it is trying to do, in a way that won't
break packages. But untested, as I still don't fully understand it.
Updated function, then snippet of diff after....
# ---------------------------------------------------------
# upgrade - upgrades a package
upgrade () {
local pkg pth
if [ -z "$1" ]; then
echo "No package name given." ; return 1
fi
pth=$( makeFN $1 )
pkg=$( package_part $pth )
if [ -z "$pkg" ]; then
echo "No package name given."; return 1
fi
if ! list_pkgs "$pkg" >/dev/null; then
echo "$pkg not installed."; return 1
fi
if [ ! -f "$pth" ]; then
echo "$pth not found."; return 1
fi
# ok, its there, installed... let's upgrade it...
(
# Does the OUTDATED, running package have a .local file?
if [ -f $PKGDIR/$pkg.local ]; then
mkdir $TMP/$SESSIONID.tmpdir
cd $TMP/$SESSIONID.tmpdir
tar -zxpf $pth $LRPKG/$pkg.local
# Does the UPDATED, non-running package also have a .local file?
if [ -f $LRPKG/$pkg.local ] ; then
package_changed_files $pkg >$TMP/$SESSIONID.changed
tar -zxpf $pth -T $LRPKG/$pkg.local
if [ "$2" = 1 ]; then
# Abort if update type is "freshen" and config files have
changed
for file in $(cat $TMP/$SESSIONID.changed); do
test -f $file \\
&& echo "$pkg freshen failed - config file(s) are
changed, try manual freshen" \\
&& return 1
done
fi
tar -ztf $pth >$LRPKG/$pkg.list
find $(cat $LRPKG/$pkg.local) -type f | \
xargs sha1sum > $LRPKG/$pkg.sha1
# remove local files that have not changed from
# the installed version of this package
# ...because possibly the updated lrp discontinued use of these
files?
rm -f $(cat $PKGDIR/$pkg.sha1 | sed '/ -/d' | \
sha1sum -c 2>/dev/null | grep OK | sed 's/: OK$//')
# But do merge changed or added config files, symlinks, and empty
directories
for file in $(cat $TMP/$SESSIONID.changed); do
if [ -L $file ] || [ -d $file ]; then
mv $file $PKGROOT/$file
else
test -f $file && apkg.merge $PKGROOT . $file
test -f $file && mv $file $PKGROOT/$file
fi
done
tar -zxpf $pth -X $TMP/$SESSIONID.changed -C $PKGROOT
mv $LRPKG/$pkg.list $PKGDIR
mv $LRPKG/$pkg.sha1 $PKGDIR
else # [ -f $LRPKG/$pkg.local ] ? Answer: No
tar -zxvpf $pth -C $PKGROOT >$PKGDIR/$pkg.list
#create_sha1 $pkg <- why was this here? If the new updated lrp
doesn't have a .local
# as should now be the case, then we should delete the existing
.local and .sha1 in $PKDIR (/var/lib/lrpkg)
rm -f $PKGDIR/$pkg.local $PKGDIR/$pkg.sha1
fi
else
tar -zxvpf $pth -C $PKGROOT >$PKGDIR/$pkg.list
# Always call create_sha1 just in case this lrp package ever gets a
.local file
create_sha1 $pkg
fi
)
if [ $? -eq 0 ]; then
echo "$pkg upgraded"
# Display list of dependencies...
deplist=""
if [ -f $PKGDIR/$pkg.deplrp ] ; then
for deplrp in `cat $PKGDIR/$pkg.deplrp` ; do
[ -f "$PKGDIR/$deplrp.list" ] || deplist="$deplist $deplrp"
done
fi
[ -n "$deplist" ] && echo "Required packages that are missed: $deplist"
return 0
else
return $?
fi
}
-----------------------------------
@@ -249,16 +271,28 @@
# ok, its there, installed... let's upgrade it...
(
+ # Does the OUTDATED, running package have a .local file?
if [ -f $PKGDIR/$pkg.local ]; then
- package_changed_files $pkg >$TMP/$SESSIONID.changed
-
mkdir $TMP/$SESSIONID.tmpdir
cd $TMP/$SESSIONID.tmpdir
tar -zxpf $pth $LRPKG/$pkg.local
+ # Does the UPDATED, non-running package also have a .local file?
if [ -f $LRPKG/$pkg.local ] ; then
+ package_changed_files $pkg >$TMP/$SESSIONID.changed
+
tar -zxpf $pth -T $LRPKG/$pkg.local
+
+ if [ "$2" = 1 ]; then
+ # Abort if update type is "freshen" and config files have
changed
+ for file in $(cat $TMP/$SESSIONID.changed); do
+ test -f $file \\
+ && echo "$pkg freshen failed - config file(s) are
changed, try manual freshen" \\
+ && return 1
+ done
+ fi
+
tar -ztf $pth >$LRPKG/$pkg.list
find $(cat $LRPKG/$pkg.local) -type f | \
@@ -266,33 +300,38 @@
# remove local files that have not changed from
# the installed version of this package
+ # ...because possibly the updated lrp discontinued use of these
files?
rm -f $(cat $PKGDIR/$pkg.sha1 | sed '/ -/d' | \
sha1sum -c 2>/dev/null | grep OK | sed 's/: OK$//')
+ # But do merge changed or added config files, symlinks, and empty
directories
for file in $(cat $TMP/$SESSIONID.changed); do
- if [ "$2" = 1 ]; then
- test -f $file && echo "$pkg upgrade failed -
config file(s) are changed, try manual upgrade" && return 1
+ if [ -L $file ] || [ -d $file ]; then
+ mv $file $PKGROOT/$file
+ else
+ test -f $file && apkg.merge $PKGROOT . $file
+ test -f $file && mv $file $PKGROOT/$file
fi
-
- test -f $file && apkg.merge $PKGROOT . $file
- test -f $file && mv $file $PKGROOT/$file
done
tar -zxpf $pth -X $TMP/$SESSIONID.changed -C $PKGROOT
mv $LRPKG/$pkg.list $PKGDIR
mv $LRPKG/$pkg.sha1 $PKGDIR
- else
+ else # [ -f $LRPKG/$pkg.local ] ? Answer: No
tar -zxvpf $pth -C $PKGROOT >$PKGDIR/$pkg.list
- create_sha1 $pkg
+ #create_sha1 $pkg <- why was this here? If the new updated lrp
doesn't have a .local
+ # as should now be the case, then we should delete the existing
.local and .sha1 in $PKDIR (/var/lib/lrpkg)
+ rm -f $PKGDIR/$pkg.local $PKGDIR/$pkg.sha1
fi
else
tar -zxvpf $pth -C $PKGROOT >$PKGDIR/$pkg.list
+ # Always call create_sha1 just in case this lrp package ever gets a
.local file
create_sha1 $pkg
fi
)
if [ $? -eq 0 ]; then
echo "$pkg upgraded"
- # process any package dependencies by recursively calling install()...
+ # Display list of dependencies...
deplist=""
if [ -f $PKGDIR/$pkg.deplrp ] ; then
for deplrp in `cat $PKGDIR/$pkg.deplrp` ; do
19.10.2014 10:13, cpu memhd пишет:
> Hello,
>
> Can someone explain when and how this function is used?
>
> I'm having troubles understanding this part:
>
> # remove local files that have not changed from
> # the installed version of this package
> rm -f $(cat $PKGDIR/$pkg.sha1 | sed '/ -/d' | \
> sha1sum -c 2>/dev/null | grep OK | sed 's/: OK$//')
>
> for file in $(cat $TMP/$SESSIONID.changed); do
> if [ "$2" = 1 ]; then
> test -f $file && echo "$pkg upgrade failed - config file(s) are
> changed, try manual upgrade" && return 1
> fi
>
> test -f $file && apkg.merge $PKGROOT . $file
> test -f $file && mv $file $PKGROOT/$file
> done
>
> When $2 = 1 that means to 'freshen'. But if a local config file has changed,
> then abort the upgrade.
>
> First of all, what is the point of this (to "freshen")? And secondly, why
> test for "local" changes, then abort if true ("return 1") inside the for
> loop, especially after the potential deletion of lots of--unchanged--files,
> from the "installed version"?
>
> Seems like this has the potential to leave an LRP in a broken/inconsistent
> state.
>
> Also note: create_sha1 $pkg is being called to create a *running* .sha1 file
> list even when the *updated* package doesn't contain a .local file. Shouldn't
> the running .local and .sha1 be deleted instead?
>
Freshen option was added as tiny hack to original apkg for upgrade
automation.
It'll be good to add work with temporary dir, to ensure that nothing
went wrong during update (for ex., ssh session not lost on merge -
this'll cause same trouble).
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
leaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/leaf-devel