return 0
}
-
-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_ISU_PKG()
-{
- local PKG_NAME=$1
- rm -rf "/opt/isu/$PKG_NAME"
-}
-
-TRY_START_SERVICE()
-{
- local SERVICE=$1
- local DESIRED_STATE=$2
-
- systemctl start "$SERVICE"
-
- if [ "$(systemctl is-active $SERVICE)" != "$DESIRED_STATE" ]; then
- echo "Couldn't start service: $SERVICE"
- fi
-}
-
-PREPARE_PKGMGR_ENV()
-{
- TRY_START_SERVICE pkgmgr-info active
- # "systemctl is-active" will output "inactive" for a oneshot unit
- # that's currently not running but was successful last time it ran
- TRY_START_SERVICE security-manager-rules-loader inactive
- TRY_START_SERVICE security-manager active
- TRY_START_SERVICE ac.service active
- TRY_START_SERVICE package-manager active
-}
-
-REMOVE_ISU_APP_PKG()
-{
- local PKG_NAME="$1"
- local APP_NAME="org.tizen.isu.$PKG_NAME"
- local APP_DIR="/opt/usr/globalapps/$APP_NAME"
- if [ -d "$APP_DIR" ]; then
- /usr/bin/pkgcmd -u -n "$APP_NAME"
- fi
-}
-
-REMOVE_UNNECESSARY_ISU_PKGS()
-{
- local OS_RELEASE_NAME
- local UPGRADE_CFG_PATH=/etc/isu/upgrade.cfg
- OS__tz_build_release_name=$(grep TZ_BUILD_RELEASE_NAME /etc/tizen-build.conf | awk -F '"' '{print $2}')
- OS__tz_build_arch=$(grep TZ_BUILD_ARCH /etc/tizen-build.conf | awk -F '=' '{print $2}')
- OS__model_name=$(sed -n -e '/.*model_name.*/s!.*<key[^>]*>\(.*\)</key>!\1!gp' /etc/config/model-config.xml)
- OS__manufacturer=$(sed -n -e '/.*manufacturer.*/s!.*<key[^>]*>\(.*\)</key>!\1!gp' /etc/config/model-config.xml)
- OS__device_type=$(sed -n -e '/.*device_type.*/s!.*<key[^>]*>\(.*\)</key>!\1!gp' /etc/config/model-config.xml)
-
- local platform_major_version_fields="tz_build_release_name tz_build_arch model_name device_type"
- if [ -f "${UPGRADE_CFG_PATH}" ]; then
- fields_from_file=$(grep -e ^platform_major_version_fields "${UPGRADE_CFG_PATH}" | cut -f2 -d= | sed -e 's/,/ /g')
- if [ -n "${fields_from_file}" ]; then
- platform_major_version_fields="$fields_from_file"
- fi
- fi
-
- for ISUCFG in $(find /opt/isu/ -maxdepth 2 -type f -name isu.cfg); do
- PKG_NAME=$(basename "$(dirname "$ISUCFG")")
- if [ ! -d "/etc/isu/$PKG_NAME" ]; then
- NOTIFY "Platform image does not contain information about ${PKG_NAME} - unable to verify which is newer (ISU or Platform). Dropping ISU package ${PKG_NAME}."
- REMOVE_ISU_PKG "$PKG_NAME"
- REMOVE_ISU_APP_PKG "$PKG_NAME"
- 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}')
- ISU__tz_build_release_name=$(grep -e "^tz_build_release_name" "/opt/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
- ISU__tz_build_arch=$(grep -e "^tz_build_arch" "/opt/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
- ISU__model_name=$(grep -e "^model_name" "/opt/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
- ISU__manufacturer=$(grep -e "^manufacturer" "/opt/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
- ISU__device_type=$(grep -e "^device_type" "/opt/isu/$PKG_NAME/isu.cfg" | awk -F "=" '{ gsub(/[ ]+/, ""); print $2}')
-
-
- for field in $platform_major_version_fields; do
- os_value=OS__$field
- isu_value=ISU__$field
- if [ "${!os_value}" != "${!isu_value}" ]; then
- # One of the values defined in /opt/isu/upgrade.cfg is different.
- # In that case we remove the ISU package because it may
- # not be compatible with this version of the system.
- NOTIFY "${field} value is different for OS and ISU - removing incompatible ${PKG_NAME} ISU package"
- REMOVE_ISU_PKG "$PKG_NAME"
- REMOVE_ISU_APP_PKG "$PKG_NAME"
- continue 2
- fi
-
- done
-
- 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
- REMOVE_ISU_PKG "$PKG_NAME"
- REMOVE_ISU_APP_PKG "$PKG_NAME"
- fi
- done
-}