seladb / PcapPlusPlus

PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets. It is designed to be efficient, powerful and easy to use. It provides C++ wrappers for the most popular packet processing engines such as libpcap, Npcap, WinPcap, DPDK, AF_XDP and PF_RING.
https://pcapplusplus.github.io/
The Unlicense
2.73k stars 669 forks source link

v22.11 make uninstall will remove /usr/local/bin #1517

Closed MapleLCG closed 2 months ago

MapleLCG commented 3 months ago

Bug description

I see there is a guy open a same issue in 2020,but he didnt give more information. This is what I did

/PcapPlusPlus-22.11$ sudo make uninstall
rm: cannot remove '/usr/local/bin/bin': Is a directory
rm: cannot remove '/usr/local/bin/doc': Is a directory
rm: cannot remove '/usr/local/bin/__pycache__': Is a directory

and the dir structure is

PcapPlusPlus-22.11/mk# ls
install.sh                   PcapPlusPlus.mk.dpdk         PcapPlusPlus.mk.macosx.arm64  platform.mk.freebsd       platform.mk.musl               vs
install.sh.freebsd.template  PcapPlusPlus.mk.dpdk_legacy  PcapPlusPlus.mk.mingw-w64     platform.mk.fuzzing       setup_dpdk.py
install.sh.template          PcapPlusPlus.mk.freebsd      PcapPlusPlus.mk.pf_ring       platform.mk.linux         uninstall
PcapPlusPlus.mk              PcapPlusPlus.mk.fuzzing      PcapPlusPlus.mk.zstd          platform.mk.macosx        uninstall.sh
PcapPlusPlus.mk.android      PcapPlusPlus.mk.linux        platform.mk                   platform.mk.macosx.arm64  uninstall.sh.freebsd.template
PcapPlusPlus.mk.common       PcapPlusPlus.mk.macosx       platform.mk.android           platform.mk.mingw-w64     uninstall.sh.template
/PcapPlusPlus-22.11# ls
3rdParty      codespell-ignore-list.txt  configure-freebsd.sh  configure-mac_os_x.sh                CONTRIBUTING.md  LICENSE   Packet++   Tests
appveyor.yml  Common++                   configure-fuzzing.sh  configure-windows-mingw.bat          Dist             Makefile  Pcap++     typos-config.toml
ci            configure-android.sh       configure-linux.sh    configure-windows-visual-studio.bat  Examples         mk        README.md

uninstal.sh

set -e # Exit with nonzero exit code if anything fails

INSTALL_DIR=/usr/local

# remove libs
rm -f $INSTALL_DIR/lib/libCommon++.a $INSTALL_DIR/lib/libPacket++.a $INSTALL_DIR/lib/libPcap++.a

# remove header files
rm -rf $INSTALL_DIR/include/pcapplusplus

# remove examples
for f in examples/*; do rm -f $INSTALL_DIR/bin/$(basename "$f"); done

# remove template makefile
rm -f $INSTALL_DIR/etc/PcapPlusPlus.mk

# remove PcapPlusPlus.pc
PKG_CONFIG_PATH="${PKG_CONFIG_PATH:-$INSTALL_DIR/lib/pkgconfig}"
rm -f $PKG_CONFIG_PATH/PcapPlusPlus.pc

Don't know much about how sh script works, but I think it's a case issue with ”examples“ dir well,in ”mk”,there is no dir named examples in source dir,there is a dir named Examples Could this be the reason?

PcapPlusPlus versions tested on

v22.11

Other PcapPlusPlus version (if applicable)

No response

Operating systems tested on

Linux

Other operation systems (if applicable)

No response

Compiler version

gcc

Packet capture backend (if applicable)

No response

MapleLCG commented 3 months ago

I built from released source and I did this make libs && make install then make uninstall

there is no check berfore "rm -f" command I'm saddened by the disappearance of my /usr/local/bin, but in order to prevent more people from having the same experience as me, I'll try to give the solution

#!/bin/bash
set -e # Exit with nonzero exit code if anything fails

INSTALL_DIR={{INSTALL_DIR}}

# Function to check if file or directory exists before removing
check_and_remove() {
  if [ -e "$1" ]; then
    rm -f "$1"
  elif [ -d "$1" ]; then
    rm -rf "$1"
  else
    echo "Skipping deletion of non-existent path: $1"
  fi
}

# Check if the installation directory exists
if [ ! -d "$INSTALL_DIR" ]; then
  echo "Installation directory does not exist: $INSTALL_DIR"
  exit 1
fi

# remove libs
check_and_remove "$INSTALL_DIR/lib/libCommon++.a"
check_and_remove "$INSTALL_DIR/lib/libPacket++.a"
check_and_remove "$INSTALL_DIR/lib/libPcap++.a"

# remove header files
check_and_remove "$INSTALL_DIR/include/pcapplusplus"

# Check if the examples directory exists before removing its contents
if [ -d "$INSTALL_DIR/bin/examples" ]; then
  for f in "$INSTALL_DIR/bin/examples"/*; do
    check_and_remove "$f"
  done
else
  echo "Examples directory does not exist, skipping: $INSTALL_DIR/bin/examples"
fi

# remove template makefile
check_and_remove "$INSTALL_DIR/etc/PcapPlusPlus.mk"

# remove PcapPlusPlus.pc
PKG_CONFIG_PATH="${PKG_CONFIG_PATH:-$INSTALL_DIR/lib/pkgconfig}"
check_and_remove "$PKG_CONFIG_PATH/PcapPlusPlus.pc"

Personally, I think it's enough to check if the examples folder exists, but these seemingly pointless checks make me feel more at ease hahaha

seladb commented 3 months ago

@MapleLCG v22.11 is not the newest version, did you try v23.09 to see if it works?

MapleLCG commented 3 months ago

@MapleLCG v22.11 is not the newest version, did you try v23.09 to see if it works?

In the beginning,I used v23.09. Then I wanted to use v22.11. It’s fine when I uninstall v23.09

seladb commented 3 months ago

@MapleLCG v22.11 is not the newest version, did you try v23.09 to see if it works?

In the beginning,I used v23.09. Then I wanted to use v22.11. It’s fine when I uninstall v23.09

I'm curious why do you prefer v22.11 over v23.09? 🤔

MapleLCG commented 3 months ago

@MapleLCG v22.11 is not the newest version, did you try v23.09 to see if it works?

In the beginning,I used v23.09. Then I wanted to use v22.11. It’s fine when I uninstall v23.09

I'm curious why do you prefer v22.11 over v23.09? 🤔

Because when I started using v23.09, although the program compiled and passed, it couldn't get my NIC when I ran it. In the process of troubleshooting the problem, out of personal habit, I downgraded pcpp, so I installed v22.11. I found out later that this is not a pcpp problem, so I'm going to uninstall v22.11 and go back to using v23.09.

I actually prefer to use the latest version, but occasionally I just try older releases for various reasons.

seladb commented 3 months ago

Because when I started using v23.09, although the program compiled and passed, it couldn't get my NIC when I ran it. In the process of troubleshooting the problem, out of personal habit, I downgraded pcpp, so I installed v22.11. I found out later that this is not a pcpp problem, so I'm going to uninstall v22.11 and go back to using v23.09.

I actually prefer to use the latest version, but occasionally I just try older releases for various reasons.

Got it. I'm not sure we want to debug and fix issues in v22.11 (we never did it before...), mostly because there is a newer version that fixes it...

MapleLCG commented 3 months ago

Because when I started using v23.09, although the program compiled and passed, it couldn't get my NIC when I ran it. In the process of troubleshooting the problem, out of personal habit, I downgraded pcpp, so I installed v22.11. I found out later that this is not a pcpp problem, so I'm going to uninstall v22.11 and go back to using v23.09. I actually prefer to use the latest version, but occasionally I just try older releases for various reasons.

Got it. I'm not sure we want to debug and fix issues in v22.11 (we never did it before...), mostly because there is a newer version that fixes it...

I understand. But note that an identical issue was mentioned back in 2020. i haven't checked other versions and i'm not sure if the cause of his issue is the same as mine. So it's possible that versions prior to v23.09 have this problem. But if you guys don't think it needs to be fixed, please at least alert people to the problem and recommend using the latest release. Thanks for your replies.

seladb commented 2 months ago

I assume it happens in all versions prior to v22.11 because we didn't change much in the installation scripts over the years (until v23.09 where we moved to CMake).

What's weird is that I never encountered this issue myself, and never heard it from anyone else. I'd assume someone would bump into it by now 🤔

Maybe you added specific params when you installed/uninstalled PcapPlusPlus?

MapleLCG commented 2 months ago

I assume it happens in all versions prior to v22.11 because we didn't change much in the installation scripts over the years (until v23.09 where we moved to CMake).

What's weird is that I never encountered this issue myself, and never heard it from anyone else. I'd assume someone would bump into it by now 🤔

Maybe you added specific params when you installed/uninstalled PcapPlusPlus?

I edited 2nd comment to show what i did. IDK how do you read github issue,so maybe you didnt see my change Well it's in Ubuntu 22.04.4 LTS and donwload source -> ./configure-linux.sh (pf_ring=no, dpdk=no) -> make libs -> make install -> make uninstall. I did't make examples and unit-tests. docs told me that I could just make libs https://pcapplusplus.github.io/docs/v22.11/install/linux#build-the-code

seladb commented 2 months ago

I'll try it myself and let you know if I see this issue also

seladb commented 2 months ago

@MapleLCG this is a bug indeed, but only when you run make libs. If you run make it will build the examples, copy them to /usr/local/bin, and when running make uninstall it won't delete the entire directory content.

So the workaround is to run make.

Unfortunately, we don't have a way to fix v22.11. My recommendation is to use the latest version which is v23.09