@@ -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
173175tar -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
176248while 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"
0 commit comments