Skip to content

Commit cb1a29a

Browse files
committed
Refactoring
1 parent 39923a1 commit cb1a29a

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

debian/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ RUN apt-get update && apt-get install -y sed
4343
COPY ./debian/${DEB_NAME} /${DEB_NAME}/
4444
COPY --from=go /app/${BINARY_NAME} /${DEB_NAME}/usr/bin/${BINARY_NAME}
4545

46+
RUN (cd /${DEB_NAME}/DEBIAN && \
47+
sed -e '/# SHARED_FUNCTIONS/r helper_func.sh' ./prerm > prerm.tmp && mv prerm.tmp ./prerm && \
48+
sed -e '/# SHARED_FUNCTIONS/r helper_func.sh' ./preinst > preinst.tmp && mv preinst.tmp ./preinst &&\
49+
chmod a+x ./prerm ./preinst)
50+
4651
# Go application are tagged with `v` prefix, this remove the first v if present
4752
RUN export VERSION=$(echo "${VERSION}" | sed -e "s/^v\(.*\)/\1/") && \
4853
sed -i "s/\$ARCH/${ARCH}/" /${DEB_NAME}/DEBIAN/control && \
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Function: cleanup_arduino_examples
2+
# Description: Stops running Arduino apps within example directories and
3+
# removes associated cache files, but only if the root
4+
# examples directory exists.
5+
#
6+
# Arguments:
7+
# $1 - The path to the root examples directory (EXAMPLES_DIR).
8+
#
9+
cleanup_arduino_examples() {
10+
local EXAMPLES_DIR="$1"
11+
12+
if [ -d "${EXAMPLES_DIR}" ]; then
13+
local EXAMPLES=$(find "${EXAMPLES_DIR}" -maxdepth 1 -mindepth 1 -type d 2>/dev/null)
14+
echo "Stopping apps and clearing cache in: ${EXAMPLES_DIR}"
15+
for dir_path in ${EXAMPLES}; do
16+
echo " -> Stopping app/removing cache in: ${dir_path}"
17+
18+
# 1. Stop the application (suppress output and errors)
19+
sudo -u arduino /usr/bin/arduino-app-cli app stop "${dir_path}" > /dev/null 2>&1 || true
20+
21+
# 2. Remove the cache directory
22+
local CACHE_PATH="${dir_path}/.cache"
23+
24+
# Check if the cache directory exists before attempting to remove it
25+
if [ -d "${CACHE_PATH}" ]; then
26+
rm -r "${CACHE_PATH}"
27+
fi
28+
done
29+
fi
30+
}

debian/arduino-app-cli/DEBIAN/preinst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ if ! getent group "$SYSUPGRADE_GROUP" >/dev/null 2>&1; then
2424
fi
2525
usermod -aG "$SYSUPGRADE_GROUP" "$APP_USER"
2626

27-
delete_obsolete_files() {
28-
OBSOLETE_DIR="/home/arduino/.local/share/arduino-app-cli/examples"
29-
for i in "${OBSOLETE_DIR}"/*; do
30-
rm -rf "${i}"/.cache;
31-
done
32-
}
27+
28+
# SHARED_FUNCTIONS
3329

3430
if [ "$1" = "upgrade" ]; then
3531
# if $2 is not empty, this is an upgrade
3632
if [ -n "$2" ]; then
3733
# check if this is an upgrade from an old version
3834
if dpkg --compare-versions "$2" lt "0.9.0"; then
39-
echo "Running pre-0.8.0 legacy cleanup/migration..."
40-
delete_obsolete_files
35+
echo "Running pre-0.9.0 legacy cleanup/migration..."
36+
cleanup_arduino_examples /home/arduino/.local/share/arduino-app-cli/examples
4137
fi
4238
fi
4339
fi

debian/arduino-app-cli/DEBIAN/prerm

100755100644
Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,9 @@ systemctl disable arduino-app-cli
55
systemctl disable arduino-burn-bootloader
66
systemctl disable arduino-avahi-serial.service
77

8-
# Function: cleanup_arduino_examples
9-
# Description: Stops running Arduino apps within example directories and
10-
# removes associated cache files, but only if the root
11-
# examples directory exists.
12-
#
13-
# Arguments:
14-
# $1 - The path to the root examples directory (EXAMPLES_DIR).
15-
#
16-
cleanup_arduino_examples() {
17-
local EXAMPLES_DIR="$1"
18-
19-
if [ -d "${EXAMPLES_DIR}" ]; then
20-
local EXAMPLES=$(find "${EXAMPLES_DIR}" -maxdepth 1 -mindepth 1 -type d 2>/dev/null)
21-
echo "Stopping apps and clearing cache in: ${EXAMPLES_DIR}"
22-
for dir_path in ${EXAMPLES}; do
23-
24-
# 1. Stop the application (suppress output and errors)
25-
echo " -> Stopping app in: ${dir_path}"
26-
sudo -u arduino /usr/bin/arduino-app-cli app stop "${dir_path}" > /dev/null 2>&1 || true
27-
28-
# 2. Remove the cache directory
29-
local CACHE_PATH="${dir_path}/.cache"
30-
31-
# Check if the cache directory exists before attempting to remove it
32-
if [ -d "${CACHE_PATH}" ]; then
33-
echo " -> Removing cache: ${CACHE_PATH}"
34-
rm -r "${CACHE_PATH}"
35-
fi
36-
done
37-
fi
38-
}
8+
# SHARED_FUNCTIONS
399

40-
# Remove .cache located in packages prev to 0.9.0
10+
echo "Running pre-0.8.0 legacy cleanup/migration..."
4111
cleanup_arduino_examples /home/arduino/.local/share/arduino-app-cli/examples
42-
# Remove .cache for the current package
12+
echo "Cache cleanup..."
4313
cleanup_arduino_examples /var/lib/arduino-app-cli/examples

0 commit comments

Comments
 (0)