Skip to content

Commit

Permalink
fixed: uninstall of patched files failed
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed May 3, 2024
1 parent c0613a5 commit 9ecea8b
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 256 deletions.
4 changes: 2 additions & 2 deletions FileSets/PatchSource/PageSettings.qml.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- /Users/Kevin/GitHub/StockVenusOsFiles/v3.20~37//opt/victronenergy/gui/qml/PageSettings.qml 2023-12-19 16:21:11
+++ PageSettings.qml 2024-01-08 16:51:07
--- /Users/Kevin/GitHub/SetupHelper.copy/FileSets/PatchSource/PageSettings.qml.orig 2024-04-13 11:31:17
+++ /Users/Kevin/GitHub/SetupHelper.copy/FileSets/PatchSource/PageSettings.qml 2024-04-13 11:31:17
@@ -1,3 +1,6 @@
+//////// modified to insert PackageManager menu
+//////// auto-generated by SetupHelper setup script
Expand Down
21 changes: 16 additions & 5 deletions FileSets/VersionIndependent/PageSettingsPackageEdit.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ MbPage {
property bool navigate: ! actionPending && ! waitForAction
property bool detailsExist: incompatibleDetails != ""
property bool detailsResolvable: incompatibleResolvableItem.valid ? incompatibleResolvableItem.value : ""
property bool showProceed: ( ! detailsExist || detailsResolvable || actionPending ) && ! waitForAction
property bool showProceed: ( showDetails || actionPending ) && ! waitForAction
/////////property bool showProceed: ( ! detailsExist || detailsResolvable || actionPending ) && ! waitForAction
property bool showDetails: false
property string localError: ""

Expand Down Expand Up @@ -209,8 +210,17 @@ MbPage {
{
if (showDetails)
{
sendCommand ( 'resolveConflicts:' + packageName, true )
showDetails = false
if (detailsResolvable)
{
sendCommand ( 'resolveConflicts:' + packageName, true )
showDetails = false
}
// trigger setup script prechecks
else
{
sendCommand ( 'check:' + packageName, true )
showDetails = false
}
}
else if (actionPending)
sendCommand ( requestedAction + ':' + packageName, true )
Expand All @@ -220,6 +230,7 @@ MbPage {
sendCommand ( 'reboot', true )
else if (actionNeeded.indexOf ( "restart" ) != -1 )
sendCommand ( 'restartGui', true )
hideActionNeededTimer.start ()
}
requestedAction = ''
}
Expand Down Expand Up @@ -341,9 +352,9 @@ MbPage {
width: 92
anchors { right: cancelButton.left; bottom: statusMessage.bottom }
description: ""
value: ( actionPending || showDetails ) ? qsTr("Proceed") : qsTr ("Now")
value: ( actionPending || detailsResolvable ) ? qsTr("Proceed") : showDetails ? qsTr ("Recheck") : qsTr ("Now")
onClicked: confirm ()
show: ( actionPending || (showDetails && detailsResolvable) || showActionNeeded ) && showProceed
show: ( actionPending || showDetails ) && showProceed || showActionNeeded
writeAccessLevel: User.AccessInstaller
}
MbOK
Expand Down
69 changes: 38 additions & 31 deletions HelperResources/CommonResources
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ standardActionPrompt ()
fi
echo " Uninstall (u) and restores all files to stock"
echo " Quit (q) without further action"
echo " Display setup log (s) outputs the last 100 lines of the log"
if [ ! -z "$packageLogFile" ]; then
echo " Display Log (l) outputs the last 100 lines of the log"
fi
echo " Display log (l) outputs the last 100 lines of the log"
echo
response=''
while true; do
Expand Down Expand Up @@ -359,9 +356,6 @@ standardActionPrompt ()
exit $EXIT_SUCCESS
;;
[lL]*)
displayLog $packageLogFile
;;
[sS]*)
displayLog $setupLogFile
;;
*)
Expand Down Expand Up @@ -627,7 +621,7 @@ updateActiveFile ()
cp "$currentPatchFile" "$previousPatchFile"
# no patch file used for this update
# make sure restoreActiveFile doesn't try to reverse patch for uninstall
else
elif [ -e "$previousPatchFile" ]; then
rm -f "$previousPatchFile"
fi
updateRestartFlags "$activeFile"
Expand Down Expand Up @@ -689,12 +683,15 @@ restoreActiveFile ()
# attempt to reverse patch the active file
# if success, don't restore original
previousPatchFile="$previousPatchesDir/$baseName.patch"
if [ -e "$previousPatchFile" ] &&
$patch --reverse "$activeFile" "$previousPatchFile" &> /dev/null ; then
if ! [ -e "$previousPatchFile" ]; then
logMessage "CRITICAL: $packageName $baseName - no prevoius patch file"
unpatchError=true
elif $patch --reverse "$activeFile" "$previousPatchFile" &> /dev/null ; then
restoreOriginal=false
# no previous patch file or reverse patch failed
# reverse patch failed
# original will be restored
else
logMessage "CRITICAL: $packageName $baseName - reverse patch failed"
unpatchError=true
fi
fi
Expand All @@ -710,15 +707,28 @@ restoreActiveFile ()
fi
fi

#### TODO: DRASTIC but can't think of a way around this
#### TODO: how/when to erase this message for this package ?????
if $unpatchError ; then
#### TODO: DRASTIC but can't think of a way around this
message="CRITICAL: $package $baseName could not be uninstalled"
logMessage "message"
echo "message" >> "$scriptDir/patchErrors"
message=" moodificataions by $remainingPackages were lost and must be reinstalled"
logMessage "message"
echo "message" >> "$scriptDir/patchErrors"
message1="CRITICAL: $package $baseName could not be uninstalled cleanly"
message2=" $remainingPackages must be uninstalled and reinstalled"
logMessage "$message1"
logMessage "$message2"
# remove previous patch errors - and report this error
rm -f "$scriptDir/patchErrors"
echo "$message1" >> "$scriptDir/patchErrors"
echo "$message2" >> "$scriptDir/patchErrors"

rm -f "$packageList"

# report errors to other packages as well
for otherPackage in $remainingPackages ; do
otherPkgPatchErrors="$packageRoot/$otherPackage/patchErrors"
rm -f "$otherPkgPatchErrors"
echo "$message1" >> "$otherPkgPatchErrors"
echo "$otherPackage must be uninstalled and reinstalled" >> "$otherPkgPatchErrors"
rm -f "$setupOptionsRoot/$otherPackage/previousPatches/$baseName.patch"
done
setInstallFailed $EXIT_PATCH_ERROR "patch error details were saved in $packageName/patchErrors"
fi

Expand Down Expand Up @@ -1454,7 +1464,6 @@ if $reinstall ; then
# not running from reinstallMods
else
runningAtBoot=false
pruneSetupLogFile
fi

if [ ! -d "$setupOptionsDir" ]; then
Expand Down Expand Up @@ -1589,14 +1598,14 @@ fi # if [ $scriptAction != 'UNINSTALL' ]

if ! [ -z "$fileListPatched" ];then
patchErrors=()
for file in ${fileListPatched[@]}; do
baseName=$( basename $file )
for activeFile in ${fileListPatched[@]}; do
baseName=$( basename $activeFile )
tempActiveFile="$tempFileDir/$baseName"
if [ -e "$file" ] ; then
if [ -e "$activeFile" ] ; then
previousPatchFile="$previousPatchesDir/$baseName.patch"

# chek for this package and others in .package list
packageList="$file.package"
packageList="$activeFile.package"
thisPackageInList=false
otherPackagesInList=false
if [ -f "$packageList" ]; then
Expand All @@ -1615,8 +1624,8 @@ if ! [ -z "$fileListPatched" ];then
if $thisPackageInList; then
# only this package modified active flie - ignore any previous patch and patch .orig file
if ! $otherPackagesInList ; then
if [ -e "$file.orig" ]; then
cp "$file.orig" "$tempActiveFile"
if [ -e "$activeFile.orig" ]; then
cp "$activeFile.orig" "$tempActiveFile"
patchOk=true
else
patchErrors+=( "no original file for $baseName" )
Expand All @@ -1625,26 +1634,24 @@ if ! [ -z "$fileListPatched" ];then
# attempt to remove the previous patch for this package
# then patch the result
else
if $patch --reverse -o "$tempActiveFile" "$file" "$previousPatchFile" &> /dev/null ; then
if $patch --reverse -o "$tempActiveFile" "$activeFile" "$previousPatchFile" &> /dev/null ; then
patchOk=true
# reverse patch failed
else
patchErrors+=( "unable to remove previous patch for $baseName" )
patchErrors+=( "unable to remove previous patch from active file $baseName" )
fi
rm "$previousPatchFile"
fi
# this package has not previously modified the active file
# other packages have modified the active file
# if not, there is no .orig file
# either way, patch the active file
else
cp "$file" "$tempActiveFile"
cp "$activeFile" "$tempActiveFile"
patchOk=true
fi
patchSuccess=false
forwardPatched="$tempFileDir/$baseName".patchedForInstall
currentPatchFile="$tempFileDir/$baseName.currentPatch"
reversePatchTest="$tempFileDir/$baseName.reversePatchTest"
# a suitable source for the patch was located above
if $patchOk; then
# attempt to patch the active file with any file ending in .patch
Expand Down Expand Up @@ -1679,7 +1686,7 @@ if ! [ -z "$fileListPatched" ];then
patchErrors+=( "$baseName no active file for patch" )
continue
fi
done # for file
done # for activeFile

# save errors in patchErrors file
if ! [ -z "$patchErrors" ] ; then
Expand Down
31 changes: 6 additions & 25 deletions HelperResources/IncludeHelpers
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
#!/bin/sh

# this script selects the correct location for helper Resources
# and sources them into the setup script
# this script sources helper Resources into the setup script
#
# for backward compatibility, CommonResources in the SetupHelper directory
# links to this file, not CommonResources
# CommonResources previously sourced the other files
# now sourcing all resource files is done from here
#
# the helper files location is either the package directory or in the SetupHelper directory
# if both are present, the one with the newer version number is incorporated
# into the setup script
# only the helper files located is the SetupHelper directory are used
# previous versions chose between this and a helper file set in the package directory
# but changes in SetupHelper to use a local copy of patch made this not possible
#
# this script should be sourced in the setup script before any other activities

# NOTE: this script uses VersionResources ONLY
# it does source any other helper files since final location has not yet been chosen

pkgDir="$( cd "$(dirname $0)" >/dev/null 2>&1 ; /bin/pwd -P )"
pkgRoot="$( dirname "$pkgDir")"
pkgName=$( basename $pkgDir )
shHelperDir="$pkgRoot/SetupHelper/HelperResources"
# assume helper files are in package directory - change below if not
helperResourcesDir="$pkgDir/HelperResources"
helperResourcesDir="$pkgRoot/SetupHelper/HelperResources"

if [ -e "$helperResourcesDir/version" ]; then
# both helper file sets are present - compare them and choose the newest
if [ -e "$shHelperDir" ]; then
# temporarily source the local VersionResources
source "$pkgDir/HelperResources/VersionResources"
# setup helper files are newer - switch to those helper files
compareVersions $( cat "$shHelperDir/version" ) $( cat "$pkgDir/HelperResources/version" )
if (( $? == 1 )); then
helperResourcesDir="$shHelperDir"
fi
fi
elif [ -e "$shHelperDir" ]; then
helperResourcesDir="$shHelperDir"
else
if ! [ -e "$helperResourcesDir" ]; then
echo "$pkgName: helper files not found - can't continue" | tee -a "/data/log/SetupHelper"
exit 1
fi
Expand Down
66 changes: 18 additions & 48 deletions HelperResources/LogHandler
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
#!/bin/bash

# LogHandler for SetupHelper
# contains a functions and variables necessare=y to write to and output logs
# contains a functions and variables necessarey to write to and output logs
#
# Refer to the SetupHelper ReadMe file for details on how to use these resources
#
# it is sourced by CommonResources and reinstall Mods
#
# there may be two logs associated with a setup script:
# the script helper log and optionally the package log
# logs are written to both places and additionally the command line if not running from reinstallMods

setupLogFile="/var/log/SetupHelper"
logDir="/var/log/PackageManager"
logFile="$logDir/current"
if ! [ "$logDir" ]; then
mkdir -P "$logDir"
touch "$logFile"
fi

oldLogFile="/var/log/SetupHelper"
if [ -e "$oldLogFile" ]; then
if (( $( tail -5 "$oldLogFile" | grep -c "WARNING: this log file no longer used" ) == 0 )); then
echo "WARNING: this log file no longer used" >> "$oldLogFile"
echo " SetupHelper now logged to /var/log/PackageManager/current" >> "$oldLogFile"
fi
fi

# enable logging to console
# scripts can disable logging by setting
Expand All @@ -21,26 +29,14 @@ logToConsole=true
# output the last 100 lines of the log file to the console
# the full path to the log file should be passed in $1
# converts the tai64 time stamp to human readable form
#
# $1 specifies the path to the log file
# $setupLogFile
# $packageLogFile is defined to point to the log file of the package if it exists

displayLog ()
{
if [ ! -z "$1" ]; then
if [ -f "$1" ]; then
tail -100 "$1" | tai64nlocal
else
echo "no log File $1 found"
fi
else
echo "no log File specified"
fi
tail -100 "$logFile" | tai64nlocal
}


# write a message to one or more log files
# write a message to log file and console

logMessage ()
{
Expand All @@ -50,31 +46,5 @@ logMessage ()
fi

# to setup helper log
if [ ! -z $setupLogFile ]; then
echo "$shortScriptName: $*" | tai64n >> $setupLogFile
fi

# to setup helper log
if [ ! -z $packageLogFile ]; then
# no log file yet - make enclosing directory
# if directory already exists mkdir will do nothing (silently)
if [ ! -f "$packageLogFile" ]; then
mkdir -p $(dirname "$packageLogFile")
fi
echo "$shortScriptName: $*" | tai64n >> $packageLogFile
fi
}


# truncates the log file if it's larger than 2000 lines
# it is called from the initialization code in CommonResources
# if NOT running at boot time

pruneSetupLogFile ()
{
if [ $(wc -l $setupLogFile | awk '{print $1}') -gt 2000 ]; then
tail -1000 $setupLogFile > $setupLogFile.tmp
mv $setupLogFile.tmp $setupLogFile
logMessage "log file truncated to last 1000 lines"
fi
echo "$shortScriptName: $*" | tai64n >> $logFile
}
1 change: 0 additions & 1 deletion HelperResources/version

This file was deleted.

1 change: 1 addition & 0 deletions HelperResources/version
2 changes: 1 addition & 1 deletion PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,7 @@ def UpdateVersionsAndFlags (self, doConflictChecks=False, doScriptPreChecks=Fals
with open ( packageDir + "/patchErrors" ) as file:
for line in file:
patchCheckErrors.append ( line )
compatible = False
patchCheckErrors = list ( set ( patchCheckErrors ) )
if patchCheckErrors != self.PatchCheckErrors:
self.PatchCheckErrors = patchCheckErrors
Expand All @@ -2092,7 +2093,6 @@ def UpdateVersionsAndFlags (self, doConflictChecks=False, doScriptPreChecks=Fals
details += patchFailure + "\n"
logging.warning (packageName + " patch check error: " + patchFailure + " ")
self.SetIncompatible ("patch error", details,)
compatible = False
else:
logging.warning (packageName + " patch check reported no errors")

Expand Down
2 changes: 1 addition & 1 deletion blindInstall/SetupHelperVersion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.0~29
v8.0~31
Loading

0 comments on commit 9ecea8b

Please sign in to comment.