diff options
author | David P <megver83@parabola.nu> | 2020-10-03 17:29:25 -0300 |
---|---|---|
committer | David P <megver83@parabola.nu> | 2020-10-03 17:29:25 -0300 |
commit | 519e83cc27b177ae86055d55ca4e1a2c42fb0919 (patch) | |
tree | eb4163ad50030ae366b9c9c6b321359ea2cffcd2 | |
parent | 6b32580fb3c4bf5abcde52ae6b2e2a0875d6e7d1 (diff) |
shellcheck find-deprecated-pkgs
and improve the method to find if it's connected to internet
Signed-off-by: David P <megver83@parabola.nu>
-rwxr-xr-x | find-deprecated-pkgs | 119 |
1 files changed, 61 insertions, 58 deletions
diff --git a/find-deprecated-pkgs b/find-deprecated-pkgs index 5945f81..0020a22 100755 --- a/find-deprecated-pkgs +++ b/find-deprecated-pkgs @@ -26,23 +26,23 @@ blacklists_parabola="your-initfreedom-blacklist.txt your-privacy-blacklist.txt y # Mirrors. Please choose HTTPS over HTTP when possible # x86_64 mirrors for r in $repos_x86_64; do - mirrors+=(https://mirrors.edge.kernel.org/archlinux/$r/os/x86_64/) + mirrors+=("https://mirrors.edge.kernel.org/archlinux/$r/os/x86_64/") done # i686 mirrors for r in $repos_i686; do - mirrors+=(https://mirror.archlinux32.org/i686/$r/) + mirrors+=("https://mirror.archlinux32.org/i686/$r/") done # armv7h mirrors for r in $repos_armv7h; do - mirrors+=(https://fl.us.mirror.archlinuxarm.org/armv7h/$r/) + mirrors+=("https://fl.us.mirror.archlinuxarm.org/armv7h/$r/") done add_parabola_mirrors(){ # Parabola mirrors, used to check [libre] and [pcr] packages for r in $repos_parabola; do - mirrors+=(https://mirror.grapentin.org/parabola/$r/os/x86_64/) - mirrors+=(https://mirror.grapentin.org/parabola/$r/os/i686/) - mirrors+=(https://mirror.grapentin.org/parabola/$r/os/armv7h/) + mirrors+=("https://mirror.grapentin.org/parabola/$r/os/x86_64/") + mirrors+=("https://mirror.grapentin.org/parabola/$r/os/i686/") + mirrors+=("https://mirror.grapentin.org/parabola/$r/os/armv7h/") done } @@ -84,27 +84,27 @@ mkpkglist(){ arch_pkgs=$(mktemp) case $1 in parabola) add_parabola_mirrors - curl -s ${mirrors[@]} | grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' | sed $sedexp > $parabola_pkgs + curl -s "${mirrors[@]}" | grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' | sed $sedexp > "$parabola_pkgs" # Separate packages by architecture for arch in x86_64 i686 armv7h any; do - grep $arch$ $parabola_pkgs | for f in $(</dev/stdin); do - echo "${f%-*-*-*} $arch" >> $parabola_pkgs-$arch + grep $arch$ "$parabola_pkgs" | for f in $(</dev/stdin); do + echo "${f%-*-*-*} $arch" >> "$parabola_pkgs"-$arch done done - cat $parabola_pkgs-{x86_64,i686,armv7h,any} | sort -u > $parabola_pkgs - rm $parabola_pkgs-{x86_64,i686,armv7h,any} + cat "$parabola_pkgs"-{x86_64,i686,armv7h,any} | sort -u > "$parabola_pkgs" + rm "$parabola_pkgs"-{x86_64,i686,armv7h,any} ;; - arch) curl -s ${mirrors[@]} | grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' | sed $sedexp > $arch_pkgs + arch) curl -s "${mirrors[@]}" | grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' | sed $sedexp > "$arch_pkgs" # Separate packages by architecture for arch in x86_64 i686 armv7h any; do - grep $arch$ $arch_pkgs | for f in $(</dev/stdin); do - echo "${f%-*-*-*} $arch" >> $arch_pkgs-$arch + grep $arch$ "$arch_pkgs" | for f in $(</dev/stdin); do + echo "${f%-*-*-*} $arch" >> "$arch_pkgs"-$arch done done - cat $arch_pkgs-{x86_64,i686,armv7h,any} | sort -u > $arch_pkgs - rm $arch_pkgs-{x86_64,i686,armv7h,any} + cat "$arch_pkgs"-{x86_64,i686,armv7h,any} | sort -u > "$arch_pkgs" + rm "$arch_pkgs"-{x86_64,i686,armv7h,any} ;; esac } @@ -136,22 +136,22 @@ get_libre_pkgs(){ if ! [[ -e $libre_pkgs ]]; then libre_pkgs=$(mktemp) for r in libre libre-multilib libre-testing libre-multilib-testing; do - mirrors_parabola+=(https://mirror.grapentin.org/parabola/$r/os/x86_64/) - mirrors_parabola+=(https://mirror.grapentin.org/parabola/$r/os/i686/) - mirrors_parabola+=(https://mirror.grapentin.org/parabola/$r/os/armv7h/) + mirrors_parabola+=("https://mirror.grapentin.org/parabola/$r/os/x86_64/") + mirrors_parabola+=("https://mirror.grapentin.org/parabola/$r/os/i686/") + mirrors_parabola+=("https://mirror.grapentin.org/parabola/$r/os/armv7h/") done - curl -s ${mirrors_parabola[@]} | grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' | sed $sedexp > $libre_pkgs + curl -s "${mirrors_parabola[@]}" | grep '".*.pkg.tar.xz"\|".*.pkg.tar.zst"' | sed $sedexp > "$libre_pkgs" for arch in x86_64 i686 armv7h any; do - grep $arch$ $libre_pkgs | for f in $(</dev/stdin); do - echo "${f%-*-*-*} $arch" >> $libre_pkgs-$arch + grep $arch$ "$libre_pkgs" | for f in $(</dev/stdin); do + echo "${f%-*-*-*} $arch" >> "$libre_pkgs"-$arch done done - cat $libre_pkgs-{x86_64,i686,armv7h,any} | sort -u > $libre_pkgs + cat "$libre_pkgs"-{x86_64,i686,armv7h,any} | sort -u > "$libre_pkgs" fi } add(){ - list=$(( $list + 1 )) + list="$(( list + 1 ))" } compare_pkgs(){ @@ -162,12 +162,12 @@ compare_pkgs(){ # a specific architecture, if not, check # if it's for 'any' package="${1%%:*}" - replacement="$(cut -d ":" -f2 <(echo $1))" + replacement="$(cut -d ":" -f2 <(echo "$1"))" for arch in x86_64 i686 armv7h; do - grep $arch$ $2 | awk '{print $1}' | grep -xw ^$package &> /dev/null || \ - grep any$ $2 | awk '{print $1}' | grep -xw ^$package &> /dev/null || \ - if [ $2 = $arch_pkgs ]; then + grep $arch$ "$2" | awk '{print $1}' | grep -xw ^"$package" &> /dev/null || \ + grep any$ "$2" | awk '{print $1}' | grep -xw ^"$package" &> /dev/null || \ + if [ "$2" = "$arch_pkgs" ]; then get_libre_pkgs # Check if the package has a replacement, and # if such replacement is available for the same @@ -175,53 +175,53 @@ compare_pkgs(){ if ! [[ $replacement = "" ]]; then # If this works, it means the pkg doesn't exist for $arch in Arch, # but we have the [libre] replacement which should be deprecated. - grep $arch$ $libre_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null || \ - grep any$ $libre_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null + grep $arch$ "$libre_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null || \ + grep any$ "$libre_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null case $? in - 0) to_be_removed+=($arch) + 0) to_be_removed+=("$arch") ;; - *) is_not_for+=($arch) + *) is_not_for+=("$arch") ;; esac else # However if this fails, it means the pkg doesn't have a replacement # for $arch, or it simply doesn't have a replacement. - is_not_for+=($arch) + is_not_for+=("$arch") fi - elif [ $2 = $parabola_pkgs ]; then - if ! [[ $replacement = "" ]]; then + elif [ "$2" = "$parabola_pkgs" ]; then + if [[ -n $replacement ]]; then # Look for the replacement - grep $arch$ $parabola_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null || \ - grep any$ $parabola_pkgs | awk '{print $1}' | grep -xw ^$replacement &> /dev/null + grep $arch$ "$parabola_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null || \ + grep any$ "$parabola_pkgs" | awk '{print $1}' | grep -xw ^"$replacement" &> /dev/null case $? in - 0) to_be_deleted+=($arch) + 0) to_be_deleted+=("$arch") ;; - *) isnt_for+=($arch) + *) isnt_for+=("$arch") ;; esac else - isnt_for+=($arch) + isnt_for+=("$arch") fi fi done # Arch - if [[ ${is_not_for[@]} = "x86_64 i686 armv7h" ]]; then + if [[ "${is_not_for[*]}" = "x86_64 i686 armv7h" ]]; then submsg "$package was not found" add - elif [[ ${to_be_removed[@]} = "x86_64 i686 armv7h" ]]; then + elif [[ "${to_be_removed[*]}" = "x86_64 i686 armv7h" ]]; then submsg "$package was not found, but we've [libre] replacements which should be removed" add - elif ! [[ ${is_not_for[@]} = "" ]] || ! [[ ${to_be_removed[@]} = "" ]]; then - for arch in ${to_be_removed[@]}; do + elif [[ -n "${is_not_for[*]}" ]] || [[ -n "${to_be_removed[*]}" ]]; then + for arch in "${to_be_removed[@]}"; do # If the replacement is available for the three arch'es supported # by Parabola, then shut up for a in x86_64 i686 armv7h; do - grep -xw "^$replacement $a$" $libre_pkgs &> /dev/null && arches+=($a) + grep -xw "^$replacement $a$" "$libre_pkgs" &> /dev/null && arches+=("$a") done - if ! [[ ${arches[*]} = "x86_64 i686 armv7h" ]]; then + if ! [[ "${arches[*]}" = "x86_64 i686 armv7h" ]]; then submsg "$package ($arch) was not found, but we've a [libre] replacement which should be removed" add fi @@ -230,11 +230,11 @@ compare_pkgs(){ fi # Parabola - if [[ ${isnt_for[@]} = "x86_64 i686 armv7h" ]]; then + if [[ "${isnt_for[*]}" = "x86_64 i686 armv7h" ]]; then submsg "$package was not found" add - elif ! [[ ${isnt_for[@]} = "" ]]; then - for arch in ${to_be_deleted[@]}; do + elif [[ -n "${isnt_for[*]}" ]]; then + for arch in "${to_be_deleted[@]}"; do submsg "$package ($arch) was not found, but we've $replacement as replacement and should be removed" add done @@ -245,21 +245,21 @@ compare_pkgs(){ } check(){ - mkpkglist $1 + mkpkglist "$1" case $1 in parabola) msg 'Comparing blacklists with Parabola packages ...' - pkgs=$(for bl in $blacklists_parabola; do grep -v ^# $bl | awk '{print $1}'; done) + pkgs=$(for bl in $blacklists_parabola; do grep -v ^# "$bl" | awk '{print $1}'; done) for p in $pkgs; do - compare_pkgs $p $parabola_pkgs + compare_pkgs "$p" "$parabola_pkgs" done - rm -f $parabola_pkgs + rm -f "$parabola_pkgs" ;; arch) msg 'Comparing blacklists with Arch packages ...' pkgs=$(for bl in $blacklists; do grep -v ^# $bl | awk '{print $1}'; done) for p in $pkgs; do - compare_pkgs $p $arch_pkgs + compare_pkgs "$p" "$arch_pkgs" done - rm -f $arch_pkgs $libre_pkgs + rm -f "$arch_pkgs" "$libre_pkgs" ;; *) err "$1 is not a valid argument" ;; @@ -272,9 +272,12 @@ check(){ } if [[ ${#@} -gt 0 ]]; then - ip r | grep ^default | awk '{print $3}' | - ping -q -w1 -c1 $(tail -n1 /dev/stdin) &> /dev/null || err 'You must have internet connection to run this program' - for arg in $@; do check $arg; done + netcheck="$(curl -sL networkcheck.kde.org)" + if [[ "$netcheck" = OK ]]; then + for arg in "$@"; do check "$arg"; done + else + err 'You must have internet connection to run this program' + fi else usage fi |