diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2019-09-18 11:25:30 -0400 |
---|---|---|
committer | Andreas Grapentin <andreas@grapentin.org> | 2022-01-18 17:31:53 +0100 |
commit | 2195e911c6e07cca69dd6bfc8c5ded650ea505de (patch) | |
tree | 7297d3672a2f800e04dd8033d2e9a0dc5e87258a | |
parent | c020062cf1fb161fd43e285f78e2801fd957d000 (diff) |
[parabolaweb-hackers-discrepancies]: initial script
-rwxr-xr-x | src/maintenance-tools/parabolaweb-hackers-discrepancies | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/maintenance-tools/parabolaweb-hackers-discrepancies b/src/maintenance-tools/parabolaweb-hackers-discrepancies new file mode 100755 index 0000000..9ae2347 --- /dev/null +++ b/src/maintenance-tools/parabolaweb-hackers-discrepancies @@ -0,0 +1,115 @@ +#!/bin/bash + +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='.*<th>(Alias|Email):</th>.*' +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}" =~ \</td\> ]] || 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 |