Last active
November 26, 2025 12:20
-
-
Save felipealfonsog/d3bf4d70504f52c03094d2c0d79992b0 to your computer and use it in GitHub Desktop.
Removing Python's EXTERNALLY-MANAGED lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| echo "──────────────────────────────────────────────" | |
| echo " Removing Python's EXTERNALLY-MANAGED lock " | |
| echo "──────────────────────────────────────────────" | |
| echo "* Developed and engineered by:" | |
| echo "* Felipe Alfonso Gonzalez <[email protected]>" | |
| echo "* Computer Science Engineer" | |
| echo "* Chile" | |
| echo "------------------------------------------------" | |
| echo "* Find me on GitHub: github.com/felipealfonsog" | |
| echo "* License: MIT & BSD v3 - Restrictive by author" | |
| echo "──────────────────────────────────────────────" | |
| show_progress() { | |
| local duration=$1 | |
| local interval=0.08 | |
| local steps | |
| steps=$(awk "BEGIN {printf \"%d\", $duration / $interval}") | |
| local i=0 | |
| while [ $i -le $steps ]; do | |
| local progress=$(( i * 100 / (steps>0 ? steps : 1) )) | |
| local filled=$(( progress * 50 / 100 )) | |
| local bar="" | |
| for ((j=0; j<filled; j++)); do bar+="="; done | |
| for ((j=filled; j<50; j++)); do bar+=" "; done | |
| printf "\r[%s] %3d%%" "$bar" "$progress" | |
| sleep $interval | |
| ((i++)) | |
| done | |
| echo | |
| } | |
| search_paths=( | |
| "/opt/homebrew" | |
| "/usr/local/Cellar" | |
| "/usr/lib" | |
| "/usr/local/lib" | |
| "/lib" | |
| "/lib64" | |
| ) | |
| found_files=() | |
| echo | |
| echo "🔍 Searching for EXTERNALLY-MANAGED files in common paths..." | |
| show_progress 1.6 | |
| for base in "${search_paths[@]}"; do | |
| if [ -d "$base" ]; then | |
| while IFS= read -r -d $'\0' file; do | |
| found_files+=("$file") | |
| done < <(find "$base" -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null) | |
| fi | |
| done | |
| if [ ${#found_files[@]} -eq 0 ]; then | |
| echo | |
| echo "No EXTERNALLY-MANAGED files found in predefined paths." | |
| echo "Searching system-wide (may take a while)..." | |
| show_progress 3.2 | |
| while IFS= read -r -d $'\0' file; do | |
| found_files+=("$file") | |
| done < <(find / -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null) | |
| fi | |
| if [ ${#found_files[@]} -gt 0 ]; then | |
| echo | |
| echo "🧹 Found ${#found_files[@]} file(s). Renaming now..." | |
| total=${#found_files[@]} | |
| count=0 | |
| for file in "${found_files[@]}"; do | |
| ((count++)) | |
| percent=$(( count * 100 / total )) | |
| filled=$(( percent * 50 / 100 )) | |
| bar="" | |
| for ((j=0; j<filled; j++)); do bar+="="; done | |
| for ((j=filled; j<50; j++)); do bar+=" "; done | |
| printf "\r[%s] %3d%% - %s" "$bar" "$percent" "$(basename "$file")" | |
| if sudo mv -- "$file" "${file}_"; then | |
| printf " ✅\n" | |
| else | |
| printf " ❌ (failed)\n" | |
| fi | |
| done | |
| echo | |
| echo "✅ All EXTERNALLY-MANAGED files processed." | |
| else | |
| echo | |
| echo "ℹ️ No EXTERNALLY-MANAGED files were found on this system." | |
| fi | |
| echo "──────────────────────────────────────────────" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| echo "──────────────────────────────────────────────" | |
| echo " Removing Python's EXTERNALLY-MANAGED lock " | |
| echo "──────────────────────────────────────────────" | |
| echo "* Developed and engineered by:" | |
| echo "* Felipe Alfonso Gonzalez <[email protected]>" | |
| echo "* Computer Science Engineer" | |
| echo "* Chile" | |
| echo "------------------------------------------------" | |
| echo "* Find me on GitHub: github.com/felipealfonsog" | |
| echo "* License: MIT & BSD v3 - Restrictive by author" | |
| echo "──────────────────────────────────────────────" | |
| search_paths=( | |
| "/opt/homebrew" | |
| "/usr/local/Cellar" | |
| "/usr/lib" | |
| "/usr/local/lib" | |
| "/lib" | |
| "/lib64" | |
| ) | |
| found_files=() | |
| # Función para buscar archivos en paths predefinidos | |
| search_in_paths() { | |
| echo | |
| echo "🔍 Searching in common paths..." | |
| for base in "${search_paths[@]}"; do | |
| if [ -d "$base" ]; then | |
| while IFS= read -r -d $'\0' file; do | |
| found_files+=("$file") | |
| done < <(find "$base" -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null) | |
| fi | |
| done | |
| } | |
| # Función para buscar system-wide con spinner | |
| search_system_wide() { | |
| echo | |
| echo "🔍 Searching system-wide (may take a while)..." | |
| temp_file=$(mktemp) | |
| find / -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null > "$temp_file" & | |
| pid=$! | |
| spinner="/|\\-" | |
| i=0 | |
| while kill -0 $pid 2>/dev/null; do | |
| i=$(( (i+1) % 4 )) | |
| printf "\r%c Searching..." "${spinner:$i:1}" | |
| sleep 0.1 | |
| done | |
| wait $pid | |
| echo | |
| while IFS= read -r -d $'\0' file; do | |
| found_files+=("$file") | |
| done < "$temp_file" | |
| rm -f "$temp_file" | |
| } | |
| # Buscar primero en paths predefinidos | |
| search_in_paths | |
| # Si no se encontró nada, buscar system-wide | |
| if [ ${#found_files[@]} -eq 0 ]; then | |
| search_system_wide | |
| fi | |
| # Renombrar archivos encontrados | |
| if [ ${#found_files[@]} -gt 0 ]; then | |
| echo | |
| echo "🧹 Found ${#found_files[@]} file(s). Renaming now..." | |
| total=${#found_files[@]} | |
| count=0 | |
| for file in "${found_files[@]}"; do | |
| ((count++)) | |
| sudo mv -- "$file" "${file}_" | |
| echo "[$count/$total] Renamed: $file" | |
| done | |
| echo | |
| echo "✅ All EXTERNALLY-MANAGED files processed." | |
| else | |
| echo | |
| echo "ℹ️ No EXTERNALLY-MANAGED files were found on this system." | |
| fi | |
| echo "──────────────────────────────────────────────" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment