summaryrefslogtreecommitdiff
path: root/src/maintenance-tools/parabolaweb-hackers-discrepancies
blob: 9ae2347dfa9241bd0dafc3090ceb78f736d9d159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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