-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f533d9e
Showing
13 changed files
with
1,447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
project( rauc-disk-updater ) | ||
|
||
option(BUILD_DOC "Build documentation" OFF) | ||
|
||
find_package(PkgConfig REQUIRED) | ||
|
||
pkg_check_modules(LIBGUDEV REQUIRED gudev-1.0>=233) | ||
include_directories(${LIBGUDEV_INCLUDE_DIRS}) | ||
|
||
pkg_check_modules(GIO REQUIRED gio-2.0>=2.26.0) | ||
include_directories(${GIO_INCLUDE_DIRS}) | ||
|
||
pkg_check_modules(GIOUNIX REQUIRED gio-unix-2.0>=2.26.0) | ||
include_directories(${GIOUNIX_INCLUDE_DIRS}) | ||
|
||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
if (BUILD_DOC) | ||
# check if Doxygen is installed | ||
find_package(Doxygen) | ||
if (DOXYGEN_FOUND) | ||
# set input and output files | ||
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) | ||
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) | ||
|
||
# request to configure the file | ||
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) | ||
message("Doxygen build started") | ||
|
||
# note the option ALL which allows to build the docs together with the application | ||
add_custom_target( doc_doxygen ALL | ||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
COMMENT "Generating documentation with Doxygen" | ||
VERBATIM ) | ||
else (DOXYGEN_FOUND) | ||
message("Doxygen need to be installed to generate the doxygen documentation") | ||
endif (DOXYGEN_FOUND) | ||
endif (BUILD_DOC) | ||
|
||
set(DISK_SRCS | ||
src/rauc-disk-updater.c | ||
src/udev.c | ||
) | ||
|
||
set(DBUS_RAUC_PREFIX de-pengutronix-rauc-gen) | ||
set(DBUS_RAUC_COMMAND | ||
gdbus-codegen | ||
--generate-c-code ${DBUS_RAUC_PREFIX} | ||
--interface-prefix de.pengutronix.rauc. | ||
--c-namespace Rauc | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/de.pengutronix.rauc.xml | ||
) | ||
|
||
|
||
set(DBUS_DISK_PREFIX de-helbling-disk-updater-gen) | ||
set(DBUS_DISK_COMMAND | ||
gdbus-codegen | ||
--generate-c-code ${DBUS_DISK_PREFIX} | ||
--interface-prefix de.helbling. | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/de.helbling.DiskUpdater.xml | ||
) | ||
|
||
|
||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/${DBUS_RAUC_PREFIX}.c | ||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/${DBUS_RAUC_PREFIX}.h | ||
COMMAND ${DBUS_RAUC_COMMAND} | ||
COMMAND mv ${DBUS_RAUC_PREFIX}.c ${CMAKE_CURRENT_SOURCE_DIR}/src/ | ||
COMMAND mv ${DBUS_RAUC_PREFIX}.h ${CMAKE_CURRENT_SOURCE_DIR}/include/ | ||
|
||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/${DBUS_DISK_PREFIX}.c | ||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/${DBUS_DISK_PREFIX}.h | ||
COMMAND ${DBUS_DISK_COMMAND} | ||
COMMAND mv ${DBUS_DISK_PREFIX}.c ${CMAKE_CURRENT_SOURCE_DIR}/src/ | ||
COMMAND mv ${DBUS_DISK_PREFIX}.h ${CMAKE_CURRENT_SOURCE_DIR}/include/ | ||
) | ||
|
||
|
||
set(DISK_SRCS | ||
${DISK_SRCS} | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/${DBUS_RAUC_PREFIX}.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/${DBUS_DISK_PREFIX}.c | ||
) | ||
|
||
|
||
add_executable( rauc-disk-updater ${DISK_SRCS} ) | ||
set_target_properties(rauc-disk-updater PROPERTIES COMPILE_FLAGS "") | ||
|
||
target_link_libraries(rauc-disk-updater | ||
LINK_PUBLIC | ||
${GIO_LIBRARIES} | ||
${LIBGUDEV_LIBRARIES} | ||
) | ||
|
||
install (TARGETS rauc-disk-updater DESTINATION /usr/bin/) | ||
|
||
if (SYSTEMD_SYSTEM_UNITDIR) | ||
install (FILES ${CMAKE_SOURCE_DIR}/data/rauc-disk-updater.service | ||
DESTINATION ${SYSTEMD_SYSTEM_UNITDIR}/) | ||
endif (SYSTEMD_SYSTEM_UNITDIR) | ||
|
||
if (DBUS_POLICY_DIR) | ||
install (FILES ${CMAKE_SOURCE_DIR}/data/de.helbling.DiskUpdater.conf | ||
DESTINATION ${DBUS_POLICY_DIR}/) | ||
endif (DBUS_POLICY_DIR) | ||
|
||
if (DBUS_SYSTEM_UNITDIR) | ||
install (FILES ${CMAKE_SOURCE_DIR}/data/de.helbling.DiskUpdater.service | ||
DESTINATION ${DBUS_SYSTEM_UNITDIR}/) | ||
endif (DBUS_SYSTEM_UNITDIR) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PROJECT_NAME = "RAUC Disk updater" | ||
PROJECT_BRIEF = "The RAUC Disk updater is a daemon for automatically installing Rauc Bundles from USB drives and SD-cards" | ||
OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/docs/ | ||
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ @CMAKE_CURRENT_SOURCE_DIR@/include/ | ||
OPTIMIZE_OUTPUT_FOR_C = YES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) Helbling Technik GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, copy, | ||
modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Rauc Disk Updater | ||
================ | ||
|
||
`rauc-disk-updater` interacts with udev and Rauc to automatically install | ||
bundles from plugged in USB devices and SD-cards. | ||
|
||
Features | ||
-------- | ||
|
||
* Script Hook Support | ||
* Controllable via D-Bus interface | ||
* Automatic Mounting | ||
* Validation of found bundles | ||
* Automatic bundle installation without user interaction | ||
* USB devices (scsi) and SD-card Support (mmc) | ||
* Support for multiple devices | ||
|
||
How Does It Work | ||
---------------- | ||
|
||
1. Create a Bundle with matching `compatible` and `version` string. | ||
2. Copy bundle on USB stick with a filesystem supported by the target machine. | ||
3. Plug in USB stick in the target machine. | ||
4. `rauc-disk-updater` search for bundles on the stick. Each bundle is validated | ||
by rauc. | ||
5. Either a hook script determines the installation or the D-Bus method | ||
`install` is called in order to start the installation of a found bundle. | ||
|
||
|
||
Compiling & Installation | ||
------------------------ | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
make install | ||
systemctl enable --now rauc-disk-updater.service | ||
``` | ||
|
||
|
||
Usage | ||
----- | ||
|
||
```bash | ||
/usr/bin/rauc-disk-updater --help | ||
Usage: | ||
rauc-usb-updater [OPTION?] | ||
|
||
Help Options: | ||
-h, --help Show help options | ||
|
||
Application Options: | ||
-s, --script-file Script file | ||
-v, --version Version information | ||
``` | ||
|
||
|
||
Script API | ||
---------- | ||
|
||
The script is called after all mounted partitons of an attached device are | ||
searched through and minimum one bundle is found. The number of bundles is | ||
passed as variable `BUNDLES`. For each bundle with index `X`, the variables | ||
`BUNDLE_VERSION_X` and `BUNDLE_PATH_X` are passed. In order to trigger the | ||
installation of a bundle, the exit code of the script is to the index `X`. If | ||
the exist code is set to `0`, the installation will be aborted. | ||
|
||
Following script automatically installs the bundle with highest version. | ||
|
||
```bash | ||
#!/bin/bash | ||
VERSION="" | ||
INDEX=0 | ||
|
||
for i in $(seq 1 $BUNDLES); do | ||
BUNDLE_VERSION="BUNDLE_VERSION_${i}" | ||
if [ "${!BUNDLE_VERSION}" '>' "$VERSION" ]; then | ||
VERSION="${!BUNDLE_VERSION}" | ||
INDEX="$i" | ||
fi | ||
done | ||
|
||
exit $INDEX | ||
esac | ||
``` | ||
|
||
|
||
Contributing | ||
------------ | ||
|
||
Fork the repository and send us a pull request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE busconfig PUBLIC | ||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" | ||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
<busconfig> | ||
<!-- This config allows anyone to control rauc --> | ||
<!-- It is usually installed to /usr/share/dbus-1/system.d --> | ||
|
||
<policy context="default"> | ||
<allow send_destination="de.helbling.DiskUpdater"/> | ||
</policy> | ||
|
||
<policy user="root"> | ||
<allow own="de.helbling.DiskUpdater"/> | ||
</policy> | ||
</busconfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[D-BUS Service] | ||
Name=de.helbling.DiskUpdater | ||
Exec=/bin/false | ||
User=root | ||
SystemdService=rauc-disk-updater.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Disk updater for Rauc | ||
After=rauc.service local-fs.target | ||
Requires=rauc.service | ||
|
||
[Service] | ||
Type=dbus | ||
BusName=de.helbling.DiskUpdater | ||
ExecStart=/usr/bin/rauc-disk-updater --script /etc/rauc-disk-updater/hook.sh | ||
Restart=on-failure | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
VERSION="" | ||
INDEX=0 | ||
|
||
for i in $(seq 1 $BUNDLES); do | ||
eval BUNDLE_VERSION=\$BUNDLE_VERSION_${i} | ||
if [ "$BUNDLE_VERSION" \> "$VERSION" ]; then | ||
VERSION="${BUNDLE_VERSION}" | ||
INDEX="$i" | ||
fi | ||
done | ||
exit $INDEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef __RAUC_USB_UPDATER__UDEV_H__ | ||
#define __RAUC_USB_UPDATER__UDEV_H__ | ||
|
||
|
||
#include <glib.h> | ||
#include <glib-object.h> | ||
#include <gudev/gudev.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
|
||
#define UDEV_TYPE_MONITOR udev_monitor_get_type () | ||
G_DECLARE_FINAL_TYPE (UdevMonitor, udev_monitor, UDEV, MONITOR, GObject) | ||
|
||
|
||
UdevMonitor *udev_monitor_new (void); | ||
void udev_monitor_quit(UdevMonitor *provider); | ||
|
||
G_END_DECLS | ||
|
||
#endif // __RAUC_USB_UPDATER__UDEV_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> | ||
<interface name="de.helbling.DiskUpdater.Bundle"> | ||
<method name="Install" /> | ||
<property name="version" type="s" access="read" /> | ||
<property name="path" type="s" access="read" /> | ||
</interface> | ||
|
||
<interface name="de.helbling.DiskUpdater"> | ||
<!--Status=idle|scanning> --> | ||
<property name="Status" type="s" access="read" /> | ||
<property name="DeviceCount" type="i" access="read" /> | ||
</interface> | ||
</node> |
Oops, something went wrong.