Patch for update-helper 74/176274/3 accepted/tizen/unified/20180419.075946 submit/tizen/20180418.090628
authorSunmin Lee <sunm.lee@samsung.com>
Wed, 14 Feb 2018 02:40:56 +0000 (11:40 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Wed, 18 Apr 2018 06:12:24 +0000 (15:12 +0900)
The update-helper is a system privileged service that:
- executes the TOTA trigger script
- copies the update result to DOWNLOAD.PATH which can be
  accessible by downloader (ex. client)

Change-Id: I9df91e1417ffdb80937d4be9d8af1e80c2e1c6d1
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
packaging/tota-ua.spec
scripts/upgrade-trigger.sh [changed mode: 0755->0644]
update-helper/update-helper.path [new file with mode: 0644]
update-helper/update-helper.service [new file with mode: 0644]
update-helper/update-helper.sh [new file with mode: 0755]

index d3d1b83..5f565e2 100755 (executable)
@@ -14,9 +14,9 @@ BuildRequires:  pkgconfig(libpng)
 BuildRequires:  pkgconfig(libssl)
 BuildRequires:  pkgconfig(tota)
 BuildRequires:  pkgconfig(openssl)
-BuildRequires:  pkgconfig(libtzplatform-config)
 
 Requires:       tar
+Requires:       gzip
 
 %description
 Fota update agent which update firmware using delta files
@@ -27,11 +27,15 @@ Requires:   %{name} = %{version}-%{release}
 %description target_wearable
 TOTA update GUI binary targeting wearable target.
 
+%package -n update-helper-service
+Summary:       Update Helper Package for update-agent
+Requires:      %{name} = %{version}-%{release}
+%description -n update-helper-service
+Update helper service and script package for update-agent
 
 %prep
 %setup -q
 
-
 %build
 export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
 LDFLAGS="$LDFLAGS"
@@ -50,8 +54,18 @@ cp scripts/wearable/41-tota-ua.list \
           %{buildroot}%{_datadir}/initrd-recovery/initrd.list.d/41-tota-ua.list.wearable
 
 install -m 755 scripts/upgrade-trigger.sh %{buildroot}%{_bindir}
-%define fota_data_dir %{TZ_SYS_GLOBALUSER_DATA}/fota/save
-mkdir -p %{buildroot}%{fota_data_dir}
+%define fota_dir /opt/usr/data/fota
+mkdir -p %{buildroot}%{fota_dir}
+
+# update-helper-service
+%define update_dir %{_datadir}/upgrade
+mkdir -p %{buildroot}%{update_dir}
+mkdir -p %{buildroot}%{_unitdir}/basic.target.wants
+install -m 755 update-helper/update-helper.sh %{buildroot}%{update_dir}
+install -m 644 update-helper/update-helper.service %{buildroot}%{_unitdir}
+install -m 644 update-helper/update-helper.path %{buildroot}%{_unitdir}
+ln -s ../update-helper.service %{buildroot}%{_unitdir}/basic.target.wants
+ln -s ../update-helper.path %{buildroot}%{_unitdir}/basic.target.wants
 
 %post target_wearable
 mv %{_datadir}/fota/res/images_wearable %{_datadir}/fota/res/images
@@ -64,7 +78,7 @@ mv %{_datadir}/initrd-recovery/initrd.list.d/41-tota-ua.list.wearable \
 %license LICENSE
 %manifest tota-ua.manifest
 %doc README
-%{fota_data_dir}
+%{fota_dir}
 %defattr(-,root,root,-)
 %{_bindir}/delta.ua
 %{_bindir}/upgrade-trigger.sh
@@ -75,3 +89,10 @@ mv %{_datadir}/initrd-recovery/initrd.list.d/41-tota-ua.list.wearable \
 %{_datadir}/fota/res/images_wearable
 %{_bindir}/fota_gui
 %{_bindir}/fota_gui_test
+
+%files -n update-helper-service
+%{update_dir}/update-helper.sh
+%{_unitdir}/update-helper.path
+%{_unitdir}/update-helper.service
+%{_unitdir}/basic.target.wants/update-helper.path
+%{_unitdir}/basic.target.wants/update-helper.service
old mode 100755 (executable)
new mode 100644 (file)
index 72f7944..93b6257
@@ -1,9 +1,9 @@
 #!/bin/bash
-source /etc/tizen-platform.conf
-FOTA_DIR="$TZ_SYS_GLOBALUSER_DATA/update/save"
+FOTA_DIR="/opt/usr/data/fota"
 STATUS_DIR="/opt/data/update"
 VERSION_FILE="/opt/etc/version"
-DELTA_TAR=$1
+DOWNLOAD_DELTA=$1
+DELTA_TAR="$FOTA_DIR/delta.tar"
 
 flash_pre_image() {
        echo "Flash images for update..."
@@ -97,13 +97,17 @@ if [ $? -ne 0 ]; then
        write_version_info
 fi
 
+echo "Copy delta.tar..."
+/bin/cp $DOWNLOAD_DELTA $DELTA_TAR
+sync
+
 # Run pre-script if exist
 run_pre_script
 
 # Flash images
-#  - in case of some image was newly included
+#  - in case of some new image was included
 #  - in case of some image should be flashed before update
-flash_pre_image $DELTA_TAR
+flash_pre_image
 
 # Extract delta.ua
 echo "Extract delta.ua..."
@@ -111,15 +115,12 @@ echo "Extract delta.ua..."
 sync
 sleep 1
 
-echo "Move delta.tar..."
-mv $DELTA_TAR $FOTA_DIR/delta.tar
-sync
-
 # FOTA: /usr/bin/rw-update-prepare.sh
 
 # Write delta saved path
-echo "Write DELTA.PATH..."
+echo "Write paths..."
 echo "$FOTA_DIR" > "$STATUS_DIR/DELTA.PATH"
+echo "$(dirname $DOWNLOAD_DELTA)" > "$STATUS_DIR/DOWNLOAD.PATH"
 sync
 
 # go to fota mode
diff --git a/update-helper/update-helper.path b/update-helper/update-helper.path
new file mode 100644 (file)
index 0000000..815a54d
--- /dev/null
@@ -0,0 +1,5 @@
+[Unit]
+Description=Path activator of update-helper
+
+[Path]
+PathExists=/tmp/.update_start
diff --git a/update-helper/update-helper.service b/update-helper/update-helper.service
new file mode 100644 (file)
index 0000000..353f530
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=Update helper service for update-agent
+DefaultDependencies=no
+
+[Service]
+Type=oneshot
+SmackProcessLabel=System::Privileged
+ExecStart=/usr/share/upgrade/update-helper.sh
diff --git a/update-helper/update-helper.sh b/update-helper/update-helper.sh
new file mode 100755 (executable)
index 0000000..a827152
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/bash
+#
+# update-helper.sh
+#
+
+UPDATE_FLAG=/tmp/.update_start
+UPDATE_DIR=/opt/data/update
+UPDATE_RESULT=${UPDATE_DIR}/result
+
+report_result() {
+       DOWNLOAD_PATH=${UPDATE_DIR}/DOWNLOAD.PATH
+
+       if [ -e ${DOWNLOAD_PATH} ]; then
+               DOWNLOAD_DIR=$(cat ${DOWNLOAD_PATH})
+               if [ -d ${DOWNLOAD_DIR} ]; then
+                       RESULT=$(cat ${UPDATE_RESULT})
+                       echo "Update result... [${RESULT}]"
+                       /bin/mv ${UPDATE_RESULT} ${DOWNLOAD_DIR}
+               else
+                       echo "Error: Directory does not exist: ${DOWNLOAD_DIR}"
+               fi
+       else
+               echo "Error: No path to report. Exit"
+       fi
+}
+
+trigger_update() {
+       sleep 1
+
+       UPDATE_PACKAGE=$(cat ${UPDATE_FLAG})
+       PACKAGE_DIR=$(dirname ${UPDATE_PACKAGE})
+
+       rm ${UPDATE_FLAG}
+
+       if [ ! -d "${PACKAGE_DIR}" ]; then
+               echo "Error: Invalid update package directory: ${PACKAGE_DIR}"
+       fi
+
+       if [ ! -e "${UPDATE_PACKAGE}" ]; then
+               echo "Error: The update package does not exist: ${UPDATE_PACKAGE}"
+       fi
+
+       # Decompress update package (delta.tar.gz -> delta.tar)
+       echo "Decompress update package"
+       gzip -d ${UPDATE_PACKAGE}
+       UPDATE_PACKAGE=${UPDATE_PACKAGE%.*}
+
+       echo "Pass the update package to trigger"
+       echo "update package: ${UPDATE_PACKAGE}"
+
+       tar xvfp ${UPDATE_PACKAGE} -C ${PACKAGE_DIR} upgrade-trigger.sh
+       exec ${PACKAGE_DIR}/upgrade-trigger.sh ${UPDATE_PACKAGE}
+}
+
+if [ -e "$UPDATE_FLAG" ]; then
+       echo "The flag was found. Tirgger the update"
+       trigger_updat
+elif [ -e "$UPDATE_RESULT" ]; then
+       echo "The result file was found. Move the result"
+       report_result
+else
+       echo "Nothing to do. Exit."
+fi