rw-upgrade: Remove deprecated ISU Pkgs after OS upgrade 06/292706/3
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 11 May 2023 11:49:03 +0000 (13:49 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Mon, 7 Aug 2023 09:33:52 +0000 (11:33 +0200)
Change-Id: Ibe1a96ce2f29a64348a02ab95172e17c69870f66

scripts/rw-upgrade/update.sh.in

index 43653e24c76176449b42cde6198f02c36b240db9..26d965ad24ff8db9254da888f9027c54848a10a4 100644 (file)
@@ -73,6 +73,55 @@ PROGRESS()
        echo "$1" > ${PROGRESS_DIR}/progress
 }
 
+VERSION_COMPARE() {
+        local IFS='.'
+        ver_a=($1)
+        ver_b=($2)
+
+        local n
+        if [[ ${#ver_a[@]} > ${#ver_b[@]} ]]; then
+                n=${#ver_a[@]}
+        else
+                n=${#ver_b[@]}
+        fi
+        for ((i=0; i < n; i++)); do
+                if [[ $i -ge ${#ver_a[@]} ]]; then
+                        ver_a[$i]=0
+                fi
+                if [[ $i -ge ${#ver_b[@]} ]]; then
+                        ver_b[$i]=0
+                fi
+        done
+        for ((i=0; i < ${#ver_a[@]}; i++)); do
+                if (( ver_a[i] > ver_b[i] )); then
+                        return 1
+                elif (( ver_a[i] < ver_b[i] )); then
+                        return 2
+                fi
+        done
+        return 0
+}
+
+REMOVE_UNNECESSARY_ISU_PKGS()
+{
+       for ISUCFG in $(find /etc/isu/ -type f -name isu.cfg); do
+               PKG_NAME=$(basename "$(dirname "$ISUCFG")")
+               if [ ! -d "/opt/isu/$PKG_NAME" ]; then
+                       continue
+               fi
+               CUR_IMG_VERSION=$(grep -e "^version" "/etc/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
+               INSTALLED_VERSION=$(grep -e "^version" "/opt/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
+
+               VERSION_COMPARE "$CUR_IMG_VERSION" "$INSTALLED_VERSION"
+
+               if [[ $? != 2 ]]; then
+                       # Package from the current image is newer than the one installed
+                       # so we can remove the installed one
+                       rm -rf "/opt/isu/$PKG_NAME"
+               fi
+       done
+}
+
 # This result file will be used for Platform Update Control API to get update result.
 UPDATE_RESULT_FILE=${UPDATE_DATA_DIR}/result
 UPI_RW_UPDATE_ERROR_NONE=00
@@ -100,6 +149,11 @@ then
        exit
 fi
 
+NOTIFY "----------------------------------------------------------------------"
+NOTIFY "Remove deprecated ISU Packages"
+
+REMOVE_UNNECESSARY_ISU_PKGS
+
 NOTIFY "----------------------------------------------------------------------"
 NOTIFY "System RW update: rw update started"