#!/bin/bash # parabolaweb-hackers-discrepancies - detect discrepancies between # the Parabola Hackers web page and hackers.git # # Copyright (C) 2019 bill-auger # # SPDX-License-Identifier: AGPL-3.0-or-later # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . readonly HACKERS_GIT_URL=https://git.parabola.nu/hackers.git readonly HACKERS_GIT_DIR=/tmp/$(basename $0) readonly HACKERS_URL=https://www.parabola.nu/people/hackers/ readonly GIT_LOGIN_REGEX='s|^username: \(.*\)$|\1|' readonly GIT_EMAIL_REGEX='s|^- \(.*\)$|\1|' readonly HTML_KEYS_REGEX='.*(Alias|Email):.*' readonly WEB_LOGIN_REGEX='s|.*>\(.*\)<.*|\1|' readonly WEB_EMAIL_REGEX='s|.*>\(.*@.*\)<.*|\1|' git_logins='' git_emails='' web_logins='' web_emails='' shell_logins='' declare -a logins_git_not_web=() declare -a emails_git_not_web=() declare -a logins_web_not_git=() declare -a emails_web_not_git=() declare -a logins_shell_not_git=() declare -a logins_git_not_shell=() echo " ############################################## ## parabolaweb<->hackers.git discrepancies: ## ##############################################" # sync hackers.git which git &> /dev/null || sudo pacman -S git ! [[ -d ${HACKERS_GIT_DIR} ]] && git clone ${HACKERS_GIT_URL} ${HACKERS_GIT_DIR} &> /dev/null cd ${HACKERS_GIT_DIR} && git pull origin &> /dev/null # parse hackers.git YAML for user_yaml in users/* do if grep -A1 'groups:' ${user_yaml} | tail -n 1 | grep 'hackers' > /dev/null then login=$(grep 'username:' ${user_yaml} | tail -n 1 | sed "${GIT_LOGIN_REGEX}") email=$(grep -A1 'email:' ${user_yaml} | tail -n 1 | sed "${GIT_EMAIL_REGEX}") git_logins="${git_logins} ${login} " git_emails="${git_emails} ${email} " fi done # parse parabolaweb hackers HTML for html in $(curl ${HACKERS_URL} 2> /dev/null | grep -A1 -E ${HTML_KEYS_REGEX}) do [[ "${html}" =~ \ ]] || continue login=$(sed "${WEB_EMAIL_REGEX}" <<< ${html}) email=$(sed "${WEB_LOGIN_REGEX}" <<< ${html}) [[ "${html}" =~ @ ]] && web_emails="${web_emails} ${login} " || web_logins="${web_logins} ${email} " done # parse parabola-hackers shell logins for hacker in $(/usr/lib/parabola-hackers/meta-cat --group hackers) do login=${hacker##*,} shell_logins="${shell_logins} ${login} " done # compare entries for login in ${git_logins} do [[ "${web_logins}" =~ " ${login} " ]] || logins_git_not_web=(${logins_git_not_web[*]} ${login}) done for email in ${git_emails} do [[ "${web_emails}" =~ " ${email} " ]] || emails_git_not_web=(${emails_git_not_web[*]} ${email}) done for login in ${web_logins} do [[ "${git_logins}" =~ " ${login} " ]] || logins_web_not_git=(${logins_web_not_git[*]} ${login}) done for email in ${web_emails} do [[ "${git_emails}" =~ " ${email} " ]] || emails_web_not_git=(${emails_web_not_git[*]} ${email}) done for login in ${shell_logins} do [[ "${git_logins}" =~ " ${login} " ]] || logins_shell_not_git=(${logins_shell_not_git[*]} ${login}) done for login in ${git_logins} do [[ "${shell_logins}" =~ " ${login} " ]] || logins_git_not_shell=(${logins_git_not_shell[*]} ${login}) done # print report if (( ${#logins_git_not_web[*]} )) || (( ${#emails_git_not_web[*]} )) then echo -e "\nin hackers.git but not on parabolaweb:" for login in ${logins_git_not_web[*]} ; do echo " (login) ${login}" ; done ; for email in ${emails_git_not_web[*]} ; do echo " (email) ${email}" ; done ; fi if (( ${#logins_web_not_git[*]} )) || (( ${#emails_web_not_git[*]} )) then echo -e "\non parabolaweb but not in hackers.git:" for login in ${logins_web_not_git[*]} ; do echo " (login) ${login}" ; done ; for email in ${emails_web_not_git[*]} ; do echo " (email) ${email}" ; done ; fi if (( ${#logins_shell_not_git[*]} )) then echo -e "\nshell logins not in hackers.git:" for login in ${logins_shell_not_git[*]} ; do echo " (login) ${login}" ; done ; fi if (( ${#logins_git_not_shell[*]} )) then echo -e "\nin hackers.git without shell login:" for login in ${logins_git_not_shell[*]} ; do echo " (login) ${login}" ; done ; fi # DEBUG begin # echo "web_logins=$web_logins" 1>&2 ; echo "web_emails=$web_emails" 1>&2 ; # echo "git_logins=$git_logins" 1>&2 ; echo "git_emails=$git_emails" 1>&2 ; # echo "shell_logins=$shell_logins" 1>&2 # echo "logins_git_not_web=${logins_git_not_web[*]}" 1>&2 # echo "emails_git_not_web=${emails_git_not_web[*]}" 1>&2 # echo "logins_web_not_git=${logins_web_not_git[*]}" 1>&2 # echo "emails_web_not_git=${emails_web_not_git[*]}" 1>&2 # echo "logins_shell_not_git=${logins_shell_not_git[*]}" 1>&2 # echo "logins_git_not_shell=${logins_git_not_shell[*]}" 1>&2 # DEBUG end