+# Restore original XenServer scripts if the OVS equivalent no longer exists.
+# This works both in the upgrade and erase cases.
+# This lists every file that every version of OVS has ever replaced. Never
+# remove old files that OVS no longer replaces, or upgrades from old versions
+# will fail to restore the XS originals, leaving the system in a broken state.
+# Also be sure to add removed script paths to the %post scriptlet above to
+# prevent the same problem when upgrading from old versions of OVS that lack
+# this restore-on-upgrade logic.
+for f in \
+ /etc/xensource/scripts/vif \
+ /usr/sbin/brctl \
+ /usr/sbin/xen-bugtool \
+ /opt/xensource/libexec/interface-reconfigure \
+ /opt/xensource/libexec/InterfaceReconfigure.py \
+ /opt/xensource/libexec/InterfaceReconfigureBridge.py \
+ /opt/xensource/libexec/InterfaceReconfigureVswitch.py
+do
+ # Only revert dangling symlinks.
+ if [ -h "$f" ] && [ ! -e "$f" ]; then
+ s=$(basename "$f")
+ if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
+ printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
+ printf "Could not restore original XenServer script.\n" >&2
+ else
+ (rm -f "$f" \
+ && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
+ || printf "Could not restore original XenServer $s script.\n" >&2
+ fi
+ fi
+done
+
+if [ "$1" = "0" ]; then # $1 = 0 for uninstall