From e1e9d71fdf62e098b38261ee36a75f4ce02c5e9e Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Wed, 14 Feb 2018 11:40:56 +0900 Subject: [PATCH] Patch for update-helper 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 --- packaging/tota-ua.spec | 31 +++++++++++++++--- scripts/upgrade-trigger.sh | 21 +++++++------ update-helper/update-helper.path | 5 +++ update-helper/update-helper.service | 8 +++++ update-helper/update-helper.sh | 63 +++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 15 deletions(-) mode change 100755 => 100644 scripts/upgrade-trigger.sh create mode 100644 update-helper/update-helper.path create mode 100644 update-helper/update-helper.service create mode 100755 update-helper/update-helper.sh diff --git a/packaging/tota-ua.spec b/packaging/tota-ua.spec index d3d1b83..5f565e2 100755 --- a/packaging/tota-ua.spec +++ b/packaging/tota-ua.spec @@ -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 diff --git a/scripts/upgrade-trigger.sh b/scripts/upgrade-trigger.sh old mode 100755 new mode 100644 index 72f7944..93b6257 --- a/scripts/upgrade-trigger.sh +++ b/scripts/upgrade-trigger.sh @@ -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 index 0000000..815a54d --- /dev/null +++ b/update-helper/update-helper.path @@ -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 index 0000000..353f530 --- /dev/null +++ b/update-helper/update-helper.service @@ -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 index 0000000..a827152 --- /dev/null +++ b/update-helper/update-helper.sh @@ -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 -- 2.7.4