Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ License: CC0-1.0
Files: *.ts .tx/*
Copyright: None
License: CC0-1.0

# scripts
Files: dconfig-center/dde-dconfig-daemon/scripts/*
Copyright: None
License: CC0-1.0
3 changes: 3 additions & 0 deletions dconfig-center/dde-dconfig-daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ install(FILES services/dde-dconfig-daemon.service DESTINATION ${CMAKE_INSTALL_PR

## bin
install(TARGETS dde-dconfig-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})

## trigger handler scripts
install(PROGRAMS scripts/dconfig-trigger-handler DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/dde-dconfig-daemon)
160 changes: 160 additions & 0 deletions dconfig-center/dde-dconfig-daemon/scripts/dconfig-trigger-handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/bash
# dconfig-trigger-handler - Handle configuration file changes via D-Bus update calls
# This script is called when Debian triggers detect changes in configuration directories

set -e

# Configuration directories to monitor
CONFIG_DIRS=(
"/usr/share/dsg/configs"
"/etc/dsg/configs"
"/var/lib/linglong/entries/share/dsg/configs"
)

# D-Bus service details
DBUS_SERVICE="org.desktopspec.ConfigManager"
DBUS_PATH="/"
UPDATE_METHOD="update"

# Logging
LOG_TAG="dconfig-trigger-handler"

# Timestamp file for tracking changes
TIMESTAMP_DIR="/var/lib/dde-dconfig-daemon"
TIMESTAMP_FILE="$TIMESTAMP_DIR/last-trigger-time"

log_info() {
logger -t "$LOG_TAG" "$1" 2>/dev/null || true
echo "$1"
}

log_error() {
logger -t "$LOG_TAG" -p daemon.err "$1" 2>/dev/null || true
echo "ERROR: $1" >&2
}

ensure_timestamp_dir() {
if [ ! -d "$TIMESTAMP_DIR" ]; then
log_info "Creating timestamp directory: $TIMESTAMP_DIR"
mkdir -p "$TIMESTAMP_DIR" || {
log_error "Failed to create timestamp directory: $TIMESTAMP_DIR"
return 1
}
fi
}

update_timestamp() {
ensure_timestamp_dir || return 1
touch "$TIMESTAMP_FILE" || {
log_error "Failed to update timestamp file: $TIMESTAMP_FILE"
return 1
}
log_info "Updated timestamp file: $TIMESTAMP_FILE"
}

is_config_file() {
local file="$1"

if [ ! -f "$file" ] || [ ! -r "$file" ]; then
return 1
fi

if [[ "$file" != *.json ]]; then
return 1
fi

# Check if file is in one of the monitored directories
local is_in_monitored_dir=false
for config_dir in "${CONFIG_DIRS[@]}"; do
if [[ "$file" == "$config_dir"/* ]]; then
is_in_monitored_dir=true
break
fi
done

if [ "$is_in_monitored_dir" = false ]; then
return 1
fi

return 0
}

call_dbus_update() {
local config_path="$1"

if dbus-send --system \
--dest="$DBUS_SERVICE" \
--type=method_call \
"$DBUS_PATH" \
"$DBUS_SERVICE.$UPDATE_METHOD" \
string:"$config_path" >/dev/null 2>&1; then
return 0
else
log_error "Failed to update configuration: $config_path"
return 1
fi
}

process_newer_files_in_directory() {
local dir="$1"
local processed_count=0

if [ ! -d "$dir" ]; then
log_info "Directory does not exist: $dir"
return 0
fi

if [ ! -f "$TIMESTAMP_FILE" ]; then
log_info "Timestamp file doesn't exist, creating it"
ensure_timestamp_dir
touch "$TIMESTAMP_FILE"
fi

# Find JSON files newer than the timestamp file
while IFS= read -r -d '' config_file; do
if is_config_file "$config_file"; then
log_info "Found newer config file: $config_file"
if call_dbus_update "$config_file"; then
processed_count=$((processed_count + 1))
fi
fi
done < <(find "$dir" -name "*.json" -type f -cnewer "$TIMESTAMP_FILE" -print0 2>/dev/null)

log_info "Processed $processed_count newer configuration files in $dir"
return 0
}

process_trigger_paths() {
local processed_count=0

for trigger_path in "$@"; do
log_info "Processing trigger path: $trigger_path"

if [ -f "$trigger_path" ]; then
if is_config_file "$trigger_path"; then
if call_dbus_update "$trigger_path"; then
processed_count=$((processed_count + 1))
fi
else
log_info "Skipping non-config file: $trigger_path"
fi
elif [ -d "$trigger_path" ]; then
process_newer_files_in_directory "$trigger_path"
else
log_error "Trigger path does not exist: $trigger_path"
fi
done
}

main() {
if [ $# -gt 0 ]; then
process_trigger_paths "$@"

# Update timestamp after processing trigger paths
update_timestamp
fi

log_info "dconfig trigger handler completed"
}

main "$@"
1 change: 1 addition & 0 deletions debian/dde-dconfig-daemon.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ usr/share/dbus-1/interfaces/*
usr/share/dbus-1/system-services/*
usr/share/dde-dconfig/translations/*
usr/lib/systemd/system/*
usr/lib/dde-dconfig-daemon/*
41 changes: 41 additions & 0 deletions debian/dde-dconfig-daemon.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
set -e

# Automatically added by dh_installsystemd/13.16
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action 'dde-dconfig-daemon.service' >/dev/null || true
fi

TIMESTAMP_DIR="/var/lib/dde-dconfig-daemon"
TIMESTAMP_FILE="$TIMESTAMP_DIR/last-trigger-time"

if [ ! -d "$TIMESTAMP_DIR" ]; then
mkdir -p "$TIMESTAMP_DIR"
fi

# Always update timestamp file when package is configured
touch "$TIMESTAMP_FILE"
fi
# End automatically added section

# Handle dconfig triggers
if [ "$1" = "triggered" ]; then
# Skip the first argument (triggered)
shift

# Execute trigger handler with all remaining arguments (trigger paths)
if [ -x /usr/lib/dde-dconfig-daemon/dconfig-trigger-handler ]; then
/usr/lib/dde-dconfig-daemon/dconfig-trigger-handler "$@"
else
echo "Warning: dconfig-trigger-handler not found or not executable"
fi
fi

exit 0
12 changes: 12 additions & 0 deletions debian/dde-dconfig-daemon.triggers
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Debian triggers for dde-dconfig-daemon
# Monitor configuration file directories for changes

# Monitor meta configuration files - use interest to get specific file paths
interest /usr/share/dsg/configs
interest /etc/dsg/configs

# Monitor Linglong configuration files - use interest to get specific file paths
interest /var/lib/linglong/entries/share/dsg/configs

# Trigger name for processing configuration updates
interest dconfig-trigger
Loading