Advertisement
Matthew_Cline

Wayward script to remove unneeded libstdc++

Nov 17th, 2019
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script removes the Electron copy of the C++ library so the system copy
  4. # can be used instead, but only if doing so is safe.
  5.  
  6. lib="libstdc++.so.6"
  7.  
  8. if [[ ! -e $lib || ! `which ldd` ]]; then
  9.     # Electron libstdc++ already removed, or ldd not available
  10.     exit 0
  11. fi
  12.  
  13. sys_lib_dir=""
  14.  
  15. # Find 64 bit version of system libstdc++
  16. for dir in /lib64 /usr/lib64 /lib /usr/lib; do
  17.     file="$dir/$lib"  
  18.     if [[ -e $file ]]; then
  19.         sys_lib_dir="$dir"
  20.         break
  21.     fi
  22. done
  23.  
  24. if [[ -z "$sys_lib_dir" ]]; then
  25.     # Can't find system libstdc++
  26.     exit 0
  27. fi
  28.  
  29. #########################################################################
  30.  
  31. # LD_LIBRAY_PATH env var is used before an ELF file's RUNPATH, so ldd will try
  32. # linking against the system copy of libstdc++ and report any missing versions.
  33. export LD_LIBRAY_PATH=$sys_lib_dir
  34.  
  35. # libdiscord-rpc.so and the Node.Js files are the ones that link against
  36. # libstdc++.so
  37. for file in libdiscord-rpc.so *.node; do
  38.     err=$(ldd $file | grep "version \`GLIBCXX_.* not found")
  39.     if [[ -n "$err" ]] ; then
  40.         exit 0
  41.     fi
  42. done
  43.  
  44. # System copy of lib has all C++ versions we need, so get rid of Electron copy
  45. # of the library
  46. mkdir -p UNNEEDED
  47. mv -f $lib UNNEEDED
  48.  
  49. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement