summaryrefslogtreecommitdiff
path: root/pkgbuild-check-nonfree
diff options
context:
space:
mode:
authorNicolas Reynolds <fauno@kiwwwi.com.ar>2012-01-21 11:12:01 -0300
committerNicolas Reynolds <fauno@kiwwwi.com.ar>2012-01-21 11:12:01 -0300
commit918e09f1a47dc3d23440f08a91d91d31d62dcb5a (patch)
treeeffadb1e2c76d3e06975c92516647148ed9f420a /pkgbuild-check-nonfree
parent0e9e94d70a0442e2c0aebdfb282269e90d688712 (diff)
parent971e5b7d0cd614e1be3a82380ef16911f2d9cefe (diff)
Merge branch 'master' into fauno
Conflicts: fullpkg toru
Diffstat (limited to 'pkgbuild-check-nonfree')
-rwxr-xr-xpkgbuild-check-nonfree177
1 files changed, 142 insertions, 35 deletions
diff --git a/pkgbuild-check-nonfree b/pkgbuild-check-nonfree
index fd7b69e..bd6fa4b 100755
--- a/pkgbuild-check-nonfree
+++ b/pkgbuild-check-nonfree
@@ -19,80 +19,187 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-source /etc/libretools.conf
+# function log_end {
+# kill "$teepid"
+# rm "$logpipe"
+# }
+
+# function log {
+# LOG="pkgbuild-check-nonfree-$(date -u +%Y%m%d).log"
+# # ensure overridden package variables survive tee with split packages
+# logpipe="$(mktemp -u "$startdir/logpipe.XXXXXXXX")"
+# mkfifo "$logpipe"
+# tee "$LOG" < "$logpipe" &
+# teepid=$!
+# trap log_end ERR EXIT
+# }
+
+
+function unset_pkgbuild {
+
+ unset 'pkgbase' 'pkgname' 'pkgver' 'pkgrel' 'epoch' 'pkgdesc' \
+ 'arch' 'url' 'license' 'groups' 'optdepends' 'provides' \
+ 'conflicts' 'replaces' 'backup' 'options' 'install' \
+ 'changelog' 'source' 'noextract' 'md5sums' 'build' \
+ 'check' 'package' 'depends' 'makedepends' 'checkdepends'
+
+}
+
+function assert_pkgbuild {
+
+ if [ -e "$1" ]; then
+
+ source "$1"
+ if [ -n "${pkgname[0]}" ]; then
+ return 0 # valid PKGBUILD
+ fi
-function in_array { # usage : in_array( $needle, $haystack )
+ fi
- [[ $2 ]] || return 1 # Not found
+ error "$1 is not a valid PKGBUILD"
+ return 1
+}
+
+function check_replacement {
+
+ [ $2 ] || return 0 # Free (not found)
local needle=$1; shift
local item
- for item in "$@"; do
- [[ ${item#@} = $needle ]] && return 0 # Found
+ local rep
+ for line in $@; do
+
+ item="$(echo "$line" | cut -d':' -f1)"
+ rep="$(echo "$line" | cut -s -d':' -f2)"
+
+ if [ "$item" == "$needle" ]; then
+ if [ -z "$rep" ]; then
+ return 15 # Nonfree (found)
+ else
+ echo "$rep"
+ return 0 # Free (has replacement)
+ fi
+ fi
+
done
- return 1 # Not Found
+ return 0 # Free (not found)
}
function get_blacklist { # Download the blacklist.
pushd "$XDG_CONFIG_HOME/libretools" >/dev/null
+
msg "Downloading the blacklist of proprietary software packages."
- wget -N -q -O blacklist.txt "${BLACKLIST}" 2>/dev/null || {
- [ -e $XDG_CONFIG_HOME/libretools/blacklist.txt ] || {
+
+ if ! wget -N -q -O blacklist.txt "${BLACKLIST}" 2>/dev/null; then
+
+ if [ -e "$XDG_CONFIG_HOME/libretools/blacklist.txt" ]; then
+ warning "Using local copy of blacklist"
+ else
error "Download failed, exiting"
- exit 1
- }
- warning "Using local copy of blacklist"
- }
+ fi
+
+ fi
+
popd > /dev/null
}
function check_deps { # Check wheter a package depends on non-free
- pushd "$XDG_CONFIG_HOME/libretools/" >/dev/null
- local unfree=($(cut -d: -f1 blacklist.txt)) # pkgname:free-replacement:comments
- local freerep=($(cut -d: -f2 blacklist.txt)) # pkgname:free-replacement:comments
- popd >/dev/null
+ unset_pkgbuild
- msg "Looking for unfree dependencies"
- for item in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ; do
+ if ! assert_pkgbuild "$1"; then
+ return 1 # not PKGBUILD
+ fi
- if in_array $item ${unfree[@]} ; then
+ msg2 "${pkgbase:-${pkgname[0]}} $pkgver $pkgrel ${epoch:-""}" # > "$logpipe"
- if in_array $item ${freerep[@]} ; then
- warning "$item is repackaged with the same name."
- continue
+ for pkg in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ${checkdepends[@]}; do
+
+ lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_"))
+
+ rep="$(check_replacement $pkg ${lines[@]})"
+ freedom=$?
- elif in_array $item-libre ${freerep[@]} ; then
- warning "$item -> $item-libre"
+ if [ "$freedom" -eq 15 ]; then
+ warning "found $pkg" # > "$logpipe"
+ ev=15
+ continue
+
+ elif [ -n "$rep" ]; then
+
+ if [ "$rep" = "$pkg" ]; then
+ plain "$pkg is repackaged with the same name." # > "$logpipe"
continue
else
- ev=15
- msg2 "found $item"
+ plain "$pkg -> $rep" # > "$logpipe"
+ continue
fi
+
fi
+
done
+
}
-if [ -e $XDG_CONFIG_HOME/libretools/libretools.conf ]; then
- source $XDG_CONFIG_HOME/libretools/libretools.conf
+function usage {
+ # TODO: implement PKGBUILD arguments
+ echo ""
+ echo "$(basename $0) [options] [PKGBUILD1 PKGBUILD2 ...]"
+ echo ""
+ echo "OPTIONS"
+ echo ""
+ echo " -h : this message"
+ echo ""
+ echo "If no PKGBUILD is specified, one is searched on current directory"
+
+ exit 1
+}
+
+while getopts 'h' arg; do
+ case "$arg" in
+ h) usage ;;
+ esac
+done
+
+if (( ! EUID )); then
+ error "Run as normal user"
fi
-if [ -z "${BLACKLIST}" ]; then
- error "BLACKLIST variable is not set your libretools.conf file"; exit 1
+source /etc/libretools.conf
+if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then
+ source "$XDG_CONFIG_HOME/libretools/libretools.conf"
fi
-if [ -r PKGBUILD ]; then
- source PKGBUILD
-else
- error "There is no PKGBUILD in dir"; exit 1
+if [ -z "${BLACKLIST}" ]; then
+ error "BLACKLIST variable is not set your libretools.conf file"
+ exit 1
fi
if [ ! -d "$XDG_CONFIG_HOME/libretools" ]; then
mkdir -p "$XDG_CONFIG_HOME/libretools"
fi
+startdir=`pwd`
+
get_blacklist
+# log
+
+shift $(( OPTIND - 1))
+
+msg "Looking for unfree dependencies"
+
+if [ $# -ge 1 ]; then
+
+ for p in $@; do
+ if [ -n "$p" ]; then
+ check_deps "$p"
+ fi
+ done
+
+else
+
+ check_deps "`pwd`/PKGBUILD"
-check_deps
+fi
exit $ev