# ================================================
APPNAME=`basename "$0"`
-MYVERSION=2.2.2+toward_2.2.3_20130114225853
+MYVERSION=2.2.2+toward_2.2.3_20130117165752
PREFIX=${PREFIX:-/usr/local}
CONFFILE=${PREFIX}/etc/${APPNAME}.conf
}
pkg_create_b ()
{
- pkg create -f tbz "$@"
+ pkg create "$@"
}
pkg_delete_f ()
{
echo "$*" | str_escape_regexp_filter
}
+create_backup_pkg ()
+{
+ local pkgname dstdir backup_pkg
+ pkgname=$1
+ dstdir=$2
+ rm -rf "${TMPDIR}"/package.tmp
+ mkdir "${TMPDIR}"/package.tmp
+ if ( cd "${TMPDIR}"/package.tmp && pkg_create_b "$pkgname" )
+ then
+ backup_pkg=`ls "${TMPDIR}"/package.tmp | \
+ grep -m 1 -E "^`str_escape_regexp \"$pkgname\"`\.(txz|tbz|tgz|tar)$"` || :
+ fi
+ if [ -z "$backup_pkg" ]
+ then
+ echo "WARNING: Failed to create backup package for $pkgname" >&2
+ return 1
+ fi
+ [ -d "$dstdir" ] || mkdir -p "$dstdir"
+ mv "${TMPDIR}/package.tmp/$backup_pkg" "$dstdir"
+ echo "$dstdir/$backup_pkg"
+}
+
rm_a_line ()
{
local item dstpath pattern
echo "INFO: The ports tree has a new version of ${APPNAME}. It will be updated first."
echo "Updating $self_origin ($self_pkg_current => $self_pkg_new)..."
echo "Backing up the installed package..."
- [ -d "${PORTSDIR}"/packages/All ] || mkdir -p "${PORTSDIR}"/packages/All
- ( cd "${PORTSDIR}"/packages/All/ && pkg_create_b "$self_pkg_current" )
+ backup_pkg=`create_backup_pkg "$self_pkg_current" "${PORTSDIR}"/packages/All` || :
echo "Reinstalling ${APPNAME}..."
pkg_delete_f "$self_pkg_current"
if ( cd "${PORTSDIR}/$self_origin" && make reinstall )
echo "WARNING: Reinstallation failed. Restoring the old package..." >&2
( cd "${PORTSDIR}/$self_origin" && make deinstall ) || :
( cd "${PORTSDIR}/$self_origin" && make clean ) || :
- pkg_add_f "${PORTSDIR}"/packages/All/"$self_pkg_current.tbz"
+ [ -n "$backup_pkg" ] && pkg_add_f "$backup_pkg"
echo "INFO: Continuing with the old version..."
fi
fi
[ -d "${DBDIR}/status_deinst" ] || mkdir -p "${DBDIR}/status_deinst"
if [ `cat "${DBDIR}/moved_or_lost.list" | wc -l` -gt 0 ]
then
- savedir=`pwd`
if [ -f "${DBDIR}/moved_or_lost.list.remained" ]
then
echo "INFO: Restarting from the previously terminated point"
cp -p "${DBDIR}/moved_or_lost.list.remained" "${TMPDIR}/moved_or_lost.tmp"
nlines=`cat "${TMPDIR}/moved_or_lost.tmp" | wc -l`
iline=1
- cd "${DBDIR}/backup_obsolete"
while [ $iline -le $nlines ]
do
origin=`sed -n ${iline}p "${TMPDIR}/moved_or_lost.tmp"`
tag=`echo $origin | sed 's|/|.|'`
if [ ! -e "${DBDIR}/status_deinst/$tag.backup" ]
then
- pkg_create_b "$currentpkg" || { echo "*** Continuating forcibly by hoping success..."; continue; }
+ backup_pkg=`create_backup_pkg "$currentpkg" "${DBDIR}/backup_obsolete"` || :
+ if [ -n "$backup_pkg" ]
+ then
+ echo "$backup_pkg" > ${DBDIR}/requires/$origin/backedup_pkgfile
+ else
+ echo "*** Continuating forcibly by keeping the installed package"
+ continue
+ fi
touch "${DBDIR}/status_deinst/$tag.backup"
fi
echo "-- (Deleting package for $origin as $currentpkg)"
_MSG_CURRENT_STAGE=${_MSG_CURRENT_STAGE_general}
echo
done
- cd "$savedir"
fi
touch "${DBDIR}/COMPLETE_DEINST_OBS_PKGS"
_MSG_CURRENT_STAGE=
if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP" ]
then
echo "-- (Creating temporal backup package for $position_msg)"
- cd "${DBDIR}/backup_failure"
- pkg_create_b "$currentpkg" || \
+ backup_pkg=`create_backup_pkg "$currentpkg" "${DBDIR}/backup_failure"` || \
{
- rm -f "${DBDIR}/backup_failure/$currentpkg.tbz"
+ rm -f "$backup_pkg"
echo "WARNING: Failed to create the backup package, but ignored by hoping success." >&2
}
cd "${PORTSDIR}/$origin"
echo $currentpkg > ${DBDIR}/requires/$origin/backedup_version
+ echo $backup_pkg > ${DBDIR}/requires/$origin/backedup_pkgfile
touch "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP"
fi
if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_BEFOREDEINSTALL" ]
if [ -n "$backedup_version" ]
then
echo "*** Restoring the backup of $backedup_version..."
- if [ ! -e "${DBDIR}/backup_failure/$backedup_version.tbz" ]
+ backup_pkg=`cat "${DBDIR}/requires/$origin/backedup_pkgfile" || :`
+ if [ -z "$backup_pkg" -o ! -e "$backup_pkg" ]
then
echo "WARNING: No backup exists, gave up." >&2
- elif pkg_add_fF "${DBDIR}/backup_failure/$backedup_version.tbz"
+ elif pkg_add_fF "$backup_pkg"
then
:
else
record_success $origin
[ -e "${DBDIR}/requires/$origin/failed_requirements" ] && cp "${DBDIR}/requires/$origin/failed_requirements" "${DBDIR}/requires/$origin/failed_requirements.previous"
rm_a_line "$origin" "${DBDIR}/reinst_todo.list"
- rm -f "${DBDIR}/backup_failure/$currentpkg.tbz"
+ backup_pkg=`cat "${DBDIR}/requires/$origin/backedup_pkgfile" || :`
+ [ -n "$backup_pkg" -a -e "$backup_pkg" ] && rm -f "$backup_pkg"
rm "${DBDIR}/requires/$origin/status/in_install"
_MSG_CURRENT_STAGE=${_MSG_CURRENT_STAGE_general}
echo