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.

Revisions

  1. jaycode revised this gist Oct 27, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion opencv-uninstall.sh
    Original file line number Diff line number Diff line change
    @@ -66,7 +66,7 @@ if [[ "$key" =~ ^[Yy]$ ]]; then
    # y pressed
    echo "Uninstalling..."
    if [ ! -z "$LIST" ];then
    sudo $PKMGR remove $LIST
    sudo $PKGMGR remove $LIST
    else
    echo "OpenCV not found in dpkg"
    echo "If OpenCV was installed,"
  2. @lonehack lonehack revised this gist Apr 16, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions opencv-uninstall.sh
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,9 @@

    #########################################################################################################
    ## OpenCV Uninstallation Script
    ## Rules : DROP all ACCEPT many
    ##
    ## Code by : Dimas Toha Pramawitra (Lonehack)
    ## <dms.pram@gmail.com>
    ## <dms.pram@gmail.com>
    ## Created : 20 Mar 2016
    ## Modified : 16 Apr 2016
    ##
  3. @lonehack lonehack revised this gist Apr 16, 2016. 1 changed file with 54 additions and 11 deletions.
    65 changes: 54 additions & 11 deletions opencv-uninstall.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,60 @@
    #!/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)
    #########################################################################################################
    ## OpenCV Uninstallation Script
    ## Rules : DROP all ACCEPT many
    ##
    ## Code by : Dimas Toha Pramawitra (Lonehack)
    ## <dms.pram@gmail.com>
    ## Created : 20 Mar 2016
    ## Modified : 16 Apr 2016
    ##
    ## This code is released to the public domain.
    ## You can use, modify, or distribute this code as you need without any restriction.
    #########################################################################################################

    #################################################################################
    ## Distribution check
    #################################################################################

    if [ -f /etc/debian_version ];then
    DIST="debian"
    PKG=$(which dpkg)
    PKGMGR=$(which apt-get)
    PKGLIST=" --get-selections"
    elif [ -f /etc/redhat-release ];then
    DIST="redhat"
    PKG=$(which rpm)
    PKGMGR=$(which dnf)
    if [ -z "$PKGMGR" ];then
    PKGMGR=$(which yum)
    fi
    PKGLIST="--all"
    else
    echo "Your Linux Distribution not yet supported by this script"
    echo "Uninstall manualy or edit this script for your need"
    exit 0
    fi

    #################################################################################
    ## Initialization
    #################################################################################

    LIST=$($PKG $PKGLIST | grep opencv | awk '{print $1}')
    VERSION=$(pkg-config --modversion opencv)
    PYT=$(pkg-config --modversion python)
    PFX="/usr/local/"

    trap ctrl_c INT
    function ctrl_c() {
    echo "Terminated by User!"
    exit 0
    }

    #################################################################################
    ## Uninstallation
    #################################################################################

    if [ -z "$VERSION" ];then
    echo "OpenCV not found in pkg-config"
    echo "If OpenCV was installed,"
    @@ -17,7 +67,7 @@ if [[ "$key" =~ ^[Yy]$ ]]; then
    # y pressed
    echo "Uninstalling..."
    if [ ! -z "$LIST" ];then
    sudo apt-get remove $LIST
    sudo $PKMGR remove $LIST
    else
    echo "OpenCV not found in dpkg"
    echo "If OpenCV was installed,"
    @@ -35,11 +85,4 @@ if [[ "$key" =~ ^[Yy]$ ]]; then
    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
  4. @lonehack lonehack created this gist Mar 19, 2016.
    45 changes: 45 additions & 0 deletions opencv-uninstall.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/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