microstack/snap-wrappers/ovs/ovs-alternatives

71 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# this initializes the ovs commands alternatives with the default non-dpdk binaries
set -e
function _remove(){
#remove both openvswitch and openvswitch-dpdk alternatives of the current release.
# it is called at post-refresh hook time and at remove hook time also.
for version in openvswitch openvswitch-dpdk; do
for dir in \
bin \
etc/init.d \
sbin \
share/openvswitch/scripts \
usr/bin \
var/snap/${SNAP_NAME}/etc/bash_completion.d \
; do
cd ${SNAP}/${version}/${dir}/
for file in *; do
update-alternatives --quiet --remove ${file} ${SNAP}/${version}/${dir}/${file}
done
cd - &>/dev/null
done
done
}
function _install(){
# only set version alternatives when it is configured via snap config options
version="openvswitch"
if [[ $(snapctl get config.network.ovs-dpdk) == *"rue" ]]; then
version="openvswitch-dpdk"
fi
for dir in \
bin \
etc/init.d \
sbin \
share/openvswitch/scripts \
usr/bin \
var/snap/${SNAP_NAME}/etc/bash_completion.d \
; do
cd ${SNAP}/${version}/${dir}/
mkdir -p ${SNAP_COMMON}/${dir}/
for file in *; do
update-alternatives --quiet --install $SNAP_COMMON/$dir/${file} ${file} ${SNAP}/${version}/${dir}/${file} 1
update-alternatives --quiet --set ${file} ${SNAP}/${version}/${dir}/${file}
done
cd - &>/dev/null
done
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-i|--install)
shift # past argument
_install
;;
-r|--remove)
shift # past argument
_remove
;;
*) # unknown option, noop
shift # past argument
;;
esac
done
exit 0