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
%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"
%{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
%license LICENSE
%manifest tota-ua.manifest
%doc README
-%{fota_data_dir}
+%{fota_dir}
%defattr(-,root,root,-)
%{_bindir}/delta.ua
%{_bindir}/upgrade-trigger.sh
%{_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
#!/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..."
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..."
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
--- /dev/null
+[Unit]
+Description=Path activator of update-helper
+
+[Path]
+PathExists=/tmp/.update_start
--- /dev/null
+[Unit]
+Description=Update helper service for update-agent
+DefaultDependencies=no
+
+[Service]
+Type=oneshot
+SmackProcessLabel=System::Privileged
+ExecStart=/usr/share/upgrade/update-helper.sh
--- /dev/null
+#!/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