Skip to content

Commit fcea4ec

Browse files
authored
fix: Enhance PR plugin script to handle file conflicts
2 parents 11f0619 + b885eee commit fcea4ec

2 files changed

Lines changed: 90 additions & 10 deletions

File tree

.github/scripts/generate-pr-plugin.sh

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ if [ -f "$MANIFEST" ]; then
8686
while IFS='|' read -r system_file backup_file; do
8787
if [ "$backup_file" == "NEW" ]; then
8888
# This was a new file from previous version, remove it
89-
if [ -f "$system_file" ]; then
89+
if [ -e "$system_file" ] || [ -L "$system_file" ]; then
9090
echo "Removing PR file: $system_file"
9191
rm -f "$system_file"
9292
fi
@@ -95,6 +95,8 @@ if [ -f "$MANIFEST" ]; then
9595
if [ -f "$backup_file" ]; then
9696
echo "Restoring original: $system_file"
9797
cp -fp "$backup_file" "$system_file"
98+
else
99+
echo "⚠️ Missing backup for: $system_file"
98100
fi
99101
fi
100102
done < "$MANIFEST"
@@ -172,6 +174,76 @@ echo ""
172174
# Get file list
173175
tar -tzf "$TARBALL" > /tmp/plugin_files.txt
174176
177+
# Abort if any files are already managed by another PR plugin
178+
OTHER_MANIFESTS="/tmp/pr_plugin_existing_files.txt"
179+
> "$OTHER_MANIFESTS"
180+
for plugin_dir in /boot/config/plugins/webgui-pr-*; do
181+
if [ ! -d "$plugin_dir" ]; then
182+
continue
183+
fi
184+
if [ "$plugin_dir" == "/boot/config/plugins/webgui-pr-PR_PLACEHOLDER" ]; then
185+
continue
186+
fi
187+
manifest="$plugin_dir/installed_files.txt"
188+
if [ -f "$manifest" ]; then
189+
plugin_name=$(basename "$plugin_dir")
190+
while IFS='|' read -r other_file _; do
191+
if [ -n "$other_file" ]; then
192+
echo "${other_file}|${plugin_name}" >> "$OTHER_MANIFESTS"
193+
fi
194+
done < "$manifest"
195+
fi
196+
done
197+
198+
if [ -s "$OTHER_MANIFESTS" ]; then
199+
declare -A existing_files
200+
while IFS='|' read -r existing_file existing_plugin; do
201+
if [ -z "$existing_file" ] || [ -z "$existing_plugin" ]; then
202+
continue
203+
fi
204+
if [ -n "${existing_files[$existing_file]:-}" ]; then
205+
if [[ ",${existing_files[$existing_file]}," != *",${existing_plugin},"* ]]; then
206+
existing_files[$existing_file]="${existing_files[$existing_file]},${existing_plugin}"
207+
fi
208+
else
209+
existing_files[$existing_file]="$existing_plugin"
210+
fi
211+
done < "$OTHER_MANIFESTS"
212+
213+
conflict_found=0
214+
declare -A conflict_plugins
215+
while IFS= read -r file; do
216+
# Skip directories
217+
if [[ "$file" == */ ]]; then
218+
continue
219+
fi
220+
221+
system_file="/${file}"
222+
if [ -n "${existing_files[$system_file]:-}" ]; then
223+
conflict_found=1
224+
echo "Conflict: $system_file is already managed by ${existing_files[$system_file]}"
225+
IFS=',' read -r -a plugin_list <<< "${existing_files[$system_file]}"
226+
for plugin in "${plugin_list[@]}"; do
227+
conflict_plugins[$plugin]=1
228+
done
229+
fi
230+
done < /tmp/plugin_files.txt
231+
232+
if [ "$conflict_found" -eq 1 ]; then
233+
echo ""
234+
echo "❌ Install aborted."
235+
echo "One or more files are already managed by another PR plugin."
236+
echo "Please uninstall the conflicting plugin(s) and try again:"
237+
for plugin in "${!conflict_plugins[@]}"; do
238+
echo " plugin remove ${plugin}.plg"
239+
done
240+
rm -f "$OTHER_MANIFESTS" /tmp/plugin_files.txt
241+
exit 1
242+
fi
243+
fi
244+
245+
rm -f "$OTHER_MANIFESTS"
246+
175247
# Backup original files BEFORE extraction
176248
while IFS= read -r file; do
177249
# Skip directories
@@ -327,15 +399,17 @@ if [ -f "$MANIFEST" ]; then
327399
while IFS='|' read -r system_file backup_file; do
328400
if [ "$backup_file" == "NEW" ]; then
329401
# This was a new file, remove it
330-
if [ -f "$system_file" ]; then
402+
if [ -e "$system_file" ] || [ -L "$system_file" ]; then
331403
echo "Removing new file: $system_file"
332404
rm -f "$system_file"
333405
fi
334406
else
335407
# Restore from backup
336408
if [ -f "$backup_file" ]; then
337409
echo "Restoring: $system_file"
338-
mv -f "$backup_file" "$system_file"
410+
cp -fp "$backup_file" "$system_file"
411+
else
412+
echo "⚠️ Missing backup for: $system_file"
339413
fi
340414
fi
341415
done < "$MANIFEST"

.github/workflows/pr-plugin-build.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
pull_request:
55
paths:
66
- 'emhttp/**'
7+
- 'etc/**'
8+
- 'sbin/**'
9+
- 'share/**'
710
- '.github/workflows/pr-plugin-build.yml'
811
- '.github/scripts/**'
912

@@ -87,6 +90,9 @@ jobs:
8790
if [ -f "$file" ]; then
8891
# Create directory structure in build with target mappings
8992
case "$file" in
93+
etc/rc.d/*)
94+
target_dir="build/usr/local/etc/rc.d"
95+
;;
9096
etc/*)
9197
target_dir="build/${file%/*}"
9298
;;
@@ -112,18 +118,18 @@ jobs:
112118
fi
113119
done < changed_files.txt
114120
121+
# Generate file list for plugin/tar (relative paths)
122+
find build -type f | sed 's|^build/||' > file_list.txt
123+
echo "File list for plugin:"
124+
cat file_list.txt
125+
115126
# Create tarball - consistent filename for updates
116127
cd build
117128
echo "Creating tarball with contents:"
118-
find usr/ -type f
119-
tar -czf ../${{ steps.version.outputs.local_txz }} usr/
129+
cat ../file_list.txt
130+
tar -czf ../${{ steps.version.outputs.local_txz }} -T ../file_list.txt
120131
cd ..
121132
122-
# Generate file list for plugin
123-
find build/etc build/usr/local/emhttp build/usr/local/sbin build/usr/local/share -type f | sed 's|^build||' > file_list.txt
124-
echo "File list for plugin:"
125-
cat file_list.txt
126-
127133
# Verify tarball contents
128134
echo "Tarball contents:"
129135
tar -tzf ${{ steps.version.outputs.local_txz }}

0 commit comments

Comments
 (0)