Skip to content

Commit 6a9a574

Browse files
committed
resize root partition and check for room on file systems before allowing install
1 parent 54fb396 commit 6a9a574

12 files changed

+693
-362
lines changed

CommonResources

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,18 @@ backupActiveFile ()
174174
#
175175
# updateActiveFile sourceFile activeFile
176176
# a separate source (replacement) file is specified
177-
# either as a full path to the actual file
178-
# or as the basename of a file to be found in the version directory or FileSets
177+
#
178+
# both sourceFile and activeFile must be a full path to the file
179179
#
180180
# if the update fails, scriptAction is changed to UNINSTALL
181181

182182
updateActiveFile ()
183183
{
184-
sourceFound=false
185184
thisFileUpdated=false
186-
187-
sourceFile="$1"
185+
local sourceFound=false
186+
local baseName
187+
local sourceFile="$1"
188+
local destinationFile
188189

189190
# separate replacement file specified
190191
if [ $# == 2 ]; then
@@ -199,13 +200,13 @@ updateActiveFile ()
199200

200201
# look for source in FileSets
201202
if ! $sourceFound ; then
202-
sourceFile="$(basename "$sourceFile")"
203+
baseName="$(basename "$sourceFile")"
203204
# found in version directory
204-
if [ -f "$fileSet/$sourceFile" ]; then
205-
sourceFile="$fileSet/$sourceFile"
205+
if [ -f "$fileSet/$baseName" ]; then
206+
sourceFile="$fileSet/$baseName"
206207
sourceFound=true
207-
elif [ -f "$pkgFileSets/$sourceFile" ]; then
208-
sourceFile="$pkgFileSets/$sourceFile"
208+
elif [ -f "$pkgFileSets/$baseName" ]; then
209+
sourceFile="$pkgFileSets/$baseName"
209210
sourceFound=true
210211
fi
211212
fi
@@ -217,10 +218,8 @@ updateActiveFile ()
217218
return
218219
# if not flagged, this is a fatal error
219220
else
220-
logMessage "ERROR: no replacement file for $sourceFile"
221-
thisFileUpdated=false
221+
logMessage "ERROR: no soure file for replacement - can't continue with install'"
222222
scriptAction='UNINSTALL'
223-
touch "$fileSet/INCOMPLETE"
224223
installFailed=true
225224
fi
226225
return
@@ -640,9 +639,17 @@ while [ $# -gt 0 ]; do
640639
shift
641640
done
642641

643-
# make sure rootfs is mounted R/W
644-
if [ -f /opt/victronenergy/swupdate-scripts/remount-rw.sh ]; then
645-
/opt/victronenergy/swupdate-scripts/remount-rw.sh
642+
# make sure rootfs is mounted R/W & and resized to allow space for replacement files
643+
if [ -f /opt/victronenergy/swupdate-scripts/resize2fs.sh ]; then
644+
/opt/victronenergy/swupdate-scripts/resize2fs.sh
645+
fi
646+
647+
# make sure the root partition has space for the package
648+
# arbitrary minimum size of 10 MB for now
649+
availableSpace=$(df -m / | tail -1 | awk '{print $4}')
650+
if (( $availableSpace < 10 )); then
651+
logMessage "no room for modified files on /root ($availableSpace MB remaining) - can't continue"
652+
exit $EXIT_ROOT_FULL
646653
fi
647654

648655
# move old installedFlag ("...inInstalled...")

EssentialResources

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ EXIT_INCOMPATIBLE_PLATFOM=253
4545
EXIT_FILE_SET_ERROR=252
4646
EXIT_OPTIONS_NOT_SET=251
4747
EXIT_RUN_AGAIN=250
48+
EXIT_ROOT_FULL=249
49+
EXIT_DATA_FULL=248
4850
# old variables - keep for compatibility
4951
exitReboot=$EXIT_REBOOT
5052
exitSuccess=$EXIT_SUCCESS

FileSets/PageSettingsPackageEdit.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ MbPage {
204204
return qsTr ("must install\nfrom command line" )
205205
else if (incompatibleReason == 'NO_FILE_SET')
206206
return qsTr ( "no file set for\n" + osVersion )
207+
else if (incompatibleReason == 'ROOT_FULL')
208+
return qsTr ( "no room on root partition" )
209+
else if (incompatibleReason == 'DATA_FULL')
210+
return qsTr ( "no room on data partition" )
207211
else
208212
return qsTr ("incompatible ???" ) // compatible for unknown reason
209213
}

PackageManager.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
# 'VERSION' if the system version is outside the package's acceptable range
4848
# 'PLATFORM' package can not run on this platform
4949
# 'NO_FILE_SET' missing or incomplete file set for Venus OS version
50+
# 'ROOT_FULL' no room on root partition to install package modificaitons
51+
# 'DATA_FULL' no room on /data partition to install package modificaitons
5052
# 'CMDLINE' setup must be run from command line
5153
# currently only for Raspberry PI packages only
5254
#
@@ -127,6 +129,9 @@
127129
EXIT_FILE_SET_ERROR = 252
128130
EXIT_OPTIONS_NOT_SET = 251
129131
EXIT_RUN_AGAIN = 250
132+
EXIT_ROOT_FULL = 249
133+
EXIT_DATA_FULL = 248
134+
130135
EXIT_ERROR = 255 # generic error
131136
# install states only
132137
ERROR_NO_SETUP_FILE = 999
@@ -2402,12 +2407,12 @@ def GitHubDownload (self, packageName= None, source=None):
24022407

24032408
# attempt to locate a directory that contains a version file
24042409
# the first directory in the tree starting with tempDicrectory
2405-
# is returnd
2410+
# is returned
24062411
unpackedPath = LocatePackagePath (tempDirectory)
24072412
if unpackedPath == None:
24082413
PackageClass.UpdateDownloadPending (packageName, False)
24092414
shutil.rmtree (tempDirectory)
2410-
logging.error ( "GitHubDownload: no archive path for " + packageName)
2415+
logging.error ( "GitHubDownload: no archive path for " + packageName )
24112416
return False
24122417

24132418
# move unpacked archive to package location
@@ -2418,7 +2423,10 @@ def GitHubDownload (self, packageName= None, source=None):
24182423
DbusIf.LOCK ()
24192424
if os.path.exists (packagePath):
24202425
os.rename (packagePath, tempPackagePath)
2421-
shutil.move (unpackedPath, packagePath)
2426+
try:
2427+
shutil.move (unpackedPath, packagePath)
2428+
except:
2429+
logging.error ( "GitHubDownload: couldn't relocate " + packageName )
24222430
if os.path.exists (tempPackagePath):
24232431
shutil.rmtree (tempPackagePath, ignore_errors=True) # like rm -rf
24242432
DbusIf.UNLOCK ()
@@ -2713,6 +2721,18 @@ def InstallPackage ( self, packageName=None, source=None , direction='install' )
27132721
where=sendStatusTo, logLevel=ERROR )
27142722
if source == 'GUI':
27152723
DbusIf.SetGuiEditAction ( 'ERROR' )
2724+
elif returnCode == EXIT_ROOT_FULL:
2725+
package.SetIncompatible ('ROOT_FULL')
2726+
DbusIf.UpdateStatus ( message=packageName + " no room on root partition ",
2727+
where=sendStatusTo, logLevel=ERROR )
2728+
if source == 'GUI':
2729+
DbusIf.SetGuiEditAction ( 'ERROR' )
2730+
elif returnCode == EXIT_DATA_FULL:
2731+
package.SetIncompatible ('DATA_FULL')
2732+
DbusIf.UpdateStatus ( message=packageName + " no room on data partition ",
2733+
where=sendStatusTo, logLevel=ERROR )
2734+
if source == 'GUI':
2735+
DbusIf.SetGuiEditAction ( 'ERROR' )
27162736
# unknown error
27172737
elif returnCode != 0:
27182738
DbusIf.UpdateStatus ( message=packageName + " " + direction + " unknown error " + str (returnCode),
@@ -2907,7 +2927,10 @@ def transferPackage (self, path, autoInstallOverride=False):
29072927
shutil.rmtree (tempPackagePath, ignore_errors=True) # like rm -rf
29082928
if os.path.exists (packagePath):
29092929
os.rename (packagePath, tempPackagePath)
2910-
shutil.move (unpackedPath, packagePath)
2930+
try:
2931+
shutil.move (unpackedPath, packagePath)
2932+
except:
2933+
logging.error ( "transferPackages: couldn't relocate " + packageName )
29112934
if os.path.exists (tempPackagePath):
29122935
shutil.rmtree (tempPackagePath, ignore_errors=True) # like rm -rf
29132936
# set package one-time install flag so this package is installed regardless of other flags
@@ -3142,7 +3165,10 @@ def settingsRestore (self, backupPath, settingsOnly = False):
31423165
for overlay in overlayFiles:
31433166
if overlay[0] == ".":
31443167
continue
3145-
shutil.copy ( overlaySourceDir + "/" + overlay, overlayDestDir )
3168+
try:
3169+
shutil.copy ( overlaySourceDir + "/" + overlay, overlayDestDir )
3170+
except:
3171+
logging.error ("settingsRestore: overlay create failed for " + overlay)
31463172
overlayCount += 1
31473173

31483174
# restore setup script options
@@ -3154,7 +3180,10 @@ def settingsRestore (self, backupPath, settingsOnly = False):
31543180
shutil.rmtree (optionsDestDir)
31553181

31563182
if os.path.isdir (optionsSourceDir):
3157-
shutil.copytree ( optionsSourceDir, optionsDestDir )
3183+
try:
3184+
shutil.copytree ( optionsSourceDir, optionsDestDir )
3185+
except:
3186+
logging.error ("settingsRestore: options restore failed")
31583187

31593188
logging.warning ("settings restore completed - " + str(settingsCount) + " settings and " + str (overlayCount) + " overlays")
31603189

ReadMe

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ CAUTION:
7979
Note that removal does not actually remove the package so other setup scripts
8080
will continue to function.
8181

82+
Note: You can install other packages using wget as described above.
83+
Or you can download the .tgz file and put that on a USB stick and plug that into the GX device.
84+
PackageManager will detect the file and install the package.
85+
8286

8387
ssh access:
8488

@@ -110,16 +114,26 @@ Third, if you have terminal or ssh access, try running the package setup scripts
110114

111115
Fourth, try booting to the previous Venus OS version (in Stored backup firmware)
112116
Then perform a fresh Online firmware update to the latest version or use the .swu update via removable media.
113-
These procedures are documented: https://www.victronenergy.com/media/pg/Cerbo_GX/en/gx---how-to-update-firmware.html
114117

115118
Use the Settings / Firmware / Stored backup formware menu if you have GUI access.
116119

117120
If you don't have GUI access, you can also switch to the backup version from the command line:
118121
/opt/victronenergy/swupdate-scripts/set-version.sh 2
119122

123+
You can also force a firmware upate from the command line if you have ssh or terminal access:
124+
For on-line updates:
125+
/opt/victronenergy/swupdate-scripts/check-swupdate.sh -force -update
126+
For updates from removable media:
127+
/opt/victronenergy/swupdate-scripts/check-swupdate.sh -force -update -offline
128+
120129
Fifth, perform the Blind uninstall procedure below.
121130

122-
Finally, if you are running on a Raspberry PI, you can reimage the system SD card.
131+
Finally:
132+
If you are running on a Raspberry PI, you can reimage the system SD card.
133+
134+
If you have a Cerbo, you can reimage it using this procedure:
135+
https://community.victronenergy.com/questions/204255/cerbo-gx-bricked-how-to-recover.html
136+
123137
Note: this will wipe out all settings and you'll need to reconfigure the GX device from scratch.
124138

125139
The Victron "restore factory default" procedure can be used to will wipe out all settings.

blindInstall/SetupHelperVersion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v5.10
1+
v5.11

changes

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
v5.11:
2+
check for room on file systems before allowing install
3+
resize root partition before installing a package
4+
the above issues are critical to avoid bricking systems !!!!!!
5+
updateFileSets:
6+
better error checking and more status while running long loops
7+
a replacement file and USE_ORIGINAL flag was incorrectly allowed
8+
the replacement file has priority during package install so
9+
this was not a severe issue, but USE_ORIGINAL is now removed in this case
10+
111
v5.10:
212
updateFileSets: check for errors before moving version-independent files
313

@@ -8,7 +18,7 @@ v5.8:
818
fixed bugs in updateFileSets introduced in v5.7
919

1020
v5.7:
11-
updateFileSets: make changes to the backup of the package
21+
updateFileSets: make changes to the copy of the package
1222
instead of to the main package directory
1323
so package is not updated until changes are accepted
1424
updateFileSets: check for version-independent files in file sets

setup

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,33 @@ fi
5757

5858
if [ $scriptAction == 'INSTALL' ] ; then
5959
# modify PageSettings here so SetupHelper is independent of Venus OS verison
60+
origFile=""
6061
if [ -f "$qmlDir/PageSettings.qml.orig" ]; then
61-
origFile="$qmlDir/PageSettings.qml.orig"
62-
else
63-
origFile="$qmlDir/PageSettings.qml"
62+
lineCount=$(wc "$qmlDir/PageSettings.qml.orig" | awk '{print $1}')
63+
if (( $lineCount > 50 )); then
64+
origFile="$qmlDir/PageSettings.qml.orig"
65+
fi
66+
elif [ -z "$origFile" ]; then
67+
lineCount=$(wc "$qmlDir/PageSettings.qml" | awk '{print $1}')
68+
if (( $lineCount > 50 )); then
69+
origFile="$qmlDir/PageSettings.qml"
70+
fi
6471
fi
65-
if (( $(grep -c "PackageManager" $origFile) > 0)); then
72+
if [ -z "$origFile" ]; then
73+
logMessage "ERROR: PageSettings.qml not found - can't continue"
74+
exit $EXIT_ERROR
75+
elif (( $(grep -c "PackageManager" $origFile) > 0)); then
6676
logMessage "WARNING: PageSettings.qml already modified for PackageManager -- skipping that modification"
6777
else
6878
rm -f "/var/volatile/tmp/PageSettings.qml"
6979
echo "//////// modified to insert PackageManager menu" > "/var/volatile/tmp/PageSettings.qml"
7080
# find line with second to last }
7181
insertBefore=$(awk '{print NR " " $s}' "$origFile" | grep '}' | tail -2 | head -n 1 | awk '{print $1}')
7282
((insertBefore -= 1))
83+
if (( $insertBefore < 10 )); then
84+
logMessage "ERROR: PageSettings.qml could not be modified - can't continue"
85+
exit $EXIT_ERROR
86+
fi
7387
# include all lines before that one
7488
head -n $insertBefore $origFile >> "/var/volatile/tmp/PageSettings.qml"
7589
# file with PackageManager menu code includes the last two }

0 commit comments

Comments
 (0)