Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ tasks:
set -e
echo "Runner version set as: {{ .EXAMPLE_VERSION }}"
TMP_PATH="$(mktemp -d)"
DEST_PATH="debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli/"
DEST_PATH="debian/arduino-app-cli/var/lib/arduino-app-cli/"
echo "Cloning arduino/app-bricks-examples into temporary directory ${TMP_PATH}..."
git clone --depth 1 --branch "{{ .EXAMPLE_VERSION }}" https://github.com/arduino/app-bricks-examples "${TMP_PATH}"
rm -rf "${DEST_PATH}/examples"
Expand Down Expand Up @@ -213,7 +213,7 @@ tasks:
TMPDIR: '{{trimSuffix "/" (env "TMPDIR")| default "/tmp"}}/generate-assets'
SEMVER_TAG: "{{.RUNNER_VERSION}}"
OUTPUT_DIR: "{{.TMPDIR}}/{{.SEMVER_TAG}}"
ASSETS_DIR: debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli/assets
ASSETS_DIR: debian/arduino-app-cli/var/lib/arduino-app-cli/assets
TESTDATA_DIR: internal/e2e/daemon/testdata/assets
preconditions:
- sh: '[ ! -d "{{.ASSETS_DIR}}/{{.SEMVER_TAG}}" ] || [ ! -d "{{.TESTDATA_DIR}}/{{.SEMVER_TAG}}" ]'
Expand Down
5 changes: 5 additions & 0 deletions debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ RUN apt-get update && apt-get install -y sed
COPY ./debian/${DEB_NAME} /${DEB_NAME}/
COPY --from=go /app/${BINARY_NAME} /${DEB_NAME}/usr/bin/${BINARY_NAME}

RUN (cd /${DEB_NAME}/DEBIAN && \
sed -e '/# SHARED_FUNCTIONS/r helper_func.sh' ./prerm > prerm.tmp && mv prerm.tmp ./prerm && \
sed -e '/# SHARED_FUNCTIONS/r helper_func.sh' ./preinst > preinst.tmp && mv preinst.tmp ./preinst &&\
chmod a+x ./prerm ./preinst)

# Go application are tagged with `v` prefix, this remove the first v if present
RUN export VERSION=$(echo "${VERSION}" | sed -e "s/^v\(.*\)/\1/") && \
sed -i "s/\$ARCH/${ARCH}/" /${DEB_NAME}/DEBIAN/control && \
Expand Down
30 changes: 30 additions & 0 deletions debian/arduino-app-cli/DEBIAN/helper_func.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Function: cleanup_arduino_examples
# Description: Stops running Arduino apps within example directories and
# removes associated cache files, but only if the root
# examples directory exists.
#
# Arguments:
# $1 - The path to the root examples directory (EXAMPLES_DIR).
#
cleanup_arduino_examples() {
local EXAMPLES_DIR="$1"

if [ -d "${EXAMPLES_DIR}" ]; then
local EXAMPLES=$(find "${EXAMPLES_DIR}" -maxdepth 1 -mindepth 1 -type d 2>/dev/null)
echo "Stopping apps and clearing cache in: ${EXAMPLES_DIR}"
for dir_path in ${EXAMPLES}; do
echo " -> Stopping app/removing cache in: ${dir_path}"

# 1. Stop the application (suppress output and errors)
sudo -u arduino /usr/bin/arduino-app-cli app stop "${dir_path}" > /dev/null 2>&1 || true

# 2. Remove the cache directory
local CACHE_PATH="${dir_path}/.cache"

# Check if the cache directory exists before attempting to remove it
if [ -d "${CACHE_PATH}" ]; then
rm -r "${CACHE_PATH}"
fi
done
fi
}
2 changes: 1 addition & 1 deletion debian/arduino-app-cli/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

chown -R arduino:arduino /home/arduino/.local/share/arduino-app-cli
chown -R arduino:arduino /var/lib/arduino-app-cli

systemctl enable arduino-app-cli
systemctl enable arduino-burn-bootloader
Expand Down
14 changes: 14 additions & 0 deletions debian/arduino-app-cli/DEBIAN/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ if ! getent group "$SYSUPGRADE_GROUP" >/dev/null 2>&1; then
groupadd --system "$SYSUPGRADE_GROUP"
fi
usermod -aG "$SYSUPGRADE_GROUP" "$APP_USER"


# SHARED_FUNCTIONS

if [ "$1" = "upgrade" ]; then
# if $2 is not empty, this is an upgrade
if [ -n "$2" ]; then
# check if this is an upgrade from an old version
if dpkg --compare-versions "$2" lt "0.9.0"; then
echo "Running pre-0.9.0 legacy cleanup/migration..."
cleanup_arduino_examples /home/arduino/.local/share/arduino-app-cli/examples
fi
fi
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fi
cp -r /home/arduino/.local/share/arduino-app-cli /examples /var/lib/arduino-app-cli

Copy link
Contributor Author

@martacarbone martacarbone Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the copy of examples here; add the copy of properties.msgpack* and bootloader_burned.flag here;
add rm -rf of examples, properties.msgpack, properties.msgpack.lock and bootloader_burned.flag in postinst

8 changes: 8 additions & 0 deletions debian/arduino-app-cli/DEBIAN/prerm
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

set -e
systemctl disable arduino-app-cli
systemctl disable arduino-burn-bootloader
systemctl disable arduino-avahi-serial.service

# SHARED_FUNCTIONS

echo "Running pre-0.8.0 legacy cleanup/migration..."
cleanup_arduino_examples /home/arduino/.local/share/arduino-app-cli/examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Running pre-0.8.0 legacy cleanup/migration..."
cleanup_arduino_examples /home/arduino/.local/share/arduino-app-cli/examples

Copy link
Contributor Author

@martacarbone martacarbone Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the cleanup of old dir examples; leave the app shutdown and cache cleanup of /var/lib/arduino-app-cli

echo "Cache cleanup..."
cleanup_arduino_examples /var/lib/arduino-app-cli/examples
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[Unit]
Description=Burn arduino zephyr bootloader on first boot
After=fs-local.target
ConditionPathExists=!/home/arduino/.local/share/arduino-app-cli/bootloader_burned.flag
ConditionPathExists=!/var/lib/arduino-app-cli/bootloader_burned.flag

[Service]
Type=oneshot
RemainAfterExit=true
User=arduino
Group=arduino
ExecStart=/usr/bin/arduino-cli burn-bootloader -b arduino:zephyr:unoq -P jlink
ExecStartPost=/bin/mkdir -p /home/arduino/.local/share/arduino-app-cli
ExecStartPost=/bin/touch /home/arduino/.local/share/arduino-app-cli/bootloader_burned.flag
ExecStartPost=/bin/mkdir -p /var/lib/arduino-app-cli
ExecStartPost=/bin/touch /var/lib/arduino-app-cli/bootloader_burned.flag
StandardOutput=journal
StandardError=journal

Expand Down
2 changes: 1 addition & 1 deletion docs/contributor-guide/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Build the project (run once):

Start the arduino-app-cli in daemon mode:

- `ARDUINO_APP_CLI__DATA_DIR=debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli go tool task start`
- `ARDUINO_APP_CLI__DATA_DIR=debian/arduino-app-cli/var/lib/arduino-app-cli go tool task start`

NOTE: only a subset of HTTP APIs are working by running the daemon mode on a development PC. To run Arduino App CLI on the board see the **Running Arduino App CLI on the board** section below.

Expand Down
4 changes: 2 additions & 2 deletions docs/user-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The following environment variables are used to configure Arduino App CLI:
| Environment Variable | Default Value | Description |
| -------------------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------- |
| `ARDUINO_APP_CLI__APPS_DIR` | `/home/arduino/ArduinoApps` | Path to the directory where Arduino Apps created by the user are stored |
| `ARDUINO_APP_CLI__DATA_DIR` | `/home/arduino/.local/share/arduino-app-cli` | Path to the directory where internal data is stored (examples, assets, properties) |
| `ARDUINO_APP_CLI__DATA_DIR` | `/var/lib/arduino-app-cli` | Path to the directory where internal data is stored (examples, assets, properties) |
| `ARDUINO_APP_BRICKS__CUSTOM_MODEL_DIR` | `$HOME/.arduino-bricks/ei-models` | Path to the directory where custom AI models are stored |
| `ARDUINO_APP_CLI__ALLOW_ROOT` | `false` | Allow running `arduino-app-cli` as root (**Not recommended to set to true**) |
| `LIBRARIES_API_URL` | `https://api2.arduino.cc/libraries/v1/libraries` | URL of the external service used to search Arduino libraries |
Expand Down Expand Up @@ -37,7 +37,7 @@ Examples of user-defined Arduino Apps stored under the `ARDUINO_APP_CLI__APPS_DI
Examples of the `assets` and the builtin `examples` stored under the `ARDUINO_APP_CLI__DATA_DIR` folder.

```
/home/arduino/.local/share/arduino-app-cli/
/var/lib/arduino-app-cli/
├── assets
│   └── 0.5.0 # Version-specific assets
│   ├── bricks-list.yaml # Available bricks
Expand Down
6 changes: 1 addition & 5 deletions internal/orchestrator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ func NewFromEnv() (Configuration, error) {

dataDir := paths.New(os.Getenv("ARDUINO_APP_CLI__DATA_DIR"))
if dataDir == nil {
xdgHome, err := os.UserHomeDir()
if err != nil {
return Configuration{}, err
}
dataDir = paths.New(xdgHome).Join(".local", "share", "arduino-app-cli")
dataDir = paths.New("/var/lib/arduino-app-cli")
}

routerSocket := paths.New(os.Getenv("ARDUINO_ROUTER_SOCKET"))
Expand Down
Loading