Skip to content

Commit

Permalink
v0.9.1: Fixed blacklists filter
Browse files Browse the repository at this point in the history
  • Loading branch information
archcrack committed Jan 29, 2021
1 parent 6346a26 commit db02b4a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .SRCINFO
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pkgbase = isfree
pkgdesc = Check your Arch system for nonfree software
pkgver = 0.9.0
pkgrel = 2
pkgver = 0.9.1
pkgrel = 1
url = https://github.com/leo-arch/isfree
arch = any
license = GPL2
Expand Down
4 changes: 2 additions & 2 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Maintainer: archcrack <[email protected]>

pkgname=isfree
pkgver=0.9.0
pkgrel=2
pkgver=0.9.1
pkgrel=1
pkgdesc="Check your Arch system for nonfree software"
arch=(any)
url="https://github.com/leo-arch/isfree"
Expand Down
97 changes: 67 additions & 30 deletions isfree
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ nc=""
### PROGRAM DATA ###

ME="IsFree"
VERSION="0.9.0"
DATE="Jan 15, 2021"
VERSION="0.9.1"
DATE="Jan 28, 2021"
AUTHOR="L. Abramovich"
LICENSE="GPL2"
WEBSITE="https://github.com/leo-arch/isfree"
Expand Down Expand Up @@ -317,8 +317,24 @@ blacklist_line ()
local pack="$1" counter="$2" bl_line=""

bl_line="$(/usr/bin/grep "^$pack:" -- "$tmp_file")"

case "$bl_line" in
# bl_line="webkit2gtk:webkit2gtk::: depends of geoclue2"

# if [[ $bl_line == *"depends"* ]]; then
# local pkg_dep="$(echo "$bl_line" \
# | grep -o "depends".* | cut -d" " -f3)"
# if [[ $bl_line == *"$pkg_dep" ]]; then
# if [[ -z $pkg_dep || $(ls -d /var/lib/pacman/local/"$pkg_dep"* 2>/dev/null) ]]; then
# :
# else
# return -1
# fi
# fi
# fi

desc="$(echo "$bl_line" | cut -d":" -f 5-10)"

case "$desc" in

*\[technical\]*|*\[branding\]*)
echo -ne "$white$counter$nc) $green$pack: $nc" \
&& (( technical++ ))
Expand All @@ -339,23 +355,29 @@ blacklist_line ()
&& (( fix_doc++ ))
;;

*)
"")
echo -ne "$white$counter$nc) $blue$pack: $nc\n" \
&& (( no_desc++ ))
;;

*)
echo -ne "$white$counter$nc) $cyan$pack: $nc" \
&& (( no_tag++ ))
;;
esac

# Get package description
if [[ $nocolor -eq 0 ]]; then
export GREP_COLORS="mt=1;36"

echo "$bl_line" | /usr/bin/cut -d":" -f5-10 \
| /usr/bin/grep --color=always -- "\[technical\]\|\[branding\]\|\[nonfree\]\|\[semifree\]\|\[uses-nonfree\]\|\[recommends-nonfree\]\|\[FIXME description\]\|\[FIXME package\]"
if ! echo "$desc" | /usr/bin/grep --color=always -- "\[technical\]\|\[branding\]\|\[nonfree\]\|\[semifree\]\|\[uses-nonfree\]\|\[recommends-nonfree\]\|\[FIXME description\]\|\[FIXME package\]"; then
echo "$desc"
fi

unset GREP_COLORS

else
echo "$bl_line" | /usr/bin/cut -d":" -f5-10
echo "$desc"
fi
}

Expand Down Expand Up @@ -432,7 +454,7 @@ free_alternative ()

color_codes ()
{
local nonfree=$1 semifree=$2 technical=$3 fix_doc=$4 no_desc=$5
local nonfree=$1 semifree=$2 technical=$3 fix_doc=$4 no_desc=$5 no_tag=$6

echo -e "\n${bold}Color codes:"

Expand All @@ -459,9 +481,15 @@ color_codes ()
"description needs to be corrected ($fix_doc)."
fi

if [[ $no_tag -gt 0 ]]; then
echo -e "${cyan}Cyan:$nc No" \
"tag in the descrition of this package in" \
"Parabola's blacklist ($no_tag)."
fi

if [[ $no_desc -gt 0 ]]; then
echo -e "${blue}Blue:$nc there is no" \
"description of this package in" \
echo -e "${blue}Blue:$nc No" \
"description for this package in" \
"Parabola's blacklist ($no_desc)."
fi
}
Expand All @@ -480,15 +508,15 @@ check_native ()
if [[ $full_bl -eq 0 ]]; then
# By default, remove all branding and merely technical
#+ non-free packs
/usr/bin/grep ":\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]\|::::$" \
/usr/bin/grep ":\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]\|^[^[]*$" \
-- "$tmp_file" | /usr/bin/sudo -u "$user" /usr/bin/tee \
/tmp/parabola_bl_official 1>/dev/null || exit $ERROR

tmp_file="/tmp/parabola_bl_official"
fi

# NOTE: the "::::$" condition in grep is aimed to keep lines
#+ coming from the AUR blacklist
# NOTE: the "^[^[]*$" condition in grep is aimed to keep lines
#+ having no square brackets at all
parabola_repo_download

echo -ne "$blue::$nc$bold Getting installed native packages...$nc "
Expand All @@ -504,20 +532,22 @@ check_native ()

local counter=0

fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0
fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0; no_tag=0;

replacement_counter=0

# Compare blocks of 20 pkgs AT ONCE against the blacklist
# This is fast! But there should be a still better solution for
#+ this

mapfile -t non_free < <(for ((i=0; i<${#pkgs[*]}; i=$((i+20)))); do
/usr/bin/grep -- "^${pkgs[$i]}:\|^${pkgs[$((i+1))]}:\|^${pkgs[$((i+2))]}:\|^${pkgs[$((i+3))]}:\|^${pkgs[$((i+4))]}:\|^${pkgs[$((i+5))]}:\|^${pkgs[$((i+6))]}:\|^${pkgs[$((i+7))]}:\|^${pkgs[$((i+8))]}:\|^${pkgs[$((i+9))]}:\|^${pkgs[$((i+10))]}:\|^${pkgs[$((i+11))]}:\|^${pkgs[$((i+12))]}:\|^${pkgs[$((i+13))]}:\|^${pkgs[$((i+14))]}:\|^${pkgs[$((i+15))]}:\|^${pkgs[$((i+16))]}:\|^${pkgs[$((i+17))]}:\|^${pkgs[$((i+18))]}:\|^${pkgs[$((i+19))]}:" "$tmp_file" | /usr/bin/cut -d":" -f1
/usr/bin/grep -- "^${pkgs[$i]}:\|^${pkgs[$((i+1))]}:\|^${pkgs[$((i+2))]}:\|^${pkgs[$((i+3))]}:\|^${pkgs[$((i+4))]}:\|^${pkgs[$((i+5))]}:\|^${pkgs[$((i+6))]}:\|^${pkgs[$((i+7))]}:\|^${pkgs[$((i+8))]}:\|^${pkgs[$((i+9))]}:\|^${pkgs[$((i+10))]}:\|^${pkgs[$((i+11))]}:\|^${pkgs[$((i+12))]}:\|^${pkgs[$((i+13))]}:\|^${pkgs[$((i+14))]}:\|^${pkgs[$((i+15))]}:\|^${pkgs[$((i+16))]}:\|^${pkgs[$((i+17))]}:\|^${pkgs[$((i+18))]}:\|^${pkgs[$((i+19))]}:" \
"$tmp_file" | /usr/bin/cut -d":" -f1
done)

for (( i=0; i<${#non_free[*]}; i++ )); do
blacklist_line "${non_free[$i]}" "$((i+1))"
free_alternative "${non_free[$i]}"
blacklist_line "${non_free[$i]}" "$((i+1))"
free_alternative "${non_free[$i]}"
done

counter=$i
Expand All @@ -530,7 +560,7 @@ check_native ()

if [[ $nocolor -eq 0 ]]; then
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" \
"$no_desc"
"$no_desc" "$no_tag"
fi

echo -e "\n$nc${bold}Packages with no free/libre alternatives (yet):$nc"
Expand Down Expand Up @@ -589,7 +619,7 @@ check_aur ()
get_blacklist "aur"

if [[ $full_bl -eq 0 ]]; then
/usr/bin/grep "::::$\|:\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]" \
/usr/bin/grep "::::$\|:\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]\|^[^[]*$" \
-- "$tmp_file" | /usr/bin/sudo -u "$user" /usr/bin/tee \
/tmp/parabola_bl_aur 1>/dev/null || exit $ERROR

Expand All @@ -605,7 +635,7 @@ check_aur ()
echo -e "${green}OK$nc"
echo -e "Non-free installed AUR packages:$nc\n"

counter=0; fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0
counter=0; fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0; no_tag=0;

mapfile -t non_free < <(for (( i=0; i<${#aur_packs[*]}; i=$((i+10)) )); do
/usr/bin/grep -- "^${aur_packs[$i]}:\|^${aur_packs[$((i+1))]}:\|^${aur_packs[$((i+2))]}:\|^${aur_packs[$((i+3))]}:\|^${aur_packs[$((i+4))]}:\|^${aur_packs[$((i+5))]}:\|^${aur_packs[$((i+6))]}:\|^${aur_packs[$((i+7))]}:\|^${aur_packs[$((i+8))]}:\|^${aur_packs[$((i+9))]}:" \
Expand All @@ -625,7 +655,7 @@ check_aur ()
fi

if [[ $nocolor -eq 0 ]]; then
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" "$no_desc"
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" "$no_desc" "$no_tag"
fi

echo -e "\n-------------"
Expand Down Expand Up @@ -681,7 +711,7 @@ check_repo ()
if [[ $full_bl -eq 0 ]]; then
# By default, remove all branding and merely technical
#+ non-free packs
/usr/bin/grep ":\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]" \
/usr/bin/grep ":\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]\|^[^[]*$" \
-- "$tmp_file" | /usr/bin/sudo -u "$user" /usr/bin/tee \
/tmp/parabola_bl_official 1>/dev/null || exit $ERROR

Expand All @@ -693,7 +723,7 @@ check_repo ()
echo -e "Non-free packages in repository $nc${bold}[$repo]$nc:\n"

nonfree_counter=0; alt_counter=0
fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0;
fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0; no_tag=0;

for (( i=0; i<${#pkgs[*]}; i=$((i+20)) )); do
/usr/bin/grep -- "^${pkgs[$i]}:\|^${pkgs[$((i+1))]}:\|^${pkgs[$((i+2))]}:\|^${pkgs[$((i+3))]}:\|^${pkgs[$((i+4))]}:\|^${pkgs[$((i+5))]}:\|^${pkgs[$((i+6))]}:\|^${pkgs[$((i+7))]}:\|^${pkgs[$((i+8))]}:\|^${pkgs[$((i+9))]}:\|^${pkgs[$((i+10))]}:\|^${pkgs[$((i+11))]}:\|^${pkgs[$((i+12))]}:\|^${pkgs[$((i+13))]}:\|^${pkgs[$((i+14))]}:\|^${pkgs[$((i+15))]}:\|^${pkgs[$((i+16))]}:\|^${pkgs[$((i+17))]}:\|^${pkgs[$((i+18))]}:\|^${pkgs[$((i+19))]}:" "$tmp_file"
Expand Down Expand Up @@ -739,7 +769,7 @@ check_repo ()
fi

if [[ $nocolor -eq 0 ]]; then
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" "$no_desc"
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" "$no_desc" "$no_tag"
fi

echo -e "\nPackages with no free alternatives (yet):"
Expand Down Expand Up @@ -779,31 +809,36 @@ check_privacy ()
echo -e "Non-secure packages installed in your system:$nc\n"

counter=0; fix_doc=0; nonfree=0; semifree=0; technical=0; no_desc=0
no_tag=0;

mapfile -t nonpriv < <(for ((i=0; i<${#pkgs[*]}; i=$((i+20)))); do
/usr/bin/grep -- "^${pkgs[$i]}:\|^${pkgs[$((i+1))]}:\|^${pkgs[$((i+2))]}:\|^${pkgs[$((i+3))]}:\|^${pkgs[$((i+4))]}:\|^${pkgs[$((i+5))]}:\|^${pkgs[$((i+6))]}:\|^${pkgs[$((i+7))]}:\|^${pkgs[$((i+8))]}:\|^${pkgs[$((i+9))]}:\|^${pkgs[$((i+10))]}:\|^${pkgs[$((i+11))]}:\|^${pkgs[$((i+12))]}:\|^${pkgs[$((i+13))]}:\|^${pkgs[$((i+14))]}:\|^${pkgs[$((i+15))]}:\|^${pkgs[$((i+16))]}:\|^${pkgs[$((i+17))]}:\|^${pkgs[$((i+18))]}:\|^${pkgs[$((i+19))]}:" \
"$tmp_file" | /usr/bin/awk -F':' '{print $1}'
done)

for (( i=0; i<${#nonpriv[*]}; i++ )); do
# if blacklist_line "${nonpriv[$i]}" "$((i+1))" -ne -1; then
blacklist_line "${nonpriv[$i]}" "$((i+1))"
free_alternative "${nonpriv[$i]}"
(( counter++ ))
# fi
done

counter=$i
if [[ $counter -eq 0 ]]; then
echo -e "\e[1A${green}[+]$nc None! You're free from privacy" \
"risking packages!"
exit $SUCCESS
fi

if [[ $nocolor -eq 0 ]]; then
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" "$no_desc"
color_codes "$nonfree" "$semifree" "$technical" "$fix_doc" "$no_desc" "$no_tag"
fi

echo -e "\n-------------"
echo -e "${red}[-]$nc ${counter}/$(/usr/bin/pacman -Q | /usr/bin/wc -l)" \
"packages might be compromizing your privacy."

echo -e "\n${bold}NOTE$nc: Suggested alternatives come from Parabola libre repositories"
}

################################
Expand Down Expand Up @@ -1046,7 +1081,7 @@ check_pkg ()

if [[ $full_bl -eq 0 ]]; then

/usr/bin/grep ":\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]" \
/usr/bin/grep ":\[semifree\]\|:\[nonfree\]\|:\[uses-nonfree\]\|^[^[]*$" \
-- "$tmp_file" | /usr/bin/sudo -u "$user" /usr/bin/tee \
/tmp/parabola_bl_official 1>/dev/null

Expand Down Expand Up @@ -1099,8 +1134,10 @@ check_pkg ()
export GREP_COLORS="mt=1;36"

if [[ -n $desc ]]; then
echo "$desc" \
| /usr/bin/grep --color=always "\[technical\]\|\[branding\]\|\[nonfree\]\|\[semifree\]\|\[uses-nonfree\]\|\[recommends-nonfree\]\|\[FIXME:description\]\|\[FIXME:package\]"
if ! echo "$desc" \
| /usr/bin/grep --color=always "\[technical\]\|\[branding\]\|\[nonfree\]\|\[semifree\]\|\[uses-nonfree\]\|\[recommends-nonfree\]\|\[FIXME:description\]\|\[FIXME:package\]"; then
echo "$desc"
fi
else
echo "None"
fi
Expand Down

0 comments on commit db02b4a

Please sign in to comment.