Skip to content

Commit

Permalink
auto update bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed Nov 16, 2021
1 parent cb51d28 commit 6b23c70
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 44 deletions.
Binary file modified .DS_Store
Binary file not shown.
51 changes: 39 additions & 12 deletions UpdateResources
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,27 @@ function checkVersions ()
getFromUsb ()
{
local package=$1
local packageArchive="/media/$dir/$package"-$gitHubBranch.tar.gz
local packageArchive
local packageDir="/data/$package"
local lastUpdate=""
local fileSuffix

# the unpacked folder for version tags don't inclue the v (e.g, v2.4 is 2.4 in archive name)
# so the gitHubBranch is reworked to create a file suffix
if [[ ${gitHubBranch:0:1} == "v" ]]; then
fileSuffix=${gitHubBranch:1:999}
else
fileSuffix=$gitHubBranch
fi
packageArchive="/media/$dir/$package"-$fileSuffix.tar.gz

# archive not found on USB stick
if [ ! -f "$packageArchive" ]; then
return 0
fi

tar -xzf "$packageArchive" -C /data
if [ ! -d "$packageDir-$gitHubBranch" ]; then
if [ ! -d "$packageDir-$fileSuffix" ]; then
logMessage "ERROR: $packageArchive did not contain $package"
return 0
fi
Expand All @@ -96,7 +106,7 @@ getFromUsb ()
fi

# get archive version
archiveVersion=$(cat "/data/$package-$gitHubBranch/version")
archiveVersion=$(cat "/data/$package-$fileSuffix/version")
if [ ! -e "$packageDir" ]; then
if $logToConsole ; then
echo "$package not yet installed"
Expand Down Expand Up @@ -125,7 +135,7 @@ getFromUsb ()
# get the package from a GitHub
# The package is left in $package-$gitHubBranch for processing later
# $1 is the name of the package
# returns 0 if updated should NOT occur or 1 if update is acceptable for update
# returns 0 if update should NOT occur or 1 if update is acceptable

getFromGitHub ()
{
Expand Down Expand Up @@ -158,37 +168,54 @@ getFromGitHub ()
echo "$package is up to date"
fi
return 0
else
return 1
fi
fi
# update the package and reinstall it
wget -qO - https://github.com/$gitHubUser/$package/archive/$gitHubBranch.tar.gz | tar -xzf - -C /data
if [ ! -d "$packageDir-$gitHubBranch" ]; then
logMessage "ERROR: $packageArchive did not contain $package"
return 0
else
if [ $? -eq 0 ]; then
return 1
else
logMessage "ERROR: $package $gitHubUser $gitHubBranch not available"
return 0
fi
}


# install the archive and run setup script
#
# $1 is the package name
# $2 is the flag to allow running the script with user interaction
# $2 is the github branch/version tag
# $3 is the flag to allow running the script with user interaction

doUpdate ()
{
local package=$1
local packageDir="/data/$package"
local gitHubBranch=$2
local fileSuffix

# the unpacked folder for version tags don't inclue the v (e.g, v2.4 is 2.4 in archive name)
if [[ ${gitHubBranch:0:1} == "v" ]]; then
fileSuffix=${gitHubBranch:1:999}
else
fileSuffix=$gitHubBranch
fi

if [ $# -gt 1 ] && [ $2 == 'prompting' ]; then
if [ $# -gt 2 ] && [ $3 == 'prompting' ]; then
installOk=true
else
installOk=false
fi

# move new version into active position
if [ -d "$packageDir-$fileSuffix" ]; then
rm -rf "$packageDir"
mv "$packageDir-$fileSuffix" "$packageDir"
else
logMessage "$packageDir-$fileSuffix is missing - can't continue"
return
fi

if [ -f "$packageDir/setup" ]; then
# if package is installed, reinstall automatically
if [ -f "$installedFlagPrefix$package" ]; then
Expand Down
25 changes: 6 additions & 19 deletions packageAutoUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ logMessage "starting up"
usbCheck=false
mediaDetected=false
lastUpdateTime=0
checkingPackage=false
updateSetupHelper=false


Expand All @@ -91,7 +92,6 @@ lastGitHubUpdateSetting=0
# loop forever
while true ; do
rebootNeeded=false
checkingPackage=false
restartFromFirstPackage=false

# skip all processing if package list doesn't exist
Expand All @@ -103,12 +103,6 @@ while true ; do

# loop through packages from package list
while read -u 9 package gitHubUser gitHubBranch; do

#initialze package name & version arrays
packageIndex=0
packageNames=()
packageVersions=()

# skip comments
if [[ ${package:0:1} == "#" ]] ; then
continue
Expand All @@ -126,12 +120,6 @@ while true ; do
# package has been installed, check for updates
else
checkingPackage=true

# update package version table
packageNames[$packageIndex]=$package
packageVersions[$packageIndex]=$(cat "$packageDir/version")
logMessage "#### package index $packageIndex name: ${packageNames[$packageIndex]} version: ${packageVersions[$packageIndex]}"
((packageIndex++))
fi

# this loop permits detection of USB media during the long wait for the next GitHub check
Expand Down Expand Up @@ -224,8 +212,8 @@ logMessage "#### package index $packageIndex name: ${packageNames[$packageIndex
# reinstall the package without user interaction
else
# update via unattended reinstall only
logMessage "updating $package"
doUpdate $package
logMessage "updating $package with $gitHubBranch"
doUpdate $package $gitHubBranch
if $usbCheck ; then
sleep 1
fi
Expand All @@ -244,16 +232,15 @@ logMessage "#### package index $packageIndex name: ${packageNames[$packageIndex
fi
done # end while checkingPackage


if $restartFromFirstPackage ; then
if $restartFromFirstPackage || $updateSetupHelper ; then
break
else
sleep 1
fi
done 9< "$packageListFile" # end while read ...

# if not restarting scan, update automatic update state
if ! $restartFromFirstPackage ; then
if ! $restartFromFirstPackage && ! $updateSetupHelper; then
# single pass
if (( $autoUpdateSetting == 3 )) ; then
setSetting 0 /Settings/GuiMods/GitHubAutoUpdate
Expand All @@ -269,7 +256,7 @@ logMessage "#### package index $packageIndex name: ${packageNames[$packageIndex
if $updateSetupHelper || $rebootNeeded ; then
logMessage "continuing in cleanup script - $packageName exiting"

nohup "$scriptDir/packageAutoUpdaterCleanup" $updateSetupHelper $rebootNeeded 2>&1 | awk '{print "packageAutoUpdater " $0}'| tai64n >> /var/log/SetupHelper &
nohup "$scriptDir/packageAutoUpdaterCleanup" $gitHubBranch $updateSetupHelper $rebootNeeded 2>&1 | awk '{print "packageAutoUpdaterCleanup " $0}'| tai64n >> /var/log/SetupHelper &

# shutdown the service which runs this script - this will end this script
svc -d "/service/SetupHelper"
Expand Down
17 changes: 9 additions & 8 deletions packageAutoUpdaterCleanup
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# This script also reboots the system if needed.

# get parameters from command line
updateSetupHelper=$1
rebootNeeded=$2

gitHubBranch=$1
updateSetupHelper=$2
rebootNeeded=$3

# get the full, unambiguous path to this script
scriptDir="$( cd "$(dirname $0)" >/dev/null 2>&1 ; /bin/pwd -P )"
shortScriptName=$(basename "$scriptDir")/$(basename "$0")
Expand All @@ -26,11 +27,11 @@ sleep 2

if $updateSetupHelper ; then
logMessage "running SetupHelper setup script to reinstall"
doUpdate "SetupHelper"
doUpdate "SetupHelper" $gitHubBranch
fi

# reboot now if any script reboots were indicated
if $rebootNeeded ; then
logMessage "rebooting ..."
reboot
fi
#if $rebootNeeded ; then
# logMessage "rebooting ..."
# reboot
#fi
2 changes: 1 addition & 1 deletion service/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#exec 2>&1
exec /data/SetupHelper/packageAutoUpdater
exec /data/SetupHelper/packageAutoUpdater > /dev/null

12 changes: 9 additions & 3 deletions updatePackageVersions
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ newNames=()
newVersions=()
oldNames=()
oldVersions=()

# read in old values
if [ -f "$versionsFile" ]; then
index=0
while read -u 8 oldPackage oldVersion; do
# skip comments
if [[ ${oldPackage:0:1} == "#" ]] ; then
continue
# skip blank/incomplete lines
elif [ -z $oldPackage ] ; then
continue
fi

oldNames[$index]=$oldPackage
oldVersions[$index]=$oldVersion
((index++))
Expand All @@ -45,7 +52,7 @@ oldCount=${#oldNames[@]}

# loop through packages from package list
index=0
rm -f "$versionsFile"
echo "# AUTO GENERATED DO NOT MODIFY" > "$versionsFile"
while read -u 9 package gitHubUser gitHubBranch; do

# skip comments
Expand Down Expand Up @@ -103,7 +110,6 @@ done

index=$newCount
while (( $index < $oldCount )); do
echo "### remove setting for $index"
removeDbusSetting "/Settings/PackageVersion/$index/PackageName"
removeDbusSetting "/Settings/PackageVersion/$index/PackageVersion"
((index++))
Expand Down
Binary file removed venus-data.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.2
v3.3

0 comments on commit 6b23c70

Please sign in to comment.