upgrade scripts: extract the common code to upgrade-common.sh 83/275883/4
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 3 Jun 2022 12:01:57 +0000 (14:01 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 7 Jun 2022 14:38:46 +0000 (16:38 +0200)
Change-Id: I01cb0deeac4aeae745bcb225a651a3b031a58ce6

scripts/upgrade-common.inc
scripts/upgrade-fota.sh
scripts/upgrade-full.sh
scripts/upgrade-partial.sh

index da9357e12f7277e5a66d7278ba7730f25bd0c6e2..2fd6acf6d6c4b0c2e96ea082e3a3921fcc714dac 100644 (file)
@@ -5,6 +5,7 @@ HAL_PART_MAP_FILE="label_map.list"
 HAL_PART_LIST_FILE="background_copy.list"
 CONFIG_FILE="update.cfg"
 SET_UPGRADE_STATUS="/usr/bin/device_board_set_upgrade_status"
+DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
 TRUE=0
 FALSE=1
 
@@ -41,6 +42,14 @@ flog() {
        log "$1" "$LOG_FILE"
 }
 
+untrap() {
+       trap '' ERR
+}
+
+retrap() {
+       trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
+}
+
 unpack_file() {
        ARCHIVE_NAME="$1"
        FILE_NAME="$2"
@@ -215,3 +224,46 @@ exit_error() {
        set_upgrade_status -1
        exit 1
 }
+
+mount_partition() {
+       local GPT_LABEL="$1"
+       local DST="$2"
+       local MOUNT_OPTIONS="$3"
+       local SRC
+       if ! SRC="$(/usr/bin/blkid-print "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB" |\
+               /bin/sed -E 's|(part_nr: [0-9]+ )\((.*)\): (.*)|\3|')"; then
+               flog "[Error] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
+               return 1
+       fi
+       local MOUNTED="$(/bin/findmnt -n -o TARGET "$SRC" | /bin/head -n 1 || echo "")"
+       if [ "$MOUNTED" != "" ]; then
+               MOUNT_OPTIONS="bind,${MOUNT_OPTIONS}"
+               SRC="$MOUNTED"
+       fi
+       if ! /bin/mkdir -p "$DST"; then
+               flog "[Error] Unable to mkdir for mount destination: $DST"
+               return 1
+       fi
+       if ! /bin/mount -o "$MOUNT_OPTIONS" "$SRC" "$DST"; then
+               flog "[Error] Unable to mount $SRC to $DST, options: $MOUNT_OPTIONS"
+               return 1
+       fi
+       CLEANUP_PARTITION+=("$DST")
+       return 0
+}
+
+cleanup_partitions() {
+       # umount in reverse order
+       for (( idx=${#CLEANUP_PARTITION[@]}-1 ; idx>=0 ; idx-- )) ; do
+               local DST="${CLEANUP_PARTITION[idx]}"
+               if [ "$DST" == "" ]; then
+                       flog "[Error] Partition for cleanup is empty, idx: $idx, partition count: ${#CLEANUP_PARTITION[@]}"
+                       continue
+               fi
+               if ! /bin/umount "$DST"; then
+                       flog "[Error] Unable to umount $DST"
+               fi
+
+       done
+       CLEANUP_PARTITION=()
+}
index f998ac85381cae9b8cc0781570fe063ebddfc7b0..94bb55b37ccbc1ec5e019d895ec88aeca4a7ab87 100755 (executable)
@@ -15,59 +15,12 @@ FOTA_DIR="/opt/usr/data/fota"
 
 FOTA_UPDATE_PREFIX="/run/upgrade-sysroot"
 VERSION_FILE="$FOTA_UPDATE_PREFIX/opt/etc/version"
-DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
 
 SCRIPT_NAME="upgrade-fota.sh"
 LOG_FILE="/tmp/update-fota.log"
 
-untrap() {
-       trap '' ERR
-}
-
-retrap() {
-       trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
-}
-
-mount_partition() {
-       GPT_LABEL="$1"
-       DST="$2"
-       MOUNT_OPTIONS="$3"
-       if ! SRC="$(/usr/bin/blkid-print "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB" |\
-               /bin/sed -E 's|(part_nr: [0-9]+ )\((.*)\): (.*)|\3|')"; then
-               flog "[Error] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
-               return 1
-       fi
-       MOUNTED="$(/bin/findmnt -n -o TARGET "$SRC" | /bin/head -n 1 || echo "")"
-       if [ "$MOUNTED" != "" ]; then
-               MOUNT_OPTIONS="bind,${MOUNT_OPTIONS}"
-               SRC="$MOUNTED"
-       fi
-       if ! /bin/mkdir -p "$DST"; then
-               flog "[Error] Unable to mkdir for mount destination: $DST"
-               return 1
-       fi
-       if ! /bin/mount -o "$MOUNT_OPTIONS" "$SRC" "$DST"; then
-               flog "[Error] Unable to mount $SRC to $DST, options: $MOUNT_OPTIONS"
-               return 1
-       fi
-       CLEANUP_PARTITION+=("$DST")
-       return 0
-}
-
 cleanup() {
-       # umount in reverse order
-       for (( idx=${#CLEANUP_PARTITION[@]}-1 ; idx>=0 ; idx-- )) ; do
-               _DST="${CLEANUP_PARTITION[idx]}"
-               if [ "$_DST" == "" ]; then
-                       flog "[Error] Partition for cleanup is empty, idx: $idx, partition count: ${#CLEANUP_PARTITION[@]}"
-                       continue
-               fi
-               if ! /bin/umount "$_DST"; then
-                       flog "[Error] Unable to umount $_DST"
-               fi
-
-       done
-       CLEANUP_PARTITION=()
+       cleanup_partitions
        cleanup_files
 }
 
index f69b10b07c5340cc39887c45e35dc17f3ccdb2e7..1129cced18832dd97ba35bb689d782e08112bdf2 100755 (executable)
@@ -16,13 +16,9 @@ FOTA_DIR="/opt/usr/data/fota"
 . "${FOTA_DIR}"/upgrade-common.inc
 
 DOWNLOAD_DELTA=$1
-DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
 
 SCRIPT_NAME="upgrade-full.sh"
 LOG_FILE="/tmp/upgrade-trigger.log"
-CONFIG_FILE="update.cfg"
-HAL_UPGRADE_CFG_DIR="/hal/etc/upgrade/"
-HAL_PART_LIST_FILE="background_copy.list"
 
 if [ "$#" != "1" ] || [ ! -f "$1" ]; then
        log "[Error] Usage: $0 path_to_upgrade.tar[.gz]" "$LOG_FILE"
@@ -33,12 +29,26 @@ DELTA_TAR="$DOWNLOAD_DELTA"
 
 flog "[Info] Using <$DELTA_TAR> delta file."
 
+mount() {
+       mkdir -p "$FOTA_UPDATE_PREFIX/opt"
+       if ! mount_partition system-data "$FOTA_UPDATE_PREFIX/opt" "rw"; then
+               critical_flog "[Error] Unable to mount opt"
+               return 1
+       fi
+}
+
+cleanup() {
+       cleanup_partitions
+       cleanup_files
+}
+
 cleanup_files() {
        rm -f -- "$DELTA_TAR"
        rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
        rm -f -- "$FOTA_DIR/$CONFIG_FILE"
        rm -f -- "$FOTA_DIR/upgrade-common.inc"
        rm -f -- "$FOTA_DIR/upgrade-trigger.sh"
+       rm -f -- "$FOTA_DIR/upgrade-apply"
 }
 
 reboot_to_fota() {
@@ -51,7 +61,7 @@ reboot_to_fota() {
                critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
                exit 1
        fi
-       cleanup_files
+       cleanup
        /bin/sync
        flog "[Info] Rebooting to fota"
        if ! /sbin/reboot fota; then
@@ -65,5 +75,6 @@ check_used_block_device
 unpack_file "$DELTA_TAR" "$CONFIG_FILE"
 upgrade_images "$DOWNLOAD_DELTA"
 set_upgrade_status 80
+mount
 reboot_to_fota
-cleanup_files
+cleanup
index 02932798e2acbae34ecf9c98fba10745d05eba74..e6f723b7223076e398d4729aeab060b574530428 100755 (executable)
@@ -14,15 +14,6 @@ FOTA_DIR="/opt/usr/data/fota"
 
 SCRIPT_NAME="upgrade-partial.sh"
 LOG_FILE="/tmp/upgrade-partial.log"
-CONFIG_FILE="update.cfg"
-
-untrap() {
-       trap '' ERR
-}
-
-retrap() {
-       trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
-}
 
 check_args() {
        DOWNLOAD_DELTA="$1"
@@ -63,46 +54,8 @@ copy_delta() {
 
 FOTA_UPDATE_PREFIX="/run/upgrade-sysroot"
 
-mount_partition() {
-       GPT_LABEL="$1"
-       DST="$2"
-       MOUNT_OPTIONS="$3"
-       if ! SRC="$(/usr/bin/blkid-print "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB" |\
-               /bin/sed -E 's|(part_nr: [0-9]+ )\((.*)\): (.*)|\3|')" || [ "$SRC" == "" ]; then
-               flog "[Info] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
-               return 1
-       fi
-       MOUNTED="$(/bin/findmnt -n -o TARGET "$SRC" | /bin/head -n 1 || echo "")"
-       if [ "$MOUNTED" != "" ]; then
-               MOUNT_OPTIONS="bind,${MOUNT_OPTIONS}"
-               SRC="$MOUNTED"
-       fi
-       if ! /bin/mkdir -p "$DST"; then
-               flog "[Error] Unable to mkdir for mount destination: $DST"
-               return 1
-       fi
-       if ! /bin/mount -o "$MOUNT_OPTIONS" "$SRC" "$DST"; then
-               flog "[Error] Unable to mount $SRC to $DST, options: $MOUNT_OPTIONS"
-               return 1
-       fi
-       CLEANUP_PARTITION+=("$DST")
-       return 0
-}
-
 cleanup() {
-       # umount in reverse order
-       for (( idx=${#CLEANUP_PARTITION[@]}-1 ; idx>=0 ; idx-- )) ; do
-               _DST="${CLEANUP_PARTITION[idx]}"
-               if [ "$_DST" == "" ]; then
-                       flog "[Error] Partition for cleanup is empty, idx: $idx, partition count: ${#CLEANUP_PARTITION[@]}"
-                       continue
-               fi
-               if ! /bin/umount "$_DST"; then
-                       flog "[Error] Unable to umount $_DST"
-               fi
-
-       done
-       CLEANUP_PARTITION=()
+       cleanup_partitions
        cleanup_files
 }