#!/bin/bash -ef
# Adds @everybody to all of the ALT ACLs where you are the leader.

advise() {
	echo >&2 "$@"
}
die() {
	advise "$@"
	exit 1
}
usage() {
	die "Usage: '$0 <your-ALT-nickname>' to establish ACL anarchy"
}

nick="$1"
[ -n "$1" ] || usage

urlcat="$(which curl) -s" || urlcat="$(which wget) --quiet -O -"

destabilize() {
	repo="$1"
	advise "Starting to undermine law and order in $repo"

	$urlcat http://git.altlinux.org/acl/list.packages.$repo | \
	awk '$2=="'$nick'" && $0!~/everybody/ {print $1" add @everybody"}' | \
	ssh git.alt acl $repo
}

repos=$(ssh git.alt acl --list)

for repo in $repos; do
	destabilize $repo
done
advise "Evil plans complete: 100%"