Skip to content

Instantly share code, notes, and snippets.

@jaycode
Forked from lonehack/opencv-uninstall.sh
Created October 27, 2018 05:39
Show Gist options
  • Select an option

  • Save jaycode/6c1684eafb6607325e7b3e01e83ec08b to your computer and use it in GitHub Desktop.

Select an option

Save jaycode/6c1684eafb6607325e7b3e01e83ec08b to your computer and use it in GitHub Desktop.
Ubuntu shellscript for uninstall OpenCV
#!/bin/bash
LIST=$(/usr/bin/dpkg --get-selections | /bin/grep opencv | /usr/bin/awk '{print $1}')
VERSION=$(/usr/bin/pkg-config --modversion opencv)
PYT=$(/usr/bin/pkg-config --modversion python)
PFX="/usr/local/"
if [ -z "$VERSION" ];then
echo "OpenCV not found in pkg-config"
echo "If OpenCV was installed,"
echo "please uninstall remaining OpenCV manually"
else
echo "Uninstall OpenCV : "$VERSION
fi
read -rsp $'Are you sure? <y/N>\n' -n 1 key
if [[ "$key" =~ ^[Yy]$ ]]; then
# y pressed
echo "Uninstalling..."
if [ ! -z "$LIST" ];then
sudo apt-get remove $LIST
else
echo "OpenCV not found in dpkg"
echo "If OpenCV was installed,"
echo "please uninstall remaining OpenCV manually"
fi
#sudo find / -name "*opencv*" -exec rm {} \;
sudo rm -rf "$PFX"{include/opencv2,include/opencv,share/OpenCV}
sudo find "$PFX"lib -maxdepth 1 -name "libopencv*" -exec rm -f {} \;
sudo find "$PFX"bin/ -maxdepth 1 -name "opencv*" -exec rm -f {} \;
sudo find "$PFX"lib/pkgconfig -maxdepth 1 -name "opencv*" -exec rm -f {} \;
if [ ! -z "$PYT" ];then
sudo find "$PFX"lib/python$PYT/dist-packages/ -maxdepth 1 -name "cv*" -exec rm -f {} \;
fi
echo "Uninstall OpenCV done!"
else
echo "Uninstall OpenCV aborted.."
exit 0
fi
trap 'abort' 1
if [ $? -eq 1 ];then
echo "Uninstall OpenCV interupted by user!!"
else
echo "Uninstall OpenCV completed!!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment