#!/bin/sh
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-

# Dual Linux or msys64

prog=$( basename $0 .bash )
ROLE=proxy
PREFIX=/usr/local

[ -n "$MSYSTEM" ] && EXET=msys || EXET=sh

[ -f $PREFIX/etc/testforge/testforge.bash ] \
    && . /usr/local/etc/testforge/testforge.bash
. /usr/local/bin/usr_local_tput.bash || exit 2

PROXIES=""
if [ -d /etc/pacman.d/gnupg ] ; then
    ROLE=msys64
    HOMEDIR=/etc/pacman.d/gnupg
    # proxy or striaght through
    PROXIES="10.152.152.12"
  elif [ -d /q/Pg64/Msys64/etc/pacman.d/gnupg ] ; then
    ROLE=q
    HOMEDIR=/q/Pg64/Msys64/etc/pacman.d/gnupg
    ppl=/usr/local/bin/proxy_ping_lib.bash
    # /sbin/ifconfig on Debian morons and /bin/ifconfig on Gentoo
    [ "$USER" != root ] && export PATH=/sbin:$PATH
    [ -z "$MODE" ] && MODE=$( $ppl proxy_ping_mode )
    if [ "$MODE" = tor ] ; then
	PROXIES="127.0.0.1:3128"
      elif [ "$MODE" = whonix ] ; then
	PROXIES="10.0.2.15:9128"
      elif [ "$MODE" = gateway ] ; then
	PROXIES="10.0.2.15:9128"
      elif ps ax | grep -q polipo ; then
	PROXIES="127.0.0.1:3128"
    else
	echo ERROR: unknown proxy
	exit 2
    fi

  fi
GPG="gpg --verbose --home $HOMEDIR"

a=`ls $HOMEDIR/private-keys-v1.d/|wc -l`
if [ $? -ne 0 -o "$a" -eq 0 ] ; then
    ERROR you need a private kepair with $GPG --quick-gen-key
    exit 3
fi

# shellcheck disable=SC2154
$GPG --list-keys  | grep -B 1 unknown && \
    WARN un-signed keys in pacman && \
    DBUG "$GPG --list-keys 2>/dev/null |grep -B1 unknown|grep '^ ' |while read elt;do \$GPG --edit-key $elt ;done"

